three.module.js 1.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928
  1. // Polyfills
  2. if ( Number.EPSILON === undefined ) {
  3. Number.EPSILON = Math.pow( 2, - 52 );
  4. }
  5. if ( Number.isInteger === undefined ) {
  6. // Missing in IE
  7. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  8. Number.isInteger = function ( value ) {
  9. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  10. };
  11. }
  12. //
  13. if ( Math.sign === undefined ) {
  14. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  15. Math.sign = function ( x ) {
  16. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  17. };
  18. }
  19. if ( 'name' in Function.prototype === false ) {
  20. // Missing in IE
  21. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  22. Object.defineProperty( Function.prototype, 'name', {
  23. get: function () {
  24. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  25. }
  26. } );
  27. }
  28. if ( Object.assign === undefined ) {
  29. // Missing in IE
  30. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  31. Object.assign = function ( target ) {
  32. if ( target === undefined || target === null ) {
  33. throw new TypeError( 'Cannot convert undefined or null to object' );
  34. }
  35. var output = Object( target );
  36. for ( var index = 1; index < arguments.length; index ++ ) {
  37. var source = arguments[ index ];
  38. if ( source !== undefined && source !== null ) {
  39. for ( var nextKey in source ) {
  40. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  41. output[ nextKey ] = source[ nextKey ];
  42. }
  43. }
  44. }
  45. }
  46. return output;
  47. };
  48. }
  49. /**
  50. * https://github.com/mrdoob/eventdispatcher.js/
  51. */
  52. function EventDispatcher() {}
  53. Object.assign( EventDispatcher.prototype, {
  54. addEventListener: function ( type, listener ) {
  55. if ( this._listeners === undefined ) this._listeners = {};
  56. var listeners = this._listeners;
  57. if ( listeners[ type ] === undefined ) {
  58. listeners[ type ] = [];
  59. }
  60. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  61. listeners[ type ].push( listener );
  62. }
  63. },
  64. hasEventListener: function ( type, listener ) {
  65. if ( this._listeners === undefined ) return false;
  66. var listeners = this._listeners;
  67. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  68. },
  69. removeEventListener: function ( type, listener ) {
  70. if ( this._listeners === undefined ) return;
  71. var listeners = this._listeners;
  72. var listenerArray = listeners[ type ];
  73. if ( listenerArray !== undefined ) {
  74. var index = listenerArray.indexOf( listener );
  75. if ( index !== - 1 ) {
  76. listenerArray.splice( index, 1 );
  77. }
  78. }
  79. },
  80. dispatchEvent: function ( event ) {
  81. if ( this._listeners === undefined ) return;
  82. var listeners = this._listeners;
  83. var listenerArray = listeners[ event.type ];
  84. if ( listenerArray !== undefined ) {
  85. event.target = this;
  86. var array = listenerArray.slice( 0 );
  87. for ( var i = 0, l = array.length; i < l; i ++ ) {
  88. array[ i ].call( this, event );
  89. }
  90. }
  91. }
  92. } );
  93. var REVISION = '108dev';
  94. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  95. var TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  96. var CullFaceNone = 0;
  97. var CullFaceBack = 1;
  98. var CullFaceFront = 2;
  99. var CullFaceFrontBack = 3;
  100. var FrontFaceDirectionCW = 0;
  101. var FrontFaceDirectionCCW = 1;
  102. var BasicShadowMap = 0;
  103. var PCFShadowMap = 1;
  104. var PCFSoftShadowMap = 2;
  105. var FrontSide = 0;
  106. var BackSide = 1;
  107. var DoubleSide = 2;
  108. var FlatShading = 1;
  109. var SmoothShading = 2;
  110. var NoColors = 0;
  111. var FaceColors = 1;
  112. var VertexColors = 2;
  113. var NoBlending = 0;
  114. var NormalBlending = 1;
  115. var AdditiveBlending = 2;
  116. var SubtractiveBlending = 3;
  117. var MultiplyBlending = 4;
  118. var CustomBlending = 5;
  119. var AddEquation = 100;
  120. var SubtractEquation = 101;
  121. var ReverseSubtractEquation = 102;
  122. var MinEquation = 103;
  123. var MaxEquation = 104;
  124. var ZeroFactor = 200;
  125. var OneFactor = 201;
  126. var SrcColorFactor = 202;
  127. var OneMinusSrcColorFactor = 203;
  128. var SrcAlphaFactor = 204;
  129. var OneMinusSrcAlphaFactor = 205;
  130. var DstAlphaFactor = 206;
  131. var OneMinusDstAlphaFactor = 207;
  132. var DstColorFactor = 208;
  133. var OneMinusDstColorFactor = 209;
  134. var SrcAlphaSaturateFactor = 210;
  135. var NeverDepth = 0;
  136. var AlwaysDepth = 1;
  137. var LessDepth = 2;
  138. var LessEqualDepth = 3;
  139. var EqualDepth = 4;
  140. var GreaterEqualDepth = 5;
  141. var GreaterDepth = 6;
  142. var NotEqualDepth = 7;
  143. var MultiplyOperation = 0;
  144. var MixOperation = 1;
  145. var AddOperation = 2;
  146. var NoToneMapping = 0;
  147. var LinearToneMapping = 1;
  148. var ReinhardToneMapping = 2;
  149. var Uncharted2ToneMapping = 3;
  150. var CineonToneMapping = 4;
  151. var ACESFilmicToneMapping = 5;
  152. var UVMapping = 300;
  153. var CubeReflectionMapping = 301;
  154. var CubeRefractionMapping = 302;
  155. var EquirectangularReflectionMapping = 303;
  156. var EquirectangularRefractionMapping = 304;
  157. var SphericalReflectionMapping = 305;
  158. var CubeUVReflectionMapping = 306;
  159. var CubeUVRefractionMapping = 307;
  160. var RepeatWrapping = 1000;
  161. var ClampToEdgeWrapping = 1001;
  162. var MirroredRepeatWrapping = 1002;
  163. var NearestFilter = 1003;
  164. var NearestMipmapNearestFilter = 1004;
  165. var NearestMipMapNearestFilter = 1004;
  166. var NearestMipmapLinearFilter = 1005;
  167. var NearestMipMapLinearFilter = 1005;
  168. var LinearFilter = 1006;
  169. var LinearMipmapNearestFilter = 1007;
  170. var LinearMipMapNearestFilter = 1007;
  171. var LinearMipmapLinearFilter = 1008;
  172. var LinearMipMapLinearFilter = 1008;
  173. var UnsignedByteType = 1009;
  174. var ByteType = 1010;
  175. var ShortType = 1011;
  176. var UnsignedShortType = 1012;
  177. var IntType = 1013;
  178. var UnsignedIntType = 1014;
  179. var FloatType = 1015;
  180. var HalfFloatType = 1016;
  181. var UnsignedShort4444Type = 1017;
  182. var UnsignedShort5551Type = 1018;
  183. var UnsignedShort565Type = 1019;
  184. var UnsignedInt248Type = 1020;
  185. var AlphaFormat = 1021;
  186. var RGBFormat = 1022;
  187. var RGBAFormat = 1023;
  188. var LuminanceFormat = 1024;
  189. var LuminanceAlphaFormat = 1025;
  190. var RGBEFormat = RGBAFormat;
  191. var DepthFormat = 1026;
  192. var DepthStencilFormat = 1027;
  193. var RedFormat = 1028;
  194. var RGB_S3TC_DXT1_Format = 33776;
  195. var RGBA_S3TC_DXT1_Format = 33777;
  196. var RGBA_S3TC_DXT3_Format = 33778;
  197. var RGBA_S3TC_DXT5_Format = 33779;
  198. var RGB_PVRTC_4BPPV1_Format = 35840;
  199. var RGB_PVRTC_2BPPV1_Format = 35841;
  200. var RGBA_PVRTC_4BPPV1_Format = 35842;
  201. var RGBA_PVRTC_2BPPV1_Format = 35843;
  202. var RGB_ETC1_Format = 36196;
  203. var RGBA_ASTC_4x4_Format = 37808;
  204. var RGBA_ASTC_5x4_Format = 37809;
  205. var RGBA_ASTC_5x5_Format = 37810;
  206. var RGBA_ASTC_6x5_Format = 37811;
  207. var RGBA_ASTC_6x6_Format = 37812;
  208. var RGBA_ASTC_8x5_Format = 37813;
  209. var RGBA_ASTC_8x6_Format = 37814;
  210. var RGBA_ASTC_8x8_Format = 37815;
  211. var RGBA_ASTC_10x5_Format = 37816;
  212. var RGBA_ASTC_10x6_Format = 37817;
  213. var RGBA_ASTC_10x8_Format = 37818;
  214. var RGBA_ASTC_10x10_Format = 37819;
  215. var RGBA_ASTC_12x10_Format = 37820;
  216. var RGBA_ASTC_12x12_Format = 37821;
  217. var LoopOnce = 2200;
  218. var LoopRepeat = 2201;
  219. var LoopPingPong = 2202;
  220. var InterpolateDiscrete = 2300;
  221. var InterpolateLinear = 2301;
  222. var InterpolateSmooth = 2302;
  223. var ZeroCurvatureEnding = 2400;
  224. var ZeroSlopeEnding = 2401;
  225. var WrapAroundEnding = 2402;
  226. var TrianglesDrawMode = 0;
  227. var TriangleStripDrawMode = 1;
  228. var TriangleFanDrawMode = 2;
  229. var LinearEncoding = 3000;
  230. var sRGBEncoding = 3001;
  231. var GammaEncoding = 3007;
  232. var RGBEEncoding = 3002;
  233. var LogLuvEncoding = 3003;
  234. var RGBM7Encoding = 3004;
  235. var RGBM16Encoding = 3005;
  236. var RGBDEncoding = 3006;
  237. var BasicDepthPacking = 3200;
  238. var RGBADepthPacking = 3201;
  239. var TangentSpaceNormalMap = 0;
  240. var ObjectSpaceNormalMap = 1;
  241. var ZeroStencilOp = 0;
  242. var KeepStencilOp = 7680;
  243. var ReplaceStencilOp = 7681;
  244. var IncrementStencilOp = 7682;
  245. var DecrementStencilOp = 7683;
  246. var IncrementWrapStencilOp = 34055;
  247. var DecrementWrapStencilOp = 34056;
  248. var InvertStencilOp = 5386;
  249. var NeverStencilFunc = 512;
  250. var LessStencilFunc = 513;
  251. var EqualStencilFunc = 514;
  252. var LessEqualStencilFunc = 515;
  253. var GreaterStencilFunc = 516;
  254. var NotEqualStencilFunc = 517;
  255. var GreaterEqualStencilFunc = 518;
  256. var AlwaysStencilFunc = 519;
  257. /**
  258. * @author alteredq / http://alteredqualia.com/
  259. * @author mrdoob / http://mrdoob.com/
  260. */
  261. var _lut = [];
  262. for ( var i = 0; i < 256; i ++ ) {
  263. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  264. }
  265. var _Math = {
  266. DEG2RAD: Math.PI / 180,
  267. RAD2DEG: 180 / Math.PI,
  268. generateUUID: function () {
  269. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  270. var d0 = Math.random() * 0xffffffff | 0;
  271. var d1 = Math.random() * 0xffffffff | 0;
  272. var d2 = Math.random() * 0xffffffff | 0;
  273. var d3 = Math.random() * 0xffffffff | 0;
  274. var uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  275. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  276. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  277. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  278. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  279. return uuid.toUpperCase();
  280. },
  281. clamp: function ( value, min, max ) {
  282. return Math.max( min, Math.min( max, value ) );
  283. },
  284. // compute euclidian modulo of m % n
  285. // https://en.wikipedia.org/wiki/Modulo_operation
  286. euclideanModulo: function ( n, m ) {
  287. return ( ( n % m ) + m ) % m;
  288. },
  289. // Linear mapping from range <a1, a2> to range <b1, b2>
  290. mapLinear: function ( x, a1, a2, b1, b2 ) {
  291. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  292. },
  293. // https://en.wikipedia.org/wiki/Linear_interpolation
  294. lerp: function ( x, y, t ) {
  295. return ( 1 - t ) * x + t * y;
  296. },
  297. // http://en.wikipedia.org/wiki/Smoothstep
  298. smoothstep: function ( x, min, max ) {
  299. if ( x <= min ) return 0;
  300. if ( x >= max ) return 1;
  301. x = ( x - min ) / ( max - min );
  302. return x * x * ( 3 - 2 * x );
  303. },
  304. smootherstep: function ( x, min, max ) {
  305. if ( x <= min ) return 0;
  306. if ( x >= max ) return 1;
  307. x = ( x - min ) / ( max - min );
  308. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  309. },
  310. // Random integer from <low, high> interval
  311. randInt: function ( low, high ) {
  312. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  313. },
  314. // Random float from <low, high> interval
  315. randFloat: function ( low, high ) {
  316. return low + Math.random() * ( high - low );
  317. },
  318. // Random float from <-range/2, range/2> interval
  319. randFloatSpread: function ( range ) {
  320. return range * ( 0.5 - Math.random() );
  321. },
  322. degToRad: function ( degrees ) {
  323. return degrees * _Math.DEG2RAD;
  324. },
  325. radToDeg: function ( radians ) {
  326. return radians * _Math.RAD2DEG;
  327. },
  328. isPowerOfTwo: function ( value ) {
  329. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  330. },
  331. ceilPowerOfTwo: function ( value ) {
  332. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  333. },
  334. floorPowerOfTwo: function ( value ) {
  335. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  336. }
  337. };
  338. /**
  339. * @author mrdoob / http://mrdoob.com/
  340. * @author philogb / http://blog.thejit.org/
  341. * @author egraether / http://egraether.com/
  342. * @author zz85 / http://www.lab4games.net/zz85/blog
  343. */
  344. function Vector2( x, y ) {
  345. this.x = x || 0;
  346. this.y = y || 0;
  347. }
  348. Object.defineProperties( Vector2.prototype, {
  349. "width": {
  350. get: function () {
  351. return this.x;
  352. },
  353. set: function ( value ) {
  354. this.x = value;
  355. }
  356. },
  357. "height": {
  358. get: function () {
  359. return this.y;
  360. },
  361. set: function ( value ) {
  362. this.y = value;
  363. }
  364. }
  365. } );
  366. Object.assign( Vector2.prototype, {
  367. isVector2: true,
  368. set: function ( x, y ) {
  369. this.x = x;
  370. this.y = y;
  371. return this;
  372. },
  373. setScalar: function ( scalar ) {
  374. this.x = scalar;
  375. this.y = scalar;
  376. return this;
  377. },
  378. setX: function ( x ) {
  379. this.x = x;
  380. return this;
  381. },
  382. setY: function ( y ) {
  383. this.y = y;
  384. return this;
  385. },
  386. setComponent: function ( index, value ) {
  387. switch ( index ) {
  388. case 0: this.x = value; break;
  389. case 1: this.y = value; break;
  390. default: throw new Error( 'index is out of range: ' + index );
  391. }
  392. return this;
  393. },
  394. getComponent: function ( index ) {
  395. switch ( index ) {
  396. case 0: return this.x;
  397. case 1: return this.y;
  398. default: throw new Error( 'index is out of range: ' + index );
  399. }
  400. },
  401. clone: function () {
  402. return new this.constructor( this.x, this.y );
  403. },
  404. copy: function ( v ) {
  405. this.x = v.x;
  406. this.y = v.y;
  407. return this;
  408. },
  409. add: function ( v, w ) {
  410. if ( w !== undefined ) {
  411. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  412. return this.addVectors( v, w );
  413. }
  414. this.x += v.x;
  415. this.y += v.y;
  416. return this;
  417. },
  418. addScalar: function ( s ) {
  419. this.x += s;
  420. this.y += s;
  421. return this;
  422. },
  423. addVectors: function ( a, b ) {
  424. this.x = a.x + b.x;
  425. this.y = a.y + b.y;
  426. return this;
  427. },
  428. addScaledVector: function ( v, s ) {
  429. this.x += v.x * s;
  430. this.y += v.y * s;
  431. return this;
  432. },
  433. sub: function ( v, w ) {
  434. if ( w !== undefined ) {
  435. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  436. return this.subVectors( v, w );
  437. }
  438. this.x -= v.x;
  439. this.y -= v.y;
  440. return this;
  441. },
  442. subScalar: function ( s ) {
  443. this.x -= s;
  444. this.y -= s;
  445. return this;
  446. },
  447. subVectors: function ( a, b ) {
  448. this.x = a.x - b.x;
  449. this.y = a.y - b.y;
  450. return this;
  451. },
  452. multiply: function ( v ) {
  453. this.x *= v.x;
  454. this.y *= v.y;
  455. return this;
  456. },
  457. multiplyScalar: function ( scalar ) {
  458. this.x *= scalar;
  459. this.y *= scalar;
  460. return this;
  461. },
  462. divide: function ( v ) {
  463. this.x /= v.x;
  464. this.y /= v.y;
  465. return this;
  466. },
  467. divideScalar: function ( scalar ) {
  468. return this.multiplyScalar( 1 / scalar );
  469. },
  470. applyMatrix3: function ( m ) {
  471. var x = this.x, y = this.y;
  472. var e = m.elements;
  473. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  474. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  475. return this;
  476. },
  477. min: function ( v ) {
  478. this.x = Math.min( this.x, v.x );
  479. this.y = Math.min( this.y, v.y );
  480. return this;
  481. },
  482. max: function ( v ) {
  483. this.x = Math.max( this.x, v.x );
  484. this.y = Math.max( this.y, v.y );
  485. return this;
  486. },
  487. clamp: function ( min, max ) {
  488. // assumes min < max, componentwise
  489. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  490. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  491. return this;
  492. },
  493. clampScalar: function ( minVal, maxVal ) {
  494. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  495. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  496. return this;
  497. },
  498. clampLength: function ( min, max ) {
  499. var length = this.length();
  500. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  501. },
  502. floor: function () {
  503. this.x = Math.floor( this.x );
  504. this.y = Math.floor( this.y );
  505. return this;
  506. },
  507. ceil: function () {
  508. this.x = Math.ceil( this.x );
  509. this.y = Math.ceil( this.y );
  510. return this;
  511. },
  512. round: function () {
  513. this.x = Math.round( this.x );
  514. this.y = Math.round( this.y );
  515. return this;
  516. },
  517. roundToZero: function () {
  518. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  519. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  520. return this;
  521. },
  522. negate: function () {
  523. this.x = - this.x;
  524. this.y = - this.y;
  525. return this;
  526. },
  527. dot: function ( v ) {
  528. return this.x * v.x + this.y * v.y;
  529. },
  530. cross: function ( v ) {
  531. return this.x * v.y - this.y * v.x;
  532. },
  533. lengthSq: function () {
  534. return this.x * this.x + this.y * this.y;
  535. },
  536. length: function () {
  537. return Math.sqrt( this.x * this.x + this.y * this.y );
  538. },
  539. manhattanLength: function () {
  540. return Math.abs( this.x ) + Math.abs( this.y );
  541. },
  542. normalize: function () {
  543. return this.divideScalar( this.length() || 1 );
  544. },
  545. angle: function () {
  546. // computes the angle in radians with respect to the positive x-axis
  547. var angle = Math.atan2( this.y, this.x );
  548. if ( angle < 0 ) angle += 2 * Math.PI;
  549. return angle;
  550. },
  551. distanceTo: function ( v ) {
  552. return Math.sqrt( this.distanceToSquared( v ) );
  553. },
  554. distanceToSquared: function ( v ) {
  555. var dx = this.x - v.x, dy = this.y - v.y;
  556. return dx * dx + dy * dy;
  557. },
  558. manhattanDistanceTo: function ( v ) {
  559. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  560. },
  561. setLength: function ( length ) {
  562. return this.normalize().multiplyScalar( length );
  563. },
  564. lerp: function ( v, alpha ) {
  565. this.x += ( v.x - this.x ) * alpha;
  566. this.y += ( v.y - this.y ) * alpha;
  567. return this;
  568. },
  569. lerpVectors: function ( v1, v2, alpha ) {
  570. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  571. },
  572. equals: function ( v ) {
  573. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  574. },
  575. fromArray: function ( array, offset ) {
  576. if ( offset === undefined ) offset = 0;
  577. this.x = array[ offset ];
  578. this.y = array[ offset + 1 ];
  579. return this;
  580. },
  581. toArray: function ( array, offset ) {
  582. if ( array === undefined ) array = [];
  583. if ( offset === undefined ) offset = 0;
  584. array[ offset ] = this.x;
  585. array[ offset + 1 ] = this.y;
  586. return array;
  587. },
  588. fromBufferAttribute: function ( attribute, index, offset ) {
  589. if ( offset !== undefined ) {
  590. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  591. }
  592. this.x = attribute.getX( index );
  593. this.y = attribute.getY( index );
  594. return this;
  595. },
  596. rotateAround: function ( center, angle ) {
  597. var c = Math.cos( angle ), s = Math.sin( angle );
  598. var x = this.x - center.x;
  599. var y = this.y - center.y;
  600. this.x = x * c - y * s + center.x;
  601. this.y = x * s + y * c + center.y;
  602. return this;
  603. }
  604. } );
  605. /**
  606. * @author mikael emtinger / http://gomo.se/
  607. * @author alteredq / http://alteredqualia.com/
  608. * @author WestLangley / http://github.com/WestLangley
  609. * @author bhouston / http://clara.io
  610. */
  611. function Quaternion( x, y, z, w ) {
  612. this._x = x || 0;
  613. this._y = y || 0;
  614. this._z = z || 0;
  615. this._w = ( w !== undefined ) ? w : 1;
  616. }
  617. Object.assign( Quaternion, {
  618. slerp: function ( qa, qb, qm, t ) {
  619. return qm.copy( qa ).slerp( qb, t );
  620. },
  621. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  622. // fuzz-free, array-based Quaternion SLERP operation
  623. var x0 = src0[ srcOffset0 + 0 ],
  624. y0 = src0[ srcOffset0 + 1 ],
  625. z0 = src0[ srcOffset0 + 2 ],
  626. w0 = src0[ srcOffset0 + 3 ],
  627. x1 = src1[ srcOffset1 + 0 ],
  628. y1 = src1[ srcOffset1 + 1 ],
  629. z1 = src1[ srcOffset1 + 2 ],
  630. w1 = src1[ srcOffset1 + 3 ];
  631. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  632. var s = 1 - t,
  633. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  634. dir = ( cos >= 0 ? 1 : - 1 ),
  635. sqrSin = 1 - cos * cos;
  636. // Skip the Slerp for tiny steps to avoid numeric problems:
  637. if ( sqrSin > Number.EPSILON ) {
  638. var sin = Math.sqrt( sqrSin ),
  639. len = Math.atan2( sin, cos * dir );
  640. s = Math.sin( s * len ) / sin;
  641. t = Math.sin( t * len ) / sin;
  642. }
  643. var tDir = t * dir;
  644. x0 = x0 * s + x1 * tDir;
  645. y0 = y0 * s + y1 * tDir;
  646. z0 = z0 * s + z1 * tDir;
  647. w0 = w0 * s + w1 * tDir;
  648. // Normalize in case we just did a lerp:
  649. if ( s === 1 - t ) {
  650. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  651. x0 *= f;
  652. y0 *= f;
  653. z0 *= f;
  654. w0 *= f;
  655. }
  656. }
  657. dst[ dstOffset ] = x0;
  658. dst[ dstOffset + 1 ] = y0;
  659. dst[ dstOffset + 2 ] = z0;
  660. dst[ dstOffset + 3 ] = w0;
  661. }
  662. } );
  663. Object.defineProperties( Quaternion.prototype, {
  664. x: {
  665. get: function () {
  666. return this._x;
  667. },
  668. set: function ( value ) {
  669. this._x = value;
  670. this._onChangeCallback();
  671. }
  672. },
  673. y: {
  674. get: function () {
  675. return this._y;
  676. },
  677. set: function ( value ) {
  678. this._y = value;
  679. this._onChangeCallback();
  680. }
  681. },
  682. z: {
  683. get: function () {
  684. return this._z;
  685. },
  686. set: function ( value ) {
  687. this._z = value;
  688. this._onChangeCallback();
  689. }
  690. },
  691. w: {
  692. get: function () {
  693. return this._w;
  694. },
  695. set: function ( value ) {
  696. this._w = value;
  697. this._onChangeCallback();
  698. }
  699. }
  700. } );
  701. Object.assign( Quaternion.prototype, {
  702. isQuaternion: true,
  703. set: function ( x, y, z, w ) {
  704. this._x = x;
  705. this._y = y;
  706. this._z = z;
  707. this._w = w;
  708. this._onChangeCallback();
  709. return this;
  710. },
  711. clone: function () {
  712. return new this.constructor( this._x, this._y, this._z, this._w );
  713. },
  714. copy: function ( quaternion ) {
  715. this._x = quaternion.x;
  716. this._y = quaternion.y;
  717. this._z = quaternion.z;
  718. this._w = quaternion.w;
  719. this._onChangeCallback();
  720. return this;
  721. },
  722. setFromEuler: function ( euler, update ) {
  723. if ( ! ( euler && euler.isEuler ) ) {
  724. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  725. }
  726. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  727. // http://www.mathworks.com/matlabcentral/fileexchange/
  728. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  729. // content/SpinCalc.m
  730. var cos = Math.cos;
  731. var sin = Math.sin;
  732. var c1 = cos( x / 2 );
  733. var c2 = cos( y / 2 );
  734. var c3 = cos( z / 2 );
  735. var s1 = sin( x / 2 );
  736. var s2 = sin( y / 2 );
  737. var s3 = sin( z / 2 );
  738. if ( order === 'XYZ' ) {
  739. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  740. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  741. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  742. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  743. } else if ( order === 'YXZ' ) {
  744. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  745. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  746. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  747. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  748. } else if ( order === 'ZXY' ) {
  749. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  750. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  751. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  752. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  753. } else if ( order === 'ZYX' ) {
  754. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  755. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  756. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  757. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  758. } else if ( order === 'YZX' ) {
  759. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  760. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  761. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  762. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  763. } else if ( order === 'XZY' ) {
  764. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  765. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  766. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  767. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  768. }
  769. if ( update !== false ) this._onChangeCallback();
  770. return this;
  771. },
  772. setFromAxisAngle: function ( axis, angle ) {
  773. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  774. // assumes axis is normalized
  775. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  776. this._x = axis.x * s;
  777. this._y = axis.y * s;
  778. this._z = axis.z * s;
  779. this._w = Math.cos( halfAngle );
  780. this._onChangeCallback();
  781. return this;
  782. },
  783. setFromRotationMatrix: function ( m ) {
  784. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  785. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  786. var te = m.elements,
  787. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  788. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  789. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  790. trace = m11 + m22 + m33,
  791. s;
  792. if ( trace > 0 ) {
  793. s = 0.5 / Math.sqrt( trace + 1.0 );
  794. this._w = 0.25 / s;
  795. this._x = ( m32 - m23 ) * s;
  796. this._y = ( m13 - m31 ) * s;
  797. this._z = ( m21 - m12 ) * s;
  798. } else if ( m11 > m22 && m11 > m33 ) {
  799. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  800. this._w = ( m32 - m23 ) / s;
  801. this._x = 0.25 * s;
  802. this._y = ( m12 + m21 ) / s;
  803. this._z = ( m13 + m31 ) / s;
  804. } else if ( m22 > m33 ) {
  805. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  806. this._w = ( m13 - m31 ) / s;
  807. this._x = ( m12 + m21 ) / s;
  808. this._y = 0.25 * s;
  809. this._z = ( m23 + m32 ) / s;
  810. } else {
  811. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  812. this._w = ( m21 - m12 ) / s;
  813. this._x = ( m13 + m31 ) / s;
  814. this._y = ( m23 + m32 ) / s;
  815. this._z = 0.25 * s;
  816. }
  817. this._onChangeCallback();
  818. return this;
  819. },
  820. setFromUnitVectors: function ( vFrom, vTo ) {
  821. // assumes direction vectors vFrom and vTo are normalized
  822. var EPS = 0.000001;
  823. var r = vFrom.dot( vTo ) + 1;
  824. if ( r < EPS ) {
  825. r = 0;
  826. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  827. this._x = - vFrom.y;
  828. this._y = vFrom.x;
  829. this._z = 0;
  830. this._w = r;
  831. } else {
  832. this._x = 0;
  833. this._y = - vFrom.z;
  834. this._z = vFrom.y;
  835. this._w = r;
  836. }
  837. } else {
  838. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  839. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  840. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  841. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  842. this._w = r;
  843. }
  844. return this.normalize();
  845. },
  846. angleTo: function ( q ) {
  847. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  848. },
  849. rotateTowards: function ( q, step ) {
  850. var angle = this.angleTo( q );
  851. if ( angle === 0 ) return this;
  852. var t = Math.min( 1, step / angle );
  853. this.slerp( q, t );
  854. return this;
  855. },
  856. inverse: function () {
  857. // quaternion is assumed to have unit length
  858. return this.conjugate();
  859. },
  860. conjugate: function () {
  861. this._x *= - 1;
  862. this._y *= - 1;
  863. this._z *= - 1;
  864. this._onChangeCallback();
  865. return this;
  866. },
  867. dot: function ( v ) {
  868. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  869. },
  870. lengthSq: function () {
  871. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  872. },
  873. length: function () {
  874. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  875. },
  876. normalize: function () {
  877. var l = this.length();
  878. if ( l === 0 ) {
  879. this._x = 0;
  880. this._y = 0;
  881. this._z = 0;
  882. this._w = 1;
  883. } else {
  884. l = 1 / l;
  885. this._x = this._x * l;
  886. this._y = this._y * l;
  887. this._z = this._z * l;
  888. this._w = this._w * l;
  889. }
  890. this._onChangeCallback();
  891. return this;
  892. },
  893. multiply: function ( q, p ) {
  894. if ( p !== undefined ) {
  895. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  896. return this.multiplyQuaternions( q, p );
  897. }
  898. return this.multiplyQuaternions( this, q );
  899. },
  900. premultiply: function ( q ) {
  901. return this.multiplyQuaternions( q, this );
  902. },
  903. multiplyQuaternions: function ( a, b ) {
  904. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  905. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  906. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  907. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  908. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  909. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  910. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  911. this._onChangeCallback();
  912. return this;
  913. },
  914. slerp: function ( qb, t ) {
  915. if ( t === 0 ) return this;
  916. if ( t === 1 ) return this.copy( qb );
  917. var x = this._x, y = this._y, z = this._z, w = this._w;
  918. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  919. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  920. if ( cosHalfTheta < 0 ) {
  921. this._w = - qb._w;
  922. this._x = - qb._x;
  923. this._y = - qb._y;
  924. this._z = - qb._z;
  925. cosHalfTheta = - cosHalfTheta;
  926. } else {
  927. this.copy( qb );
  928. }
  929. if ( cosHalfTheta >= 1.0 ) {
  930. this._w = w;
  931. this._x = x;
  932. this._y = y;
  933. this._z = z;
  934. return this;
  935. }
  936. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  937. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  938. var s = 1 - t;
  939. this._w = s * w + t * this._w;
  940. this._x = s * x + t * this._x;
  941. this._y = s * y + t * this._y;
  942. this._z = s * z + t * this._z;
  943. this.normalize();
  944. this._onChangeCallback();
  945. return this;
  946. }
  947. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  948. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  949. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  950. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  951. this._w = ( w * ratioA + this._w * ratioB );
  952. this._x = ( x * ratioA + this._x * ratioB );
  953. this._y = ( y * ratioA + this._y * ratioB );
  954. this._z = ( z * ratioA + this._z * ratioB );
  955. this._onChangeCallback();
  956. return this;
  957. },
  958. equals: function ( quaternion ) {
  959. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  960. },
  961. fromArray: function ( array, offset ) {
  962. if ( offset === undefined ) offset = 0;
  963. this._x = array[ offset ];
  964. this._y = array[ offset + 1 ];
  965. this._z = array[ offset + 2 ];
  966. this._w = array[ offset + 3 ];
  967. this._onChangeCallback();
  968. return this;
  969. },
  970. toArray: function ( array, offset ) {
  971. if ( array === undefined ) array = [];
  972. if ( offset === undefined ) offset = 0;
  973. array[ offset ] = this._x;
  974. array[ offset + 1 ] = this._y;
  975. array[ offset + 2 ] = this._z;
  976. array[ offset + 3 ] = this._w;
  977. return array;
  978. },
  979. _onChange: function ( callback ) {
  980. this._onChangeCallback = callback;
  981. return this;
  982. },
  983. _onChangeCallback: function () {}
  984. } );
  985. /**
  986. * @author mrdoob / http://mrdoob.com/
  987. * @author kile / http://kile.stravaganza.org/
  988. * @author philogb / http://blog.thejit.org/
  989. * @author mikael emtinger / http://gomo.se/
  990. * @author egraether / http://egraether.com/
  991. * @author WestLangley / http://github.com/WestLangley
  992. */
  993. var _vector, _quaternion;
  994. function Vector3( x, y, z ) {
  995. this.x = x || 0;
  996. this.y = y || 0;
  997. this.z = z || 0;
  998. }
  999. Object.assign( Vector3.prototype, {
  1000. isVector3: true,
  1001. set: function ( x, y, z ) {
  1002. this.x = x;
  1003. this.y = y;
  1004. this.z = z;
  1005. return this;
  1006. },
  1007. setScalar: function ( scalar ) {
  1008. this.x = scalar;
  1009. this.y = scalar;
  1010. this.z = scalar;
  1011. return this;
  1012. },
  1013. setX: function ( x ) {
  1014. this.x = x;
  1015. return this;
  1016. },
  1017. setY: function ( y ) {
  1018. this.y = y;
  1019. return this;
  1020. },
  1021. setZ: function ( z ) {
  1022. this.z = z;
  1023. return this;
  1024. },
  1025. setComponent: function ( index, value ) {
  1026. switch ( index ) {
  1027. case 0: this.x = value; break;
  1028. case 1: this.y = value; break;
  1029. case 2: this.z = value; break;
  1030. default: throw new Error( 'index is out of range: ' + index );
  1031. }
  1032. return this;
  1033. },
  1034. getComponent: function ( index ) {
  1035. switch ( index ) {
  1036. case 0: return this.x;
  1037. case 1: return this.y;
  1038. case 2: return this.z;
  1039. default: throw new Error( 'index is out of range: ' + index );
  1040. }
  1041. },
  1042. clone: function () {
  1043. return new this.constructor( this.x, this.y, this.z );
  1044. },
  1045. copy: function ( v ) {
  1046. this.x = v.x;
  1047. this.y = v.y;
  1048. this.z = v.z;
  1049. return this;
  1050. },
  1051. add: function ( v, w ) {
  1052. if ( w !== undefined ) {
  1053. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1054. return this.addVectors( v, w );
  1055. }
  1056. this.x += v.x;
  1057. this.y += v.y;
  1058. this.z += v.z;
  1059. return this;
  1060. },
  1061. addScalar: function ( s ) {
  1062. this.x += s;
  1063. this.y += s;
  1064. this.z += s;
  1065. return this;
  1066. },
  1067. addVectors: function ( a, b ) {
  1068. this.x = a.x + b.x;
  1069. this.y = a.y + b.y;
  1070. this.z = a.z + b.z;
  1071. return this;
  1072. },
  1073. addScaledVector: function ( v, s ) {
  1074. this.x += v.x * s;
  1075. this.y += v.y * s;
  1076. this.z += v.z * s;
  1077. return this;
  1078. },
  1079. sub: function ( v, w ) {
  1080. if ( w !== undefined ) {
  1081. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1082. return this.subVectors( v, w );
  1083. }
  1084. this.x -= v.x;
  1085. this.y -= v.y;
  1086. this.z -= v.z;
  1087. return this;
  1088. },
  1089. subScalar: function ( s ) {
  1090. this.x -= s;
  1091. this.y -= s;
  1092. this.z -= s;
  1093. return this;
  1094. },
  1095. subVectors: function ( a, b ) {
  1096. this.x = a.x - b.x;
  1097. this.y = a.y - b.y;
  1098. this.z = a.z - b.z;
  1099. return this;
  1100. },
  1101. multiply: function ( v, w ) {
  1102. if ( w !== undefined ) {
  1103. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1104. return this.multiplyVectors( v, w );
  1105. }
  1106. this.x *= v.x;
  1107. this.y *= v.y;
  1108. this.z *= v.z;
  1109. return this;
  1110. },
  1111. multiplyScalar: function ( scalar ) {
  1112. this.x *= scalar;
  1113. this.y *= scalar;
  1114. this.z *= scalar;
  1115. return this;
  1116. },
  1117. multiplyVectors: function ( a, b ) {
  1118. this.x = a.x * b.x;
  1119. this.y = a.y * b.y;
  1120. this.z = a.z * b.z;
  1121. return this;
  1122. },
  1123. applyEuler: function ( euler ) {
  1124. if ( _quaternion === undefined ) _quaternion = new Quaternion();
  1125. if ( ! ( euler && euler.isEuler ) ) {
  1126. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1127. }
  1128. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  1129. },
  1130. applyAxisAngle: function ( axis, angle ) {
  1131. if ( _quaternion === undefined ) _quaternion = new Quaternion();
  1132. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  1133. },
  1134. applyMatrix3: function ( m ) {
  1135. var x = this.x, y = this.y, z = this.z;
  1136. var e = m.elements;
  1137. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1138. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1139. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1140. return this;
  1141. },
  1142. applyMatrix4: function ( m ) {
  1143. var x = this.x, y = this.y, z = this.z;
  1144. var e = m.elements;
  1145. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1146. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1147. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1148. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1149. return this;
  1150. },
  1151. applyQuaternion: function ( q ) {
  1152. var x = this.x, y = this.y, z = this.z;
  1153. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1154. // calculate quat * vector
  1155. var ix = qw * x + qy * z - qz * y;
  1156. var iy = qw * y + qz * x - qx * z;
  1157. var iz = qw * z + qx * y - qy * x;
  1158. var iw = - qx * x - qy * y - qz * z;
  1159. // calculate result * inverse quat
  1160. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1161. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1162. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1163. return this;
  1164. },
  1165. project: function ( camera ) {
  1166. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1167. },
  1168. unproject: function ( camera ) {
  1169. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1170. },
  1171. transformDirection: function ( m ) {
  1172. // input: THREE.Matrix4 affine matrix
  1173. // vector interpreted as a direction
  1174. var x = this.x, y = this.y, z = this.z;
  1175. var e = m.elements;
  1176. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1177. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1178. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1179. return this.normalize();
  1180. },
  1181. divide: function ( v ) {
  1182. this.x /= v.x;
  1183. this.y /= v.y;
  1184. this.z /= v.z;
  1185. return this;
  1186. },
  1187. divideScalar: function ( scalar ) {
  1188. return this.multiplyScalar( 1 / scalar );
  1189. },
  1190. min: function ( v ) {
  1191. this.x = Math.min( this.x, v.x );
  1192. this.y = Math.min( this.y, v.y );
  1193. this.z = Math.min( this.z, v.z );
  1194. return this;
  1195. },
  1196. max: function ( v ) {
  1197. this.x = Math.max( this.x, v.x );
  1198. this.y = Math.max( this.y, v.y );
  1199. this.z = Math.max( this.z, v.z );
  1200. return this;
  1201. },
  1202. clamp: function ( min, max ) {
  1203. // assumes min < max, componentwise
  1204. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1205. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1206. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1207. return this;
  1208. },
  1209. clampScalar: function ( minVal, maxVal ) {
  1210. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1211. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1212. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1213. return this;
  1214. },
  1215. clampLength: function ( min, max ) {
  1216. var length = this.length();
  1217. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1218. },
  1219. floor: function () {
  1220. this.x = Math.floor( this.x );
  1221. this.y = Math.floor( this.y );
  1222. this.z = Math.floor( this.z );
  1223. return this;
  1224. },
  1225. ceil: function () {
  1226. this.x = Math.ceil( this.x );
  1227. this.y = Math.ceil( this.y );
  1228. this.z = Math.ceil( this.z );
  1229. return this;
  1230. },
  1231. round: function () {
  1232. this.x = Math.round( this.x );
  1233. this.y = Math.round( this.y );
  1234. this.z = Math.round( this.z );
  1235. return this;
  1236. },
  1237. roundToZero: function () {
  1238. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1239. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1240. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1241. return this;
  1242. },
  1243. negate: function () {
  1244. this.x = - this.x;
  1245. this.y = - this.y;
  1246. this.z = - this.z;
  1247. return this;
  1248. },
  1249. dot: function ( v ) {
  1250. return this.x * v.x + this.y * v.y + this.z * v.z;
  1251. },
  1252. // TODO lengthSquared?
  1253. lengthSq: function () {
  1254. return this.x * this.x + this.y * this.y + this.z * this.z;
  1255. },
  1256. length: function () {
  1257. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1258. },
  1259. manhattanLength: function () {
  1260. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1261. },
  1262. normalize: function () {
  1263. return this.divideScalar( this.length() || 1 );
  1264. },
  1265. setLength: function ( length ) {
  1266. return this.normalize().multiplyScalar( length );
  1267. },
  1268. lerp: function ( v, alpha ) {
  1269. this.x += ( v.x - this.x ) * alpha;
  1270. this.y += ( v.y - this.y ) * alpha;
  1271. this.z += ( v.z - this.z ) * alpha;
  1272. return this;
  1273. },
  1274. lerpVectors: function ( v1, v2, alpha ) {
  1275. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1276. },
  1277. cross: function ( v, w ) {
  1278. if ( w !== undefined ) {
  1279. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1280. return this.crossVectors( v, w );
  1281. }
  1282. return this.crossVectors( this, v );
  1283. },
  1284. crossVectors: function ( a, b ) {
  1285. var ax = a.x, ay = a.y, az = a.z;
  1286. var bx = b.x, by = b.y, bz = b.z;
  1287. this.x = ay * bz - az * by;
  1288. this.y = az * bx - ax * bz;
  1289. this.z = ax * by - ay * bx;
  1290. return this;
  1291. },
  1292. projectOnVector: function ( vector ) {
  1293. var scalar = vector.dot( this ) / vector.lengthSq();
  1294. return this.copy( vector ).multiplyScalar( scalar );
  1295. },
  1296. projectOnPlane: function ( planeNormal ) {
  1297. if ( _vector === undefined ) _vector = new Vector3();
  1298. _vector.copy( this ).projectOnVector( planeNormal );
  1299. return this.sub( _vector );
  1300. },
  1301. reflect: function ( normal ) {
  1302. if ( _vector === undefined ) _vector = new Vector3();
  1303. // reflect incident vector off plane orthogonal to normal
  1304. // normal is assumed to have unit length
  1305. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1306. },
  1307. angleTo: function ( v ) {
  1308. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1309. // clamp, to handle numerical problems
  1310. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1311. },
  1312. distanceTo: function ( v ) {
  1313. return Math.sqrt( this.distanceToSquared( v ) );
  1314. },
  1315. distanceToSquared: function ( v ) {
  1316. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1317. return dx * dx + dy * dy + dz * dz;
  1318. },
  1319. manhattanDistanceTo: function ( v ) {
  1320. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1321. },
  1322. setFromSpherical: function ( s ) {
  1323. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1324. },
  1325. setFromSphericalCoords: function ( radius, phi, theta ) {
  1326. var sinPhiRadius = Math.sin( phi ) * radius;
  1327. this.x = sinPhiRadius * Math.sin( theta );
  1328. this.y = Math.cos( phi ) * radius;
  1329. this.z = sinPhiRadius * Math.cos( theta );
  1330. return this;
  1331. },
  1332. setFromCylindrical: function ( c ) {
  1333. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1334. },
  1335. setFromCylindricalCoords: function ( radius, theta, y ) {
  1336. this.x = radius * Math.sin( theta );
  1337. this.y = y;
  1338. this.z = radius * Math.cos( theta );
  1339. return this;
  1340. },
  1341. setFromMatrixPosition: function ( m ) {
  1342. var e = m.elements;
  1343. this.x = e[ 12 ];
  1344. this.y = e[ 13 ];
  1345. this.z = e[ 14 ];
  1346. return this;
  1347. },
  1348. setFromMatrixScale: function ( m ) {
  1349. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1350. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1351. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1352. this.x = sx;
  1353. this.y = sy;
  1354. this.z = sz;
  1355. return this;
  1356. },
  1357. setFromMatrixColumn: function ( m, index ) {
  1358. return this.fromArray( m.elements, index * 4 );
  1359. },
  1360. equals: function ( v ) {
  1361. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1362. },
  1363. fromArray: function ( array, offset ) {
  1364. if ( offset === undefined ) offset = 0;
  1365. this.x = array[ offset ];
  1366. this.y = array[ offset + 1 ];
  1367. this.z = array[ offset + 2 ];
  1368. return this;
  1369. },
  1370. toArray: function ( array, offset ) {
  1371. if ( array === undefined ) array = [];
  1372. if ( offset === undefined ) offset = 0;
  1373. array[ offset ] = this.x;
  1374. array[ offset + 1 ] = this.y;
  1375. array[ offset + 2 ] = this.z;
  1376. return array;
  1377. },
  1378. fromBufferAttribute: function ( attribute, index, offset ) {
  1379. if ( offset !== undefined ) {
  1380. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1381. }
  1382. this.x = attribute.getX( index );
  1383. this.y = attribute.getY( index );
  1384. this.z = attribute.getZ( index );
  1385. return this;
  1386. }
  1387. } );
  1388. /**
  1389. * @author alteredq / http://alteredqualia.com/
  1390. * @author WestLangley / http://github.com/WestLangley
  1391. * @author bhouston / http://clara.io
  1392. * @author tschw
  1393. */
  1394. var _vector$1;
  1395. function Matrix3() {
  1396. this.elements = [
  1397. 1, 0, 0,
  1398. 0, 1, 0,
  1399. 0, 0, 1
  1400. ];
  1401. if ( arguments.length > 0 ) {
  1402. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1403. }
  1404. }
  1405. Object.assign( Matrix3.prototype, {
  1406. isMatrix3: true,
  1407. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1408. var te = this.elements;
  1409. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1410. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1411. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1412. return this;
  1413. },
  1414. identity: function () {
  1415. this.set(
  1416. 1, 0, 0,
  1417. 0, 1, 0,
  1418. 0, 0, 1
  1419. );
  1420. return this;
  1421. },
  1422. clone: function () {
  1423. return new this.constructor().fromArray( this.elements );
  1424. },
  1425. copy: function ( m ) {
  1426. var te = this.elements;
  1427. var me = m.elements;
  1428. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1429. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1430. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1431. return this;
  1432. },
  1433. setFromMatrix4: function ( m ) {
  1434. var me = m.elements;
  1435. this.set(
  1436. me[ 0 ], me[ 4 ], me[ 8 ],
  1437. me[ 1 ], me[ 5 ], me[ 9 ],
  1438. me[ 2 ], me[ 6 ], me[ 10 ]
  1439. );
  1440. return this;
  1441. },
  1442. applyToBufferAttribute: function ( attribute ) {
  1443. if ( _vector$1 === undefined ) _vector$1 = new Vector3();
  1444. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1445. _vector$1.x = attribute.getX( i );
  1446. _vector$1.y = attribute.getY( i );
  1447. _vector$1.z = attribute.getZ( i );
  1448. _vector$1.applyMatrix3( this );
  1449. attribute.setXYZ( i, _vector$1.x, _vector$1.y, _vector$1.z );
  1450. }
  1451. return attribute;
  1452. },
  1453. multiply: function ( m ) {
  1454. return this.multiplyMatrices( this, m );
  1455. },
  1456. premultiply: function ( m ) {
  1457. return this.multiplyMatrices( m, this );
  1458. },
  1459. multiplyMatrices: function ( a, b ) {
  1460. var ae = a.elements;
  1461. var be = b.elements;
  1462. var te = this.elements;
  1463. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1464. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1465. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1466. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1467. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1468. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1469. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1470. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1471. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1472. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1473. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1474. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1475. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1476. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1477. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1478. return this;
  1479. },
  1480. multiplyScalar: function ( s ) {
  1481. var te = this.elements;
  1482. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1483. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1484. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1485. return this;
  1486. },
  1487. determinant: function () {
  1488. var te = this.elements;
  1489. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1490. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1491. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1492. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1493. },
  1494. getInverse: function ( matrix, throwOnDegenerate ) {
  1495. if ( matrix && matrix.isMatrix4 ) {
  1496. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1497. }
  1498. var me = matrix.elements,
  1499. te = this.elements,
  1500. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1501. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1502. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1503. t11 = n33 * n22 - n32 * n23,
  1504. t12 = n32 * n13 - n33 * n12,
  1505. t13 = n23 * n12 - n22 * n13,
  1506. det = n11 * t11 + n21 * t12 + n31 * t13;
  1507. if ( det === 0 ) {
  1508. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1509. if ( throwOnDegenerate === true ) {
  1510. throw new Error( msg );
  1511. } else {
  1512. console.warn( msg );
  1513. }
  1514. return this.identity();
  1515. }
  1516. var detInv = 1 / det;
  1517. te[ 0 ] = t11 * detInv;
  1518. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1519. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1520. te[ 3 ] = t12 * detInv;
  1521. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1522. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1523. te[ 6 ] = t13 * detInv;
  1524. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1525. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1526. return this;
  1527. },
  1528. transpose: function () {
  1529. var tmp, m = this.elements;
  1530. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1531. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1532. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1533. return this;
  1534. },
  1535. getNormalMatrix: function ( matrix4 ) {
  1536. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1537. },
  1538. transposeIntoArray: function ( r ) {
  1539. var m = this.elements;
  1540. r[ 0 ] = m[ 0 ];
  1541. r[ 1 ] = m[ 3 ];
  1542. r[ 2 ] = m[ 6 ];
  1543. r[ 3 ] = m[ 1 ];
  1544. r[ 4 ] = m[ 4 ];
  1545. r[ 5 ] = m[ 7 ];
  1546. r[ 6 ] = m[ 2 ];
  1547. r[ 7 ] = m[ 5 ];
  1548. r[ 8 ] = m[ 8 ];
  1549. return this;
  1550. },
  1551. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1552. var c = Math.cos( rotation );
  1553. var s = Math.sin( rotation );
  1554. this.set(
  1555. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1556. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1557. 0, 0, 1
  1558. );
  1559. },
  1560. scale: function ( sx, sy ) {
  1561. var te = this.elements;
  1562. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1563. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1564. return this;
  1565. },
  1566. rotate: function ( theta ) {
  1567. var c = Math.cos( theta );
  1568. var s = Math.sin( theta );
  1569. var te = this.elements;
  1570. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1571. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1572. te[ 0 ] = c * a11 + s * a21;
  1573. te[ 3 ] = c * a12 + s * a22;
  1574. te[ 6 ] = c * a13 + s * a23;
  1575. te[ 1 ] = - s * a11 + c * a21;
  1576. te[ 4 ] = - s * a12 + c * a22;
  1577. te[ 7 ] = - s * a13 + c * a23;
  1578. return this;
  1579. },
  1580. translate: function ( tx, ty ) {
  1581. var te = this.elements;
  1582. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1583. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1584. return this;
  1585. },
  1586. equals: function ( matrix ) {
  1587. var te = this.elements;
  1588. var me = matrix.elements;
  1589. for ( var i = 0; i < 9; i ++ ) {
  1590. if ( te[ i ] !== me[ i ] ) return false;
  1591. }
  1592. return true;
  1593. },
  1594. fromArray: function ( array, offset ) {
  1595. if ( offset === undefined ) offset = 0;
  1596. for ( var i = 0; i < 9; i ++ ) {
  1597. this.elements[ i ] = array[ i + offset ];
  1598. }
  1599. return this;
  1600. },
  1601. toArray: function ( array, offset ) {
  1602. if ( array === undefined ) array = [];
  1603. if ( offset === undefined ) offset = 0;
  1604. var te = this.elements;
  1605. array[ offset ] = te[ 0 ];
  1606. array[ offset + 1 ] = te[ 1 ];
  1607. array[ offset + 2 ] = te[ 2 ];
  1608. array[ offset + 3 ] = te[ 3 ];
  1609. array[ offset + 4 ] = te[ 4 ];
  1610. array[ offset + 5 ] = te[ 5 ];
  1611. array[ offset + 6 ] = te[ 6 ];
  1612. array[ offset + 7 ] = te[ 7 ];
  1613. array[ offset + 8 ] = te[ 8 ];
  1614. return array;
  1615. }
  1616. } );
  1617. /**
  1618. * @author mrdoob / http://mrdoob.com/
  1619. * @author alteredq / http://alteredqualia.com/
  1620. * @author szimek / https://github.com/szimek/
  1621. */
  1622. var _canvas;
  1623. var ImageUtils = {
  1624. getDataURL: function ( image ) {
  1625. var canvas;
  1626. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1627. return image.src;
  1628. } else if ( image instanceof HTMLCanvasElement ) {
  1629. canvas = image;
  1630. } else {
  1631. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1632. _canvas.width = image.width;
  1633. _canvas.height = image.height;
  1634. var context = _canvas.getContext( '2d' );
  1635. if ( image instanceof ImageData ) {
  1636. context.putImageData( image, 0, 0 );
  1637. } else {
  1638. context.drawImage( image, 0, 0, image.width, image.height );
  1639. }
  1640. canvas = _canvas;
  1641. }
  1642. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1643. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1644. } else {
  1645. return canvas.toDataURL( 'image/png' );
  1646. }
  1647. }
  1648. };
  1649. /**
  1650. * @author mrdoob / http://mrdoob.com/
  1651. * @author alteredq / http://alteredqualia.com/
  1652. * @author szimek / https://github.com/szimek/
  1653. */
  1654. var textureId = 0;
  1655. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1656. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1657. this.uuid = _Math.generateUUID();
  1658. this.name = '';
  1659. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1660. this.mipmaps = [];
  1661. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1662. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1663. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1664. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1665. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1666. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1667. this.format = format !== undefined ? format : RGBAFormat;
  1668. this.type = type !== undefined ? type : UnsignedByteType;
  1669. this.offset = new Vector2( 0, 0 );
  1670. this.repeat = new Vector2( 1, 1 );
  1671. this.center = new Vector2( 0, 0 );
  1672. this.rotation = 0;
  1673. this.matrixAutoUpdate = true;
  1674. this.matrix = new Matrix3();
  1675. this.generateMipmaps = true;
  1676. this.premultiplyAlpha = false;
  1677. this.flipY = true;
  1678. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1679. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1680. //
  1681. // Also changing the encoding after already used by a Material will not automatically make the Material
  1682. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1683. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1684. this.version = 0;
  1685. this.onUpdate = null;
  1686. }
  1687. Texture.DEFAULT_IMAGE = undefined;
  1688. Texture.DEFAULT_MAPPING = UVMapping;
  1689. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1690. constructor: Texture,
  1691. isTexture: true,
  1692. updateMatrix: function () {
  1693. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1694. },
  1695. clone: function () {
  1696. return new this.constructor().copy( this );
  1697. },
  1698. copy: function ( source ) {
  1699. this.name = source.name;
  1700. this.image = source.image;
  1701. this.mipmaps = source.mipmaps.slice( 0 );
  1702. this.mapping = source.mapping;
  1703. this.wrapS = source.wrapS;
  1704. this.wrapT = source.wrapT;
  1705. this.magFilter = source.magFilter;
  1706. this.minFilter = source.minFilter;
  1707. this.anisotropy = source.anisotropy;
  1708. this.format = source.format;
  1709. this.type = source.type;
  1710. this.offset.copy( source.offset );
  1711. this.repeat.copy( source.repeat );
  1712. this.center.copy( source.center );
  1713. this.rotation = source.rotation;
  1714. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1715. this.matrix.copy( source.matrix );
  1716. this.generateMipmaps = source.generateMipmaps;
  1717. this.premultiplyAlpha = source.premultiplyAlpha;
  1718. this.flipY = source.flipY;
  1719. this.unpackAlignment = source.unpackAlignment;
  1720. this.encoding = source.encoding;
  1721. return this;
  1722. },
  1723. toJSON: function ( meta ) {
  1724. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1725. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1726. return meta.textures[ this.uuid ];
  1727. }
  1728. var output = {
  1729. metadata: {
  1730. version: 4.5,
  1731. type: 'Texture',
  1732. generator: 'Texture.toJSON'
  1733. },
  1734. uuid: this.uuid,
  1735. name: this.name,
  1736. mapping: this.mapping,
  1737. repeat: [ this.repeat.x, this.repeat.y ],
  1738. offset: [ this.offset.x, this.offset.y ],
  1739. center: [ this.center.x, this.center.y ],
  1740. rotation: this.rotation,
  1741. wrap: [ this.wrapS, this.wrapT ],
  1742. format: this.format,
  1743. type: this.type,
  1744. encoding: this.encoding,
  1745. minFilter: this.minFilter,
  1746. magFilter: this.magFilter,
  1747. anisotropy: this.anisotropy,
  1748. flipY: this.flipY,
  1749. premultiplyAlpha: this.premultiplyAlpha,
  1750. unpackAlignment: this.unpackAlignment
  1751. };
  1752. if ( this.image !== undefined ) {
  1753. // TODO: Move to THREE.Image
  1754. var image = this.image;
  1755. if ( image.uuid === undefined ) {
  1756. image.uuid = _Math.generateUUID(); // UGH
  1757. }
  1758. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1759. var url;
  1760. if ( Array.isArray( image ) ) {
  1761. // process array of images e.g. CubeTexture
  1762. url = [];
  1763. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1764. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1765. }
  1766. } else {
  1767. // process single image
  1768. url = ImageUtils.getDataURL( image );
  1769. }
  1770. meta.images[ image.uuid ] = {
  1771. uuid: image.uuid,
  1772. url: url
  1773. };
  1774. }
  1775. output.image = image.uuid;
  1776. }
  1777. if ( ! isRootObject ) {
  1778. meta.textures[ this.uuid ] = output;
  1779. }
  1780. return output;
  1781. },
  1782. dispose: function () {
  1783. this.dispatchEvent( { type: 'dispose' } );
  1784. },
  1785. transformUv: function ( uv ) {
  1786. if ( this.mapping !== UVMapping ) return uv;
  1787. uv.applyMatrix3( this.matrix );
  1788. if ( uv.x < 0 || uv.x > 1 ) {
  1789. switch ( this.wrapS ) {
  1790. case RepeatWrapping:
  1791. uv.x = uv.x - Math.floor( uv.x );
  1792. break;
  1793. case ClampToEdgeWrapping:
  1794. uv.x = uv.x < 0 ? 0 : 1;
  1795. break;
  1796. case MirroredRepeatWrapping:
  1797. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1798. uv.x = Math.ceil( uv.x ) - uv.x;
  1799. } else {
  1800. uv.x = uv.x - Math.floor( uv.x );
  1801. }
  1802. break;
  1803. }
  1804. }
  1805. if ( uv.y < 0 || uv.y > 1 ) {
  1806. switch ( this.wrapT ) {
  1807. case RepeatWrapping:
  1808. uv.y = uv.y - Math.floor( uv.y );
  1809. break;
  1810. case ClampToEdgeWrapping:
  1811. uv.y = uv.y < 0 ? 0 : 1;
  1812. break;
  1813. case MirroredRepeatWrapping:
  1814. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1815. uv.y = Math.ceil( uv.y ) - uv.y;
  1816. } else {
  1817. uv.y = uv.y - Math.floor( uv.y );
  1818. }
  1819. break;
  1820. }
  1821. }
  1822. if ( this.flipY ) {
  1823. uv.y = 1 - uv.y;
  1824. }
  1825. return uv;
  1826. }
  1827. } );
  1828. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1829. set: function ( value ) {
  1830. if ( value === true ) this.version ++;
  1831. }
  1832. } );
  1833. /**
  1834. * @author supereggbert / http://www.paulbrunt.co.uk/
  1835. * @author philogb / http://blog.thejit.org/
  1836. * @author mikael emtinger / http://gomo.se/
  1837. * @author egraether / http://egraether.com/
  1838. * @author WestLangley / http://github.com/WestLangley
  1839. */
  1840. function Vector4( x, y, z, w ) {
  1841. this.x = x || 0;
  1842. this.y = y || 0;
  1843. this.z = z || 0;
  1844. this.w = ( w !== undefined ) ? w : 1;
  1845. }
  1846. Object.defineProperties( Vector4.prototype, {
  1847. "width": {
  1848. get: function () {
  1849. return this.z;
  1850. },
  1851. set: function ( value ) {
  1852. this.z = value;
  1853. }
  1854. },
  1855. "height": {
  1856. get: function () {
  1857. return this.w;
  1858. },
  1859. set: function ( value ) {
  1860. this.w = value;
  1861. }
  1862. }
  1863. } );
  1864. Object.assign( Vector4.prototype, {
  1865. isVector4: true,
  1866. set: function ( x, y, z, w ) {
  1867. this.x = x;
  1868. this.y = y;
  1869. this.z = z;
  1870. this.w = w;
  1871. return this;
  1872. },
  1873. setScalar: function ( scalar ) {
  1874. this.x = scalar;
  1875. this.y = scalar;
  1876. this.z = scalar;
  1877. this.w = scalar;
  1878. return this;
  1879. },
  1880. setX: function ( x ) {
  1881. this.x = x;
  1882. return this;
  1883. },
  1884. setY: function ( y ) {
  1885. this.y = y;
  1886. return this;
  1887. },
  1888. setZ: function ( z ) {
  1889. this.z = z;
  1890. return this;
  1891. },
  1892. setW: function ( w ) {
  1893. this.w = w;
  1894. return this;
  1895. },
  1896. setComponent: function ( index, value ) {
  1897. switch ( index ) {
  1898. case 0: this.x = value; break;
  1899. case 1: this.y = value; break;
  1900. case 2: this.z = value; break;
  1901. case 3: this.w = value; break;
  1902. default: throw new Error( 'index is out of range: ' + index );
  1903. }
  1904. return this;
  1905. },
  1906. getComponent: function ( index ) {
  1907. switch ( index ) {
  1908. case 0: return this.x;
  1909. case 1: return this.y;
  1910. case 2: return this.z;
  1911. case 3: return this.w;
  1912. default: throw new Error( 'index is out of range: ' + index );
  1913. }
  1914. },
  1915. clone: function () {
  1916. return new this.constructor( this.x, this.y, this.z, this.w );
  1917. },
  1918. copy: function ( v ) {
  1919. this.x = v.x;
  1920. this.y = v.y;
  1921. this.z = v.z;
  1922. this.w = ( v.w !== undefined ) ? v.w : 1;
  1923. return this;
  1924. },
  1925. add: function ( v, w ) {
  1926. if ( w !== undefined ) {
  1927. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1928. return this.addVectors( v, w );
  1929. }
  1930. this.x += v.x;
  1931. this.y += v.y;
  1932. this.z += v.z;
  1933. this.w += v.w;
  1934. return this;
  1935. },
  1936. addScalar: function ( s ) {
  1937. this.x += s;
  1938. this.y += s;
  1939. this.z += s;
  1940. this.w += s;
  1941. return this;
  1942. },
  1943. addVectors: function ( a, b ) {
  1944. this.x = a.x + b.x;
  1945. this.y = a.y + b.y;
  1946. this.z = a.z + b.z;
  1947. this.w = a.w + b.w;
  1948. return this;
  1949. },
  1950. addScaledVector: function ( v, s ) {
  1951. this.x += v.x * s;
  1952. this.y += v.y * s;
  1953. this.z += v.z * s;
  1954. this.w += v.w * s;
  1955. return this;
  1956. },
  1957. sub: function ( v, w ) {
  1958. if ( w !== undefined ) {
  1959. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1960. return this.subVectors( v, w );
  1961. }
  1962. this.x -= v.x;
  1963. this.y -= v.y;
  1964. this.z -= v.z;
  1965. this.w -= v.w;
  1966. return this;
  1967. },
  1968. subScalar: function ( s ) {
  1969. this.x -= s;
  1970. this.y -= s;
  1971. this.z -= s;
  1972. this.w -= s;
  1973. return this;
  1974. },
  1975. subVectors: function ( a, b ) {
  1976. this.x = a.x - b.x;
  1977. this.y = a.y - b.y;
  1978. this.z = a.z - b.z;
  1979. this.w = a.w - b.w;
  1980. return this;
  1981. },
  1982. multiplyScalar: function ( scalar ) {
  1983. this.x *= scalar;
  1984. this.y *= scalar;
  1985. this.z *= scalar;
  1986. this.w *= scalar;
  1987. return this;
  1988. },
  1989. applyMatrix4: function ( m ) {
  1990. var x = this.x, y = this.y, z = this.z, w = this.w;
  1991. var e = m.elements;
  1992. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1993. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1994. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1995. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1996. return this;
  1997. },
  1998. divideScalar: function ( scalar ) {
  1999. return this.multiplyScalar( 1 / scalar );
  2000. },
  2001. setAxisAngleFromQuaternion: function ( q ) {
  2002. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2003. // q is assumed to be normalized
  2004. this.w = 2 * Math.acos( q.w );
  2005. var s = Math.sqrt( 1 - q.w * q.w );
  2006. if ( s < 0.0001 ) {
  2007. this.x = 1;
  2008. this.y = 0;
  2009. this.z = 0;
  2010. } else {
  2011. this.x = q.x / s;
  2012. this.y = q.y / s;
  2013. this.z = q.z / s;
  2014. }
  2015. return this;
  2016. },
  2017. setAxisAngleFromRotationMatrix: function ( m ) {
  2018. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2019. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2020. var angle, x, y, z, // variables for result
  2021. epsilon = 0.01, // margin to allow for rounding errors
  2022. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2023. te = m.elements,
  2024. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2025. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2026. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2027. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2028. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2029. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2030. // singularity found
  2031. // first check for identity matrix which must have +1 for all terms
  2032. // in leading diagonal and zero in other terms
  2033. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2034. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2035. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2036. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2037. // this singularity is identity matrix so angle = 0
  2038. this.set( 1, 0, 0, 0 );
  2039. return this; // zero angle, arbitrary axis
  2040. }
  2041. // otherwise this singularity is angle = 180
  2042. angle = Math.PI;
  2043. var xx = ( m11 + 1 ) / 2;
  2044. var yy = ( m22 + 1 ) / 2;
  2045. var zz = ( m33 + 1 ) / 2;
  2046. var xy = ( m12 + m21 ) / 4;
  2047. var xz = ( m13 + m31 ) / 4;
  2048. var yz = ( m23 + m32 ) / 4;
  2049. if ( ( xx > yy ) && ( xx > zz ) ) {
  2050. // m11 is the largest diagonal term
  2051. if ( xx < epsilon ) {
  2052. x = 0;
  2053. y = 0.707106781;
  2054. z = 0.707106781;
  2055. } else {
  2056. x = Math.sqrt( xx );
  2057. y = xy / x;
  2058. z = xz / x;
  2059. }
  2060. } else if ( yy > zz ) {
  2061. // m22 is the largest diagonal term
  2062. if ( yy < epsilon ) {
  2063. x = 0.707106781;
  2064. y = 0;
  2065. z = 0.707106781;
  2066. } else {
  2067. y = Math.sqrt( yy );
  2068. x = xy / y;
  2069. z = yz / y;
  2070. }
  2071. } else {
  2072. // m33 is the largest diagonal term so base result on this
  2073. if ( zz < epsilon ) {
  2074. x = 0.707106781;
  2075. y = 0.707106781;
  2076. z = 0;
  2077. } else {
  2078. z = Math.sqrt( zz );
  2079. x = xz / z;
  2080. y = yz / z;
  2081. }
  2082. }
  2083. this.set( x, y, z, angle );
  2084. return this; // return 180 deg rotation
  2085. }
  2086. // as we have reached here there are no singularities so we can handle normally
  2087. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2088. ( m13 - m31 ) * ( m13 - m31 ) +
  2089. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2090. if ( Math.abs( s ) < 0.001 ) s = 1;
  2091. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2092. // caught by singularity test above, but I've left it in just in case
  2093. this.x = ( m32 - m23 ) / s;
  2094. this.y = ( m13 - m31 ) / s;
  2095. this.z = ( m21 - m12 ) / s;
  2096. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2097. return this;
  2098. },
  2099. min: function ( v ) {
  2100. this.x = Math.min( this.x, v.x );
  2101. this.y = Math.min( this.y, v.y );
  2102. this.z = Math.min( this.z, v.z );
  2103. this.w = Math.min( this.w, v.w );
  2104. return this;
  2105. },
  2106. max: function ( v ) {
  2107. this.x = Math.max( this.x, v.x );
  2108. this.y = Math.max( this.y, v.y );
  2109. this.z = Math.max( this.z, v.z );
  2110. this.w = Math.max( this.w, v.w );
  2111. return this;
  2112. },
  2113. clamp: function ( min, max ) {
  2114. // assumes min < max, componentwise
  2115. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2116. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2117. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2118. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2119. return this;
  2120. },
  2121. clampScalar: function ( minVal, maxVal ) {
  2122. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2123. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2124. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2125. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  2126. return this;
  2127. },
  2128. clampLength: function ( min, max ) {
  2129. var length = this.length();
  2130. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2131. },
  2132. floor: function () {
  2133. this.x = Math.floor( this.x );
  2134. this.y = Math.floor( this.y );
  2135. this.z = Math.floor( this.z );
  2136. this.w = Math.floor( this.w );
  2137. return this;
  2138. },
  2139. ceil: function () {
  2140. this.x = Math.ceil( this.x );
  2141. this.y = Math.ceil( this.y );
  2142. this.z = Math.ceil( this.z );
  2143. this.w = Math.ceil( this.w );
  2144. return this;
  2145. },
  2146. round: function () {
  2147. this.x = Math.round( this.x );
  2148. this.y = Math.round( this.y );
  2149. this.z = Math.round( this.z );
  2150. this.w = Math.round( this.w );
  2151. return this;
  2152. },
  2153. roundToZero: function () {
  2154. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2155. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2156. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2157. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2158. return this;
  2159. },
  2160. negate: function () {
  2161. this.x = - this.x;
  2162. this.y = - this.y;
  2163. this.z = - this.z;
  2164. this.w = - this.w;
  2165. return this;
  2166. },
  2167. dot: function ( v ) {
  2168. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2169. },
  2170. lengthSq: function () {
  2171. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2172. },
  2173. length: function () {
  2174. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2175. },
  2176. manhattanLength: function () {
  2177. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2178. },
  2179. normalize: function () {
  2180. return this.divideScalar( this.length() || 1 );
  2181. },
  2182. setLength: function ( length ) {
  2183. return this.normalize().multiplyScalar( length );
  2184. },
  2185. lerp: function ( v, alpha ) {
  2186. this.x += ( v.x - this.x ) * alpha;
  2187. this.y += ( v.y - this.y ) * alpha;
  2188. this.z += ( v.z - this.z ) * alpha;
  2189. this.w += ( v.w - this.w ) * alpha;
  2190. return this;
  2191. },
  2192. lerpVectors: function ( v1, v2, alpha ) {
  2193. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2194. },
  2195. equals: function ( v ) {
  2196. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2197. },
  2198. fromArray: function ( array, offset ) {
  2199. if ( offset === undefined ) offset = 0;
  2200. this.x = array[ offset ];
  2201. this.y = array[ offset + 1 ];
  2202. this.z = array[ offset + 2 ];
  2203. this.w = array[ offset + 3 ];
  2204. return this;
  2205. },
  2206. toArray: function ( array, offset ) {
  2207. if ( array === undefined ) array = [];
  2208. if ( offset === undefined ) offset = 0;
  2209. array[ offset ] = this.x;
  2210. array[ offset + 1 ] = this.y;
  2211. array[ offset + 2 ] = this.z;
  2212. array[ offset + 3 ] = this.w;
  2213. return array;
  2214. },
  2215. fromBufferAttribute: function ( attribute, index, offset ) {
  2216. if ( offset !== undefined ) {
  2217. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2218. }
  2219. this.x = attribute.getX( index );
  2220. this.y = attribute.getY( index );
  2221. this.z = attribute.getZ( index );
  2222. this.w = attribute.getW( index );
  2223. return this;
  2224. }
  2225. } );
  2226. /**
  2227. * @author szimek / https://github.com/szimek/
  2228. * @author alteredq / http://alteredqualia.com/
  2229. * @author Marius Kintel / https://github.com/kintel
  2230. */
  2231. /*
  2232. In options, we can specify:
  2233. * Texture parameters for an auto-generated target texture
  2234. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2235. */
  2236. function WebGLRenderTarget( width, height, options ) {
  2237. this.width = width;
  2238. this.height = height;
  2239. this.scissor = new Vector4( 0, 0, width, height );
  2240. this.scissorTest = false;
  2241. this.viewport = new Vector4( 0, 0, width, height );
  2242. options = options || {};
  2243. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2244. this.texture.image = {};
  2245. this.texture.image.width = width;
  2246. this.texture.image.height = height;
  2247. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2248. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2249. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2250. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2251. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2252. }
  2253. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2254. constructor: WebGLRenderTarget,
  2255. isWebGLRenderTarget: true,
  2256. setSize: function ( width, height ) {
  2257. if ( this.width !== width || this.height !== height ) {
  2258. this.width = width;
  2259. this.height = height;
  2260. this.texture.image.width = width;
  2261. this.texture.image.height = height;
  2262. this.dispose();
  2263. }
  2264. this.viewport.set( 0, 0, width, height );
  2265. this.scissor.set( 0, 0, width, height );
  2266. },
  2267. clone: function () {
  2268. return new this.constructor().copy( this );
  2269. },
  2270. copy: function ( source ) {
  2271. this.width = source.width;
  2272. this.height = source.height;
  2273. this.viewport.copy( source.viewport );
  2274. this.texture = source.texture.clone();
  2275. this.depthBuffer = source.depthBuffer;
  2276. this.stencilBuffer = source.stencilBuffer;
  2277. this.depthTexture = source.depthTexture;
  2278. return this;
  2279. },
  2280. dispose: function () {
  2281. this.dispatchEvent( { type: 'dispose' } );
  2282. }
  2283. } );
  2284. /**
  2285. * @author Mugen87 / https://github.com/Mugen87
  2286. * @author Matt DesLauriers / @mattdesl
  2287. */
  2288. function WebGLMultisampleRenderTarget( width, height, options ) {
  2289. WebGLRenderTarget.call( this, width, height, options );
  2290. this.samples = 4;
  2291. }
  2292. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2293. constructor: WebGLMultisampleRenderTarget,
  2294. isWebGLMultisampleRenderTarget: true,
  2295. copy: function ( source ) {
  2296. WebGLRenderTarget.prototype.copy.call( this, source );
  2297. this.samples = source.samples;
  2298. return this;
  2299. }
  2300. } );
  2301. /**
  2302. * @author mrdoob / http://mrdoob.com/
  2303. * @author supereggbert / http://www.paulbrunt.co.uk/
  2304. * @author philogb / http://blog.thejit.org/
  2305. * @author jordi_ros / http://plattsoft.com
  2306. * @author D1plo1d / http://github.com/D1plo1d
  2307. * @author alteredq / http://alteredqualia.com/
  2308. * @author mikael emtinger / http://gomo.se/
  2309. * @author timknip / http://www.floorplanner.com/
  2310. * @author bhouston / http://clara.io
  2311. * @author WestLangley / http://github.com/WestLangley
  2312. */
  2313. var _v1, _m1;
  2314. var _zero, _one;
  2315. var _x, _y, _z;
  2316. function Matrix4() {
  2317. this.elements = [
  2318. 1, 0, 0, 0,
  2319. 0, 1, 0, 0,
  2320. 0, 0, 1, 0,
  2321. 0, 0, 0, 1
  2322. ];
  2323. if ( arguments.length > 0 ) {
  2324. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2325. }
  2326. }
  2327. Object.assign( Matrix4.prototype, {
  2328. isMatrix4: true,
  2329. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2330. var te = this.elements;
  2331. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2332. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2333. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2334. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2335. return this;
  2336. },
  2337. identity: function () {
  2338. this.set(
  2339. 1, 0, 0, 0,
  2340. 0, 1, 0, 0,
  2341. 0, 0, 1, 0,
  2342. 0, 0, 0, 1
  2343. );
  2344. return this;
  2345. },
  2346. clone: function () {
  2347. return new Matrix4().fromArray( this.elements );
  2348. },
  2349. copy: function ( m ) {
  2350. var te = this.elements;
  2351. var me = m.elements;
  2352. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2353. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2354. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2355. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2356. return this;
  2357. },
  2358. copyPosition: function ( m ) {
  2359. var te = this.elements, me = m.elements;
  2360. te[ 12 ] = me[ 12 ];
  2361. te[ 13 ] = me[ 13 ];
  2362. te[ 14 ] = me[ 14 ];
  2363. return this;
  2364. },
  2365. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2366. xAxis.setFromMatrixColumn( this, 0 );
  2367. yAxis.setFromMatrixColumn( this, 1 );
  2368. zAxis.setFromMatrixColumn( this, 2 );
  2369. return this;
  2370. },
  2371. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2372. this.set(
  2373. xAxis.x, yAxis.x, zAxis.x, 0,
  2374. xAxis.y, yAxis.y, zAxis.y, 0,
  2375. xAxis.z, yAxis.z, zAxis.z, 0,
  2376. 0, 0, 0, 1
  2377. );
  2378. return this;
  2379. },
  2380. extractRotation: function ( m ) {
  2381. if ( _v1 === undefined ) _v1 = new Vector3();
  2382. // this method does not support reflection matrices
  2383. var te = this.elements;
  2384. var me = m.elements;
  2385. var scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length();
  2386. var scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length();
  2387. var scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length();
  2388. te[ 0 ] = me[ 0 ] * scaleX;
  2389. te[ 1 ] = me[ 1 ] * scaleX;
  2390. te[ 2 ] = me[ 2 ] * scaleX;
  2391. te[ 3 ] = 0;
  2392. te[ 4 ] = me[ 4 ] * scaleY;
  2393. te[ 5 ] = me[ 5 ] * scaleY;
  2394. te[ 6 ] = me[ 6 ] * scaleY;
  2395. te[ 7 ] = 0;
  2396. te[ 8 ] = me[ 8 ] * scaleZ;
  2397. te[ 9 ] = me[ 9 ] * scaleZ;
  2398. te[ 10 ] = me[ 10 ] * scaleZ;
  2399. te[ 11 ] = 0;
  2400. te[ 12 ] = 0;
  2401. te[ 13 ] = 0;
  2402. te[ 14 ] = 0;
  2403. te[ 15 ] = 1;
  2404. return this;
  2405. },
  2406. makeRotationFromEuler: function ( euler ) {
  2407. if ( ! ( euler && euler.isEuler ) ) {
  2408. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2409. }
  2410. var te = this.elements;
  2411. var x = euler.x, y = euler.y, z = euler.z;
  2412. var a = Math.cos( x ), b = Math.sin( x );
  2413. var c = Math.cos( y ), d = Math.sin( y );
  2414. var e = Math.cos( z ), f = Math.sin( z );
  2415. if ( euler.order === 'XYZ' ) {
  2416. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2417. te[ 0 ] = c * e;
  2418. te[ 4 ] = - c * f;
  2419. te[ 8 ] = d;
  2420. te[ 1 ] = af + be * d;
  2421. te[ 5 ] = ae - bf * d;
  2422. te[ 9 ] = - b * c;
  2423. te[ 2 ] = bf - ae * d;
  2424. te[ 6 ] = be + af * d;
  2425. te[ 10 ] = a * c;
  2426. } else if ( euler.order === 'YXZ' ) {
  2427. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2428. te[ 0 ] = ce + df * b;
  2429. te[ 4 ] = de * b - cf;
  2430. te[ 8 ] = a * d;
  2431. te[ 1 ] = a * f;
  2432. te[ 5 ] = a * e;
  2433. te[ 9 ] = - b;
  2434. te[ 2 ] = cf * b - de;
  2435. te[ 6 ] = df + ce * b;
  2436. te[ 10 ] = a * c;
  2437. } else if ( euler.order === 'ZXY' ) {
  2438. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2439. te[ 0 ] = ce - df * b;
  2440. te[ 4 ] = - a * f;
  2441. te[ 8 ] = de + cf * b;
  2442. te[ 1 ] = cf + de * b;
  2443. te[ 5 ] = a * e;
  2444. te[ 9 ] = df - ce * b;
  2445. te[ 2 ] = - a * d;
  2446. te[ 6 ] = b;
  2447. te[ 10 ] = a * c;
  2448. } else if ( euler.order === 'ZYX' ) {
  2449. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2450. te[ 0 ] = c * e;
  2451. te[ 4 ] = be * d - af;
  2452. te[ 8 ] = ae * d + bf;
  2453. te[ 1 ] = c * f;
  2454. te[ 5 ] = bf * d + ae;
  2455. te[ 9 ] = af * d - be;
  2456. te[ 2 ] = - d;
  2457. te[ 6 ] = b * c;
  2458. te[ 10 ] = a * c;
  2459. } else if ( euler.order === 'YZX' ) {
  2460. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2461. te[ 0 ] = c * e;
  2462. te[ 4 ] = bd - ac * f;
  2463. te[ 8 ] = bc * f + ad;
  2464. te[ 1 ] = f;
  2465. te[ 5 ] = a * e;
  2466. te[ 9 ] = - b * e;
  2467. te[ 2 ] = - d * e;
  2468. te[ 6 ] = ad * f + bc;
  2469. te[ 10 ] = ac - bd * f;
  2470. } else if ( euler.order === 'XZY' ) {
  2471. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2472. te[ 0 ] = c * e;
  2473. te[ 4 ] = - f;
  2474. te[ 8 ] = d * e;
  2475. te[ 1 ] = ac * f + bd;
  2476. te[ 5 ] = a * e;
  2477. te[ 9 ] = ad * f - bc;
  2478. te[ 2 ] = bc * f - ad;
  2479. te[ 6 ] = b * e;
  2480. te[ 10 ] = bd * f + ac;
  2481. }
  2482. // bottom row
  2483. te[ 3 ] = 0;
  2484. te[ 7 ] = 0;
  2485. te[ 11 ] = 0;
  2486. // last column
  2487. te[ 12 ] = 0;
  2488. te[ 13 ] = 0;
  2489. te[ 14 ] = 0;
  2490. te[ 15 ] = 1;
  2491. return this;
  2492. },
  2493. makeRotationFromQuaternion: function ( q ) {
  2494. if ( _zero === undefined ) {
  2495. _zero = new Vector3( 0, 0, 0 );
  2496. _one = new Vector3( 1, 1, 1 );
  2497. }
  2498. return this.compose( _zero, q, _one );
  2499. },
  2500. lookAt: function ( eye, target, up ) {
  2501. if ( _x === undefined ) {
  2502. _x = new Vector3();
  2503. _y = new Vector3();
  2504. _z = new Vector3();
  2505. }
  2506. var te = this.elements;
  2507. _z.subVectors( eye, target );
  2508. if ( _z.lengthSq() === 0 ) {
  2509. // eye and target are in the same position
  2510. _z.z = 1;
  2511. }
  2512. _z.normalize();
  2513. _x.crossVectors( up, _z );
  2514. if ( _x.lengthSq() === 0 ) {
  2515. // up and z are parallel
  2516. if ( Math.abs( up.z ) === 1 ) {
  2517. _z.x += 0.0001;
  2518. } else {
  2519. _z.z += 0.0001;
  2520. }
  2521. _z.normalize();
  2522. _x.crossVectors( up, _z );
  2523. }
  2524. _x.normalize();
  2525. _y.crossVectors( _z, _x );
  2526. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  2527. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  2528. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  2529. return this;
  2530. },
  2531. multiply: function ( m, n ) {
  2532. if ( n !== undefined ) {
  2533. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2534. return this.multiplyMatrices( m, n );
  2535. }
  2536. return this.multiplyMatrices( this, m );
  2537. },
  2538. premultiply: function ( m ) {
  2539. return this.multiplyMatrices( m, this );
  2540. },
  2541. multiplyMatrices: function ( a, b ) {
  2542. var ae = a.elements;
  2543. var be = b.elements;
  2544. var te = this.elements;
  2545. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2546. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2547. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2548. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2549. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2550. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2551. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2552. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2553. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2554. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2555. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2556. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2557. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2558. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2559. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2560. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2561. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2562. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2563. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2564. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2565. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2566. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2567. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2568. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2569. return this;
  2570. },
  2571. multiplyScalar: function ( s ) {
  2572. var te = this.elements;
  2573. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2574. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2575. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2576. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2577. return this;
  2578. },
  2579. applyToBufferAttribute: function ( attribute ) {
  2580. if ( _v1 === undefined ) _v1 = new Vector3();
  2581. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2582. _v1.x = attribute.getX( i );
  2583. _v1.y = attribute.getY( i );
  2584. _v1.z = attribute.getZ( i );
  2585. _v1.applyMatrix4( this );
  2586. attribute.setXYZ( i, _v1.x, _v1.y, _v1.z );
  2587. }
  2588. return attribute;
  2589. },
  2590. determinant: function () {
  2591. var te = this.elements;
  2592. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2593. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2594. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2595. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2596. //TODO: make this more efficient
  2597. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2598. return (
  2599. n41 * (
  2600. + n14 * n23 * n32
  2601. - n13 * n24 * n32
  2602. - n14 * n22 * n33
  2603. + n12 * n24 * n33
  2604. + n13 * n22 * n34
  2605. - n12 * n23 * n34
  2606. ) +
  2607. n42 * (
  2608. + n11 * n23 * n34
  2609. - n11 * n24 * n33
  2610. + n14 * n21 * n33
  2611. - n13 * n21 * n34
  2612. + n13 * n24 * n31
  2613. - n14 * n23 * n31
  2614. ) +
  2615. n43 * (
  2616. + n11 * n24 * n32
  2617. - n11 * n22 * n34
  2618. - n14 * n21 * n32
  2619. + n12 * n21 * n34
  2620. + n14 * n22 * n31
  2621. - n12 * n24 * n31
  2622. ) +
  2623. n44 * (
  2624. - n13 * n22 * n31
  2625. - n11 * n23 * n32
  2626. + n11 * n22 * n33
  2627. + n13 * n21 * n32
  2628. - n12 * n21 * n33
  2629. + n12 * n23 * n31
  2630. )
  2631. );
  2632. },
  2633. transpose: function () {
  2634. var te = this.elements;
  2635. var tmp;
  2636. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2637. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2638. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2639. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2640. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2641. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2642. return this;
  2643. },
  2644. setPosition: function ( x, y, z ) {
  2645. var te = this.elements;
  2646. if ( x.isVector3 ) {
  2647. te[ 12 ] = x.x;
  2648. te[ 13 ] = x.y;
  2649. te[ 14 ] = x.z;
  2650. } else {
  2651. te[ 12 ] = x;
  2652. te[ 13 ] = y;
  2653. te[ 14 ] = z;
  2654. }
  2655. return this;
  2656. },
  2657. getInverse: function ( m, throwOnDegenerate ) {
  2658. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2659. var te = this.elements,
  2660. me = m.elements,
  2661. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2662. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2663. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2664. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2665. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2666. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2667. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2668. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2669. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2670. if ( det === 0 ) {
  2671. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  2672. if ( throwOnDegenerate === true ) {
  2673. throw new Error( msg );
  2674. } else {
  2675. console.warn( msg );
  2676. }
  2677. return this.identity();
  2678. }
  2679. var detInv = 1 / det;
  2680. te[ 0 ] = t11 * detInv;
  2681. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2682. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2683. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2684. te[ 4 ] = t12 * detInv;
  2685. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2686. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2687. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2688. te[ 8 ] = t13 * detInv;
  2689. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2690. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2691. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2692. te[ 12 ] = t14 * detInv;
  2693. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2694. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2695. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2696. return this;
  2697. },
  2698. scale: function ( v ) {
  2699. var te = this.elements;
  2700. var x = v.x, y = v.y, z = v.z;
  2701. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2702. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2703. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2704. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2705. return this;
  2706. },
  2707. getMaxScaleOnAxis: function () {
  2708. var te = this.elements;
  2709. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2710. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2711. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2712. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2713. },
  2714. makeTranslation: function ( x, y, z ) {
  2715. this.set(
  2716. 1, 0, 0, x,
  2717. 0, 1, 0, y,
  2718. 0, 0, 1, z,
  2719. 0, 0, 0, 1
  2720. );
  2721. return this;
  2722. },
  2723. makeRotationX: function ( theta ) {
  2724. var c = Math.cos( theta ), s = Math.sin( theta );
  2725. this.set(
  2726. 1, 0, 0, 0,
  2727. 0, c, - s, 0,
  2728. 0, s, c, 0,
  2729. 0, 0, 0, 1
  2730. );
  2731. return this;
  2732. },
  2733. makeRotationY: function ( theta ) {
  2734. var c = Math.cos( theta ), s = Math.sin( theta );
  2735. this.set(
  2736. c, 0, s, 0,
  2737. 0, 1, 0, 0,
  2738. - s, 0, c, 0,
  2739. 0, 0, 0, 1
  2740. );
  2741. return this;
  2742. },
  2743. makeRotationZ: function ( theta ) {
  2744. var c = Math.cos( theta ), s = Math.sin( theta );
  2745. this.set(
  2746. c, - s, 0, 0,
  2747. s, c, 0, 0,
  2748. 0, 0, 1, 0,
  2749. 0, 0, 0, 1
  2750. );
  2751. return this;
  2752. },
  2753. makeRotationAxis: function ( axis, angle ) {
  2754. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2755. var c = Math.cos( angle );
  2756. var s = Math.sin( angle );
  2757. var t = 1 - c;
  2758. var x = axis.x, y = axis.y, z = axis.z;
  2759. var tx = t * x, ty = t * y;
  2760. this.set(
  2761. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2762. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2763. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2764. 0, 0, 0, 1
  2765. );
  2766. return this;
  2767. },
  2768. makeScale: function ( x, y, z ) {
  2769. this.set(
  2770. x, 0, 0, 0,
  2771. 0, y, 0, 0,
  2772. 0, 0, z, 0,
  2773. 0, 0, 0, 1
  2774. );
  2775. return this;
  2776. },
  2777. makeShear: function ( x, y, z ) {
  2778. this.set(
  2779. 1, y, z, 0,
  2780. x, 1, z, 0,
  2781. x, y, 1, 0,
  2782. 0, 0, 0, 1
  2783. );
  2784. return this;
  2785. },
  2786. compose: function ( position, quaternion, scale ) {
  2787. var te = this.elements;
  2788. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2789. var x2 = x + x, y2 = y + y, z2 = z + z;
  2790. var xx = x * x2, xy = x * y2, xz = x * z2;
  2791. var yy = y * y2, yz = y * z2, zz = z * z2;
  2792. var wx = w * x2, wy = w * y2, wz = w * z2;
  2793. var sx = scale.x, sy = scale.y, sz = scale.z;
  2794. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2795. te[ 1 ] = ( xy + wz ) * sx;
  2796. te[ 2 ] = ( xz - wy ) * sx;
  2797. te[ 3 ] = 0;
  2798. te[ 4 ] = ( xy - wz ) * sy;
  2799. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2800. te[ 6 ] = ( yz + wx ) * sy;
  2801. te[ 7 ] = 0;
  2802. te[ 8 ] = ( xz + wy ) * sz;
  2803. te[ 9 ] = ( yz - wx ) * sz;
  2804. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2805. te[ 11 ] = 0;
  2806. te[ 12 ] = position.x;
  2807. te[ 13 ] = position.y;
  2808. te[ 14 ] = position.z;
  2809. te[ 15 ] = 1;
  2810. return this;
  2811. },
  2812. decompose: function ( position, quaternion, scale ) {
  2813. if ( _m1 === undefined ) {
  2814. _m1 = new Matrix4();
  2815. _v1 = new Vector3();
  2816. }
  2817. var te = this.elements;
  2818. var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2819. var sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2820. var sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2821. // if determine is negative, we need to invert one scale
  2822. var det = this.determinant();
  2823. if ( det < 0 ) sx = - sx;
  2824. position.x = te[ 12 ];
  2825. position.y = te[ 13 ];
  2826. position.z = te[ 14 ];
  2827. // scale the rotation part
  2828. _m1.copy( this );
  2829. var invSX = 1 / sx;
  2830. var invSY = 1 / sy;
  2831. var invSZ = 1 / sz;
  2832. _m1.elements[ 0 ] *= invSX;
  2833. _m1.elements[ 1 ] *= invSX;
  2834. _m1.elements[ 2 ] *= invSX;
  2835. _m1.elements[ 4 ] *= invSY;
  2836. _m1.elements[ 5 ] *= invSY;
  2837. _m1.elements[ 6 ] *= invSY;
  2838. _m1.elements[ 8 ] *= invSZ;
  2839. _m1.elements[ 9 ] *= invSZ;
  2840. _m1.elements[ 10 ] *= invSZ;
  2841. quaternion.setFromRotationMatrix( _m1 );
  2842. scale.x = sx;
  2843. scale.y = sy;
  2844. scale.z = sz;
  2845. return this;
  2846. },
  2847. makePerspective: function ( left, right, top, bottom, near, far ) {
  2848. if ( far === undefined ) {
  2849. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2850. }
  2851. var te = this.elements;
  2852. var x = 2 * near / ( right - left );
  2853. var y = 2 * near / ( top - bottom );
  2854. var a = ( right + left ) / ( right - left );
  2855. var b = ( top + bottom ) / ( top - bottom );
  2856. var c = - ( far + near ) / ( far - near );
  2857. var d = - 2 * far * near / ( far - near );
  2858. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2859. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2860. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2861. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2862. return this;
  2863. },
  2864. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2865. var te = this.elements;
  2866. var w = 1.0 / ( right - left );
  2867. var h = 1.0 / ( top - bottom );
  2868. var p = 1.0 / ( far - near );
  2869. var x = ( right + left ) * w;
  2870. var y = ( top + bottom ) * h;
  2871. var z = ( far + near ) * p;
  2872. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2873. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2874. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2875. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2876. return this;
  2877. },
  2878. equals: function ( matrix ) {
  2879. var te = this.elements;
  2880. var me = matrix.elements;
  2881. for ( var i = 0; i < 16; i ++ ) {
  2882. if ( te[ i ] !== me[ i ] ) return false;
  2883. }
  2884. return true;
  2885. },
  2886. fromArray: function ( array, offset ) {
  2887. if ( offset === undefined ) offset = 0;
  2888. for ( var i = 0; i < 16; i ++ ) {
  2889. this.elements[ i ] = array[ i + offset ];
  2890. }
  2891. return this;
  2892. },
  2893. toArray: function ( array, offset ) {
  2894. if ( array === undefined ) array = [];
  2895. if ( offset === undefined ) offset = 0;
  2896. var te = this.elements;
  2897. array[ offset ] = te[ 0 ];
  2898. array[ offset + 1 ] = te[ 1 ];
  2899. array[ offset + 2 ] = te[ 2 ];
  2900. array[ offset + 3 ] = te[ 3 ];
  2901. array[ offset + 4 ] = te[ 4 ];
  2902. array[ offset + 5 ] = te[ 5 ];
  2903. array[ offset + 6 ] = te[ 6 ];
  2904. array[ offset + 7 ] = te[ 7 ];
  2905. array[ offset + 8 ] = te[ 8 ];
  2906. array[ offset + 9 ] = te[ 9 ];
  2907. array[ offset + 10 ] = te[ 10 ];
  2908. array[ offset + 11 ] = te[ 11 ];
  2909. array[ offset + 12 ] = te[ 12 ];
  2910. array[ offset + 13 ] = te[ 13 ];
  2911. array[ offset + 14 ] = te[ 14 ];
  2912. array[ offset + 15 ] = te[ 15 ];
  2913. return array;
  2914. }
  2915. } );
  2916. /**
  2917. * @author mrdoob / http://mrdoob.com/
  2918. * @author WestLangley / http://github.com/WestLangley
  2919. * @author bhouston / http://clara.io
  2920. */
  2921. var _matrix, _quaternion$1;
  2922. function Euler( x, y, z, order ) {
  2923. this._x = x || 0;
  2924. this._y = y || 0;
  2925. this._z = z || 0;
  2926. this._order = order || Euler.DefaultOrder;
  2927. }
  2928. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2929. Euler.DefaultOrder = 'XYZ';
  2930. Object.defineProperties( Euler.prototype, {
  2931. x: {
  2932. get: function () {
  2933. return this._x;
  2934. },
  2935. set: function ( value ) {
  2936. this._x = value;
  2937. this._onChangeCallback();
  2938. }
  2939. },
  2940. y: {
  2941. get: function () {
  2942. return this._y;
  2943. },
  2944. set: function ( value ) {
  2945. this._y = value;
  2946. this._onChangeCallback();
  2947. }
  2948. },
  2949. z: {
  2950. get: function () {
  2951. return this._z;
  2952. },
  2953. set: function ( value ) {
  2954. this._z = value;
  2955. this._onChangeCallback();
  2956. }
  2957. },
  2958. order: {
  2959. get: function () {
  2960. return this._order;
  2961. },
  2962. set: function ( value ) {
  2963. this._order = value;
  2964. this._onChangeCallback();
  2965. }
  2966. }
  2967. } );
  2968. Object.assign( Euler.prototype, {
  2969. isEuler: true,
  2970. set: function ( x, y, z, order ) {
  2971. this._x = x;
  2972. this._y = y;
  2973. this._z = z;
  2974. this._order = order || this._order;
  2975. this._onChangeCallback();
  2976. return this;
  2977. },
  2978. clone: function () {
  2979. return new this.constructor( this._x, this._y, this._z, this._order );
  2980. },
  2981. copy: function ( euler ) {
  2982. this._x = euler._x;
  2983. this._y = euler._y;
  2984. this._z = euler._z;
  2985. this._order = euler._order;
  2986. this._onChangeCallback();
  2987. return this;
  2988. },
  2989. setFromRotationMatrix: function ( m, order, update ) {
  2990. var clamp = _Math.clamp;
  2991. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2992. var te = m.elements;
  2993. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2994. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2995. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2996. order = order || this._order;
  2997. if ( order === 'XYZ' ) {
  2998. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2999. if ( Math.abs( m13 ) < 0.9999999 ) {
  3000. this._x = Math.atan2( - m23, m33 );
  3001. this._z = Math.atan2( - m12, m11 );
  3002. } else {
  3003. this._x = Math.atan2( m32, m22 );
  3004. this._z = 0;
  3005. }
  3006. } else if ( order === 'YXZ' ) {
  3007. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3008. if ( Math.abs( m23 ) < 0.9999999 ) {
  3009. this._y = Math.atan2( m13, m33 );
  3010. this._z = Math.atan2( m21, m22 );
  3011. } else {
  3012. this._y = Math.atan2( - m31, m11 );
  3013. this._z = 0;
  3014. }
  3015. } else if ( order === 'ZXY' ) {
  3016. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3017. if ( Math.abs( m32 ) < 0.9999999 ) {
  3018. this._y = Math.atan2( - m31, m33 );
  3019. this._z = Math.atan2( - m12, m22 );
  3020. } else {
  3021. this._y = 0;
  3022. this._z = Math.atan2( m21, m11 );
  3023. }
  3024. } else if ( order === 'ZYX' ) {
  3025. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3026. if ( Math.abs( m31 ) < 0.9999999 ) {
  3027. this._x = Math.atan2( m32, m33 );
  3028. this._z = Math.atan2( m21, m11 );
  3029. } else {
  3030. this._x = 0;
  3031. this._z = Math.atan2( - m12, m22 );
  3032. }
  3033. } else if ( order === 'YZX' ) {
  3034. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3035. if ( Math.abs( m21 ) < 0.9999999 ) {
  3036. this._x = Math.atan2( - m23, m22 );
  3037. this._y = Math.atan2( - m31, m11 );
  3038. } else {
  3039. this._x = 0;
  3040. this._y = Math.atan2( m13, m33 );
  3041. }
  3042. } else if ( order === 'XZY' ) {
  3043. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3044. if ( Math.abs( m12 ) < 0.9999999 ) {
  3045. this._x = Math.atan2( m32, m22 );
  3046. this._y = Math.atan2( m13, m11 );
  3047. } else {
  3048. this._x = Math.atan2( - m23, m33 );
  3049. this._y = 0;
  3050. }
  3051. } else {
  3052. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  3053. }
  3054. this._order = order;
  3055. if ( update !== false ) this._onChangeCallback();
  3056. return this;
  3057. },
  3058. setFromQuaternion: function ( q, order, update ) {
  3059. if ( _matrix === undefined ) _matrix = new Matrix4();
  3060. _matrix.makeRotationFromQuaternion( q );
  3061. return this.setFromRotationMatrix( _matrix, order, update );
  3062. },
  3063. setFromVector3: function ( v, order ) {
  3064. return this.set( v.x, v.y, v.z, order || this._order );
  3065. },
  3066. reorder: function ( newOrder ) {
  3067. // WARNING: this discards revolution information -bhouston
  3068. if ( _quaternion$1 === undefined ) _quaternion$1 = new Quaternion();
  3069. _quaternion$1.setFromEuler( this );
  3070. return this.setFromQuaternion( _quaternion$1, newOrder );
  3071. },
  3072. equals: function ( euler ) {
  3073. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3074. },
  3075. fromArray: function ( array ) {
  3076. this._x = array[ 0 ];
  3077. this._y = array[ 1 ];
  3078. this._z = array[ 2 ];
  3079. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3080. this._onChangeCallback();
  3081. return this;
  3082. },
  3083. toArray: function ( array, offset ) {
  3084. if ( array === undefined ) array = [];
  3085. if ( offset === undefined ) offset = 0;
  3086. array[ offset ] = this._x;
  3087. array[ offset + 1 ] = this._y;
  3088. array[ offset + 2 ] = this._z;
  3089. array[ offset + 3 ] = this._order;
  3090. return array;
  3091. },
  3092. toVector3: function ( optionalResult ) {
  3093. if ( optionalResult ) {
  3094. return optionalResult.set( this._x, this._y, this._z );
  3095. } else {
  3096. return new Vector3( this._x, this._y, this._z );
  3097. }
  3098. },
  3099. _onChange: function ( callback ) {
  3100. this._onChangeCallback = callback;
  3101. return this;
  3102. },
  3103. _onChangeCallback: function () {}
  3104. } );
  3105. /**
  3106. * @author mrdoob / http://mrdoob.com/
  3107. */
  3108. function Layers() {
  3109. this.mask = 1 | 0;
  3110. }
  3111. Object.assign( Layers.prototype, {
  3112. set: function ( channel ) {
  3113. this.mask = 1 << channel | 0;
  3114. },
  3115. enable: function ( channel ) {
  3116. this.mask |= 1 << channel | 0;
  3117. },
  3118. toggle: function ( channel ) {
  3119. this.mask ^= 1 << channel | 0;
  3120. },
  3121. disable: function ( channel ) {
  3122. this.mask &= ~ ( 1 << channel | 0 );
  3123. },
  3124. test: function ( layers ) {
  3125. return ( this.mask & layers.mask ) !== 0;
  3126. }
  3127. } );
  3128. /**
  3129. * @author mrdoob / http://mrdoob.com/
  3130. * @author mikael emtinger / http://gomo.se/
  3131. * @author alteredq / http://alteredqualia.com/
  3132. * @author WestLangley / http://github.com/WestLangley
  3133. * @author elephantatwork / www.elephantatwork.ch
  3134. */
  3135. var _object3DId = 0;
  3136. var _m1$1, _q1, _v1$1;
  3137. var _xAxis, _yAxis, _zAxis;
  3138. var _target, _position, _scale, _quaternion$2;
  3139. function Object3D() {
  3140. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3141. this.uuid = _Math.generateUUID();
  3142. this.name = '';
  3143. this.type = 'Object3D';
  3144. this.parent = null;
  3145. this.children = [];
  3146. this.up = Object3D.DefaultUp.clone();
  3147. var position = new Vector3();
  3148. var rotation = new Euler();
  3149. var quaternion = new Quaternion();
  3150. var scale = new Vector3( 1, 1, 1 );
  3151. function onRotationChange() {
  3152. quaternion.setFromEuler( rotation, false );
  3153. }
  3154. function onQuaternionChange() {
  3155. rotation.setFromQuaternion( quaternion, undefined, false );
  3156. }
  3157. rotation._onChange( onRotationChange );
  3158. quaternion._onChange( onQuaternionChange );
  3159. Object.defineProperties( this, {
  3160. position: {
  3161. configurable: true,
  3162. enumerable: true,
  3163. value: position
  3164. },
  3165. rotation: {
  3166. configurable: true,
  3167. enumerable: true,
  3168. value: rotation
  3169. },
  3170. quaternion: {
  3171. configurable: true,
  3172. enumerable: true,
  3173. value: quaternion
  3174. },
  3175. scale: {
  3176. configurable: true,
  3177. enumerable: true,
  3178. value: scale
  3179. },
  3180. modelViewMatrix: {
  3181. value: new Matrix4()
  3182. },
  3183. normalMatrix: {
  3184. value: new Matrix3()
  3185. }
  3186. } );
  3187. this.matrix = new Matrix4();
  3188. this.matrixWorld = new Matrix4();
  3189. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3190. this.matrixWorldNeedsUpdate = false;
  3191. this.layers = new Layers();
  3192. this.visible = true;
  3193. this.castShadow = false;
  3194. this.receiveShadow = false;
  3195. this.frustumCulled = true;
  3196. this.renderOrder = 0;
  3197. this.userData = {};
  3198. }
  3199. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3200. Object3D.DefaultMatrixAutoUpdate = true;
  3201. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3202. constructor: Object3D,
  3203. isObject3D: true,
  3204. onBeforeRender: function () {},
  3205. onAfterRender: function () {},
  3206. applyMatrix: function ( matrix ) {
  3207. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3208. this.matrix.premultiply( matrix );
  3209. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3210. },
  3211. applyQuaternion: function ( q ) {
  3212. this.quaternion.premultiply( q );
  3213. return this;
  3214. },
  3215. setRotationFromAxisAngle: function ( axis, angle ) {
  3216. // assumes axis is normalized
  3217. this.quaternion.setFromAxisAngle( axis, angle );
  3218. },
  3219. setRotationFromEuler: function ( euler ) {
  3220. this.quaternion.setFromEuler( euler, true );
  3221. },
  3222. setRotationFromMatrix: function ( m ) {
  3223. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3224. this.quaternion.setFromRotationMatrix( m );
  3225. },
  3226. setRotationFromQuaternion: function ( q ) {
  3227. // assumes q is normalized
  3228. this.quaternion.copy( q );
  3229. },
  3230. rotateOnAxis: function ( axis, angle ) {
  3231. // rotate object on axis in object space
  3232. // axis is assumed to be normalized
  3233. if ( _q1 === undefined ) _q1 = new Quaternion();
  3234. _q1.setFromAxisAngle( axis, angle );
  3235. this.quaternion.multiply( _q1 );
  3236. return this;
  3237. },
  3238. rotateOnWorldAxis: function ( axis, angle ) {
  3239. // rotate object on axis in world space
  3240. // axis is assumed to be normalized
  3241. // method assumes no rotated parent
  3242. if ( _q1 === undefined ) _q1 = new Quaternion();
  3243. _q1.setFromAxisAngle( axis, angle );
  3244. this.quaternion.premultiply( _q1 );
  3245. return this;
  3246. },
  3247. rotateX: function ( angle ) {
  3248. if ( _xAxis === undefined ) _xAxis = new Vector3( 1, 0, 0 );
  3249. return this.rotateOnAxis( _xAxis, angle );
  3250. },
  3251. rotateY: function ( angle ) {
  3252. if ( _yAxis === undefined ) _yAxis = new Vector3( 0, 1, 0 );
  3253. return this.rotateOnAxis( _yAxis, angle );
  3254. },
  3255. rotateZ: function ( angle ) {
  3256. if ( _zAxis === undefined ) _zAxis = new Vector3( 0, 0, 1 );
  3257. return this.rotateOnAxis( _zAxis, angle );
  3258. },
  3259. translateOnAxis: function ( axis, distance ) {
  3260. // translate object by distance along axis in object space
  3261. // axis is assumed to be normalized
  3262. if ( _v1$1 === undefined ) _v1$1 = new Vector3();
  3263. _v1$1.copy( axis ).applyQuaternion( this.quaternion );
  3264. this.position.add( _v1$1.multiplyScalar( distance ) );
  3265. return this;
  3266. },
  3267. translateX: function ( distance ) {
  3268. if ( _xAxis === undefined ) _xAxis = new Vector3( 1, 0, 0 );
  3269. return this.translateOnAxis( _xAxis, distance );
  3270. },
  3271. translateY: function ( distance ) {
  3272. if ( _yAxis === undefined ) _yAxis = new Vector3( 0, 1, 0 );
  3273. return this.translateOnAxis( _yAxis, distance );
  3274. },
  3275. translateZ: function ( distance ) {
  3276. if ( _zAxis === undefined ) _zAxis = new Vector3( 0, 0, 1 );
  3277. return this.translateOnAxis( _zAxis, distance );
  3278. },
  3279. localToWorld: function ( vector ) {
  3280. return vector.applyMatrix4( this.matrixWorld );
  3281. },
  3282. worldToLocal: function ( vector ) {
  3283. if ( _m1$1 === undefined ) _m1$1 = new Matrix4();
  3284. return vector.applyMatrix4( _m1$1.getInverse( this.matrixWorld ) );
  3285. },
  3286. lookAt: function ( x, y, z ) {
  3287. // This method does not support objects having non-uniformly-scaled parent(s)
  3288. if ( _position === undefined ) {
  3289. _q1 = new Quaternion();
  3290. _m1$1 = new Matrix4();
  3291. _target = new Vector3();
  3292. _position = new Vector3();
  3293. }
  3294. if ( x.isVector3 ) {
  3295. _target.copy( x );
  3296. } else {
  3297. _target.set( x, y, z );
  3298. }
  3299. var parent = this.parent;
  3300. this.updateWorldMatrix( true, false );
  3301. _position.setFromMatrixPosition( this.matrixWorld );
  3302. if ( this.isCamera || this.isLight ) {
  3303. _m1$1.lookAt( _position, _target, this.up );
  3304. } else {
  3305. _m1$1.lookAt( _target, _position, this.up );
  3306. }
  3307. this.quaternion.setFromRotationMatrix( _m1$1 );
  3308. if ( parent ) {
  3309. _m1$1.extractRotation( parent.matrixWorld );
  3310. _q1.setFromRotationMatrix( _m1$1 );
  3311. this.quaternion.premultiply( _q1.inverse() );
  3312. }
  3313. },
  3314. add: function ( object ) {
  3315. if ( arguments.length > 1 ) {
  3316. for ( var i = 0; i < arguments.length; i ++ ) {
  3317. this.add( arguments[ i ] );
  3318. }
  3319. return this;
  3320. }
  3321. if ( object === this ) {
  3322. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3323. return this;
  3324. }
  3325. if ( ( object && object.isObject3D ) ) {
  3326. if ( object.parent !== null ) {
  3327. object.parent.remove( object );
  3328. }
  3329. object.parent = this;
  3330. this.children.push( object );
  3331. object.dispatchEvent( { type: 'added' } );
  3332. } else {
  3333. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3334. }
  3335. return this;
  3336. },
  3337. remove: function ( object ) {
  3338. if ( arguments.length > 1 ) {
  3339. for ( var i = 0; i < arguments.length; i ++ ) {
  3340. this.remove( arguments[ i ] );
  3341. }
  3342. return this;
  3343. }
  3344. var index = this.children.indexOf( object );
  3345. if ( index !== - 1 ) {
  3346. object.parent = null;
  3347. this.children.splice( index, 1 );
  3348. object.dispatchEvent( { type: 'removed' } );
  3349. }
  3350. return this;
  3351. },
  3352. attach: function ( object ) {
  3353. // adds object as a child of this, while maintaining the object's world transform
  3354. if ( _m1$1 === undefined ) _m1$1 = new Matrix4();
  3355. this.updateWorldMatrix( true, false );
  3356. _m1$1.getInverse( this.matrixWorld );
  3357. if ( object.parent !== null ) {
  3358. object.parent.updateWorldMatrix( true, false );
  3359. _m1$1.multiply( object.parent.matrixWorld );
  3360. }
  3361. object.applyMatrix( _m1$1 );
  3362. object.updateWorldMatrix( false, false );
  3363. this.add( object );
  3364. return this;
  3365. },
  3366. getObjectById: function ( id ) {
  3367. return this.getObjectByProperty( 'id', id );
  3368. },
  3369. getObjectByName: function ( name ) {
  3370. return this.getObjectByProperty( 'name', name );
  3371. },
  3372. getObjectByProperty: function ( name, value ) {
  3373. if ( this[ name ] === value ) return this;
  3374. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3375. var child = this.children[ i ];
  3376. var object = child.getObjectByProperty( name, value );
  3377. if ( object !== undefined ) {
  3378. return object;
  3379. }
  3380. }
  3381. return undefined;
  3382. },
  3383. getWorldPosition: function ( target ) {
  3384. if ( target === undefined ) {
  3385. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3386. target = new Vector3();
  3387. }
  3388. this.updateMatrixWorld( true );
  3389. return target.setFromMatrixPosition( this.matrixWorld );
  3390. },
  3391. getWorldQuaternion: function ( target ) {
  3392. if ( _scale === undefined ) {
  3393. _position = new Vector3();
  3394. _scale = new Vector3();
  3395. }
  3396. if ( target === undefined ) {
  3397. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3398. target = new Quaternion();
  3399. }
  3400. this.updateMatrixWorld( true );
  3401. this.matrixWorld.decompose( _position, target, _scale );
  3402. return target;
  3403. },
  3404. getWorldScale: function ( target ) {
  3405. if ( _quaternion$2 === undefined ) {
  3406. _position = new Vector3();
  3407. _quaternion$2 = new Quaternion();
  3408. }
  3409. if ( target === undefined ) {
  3410. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3411. target = new Vector3();
  3412. }
  3413. this.updateMatrixWorld( true );
  3414. this.matrixWorld.decompose( _position, _quaternion$2, target );
  3415. return target;
  3416. },
  3417. getWorldDirection: function ( target ) {
  3418. if ( target === undefined ) {
  3419. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3420. target = new Vector3();
  3421. }
  3422. this.updateMatrixWorld( true );
  3423. var e = this.matrixWorld.elements;
  3424. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3425. },
  3426. raycast: function () {},
  3427. traverse: function ( callback ) {
  3428. callback( this );
  3429. var children = this.children;
  3430. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3431. children[ i ].traverse( callback );
  3432. }
  3433. },
  3434. traverseVisible: function ( callback ) {
  3435. if ( this.visible === false ) return;
  3436. callback( this );
  3437. var children = this.children;
  3438. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3439. children[ i ].traverseVisible( callback );
  3440. }
  3441. },
  3442. traverseAncestors: function ( callback ) {
  3443. var parent = this.parent;
  3444. if ( parent !== null ) {
  3445. callback( parent );
  3446. parent.traverseAncestors( callback );
  3447. }
  3448. },
  3449. updateMatrix: function () {
  3450. this.matrix.compose( this.position, this.quaternion, this.scale );
  3451. this.matrixWorldNeedsUpdate = true;
  3452. },
  3453. updateMatrixWorld: function ( force ) {
  3454. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3455. if ( this.matrixWorldNeedsUpdate || force ) {
  3456. if ( this.parent === null ) {
  3457. this.matrixWorld.copy( this.matrix );
  3458. } else {
  3459. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3460. }
  3461. this.matrixWorldNeedsUpdate = false;
  3462. force = true;
  3463. }
  3464. // update children
  3465. var children = this.children;
  3466. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3467. children[ i ].updateMatrixWorld( force );
  3468. }
  3469. },
  3470. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3471. var parent = this.parent;
  3472. if ( updateParents === true && parent !== null ) {
  3473. parent.updateWorldMatrix( true, false );
  3474. }
  3475. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3476. if ( this.parent === null ) {
  3477. this.matrixWorld.copy( this.matrix );
  3478. } else {
  3479. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3480. }
  3481. // update children
  3482. if ( updateChildren === true ) {
  3483. var children = this.children;
  3484. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3485. children[ i ].updateWorldMatrix( false, true );
  3486. }
  3487. }
  3488. },
  3489. toJSON: function ( meta ) {
  3490. // meta is a string when called from JSON.stringify
  3491. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3492. var output = {};
  3493. // meta is a hash used to collect geometries, materials.
  3494. // not providing it implies that this is the root object
  3495. // being serialized.
  3496. if ( isRootObject ) {
  3497. // initialize meta obj
  3498. meta = {
  3499. geometries: {},
  3500. materials: {},
  3501. textures: {},
  3502. images: {},
  3503. shapes: {}
  3504. };
  3505. output.metadata = {
  3506. version: 4.5,
  3507. type: 'Object',
  3508. generator: 'Object3D.toJSON'
  3509. };
  3510. }
  3511. // standard Object3D serialization
  3512. var object = {};
  3513. object.uuid = this.uuid;
  3514. object.type = this.type;
  3515. if ( this.name !== '' ) object.name = this.name;
  3516. if ( this.castShadow === true ) object.castShadow = true;
  3517. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3518. if ( this.visible === false ) object.visible = false;
  3519. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3520. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3521. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3522. object.layers = this.layers.mask;
  3523. object.matrix = this.matrix.toArray();
  3524. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3525. // object specific properties
  3526. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  3527. //
  3528. function serialize( library, element ) {
  3529. if ( library[ element.uuid ] === undefined ) {
  3530. library[ element.uuid ] = element.toJSON( meta );
  3531. }
  3532. return element.uuid;
  3533. }
  3534. if ( this.isMesh || this.isLine || this.isPoints ) {
  3535. object.geometry = serialize( meta.geometries, this.geometry );
  3536. var parameters = this.geometry.parameters;
  3537. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3538. var shapes = parameters.shapes;
  3539. if ( Array.isArray( shapes ) ) {
  3540. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3541. var shape = shapes[ i ];
  3542. serialize( meta.shapes, shape );
  3543. }
  3544. } else {
  3545. serialize( meta.shapes, shapes );
  3546. }
  3547. }
  3548. }
  3549. if ( this.material !== undefined ) {
  3550. if ( Array.isArray( this.material ) ) {
  3551. var uuids = [];
  3552. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  3553. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3554. }
  3555. object.material = uuids;
  3556. } else {
  3557. object.material = serialize( meta.materials, this.material );
  3558. }
  3559. }
  3560. //
  3561. if ( this.children.length > 0 ) {
  3562. object.children = [];
  3563. for ( var i = 0; i < this.children.length; i ++ ) {
  3564. object.children.push( this.children[ i ].toJSON( meta ).object );
  3565. }
  3566. }
  3567. if ( isRootObject ) {
  3568. var geometries = extractFromCache( meta.geometries );
  3569. var materials = extractFromCache( meta.materials );
  3570. var textures = extractFromCache( meta.textures );
  3571. var images = extractFromCache( meta.images );
  3572. var shapes = extractFromCache( meta.shapes );
  3573. if ( geometries.length > 0 ) output.geometries = geometries;
  3574. if ( materials.length > 0 ) output.materials = materials;
  3575. if ( textures.length > 0 ) output.textures = textures;
  3576. if ( images.length > 0 ) output.images = images;
  3577. if ( shapes.length > 0 ) output.shapes = shapes;
  3578. }
  3579. output.object = object;
  3580. return output;
  3581. // extract data from the cache hash
  3582. // remove metadata on each item
  3583. // and return as array
  3584. function extractFromCache( cache ) {
  3585. var values = [];
  3586. for ( var key in cache ) {
  3587. var data = cache[ key ];
  3588. delete data.metadata;
  3589. values.push( data );
  3590. }
  3591. return values;
  3592. }
  3593. },
  3594. clone: function ( recursive ) {
  3595. return new this.constructor().copy( this, recursive );
  3596. },
  3597. copy: function ( source, recursive ) {
  3598. if ( recursive === undefined ) recursive = true;
  3599. this.name = source.name;
  3600. this.up.copy( source.up );
  3601. this.position.copy( source.position );
  3602. this.quaternion.copy( source.quaternion );
  3603. this.scale.copy( source.scale );
  3604. this.matrix.copy( source.matrix );
  3605. this.matrixWorld.copy( source.matrixWorld );
  3606. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3607. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3608. this.layers.mask = source.layers.mask;
  3609. this.visible = source.visible;
  3610. this.castShadow = source.castShadow;
  3611. this.receiveShadow = source.receiveShadow;
  3612. this.frustumCulled = source.frustumCulled;
  3613. this.renderOrder = source.renderOrder;
  3614. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3615. if ( recursive === true ) {
  3616. for ( var i = 0; i < source.children.length; i ++ ) {
  3617. var child = source.children[ i ];
  3618. this.add( child.clone() );
  3619. }
  3620. }
  3621. return this;
  3622. }
  3623. } );
  3624. /**
  3625. * @author mrdoob / http://mrdoob.com/
  3626. */
  3627. function Scene() {
  3628. Object3D.call( this );
  3629. this.type = 'Scene';
  3630. this.background = null;
  3631. this.fog = null;
  3632. this.overrideMaterial = null;
  3633. this.autoUpdate = true; // checked by the renderer
  3634. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3635. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3636. }
  3637. }
  3638. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3639. constructor: Scene,
  3640. isScene: true,
  3641. copy: function ( source, recursive ) {
  3642. Object3D.prototype.copy.call( this, source, recursive );
  3643. if ( source.background !== null ) this.background = source.background.clone();
  3644. if ( source.fog !== null ) this.fog = source.fog.clone();
  3645. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3646. this.autoUpdate = source.autoUpdate;
  3647. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3648. return this;
  3649. },
  3650. toJSON: function ( meta ) {
  3651. var data = Object3D.prototype.toJSON.call( this, meta );
  3652. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3653. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3654. return data;
  3655. },
  3656. dispose: function () {
  3657. this.dispatchEvent( { type: 'dispose' } );
  3658. }
  3659. } );
  3660. /**
  3661. * @author bhouston / http://clara.io
  3662. * @author WestLangley / http://github.com/WestLangley
  3663. */
  3664. var _points;
  3665. var _vector$2;
  3666. var _v0, _v1$2, _v2;
  3667. var _f0, _f1, _f2;
  3668. var _center;
  3669. var _extents;
  3670. var _triangleNormal;
  3671. function Box3( min, max ) {
  3672. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3673. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3674. }
  3675. Object.assign( Box3.prototype, {
  3676. isBox3: true,
  3677. set: function ( min, max ) {
  3678. this.min.copy( min );
  3679. this.max.copy( max );
  3680. return this;
  3681. },
  3682. setFromArray: function ( array ) {
  3683. var minX = + Infinity;
  3684. var minY = + Infinity;
  3685. var minZ = + Infinity;
  3686. var maxX = - Infinity;
  3687. var maxY = - Infinity;
  3688. var maxZ = - Infinity;
  3689. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3690. var x = array[ i ];
  3691. var y = array[ i + 1 ];
  3692. var z = array[ i + 2 ];
  3693. if ( x < minX ) minX = x;
  3694. if ( y < minY ) minY = y;
  3695. if ( z < minZ ) minZ = z;
  3696. if ( x > maxX ) maxX = x;
  3697. if ( y > maxY ) maxY = y;
  3698. if ( z > maxZ ) maxZ = z;
  3699. }
  3700. this.min.set( minX, minY, minZ );
  3701. this.max.set( maxX, maxY, maxZ );
  3702. return this;
  3703. },
  3704. setFromBufferAttribute: function ( attribute ) {
  3705. var minX = + Infinity;
  3706. var minY = + Infinity;
  3707. var minZ = + Infinity;
  3708. var maxX = - Infinity;
  3709. var maxY = - Infinity;
  3710. var maxZ = - Infinity;
  3711. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3712. var x = attribute.getX( i );
  3713. var y = attribute.getY( i );
  3714. var z = attribute.getZ( i );
  3715. if ( x < minX ) minX = x;
  3716. if ( y < minY ) minY = y;
  3717. if ( z < minZ ) minZ = z;
  3718. if ( x > maxX ) maxX = x;
  3719. if ( y > maxY ) maxY = y;
  3720. if ( z > maxZ ) maxZ = z;
  3721. }
  3722. this.min.set( minX, minY, minZ );
  3723. this.max.set( maxX, maxY, maxZ );
  3724. return this;
  3725. },
  3726. setFromPoints: function ( points ) {
  3727. this.makeEmpty();
  3728. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3729. this.expandByPoint( points[ i ] );
  3730. }
  3731. return this;
  3732. },
  3733. setFromCenterAndSize: function ( center, size ) {
  3734. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3735. var halfSize = _vector$2.copy( size ).multiplyScalar( 0.5 );
  3736. this.min.copy( center ).sub( halfSize );
  3737. this.max.copy( center ).add( halfSize );
  3738. return this;
  3739. },
  3740. setFromObject: function ( object ) {
  3741. this.makeEmpty();
  3742. return this.expandByObject( object );
  3743. },
  3744. clone: function () {
  3745. return new this.constructor().copy( this );
  3746. },
  3747. copy: function ( box ) {
  3748. this.min.copy( box.min );
  3749. this.max.copy( box.max );
  3750. return this;
  3751. },
  3752. makeEmpty: function () {
  3753. this.min.x = this.min.y = this.min.z = + Infinity;
  3754. this.max.x = this.max.y = this.max.z = - Infinity;
  3755. return this;
  3756. },
  3757. isEmpty: function () {
  3758. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3759. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3760. },
  3761. getCenter: function ( target ) {
  3762. if ( target === undefined ) {
  3763. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3764. target = new Vector3();
  3765. }
  3766. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3767. },
  3768. getSize: function ( target ) {
  3769. if ( target === undefined ) {
  3770. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3771. target = new Vector3();
  3772. }
  3773. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3774. },
  3775. expandByPoint: function ( point ) {
  3776. this.min.min( point );
  3777. this.max.max( point );
  3778. return this;
  3779. },
  3780. expandByVector: function ( vector ) {
  3781. this.min.sub( vector );
  3782. this.max.add( vector );
  3783. return this;
  3784. },
  3785. expandByScalar: function ( scalar ) {
  3786. this.min.addScalar( - scalar );
  3787. this.max.addScalar( scalar );
  3788. return this;
  3789. },
  3790. expandByObject: function ( object ) {
  3791. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3792. var i, l;
  3793. // Computes the world-axis-aligned bounding box of an object (including its children),
  3794. // accounting for both the object's, and children's, world transforms
  3795. object.updateWorldMatrix( false, false );
  3796. var geometry = object.geometry;
  3797. if ( geometry !== undefined ) {
  3798. if ( geometry.isGeometry ) {
  3799. var vertices = geometry.vertices;
  3800. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3801. _vector$2.copy( vertices[ i ] );
  3802. _vector$2.applyMatrix4( object.matrixWorld );
  3803. this.expandByPoint( _vector$2 );
  3804. }
  3805. } else if ( geometry.isBufferGeometry ) {
  3806. var attribute = geometry.attributes.position;
  3807. if ( attribute !== undefined ) {
  3808. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3809. _vector$2.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld );
  3810. this.expandByPoint( _vector$2 );
  3811. }
  3812. }
  3813. }
  3814. }
  3815. //
  3816. var children = object.children;
  3817. for ( i = 0, l = children.length; i < l; i ++ ) {
  3818. this.expandByObject( children[ i ] );
  3819. }
  3820. return this;
  3821. },
  3822. containsPoint: function ( point ) {
  3823. return point.x < this.min.x || point.x > this.max.x ||
  3824. point.y < this.min.y || point.y > this.max.y ||
  3825. point.z < this.min.z || point.z > this.max.z ? false : true;
  3826. },
  3827. containsBox: function ( box ) {
  3828. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3829. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3830. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3831. },
  3832. getParameter: function ( point, target ) {
  3833. // This can potentially have a divide by zero if the box
  3834. // has a size dimension of 0.
  3835. if ( target === undefined ) {
  3836. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3837. target = new Vector3();
  3838. }
  3839. return target.set(
  3840. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3841. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3842. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3843. );
  3844. },
  3845. intersectsBox: function ( box ) {
  3846. // using 6 splitting planes to rule out intersections.
  3847. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3848. box.max.y < this.min.y || box.min.y > this.max.y ||
  3849. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3850. },
  3851. intersectsSphere: function ( sphere ) {
  3852. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3853. // Find the point on the AABB closest to the sphere center.
  3854. this.clampPoint( sphere.center, _vector$2 );
  3855. // If that point is inside the sphere, the AABB and sphere intersect.
  3856. return _vector$2.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3857. },
  3858. intersectsPlane: function ( plane ) {
  3859. // We compute the minimum and maximum dot product values. If those values
  3860. // are on the same side (back or front) of the plane, then there is no intersection.
  3861. var min, max;
  3862. if ( plane.normal.x > 0 ) {
  3863. min = plane.normal.x * this.min.x;
  3864. max = plane.normal.x * this.max.x;
  3865. } else {
  3866. min = plane.normal.x * this.max.x;
  3867. max = plane.normal.x * this.min.x;
  3868. }
  3869. if ( plane.normal.y > 0 ) {
  3870. min += plane.normal.y * this.min.y;
  3871. max += plane.normal.y * this.max.y;
  3872. } else {
  3873. min += plane.normal.y * this.max.y;
  3874. max += plane.normal.y * this.min.y;
  3875. }
  3876. if ( plane.normal.z > 0 ) {
  3877. min += plane.normal.z * this.min.z;
  3878. max += plane.normal.z * this.max.z;
  3879. } else {
  3880. min += plane.normal.z * this.max.z;
  3881. max += plane.normal.z * this.min.z;
  3882. }
  3883. return ( min <= - plane.constant && max >= - plane.constant );
  3884. },
  3885. intersectsTriangle: function ( triangle ) {
  3886. if ( _v0 === undefined ) {
  3887. // triangle centered vertices
  3888. _v0 = new Vector3();
  3889. _v1$2 = new Vector3();
  3890. _v2 = new Vector3();
  3891. // triangle edge vectors
  3892. _f0 = new Vector3();
  3893. _f1 = new Vector3();
  3894. _f2 = new Vector3();
  3895. _center = new Vector3();
  3896. _extents = new Vector3();
  3897. _triangleNormal = new Vector3();
  3898. }
  3899. if ( this.isEmpty() ) {
  3900. return false;
  3901. }
  3902. // compute box center and extents
  3903. this.getCenter( _center );
  3904. _extents.subVectors( this.max, _center );
  3905. // translate triangle to aabb origin
  3906. _v0.subVectors( triangle.a, _center );
  3907. _v1$2.subVectors( triangle.b, _center );
  3908. _v2.subVectors( triangle.c, _center );
  3909. // compute edge vectors for triangle
  3910. _f0.subVectors( _v1$2, _v0 );
  3911. _f1.subVectors( _v2, _v1$2 );
  3912. _f2.subVectors( _v0, _v2 );
  3913. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3914. // 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
  3915. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3916. var axes = [
  3917. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  3918. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  3919. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  3920. ];
  3921. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  3922. return false;
  3923. }
  3924. // test 3 face normals from the aabb
  3925. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3926. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  3927. return false;
  3928. }
  3929. // finally testing the face normal of the triangle
  3930. // use already existing triangle edge vectors here
  3931. _triangleNormal.crossVectors( _f0, _f1 );
  3932. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  3933. return satForAxes( axes, _v0, _v1$2, _v2, _extents );
  3934. },
  3935. clampPoint: function ( point, target ) {
  3936. if ( target === undefined ) {
  3937. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3938. target = new Vector3();
  3939. }
  3940. return target.copy( point ).clamp( this.min, this.max );
  3941. },
  3942. distanceToPoint: function ( point ) {
  3943. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3944. var clampedPoint = _vector$2.copy( point ).clamp( this.min, this.max );
  3945. return clampedPoint.sub( point ).length();
  3946. },
  3947. getBoundingSphere: function ( target ) {
  3948. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3949. if ( target === undefined ) {
  3950. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3951. //target = new Sphere(); // removed to avoid cyclic dependency
  3952. }
  3953. this.getCenter( target.center );
  3954. target.radius = this.getSize( _vector$2 ).length() * 0.5;
  3955. return target;
  3956. },
  3957. intersect: function ( box ) {
  3958. this.min.max( box.min );
  3959. this.max.min( box.max );
  3960. // 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.
  3961. if ( this.isEmpty() ) this.makeEmpty();
  3962. return this;
  3963. },
  3964. union: function ( box ) {
  3965. this.min.min( box.min );
  3966. this.max.max( box.max );
  3967. return this;
  3968. },
  3969. applyMatrix4: function ( matrix ) {
  3970. if ( _points === undefined ) {
  3971. _points = [
  3972. new Vector3(),
  3973. new Vector3(),
  3974. new Vector3(),
  3975. new Vector3(),
  3976. new Vector3(),
  3977. new Vector3(),
  3978. new Vector3(),
  3979. new Vector3()
  3980. ];
  3981. }
  3982. // transform of empty box is an empty box.
  3983. if ( this.isEmpty() ) return this;
  3984. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3985. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3986. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3987. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3988. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3989. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3990. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3991. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3992. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3993. this.setFromPoints( _points );
  3994. return this;
  3995. },
  3996. translate: function ( offset ) {
  3997. this.min.add( offset );
  3998. this.max.add( offset );
  3999. return this;
  4000. },
  4001. equals: function ( box ) {
  4002. return box.min.equals( this.min ) && box.max.equals( this.max );
  4003. }
  4004. } );
  4005. var _testAxis;
  4006. function satForAxes( axes, v0, v1, v2, extents ) {
  4007. if ( _testAxis === undefined ) _testAxis = new Vector3();
  4008. var i, j;
  4009. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  4010. _testAxis.fromArray( axes, i );
  4011. // project the aabb onto the seperating axis
  4012. var r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  4013. // project all 3 vertices of the triangle onto the seperating axis
  4014. var p0 = v0.dot( _testAxis );
  4015. var p1 = v1.dot( _testAxis );
  4016. var p2 = v2.dot( _testAxis );
  4017. // actual test, basically see if either of the most extreme of the triangle points intersects r
  4018. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  4019. // points of the projected triangle are outside the projected half-length of the aabb
  4020. // the axis is seperating and we can exit
  4021. return false;
  4022. }
  4023. }
  4024. return true;
  4025. }
  4026. /**
  4027. * @author bhouston / http://clara.io
  4028. * @author mrdoob / http://mrdoob.com/
  4029. */
  4030. var _box;
  4031. function Sphere( center, radius ) {
  4032. this.center = ( center !== undefined ) ? center : new Vector3();
  4033. this.radius = ( radius !== undefined ) ? radius : 0;
  4034. }
  4035. Object.assign( Sphere.prototype, {
  4036. set: function ( center, radius ) {
  4037. this.center.copy( center );
  4038. this.radius = radius;
  4039. return this;
  4040. },
  4041. setFromPoints: function ( points, optionalCenter ) {
  4042. if ( _box === undefined ) _box = new Box3();
  4043. var center = this.center;
  4044. if ( optionalCenter !== undefined ) {
  4045. center.copy( optionalCenter );
  4046. } else {
  4047. _box.setFromPoints( points ).getCenter( center );
  4048. }
  4049. var maxRadiusSq = 0;
  4050. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4051. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4052. }
  4053. this.radius = Math.sqrt( maxRadiusSq );
  4054. return this;
  4055. },
  4056. clone: function () {
  4057. return new this.constructor().copy( this );
  4058. },
  4059. copy: function ( sphere ) {
  4060. this.center.copy( sphere.center );
  4061. this.radius = sphere.radius;
  4062. return this;
  4063. },
  4064. empty: function () {
  4065. return ( this.radius <= 0 );
  4066. },
  4067. containsPoint: function ( point ) {
  4068. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4069. },
  4070. distanceToPoint: function ( point ) {
  4071. return ( point.distanceTo( this.center ) - this.radius );
  4072. },
  4073. intersectsSphere: function ( sphere ) {
  4074. var radiusSum = this.radius + sphere.radius;
  4075. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4076. },
  4077. intersectsBox: function ( box ) {
  4078. return box.intersectsSphere( this );
  4079. },
  4080. intersectsPlane: function ( plane ) {
  4081. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4082. },
  4083. clampPoint: function ( point, target ) {
  4084. var deltaLengthSq = this.center.distanceToSquared( point );
  4085. if ( target === undefined ) {
  4086. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4087. target = new Vector3();
  4088. }
  4089. target.copy( point );
  4090. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4091. target.sub( this.center ).normalize();
  4092. target.multiplyScalar( this.radius ).add( this.center );
  4093. }
  4094. return target;
  4095. },
  4096. getBoundingBox: function ( target ) {
  4097. if ( target === undefined ) {
  4098. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4099. target = new Box3();
  4100. }
  4101. target.set( this.center, this.center );
  4102. target.expandByScalar( this.radius );
  4103. return target;
  4104. },
  4105. applyMatrix4: function ( matrix ) {
  4106. this.center.applyMatrix4( matrix );
  4107. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4108. return this;
  4109. },
  4110. translate: function ( offset ) {
  4111. this.center.add( offset );
  4112. return this;
  4113. },
  4114. equals: function ( sphere ) {
  4115. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4116. }
  4117. } );
  4118. /**
  4119. * @author bhouston / http://clara.io
  4120. */
  4121. var _vector$3;
  4122. var _segCenter, _segDir, _diff;
  4123. var _diff, _edge1, _edge2, _normal;
  4124. function Ray( origin, direction ) {
  4125. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4126. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  4127. }
  4128. Object.assign( Ray.prototype, {
  4129. set: function ( origin, direction ) {
  4130. this.origin.copy( origin );
  4131. this.direction.copy( direction );
  4132. return this;
  4133. },
  4134. clone: function () {
  4135. return new this.constructor().copy( this );
  4136. },
  4137. copy: function ( ray ) {
  4138. this.origin.copy( ray.origin );
  4139. this.direction.copy( ray.direction );
  4140. return this;
  4141. },
  4142. at: function ( t, target ) {
  4143. if ( target === undefined ) {
  4144. console.warn( 'THREE.Ray: .at() target is now required' );
  4145. target = new Vector3();
  4146. }
  4147. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4148. },
  4149. lookAt: function ( v ) {
  4150. this.direction.copy( v ).sub( this.origin ).normalize();
  4151. return this;
  4152. },
  4153. recast: function ( t ) {
  4154. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4155. this.origin.copy( this.at( t, _vector$3 ) );
  4156. return this;
  4157. },
  4158. closestPointToPoint: function ( point, target ) {
  4159. if ( target === undefined ) {
  4160. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4161. target = new Vector3();
  4162. }
  4163. target.subVectors( point, this.origin );
  4164. var directionDistance = target.dot( this.direction );
  4165. if ( directionDistance < 0 ) {
  4166. return target.copy( this.origin );
  4167. }
  4168. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4169. },
  4170. distanceToPoint: function ( point ) {
  4171. return Math.sqrt( this.distanceSqToPoint( point ) );
  4172. },
  4173. distanceSqToPoint: function ( point ) {
  4174. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4175. var directionDistance = _vector$3.subVectors( point, this.origin ).dot( this.direction );
  4176. // point behind the ray
  4177. if ( directionDistance < 0 ) {
  4178. return this.origin.distanceToSquared( point );
  4179. }
  4180. _vector$3.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4181. return _vector$3.distanceToSquared( point );
  4182. },
  4183. distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4184. if ( _segCenter === undefined ) {
  4185. _segCenter = new Vector3();
  4186. _segDir = new Vector3();
  4187. _diff = new Vector3();
  4188. }
  4189. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4190. // It returns the min distance between the ray and the segment
  4191. // defined by v0 and v1
  4192. // It can also set two optional targets :
  4193. // - The closest point on the ray
  4194. // - The closest point on the segment
  4195. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4196. _segDir.copy( v1 ).sub( v0 ).normalize();
  4197. _diff.copy( this.origin ).sub( _segCenter );
  4198. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4199. var a01 = - this.direction.dot( _segDir );
  4200. var b0 = _diff.dot( this.direction );
  4201. var b1 = - _diff.dot( _segDir );
  4202. var c = _diff.lengthSq();
  4203. var det = Math.abs( 1 - a01 * a01 );
  4204. var s0, s1, sqrDist, extDet;
  4205. if ( det > 0 ) {
  4206. // The ray and segment are not parallel.
  4207. s0 = a01 * b1 - b0;
  4208. s1 = a01 * b0 - b1;
  4209. extDet = segExtent * det;
  4210. if ( s0 >= 0 ) {
  4211. if ( s1 >= - extDet ) {
  4212. if ( s1 <= extDet ) {
  4213. // region 0
  4214. // Minimum at interior points of ray and segment.
  4215. var invDet = 1 / det;
  4216. s0 *= invDet;
  4217. s1 *= invDet;
  4218. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4219. } else {
  4220. // region 1
  4221. s1 = segExtent;
  4222. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4223. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4224. }
  4225. } else {
  4226. // region 5
  4227. s1 = - segExtent;
  4228. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4229. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4230. }
  4231. } else {
  4232. if ( s1 <= - extDet ) {
  4233. // region 4
  4234. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4235. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4236. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4237. } else if ( s1 <= extDet ) {
  4238. // region 3
  4239. s0 = 0;
  4240. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4241. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4242. } else {
  4243. // region 2
  4244. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4245. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4246. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4247. }
  4248. }
  4249. } else {
  4250. // Ray and segment are parallel.
  4251. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4252. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4253. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4254. }
  4255. if ( optionalPointOnRay ) {
  4256. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4257. }
  4258. if ( optionalPointOnSegment ) {
  4259. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  4260. }
  4261. return sqrDist;
  4262. },
  4263. intersectSphere: function ( sphere, target ) {
  4264. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4265. _vector$3.subVectors( sphere.center, this.origin );
  4266. var tca = _vector$3.dot( this.direction );
  4267. var d2 = _vector$3.dot( _vector$3 ) - tca * tca;
  4268. var radius2 = sphere.radius * sphere.radius;
  4269. if ( d2 > radius2 ) return null;
  4270. var thc = Math.sqrt( radius2 - d2 );
  4271. // t0 = first intersect point - entrance on front of sphere
  4272. var t0 = tca - thc;
  4273. // t1 = second intersect point - exit point on back of sphere
  4274. var t1 = tca + thc;
  4275. // test to see if both t0 and t1 are behind the ray - if so, return null
  4276. if ( t0 < 0 && t1 < 0 ) return null;
  4277. // test to see if t0 is behind the ray:
  4278. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4279. // in order to always return an intersect point that is in front of the ray.
  4280. if ( t0 < 0 ) return this.at( t1, target );
  4281. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4282. return this.at( t0, target );
  4283. },
  4284. intersectsSphere: function ( sphere ) {
  4285. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4286. },
  4287. distanceToPlane: function ( plane ) {
  4288. var denominator = plane.normal.dot( this.direction );
  4289. if ( denominator === 0 ) {
  4290. // line is coplanar, return origin
  4291. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4292. return 0;
  4293. }
  4294. // Null is preferable to undefined since undefined means.... it is undefined
  4295. return null;
  4296. }
  4297. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4298. // Return if the ray never intersects the plane
  4299. return t >= 0 ? t : null;
  4300. },
  4301. intersectPlane: function ( plane, target ) {
  4302. var t = this.distanceToPlane( plane );
  4303. if ( t === null ) {
  4304. return null;
  4305. }
  4306. return this.at( t, target );
  4307. },
  4308. intersectsPlane: function ( plane ) {
  4309. // check if the ray lies on the plane first
  4310. var distToPoint = plane.distanceToPoint( this.origin );
  4311. if ( distToPoint === 0 ) {
  4312. return true;
  4313. }
  4314. var denominator = plane.normal.dot( this.direction );
  4315. if ( denominator * distToPoint < 0 ) {
  4316. return true;
  4317. }
  4318. // ray origin is behind the plane (and is pointing behind it)
  4319. return false;
  4320. },
  4321. intersectBox: function ( box, target ) {
  4322. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4323. var invdirx = 1 / this.direction.x,
  4324. invdiry = 1 / this.direction.y,
  4325. invdirz = 1 / this.direction.z;
  4326. var origin = this.origin;
  4327. if ( invdirx >= 0 ) {
  4328. tmin = ( box.min.x - origin.x ) * invdirx;
  4329. tmax = ( box.max.x - origin.x ) * invdirx;
  4330. } else {
  4331. tmin = ( box.max.x - origin.x ) * invdirx;
  4332. tmax = ( box.min.x - origin.x ) * invdirx;
  4333. }
  4334. if ( invdiry >= 0 ) {
  4335. tymin = ( box.min.y - origin.y ) * invdiry;
  4336. tymax = ( box.max.y - origin.y ) * invdiry;
  4337. } else {
  4338. tymin = ( box.max.y - origin.y ) * invdiry;
  4339. tymax = ( box.min.y - origin.y ) * invdiry;
  4340. }
  4341. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4342. // These lines also handle the case where tmin or tmax is NaN
  4343. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4344. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4345. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4346. if ( invdirz >= 0 ) {
  4347. tzmin = ( box.min.z - origin.z ) * invdirz;
  4348. tzmax = ( box.max.z - origin.z ) * invdirz;
  4349. } else {
  4350. tzmin = ( box.max.z - origin.z ) * invdirz;
  4351. tzmax = ( box.min.z - origin.z ) * invdirz;
  4352. }
  4353. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4354. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4355. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4356. //return point closest to the ray (positive side)
  4357. if ( tmax < 0 ) return null;
  4358. return this.at( tmin >= 0 ? tmin : tmax, target );
  4359. },
  4360. intersectsBox: function ( box ) {
  4361. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4362. return this.intersectBox( box, _vector$3 ) !== null;
  4363. },
  4364. intersectTriangle: function ( a, b, c, backfaceCulling, target ) {
  4365. // Compute the offset origin, edges, and normal.
  4366. if ( _diff === undefined ) {
  4367. _diff = new Vector3();
  4368. _edge1 = new Vector3();
  4369. _edge2 = new Vector3();
  4370. _normal = new Vector3();
  4371. }
  4372. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4373. _edge1.subVectors( b, a );
  4374. _edge2.subVectors( c, a );
  4375. _normal.crossVectors( _edge1, _edge2 );
  4376. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4377. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4378. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4379. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4380. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4381. var DdN = this.direction.dot( _normal );
  4382. var sign;
  4383. if ( DdN > 0 ) {
  4384. if ( backfaceCulling ) return null;
  4385. sign = 1;
  4386. } else if ( DdN < 0 ) {
  4387. sign = - 1;
  4388. DdN = - DdN;
  4389. } else {
  4390. return null;
  4391. }
  4392. _diff.subVectors( this.origin, a );
  4393. var DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  4394. // b1 < 0, no intersection
  4395. if ( DdQxE2 < 0 ) {
  4396. return null;
  4397. }
  4398. var DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  4399. // b2 < 0, no intersection
  4400. if ( DdE1xQ < 0 ) {
  4401. return null;
  4402. }
  4403. // b1+b2 > 1, no intersection
  4404. if ( DdQxE2 + DdE1xQ > DdN ) {
  4405. return null;
  4406. }
  4407. // Line intersects triangle, check if ray does.
  4408. var QdN = - sign * _diff.dot( _normal );
  4409. // t < 0, no intersection
  4410. if ( QdN < 0 ) {
  4411. return null;
  4412. }
  4413. // Ray intersects triangle.
  4414. return this.at( QdN / DdN, target );
  4415. },
  4416. applyMatrix4: function ( matrix4 ) {
  4417. this.origin.applyMatrix4( matrix4 );
  4418. this.direction.transformDirection( matrix4 );
  4419. return this;
  4420. },
  4421. equals: function ( ray ) {
  4422. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4423. }
  4424. } );
  4425. /**
  4426. * @author bhouston / http://clara.io
  4427. * @author mrdoob / http://mrdoob.com/
  4428. */
  4429. var _v0$1, _v1$3, _v2$1, _v3;
  4430. var _vab, _vac, _vbc, _vap, _vbp, _vcp;
  4431. function Triangle( a, b, c ) {
  4432. this.a = ( a !== undefined ) ? a : new Vector3();
  4433. this.b = ( b !== undefined ) ? b : new Vector3();
  4434. this.c = ( c !== undefined ) ? c : new Vector3();
  4435. }
  4436. Object.assign( Triangle, {
  4437. getNormal: function ( a, b, c, target ) {
  4438. if ( _v0$1 === undefined ) _v0$1 = new Vector3();
  4439. if ( target === undefined ) {
  4440. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4441. target = new Vector3();
  4442. }
  4443. target.subVectors( c, b );
  4444. _v0$1.subVectors( a, b );
  4445. target.cross( _v0$1 );
  4446. var targetLengthSq = target.lengthSq();
  4447. if ( targetLengthSq > 0 ) {
  4448. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4449. }
  4450. return target.set( 0, 0, 0 );
  4451. },
  4452. // static/instance method to calculate barycentric coordinates
  4453. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4454. getBarycoord: function ( point, a, b, c, target ) {
  4455. if ( _v2$1 === undefined ) {
  4456. _v0$1 = new Vector3();
  4457. _v1$3 = new Vector3();
  4458. _v2$1 = new Vector3();
  4459. }
  4460. _v0$1.subVectors( c, a );
  4461. _v1$3.subVectors( b, a );
  4462. _v2$1.subVectors( point, a );
  4463. var dot00 = _v0$1.dot( _v0$1 );
  4464. var dot01 = _v0$1.dot( _v1$3 );
  4465. var dot02 = _v0$1.dot( _v2$1 );
  4466. var dot11 = _v1$3.dot( _v1$3 );
  4467. var dot12 = _v1$3.dot( _v2$1 );
  4468. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4469. if ( target === undefined ) {
  4470. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4471. target = new Vector3();
  4472. }
  4473. // collinear or singular triangle
  4474. if ( denom === 0 ) {
  4475. // arbitrary location outside of triangle?
  4476. // not sure if this is the best idea, maybe should be returning undefined
  4477. return target.set( - 2, - 1, - 1 );
  4478. }
  4479. var invDenom = 1 / denom;
  4480. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4481. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4482. // barycentric coordinates must always sum to 1
  4483. return target.set( 1 - u - v, v, u );
  4484. },
  4485. containsPoint: function ( point, a, b, c ) {
  4486. if ( _v3 === undefined ) _v3 = new Vector3();
  4487. Triangle.getBarycoord( point, a, b, c, _v3 );
  4488. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4489. },
  4490. getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4491. if ( _v3 === undefined ) _v3 = new Vector3();
  4492. this.getBarycoord( point, p1, p2, p3, _v3 );
  4493. target.set( 0, 0 );
  4494. target.addScaledVector( uv1, _v3.x );
  4495. target.addScaledVector( uv2, _v3.y );
  4496. target.addScaledVector( uv3, _v3.z );
  4497. return target;
  4498. },
  4499. isFrontFacing: function ( a, b, c, direction ) {
  4500. if ( _v1$3 === undefined ) {
  4501. _v0$1 = new Vector3();
  4502. _v1$3 = new Vector3();
  4503. }
  4504. _v0$1.subVectors( c, b );
  4505. _v1$3.subVectors( a, b );
  4506. // strictly front facing
  4507. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4508. }
  4509. } );
  4510. Object.assign( Triangle.prototype, {
  4511. set: function ( a, b, c ) {
  4512. this.a.copy( a );
  4513. this.b.copy( b );
  4514. this.c.copy( c );
  4515. return this;
  4516. },
  4517. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4518. this.a.copy( points[ i0 ] );
  4519. this.b.copy( points[ i1 ] );
  4520. this.c.copy( points[ i2 ] );
  4521. return this;
  4522. },
  4523. clone: function () {
  4524. return new this.constructor().copy( this );
  4525. },
  4526. copy: function ( triangle ) {
  4527. this.a.copy( triangle.a );
  4528. this.b.copy( triangle.b );
  4529. this.c.copy( triangle.c );
  4530. return this;
  4531. },
  4532. getArea: function () {
  4533. if ( _v1$3 === undefined ) {
  4534. _v0$1 = new Vector3();
  4535. _v1$3 = new Vector3();
  4536. }
  4537. _v0$1.subVectors( this.c, this.b );
  4538. _v1$3.subVectors( this.a, this.b );
  4539. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4540. },
  4541. getMidpoint: function ( target ) {
  4542. if ( target === undefined ) {
  4543. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4544. target = new Vector3();
  4545. }
  4546. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4547. },
  4548. getNormal: function ( target ) {
  4549. return Triangle.getNormal( this.a, this.b, this.c, target );
  4550. },
  4551. getPlane: function ( target ) {
  4552. if ( target === undefined ) {
  4553. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4554. target = new Vector3();
  4555. }
  4556. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4557. },
  4558. getBarycoord: function ( point, target ) {
  4559. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4560. },
  4561. getUV: function ( point, uv1, uv2, uv3, target ) {
  4562. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4563. },
  4564. containsPoint: function ( point ) {
  4565. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4566. },
  4567. isFrontFacing: function ( direction ) {
  4568. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4569. },
  4570. intersectsBox: function ( box ) {
  4571. return box.intersectsTriangle( this );
  4572. },
  4573. closestPointToPoint: function ( p, target ) {
  4574. if ( _vab === undefined ) {
  4575. _vab = new Vector3();
  4576. _vac = new Vector3();
  4577. _vbc = new Vector3();
  4578. _vap = new Vector3();
  4579. _vbp = new Vector3();
  4580. _vcp = new Vector3();
  4581. }
  4582. if ( target === undefined ) {
  4583. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4584. target = new Vector3();
  4585. }
  4586. var a = this.a, b = this.b, c = this.c;
  4587. var v, w;
  4588. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4589. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4590. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4591. // basically, we're distinguishing which of the voronoi regions of the triangle
  4592. // the point lies in with the minimum amount of redundant computation.
  4593. _vab.subVectors( b, a );
  4594. _vac.subVectors( c, a );
  4595. _vap.subVectors( p, a );
  4596. var d1 = _vab.dot( _vap );
  4597. var d2 = _vac.dot( _vap );
  4598. if ( d1 <= 0 && d2 <= 0 ) {
  4599. // vertex region of A; barycentric coords (1, 0, 0)
  4600. return target.copy( a );
  4601. }
  4602. _vbp.subVectors( p, b );
  4603. var d3 = _vab.dot( _vbp );
  4604. var d4 = _vac.dot( _vbp );
  4605. if ( d3 >= 0 && d4 <= d3 ) {
  4606. // vertex region of B; barycentric coords (0, 1, 0)
  4607. return target.copy( b );
  4608. }
  4609. var vc = d1 * d4 - d3 * d2;
  4610. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4611. v = d1 / ( d1 - d3 );
  4612. // edge region of AB; barycentric coords (1-v, v, 0)
  4613. return target.copy( a ).addScaledVector( _vab, v );
  4614. }
  4615. _vcp.subVectors( p, c );
  4616. var d5 = _vab.dot( _vcp );
  4617. var d6 = _vac.dot( _vcp );
  4618. if ( d6 >= 0 && d5 <= d6 ) {
  4619. // vertex region of C; barycentric coords (0, 0, 1)
  4620. return target.copy( c );
  4621. }
  4622. var vb = d5 * d2 - d1 * d6;
  4623. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4624. w = d2 / ( d2 - d6 );
  4625. // edge region of AC; barycentric coords (1-w, 0, w)
  4626. return target.copy( a ).addScaledVector( _vac, w );
  4627. }
  4628. var va = d3 * d6 - d5 * d4;
  4629. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4630. _vbc.subVectors( c, b );
  4631. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4632. // edge region of BC; barycentric coords (0, 1-w, w)
  4633. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4634. }
  4635. // face region
  4636. var denom = 1 / ( va + vb + vc );
  4637. // u = va * denom
  4638. v = vb * denom;
  4639. w = vc * denom;
  4640. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4641. },
  4642. equals: function ( triangle ) {
  4643. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4644. }
  4645. } );
  4646. /**
  4647. * @author mrdoob / http://mrdoob.com/
  4648. */
  4649. var _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4650. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4651. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4652. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4653. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4654. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4655. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4656. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4657. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4658. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4659. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4660. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4661. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4662. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4663. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4664. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4665. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4666. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4667. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4668. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4669. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4670. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4671. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4672. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4673. var _hslA = { h: 0, s: 0, l: 0 };
  4674. var _hslB = { h: 0, s: 0, l: 0 };
  4675. function Color( r, g, b ) {
  4676. if ( g === undefined && b === undefined ) {
  4677. // r is THREE.Color, hex or string
  4678. return this.set( r );
  4679. }
  4680. return this.setRGB( r, g, b );
  4681. }
  4682. function hue2rgb( p, q, t ) {
  4683. if ( t < 0 ) t += 1;
  4684. if ( t > 1 ) t -= 1;
  4685. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4686. if ( t < 1 / 2 ) return q;
  4687. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4688. return p;
  4689. }
  4690. function SRGBToLinear( c ) {
  4691. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4692. }
  4693. function LinearToSRGB( c ) {
  4694. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4695. }
  4696. Object.assign( Color.prototype, {
  4697. isColor: true,
  4698. r: 1, g: 1, b: 1,
  4699. set: function ( value ) {
  4700. if ( value && value.isColor ) {
  4701. this.copy( value );
  4702. } else if ( typeof value === 'number' ) {
  4703. this.setHex( value );
  4704. } else if ( typeof value === 'string' ) {
  4705. this.setStyle( value );
  4706. }
  4707. return this;
  4708. },
  4709. setScalar: function ( scalar ) {
  4710. this.r = scalar;
  4711. this.g = scalar;
  4712. this.b = scalar;
  4713. return this;
  4714. },
  4715. setHex: function ( hex ) {
  4716. hex = Math.floor( hex );
  4717. this.r = ( hex >> 16 & 255 ) / 255;
  4718. this.g = ( hex >> 8 & 255 ) / 255;
  4719. this.b = ( hex & 255 ) / 255;
  4720. return this;
  4721. },
  4722. setRGB: function ( r, g, b ) {
  4723. this.r = r;
  4724. this.g = g;
  4725. this.b = b;
  4726. return this;
  4727. },
  4728. setHSL: function ( h, s, l ) {
  4729. // h,s,l ranges are in 0.0 - 1.0
  4730. h = _Math.euclideanModulo( h, 1 );
  4731. s = _Math.clamp( s, 0, 1 );
  4732. l = _Math.clamp( l, 0, 1 );
  4733. if ( s === 0 ) {
  4734. this.r = this.g = this.b = l;
  4735. } else {
  4736. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4737. var q = ( 2 * l ) - p;
  4738. this.r = hue2rgb( q, p, h + 1 / 3 );
  4739. this.g = hue2rgb( q, p, h );
  4740. this.b = hue2rgb( q, p, h - 1 / 3 );
  4741. }
  4742. return this;
  4743. },
  4744. setStyle: function ( style ) {
  4745. function handleAlpha( string ) {
  4746. if ( string === undefined ) return;
  4747. if ( parseFloat( string ) < 1 ) {
  4748. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4749. }
  4750. }
  4751. var m;
  4752. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4753. // rgb / hsl
  4754. var color;
  4755. var name = m[ 1 ];
  4756. var components = m[ 2 ];
  4757. switch ( name ) {
  4758. case 'rgb':
  4759. case 'rgba':
  4760. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4761. // rgb(255,0,0) rgba(255,0,0,0.5)
  4762. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4763. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4764. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4765. handleAlpha( color[ 5 ] );
  4766. return this;
  4767. }
  4768. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4769. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4770. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4771. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4772. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4773. handleAlpha( color[ 5 ] );
  4774. return this;
  4775. }
  4776. break;
  4777. case 'hsl':
  4778. case 'hsla':
  4779. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4780. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4781. var h = parseFloat( color[ 1 ] ) / 360;
  4782. var s = parseInt( color[ 2 ], 10 ) / 100;
  4783. var l = parseInt( color[ 3 ], 10 ) / 100;
  4784. handleAlpha( color[ 5 ] );
  4785. return this.setHSL( h, s, l );
  4786. }
  4787. break;
  4788. }
  4789. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4790. // hex color
  4791. var hex = m[ 1 ];
  4792. var size = hex.length;
  4793. if ( size === 3 ) {
  4794. // #ff0
  4795. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4796. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4797. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4798. return this;
  4799. } else if ( size === 6 ) {
  4800. // #ff0000
  4801. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4802. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4803. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4804. return this;
  4805. }
  4806. }
  4807. if ( style && style.length > 0 ) {
  4808. // color keywords
  4809. var hex = _colorKeywords[ style ];
  4810. if ( hex !== undefined ) {
  4811. // red
  4812. this.setHex( hex );
  4813. } else {
  4814. // unknown color
  4815. console.warn( 'THREE.Color: Unknown color ' + style );
  4816. }
  4817. }
  4818. return this;
  4819. },
  4820. clone: function () {
  4821. return new this.constructor( this.r, this.g, this.b );
  4822. },
  4823. copy: function ( color ) {
  4824. this.r = color.r;
  4825. this.g = color.g;
  4826. this.b = color.b;
  4827. return this;
  4828. },
  4829. copyGammaToLinear: function ( color, gammaFactor ) {
  4830. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4831. this.r = Math.pow( color.r, gammaFactor );
  4832. this.g = Math.pow( color.g, gammaFactor );
  4833. this.b = Math.pow( color.b, gammaFactor );
  4834. return this;
  4835. },
  4836. copyLinearToGamma: function ( color, gammaFactor ) {
  4837. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4838. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4839. this.r = Math.pow( color.r, safeInverse );
  4840. this.g = Math.pow( color.g, safeInverse );
  4841. this.b = Math.pow( color.b, safeInverse );
  4842. return this;
  4843. },
  4844. convertGammaToLinear: function ( gammaFactor ) {
  4845. this.copyGammaToLinear( this, gammaFactor );
  4846. return this;
  4847. },
  4848. convertLinearToGamma: function ( gammaFactor ) {
  4849. this.copyLinearToGamma( this, gammaFactor );
  4850. return this;
  4851. },
  4852. copySRGBToLinear: function ( color ) {
  4853. this.r = SRGBToLinear( color.r );
  4854. this.g = SRGBToLinear( color.g );
  4855. this.b = SRGBToLinear( color.b );
  4856. return this;
  4857. },
  4858. copyLinearToSRGB: function ( color ) {
  4859. this.r = LinearToSRGB( color.r );
  4860. this.g = LinearToSRGB( color.g );
  4861. this.b = LinearToSRGB( color.b );
  4862. return this;
  4863. },
  4864. convertSRGBToLinear: function () {
  4865. this.copySRGBToLinear( this );
  4866. return this;
  4867. },
  4868. convertLinearToSRGB: function () {
  4869. this.copyLinearToSRGB( this );
  4870. return this;
  4871. },
  4872. getHex: function () {
  4873. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4874. },
  4875. getHexString: function () {
  4876. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4877. },
  4878. getHSL: function ( target ) {
  4879. // h,s,l ranges are in 0.0 - 1.0
  4880. if ( target === undefined ) {
  4881. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4882. target = { h: 0, s: 0, l: 0 };
  4883. }
  4884. var r = this.r, g = this.g, b = this.b;
  4885. var max = Math.max( r, g, b );
  4886. var min = Math.min( r, g, b );
  4887. var hue, saturation;
  4888. var lightness = ( min + max ) / 2.0;
  4889. if ( min === max ) {
  4890. hue = 0;
  4891. saturation = 0;
  4892. } else {
  4893. var delta = max - min;
  4894. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4895. switch ( max ) {
  4896. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4897. case g: hue = ( b - r ) / delta + 2; break;
  4898. case b: hue = ( r - g ) / delta + 4; break;
  4899. }
  4900. hue /= 6;
  4901. }
  4902. target.h = hue;
  4903. target.s = saturation;
  4904. target.l = lightness;
  4905. return target;
  4906. },
  4907. getStyle: function () {
  4908. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4909. },
  4910. offsetHSL: function ( h, s, l ) {
  4911. this.getHSL( _hslA );
  4912. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  4913. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  4914. return this;
  4915. },
  4916. add: function ( color ) {
  4917. this.r += color.r;
  4918. this.g += color.g;
  4919. this.b += color.b;
  4920. return this;
  4921. },
  4922. addColors: function ( color1, color2 ) {
  4923. this.r = color1.r + color2.r;
  4924. this.g = color1.g + color2.g;
  4925. this.b = color1.b + color2.b;
  4926. return this;
  4927. },
  4928. addScalar: function ( s ) {
  4929. this.r += s;
  4930. this.g += s;
  4931. this.b += s;
  4932. return this;
  4933. },
  4934. sub: function ( color ) {
  4935. this.r = Math.max( 0, this.r - color.r );
  4936. this.g = Math.max( 0, this.g - color.g );
  4937. this.b = Math.max( 0, this.b - color.b );
  4938. return this;
  4939. },
  4940. multiply: function ( color ) {
  4941. this.r *= color.r;
  4942. this.g *= color.g;
  4943. this.b *= color.b;
  4944. return this;
  4945. },
  4946. multiplyScalar: function ( s ) {
  4947. this.r *= s;
  4948. this.g *= s;
  4949. this.b *= s;
  4950. return this;
  4951. },
  4952. lerp: function ( color, alpha ) {
  4953. this.r += ( color.r - this.r ) * alpha;
  4954. this.g += ( color.g - this.g ) * alpha;
  4955. this.b += ( color.b - this.b ) * alpha;
  4956. return this;
  4957. },
  4958. lerpHSL: function ( color, alpha ) {
  4959. this.getHSL( _hslA );
  4960. color.getHSL( _hslB );
  4961. var h = _Math.lerp( _hslA.h, _hslB.h, alpha );
  4962. var s = _Math.lerp( _hslA.s, _hslB.s, alpha );
  4963. var l = _Math.lerp( _hslA.l, _hslB.l, alpha );
  4964. this.setHSL( h, s, l );
  4965. return this;
  4966. },
  4967. equals: function ( c ) {
  4968. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4969. },
  4970. fromArray: function ( array, offset ) {
  4971. if ( offset === undefined ) offset = 0;
  4972. this.r = array[ offset ];
  4973. this.g = array[ offset + 1 ];
  4974. this.b = array[ offset + 2 ];
  4975. return this;
  4976. },
  4977. toArray: function ( array, offset ) {
  4978. if ( array === undefined ) array = [];
  4979. if ( offset === undefined ) offset = 0;
  4980. array[ offset ] = this.r;
  4981. array[ offset + 1 ] = this.g;
  4982. array[ offset + 2 ] = this.b;
  4983. return array;
  4984. },
  4985. toJSON: function () {
  4986. return this.getHex();
  4987. }
  4988. } );
  4989. /**
  4990. * @author mrdoob / http://mrdoob.com/
  4991. * @author alteredq / http://alteredqualia.com/
  4992. */
  4993. function Face3( a, b, c, normal, color, materialIndex ) {
  4994. this.a = a;
  4995. this.b = b;
  4996. this.c = c;
  4997. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4998. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4999. this.color = ( color && color.isColor ) ? color : new Color();
  5000. this.vertexColors = Array.isArray( color ) ? color : [];
  5001. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5002. }
  5003. Object.assign( Face3.prototype, {
  5004. clone: function () {
  5005. return new this.constructor().copy( this );
  5006. },
  5007. copy: function ( source ) {
  5008. this.a = source.a;
  5009. this.b = source.b;
  5010. this.c = source.c;
  5011. this.normal.copy( source.normal );
  5012. this.color.copy( source.color );
  5013. this.materialIndex = source.materialIndex;
  5014. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5015. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5016. }
  5017. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5018. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5019. }
  5020. return this;
  5021. }
  5022. } );
  5023. /**
  5024. * @author mrdoob / http://mrdoob.com/
  5025. * @author alteredq / http://alteredqualia.com/
  5026. */
  5027. var materialId = 0;
  5028. function Material() {
  5029. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5030. this.uuid = _Math.generateUUID();
  5031. this.name = '';
  5032. this.type = 'Material';
  5033. this.fog = true;
  5034. this.lights = true;
  5035. this.blending = NormalBlending;
  5036. this.side = FrontSide;
  5037. this.flatShading = false;
  5038. this.vertexTangents = false;
  5039. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  5040. this.opacity = 1;
  5041. this.transparent = false;
  5042. this.blendSrc = SrcAlphaFactor;
  5043. this.blendDst = OneMinusSrcAlphaFactor;
  5044. this.blendEquation = AddEquation;
  5045. this.blendSrcAlpha = null;
  5046. this.blendDstAlpha = null;
  5047. this.blendEquationAlpha = null;
  5048. this.depthFunc = LessEqualDepth;
  5049. this.depthTest = true;
  5050. this.depthWrite = true;
  5051. this.stencilFunc = AlwaysStencilFunc;
  5052. this.stencilRef = 0;
  5053. this.stencilMask = 0xff;
  5054. this.stencilFail = KeepStencilOp;
  5055. this.stencilZFail = KeepStencilOp;
  5056. this.stencilZPass = KeepStencilOp;
  5057. this.stencilWrite = false;
  5058. this.clippingPlanes = null;
  5059. this.clipIntersection = false;
  5060. this.clipShadows = false;
  5061. this.shadowSide = null;
  5062. this.colorWrite = true;
  5063. this.precision = null; // override the renderer's default precision for this material
  5064. this.polygonOffset = false;
  5065. this.polygonOffsetFactor = 0;
  5066. this.polygonOffsetUnits = 0;
  5067. this.dithering = false;
  5068. this.alphaTest = 0;
  5069. this.premultipliedAlpha = false;
  5070. this.visible = true;
  5071. this.userData = {};
  5072. this.needsUpdate = true;
  5073. }
  5074. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5075. constructor: Material,
  5076. isMaterial: true,
  5077. onBeforeCompile: function () {},
  5078. setValues: function ( values ) {
  5079. if ( values === undefined ) return;
  5080. for ( var key in values ) {
  5081. var newValue = values[ key ];
  5082. if ( newValue === undefined ) {
  5083. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5084. continue;
  5085. }
  5086. // for backward compatability if shading is set in the constructor
  5087. if ( key === 'shading' ) {
  5088. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5089. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5090. continue;
  5091. }
  5092. var currentValue = this[ key ];
  5093. if ( currentValue === undefined ) {
  5094. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5095. continue;
  5096. }
  5097. if ( currentValue && currentValue.isColor ) {
  5098. currentValue.set( newValue );
  5099. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5100. currentValue.copy( newValue );
  5101. } else {
  5102. this[ key ] = newValue;
  5103. }
  5104. }
  5105. },
  5106. toJSON: function ( meta ) {
  5107. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5108. if ( isRoot ) {
  5109. meta = {
  5110. textures: {},
  5111. images: {}
  5112. };
  5113. }
  5114. var data = {
  5115. metadata: {
  5116. version: 4.5,
  5117. type: 'Material',
  5118. generator: 'Material.toJSON'
  5119. }
  5120. };
  5121. // standard Material serialization
  5122. data.uuid = this.uuid;
  5123. data.type = this.type;
  5124. if ( this.name !== '' ) data.name = this.name;
  5125. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5126. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5127. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5128. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5129. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5130. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5131. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5132. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  5133. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  5134. if ( this.clearCoatNormalMap && this.clearCoatNormalMap.isTexture ) {
  5135. data.clearCoatNormalMap = this.clearCoatNormalMap.toJSON( meta ).uuid;
  5136. data.clearCoatNormalScale = this.clearCoatNormalScale.toArray();
  5137. }
  5138. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5139. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5140. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5141. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5142. if ( this.aoMap && this.aoMap.isTexture ) {
  5143. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5144. data.aoMapIntensity = this.aoMapIntensity;
  5145. }
  5146. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5147. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5148. data.bumpScale = this.bumpScale;
  5149. }
  5150. if ( this.normalMap && this.normalMap.isTexture ) {
  5151. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5152. data.normalMapType = this.normalMapType;
  5153. data.normalScale = this.normalScale.toArray();
  5154. }
  5155. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5156. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5157. data.displacementScale = this.displacementScale;
  5158. data.displacementBias = this.displacementBias;
  5159. }
  5160. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5161. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5162. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5163. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5164. if ( this.envMap && this.envMap.isTexture ) {
  5165. data.envMap = this.envMap.toJSON( meta ).uuid;
  5166. data.reflectivity = this.reflectivity; // Scale behind envMap
  5167. data.refractionRatio = this.refractionRatio;
  5168. if ( this.combine !== undefined ) data.combine = this.combine;
  5169. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5170. }
  5171. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5172. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5173. }
  5174. if ( this.size !== undefined ) data.size = this.size;
  5175. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5176. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5177. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5178. if ( this.side !== FrontSide ) data.side = this.side;
  5179. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  5180. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5181. if ( this.transparent === true ) data.transparent = this.transparent;
  5182. data.depthFunc = this.depthFunc;
  5183. data.depthTest = this.depthTest;
  5184. data.depthWrite = this.depthWrite;
  5185. data.stencilWrite = this.stencilWrite;
  5186. data.stencilFunc = this.stencilFunc;
  5187. data.stencilRef = this.stencilRef;
  5188. data.stencilMask = this.stencilMask;
  5189. data.stencilFail = this.stencilFail;
  5190. data.stencilZFail = this.stencilZFail;
  5191. data.stencilZPass = this.stencilZPass;
  5192. // rotation (SpriteMaterial)
  5193. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5194. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5195. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5196. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5197. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5198. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5199. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5200. if ( this.scale !== undefined ) data.scale = this.scale;
  5201. if ( this.dithering === true ) data.dithering = true;
  5202. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5203. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5204. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5205. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5206. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5207. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5208. if ( this.morphTargets === true ) data.morphTargets = true;
  5209. if ( this.morphNormals === true ) data.morphNormals = true;
  5210. if ( this.skinning === true ) data.skinning = true;
  5211. if ( this.visible === false ) data.visible = false;
  5212. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5213. // TODO: Copied from Object3D.toJSON
  5214. function extractFromCache( cache ) {
  5215. var values = [];
  5216. for ( var key in cache ) {
  5217. var data = cache[ key ];
  5218. delete data.metadata;
  5219. values.push( data );
  5220. }
  5221. return values;
  5222. }
  5223. if ( isRoot ) {
  5224. var textures = extractFromCache( meta.textures );
  5225. var images = extractFromCache( meta.images );
  5226. if ( textures.length > 0 ) data.textures = textures;
  5227. if ( images.length > 0 ) data.images = images;
  5228. }
  5229. return data;
  5230. },
  5231. clone: function () {
  5232. return new this.constructor().copy( this );
  5233. },
  5234. copy: function ( source ) {
  5235. this.name = source.name;
  5236. this.fog = source.fog;
  5237. this.lights = source.lights;
  5238. this.blending = source.blending;
  5239. this.side = source.side;
  5240. this.flatShading = source.flatShading;
  5241. this.vertexColors = source.vertexColors;
  5242. this.opacity = source.opacity;
  5243. this.transparent = source.transparent;
  5244. this.blendSrc = source.blendSrc;
  5245. this.blendDst = source.blendDst;
  5246. this.blendEquation = source.blendEquation;
  5247. this.blendSrcAlpha = source.blendSrcAlpha;
  5248. this.blendDstAlpha = source.blendDstAlpha;
  5249. this.blendEquationAlpha = source.blendEquationAlpha;
  5250. this.depthFunc = source.depthFunc;
  5251. this.depthTest = source.depthTest;
  5252. this.depthWrite = source.depthWrite;
  5253. this.stencilWrite = source.stencilWrite;
  5254. this.stencilFunc = source.stencilFunc;
  5255. this.stencilRef = source.stencilRef;
  5256. this.stencilMask = source.stencilMask;
  5257. this.stencilFail = source.stencilFail;
  5258. this.stencilZFail = source.stencilZFail;
  5259. this.stencilZPass = source.stencilZPass;
  5260. this.colorWrite = source.colorWrite;
  5261. this.precision = source.precision;
  5262. this.polygonOffset = source.polygonOffset;
  5263. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5264. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5265. this.dithering = source.dithering;
  5266. this.alphaTest = source.alphaTest;
  5267. this.premultipliedAlpha = source.premultipliedAlpha;
  5268. this.visible = source.visible;
  5269. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5270. this.clipShadows = source.clipShadows;
  5271. this.clipIntersection = source.clipIntersection;
  5272. var srcPlanes = source.clippingPlanes,
  5273. dstPlanes = null;
  5274. if ( srcPlanes !== null ) {
  5275. var n = srcPlanes.length;
  5276. dstPlanes = new Array( n );
  5277. for ( var i = 0; i !== n; ++ i )
  5278. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5279. }
  5280. this.clippingPlanes = dstPlanes;
  5281. this.shadowSide = source.shadowSide;
  5282. return this;
  5283. },
  5284. dispose: function () {
  5285. this.dispatchEvent( { type: 'dispose' } );
  5286. }
  5287. } );
  5288. /**
  5289. * @author mrdoob / http://mrdoob.com/
  5290. * @author alteredq / http://alteredqualia.com/
  5291. *
  5292. * parameters = {
  5293. * color: <hex>,
  5294. * opacity: <float>,
  5295. * map: new THREE.Texture( <Image> ),
  5296. *
  5297. * lightMap: new THREE.Texture( <Image> ),
  5298. * lightMapIntensity: <float>
  5299. *
  5300. * aoMap: new THREE.Texture( <Image> ),
  5301. * aoMapIntensity: <float>
  5302. *
  5303. * specularMap: new THREE.Texture( <Image> ),
  5304. *
  5305. * alphaMap: new THREE.Texture( <Image> ),
  5306. *
  5307. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5308. * combine: THREE.Multiply,
  5309. * reflectivity: <float>,
  5310. * refractionRatio: <float>,
  5311. *
  5312. * depthTest: <bool>,
  5313. * depthWrite: <bool>,
  5314. *
  5315. * wireframe: <boolean>,
  5316. * wireframeLinewidth: <float>,
  5317. *
  5318. * skinning: <bool>,
  5319. * morphTargets: <bool>
  5320. * }
  5321. */
  5322. function MeshBasicMaterial( parameters ) {
  5323. Material.call( this );
  5324. this.type = 'MeshBasicMaterial';
  5325. this.color = new Color( 0xffffff ); // emissive
  5326. this.map = null;
  5327. this.lightMap = null;
  5328. this.lightMapIntensity = 1.0;
  5329. this.aoMap = null;
  5330. this.aoMapIntensity = 1.0;
  5331. this.specularMap = null;
  5332. this.alphaMap = null;
  5333. this.envMap = null;
  5334. this.combine = MultiplyOperation;
  5335. this.reflectivity = 1;
  5336. this.refractionRatio = 0.98;
  5337. this.wireframe = false;
  5338. this.wireframeLinewidth = 1;
  5339. this.wireframeLinecap = 'round';
  5340. this.wireframeLinejoin = 'round';
  5341. this.skinning = false;
  5342. this.morphTargets = false;
  5343. this.lights = false;
  5344. this.setValues( parameters );
  5345. }
  5346. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5347. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5348. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5349. MeshBasicMaterial.prototype.copy = function ( source ) {
  5350. Material.prototype.copy.call( this, source );
  5351. this.color.copy( source.color );
  5352. this.map = source.map;
  5353. this.lightMap = source.lightMap;
  5354. this.lightMapIntensity = source.lightMapIntensity;
  5355. this.aoMap = source.aoMap;
  5356. this.aoMapIntensity = source.aoMapIntensity;
  5357. this.specularMap = source.specularMap;
  5358. this.alphaMap = source.alphaMap;
  5359. this.envMap = source.envMap;
  5360. this.combine = source.combine;
  5361. this.reflectivity = source.reflectivity;
  5362. this.refractionRatio = source.refractionRatio;
  5363. this.wireframe = source.wireframe;
  5364. this.wireframeLinewidth = source.wireframeLinewidth;
  5365. this.wireframeLinecap = source.wireframeLinecap;
  5366. this.wireframeLinejoin = source.wireframeLinejoin;
  5367. this.skinning = source.skinning;
  5368. this.morphTargets = source.morphTargets;
  5369. return this;
  5370. };
  5371. /**
  5372. * @author mrdoob / http://mrdoob.com/
  5373. */
  5374. function BufferAttribute( array, itemSize, normalized ) {
  5375. if ( Array.isArray( array ) ) {
  5376. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5377. }
  5378. this.name = '';
  5379. this.array = array;
  5380. this.itemSize = itemSize;
  5381. this.count = array !== undefined ? array.length / itemSize : 0;
  5382. this.normalized = normalized === true;
  5383. this.dynamic = false;
  5384. this.updateRange = { offset: 0, count: - 1 };
  5385. this.version = 0;
  5386. }
  5387. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5388. set: function ( value ) {
  5389. if ( value === true ) this.version ++;
  5390. }
  5391. } );
  5392. Object.assign( BufferAttribute.prototype, {
  5393. isBufferAttribute: true,
  5394. onUploadCallback: function () {},
  5395. setArray: function ( array ) {
  5396. if ( Array.isArray( array ) ) {
  5397. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5398. }
  5399. this.count = array !== undefined ? array.length / this.itemSize : 0;
  5400. this.array = array;
  5401. return this;
  5402. },
  5403. setDynamic: function ( value ) {
  5404. this.dynamic = value;
  5405. return this;
  5406. },
  5407. copy: function ( source ) {
  5408. this.name = source.name;
  5409. this.array = new source.array.constructor( source.array );
  5410. this.itemSize = source.itemSize;
  5411. this.count = source.count;
  5412. this.normalized = source.normalized;
  5413. this.dynamic = source.dynamic;
  5414. return this;
  5415. },
  5416. copyAt: function ( index1, attribute, index2 ) {
  5417. index1 *= this.itemSize;
  5418. index2 *= attribute.itemSize;
  5419. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5420. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5421. }
  5422. return this;
  5423. },
  5424. copyArray: function ( array ) {
  5425. this.array.set( array );
  5426. return this;
  5427. },
  5428. copyColorsArray: function ( colors ) {
  5429. var array = this.array, offset = 0;
  5430. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5431. var color = colors[ i ];
  5432. if ( color === undefined ) {
  5433. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5434. color = new Color();
  5435. }
  5436. array[ offset ++ ] = color.r;
  5437. array[ offset ++ ] = color.g;
  5438. array[ offset ++ ] = color.b;
  5439. }
  5440. return this;
  5441. },
  5442. copyVector2sArray: function ( vectors ) {
  5443. var array = this.array, offset = 0;
  5444. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5445. var vector = vectors[ i ];
  5446. if ( vector === undefined ) {
  5447. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5448. vector = new Vector2();
  5449. }
  5450. array[ offset ++ ] = vector.x;
  5451. array[ offset ++ ] = vector.y;
  5452. }
  5453. return this;
  5454. },
  5455. copyVector3sArray: function ( vectors ) {
  5456. var array = this.array, offset = 0;
  5457. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5458. var vector = vectors[ i ];
  5459. if ( vector === undefined ) {
  5460. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5461. vector = new Vector3();
  5462. }
  5463. array[ offset ++ ] = vector.x;
  5464. array[ offset ++ ] = vector.y;
  5465. array[ offset ++ ] = vector.z;
  5466. }
  5467. return this;
  5468. },
  5469. copyVector4sArray: function ( vectors ) {
  5470. var array = this.array, offset = 0;
  5471. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5472. var vector = vectors[ i ];
  5473. if ( vector === undefined ) {
  5474. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5475. vector = new Vector4();
  5476. }
  5477. array[ offset ++ ] = vector.x;
  5478. array[ offset ++ ] = vector.y;
  5479. array[ offset ++ ] = vector.z;
  5480. array[ offset ++ ] = vector.w;
  5481. }
  5482. return this;
  5483. },
  5484. set: function ( value, offset ) {
  5485. if ( offset === undefined ) offset = 0;
  5486. this.array.set( value, offset );
  5487. return this;
  5488. },
  5489. getX: function ( index ) {
  5490. return this.array[ index * this.itemSize ];
  5491. },
  5492. setX: function ( index, x ) {
  5493. this.array[ index * this.itemSize ] = x;
  5494. return this;
  5495. },
  5496. getY: function ( index ) {
  5497. return this.array[ index * this.itemSize + 1 ];
  5498. },
  5499. setY: function ( index, y ) {
  5500. this.array[ index * this.itemSize + 1 ] = y;
  5501. return this;
  5502. },
  5503. getZ: function ( index ) {
  5504. return this.array[ index * this.itemSize + 2 ];
  5505. },
  5506. setZ: function ( index, z ) {
  5507. this.array[ index * this.itemSize + 2 ] = z;
  5508. return this;
  5509. },
  5510. getW: function ( index ) {
  5511. return this.array[ index * this.itemSize + 3 ];
  5512. },
  5513. setW: function ( index, w ) {
  5514. this.array[ index * this.itemSize + 3 ] = w;
  5515. return this;
  5516. },
  5517. setXY: function ( index, x, y ) {
  5518. index *= this.itemSize;
  5519. this.array[ index + 0 ] = x;
  5520. this.array[ index + 1 ] = y;
  5521. return this;
  5522. },
  5523. setXYZ: function ( index, x, y, z ) {
  5524. index *= this.itemSize;
  5525. this.array[ index + 0 ] = x;
  5526. this.array[ index + 1 ] = y;
  5527. this.array[ index + 2 ] = z;
  5528. return this;
  5529. },
  5530. setXYZW: function ( index, x, y, z, w ) {
  5531. index *= this.itemSize;
  5532. this.array[ index + 0 ] = x;
  5533. this.array[ index + 1 ] = y;
  5534. this.array[ index + 2 ] = z;
  5535. this.array[ index + 3 ] = w;
  5536. return this;
  5537. },
  5538. onUpload: function ( callback ) {
  5539. this.onUploadCallback = callback;
  5540. return this;
  5541. },
  5542. clone: function () {
  5543. return new this.constructor( this.array, this.itemSize ).copy( this );
  5544. },
  5545. toJSON: function () {
  5546. return {
  5547. itemSize: this.itemSize,
  5548. type: this.array.constructor.name,
  5549. array: Array.prototype.slice.call( this.array ),
  5550. normalized: this.normalized
  5551. };
  5552. }
  5553. } );
  5554. //
  5555. function Int8BufferAttribute( array, itemSize, normalized ) {
  5556. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5557. }
  5558. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5559. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5560. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5561. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5562. }
  5563. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5564. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5565. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5566. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5567. }
  5568. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5569. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5570. function Int16BufferAttribute( array, itemSize, normalized ) {
  5571. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5572. }
  5573. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5574. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5575. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5576. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5577. }
  5578. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5579. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5580. function Int32BufferAttribute( array, itemSize, normalized ) {
  5581. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5582. }
  5583. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5584. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5585. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5586. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5587. }
  5588. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5589. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5590. function Float32BufferAttribute( array, itemSize, normalized ) {
  5591. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5592. }
  5593. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5594. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5595. function Float64BufferAttribute( array, itemSize, normalized ) {
  5596. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5597. }
  5598. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5599. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5600. /**
  5601. * @author mrdoob / http://mrdoob.com/
  5602. */
  5603. function DirectGeometry() {
  5604. this.vertices = [];
  5605. this.normals = [];
  5606. this.colors = [];
  5607. this.uvs = [];
  5608. this.uvs2 = [];
  5609. this.groups = [];
  5610. this.morphTargets = {};
  5611. this.skinWeights = [];
  5612. this.skinIndices = [];
  5613. // this.lineDistances = [];
  5614. this.boundingBox = null;
  5615. this.boundingSphere = null;
  5616. // update flags
  5617. this.verticesNeedUpdate = false;
  5618. this.normalsNeedUpdate = false;
  5619. this.colorsNeedUpdate = false;
  5620. this.uvsNeedUpdate = false;
  5621. this.groupsNeedUpdate = false;
  5622. }
  5623. Object.assign( DirectGeometry.prototype, {
  5624. computeGroups: function ( geometry ) {
  5625. var group;
  5626. var groups = [];
  5627. var materialIndex = undefined;
  5628. var faces = geometry.faces;
  5629. for ( var i = 0; i < faces.length; i ++ ) {
  5630. var face = faces[ i ];
  5631. // materials
  5632. if ( face.materialIndex !== materialIndex ) {
  5633. materialIndex = face.materialIndex;
  5634. if ( group !== undefined ) {
  5635. group.count = ( i * 3 ) - group.start;
  5636. groups.push( group );
  5637. }
  5638. group = {
  5639. start: i * 3,
  5640. materialIndex: materialIndex
  5641. };
  5642. }
  5643. }
  5644. if ( group !== undefined ) {
  5645. group.count = ( i * 3 ) - group.start;
  5646. groups.push( group );
  5647. }
  5648. this.groups = groups;
  5649. },
  5650. fromGeometry: function ( geometry ) {
  5651. var faces = geometry.faces;
  5652. var vertices = geometry.vertices;
  5653. var faceVertexUvs = geometry.faceVertexUvs;
  5654. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5655. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5656. // morphs
  5657. var morphTargets = geometry.morphTargets;
  5658. var morphTargetsLength = morphTargets.length;
  5659. var morphTargetsPosition;
  5660. if ( morphTargetsLength > 0 ) {
  5661. morphTargetsPosition = [];
  5662. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5663. morphTargetsPosition[ i ] = {
  5664. name: morphTargets[ i ].name,
  5665. data: []
  5666. };
  5667. }
  5668. this.morphTargets.position = morphTargetsPosition;
  5669. }
  5670. var morphNormals = geometry.morphNormals;
  5671. var morphNormalsLength = morphNormals.length;
  5672. var morphTargetsNormal;
  5673. if ( morphNormalsLength > 0 ) {
  5674. morphTargetsNormal = [];
  5675. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5676. morphTargetsNormal[ i ] = {
  5677. name: morphNormals[ i ].name,
  5678. data: []
  5679. };
  5680. }
  5681. this.morphTargets.normal = morphTargetsNormal;
  5682. }
  5683. // skins
  5684. var skinIndices = geometry.skinIndices;
  5685. var skinWeights = geometry.skinWeights;
  5686. var hasSkinIndices = skinIndices.length === vertices.length;
  5687. var hasSkinWeights = skinWeights.length === vertices.length;
  5688. //
  5689. if ( vertices.length > 0 && faces.length === 0 ) {
  5690. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5691. }
  5692. for ( var i = 0; i < faces.length; i ++ ) {
  5693. var face = faces[ i ];
  5694. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5695. var vertexNormals = face.vertexNormals;
  5696. if ( vertexNormals.length === 3 ) {
  5697. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5698. } else {
  5699. var normal = face.normal;
  5700. this.normals.push( normal, normal, normal );
  5701. }
  5702. var vertexColors = face.vertexColors;
  5703. if ( vertexColors.length === 3 ) {
  5704. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5705. } else {
  5706. var color = face.color;
  5707. this.colors.push( color, color, color );
  5708. }
  5709. if ( hasFaceVertexUv === true ) {
  5710. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5711. if ( vertexUvs !== undefined ) {
  5712. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5713. } else {
  5714. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5715. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5716. }
  5717. }
  5718. if ( hasFaceVertexUv2 === true ) {
  5719. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5720. if ( vertexUvs !== undefined ) {
  5721. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5722. } else {
  5723. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5724. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5725. }
  5726. }
  5727. // morphs
  5728. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5729. var morphTarget = morphTargets[ j ].vertices;
  5730. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5731. }
  5732. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5733. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5734. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5735. }
  5736. // skins
  5737. if ( hasSkinIndices ) {
  5738. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5739. }
  5740. if ( hasSkinWeights ) {
  5741. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5742. }
  5743. }
  5744. this.computeGroups( geometry );
  5745. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5746. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5747. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5748. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5749. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5750. if ( geometry.boundingSphere !== null ) {
  5751. this.boundingSphere = geometry.boundingSphere.clone();
  5752. }
  5753. if ( geometry.boundingBox !== null ) {
  5754. this.boundingBox = geometry.boundingBox.clone();
  5755. }
  5756. return this;
  5757. }
  5758. } );
  5759. /**
  5760. * @author mrdoob / http://mrdoob.com/
  5761. */
  5762. function arrayMax( array ) {
  5763. if ( array.length === 0 ) return - Infinity;
  5764. var max = array[ 0 ];
  5765. for ( var i = 1, l = array.length; i < l; ++ i ) {
  5766. if ( array[ i ] > max ) max = array[ i ];
  5767. }
  5768. return max;
  5769. }
  5770. /**
  5771. * @author alteredq / http://alteredqualia.com/
  5772. * @author mrdoob / http://mrdoob.com/
  5773. */
  5774. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5775. var _m1$2, _obj, _offset;
  5776. var _box$1, _boxMorphTargets;
  5777. var _vector$4;
  5778. function BufferGeometry() {
  5779. Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
  5780. this.uuid = _Math.generateUUID();
  5781. this.name = '';
  5782. this.type = 'BufferGeometry';
  5783. this.index = null;
  5784. this.attributes = {};
  5785. this.morphAttributes = {};
  5786. this.groups = [];
  5787. this.boundingBox = null;
  5788. this.boundingSphere = null;
  5789. this.drawRange = { start: 0, count: Infinity };
  5790. this.userData = {};
  5791. }
  5792. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5793. constructor: BufferGeometry,
  5794. isBufferGeometry: true,
  5795. getIndex: function () {
  5796. return this.index;
  5797. },
  5798. setIndex: function ( index ) {
  5799. if ( Array.isArray( index ) ) {
  5800. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5801. } else {
  5802. this.index = index;
  5803. }
  5804. },
  5805. addAttribute: function ( name, attribute ) {
  5806. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  5807. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  5808. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  5809. }
  5810. if ( name === 'index' ) {
  5811. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  5812. this.setIndex( attribute );
  5813. return this;
  5814. }
  5815. this.attributes[ name ] = attribute;
  5816. return this;
  5817. },
  5818. getAttribute: function ( name ) {
  5819. return this.attributes[ name ];
  5820. },
  5821. removeAttribute: function ( name ) {
  5822. delete this.attributes[ name ];
  5823. return this;
  5824. },
  5825. addGroup: function ( start, count, materialIndex ) {
  5826. this.groups.push( {
  5827. start: start,
  5828. count: count,
  5829. materialIndex: materialIndex !== undefined ? materialIndex : 0
  5830. } );
  5831. },
  5832. clearGroups: function () {
  5833. this.groups = [];
  5834. },
  5835. setDrawRange: function ( start, count ) {
  5836. this.drawRange.start = start;
  5837. this.drawRange.count = count;
  5838. },
  5839. applyMatrix: function ( matrix ) {
  5840. var position = this.attributes.position;
  5841. if ( position !== undefined ) {
  5842. matrix.applyToBufferAttribute( position );
  5843. position.needsUpdate = true;
  5844. }
  5845. var normal = this.attributes.normal;
  5846. if ( normal !== undefined ) {
  5847. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5848. normalMatrix.applyToBufferAttribute( normal );
  5849. normal.needsUpdate = true;
  5850. }
  5851. var tangent = this.attributes.tangent;
  5852. if ( tangent !== undefined ) {
  5853. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5854. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  5855. normalMatrix.applyToBufferAttribute( tangent );
  5856. tangent.needsUpdate = true;
  5857. }
  5858. if ( this.boundingBox !== null ) {
  5859. this.computeBoundingBox();
  5860. }
  5861. if ( this.boundingSphere !== null ) {
  5862. this.computeBoundingSphere();
  5863. }
  5864. return this;
  5865. },
  5866. rotateX: function ( angle ) {
  5867. // rotate geometry around world x-axis
  5868. if ( _m1$2 === undefined ) _m1$2 = new Matrix4();
  5869. _m1$2.makeRotationX( angle );
  5870. this.applyMatrix( _m1$2 );
  5871. return this;
  5872. },
  5873. rotateY: function ( angle ) {
  5874. // rotate geometry around world y-axis
  5875. if ( _m1$2 === undefined ) _m1$2 = new Matrix4();
  5876. _m1$2.makeRotationY( angle );
  5877. this.applyMatrix( _m1$2 );
  5878. return this;
  5879. },
  5880. rotateZ: function ( angle ) {
  5881. // rotate geometry around world z-axis
  5882. if ( _m1$2 === undefined ) _m1$2 = new Matrix4();
  5883. _m1$2.makeRotationZ( angle );
  5884. this.applyMatrix( _m1$2 );
  5885. return this;
  5886. },
  5887. translate: function ( x, y, z ) {
  5888. // translate geometry
  5889. if ( _m1$2 === undefined ) _m1$2 = new Matrix4();
  5890. _m1$2.makeTranslation( x, y, z );
  5891. this.applyMatrix( _m1$2 );
  5892. return this;
  5893. },
  5894. scale: function ( x, y, z ) {
  5895. // scale geometry
  5896. if ( _m1$2 === undefined ) _m1$2 = new Matrix4();
  5897. _m1$2.makeScale( x, y, z );
  5898. this.applyMatrix( _m1$2 );
  5899. return this;
  5900. },
  5901. lookAt: function ( vector ) {
  5902. if ( _obj === undefined ) _obj = new Object3D();
  5903. _obj.lookAt( vector );
  5904. _obj.updateMatrix();
  5905. this.applyMatrix( _obj.matrix );
  5906. return this;
  5907. },
  5908. center: function () {
  5909. if ( _offset === undefined ) _offset = new Vector3();
  5910. this.computeBoundingBox();
  5911. this.boundingBox.getCenter( _offset ).negate();
  5912. this.translate( _offset.x, _offset.y, _offset.z );
  5913. return this;
  5914. },
  5915. setFromObject: function ( object ) {
  5916. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5917. var geometry = object.geometry;
  5918. if ( object.isPoints || object.isLine ) {
  5919. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5920. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  5921. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5922. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5923. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  5924. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  5925. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  5926. }
  5927. if ( geometry.boundingSphere !== null ) {
  5928. this.boundingSphere = geometry.boundingSphere.clone();
  5929. }
  5930. if ( geometry.boundingBox !== null ) {
  5931. this.boundingBox = geometry.boundingBox.clone();
  5932. }
  5933. } else if ( object.isMesh ) {
  5934. if ( geometry && geometry.isGeometry ) {
  5935. this.fromGeometry( geometry );
  5936. }
  5937. }
  5938. return this;
  5939. },
  5940. setFromPoints: function ( points ) {
  5941. var position = [];
  5942. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5943. var point = points[ i ];
  5944. position.push( point.x, point.y, point.z || 0 );
  5945. }
  5946. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  5947. return this;
  5948. },
  5949. updateFromObject: function ( object ) {
  5950. var geometry = object.geometry;
  5951. if ( object.isMesh ) {
  5952. var direct = geometry.__directGeometry;
  5953. if ( geometry.elementsNeedUpdate === true ) {
  5954. direct = undefined;
  5955. geometry.elementsNeedUpdate = false;
  5956. }
  5957. if ( direct === undefined ) {
  5958. return this.fromGeometry( geometry );
  5959. }
  5960. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5961. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5962. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5963. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5964. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5965. geometry.verticesNeedUpdate = false;
  5966. geometry.normalsNeedUpdate = false;
  5967. geometry.colorsNeedUpdate = false;
  5968. geometry.uvsNeedUpdate = false;
  5969. geometry.groupsNeedUpdate = false;
  5970. geometry = direct;
  5971. }
  5972. var attribute;
  5973. if ( geometry.verticesNeedUpdate === true ) {
  5974. attribute = this.attributes.position;
  5975. if ( attribute !== undefined ) {
  5976. attribute.copyVector3sArray( geometry.vertices );
  5977. attribute.needsUpdate = true;
  5978. }
  5979. geometry.verticesNeedUpdate = false;
  5980. }
  5981. if ( geometry.normalsNeedUpdate === true ) {
  5982. attribute = this.attributes.normal;
  5983. if ( attribute !== undefined ) {
  5984. attribute.copyVector3sArray( geometry.normals );
  5985. attribute.needsUpdate = true;
  5986. }
  5987. geometry.normalsNeedUpdate = false;
  5988. }
  5989. if ( geometry.colorsNeedUpdate === true ) {
  5990. attribute = this.attributes.color;
  5991. if ( attribute !== undefined ) {
  5992. attribute.copyColorsArray( geometry.colors );
  5993. attribute.needsUpdate = true;
  5994. }
  5995. geometry.colorsNeedUpdate = false;
  5996. }
  5997. if ( geometry.uvsNeedUpdate ) {
  5998. attribute = this.attributes.uv;
  5999. if ( attribute !== undefined ) {
  6000. attribute.copyVector2sArray( geometry.uvs );
  6001. attribute.needsUpdate = true;
  6002. }
  6003. geometry.uvsNeedUpdate = false;
  6004. }
  6005. if ( geometry.lineDistancesNeedUpdate ) {
  6006. attribute = this.attributes.lineDistance;
  6007. if ( attribute !== undefined ) {
  6008. attribute.copyArray( geometry.lineDistances );
  6009. attribute.needsUpdate = true;
  6010. }
  6011. geometry.lineDistancesNeedUpdate = false;
  6012. }
  6013. if ( geometry.groupsNeedUpdate ) {
  6014. geometry.computeGroups( object.geometry );
  6015. this.groups = geometry.groups;
  6016. geometry.groupsNeedUpdate = false;
  6017. }
  6018. return this;
  6019. },
  6020. fromGeometry: function ( geometry ) {
  6021. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6022. return this.fromDirectGeometry( geometry.__directGeometry );
  6023. },
  6024. fromDirectGeometry: function ( geometry ) {
  6025. var positions = new Float32Array( geometry.vertices.length * 3 );
  6026. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6027. if ( geometry.normals.length > 0 ) {
  6028. var normals = new Float32Array( geometry.normals.length * 3 );
  6029. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6030. }
  6031. if ( geometry.colors.length > 0 ) {
  6032. var colors = new Float32Array( geometry.colors.length * 3 );
  6033. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6034. }
  6035. if ( geometry.uvs.length > 0 ) {
  6036. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6037. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6038. }
  6039. if ( geometry.uvs2.length > 0 ) {
  6040. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6041. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6042. }
  6043. // groups
  6044. this.groups = geometry.groups;
  6045. // morphs
  6046. for ( var name in geometry.morphTargets ) {
  6047. var array = [];
  6048. var morphTargets = geometry.morphTargets[ name ];
  6049. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6050. var morphTarget = morphTargets[ i ];
  6051. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6052. attribute.name = morphTarget.name;
  6053. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6054. }
  6055. this.morphAttributes[ name ] = array;
  6056. }
  6057. // skinning
  6058. if ( geometry.skinIndices.length > 0 ) {
  6059. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6060. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6061. }
  6062. if ( geometry.skinWeights.length > 0 ) {
  6063. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6064. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6065. }
  6066. //
  6067. if ( geometry.boundingSphere !== null ) {
  6068. this.boundingSphere = geometry.boundingSphere.clone();
  6069. }
  6070. if ( geometry.boundingBox !== null ) {
  6071. this.boundingBox = geometry.boundingBox.clone();
  6072. }
  6073. return this;
  6074. },
  6075. computeBoundingBox: function () {
  6076. if ( _box$1 === undefined ) {
  6077. _box$1 = new Box3();
  6078. }
  6079. if ( this.boundingBox === null ) {
  6080. this.boundingBox = new Box3();
  6081. }
  6082. var position = this.attributes.position;
  6083. var morphAttributesPosition = this.morphAttributes.position;
  6084. if ( position !== undefined ) {
  6085. this.boundingBox.setFromBufferAttribute( position );
  6086. // process morph attributes if present
  6087. if ( morphAttributesPosition ) {
  6088. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6089. var morphAttribute = morphAttributesPosition[ i ];
  6090. _box$1.setFromBufferAttribute( morphAttribute );
  6091. this.boundingBox.expandByPoint( _box$1.min );
  6092. this.boundingBox.expandByPoint( _box$1.max );
  6093. }
  6094. }
  6095. } else {
  6096. this.boundingBox.makeEmpty();
  6097. }
  6098. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6099. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6100. }
  6101. },
  6102. computeBoundingSphere: function () {
  6103. if ( _boxMorphTargets === undefined ) {
  6104. _box$1 = new Box3();
  6105. _vector$4 = new Vector3();
  6106. _boxMorphTargets = new Box3();
  6107. }
  6108. if ( this.boundingSphere === null ) {
  6109. this.boundingSphere = new Sphere();
  6110. }
  6111. var position = this.attributes.position;
  6112. var morphAttributesPosition = this.morphAttributes.position;
  6113. if ( position ) {
  6114. // first, find the center of the bounding sphere
  6115. var center = this.boundingSphere.center;
  6116. _box$1.setFromBufferAttribute( position );
  6117. // process morph attributes if present
  6118. if ( morphAttributesPosition ) {
  6119. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6120. var morphAttribute = morphAttributesPosition[ i ];
  6121. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6122. _box$1.expandByPoint( _boxMorphTargets.min );
  6123. _box$1.expandByPoint( _boxMorphTargets.max );
  6124. }
  6125. }
  6126. _box$1.getCenter( center );
  6127. // second, try to find a boundingSphere with a radius smaller than the
  6128. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6129. var maxRadiusSq = 0;
  6130. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6131. _vector$4.fromBufferAttribute( position, i );
  6132. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6133. }
  6134. // process morph attributes if present
  6135. if ( morphAttributesPosition ) {
  6136. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6137. var morphAttribute = morphAttributesPosition[ i ];
  6138. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6139. _vector$4.fromBufferAttribute( morphAttribute, j );
  6140. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6141. }
  6142. }
  6143. }
  6144. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6145. if ( isNaN( this.boundingSphere.radius ) ) {
  6146. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6147. }
  6148. }
  6149. },
  6150. computeFaceNormals: function () {
  6151. // backwards compatibility
  6152. },
  6153. computeVertexNormals: function () {
  6154. var index = this.index;
  6155. var attributes = this.attributes;
  6156. if ( attributes.position ) {
  6157. var positions = attributes.position.array;
  6158. if ( attributes.normal === undefined ) {
  6159. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6160. } else {
  6161. // reset existing normals to zero
  6162. var array = attributes.normal.array;
  6163. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6164. array[ i ] = 0;
  6165. }
  6166. }
  6167. var normals = attributes.normal.array;
  6168. var vA, vB, vC;
  6169. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6170. var cb = new Vector3(), ab = new Vector3();
  6171. // indexed elements
  6172. if ( index ) {
  6173. var indices = index.array;
  6174. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  6175. vA = indices[ i + 0 ] * 3;
  6176. vB = indices[ i + 1 ] * 3;
  6177. vC = indices[ i + 2 ] * 3;
  6178. pA.fromArray( positions, vA );
  6179. pB.fromArray( positions, vB );
  6180. pC.fromArray( positions, vC );
  6181. cb.subVectors( pC, pB );
  6182. ab.subVectors( pA, pB );
  6183. cb.cross( ab );
  6184. normals[ vA ] += cb.x;
  6185. normals[ vA + 1 ] += cb.y;
  6186. normals[ vA + 2 ] += cb.z;
  6187. normals[ vB ] += cb.x;
  6188. normals[ vB + 1 ] += cb.y;
  6189. normals[ vB + 2 ] += cb.z;
  6190. normals[ vC ] += cb.x;
  6191. normals[ vC + 1 ] += cb.y;
  6192. normals[ vC + 2 ] += cb.z;
  6193. }
  6194. } else {
  6195. // non-indexed elements (unconnected triangle soup)
  6196. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6197. pA.fromArray( positions, i );
  6198. pB.fromArray( positions, i + 3 );
  6199. pC.fromArray( positions, i + 6 );
  6200. cb.subVectors( pC, pB );
  6201. ab.subVectors( pA, pB );
  6202. cb.cross( ab );
  6203. normals[ i ] = cb.x;
  6204. normals[ i + 1 ] = cb.y;
  6205. normals[ i + 2 ] = cb.z;
  6206. normals[ i + 3 ] = cb.x;
  6207. normals[ i + 4 ] = cb.y;
  6208. normals[ i + 5 ] = cb.z;
  6209. normals[ i + 6 ] = cb.x;
  6210. normals[ i + 7 ] = cb.y;
  6211. normals[ i + 8 ] = cb.z;
  6212. }
  6213. }
  6214. this.normalizeNormals();
  6215. attributes.normal.needsUpdate = true;
  6216. }
  6217. },
  6218. merge: function ( geometry, offset ) {
  6219. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6220. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6221. return;
  6222. }
  6223. if ( offset === undefined ) {
  6224. offset = 0;
  6225. console.warn(
  6226. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6227. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6228. );
  6229. }
  6230. var attributes = this.attributes;
  6231. for ( var key in attributes ) {
  6232. if ( geometry.attributes[ key ] === undefined ) continue;
  6233. var attribute1 = attributes[ key ];
  6234. var attributeArray1 = attribute1.array;
  6235. var attribute2 = geometry.attributes[ key ];
  6236. var attributeArray2 = attribute2.array;
  6237. var attributeOffset = attribute2.itemSize * offset;
  6238. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6239. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6240. attributeArray1[ j ] = attributeArray2[ i ];
  6241. }
  6242. }
  6243. return this;
  6244. },
  6245. normalizeNormals: function () {
  6246. if ( _vector$4 === undefined ) _vector$4 = new Vector3();
  6247. var normals = this.attributes.normal;
  6248. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6249. _vector$4.x = normals.getX( i );
  6250. _vector$4.y = normals.getY( i );
  6251. _vector$4.z = normals.getZ( i );
  6252. _vector$4.normalize();
  6253. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6254. }
  6255. },
  6256. toNonIndexed: function () {
  6257. function convertBufferAttribute( attribute, indices ) {
  6258. var array = attribute.array;
  6259. var itemSize = attribute.itemSize;
  6260. var array2 = new array.constructor( indices.length * itemSize );
  6261. var index = 0, index2 = 0;
  6262. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6263. index = indices[ i ] * itemSize;
  6264. for ( var j = 0; j < itemSize; j ++ ) {
  6265. array2[ index2 ++ ] = array[ index ++ ];
  6266. }
  6267. }
  6268. return new BufferAttribute( array2, itemSize );
  6269. }
  6270. //
  6271. if ( this.index === null ) {
  6272. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6273. return this;
  6274. }
  6275. var geometry2 = new BufferGeometry();
  6276. var indices = this.index.array;
  6277. var attributes = this.attributes;
  6278. // attributes
  6279. for ( var name in attributes ) {
  6280. var attribute = attributes[ name ];
  6281. var newAttribute = convertBufferAttribute( attribute, indices );
  6282. geometry2.addAttribute( name, newAttribute );
  6283. }
  6284. // morph attributes
  6285. var morphAttributes = this.morphAttributes;
  6286. for ( name in morphAttributes ) {
  6287. var morphArray = [];
  6288. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6289. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6290. var attribute = morphAttribute[ i ];
  6291. var newAttribute = convertBufferAttribute( attribute, indices );
  6292. morphArray.push( newAttribute );
  6293. }
  6294. geometry2.morphAttributes[ name ] = morphArray;
  6295. }
  6296. // groups
  6297. var groups = this.groups;
  6298. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6299. var group = groups[ i ];
  6300. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6301. }
  6302. return geometry2;
  6303. },
  6304. toJSON: function () {
  6305. var data = {
  6306. metadata: {
  6307. version: 4.5,
  6308. type: 'BufferGeometry',
  6309. generator: 'BufferGeometry.toJSON'
  6310. }
  6311. };
  6312. // standard BufferGeometry serialization
  6313. data.uuid = this.uuid;
  6314. data.type = this.type;
  6315. if ( this.name !== '' ) data.name = this.name;
  6316. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6317. if ( this.parameters !== undefined ) {
  6318. var parameters = this.parameters;
  6319. for ( var key in parameters ) {
  6320. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6321. }
  6322. return data;
  6323. }
  6324. data.data = { attributes: {} };
  6325. var index = this.index;
  6326. if ( index !== null ) {
  6327. data.data.index = {
  6328. type: index.array.constructor.name,
  6329. array: Array.prototype.slice.call( index.array )
  6330. };
  6331. }
  6332. var attributes = this.attributes;
  6333. for ( var key in attributes ) {
  6334. var attribute = attributes[ key ];
  6335. var attributeData = attribute.toJSON();
  6336. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6337. data.data.attributes[ key ] = attributeData;
  6338. }
  6339. var morphAttributes = {};
  6340. var hasMorphAttributes = false;
  6341. for ( var key in this.morphAttributes ) {
  6342. var attributeArray = this.morphAttributes[ key ];
  6343. var array = [];
  6344. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6345. var attribute = attributeArray[ i ];
  6346. var attributeData = attribute.toJSON();
  6347. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6348. array.push( attributeData );
  6349. }
  6350. if ( array.length > 0 ) {
  6351. morphAttributes[ key ] = array;
  6352. hasMorphAttributes = true;
  6353. }
  6354. }
  6355. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  6356. var groups = this.groups;
  6357. if ( groups.length > 0 ) {
  6358. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6359. }
  6360. var boundingSphere = this.boundingSphere;
  6361. if ( boundingSphere !== null ) {
  6362. data.data.boundingSphere = {
  6363. center: boundingSphere.center.toArray(),
  6364. radius: boundingSphere.radius
  6365. };
  6366. }
  6367. return data;
  6368. },
  6369. clone: function () {
  6370. /*
  6371. // Handle primitives
  6372. var parameters = this.parameters;
  6373. if ( parameters !== undefined ) {
  6374. var values = [];
  6375. for ( var key in parameters ) {
  6376. values.push( parameters[ key ] );
  6377. }
  6378. var geometry = Object.create( this.constructor.prototype );
  6379. this.constructor.apply( geometry, values );
  6380. return geometry;
  6381. }
  6382. return new this.constructor().copy( this );
  6383. */
  6384. return new BufferGeometry().copy( this );
  6385. },
  6386. copy: function ( source ) {
  6387. var name, i, l;
  6388. // reset
  6389. this.index = null;
  6390. this.attributes = {};
  6391. this.morphAttributes = {};
  6392. this.groups = [];
  6393. this.boundingBox = null;
  6394. this.boundingSphere = null;
  6395. // name
  6396. this.name = source.name;
  6397. // index
  6398. var index = source.index;
  6399. if ( index !== null ) {
  6400. this.setIndex( index.clone() );
  6401. }
  6402. // attributes
  6403. var attributes = source.attributes;
  6404. for ( name in attributes ) {
  6405. var attribute = attributes[ name ];
  6406. this.addAttribute( name, attribute.clone() );
  6407. }
  6408. // morph attributes
  6409. var morphAttributes = source.morphAttributes;
  6410. for ( name in morphAttributes ) {
  6411. var array = [];
  6412. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6413. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6414. array.push( morphAttribute[ i ].clone() );
  6415. }
  6416. this.morphAttributes[ name ] = array;
  6417. }
  6418. // groups
  6419. var groups = source.groups;
  6420. for ( i = 0, l = groups.length; i < l; i ++ ) {
  6421. var group = groups[ i ];
  6422. this.addGroup( group.start, group.count, group.materialIndex );
  6423. }
  6424. // bounding box
  6425. var boundingBox = source.boundingBox;
  6426. if ( boundingBox !== null ) {
  6427. this.boundingBox = boundingBox.clone();
  6428. }
  6429. // bounding sphere
  6430. var boundingSphere = source.boundingSphere;
  6431. if ( boundingSphere !== null ) {
  6432. this.boundingSphere = boundingSphere.clone();
  6433. }
  6434. // draw range
  6435. this.drawRange.start = source.drawRange.start;
  6436. this.drawRange.count = source.drawRange.count;
  6437. // user data
  6438. this.userData = source.userData;
  6439. return this;
  6440. },
  6441. dispose: function () {
  6442. this.dispatchEvent( { type: 'dispose' } );
  6443. }
  6444. } );
  6445. /**
  6446. * @author mrdoob / http://mrdoob.com/
  6447. * @author alteredq / http://alteredqualia.com/
  6448. * @author mikael emtinger / http://gomo.se/
  6449. * @author jonobr1 / http://jonobr1.com/
  6450. */
  6451. var _inverseMatrix, _ray, _sphere;
  6452. var _vA, _vB, _vC;
  6453. var _tempA, _tempB, _tempC;
  6454. var _morphA, _morphB, _morphC;
  6455. var _uvA, _uvB, _uvC;
  6456. var _intersectionPoint, _intersectionPointWorld;
  6457. function Mesh( geometry, material ) {
  6458. Object3D.call( this );
  6459. this.type = 'Mesh';
  6460. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6461. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  6462. this.drawMode = TrianglesDrawMode;
  6463. this.updateMorphTargets();
  6464. }
  6465. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6466. constructor: Mesh,
  6467. isMesh: true,
  6468. setDrawMode: function ( value ) {
  6469. this.drawMode = value;
  6470. },
  6471. copy: function ( source ) {
  6472. Object3D.prototype.copy.call( this, source );
  6473. this.drawMode = source.drawMode;
  6474. if ( source.morphTargetInfluences !== undefined ) {
  6475. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6476. }
  6477. if ( source.morphTargetDictionary !== undefined ) {
  6478. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6479. }
  6480. return this;
  6481. },
  6482. updateMorphTargets: function () {
  6483. var geometry = this.geometry;
  6484. var m, ml, name;
  6485. if ( geometry.isBufferGeometry ) {
  6486. var morphAttributes = geometry.morphAttributes;
  6487. var keys = Object.keys( morphAttributes );
  6488. if ( keys.length > 0 ) {
  6489. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6490. if ( morphAttribute !== undefined ) {
  6491. this.morphTargetInfluences = [];
  6492. this.morphTargetDictionary = {};
  6493. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6494. name = morphAttribute[ m ].name || String( m );
  6495. this.morphTargetInfluences.push( 0 );
  6496. this.morphTargetDictionary[ name ] = m;
  6497. }
  6498. }
  6499. }
  6500. } else {
  6501. var morphTargets = geometry.morphTargets;
  6502. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6503. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6504. }
  6505. }
  6506. },
  6507. raycast: function ( raycaster, intersects ) {
  6508. if ( _intersectionPointWorld === undefined ) {
  6509. _inverseMatrix = new Matrix4();
  6510. _ray = new Ray();
  6511. _sphere = new Sphere();
  6512. _vA = new Vector3();
  6513. _vB = new Vector3();
  6514. _vC = new Vector3();
  6515. _tempA = new Vector3();
  6516. _tempB = new Vector3();
  6517. _tempC = new Vector3();
  6518. _morphA = new Vector3();
  6519. _morphB = new Vector3();
  6520. _morphC = new Vector3();
  6521. _uvA = new Vector2();
  6522. _uvB = new Vector2();
  6523. _uvC = new Vector2();
  6524. _intersectionPoint = new Vector3();
  6525. _intersectionPointWorld = new Vector3();
  6526. }
  6527. var geometry = this.geometry;
  6528. var material = this.material;
  6529. var matrixWorld = this.matrixWorld;
  6530. if ( material === undefined ) return;
  6531. // Checking boundingSphere distance to ray
  6532. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6533. _sphere.copy( geometry.boundingSphere );
  6534. _sphere.applyMatrix4( matrixWorld );
  6535. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  6536. //
  6537. _inverseMatrix.getInverse( matrixWorld );
  6538. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6539. // Check boundingBox before continuing
  6540. if ( geometry.boundingBox !== null ) {
  6541. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6542. }
  6543. var intersection;
  6544. if ( geometry.isBufferGeometry ) {
  6545. var a, b, c;
  6546. var index = geometry.index;
  6547. var position = geometry.attributes.position;
  6548. var morphPosition = geometry.morphAttributes.position;
  6549. var uv = geometry.attributes.uv;
  6550. var uv2 = geometry.attributes.uv2;
  6551. var groups = geometry.groups;
  6552. var drawRange = geometry.drawRange;
  6553. var i, j, il, jl;
  6554. var group, groupMaterial;
  6555. var start, end;
  6556. if ( index !== null ) {
  6557. // indexed buffer geometry
  6558. if ( Array.isArray( material ) ) {
  6559. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6560. group = groups[ i ];
  6561. groupMaterial = material[ group.materialIndex ];
  6562. start = Math.max( group.start, drawRange.start );
  6563. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6564. for ( j = start, jl = end; j < jl; j += 3 ) {
  6565. a = index.getX( j );
  6566. b = index.getX( j + 1 );
  6567. c = index.getX( j + 2 );
  6568. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
  6569. if ( intersection ) {
  6570. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6571. intersection.face.materialIndex = group.materialIndex;
  6572. intersects.push( intersection );
  6573. }
  6574. }
  6575. }
  6576. } else {
  6577. start = Math.max( 0, drawRange.start );
  6578. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6579. for ( i = start, il = end; i < il; i += 3 ) {
  6580. a = index.getX( i );
  6581. b = index.getX( i + 1 );
  6582. c = index.getX( i + 2 );
  6583. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
  6584. if ( intersection ) {
  6585. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6586. intersects.push( intersection );
  6587. }
  6588. }
  6589. }
  6590. } else if ( position !== undefined ) {
  6591. // non-indexed buffer geometry
  6592. if ( Array.isArray( material ) ) {
  6593. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6594. group = groups[ i ];
  6595. groupMaterial = material[ group.materialIndex ];
  6596. start = Math.max( group.start, drawRange.start );
  6597. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6598. for ( j = start, jl = end; j < jl; j += 3 ) {
  6599. a = j;
  6600. b = j + 1;
  6601. c = j + 2;
  6602. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
  6603. if ( intersection ) {
  6604. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6605. intersection.face.materialIndex = group.materialIndex;
  6606. intersects.push( intersection );
  6607. }
  6608. }
  6609. }
  6610. } else {
  6611. start = Math.max( 0, drawRange.start );
  6612. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6613. for ( i = start, il = end; i < il; i += 3 ) {
  6614. a = i;
  6615. b = i + 1;
  6616. c = i + 2;
  6617. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
  6618. if ( intersection ) {
  6619. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6620. intersects.push( intersection );
  6621. }
  6622. }
  6623. }
  6624. }
  6625. } else if ( geometry.isGeometry ) {
  6626. var fvA, fvB, fvC;
  6627. var isMultiMaterial = Array.isArray( material );
  6628. var vertices = geometry.vertices;
  6629. var faces = geometry.faces;
  6630. var uvs;
  6631. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6632. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6633. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6634. var face = faces[ f ];
  6635. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6636. if ( faceMaterial === undefined ) continue;
  6637. fvA = vertices[ face.a ];
  6638. fvB = vertices[ face.b ];
  6639. fvC = vertices[ face.c ];
  6640. intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
  6641. if ( intersection ) {
  6642. if ( uvs && uvs[ f ] ) {
  6643. var uvs_f = uvs[ f ];
  6644. _uvA.copy( uvs_f[ 0 ] );
  6645. _uvB.copy( uvs_f[ 1 ] );
  6646. _uvC.copy( uvs_f[ 2 ] );
  6647. intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
  6648. }
  6649. intersection.face = face;
  6650. intersection.faceIndex = f;
  6651. intersects.push( intersection );
  6652. }
  6653. }
  6654. }
  6655. },
  6656. clone: function () {
  6657. return new this.constructor( this.geometry, this.material ).copy( this );
  6658. }
  6659. } );
  6660. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6661. var intersect;
  6662. if ( material.side === BackSide ) {
  6663. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6664. } else {
  6665. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6666. }
  6667. if ( intersect === null ) return null;
  6668. _intersectionPointWorld.copy( point );
  6669. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6670. var distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6671. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6672. return {
  6673. distance: distance,
  6674. point: _intersectionPointWorld.clone(),
  6675. object: object
  6676. };
  6677. }
  6678. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c ) {
  6679. _vA.fromBufferAttribute( position, a );
  6680. _vB.fromBufferAttribute( position, b );
  6681. _vC.fromBufferAttribute( position, c );
  6682. var morphInfluences = object.morphTargetInfluences;
  6683. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6684. _morphA.set( 0, 0, 0 );
  6685. _morphB.set( 0, 0, 0 );
  6686. _morphC.set( 0, 0, 0 );
  6687. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6688. var influence = morphInfluences[ i ];
  6689. var morphAttribute = morphPosition[ i ];
  6690. if ( influence === 0 ) continue;
  6691. _tempA.fromBufferAttribute( morphAttribute, a );
  6692. _tempB.fromBufferAttribute( morphAttribute, b );
  6693. _tempC.fromBufferAttribute( morphAttribute, c );
  6694. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6695. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6696. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6697. }
  6698. _vA.add( _morphA );
  6699. _vB.add( _morphB );
  6700. _vC.add( _morphC );
  6701. }
  6702. var intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6703. if ( intersection ) {
  6704. if ( uv ) {
  6705. _uvA.fromBufferAttribute( uv, a );
  6706. _uvB.fromBufferAttribute( uv, b );
  6707. _uvC.fromBufferAttribute( uv, c );
  6708. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6709. }
  6710. if ( uv2 ) {
  6711. _uvA.fromBufferAttribute( uv2, a );
  6712. _uvB.fromBufferAttribute( uv2, b );
  6713. _uvC.fromBufferAttribute( uv2, c );
  6714. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6715. }
  6716. var face = new Face3( a, b, c );
  6717. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6718. intersection.face = face;
  6719. }
  6720. return intersection;
  6721. }
  6722. /**
  6723. * @author mrdoob / http://mrdoob.com/
  6724. * @author kile / http://kile.stravaganza.org/
  6725. * @author alteredq / http://alteredqualia.com/
  6726. * @author mikael emtinger / http://gomo.se/
  6727. * @author zz85 / http://www.lab4games.net/zz85/blog
  6728. * @author bhouston / http://clara.io
  6729. */
  6730. var _geometryId = 0; // Geometry uses even numbers as Id
  6731. var _m1$3, _obj$1, _offset$1;
  6732. function Geometry() {
  6733. Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
  6734. this.uuid = _Math.generateUUID();
  6735. this.name = '';
  6736. this.type = 'Geometry';
  6737. this.vertices = [];
  6738. this.colors = [];
  6739. this.faces = [];
  6740. this.faceVertexUvs = [[]];
  6741. this.morphTargets = [];
  6742. this.morphNormals = [];
  6743. this.skinWeights = [];
  6744. this.skinIndices = [];
  6745. this.lineDistances = [];
  6746. this.boundingBox = null;
  6747. this.boundingSphere = null;
  6748. // update flags
  6749. this.elementsNeedUpdate = false;
  6750. this.verticesNeedUpdate = false;
  6751. this.uvsNeedUpdate = false;
  6752. this.normalsNeedUpdate = false;
  6753. this.colorsNeedUpdate = false;
  6754. this.lineDistancesNeedUpdate = false;
  6755. this.groupsNeedUpdate = false;
  6756. }
  6757. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6758. constructor: Geometry,
  6759. isGeometry: true,
  6760. applyMatrix: function ( matrix ) {
  6761. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6762. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6763. var vertex = this.vertices[ i ];
  6764. vertex.applyMatrix4( matrix );
  6765. }
  6766. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6767. var face = this.faces[ i ];
  6768. face.normal.applyMatrix3( normalMatrix ).normalize();
  6769. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6770. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6771. }
  6772. }
  6773. if ( this.boundingBox !== null ) {
  6774. this.computeBoundingBox();
  6775. }
  6776. if ( this.boundingSphere !== null ) {
  6777. this.computeBoundingSphere();
  6778. }
  6779. this.verticesNeedUpdate = true;
  6780. this.normalsNeedUpdate = true;
  6781. return this;
  6782. },
  6783. rotateX: function ( angle ) {
  6784. // rotate geometry around world x-axis
  6785. if ( _m1$3 === undefined ) _m1$3 = new Matrix4();
  6786. _m1$3.makeRotationX( angle );
  6787. this.applyMatrix( _m1$3 );
  6788. return this;
  6789. },
  6790. rotateY: function ( angle ) {
  6791. // rotate geometry around world y-axis
  6792. if ( _m1$3 === undefined ) _m1$3 = new Matrix4();
  6793. _m1$3.makeRotationY( angle );
  6794. this.applyMatrix( _m1$3 );
  6795. return this;
  6796. },
  6797. rotateZ: function ( angle ) {
  6798. // rotate geometry around world z-axis
  6799. if ( _m1$3 === undefined ) _m1$3 = new Matrix4();
  6800. _m1$3.makeRotationZ( angle );
  6801. this.applyMatrix( _m1$3 );
  6802. return this;
  6803. },
  6804. translate: function ( x, y, z ) {
  6805. // translate geometry
  6806. if ( _m1$3 === undefined ) _m1$3 = new Matrix4();
  6807. _m1$3.makeTranslation( x, y, z );
  6808. this.applyMatrix( _m1$3 );
  6809. return this;
  6810. },
  6811. scale: function ( x, y, z ) {
  6812. // scale geometry
  6813. if ( _m1$3 === undefined ) _m1$3 = new Matrix4();
  6814. _m1$3.makeScale( x, y, z );
  6815. this.applyMatrix( _m1$3 );
  6816. return this;
  6817. },
  6818. lookAt: function ( vector ) {
  6819. if ( _obj$1 === undefined ) _obj$1 = new Object3D();
  6820. _obj$1.lookAt( vector );
  6821. _obj$1.updateMatrix();
  6822. this.applyMatrix( _obj$1.matrix );
  6823. return this;
  6824. },
  6825. fromBufferGeometry: function ( geometry ) {
  6826. var scope = this;
  6827. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6828. var attributes = geometry.attributes;
  6829. var positions = attributes.position.array;
  6830. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6831. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6832. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6833. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6834. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6835. for ( var i = 0; i < positions.length; i += 3 ) {
  6836. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  6837. if ( colors !== undefined ) {
  6838. scope.colors.push( new Color().fromArray( colors, i ) );
  6839. }
  6840. }
  6841. function addFace( a, b, c, materialIndex ) {
  6842. var vertexColors = ( colors === undefined ) ? [] : [
  6843. scope.colors[ a ].clone(),
  6844. scope.colors[ b ].clone(),
  6845. scope.colors[ c ].clone() ];
  6846. var vertexNormals = ( normals === undefined ) ? [] : [
  6847. new Vector3().fromArray( normals, a * 3 ),
  6848. new Vector3().fromArray( normals, b * 3 ),
  6849. new Vector3().fromArray( normals, c * 3 )
  6850. ];
  6851. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6852. scope.faces.push( face );
  6853. if ( uvs !== undefined ) {
  6854. scope.faceVertexUvs[ 0 ].push( [
  6855. new Vector2().fromArray( uvs, a * 2 ),
  6856. new Vector2().fromArray( uvs, b * 2 ),
  6857. new Vector2().fromArray( uvs, c * 2 )
  6858. ] );
  6859. }
  6860. if ( uvs2 !== undefined ) {
  6861. scope.faceVertexUvs[ 1 ].push( [
  6862. new Vector2().fromArray( uvs2, a * 2 ),
  6863. new Vector2().fromArray( uvs2, b * 2 ),
  6864. new Vector2().fromArray( uvs2, c * 2 )
  6865. ] );
  6866. }
  6867. }
  6868. var groups = geometry.groups;
  6869. if ( groups.length > 0 ) {
  6870. for ( var i = 0; i < groups.length; i ++ ) {
  6871. var group = groups[ i ];
  6872. var start = group.start;
  6873. var count = group.count;
  6874. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6875. if ( indices !== undefined ) {
  6876. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6877. } else {
  6878. addFace( j, j + 1, j + 2, group.materialIndex );
  6879. }
  6880. }
  6881. }
  6882. } else {
  6883. if ( indices !== undefined ) {
  6884. for ( var i = 0; i < indices.length; i += 3 ) {
  6885. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6886. }
  6887. } else {
  6888. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6889. addFace( i, i + 1, i + 2 );
  6890. }
  6891. }
  6892. }
  6893. this.computeFaceNormals();
  6894. if ( geometry.boundingBox !== null ) {
  6895. this.boundingBox = geometry.boundingBox.clone();
  6896. }
  6897. if ( geometry.boundingSphere !== null ) {
  6898. this.boundingSphere = geometry.boundingSphere.clone();
  6899. }
  6900. return this;
  6901. },
  6902. center: function () {
  6903. if ( _offset$1 === undefined ) _offset$1 = new Vector3();
  6904. this.computeBoundingBox();
  6905. this.boundingBox.getCenter( _offset$1 ).negate();
  6906. this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
  6907. return this;
  6908. },
  6909. normalize: function () {
  6910. this.computeBoundingSphere();
  6911. var center = this.boundingSphere.center;
  6912. var radius = this.boundingSphere.radius;
  6913. var s = radius === 0 ? 1 : 1.0 / radius;
  6914. var matrix = new Matrix4();
  6915. matrix.set(
  6916. s, 0, 0, - s * center.x,
  6917. 0, s, 0, - s * center.y,
  6918. 0, 0, s, - s * center.z,
  6919. 0, 0, 0, 1
  6920. );
  6921. this.applyMatrix( matrix );
  6922. return this;
  6923. },
  6924. computeFaceNormals: function () {
  6925. var cb = new Vector3(), ab = new Vector3();
  6926. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6927. var face = this.faces[ f ];
  6928. var vA = this.vertices[ face.a ];
  6929. var vB = this.vertices[ face.b ];
  6930. var vC = this.vertices[ face.c ];
  6931. cb.subVectors( vC, vB );
  6932. ab.subVectors( vA, vB );
  6933. cb.cross( ab );
  6934. cb.normalize();
  6935. face.normal.copy( cb );
  6936. }
  6937. },
  6938. computeVertexNormals: function ( areaWeighted ) {
  6939. if ( areaWeighted === undefined ) areaWeighted = true;
  6940. var v, vl, f, fl, face, vertices;
  6941. vertices = new Array( this.vertices.length );
  6942. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6943. vertices[ v ] = new Vector3();
  6944. }
  6945. if ( areaWeighted ) {
  6946. // vertex normals weighted by triangle areas
  6947. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6948. var vA, vB, vC;
  6949. var cb = new Vector3(), ab = new Vector3();
  6950. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6951. face = this.faces[ f ];
  6952. vA = this.vertices[ face.a ];
  6953. vB = this.vertices[ face.b ];
  6954. vC = this.vertices[ face.c ];
  6955. cb.subVectors( vC, vB );
  6956. ab.subVectors( vA, vB );
  6957. cb.cross( ab );
  6958. vertices[ face.a ].add( cb );
  6959. vertices[ face.b ].add( cb );
  6960. vertices[ face.c ].add( cb );
  6961. }
  6962. } else {
  6963. this.computeFaceNormals();
  6964. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6965. face = this.faces[ f ];
  6966. vertices[ face.a ].add( face.normal );
  6967. vertices[ face.b ].add( face.normal );
  6968. vertices[ face.c ].add( face.normal );
  6969. }
  6970. }
  6971. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6972. vertices[ v ].normalize();
  6973. }
  6974. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6975. face = this.faces[ f ];
  6976. var vertexNormals = face.vertexNormals;
  6977. if ( vertexNormals.length === 3 ) {
  6978. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6979. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6980. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6981. } else {
  6982. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6983. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6984. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6985. }
  6986. }
  6987. if ( this.faces.length > 0 ) {
  6988. this.normalsNeedUpdate = true;
  6989. }
  6990. },
  6991. computeFlatVertexNormals: function () {
  6992. var f, fl, face;
  6993. this.computeFaceNormals();
  6994. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6995. face = this.faces[ f ];
  6996. var vertexNormals = face.vertexNormals;
  6997. if ( vertexNormals.length === 3 ) {
  6998. vertexNormals[ 0 ].copy( face.normal );
  6999. vertexNormals[ 1 ].copy( face.normal );
  7000. vertexNormals[ 2 ].copy( face.normal );
  7001. } else {
  7002. vertexNormals[ 0 ] = face.normal.clone();
  7003. vertexNormals[ 1 ] = face.normal.clone();
  7004. vertexNormals[ 2 ] = face.normal.clone();
  7005. }
  7006. }
  7007. if ( this.faces.length > 0 ) {
  7008. this.normalsNeedUpdate = true;
  7009. }
  7010. },
  7011. computeMorphNormals: function () {
  7012. var i, il, f, fl, face;
  7013. // save original normals
  7014. // - create temp variables on first access
  7015. // otherwise just copy (for faster repeated calls)
  7016. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7017. face = this.faces[ f ];
  7018. if ( ! face.__originalFaceNormal ) {
  7019. face.__originalFaceNormal = face.normal.clone();
  7020. } else {
  7021. face.__originalFaceNormal.copy( face.normal );
  7022. }
  7023. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7024. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7025. if ( ! face.__originalVertexNormals[ i ] ) {
  7026. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7027. } else {
  7028. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7029. }
  7030. }
  7031. }
  7032. // use temp geometry to compute face and vertex normals for each morph
  7033. var tmpGeo = new Geometry();
  7034. tmpGeo.faces = this.faces;
  7035. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7036. // create on first access
  7037. if ( ! this.morphNormals[ i ] ) {
  7038. this.morphNormals[ i ] = {};
  7039. this.morphNormals[ i ].faceNormals = [];
  7040. this.morphNormals[ i ].vertexNormals = [];
  7041. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7042. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7043. var faceNormal, vertexNormals;
  7044. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7045. faceNormal = new Vector3();
  7046. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7047. dstNormalsFace.push( faceNormal );
  7048. dstNormalsVertex.push( vertexNormals );
  7049. }
  7050. }
  7051. var morphNormals = this.morphNormals[ i ];
  7052. // set vertices to morph target
  7053. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7054. // compute morph normals
  7055. tmpGeo.computeFaceNormals();
  7056. tmpGeo.computeVertexNormals();
  7057. // store morph normals
  7058. var faceNormal, vertexNormals;
  7059. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7060. face = this.faces[ f ];
  7061. faceNormal = morphNormals.faceNormals[ f ];
  7062. vertexNormals = morphNormals.vertexNormals[ f ];
  7063. faceNormal.copy( face.normal );
  7064. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7065. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7066. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7067. }
  7068. }
  7069. // restore original normals
  7070. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7071. face = this.faces[ f ];
  7072. face.normal = face.__originalFaceNormal;
  7073. face.vertexNormals = face.__originalVertexNormals;
  7074. }
  7075. },
  7076. computeBoundingBox: function () {
  7077. if ( this.boundingBox === null ) {
  7078. this.boundingBox = new Box3();
  7079. }
  7080. this.boundingBox.setFromPoints( this.vertices );
  7081. },
  7082. computeBoundingSphere: function () {
  7083. if ( this.boundingSphere === null ) {
  7084. this.boundingSphere = new Sphere();
  7085. }
  7086. this.boundingSphere.setFromPoints( this.vertices );
  7087. },
  7088. merge: function ( geometry, matrix, materialIndexOffset ) {
  7089. if ( ! ( geometry && geometry.isGeometry ) ) {
  7090. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7091. return;
  7092. }
  7093. var normalMatrix,
  7094. vertexOffset = this.vertices.length,
  7095. vertices1 = this.vertices,
  7096. vertices2 = geometry.vertices,
  7097. faces1 = this.faces,
  7098. faces2 = geometry.faces,
  7099. colors1 = this.colors,
  7100. colors2 = geometry.colors;
  7101. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7102. if ( matrix !== undefined ) {
  7103. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7104. }
  7105. // vertices
  7106. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7107. var vertex = vertices2[ i ];
  7108. var vertexCopy = vertex.clone();
  7109. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7110. vertices1.push( vertexCopy );
  7111. }
  7112. // colors
  7113. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7114. colors1.push( colors2[ i ].clone() );
  7115. }
  7116. // faces
  7117. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7118. var face = faces2[ i ], faceCopy, normal, color,
  7119. faceVertexNormals = face.vertexNormals,
  7120. faceVertexColors = face.vertexColors;
  7121. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7122. faceCopy.normal.copy( face.normal );
  7123. if ( normalMatrix !== undefined ) {
  7124. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7125. }
  7126. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7127. normal = faceVertexNormals[ j ].clone();
  7128. if ( normalMatrix !== undefined ) {
  7129. normal.applyMatrix3( normalMatrix ).normalize();
  7130. }
  7131. faceCopy.vertexNormals.push( normal );
  7132. }
  7133. faceCopy.color.copy( face.color );
  7134. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7135. color = faceVertexColors[ j ];
  7136. faceCopy.vertexColors.push( color.clone() );
  7137. }
  7138. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7139. faces1.push( faceCopy );
  7140. }
  7141. // uvs
  7142. for ( var i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7143. var faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7144. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7145. for ( var j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7146. var uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7147. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7148. uvsCopy.push( uvs2[ k ].clone() );
  7149. }
  7150. this.faceVertexUvs[ i ].push( uvsCopy );
  7151. }
  7152. }
  7153. },
  7154. mergeMesh: function ( mesh ) {
  7155. if ( ! ( mesh && mesh.isMesh ) ) {
  7156. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7157. return;
  7158. }
  7159. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7160. this.merge( mesh.geometry, mesh.matrix );
  7161. },
  7162. /*
  7163. * Checks for duplicate vertices with hashmap.
  7164. * Duplicated vertices are removed
  7165. * and faces' vertices are updated.
  7166. */
  7167. mergeVertices: function () {
  7168. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7169. var unique = [], changes = [];
  7170. var v, key;
  7171. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7172. var precision = Math.pow( 10, precisionPoints );
  7173. var i, il, face;
  7174. var indices, j, jl;
  7175. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7176. v = this.vertices[ i ];
  7177. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7178. if ( verticesMap[ key ] === undefined ) {
  7179. verticesMap[ key ] = i;
  7180. unique.push( this.vertices[ i ] );
  7181. changes[ i ] = unique.length - 1;
  7182. } else {
  7183. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7184. changes[ i ] = changes[ verticesMap[ key ] ];
  7185. }
  7186. }
  7187. // if faces are completely degenerate after merging vertices, we
  7188. // have to remove them from the geometry.
  7189. var faceIndicesToRemove = [];
  7190. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7191. face = this.faces[ i ];
  7192. face.a = changes[ face.a ];
  7193. face.b = changes[ face.b ];
  7194. face.c = changes[ face.c ];
  7195. indices = [ face.a, face.b, face.c ];
  7196. // if any duplicate vertices are found in a Face3
  7197. // we have to remove the face as nothing can be saved
  7198. for ( var n = 0; n < 3; n ++ ) {
  7199. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7200. faceIndicesToRemove.push( i );
  7201. break;
  7202. }
  7203. }
  7204. }
  7205. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7206. var idx = faceIndicesToRemove[ i ];
  7207. this.faces.splice( idx, 1 );
  7208. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7209. this.faceVertexUvs[ j ].splice( idx, 1 );
  7210. }
  7211. }
  7212. // Use unique set of vertices
  7213. var diff = this.vertices.length - unique.length;
  7214. this.vertices = unique;
  7215. return diff;
  7216. },
  7217. setFromPoints: function ( points ) {
  7218. this.vertices = [];
  7219. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7220. var point = points[ i ];
  7221. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7222. }
  7223. return this;
  7224. },
  7225. sortFacesByMaterialIndex: function () {
  7226. var faces = this.faces;
  7227. var length = faces.length;
  7228. // tag faces
  7229. for ( var i = 0; i < length; i ++ ) {
  7230. faces[ i ]._id = i;
  7231. }
  7232. // sort faces
  7233. function materialIndexSort( a, b ) {
  7234. return a.materialIndex - b.materialIndex;
  7235. }
  7236. faces.sort( materialIndexSort );
  7237. // sort uvs
  7238. var uvs1 = this.faceVertexUvs[ 0 ];
  7239. var uvs2 = this.faceVertexUvs[ 1 ];
  7240. var newUvs1, newUvs2;
  7241. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7242. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7243. for ( var i = 0; i < length; i ++ ) {
  7244. var id = faces[ i ]._id;
  7245. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7246. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7247. }
  7248. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7249. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7250. },
  7251. toJSON: function () {
  7252. var data = {
  7253. metadata: {
  7254. version: 4.5,
  7255. type: 'Geometry',
  7256. generator: 'Geometry.toJSON'
  7257. }
  7258. };
  7259. // standard Geometry serialization
  7260. data.uuid = this.uuid;
  7261. data.type = this.type;
  7262. if ( this.name !== '' ) data.name = this.name;
  7263. if ( this.parameters !== undefined ) {
  7264. var parameters = this.parameters;
  7265. for ( var key in parameters ) {
  7266. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7267. }
  7268. return data;
  7269. }
  7270. var vertices = [];
  7271. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7272. var vertex = this.vertices[ i ];
  7273. vertices.push( vertex.x, vertex.y, vertex.z );
  7274. }
  7275. var faces = [];
  7276. var normals = [];
  7277. var normalsHash = {};
  7278. var colors = [];
  7279. var colorsHash = {};
  7280. var uvs = [];
  7281. var uvsHash = {};
  7282. for ( var i = 0; i < this.faces.length; i ++ ) {
  7283. var face = this.faces[ i ];
  7284. var hasMaterial = true;
  7285. var hasFaceUv = false; // deprecated
  7286. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7287. var hasFaceNormal = face.normal.length() > 0;
  7288. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7289. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7290. var hasFaceVertexColor = face.vertexColors.length > 0;
  7291. var faceType = 0;
  7292. faceType = setBit( faceType, 0, 0 ); // isQuad
  7293. faceType = setBit( faceType, 1, hasMaterial );
  7294. faceType = setBit( faceType, 2, hasFaceUv );
  7295. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7296. faceType = setBit( faceType, 4, hasFaceNormal );
  7297. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7298. faceType = setBit( faceType, 6, hasFaceColor );
  7299. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7300. faces.push( faceType );
  7301. faces.push( face.a, face.b, face.c );
  7302. faces.push( face.materialIndex );
  7303. if ( hasFaceVertexUv ) {
  7304. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7305. faces.push(
  7306. getUvIndex( faceVertexUvs[ 0 ] ),
  7307. getUvIndex( faceVertexUvs[ 1 ] ),
  7308. getUvIndex( faceVertexUvs[ 2 ] )
  7309. );
  7310. }
  7311. if ( hasFaceNormal ) {
  7312. faces.push( getNormalIndex( face.normal ) );
  7313. }
  7314. if ( hasFaceVertexNormal ) {
  7315. var vertexNormals = face.vertexNormals;
  7316. faces.push(
  7317. getNormalIndex( vertexNormals[ 0 ] ),
  7318. getNormalIndex( vertexNormals[ 1 ] ),
  7319. getNormalIndex( vertexNormals[ 2 ] )
  7320. );
  7321. }
  7322. if ( hasFaceColor ) {
  7323. faces.push( getColorIndex( face.color ) );
  7324. }
  7325. if ( hasFaceVertexColor ) {
  7326. var vertexColors = face.vertexColors;
  7327. faces.push(
  7328. getColorIndex( vertexColors[ 0 ] ),
  7329. getColorIndex( vertexColors[ 1 ] ),
  7330. getColorIndex( vertexColors[ 2 ] )
  7331. );
  7332. }
  7333. }
  7334. function setBit( value, position, enabled ) {
  7335. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7336. }
  7337. function getNormalIndex( normal ) {
  7338. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7339. if ( normalsHash[ hash ] !== undefined ) {
  7340. return normalsHash[ hash ];
  7341. }
  7342. normalsHash[ hash ] = normals.length / 3;
  7343. normals.push( normal.x, normal.y, normal.z );
  7344. return normalsHash[ hash ];
  7345. }
  7346. function getColorIndex( color ) {
  7347. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7348. if ( colorsHash[ hash ] !== undefined ) {
  7349. return colorsHash[ hash ];
  7350. }
  7351. colorsHash[ hash ] = colors.length;
  7352. colors.push( color.getHex() );
  7353. return colorsHash[ hash ];
  7354. }
  7355. function getUvIndex( uv ) {
  7356. var hash = uv.x.toString() + uv.y.toString();
  7357. if ( uvsHash[ hash ] !== undefined ) {
  7358. return uvsHash[ hash ];
  7359. }
  7360. uvsHash[ hash ] = uvs.length / 2;
  7361. uvs.push( uv.x, uv.y );
  7362. return uvsHash[ hash ];
  7363. }
  7364. data.data = {};
  7365. data.data.vertices = vertices;
  7366. data.data.normals = normals;
  7367. if ( colors.length > 0 ) data.data.colors = colors;
  7368. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7369. data.data.faces = faces;
  7370. return data;
  7371. },
  7372. clone: function () {
  7373. /*
  7374. // Handle primitives
  7375. var parameters = this.parameters;
  7376. if ( parameters !== undefined ) {
  7377. var values = [];
  7378. for ( var key in parameters ) {
  7379. values.push( parameters[ key ] );
  7380. }
  7381. var geometry = Object.create( this.constructor.prototype );
  7382. this.constructor.apply( geometry, values );
  7383. return geometry;
  7384. }
  7385. return new this.constructor().copy( this );
  7386. */
  7387. return new Geometry().copy( this );
  7388. },
  7389. copy: function ( source ) {
  7390. var i, il, j, jl, k, kl;
  7391. // reset
  7392. this.vertices = [];
  7393. this.colors = [];
  7394. this.faces = [];
  7395. this.faceVertexUvs = [[]];
  7396. this.morphTargets = [];
  7397. this.morphNormals = [];
  7398. this.skinWeights = [];
  7399. this.skinIndices = [];
  7400. this.lineDistances = [];
  7401. this.boundingBox = null;
  7402. this.boundingSphere = null;
  7403. // name
  7404. this.name = source.name;
  7405. // vertices
  7406. var vertices = source.vertices;
  7407. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7408. this.vertices.push( vertices[ i ].clone() );
  7409. }
  7410. // colors
  7411. var colors = source.colors;
  7412. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7413. this.colors.push( colors[ i ].clone() );
  7414. }
  7415. // faces
  7416. var faces = source.faces;
  7417. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7418. this.faces.push( faces[ i ].clone() );
  7419. }
  7420. // face vertex uvs
  7421. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7422. var faceVertexUvs = source.faceVertexUvs[ i ];
  7423. if ( this.faceVertexUvs[ i ] === undefined ) {
  7424. this.faceVertexUvs[ i ] = [];
  7425. }
  7426. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7427. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7428. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7429. var uv = uvs[ k ];
  7430. uvsCopy.push( uv.clone() );
  7431. }
  7432. this.faceVertexUvs[ i ].push( uvsCopy );
  7433. }
  7434. }
  7435. // morph targets
  7436. var morphTargets = source.morphTargets;
  7437. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7438. var morphTarget = {};
  7439. morphTarget.name = morphTargets[ i ].name;
  7440. // vertices
  7441. if ( morphTargets[ i ].vertices !== undefined ) {
  7442. morphTarget.vertices = [];
  7443. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7444. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7445. }
  7446. }
  7447. // normals
  7448. if ( morphTargets[ i ].normals !== undefined ) {
  7449. morphTarget.normals = [];
  7450. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7451. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7452. }
  7453. }
  7454. this.morphTargets.push( morphTarget );
  7455. }
  7456. // morph normals
  7457. var morphNormals = source.morphNormals;
  7458. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7459. var morphNormal = {};
  7460. // vertex normals
  7461. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7462. morphNormal.vertexNormals = [];
  7463. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7464. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7465. var destVertexNormal = {};
  7466. destVertexNormal.a = srcVertexNormal.a.clone();
  7467. destVertexNormal.b = srcVertexNormal.b.clone();
  7468. destVertexNormal.c = srcVertexNormal.c.clone();
  7469. morphNormal.vertexNormals.push( destVertexNormal );
  7470. }
  7471. }
  7472. // face normals
  7473. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7474. morphNormal.faceNormals = [];
  7475. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7476. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7477. }
  7478. }
  7479. this.morphNormals.push( morphNormal );
  7480. }
  7481. // skin weights
  7482. var skinWeights = source.skinWeights;
  7483. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7484. this.skinWeights.push( skinWeights[ i ].clone() );
  7485. }
  7486. // skin indices
  7487. var skinIndices = source.skinIndices;
  7488. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7489. this.skinIndices.push( skinIndices[ i ].clone() );
  7490. }
  7491. // line distances
  7492. var lineDistances = source.lineDistances;
  7493. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7494. this.lineDistances.push( lineDistances[ i ] );
  7495. }
  7496. // bounding box
  7497. var boundingBox = source.boundingBox;
  7498. if ( boundingBox !== null ) {
  7499. this.boundingBox = boundingBox.clone();
  7500. }
  7501. // bounding sphere
  7502. var boundingSphere = source.boundingSphere;
  7503. if ( boundingSphere !== null ) {
  7504. this.boundingSphere = boundingSphere.clone();
  7505. }
  7506. // update flags
  7507. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7508. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7509. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7510. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7511. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7512. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7513. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7514. return this;
  7515. },
  7516. dispose: function () {
  7517. this.dispatchEvent( { type: 'dispose' } );
  7518. }
  7519. } );
  7520. /**
  7521. * @author mrdoob / http://mrdoob.com/
  7522. * @author Mugen87 / https://github.com/Mugen87
  7523. */
  7524. // BoxGeometry
  7525. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7526. Geometry.call( this );
  7527. this.type = 'BoxGeometry';
  7528. this.parameters = {
  7529. width: width,
  7530. height: height,
  7531. depth: depth,
  7532. widthSegments: widthSegments,
  7533. heightSegments: heightSegments,
  7534. depthSegments: depthSegments
  7535. };
  7536. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7537. this.mergeVertices();
  7538. }
  7539. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7540. BoxGeometry.prototype.constructor = BoxGeometry;
  7541. // BoxBufferGeometry
  7542. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7543. BufferGeometry.call( this );
  7544. this.type = 'BoxBufferGeometry';
  7545. this.parameters = {
  7546. width: width,
  7547. height: height,
  7548. depth: depth,
  7549. widthSegments: widthSegments,
  7550. heightSegments: heightSegments,
  7551. depthSegments: depthSegments
  7552. };
  7553. var scope = this;
  7554. width = width || 1;
  7555. height = height || 1;
  7556. depth = depth || 1;
  7557. // segments
  7558. widthSegments = Math.floor( widthSegments ) || 1;
  7559. heightSegments = Math.floor( heightSegments ) || 1;
  7560. depthSegments = Math.floor( depthSegments ) || 1;
  7561. // buffers
  7562. var indices = [];
  7563. var vertices = [];
  7564. var normals = [];
  7565. var uvs = [];
  7566. // helper variables
  7567. var numberOfVertices = 0;
  7568. var groupStart = 0;
  7569. // build each side of the box geometry
  7570. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7571. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7572. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7573. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7574. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7575. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7576. // build geometry
  7577. this.setIndex( indices );
  7578. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7579. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7580. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7581. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7582. var segmentWidth = width / gridX;
  7583. var segmentHeight = height / gridY;
  7584. var widthHalf = width / 2;
  7585. var heightHalf = height / 2;
  7586. var depthHalf = depth / 2;
  7587. var gridX1 = gridX + 1;
  7588. var gridY1 = gridY + 1;
  7589. var vertexCounter = 0;
  7590. var groupCount = 0;
  7591. var ix, iy;
  7592. var vector = new Vector3();
  7593. // generate vertices, normals and uvs
  7594. for ( iy = 0; iy < gridY1; iy ++ ) {
  7595. var y = iy * segmentHeight - heightHalf;
  7596. for ( ix = 0; ix < gridX1; ix ++ ) {
  7597. var x = ix * segmentWidth - widthHalf;
  7598. // set values to correct vector component
  7599. vector[ u ] = x * udir;
  7600. vector[ v ] = y * vdir;
  7601. vector[ w ] = depthHalf;
  7602. // now apply vector to vertex buffer
  7603. vertices.push( vector.x, vector.y, vector.z );
  7604. // set values to correct vector component
  7605. vector[ u ] = 0;
  7606. vector[ v ] = 0;
  7607. vector[ w ] = depth > 0 ? 1 : - 1;
  7608. // now apply vector to normal buffer
  7609. normals.push( vector.x, vector.y, vector.z );
  7610. // uvs
  7611. uvs.push( ix / gridX );
  7612. uvs.push( 1 - ( iy / gridY ) );
  7613. // counters
  7614. vertexCounter += 1;
  7615. }
  7616. }
  7617. // indices
  7618. // 1. you need three indices to draw a single face
  7619. // 2. a single segment consists of two faces
  7620. // 3. so we need to generate six (2*3) indices per segment
  7621. for ( iy = 0; iy < gridY; iy ++ ) {
  7622. for ( ix = 0; ix < gridX; ix ++ ) {
  7623. var a = numberOfVertices + ix + gridX1 * iy;
  7624. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7625. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7626. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7627. // faces
  7628. indices.push( a, b, d );
  7629. indices.push( b, c, d );
  7630. // increase counter
  7631. groupCount += 6;
  7632. }
  7633. }
  7634. // add a group to the geometry. this will ensure multi material support
  7635. scope.addGroup( groupStart, groupCount, materialIndex );
  7636. // calculate new start value for groups
  7637. groupStart += groupCount;
  7638. // update total number of vertices
  7639. numberOfVertices += vertexCounter;
  7640. }
  7641. }
  7642. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7643. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7644. /**
  7645. * Uniform Utilities
  7646. */
  7647. function cloneUniforms( src ) {
  7648. var dst = {};
  7649. for ( var u in src ) {
  7650. dst[ u ] = {};
  7651. for ( var p in src[ u ] ) {
  7652. var property = src[ u ][ p ];
  7653. if ( property && ( property.isColor ||
  7654. property.isMatrix3 || property.isMatrix4 ||
  7655. property.isVector2 || property.isVector3 || property.isVector4 ||
  7656. property.isTexture ) ) {
  7657. dst[ u ][ p ] = property.clone();
  7658. } else if ( Array.isArray( property ) ) {
  7659. dst[ u ][ p ] = property.slice();
  7660. } else {
  7661. dst[ u ][ p ] = property;
  7662. }
  7663. }
  7664. }
  7665. return dst;
  7666. }
  7667. function mergeUniforms( uniforms ) {
  7668. var merged = {};
  7669. for ( var u = 0; u < uniforms.length; u ++ ) {
  7670. var tmp = cloneUniforms( uniforms[ u ] );
  7671. for ( var p in tmp ) {
  7672. merged[ p ] = tmp[ p ];
  7673. }
  7674. }
  7675. return merged;
  7676. }
  7677. // Legacy
  7678. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7679. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7680. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7681. /**
  7682. * @author alteredq / http://alteredqualia.com/
  7683. *
  7684. * parameters = {
  7685. * defines: { "label" : "value" },
  7686. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7687. *
  7688. * fragmentShader: <string>,
  7689. * vertexShader: <string>,
  7690. *
  7691. * wireframe: <boolean>,
  7692. * wireframeLinewidth: <float>,
  7693. *
  7694. * lights: <bool>,
  7695. *
  7696. * skinning: <bool>,
  7697. * morphTargets: <bool>,
  7698. * morphNormals: <bool>
  7699. * }
  7700. */
  7701. function ShaderMaterial( parameters ) {
  7702. Material.call( this );
  7703. this.type = 'ShaderMaterial';
  7704. this.defines = {};
  7705. this.uniforms = {};
  7706. this.vertexShader = default_vertex;
  7707. this.fragmentShader = default_fragment;
  7708. this.linewidth = 1;
  7709. this.wireframe = false;
  7710. this.wireframeLinewidth = 1;
  7711. this.fog = false; // set to use scene fog
  7712. this.lights = false; // set to use scene lights
  7713. this.clipping = false; // set to use user-defined clipping planes
  7714. this.skinning = false; // set to use skinning attribute streams
  7715. this.morphTargets = false; // set to use morph targets
  7716. this.morphNormals = false; // set to use morph normals
  7717. this.extensions = {
  7718. derivatives: false, // set to use derivatives
  7719. fragDepth: false, // set to use fragment depth values
  7720. drawBuffers: false, // set to use draw buffers
  7721. shaderTextureLOD: false // set to use shader texture LOD
  7722. };
  7723. // When rendered geometry doesn't include these attributes but the material does,
  7724. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7725. this.defaultAttributeValues = {
  7726. 'color': [ 1, 1, 1 ],
  7727. 'uv': [ 0, 0 ],
  7728. 'uv2': [ 0, 0 ]
  7729. };
  7730. this.index0AttributeName = undefined;
  7731. this.uniformsNeedUpdate = false;
  7732. if ( parameters !== undefined ) {
  7733. if ( parameters.attributes !== undefined ) {
  7734. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7735. }
  7736. this.setValues( parameters );
  7737. }
  7738. }
  7739. ShaderMaterial.prototype = Object.create( Material.prototype );
  7740. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7741. ShaderMaterial.prototype.isShaderMaterial = true;
  7742. ShaderMaterial.prototype.copy = function ( source ) {
  7743. Material.prototype.copy.call( this, source );
  7744. this.fragmentShader = source.fragmentShader;
  7745. this.vertexShader = source.vertexShader;
  7746. this.uniforms = cloneUniforms( source.uniforms );
  7747. this.defines = Object.assign( {}, source.defines );
  7748. this.wireframe = source.wireframe;
  7749. this.wireframeLinewidth = source.wireframeLinewidth;
  7750. this.lights = source.lights;
  7751. this.clipping = source.clipping;
  7752. this.skinning = source.skinning;
  7753. this.morphTargets = source.morphTargets;
  7754. this.morphNormals = source.morphNormals;
  7755. this.extensions = source.extensions;
  7756. return this;
  7757. };
  7758. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7759. var data = Material.prototype.toJSON.call( this, meta );
  7760. data.uniforms = {};
  7761. for ( var name in this.uniforms ) {
  7762. var uniform = this.uniforms[ name ];
  7763. var value = uniform.value;
  7764. if ( value && value.isTexture ) {
  7765. data.uniforms[ name ] = {
  7766. type: 't',
  7767. value: value.toJSON( meta ).uuid
  7768. };
  7769. } else if ( value && value.isColor ) {
  7770. data.uniforms[ name ] = {
  7771. type: 'c',
  7772. value: value.getHex()
  7773. };
  7774. } else if ( value && value.isVector2 ) {
  7775. data.uniforms[ name ] = {
  7776. type: 'v2',
  7777. value: value.toArray()
  7778. };
  7779. } else if ( value && value.isVector3 ) {
  7780. data.uniforms[ name ] = {
  7781. type: 'v3',
  7782. value: value.toArray()
  7783. };
  7784. } else if ( value && value.isVector4 ) {
  7785. data.uniforms[ name ] = {
  7786. type: 'v4',
  7787. value: value.toArray()
  7788. };
  7789. } else if ( value && value.isMatrix3 ) {
  7790. data.uniforms[ name ] = {
  7791. type: 'm3',
  7792. value: value.toArray()
  7793. };
  7794. } else if ( value && value.isMatrix4 ) {
  7795. data.uniforms[ name ] = {
  7796. type: 'm4',
  7797. value: value.toArray()
  7798. };
  7799. } else {
  7800. data.uniforms[ name ] = {
  7801. value: value
  7802. };
  7803. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7804. }
  7805. }
  7806. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7807. data.vertexShader = this.vertexShader;
  7808. data.fragmentShader = this.fragmentShader;
  7809. var extensions = {};
  7810. for ( var key in this.extensions ) {
  7811. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7812. }
  7813. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7814. return data;
  7815. };
  7816. /**
  7817. * @author mrdoob / http://mrdoob.com/
  7818. * @author mikael emtinger / http://gomo.se/
  7819. * @author WestLangley / http://github.com/WestLangley
  7820. */
  7821. function Camera() {
  7822. Object3D.call( this );
  7823. this.type = 'Camera';
  7824. this.matrixWorldInverse = new Matrix4();
  7825. this.projectionMatrix = new Matrix4();
  7826. this.projectionMatrixInverse = new Matrix4();
  7827. }
  7828. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7829. constructor: Camera,
  7830. isCamera: true,
  7831. copy: function ( source, recursive ) {
  7832. Object3D.prototype.copy.call( this, source, recursive );
  7833. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7834. this.projectionMatrix.copy( source.projectionMatrix );
  7835. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7836. return this;
  7837. },
  7838. getWorldDirection: function ( target ) {
  7839. if ( target === undefined ) {
  7840. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7841. target = new Vector3();
  7842. }
  7843. this.updateMatrixWorld( true );
  7844. var e = this.matrixWorld.elements;
  7845. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7846. },
  7847. updateMatrixWorld: function ( force ) {
  7848. Object3D.prototype.updateMatrixWorld.call( this, force );
  7849. this.matrixWorldInverse.getInverse( this.matrixWorld );
  7850. },
  7851. clone: function () {
  7852. return new this.constructor().copy( this );
  7853. }
  7854. } );
  7855. /**
  7856. * @author mrdoob / http://mrdoob.com/
  7857. * @author greggman / http://games.greggman.com/
  7858. * @author zz85 / http://www.lab4games.net/zz85/blog
  7859. * @author tschw
  7860. */
  7861. function PerspectiveCamera( fov, aspect, near, far ) {
  7862. Camera.call( this );
  7863. this.type = 'PerspectiveCamera';
  7864. this.fov = fov !== undefined ? fov : 50;
  7865. this.zoom = 1;
  7866. this.near = near !== undefined ? near : 0.1;
  7867. this.far = far !== undefined ? far : 2000;
  7868. this.focus = 10;
  7869. this.aspect = aspect !== undefined ? aspect : 1;
  7870. this.view = null;
  7871. this.filmGauge = 35; // width of the film (default in millimeters)
  7872. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7873. this.updateProjectionMatrix();
  7874. }
  7875. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7876. constructor: PerspectiveCamera,
  7877. isPerspectiveCamera: true,
  7878. copy: function ( source, recursive ) {
  7879. Camera.prototype.copy.call( this, source, recursive );
  7880. this.fov = source.fov;
  7881. this.zoom = source.zoom;
  7882. this.near = source.near;
  7883. this.far = source.far;
  7884. this.focus = source.focus;
  7885. this.aspect = source.aspect;
  7886. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7887. this.filmGauge = source.filmGauge;
  7888. this.filmOffset = source.filmOffset;
  7889. return this;
  7890. },
  7891. /**
  7892. * Sets the FOV by focal length in respect to the current .filmGauge.
  7893. *
  7894. * The default film gauge is 35, so that the focal length can be specified for
  7895. * a 35mm (full frame) camera.
  7896. *
  7897. * Values for focal length and film gauge must have the same unit.
  7898. */
  7899. setFocalLength: function ( focalLength ) {
  7900. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7901. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7902. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7903. this.updateProjectionMatrix();
  7904. },
  7905. /**
  7906. * Calculates the focal length from the current .fov and .filmGauge.
  7907. */
  7908. getFocalLength: function () {
  7909. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  7910. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7911. },
  7912. getEffectiveFOV: function () {
  7913. return _Math.RAD2DEG * 2 * Math.atan(
  7914. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7915. },
  7916. getFilmWidth: function () {
  7917. // film not completely covered in portrait format (aspect < 1)
  7918. return this.filmGauge * Math.min( this.aspect, 1 );
  7919. },
  7920. getFilmHeight: function () {
  7921. // film not completely covered in landscape format (aspect > 1)
  7922. return this.filmGauge / Math.max( this.aspect, 1 );
  7923. },
  7924. /**
  7925. * Sets an offset in a larger frustum. This is useful for multi-window or
  7926. * multi-monitor/multi-machine setups.
  7927. *
  7928. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7929. * the monitors are in grid like this
  7930. *
  7931. * +---+---+---+
  7932. * | A | B | C |
  7933. * +---+---+---+
  7934. * | D | E | F |
  7935. * +---+---+---+
  7936. *
  7937. * then for each monitor you would call it like this
  7938. *
  7939. * var w = 1920;
  7940. * var h = 1080;
  7941. * var fullWidth = w * 3;
  7942. * var fullHeight = h * 2;
  7943. *
  7944. * --A--
  7945. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7946. * --B--
  7947. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7948. * --C--
  7949. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7950. * --D--
  7951. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7952. * --E--
  7953. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7954. * --F--
  7955. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7956. *
  7957. * Note there is no reason monitors have to be the same size or in a grid.
  7958. */
  7959. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  7960. this.aspect = fullWidth / fullHeight;
  7961. if ( this.view === null ) {
  7962. this.view = {
  7963. enabled: true,
  7964. fullWidth: 1,
  7965. fullHeight: 1,
  7966. offsetX: 0,
  7967. offsetY: 0,
  7968. width: 1,
  7969. height: 1
  7970. };
  7971. }
  7972. this.view.enabled = true;
  7973. this.view.fullWidth = fullWidth;
  7974. this.view.fullHeight = fullHeight;
  7975. this.view.offsetX = x;
  7976. this.view.offsetY = y;
  7977. this.view.width = width;
  7978. this.view.height = height;
  7979. this.updateProjectionMatrix();
  7980. },
  7981. clearViewOffset: function () {
  7982. if ( this.view !== null ) {
  7983. this.view.enabled = false;
  7984. }
  7985. this.updateProjectionMatrix();
  7986. },
  7987. updateProjectionMatrix: function () {
  7988. var near = this.near,
  7989. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  7990. height = 2 * top,
  7991. width = this.aspect * height,
  7992. left = - 0.5 * width,
  7993. view = this.view;
  7994. if ( this.view !== null && this.view.enabled ) {
  7995. var fullWidth = view.fullWidth,
  7996. fullHeight = view.fullHeight;
  7997. left += view.offsetX * width / fullWidth;
  7998. top -= view.offsetY * height / fullHeight;
  7999. width *= view.width / fullWidth;
  8000. height *= view.height / fullHeight;
  8001. }
  8002. var skew = this.filmOffset;
  8003. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8004. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8005. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8006. },
  8007. toJSON: function ( meta ) {
  8008. var data = Object3D.prototype.toJSON.call( this, meta );
  8009. data.object.fov = this.fov;
  8010. data.object.zoom = this.zoom;
  8011. data.object.near = this.near;
  8012. data.object.far = this.far;
  8013. data.object.focus = this.focus;
  8014. data.object.aspect = this.aspect;
  8015. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8016. data.object.filmGauge = this.filmGauge;
  8017. data.object.filmOffset = this.filmOffset;
  8018. return data;
  8019. }
  8020. } );
  8021. /**
  8022. * Camera for rendering cube maps
  8023. * - renders scene into axis-aligned cube
  8024. *
  8025. * @author alteredq / http://alteredqualia.com/
  8026. */
  8027. var fov = 90, aspect = 1;
  8028. function CubeCamera( near, far, cubeResolution, options ) {
  8029. Object3D.call( this );
  8030. this.type = 'CubeCamera';
  8031. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8032. cameraPX.up.set( 0, - 1, 0 );
  8033. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8034. this.add( cameraPX );
  8035. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8036. cameraNX.up.set( 0, - 1, 0 );
  8037. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8038. this.add( cameraNX );
  8039. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8040. cameraPY.up.set( 0, 0, 1 );
  8041. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8042. this.add( cameraPY );
  8043. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8044. cameraNY.up.set( 0, 0, - 1 );
  8045. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8046. this.add( cameraNY );
  8047. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8048. cameraPZ.up.set( 0, - 1, 0 );
  8049. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8050. this.add( cameraPZ );
  8051. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8052. cameraNZ.up.set( 0, - 1, 0 );
  8053. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8054. this.add( cameraNZ );
  8055. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  8056. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  8057. this.renderTarget.texture.name = "CubeCamera";
  8058. this.update = function ( renderer, scene ) {
  8059. if ( this.parent === null ) this.updateMatrixWorld();
  8060. var currentRenderTarget = renderer.getRenderTarget();
  8061. var renderTarget = this.renderTarget;
  8062. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8063. renderTarget.texture.generateMipmaps = false;
  8064. renderer.setRenderTarget( renderTarget, 0 );
  8065. renderer.render( scene, cameraPX );
  8066. renderer.setRenderTarget( renderTarget, 1 );
  8067. renderer.render( scene, cameraNX );
  8068. renderer.setRenderTarget( renderTarget, 2 );
  8069. renderer.render( scene, cameraPY );
  8070. renderer.setRenderTarget( renderTarget, 3 );
  8071. renderer.render( scene, cameraNY );
  8072. renderer.setRenderTarget( renderTarget, 4 );
  8073. renderer.render( scene, cameraPZ );
  8074. renderTarget.texture.generateMipmaps = generateMipmaps;
  8075. renderer.setRenderTarget( renderTarget, 5 );
  8076. renderer.render( scene, cameraNZ );
  8077. renderer.setRenderTarget( currentRenderTarget );
  8078. };
  8079. this.clear = function ( renderer, color, depth, stencil ) {
  8080. var currentRenderTarget = renderer.getRenderTarget();
  8081. var renderTarget = this.renderTarget;
  8082. for ( var i = 0; i < 6; i ++ ) {
  8083. renderer.setRenderTarget( renderTarget, i );
  8084. renderer.clear( color, depth, stencil );
  8085. }
  8086. renderer.setRenderTarget( currentRenderTarget );
  8087. };
  8088. }
  8089. CubeCamera.prototype = Object.create( Object3D.prototype );
  8090. CubeCamera.prototype.constructor = CubeCamera;
  8091. /**
  8092. * @author alteredq / http://alteredqualia.com
  8093. * @author WestLangley / http://github.com/WestLangley
  8094. */
  8095. function WebGLRenderTargetCube( width, height, options ) {
  8096. WebGLRenderTarget.call( this, width, height, options );
  8097. }
  8098. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  8099. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  8100. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  8101. WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8102. this.texture.type = texture.type;
  8103. this.texture.format = texture.format;
  8104. this.texture.encoding = texture.encoding;
  8105. var scene = new Scene();
  8106. var shader = {
  8107. uniforms: {
  8108. tEquirect: { value: null },
  8109. },
  8110. vertexShader: [
  8111. "varying vec3 vWorldDirection;",
  8112. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8113. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8114. "}",
  8115. "void main() {",
  8116. " vWorldDirection = transformDirection( position, modelMatrix );",
  8117. " #include <begin_vertex>",
  8118. " #include <project_vertex>",
  8119. "}"
  8120. ].join( '\n' ),
  8121. fragmentShader: [
  8122. "uniform sampler2D tEquirect;",
  8123. "varying vec3 vWorldDirection;",
  8124. "#define RECIPROCAL_PI 0.31830988618",
  8125. "#define RECIPROCAL_PI2 0.15915494",
  8126. "void main() {",
  8127. " vec3 direction = normalize( vWorldDirection );",
  8128. " vec2 sampleUV;",
  8129. " sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
  8130. " sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  8131. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8132. "}"
  8133. ].join( '\n' ),
  8134. };
  8135. var material = new ShaderMaterial( {
  8136. type: 'CubemapFromEquirect',
  8137. uniforms: cloneUniforms( shader.uniforms ),
  8138. vertexShader: shader.vertexShader,
  8139. fragmentShader: shader.fragmentShader,
  8140. side: BackSide,
  8141. blending: NoBlending
  8142. } );
  8143. material.uniforms.tEquirect.value = texture;
  8144. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8145. scene.add( mesh );
  8146. var camera = new CubeCamera( 1, 10, 1 );
  8147. camera.renderTarget = this;
  8148. camera.renderTarget.texture.name = 'CubeCameraTexture';
  8149. camera.update( renderer, scene );
  8150. mesh.geometry.dispose();
  8151. mesh.material.dispose();
  8152. return this;
  8153. };
  8154. /**
  8155. * @author alteredq / http://alteredqualia.com/
  8156. */
  8157. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8158. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8159. this.image = { data: data, width: width, height: height };
  8160. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8161. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8162. this.generateMipmaps = false;
  8163. this.flipY = false;
  8164. this.unpackAlignment = 1;
  8165. }
  8166. DataTexture.prototype = Object.create( Texture.prototype );
  8167. DataTexture.prototype.constructor = DataTexture;
  8168. DataTexture.prototype.isDataTexture = true;
  8169. /**
  8170. * @author bhouston / http://clara.io
  8171. */
  8172. var _vector1, _vector2, _normalMatrix;
  8173. function Plane( normal, constant ) {
  8174. // normal is assumed to be normalized
  8175. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  8176. this.constant = ( constant !== undefined ) ? constant : 0;
  8177. }
  8178. Object.assign( Plane.prototype, {
  8179. isPlane: true,
  8180. set: function ( normal, constant ) {
  8181. this.normal.copy( normal );
  8182. this.constant = constant;
  8183. return this;
  8184. },
  8185. setComponents: function ( x, y, z, w ) {
  8186. this.normal.set( x, y, z );
  8187. this.constant = w;
  8188. return this;
  8189. },
  8190. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  8191. this.normal.copy( normal );
  8192. this.constant = - point.dot( this.normal );
  8193. return this;
  8194. },
  8195. setFromCoplanarPoints: function ( a, b, c ) {
  8196. if ( _vector1 === undefined ) {
  8197. _vector1 = new Vector3();
  8198. _vector2 = new Vector3();
  8199. }
  8200. var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  8201. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8202. this.setFromNormalAndCoplanarPoint( normal, a );
  8203. return this;
  8204. },
  8205. clone: function () {
  8206. return new this.constructor().copy( this );
  8207. },
  8208. copy: function ( plane ) {
  8209. this.normal.copy( plane.normal );
  8210. this.constant = plane.constant;
  8211. return this;
  8212. },
  8213. normalize: function () {
  8214. // Note: will lead to a divide by zero if the plane is invalid.
  8215. var inverseNormalLength = 1.0 / this.normal.length();
  8216. this.normal.multiplyScalar( inverseNormalLength );
  8217. this.constant *= inverseNormalLength;
  8218. return this;
  8219. },
  8220. negate: function () {
  8221. this.constant *= - 1;
  8222. this.normal.negate();
  8223. return this;
  8224. },
  8225. distanceToPoint: function ( point ) {
  8226. return this.normal.dot( point ) + this.constant;
  8227. },
  8228. distanceToSphere: function ( sphere ) {
  8229. return this.distanceToPoint( sphere.center ) - sphere.radius;
  8230. },
  8231. projectPoint: function ( point, target ) {
  8232. if ( target === undefined ) {
  8233. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  8234. target = new Vector3();
  8235. }
  8236. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  8237. },
  8238. intersectLine: function ( line, target ) {
  8239. if ( _vector1 === undefined ) _vector1 = new Vector3();
  8240. if ( target === undefined ) {
  8241. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  8242. target = new Vector3();
  8243. }
  8244. var direction = line.delta( _vector1 );
  8245. var denominator = this.normal.dot( direction );
  8246. if ( denominator === 0 ) {
  8247. // line is coplanar, return origin
  8248. if ( this.distanceToPoint( line.start ) === 0 ) {
  8249. return target.copy( line.start );
  8250. }
  8251. // Unsure if this is the correct method to handle this case.
  8252. return undefined;
  8253. }
  8254. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  8255. if ( t < 0 || t > 1 ) {
  8256. return undefined;
  8257. }
  8258. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  8259. },
  8260. intersectsLine: function ( line ) {
  8261. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  8262. var startSign = this.distanceToPoint( line.start );
  8263. var endSign = this.distanceToPoint( line.end );
  8264. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  8265. },
  8266. intersectsBox: function ( box ) {
  8267. return box.intersectsPlane( this );
  8268. },
  8269. intersectsSphere: function ( sphere ) {
  8270. return sphere.intersectsPlane( this );
  8271. },
  8272. coplanarPoint: function ( target ) {
  8273. if ( target === undefined ) {
  8274. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  8275. target = new Vector3();
  8276. }
  8277. return target.copy( this.normal ).multiplyScalar( - this.constant );
  8278. },
  8279. applyMatrix4: function ( matrix, optionalNormalMatrix ) {
  8280. if ( _normalMatrix === undefined ) {
  8281. _normalMatrix = new Matrix3();
  8282. _vector1 = new Vector3();
  8283. }
  8284. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  8285. var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  8286. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  8287. this.constant = - referencePoint.dot( normal );
  8288. return this;
  8289. },
  8290. translate: function ( offset ) {
  8291. this.constant -= offset.dot( this.normal );
  8292. return this;
  8293. },
  8294. equals: function ( plane ) {
  8295. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  8296. }
  8297. } );
  8298. /**
  8299. * @author mrdoob / http://mrdoob.com/
  8300. * @author alteredq / http://alteredqualia.com/
  8301. * @author bhouston / http://clara.io
  8302. */
  8303. var _sphere$1;
  8304. var _vector$5;
  8305. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8306. this.planes = [
  8307. ( p0 !== undefined ) ? p0 : new Plane(),
  8308. ( p1 !== undefined ) ? p1 : new Plane(),
  8309. ( p2 !== undefined ) ? p2 : new Plane(),
  8310. ( p3 !== undefined ) ? p3 : new Plane(),
  8311. ( p4 !== undefined ) ? p4 : new Plane(),
  8312. ( p5 !== undefined ) ? p5 : new Plane()
  8313. ];
  8314. }
  8315. Object.assign( Frustum.prototype, {
  8316. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8317. var planes = this.planes;
  8318. planes[ 0 ].copy( p0 );
  8319. planes[ 1 ].copy( p1 );
  8320. planes[ 2 ].copy( p2 );
  8321. planes[ 3 ].copy( p3 );
  8322. planes[ 4 ].copy( p4 );
  8323. planes[ 5 ].copy( p5 );
  8324. return this;
  8325. },
  8326. clone: function () {
  8327. return new this.constructor().copy( this );
  8328. },
  8329. copy: function ( frustum ) {
  8330. var planes = this.planes;
  8331. for ( var i = 0; i < 6; i ++ ) {
  8332. planes[ i ].copy( frustum.planes[ i ] );
  8333. }
  8334. return this;
  8335. },
  8336. setFromMatrix: function ( m ) {
  8337. var planes = this.planes;
  8338. var me = m.elements;
  8339. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8340. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8341. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8342. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8343. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8344. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8345. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8346. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8347. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8348. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8349. return this;
  8350. },
  8351. intersectsObject: function ( object ) {
  8352. if ( _sphere$1 === undefined ) _sphere$1 = new Sphere();
  8353. var geometry = object.geometry;
  8354. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8355. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  8356. return this.intersectsSphere( _sphere$1 );
  8357. },
  8358. intersectsSprite: function ( sprite ) {
  8359. if ( _sphere$1 === undefined ) _sphere$1 = new Sphere();
  8360. _sphere$1.center.set( 0, 0, 0 );
  8361. _sphere$1.radius = 0.7071067811865476;
  8362. _sphere$1.applyMatrix4( sprite.matrixWorld );
  8363. return this.intersectsSphere( _sphere$1 );
  8364. },
  8365. intersectsSphere: function ( sphere ) {
  8366. var planes = this.planes;
  8367. var center = sphere.center;
  8368. var negRadius = - sphere.radius;
  8369. for ( var i = 0; i < 6; i ++ ) {
  8370. var distance = planes[ i ].distanceToPoint( center );
  8371. if ( distance < negRadius ) {
  8372. return false;
  8373. }
  8374. }
  8375. return true;
  8376. },
  8377. intersectsBox: function ( box ) {
  8378. if ( _vector$5 === undefined ) _vector$5 = new Vector3();
  8379. var planes = this.planes;
  8380. for ( var i = 0; i < 6; i ++ ) {
  8381. var plane = planes[ i ];
  8382. // corner at max distance
  8383. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8384. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8385. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8386. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  8387. return false;
  8388. }
  8389. }
  8390. return true;
  8391. },
  8392. containsPoint: function ( point ) {
  8393. var planes = this.planes;
  8394. for ( var i = 0; i < 6; i ++ ) {
  8395. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8396. return false;
  8397. }
  8398. }
  8399. return true;
  8400. }
  8401. } );
  8402. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8403. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8404. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8405. 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";
  8406. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8407. var begin_vertex = "vec3 transformed = vec3( position );";
  8408. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8409. 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}";
  8410. 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";
  8411. 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";
  8412. 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";
  8413. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  8414. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  8415. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8416. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8417. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8418. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8419. 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}";
  8420. 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";
  8421. 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";
  8422. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8423. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  8424. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8425. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8426. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8427. 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}";
  8428. 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";
  8429. 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";
  8430. 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";
  8431. 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";
  8432. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8433. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8434. 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";
  8435. 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";
  8436. 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";
  8437. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  8438. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8439. 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";
  8440. 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";
  8441. 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";
  8442. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8443. 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)";
  8444. 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";
  8445. 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}\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}";
  8446. 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";
  8447. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, Material_BlinnShininessExponent( material ), maxMipLevel );\n\t#ifndef STANDARD\n\t\tclearCoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearCoatNormal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );\n\t#endif\n#endif";
  8448. 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";
  8449. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  8450. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  8451. 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";
  8452. 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";
  8453. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8454. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8455. 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";
  8456. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  8457. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8458. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8459. 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";
  8460. 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";
  8461. 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";
  8462. 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;";
  8463. 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";
  8464. 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\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy *= normalScale;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvec3 NfromST = cross( S, T );\n\t\t\tif( dot( NfromST, N ) > 0.0 ) {\n\t\t\t\tS *= -1.0;\n\t\t\t\tT *= -1.0;\n\t\t\t}\n\t\t#else\n\t\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\tmat3 tsn = mat3( S, T, N );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8465. var clearcoat_normal_fragment_begin = "#ifdef USE_CLEARCOAT_NORMALMAP\n vec3 clearCoatNormal = geometryNormal;\n#endif";
  8466. 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";
  8467. var clearcoat_normalmap_pars_fragment = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearCoatNormalMap;\n\tuniform vec2 clearCoatNormalScale;\n#endif";
  8468. 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}";
  8469. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8470. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  8471. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8472. var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";
  8473. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8474. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8475. 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 ) + 0.5 ) * texelSize;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#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";
  8476. 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";
  8477. 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";
  8478. 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}";
  8479. 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";
  8480. 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";
  8481. 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";
  8482. 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";
  8483. 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";
  8484. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8485. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8486. 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}";
  8487. var uv_pars_fragment = "#ifdef USE_UV\n\tvarying vec2 vUv;\n#endif";
  8488. var uv_pars_vertex = "#ifdef USE_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif";
  8489. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8490. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8491. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  8492. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  8493. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  8494. 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}";
  8495. 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}";
  8496. 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}";
  8497. 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}";
  8498. 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}";
  8499. 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}";
  8500. 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}";
  8501. 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}";
  8502. 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}";
  8503. 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}";
  8504. 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}";
  8505. 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}";
  8506. 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}";
  8507. 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}";
  8508. 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}";
  8509. 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}";
  8510. 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}";
  8511. 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}";
  8512. 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}";
  8513. 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}";
  8514. 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}";
  8515. 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}";
  8516. 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}";
  8517. 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}";
  8518. 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}";
  8519. 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}";
  8520. 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}";
  8521. 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}";
  8522. 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}";
  8523. 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}";
  8524. var ShaderChunk = {
  8525. alphamap_fragment: alphamap_fragment,
  8526. alphamap_pars_fragment: alphamap_pars_fragment,
  8527. alphatest_fragment: alphatest_fragment,
  8528. aomap_fragment: aomap_fragment,
  8529. aomap_pars_fragment: aomap_pars_fragment,
  8530. begin_vertex: begin_vertex,
  8531. beginnormal_vertex: beginnormal_vertex,
  8532. bsdfs: bsdfs,
  8533. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8534. clipping_planes_fragment: clipping_planes_fragment,
  8535. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8536. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8537. clipping_planes_vertex: clipping_planes_vertex,
  8538. color_fragment: color_fragment,
  8539. color_pars_fragment: color_pars_fragment,
  8540. color_pars_vertex: color_pars_vertex,
  8541. color_vertex: color_vertex,
  8542. common: common,
  8543. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8544. defaultnormal_vertex: defaultnormal_vertex,
  8545. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8546. displacementmap_vertex: displacementmap_vertex,
  8547. emissivemap_fragment: emissivemap_fragment,
  8548. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8549. encodings_fragment: encodings_fragment,
  8550. encodings_pars_fragment: encodings_pars_fragment,
  8551. envmap_fragment: envmap_fragment,
  8552. envmap_pars_fragment: envmap_pars_fragment,
  8553. envmap_pars_vertex: envmap_pars_vertex,
  8554. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8555. envmap_vertex: envmap_vertex,
  8556. fog_vertex: fog_vertex,
  8557. fog_pars_vertex: fog_pars_vertex,
  8558. fog_fragment: fog_fragment,
  8559. fog_pars_fragment: fog_pars_fragment,
  8560. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8561. lightmap_fragment: lightmap_fragment,
  8562. lightmap_pars_fragment: lightmap_pars_fragment,
  8563. lights_lambert_vertex: lights_lambert_vertex,
  8564. lights_pars_begin: lights_pars_begin,
  8565. lights_phong_fragment: lights_phong_fragment,
  8566. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8567. lights_physical_fragment: lights_physical_fragment,
  8568. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8569. lights_fragment_begin: lights_fragment_begin,
  8570. lights_fragment_maps: lights_fragment_maps,
  8571. lights_fragment_end: lights_fragment_end,
  8572. logdepthbuf_fragment: logdepthbuf_fragment,
  8573. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8574. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8575. logdepthbuf_vertex: logdepthbuf_vertex,
  8576. map_fragment: map_fragment,
  8577. map_pars_fragment: map_pars_fragment,
  8578. map_particle_fragment: map_particle_fragment,
  8579. map_particle_pars_fragment: map_particle_pars_fragment,
  8580. metalnessmap_fragment: metalnessmap_fragment,
  8581. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8582. morphnormal_vertex: morphnormal_vertex,
  8583. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8584. morphtarget_vertex: morphtarget_vertex,
  8585. normal_fragment_begin: normal_fragment_begin,
  8586. normal_fragment_maps: normal_fragment_maps,
  8587. normalmap_pars_fragment: normalmap_pars_fragment,
  8588. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8589. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8590. clearcoat_normalmap_pars_fragment: clearcoat_normalmap_pars_fragment,
  8591. packing: packing,
  8592. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8593. project_vertex: project_vertex,
  8594. dithering_fragment: dithering_fragment,
  8595. dithering_pars_fragment: dithering_pars_fragment,
  8596. roughnessmap_fragment: roughnessmap_fragment,
  8597. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8598. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8599. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8600. shadowmap_vertex: shadowmap_vertex,
  8601. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8602. skinbase_vertex: skinbase_vertex,
  8603. skinning_pars_vertex: skinning_pars_vertex,
  8604. skinning_vertex: skinning_vertex,
  8605. skinnormal_vertex: skinnormal_vertex,
  8606. specularmap_fragment: specularmap_fragment,
  8607. specularmap_pars_fragment: specularmap_pars_fragment,
  8608. tonemapping_fragment: tonemapping_fragment,
  8609. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8610. uv_pars_fragment: uv_pars_fragment,
  8611. uv_pars_vertex: uv_pars_vertex,
  8612. uv_vertex: uv_vertex,
  8613. uv2_pars_fragment: uv2_pars_fragment,
  8614. uv2_pars_vertex: uv2_pars_vertex,
  8615. uv2_vertex: uv2_vertex,
  8616. worldpos_vertex: worldpos_vertex,
  8617. background_frag: background_frag,
  8618. background_vert: background_vert,
  8619. cube_frag: cube_frag,
  8620. cube_vert: cube_vert,
  8621. depth_frag: depth_frag,
  8622. depth_vert: depth_vert,
  8623. distanceRGBA_frag: distanceRGBA_frag,
  8624. distanceRGBA_vert: distanceRGBA_vert,
  8625. equirect_frag: equirect_frag,
  8626. equirect_vert: equirect_vert,
  8627. linedashed_frag: linedashed_frag,
  8628. linedashed_vert: linedashed_vert,
  8629. meshbasic_frag: meshbasic_frag,
  8630. meshbasic_vert: meshbasic_vert,
  8631. meshlambert_frag: meshlambert_frag,
  8632. meshlambert_vert: meshlambert_vert,
  8633. meshmatcap_frag: meshmatcap_frag,
  8634. meshmatcap_vert: meshmatcap_vert,
  8635. meshphong_frag: meshphong_frag,
  8636. meshphong_vert: meshphong_vert,
  8637. meshphysical_frag: meshphysical_frag,
  8638. meshphysical_vert: meshphysical_vert,
  8639. normal_frag: normal_frag,
  8640. normal_vert: normal_vert,
  8641. points_frag: points_frag,
  8642. points_vert: points_vert,
  8643. shadow_frag: shadow_frag,
  8644. shadow_vert: shadow_vert,
  8645. sprite_frag: sprite_frag,
  8646. sprite_vert: sprite_vert
  8647. };
  8648. /**
  8649. * Uniforms library for shared webgl shaders
  8650. */
  8651. var UniformsLib = {
  8652. common: {
  8653. diffuse: { value: new Color( 0xeeeeee ) },
  8654. opacity: { value: 1.0 },
  8655. map: { value: null },
  8656. uvTransform: { value: new Matrix3() },
  8657. alphaMap: { value: null },
  8658. },
  8659. specularmap: {
  8660. specularMap: { value: null },
  8661. },
  8662. envmap: {
  8663. envMap: { value: null },
  8664. flipEnvMap: { value: - 1 },
  8665. reflectivity: { value: 1.0 },
  8666. refractionRatio: { value: 0.98 },
  8667. maxMipLevel: { value: 0 }
  8668. },
  8669. aomap: {
  8670. aoMap: { value: null },
  8671. aoMapIntensity: { value: 1 }
  8672. },
  8673. lightmap: {
  8674. lightMap: { value: null },
  8675. lightMapIntensity: { value: 1 }
  8676. },
  8677. emissivemap: {
  8678. emissiveMap: { value: null }
  8679. },
  8680. bumpmap: {
  8681. bumpMap: { value: null },
  8682. bumpScale: { value: 1 }
  8683. },
  8684. normalmap: {
  8685. normalMap: { value: null },
  8686. normalScale: { value: new Vector2( 1, 1 ) }
  8687. },
  8688. displacementmap: {
  8689. displacementMap: { value: null },
  8690. displacementScale: { value: 1 },
  8691. displacementBias: { value: 0 }
  8692. },
  8693. roughnessmap: {
  8694. roughnessMap: { value: null }
  8695. },
  8696. metalnessmap: {
  8697. metalnessMap: { value: null }
  8698. },
  8699. gradientmap: {
  8700. gradientMap: { value: null }
  8701. },
  8702. fog: {
  8703. fogDensity: { value: 0.00025 },
  8704. fogNear: { value: 1 },
  8705. fogFar: { value: 2000 },
  8706. fogColor: { value: new Color( 0xffffff ) }
  8707. },
  8708. lights: {
  8709. ambientLightColor: { value: [] },
  8710. lightProbe: { value: [] },
  8711. directionalLights: { value: [], properties: {
  8712. direction: {},
  8713. color: {},
  8714. shadow: {},
  8715. shadowBias: {},
  8716. shadowRadius: {},
  8717. shadowMapSize: {}
  8718. } },
  8719. directionalShadowMap: { value: [] },
  8720. directionalShadowMatrix: { value: [] },
  8721. spotLights: { value: [], properties: {
  8722. color: {},
  8723. position: {},
  8724. direction: {},
  8725. distance: {},
  8726. coneCos: {},
  8727. penumbraCos: {},
  8728. decay: {},
  8729. shadow: {},
  8730. shadowBias: {},
  8731. shadowRadius: {},
  8732. shadowMapSize: {}
  8733. } },
  8734. spotShadowMap: { value: [] },
  8735. spotShadowMatrix: { value: [] },
  8736. pointLights: { value: [], properties: {
  8737. color: {},
  8738. position: {},
  8739. decay: {},
  8740. distance: {},
  8741. shadow: {},
  8742. shadowBias: {},
  8743. shadowRadius: {},
  8744. shadowMapSize: {},
  8745. shadowCameraNear: {},
  8746. shadowCameraFar: {}
  8747. } },
  8748. pointShadowMap: { value: [] },
  8749. pointShadowMatrix: { value: [] },
  8750. hemisphereLights: { value: [], properties: {
  8751. direction: {},
  8752. skyColor: {},
  8753. groundColor: {}
  8754. } },
  8755. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8756. rectAreaLights: { value: [], properties: {
  8757. color: {},
  8758. position: {},
  8759. width: {},
  8760. height: {}
  8761. } }
  8762. },
  8763. points: {
  8764. diffuse: { value: new Color( 0xeeeeee ) },
  8765. opacity: { value: 1.0 },
  8766. size: { value: 1.0 },
  8767. scale: { value: 1.0 },
  8768. map: { value: null },
  8769. uvTransform: { value: new Matrix3() }
  8770. },
  8771. sprite: {
  8772. diffuse: { value: new Color( 0xeeeeee ) },
  8773. opacity: { value: 1.0 },
  8774. center: { value: new Vector2( 0.5, 0.5 ) },
  8775. rotation: { value: 0.0 },
  8776. map: { value: null },
  8777. uvTransform: { value: new Matrix3() }
  8778. }
  8779. };
  8780. /**
  8781. * @author alteredq / http://alteredqualia.com/
  8782. * @author mrdoob / http://mrdoob.com/
  8783. * @author mikael emtinger / http://gomo.se/
  8784. */
  8785. var ShaderLib = {
  8786. basic: {
  8787. uniforms: mergeUniforms( [
  8788. UniformsLib.common,
  8789. UniformsLib.specularmap,
  8790. UniformsLib.envmap,
  8791. UniformsLib.aomap,
  8792. UniformsLib.lightmap,
  8793. UniformsLib.fog
  8794. ] ),
  8795. vertexShader: ShaderChunk.meshbasic_vert,
  8796. fragmentShader: ShaderChunk.meshbasic_frag
  8797. },
  8798. lambert: {
  8799. uniforms: mergeUniforms( [
  8800. UniformsLib.common,
  8801. UniformsLib.specularmap,
  8802. UniformsLib.envmap,
  8803. UniformsLib.aomap,
  8804. UniformsLib.lightmap,
  8805. UniformsLib.emissivemap,
  8806. UniformsLib.fog,
  8807. UniformsLib.lights,
  8808. {
  8809. emissive: { value: new Color( 0x000000 ) }
  8810. }
  8811. ] ),
  8812. vertexShader: ShaderChunk.meshlambert_vert,
  8813. fragmentShader: ShaderChunk.meshlambert_frag
  8814. },
  8815. phong: {
  8816. uniforms: mergeUniforms( [
  8817. UniformsLib.common,
  8818. UniformsLib.specularmap,
  8819. UniformsLib.envmap,
  8820. UniformsLib.aomap,
  8821. UniformsLib.lightmap,
  8822. UniformsLib.emissivemap,
  8823. UniformsLib.bumpmap,
  8824. UniformsLib.normalmap,
  8825. UniformsLib.displacementmap,
  8826. UniformsLib.gradientmap,
  8827. UniformsLib.fog,
  8828. UniformsLib.lights,
  8829. {
  8830. emissive: { value: new Color( 0x000000 ) },
  8831. specular: { value: new Color( 0x111111 ) },
  8832. shininess: { value: 30 }
  8833. }
  8834. ] ),
  8835. vertexShader: ShaderChunk.meshphong_vert,
  8836. fragmentShader: ShaderChunk.meshphong_frag
  8837. },
  8838. standard: {
  8839. uniforms: mergeUniforms( [
  8840. UniformsLib.common,
  8841. UniformsLib.envmap,
  8842. UniformsLib.aomap,
  8843. UniformsLib.lightmap,
  8844. UniformsLib.emissivemap,
  8845. UniformsLib.bumpmap,
  8846. UniformsLib.normalmap,
  8847. UniformsLib.displacementmap,
  8848. UniformsLib.roughnessmap,
  8849. UniformsLib.metalnessmap,
  8850. UniformsLib.fog,
  8851. UniformsLib.lights,
  8852. {
  8853. emissive: { value: new Color( 0x000000 ) },
  8854. roughness: { value: 0.5 },
  8855. metalness: { value: 0.5 },
  8856. envMapIntensity: { value: 1 } // temporary
  8857. }
  8858. ] ),
  8859. vertexShader: ShaderChunk.meshphysical_vert,
  8860. fragmentShader: ShaderChunk.meshphysical_frag
  8861. },
  8862. matcap: {
  8863. uniforms: mergeUniforms( [
  8864. UniformsLib.common,
  8865. UniformsLib.bumpmap,
  8866. UniformsLib.normalmap,
  8867. UniformsLib.displacementmap,
  8868. UniformsLib.fog,
  8869. {
  8870. matcap: { value: null }
  8871. }
  8872. ] ),
  8873. vertexShader: ShaderChunk.meshmatcap_vert,
  8874. fragmentShader: ShaderChunk.meshmatcap_frag
  8875. },
  8876. points: {
  8877. uniforms: mergeUniforms( [
  8878. UniformsLib.points,
  8879. UniformsLib.fog
  8880. ] ),
  8881. vertexShader: ShaderChunk.points_vert,
  8882. fragmentShader: ShaderChunk.points_frag
  8883. },
  8884. dashed: {
  8885. uniforms: mergeUniforms( [
  8886. UniformsLib.common,
  8887. UniformsLib.fog,
  8888. {
  8889. scale: { value: 1 },
  8890. dashSize: { value: 1 },
  8891. totalSize: { value: 2 }
  8892. }
  8893. ] ),
  8894. vertexShader: ShaderChunk.linedashed_vert,
  8895. fragmentShader: ShaderChunk.linedashed_frag
  8896. },
  8897. depth: {
  8898. uniforms: mergeUniforms( [
  8899. UniformsLib.common,
  8900. UniformsLib.displacementmap
  8901. ] ),
  8902. vertexShader: ShaderChunk.depth_vert,
  8903. fragmentShader: ShaderChunk.depth_frag
  8904. },
  8905. normal: {
  8906. uniforms: mergeUniforms( [
  8907. UniformsLib.common,
  8908. UniformsLib.bumpmap,
  8909. UniformsLib.normalmap,
  8910. UniformsLib.displacementmap,
  8911. {
  8912. opacity: { value: 1.0 }
  8913. }
  8914. ] ),
  8915. vertexShader: ShaderChunk.normal_vert,
  8916. fragmentShader: ShaderChunk.normal_frag
  8917. },
  8918. sprite: {
  8919. uniforms: mergeUniforms( [
  8920. UniformsLib.sprite,
  8921. UniformsLib.fog
  8922. ] ),
  8923. vertexShader: ShaderChunk.sprite_vert,
  8924. fragmentShader: ShaderChunk.sprite_frag
  8925. },
  8926. background: {
  8927. uniforms: {
  8928. uvTransform: { value: new Matrix3() },
  8929. t2D: { value: null },
  8930. },
  8931. vertexShader: ShaderChunk.background_vert,
  8932. fragmentShader: ShaderChunk.background_frag
  8933. },
  8934. /* -------------------------------------------------------------------------
  8935. // Cube map shader
  8936. ------------------------------------------------------------------------- */
  8937. cube: {
  8938. uniforms: {
  8939. tCube: { value: null },
  8940. tFlip: { value: - 1 },
  8941. opacity: { value: 1.0 }
  8942. },
  8943. vertexShader: ShaderChunk.cube_vert,
  8944. fragmentShader: ShaderChunk.cube_frag
  8945. },
  8946. equirect: {
  8947. uniforms: {
  8948. tEquirect: { value: null },
  8949. },
  8950. vertexShader: ShaderChunk.equirect_vert,
  8951. fragmentShader: ShaderChunk.equirect_frag
  8952. },
  8953. distanceRGBA: {
  8954. uniforms: mergeUniforms( [
  8955. UniformsLib.common,
  8956. UniformsLib.displacementmap,
  8957. {
  8958. referencePosition: { value: new Vector3() },
  8959. nearDistance: { value: 1 },
  8960. farDistance: { value: 1000 }
  8961. }
  8962. ] ),
  8963. vertexShader: ShaderChunk.distanceRGBA_vert,
  8964. fragmentShader: ShaderChunk.distanceRGBA_frag
  8965. },
  8966. shadow: {
  8967. uniforms: mergeUniforms( [
  8968. UniformsLib.lights,
  8969. UniformsLib.fog,
  8970. {
  8971. color: { value: new Color( 0x00000 ) },
  8972. opacity: { value: 1.0 }
  8973. },
  8974. ] ),
  8975. vertexShader: ShaderChunk.shadow_vert,
  8976. fragmentShader: ShaderChunk.shadow_frag
  8977. }
  8978. };
  8979. ShaderLib.physical = {
  8980. uniforms: mergeUniforms( [
  8981. ShaderLib.standard.uniforms,
  8982. {
  8983. clearCoat: { value: 0 },
  8984. clearCoatRoughness: { value: 0 },
  8985. clearCoatNormalScale: { value: new Vector2( 1, 1 ) },
  8986. clearCoatNormalMap: { value: null },
  8987. }
  8988. ] ),
  8989. vertexShader: ShaderChunk.meshphysical_vert,
  8990. fragmentShader: ShaderChunk.meshphysical_frag
  8991. };
  8992. /**
  8993. * @author mrdoob / http://mrdoob.com/
  8994. */
  8995. function WebGLAnimation() {
  8996. var context = null;
  8997. var isAnimating = false;
  8998. var animationLoop = null;
  8999. function onAnimationFrame( time, frame ) {
  9000. if ( isAnimating === false ) return;
  9001. animationLoop( time, frame );
  9002. context.requestAnimationFrame( onAnimationFrame );
  9003. }
  9004. return {
  9005. start: function () {
  9006. if ( isAnimating === true ) return;
  9007. if ( animationLoop === null ) return;
  9008. context.requestAnimationFrame( onAnimationFrame );
  9009. isAnimating = true;
  9010. },
  9011. stop: function () {
  9012. isAnimating = false;
  9013. },
  9014. setAnimationLoop: function ( callback ) {
  9015. animationLoop = callback;
  9016. },
  9017. setContext: function ( value ) {
  9018. context = value;
  9019. }
  9020. };
  9021. }
  9022. /**
  9023. * @author mrdoob / http://mrdoob.com/
  9024. */
  9025. function WebGLAttributes( gl ) {
  9026. var buffers = new WeakMap();
  9027. function createBuffer( attribute, bufferType ) {
  9028. var array = attribute.array;
  9029. var usage = attribute.dynamic ? 35048 : 35044;
  9030. var buffer = gl.createBuffer();
  9031. gl.bindBuffer( bufferType, buffer );
  9032. gl.bufferData( bufferType, array, usage );
  9033. attribute.onUploadCallback();
  9034. var type = 5126;
  9035. if ( array instanceof Float32Array ) {
  9036. type = 5126;
  9037. } else if ( array instanceof Float64Array ) {
  9038. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  9039. } else if ( array instanceof Uint16Array ) {
  9040. type = 5123;
  9041. } else if ( array instanceof Int16Array ) {
  9042. type = 5122;
  9043. } else if ( array instanceof Uint32Array ) {
  9044. type = 5125;
  9045. } else if ( array instanceof Int32Array ) {
  9046. type = 5124;
  9047. } else if ( array instanceof Int8Array ) {
  9048. type = 5120;
  9049. } else if ( array instanceof Uint8Array ) {
  9050. type = 5121;
  9051. }
  9052. return {
  9053. buffer: buffer,
  9054. type: type,
  9055. bytesPerElement: array.BYTES_PER_ELEMENT,
  9056. version: attribute.version
  9057. };
  9058. }
  9059. function updateBuffer( buffer, attribute, bufferType ) {
  9060. var array = attribute.array;
  9061. var updateRange = attribute.updateRange;
  9062. gl.bindBuffer( bufferType, buffer );
  9063. if ( attribute.dynamic === false ) {
  9064. gl.bufferData( bufferType, array, 35044 );
  9065. } else if ( updateRange.count === - 1 ) {
  9066. // Not using update ranges
  9067. gl.bufferSubData( bufferType, 0, array );
  9068. } else if ( updateRange.count === 0 ) {
  9069. 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.' );
  9070. } else {
  9071. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9072. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9073. updateRange.count = - 1; // reset range
  9074. }
  9075. }
  9076. //
  9077. function get( attribute ) {
  9078. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9079. return buffers.get( attribute );
  9080. }
  9081. function remove( attribute ) {
  9082. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9083. var data = buffers.get( attribute );
  9084. if ( data ) {
  9085. gl.deleteBuffer( data.buffer );
  9086. buffers.delete( attribute );
  9087. }
  9088. }
  9089. function update( attribute, bufferType ) {
  9090. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9091. var data = buffers.get( attribute );
  9092. if ( data === undefined ) {
  9093. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  9094. } else if ( data.version < attribute.version ) {
  9095. updateBuffer( data.buffer, attribute, bufferType );
  9096. data.version = attribute.version;
  9097. }
  9098. }
  9099. return {
  9100. get: get,
  9101. remove: remove,
  9102. update: update
  9103. };
  9104. }
  9105. /**
  9106. * @author mrdoob / http://mrdoob.com/
  9107. * @author Mugen87 / https://github.com/Mugen87
  9108. */
  9109. // PlaneGeometry
  9110. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  9111. Geometry.call( this );
  9112. this.type = 'PlaneGeometry';
  9113. this.parameters = {
  9114. width: width,
  9115. height: height,
  9116. widthSegments: widthSegments,
  9117. heightSegments: heightSegments
  9118. };
  9119. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  9120. this.mergeVertices();
  9121. }
  9122. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  9123. PlaneGeometry.prototype.constructor = PlaneGeometry;
  9124. // PlaneBufferGeometry
  9125. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  9126. BufferGeometry.call( this );
  9127. this.type = 'PlaneBufferGeometry';
  9128. this.parameters = {
  9129. width: width,
  9130. height: height,
  9131. widthSegments: widthSegments,
  9132. heightSegments: heightSegments
  9133. };
  9134. width = width || 1;
  9135. height = height || 1;
  9136. var width_half = width / 2;
  9137. var height_half = height / 2;
  9138. var gridX = Math.floor( widthSegments ) || 1;
  9139. var gridY = Math.floor( heightSegments ) || 1;
  9140. var gridX1 = gridX + 1;
  9141. var gridY1 = gridY + 1;
  9142. var segment_width = width / gridX;
  9143. var segment_height = height / gridY;
  9144. var ix, iy;
  9145. // buffers
  9146. var indices = [];
  9147. var vertices = [];
  9148. var normals = [];
  9149. var uvs = [];
  9150. // generate vertices, normals and uvs
  9151. for ( iy = 0; iy < gridY1; iy ++ ) {
  9152. var y = iy * segment_height - height_half;
  9153. for ( ix = 0; ix < gridX1; ix ++ ) {
  9154. var x = ix * segment_width - width_half;
  9155. vertices.push( x, - y, 0 );
  9156. normals.push( 0, 0, 1 );
  9157. uvs.push( ix / gridX );
  9158. uvs.push( 1 - ( iy / gridY ) );
  9159. }
  9160. }
  9161. // indices
  9162. for ( iy = 0; iy < gridY; iy ++ ) {
  9163. for ( ix = 0; ix < gridX; ix ++ ) {
  9164. var a = ix + gridX1 * iy;
  9165. var b = ix + gridX1 * ( iy + 1 );
  9166. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  9167. var d = ( ix + 1 ) + gridX1 * iy;
  9168. // faces
  9169. indices.push( a, b, d );
  9170. indices.push( b, c, d );
  9171. }
  9172. }
  9173. // build geometry
  9174. this.setIndex( indices );
  9175. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9176. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9177. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9178. }
  9179. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9180. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  9181. /**
  9182. * @author mrdoob / http://mrdoob.com/
  9183. */
  9184. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9185. var clearColor = new Color( 0x000000 );
  9186. var clearAlpha = 0;
  9187. var planeMesh;
  9188. var boxMesh;
  9189. // Store the current background texture and its `version`
  9190. // so we can recompile the material accordingly.
  9191. var currentBackground = null;
  9192. var currentBackgroundVersion = 0;
  9193. function render( renderList, scene, camera, forceClear ) {
  9194. var background = scene.background;
  9195. // Ignore background in AR
  9196. // TODO: Reconsider this.
  9197. var vr = renderer.vr;
  9198. var session = vr.getSession && vr.getSession();
  9199. if ( session && session.environmentBlendMode === 'additive' ) {
  9200. background = null;
  9201. }
  9202. if ( background === null ) {
  9203. setClear( clearColor, clearAlpha );
  9204. currentBackground = null;
  9205. currentBackgroundVersion = 0;
  9206. } else if ( background && background.isColor ) {
  9207. setClear( background, 1 );
  9208. forceClear = true;
  9209. currentBackground = null;
  9210. currentBackgroundVersion = 0;
  9211. }
  9212. if ( renderer.autoClear || forceClear ) {
  9213. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9214. }
  9215. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  9216. if ( boxMesh === undefined ) {
  9217. boxMesh = new Mesh(
  9218. new BoxBufferGeometry( 1, 1, 1 ),
  9219. new ShaderMaterial( {
  9220. type: 'BackgroundCubeMaterial',
  9221. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9222. vertexShader: ShaderLib.cube.vertexShader,
  9223. fragmentShader: ShaderLib.cube.fragmentShader,
  9224. side: BackSide,
  9225. depthTest: false,
  9226. depthWrite: false,
  9227. fog: false
  9228. } )
  9229. );
  9230. boxMesh.geometry.removeAttribute( 'normal' );
  9231. boxMesh.geometry.removeAttribute( 'uv' );
  9232. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9233. this.matrixWorld.copyPosition( camera.matrixWorld );
  9234. };
  9235. // enable code injection for non-built-in material
  9236. Object.defineProperty( boxMesh.material, 'map', {
  9237. get: function () {
  9238. return this.uniforms.tCube.value;
  9239. }
  9240. } );
  9241. objects.update( boxMesh );
  9242. }
  9243. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  9244. boxMesh.material.uniforms.tCube.value = texture;
  9245. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  9246. if ( currentBackground !== background ||
  9247. currentBackgroundVersion !== texture.version ) {
  9248. boxMesh.material.needsUpdate = true;
  9249. currentBackground = background;
  9250. currentBackgroundVersion = texture.version;
  9251. }
  9252. // push to the pre-sorted opaque render list
  9253. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9254. } else if ( background && background.isTexture ) {
  9255. if ( planeMesh === undefined ) {
  9256. planeMesh = new Mesh(
  9257. new PlaneBufferGeometry( 2, 2 ),
  9258. new ShaderMaterial( {
  9259. type: 'BackgroundMaterial',
  9260. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9261. vertexShader: ShaderLib.background.vertexShader,
  9262. fragmentShader: ShaderLib.background.fragmentShader,
  9263. side: FrontSide,
  9264. depthTest: false,
  9265. depthWrite: false,
  9266. fog: false
  9267. } )
  9268. );
  9269. planeMesh.geometry.removeAttribute( 'normal' );
  9270. // enable code injection for non-built-in material
  9271. Object.defineProperty( planeMesh.material, 'map', {
  9272. get: function () {
  9273. return this.uniforms.t2D.value;
  9274. }
  9275. } );
  9276. objects.update( planeMesh );
  9277. }
  9278. planeMesh.material.uniforms.t2D.value = background;
  9279. if ( background.matrixAutoUpdate === true ) {
  9280. background.updateMatrix();
  9281. }
  9282. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9283. if ( currentBackground !== background ||
  9284. currentBackgroundVersion !== background.version ) {
  9285. planeMesh.material.needsUpdate = true;
  9286. currentBackground = background;
  9287. currentBackgroundVersion = background.version;
  9288. }
  9289. // push to the pre-sorted opaque render list
  9290. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9291. }
  9292. }
  9293. function setClear( color, alpha ) {
  9294. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9295. }
  9296. return {
  9297. getClearColor: function () {
  9298. return clearColor;
  9299. },
  9300. setClearColor: function ( color, alpha ) {
  9301. clearColor.set( color );
  9302. clearAlpha = alpha !== undefined ? alpha : 1;
  9303. setClear( clearColor, clearAlpha );
  9304. },
  9305. getClearAlpha: function () {
  9306. return clearAlpha;
  9307. },
  9308. setClearAlpha: function ( alpha ) {
  9309. clearAlpha = alpha;
  9310. setClear( clearColor, clearAlpha );
  9311. },
  9312. render: render
  9313. };
  9314. }
  9315. /**
  9316. * @author mrdoob / http://mrdoob.com/
  9317. */
  9318. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9319. var mode;
  9320. function setMode( value ) {
  9321. mode = value;
  9322. }
  9323. function render( start, count ) {
  9324. gl.drawArrays( mode, start, count );
  9325. info.update( count, mode );
  9326. }
  9327. function renderInstances( geometry, start, count ) {
  9328. var extension;
  9329. if ( capabilities.isWebGL2 ) {
  9330. extension = gl;
  9331. } else {
  9332. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9333. if ( extension === null ) {
  9334. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9335. return;
  9336. }
  9337. }
  9338. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  9339. info.update( count, mode, geometry.maxInstancedCount );
  9340. }
  9341. //
  9342. this.setMode = setMode;
  9343. this.render = render;
  9344. this.renderInstances = renderInstances;
  9345. }
  9346. /**
  9347. * @author mrdoob / http://mrdoob.com/
  9348. */
  9349. function WebGLCapabilities( gl, extensions, parameters ) {
  9350. var maxAnisotropy;
  9351. function getMaxAnisotropy() {
  9352. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  9353. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9354. if ( extension !== null ) {
  9355. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9356. } else {
  9357. maxAnisotropy = 0;
  9358. }
  9359. return maxAnisotropy;
  9360. }
  9361. function getMaxPrecision( precision ) {
  9362. if ( precision === 'highp' ) {
  9363. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9364. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9365. return 'highp';
  9366. }
  9367. precision = 'mediump';
  9368. }
  9369. if ( precision === 'mediump' ) {
  9370. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9371. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9372. return 'mediump';
  9373. }
  9374. }
  9375. return 'lowp';
  9376. }
  9377. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  9378. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9379. var maxPrecision = getMaxPrecision( precision );
  9380. if ( maxPrecision !== precision ) {
  9381. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9382. precision = maxPrecision;
  9383. }
  9384. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9385. var maxTextures = gl.getParameter( 34930 );
  9386. var maxVertexTextures = gl.getParameter( 35660 );
  9387. var maxTextureSize = gl.getParameter( 3379 );
  9388. var maxCubemapSize = gl.getParameter( 34076 );
  9389. var maxAttributes = gl.getParameter( 34921 );
  9390. var maxVertexUniforms = gl.getParameter( 36347 );
  9391. var maxVaryings = gl.getParameter( 36348 );
  9392. var maxFragmentUniforms = gl.getParameter( 36349 );
  9393. var vertexTextures = maxVertexTextures > 0;
  9394. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9395. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9396. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9397. return {
  9398. isWebGL2: isWebGL2,
  9399. getMaxAnisotropy: getMaxAnisotropy,
  9400. getMaxPrecision: getMaxPrecision,
  9401. precision: precision,
  9402. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9403. maxTextures: maxTextures,
  9404. maxVertexTextures: maxVertexTextures,
  9405. maxTextureSize: maxTextureSize,
  9406. maxCubemapSize: maxCubemapSize,
  9407. maxAttributes: maxAttributes,
  9408. maxVertexUniforms: maxVertexUniforms,
  9409. maxVaryings: maxVaryings,
  9410. maxFragmentUniforms: maxFragmentUniforms,
  9411. vertexTextures: vertexTextures,
  9412. floatFragmentTextures: floatFragmentTextures,
  9413. floatVertexTextures: floatVertexTextures,
  9414. maxSamples: maxSamples
  9415. };
  9416. }
  9417. /**
  9418. * @author tschw
  9419. */
  9420. function WebGLClipping() {
  9421. var scope = this,
  9422. globalState = null,
  9423. numGlobalPlanes = 0,
  9424. localClippingEnabled = false,
  9425. renderingShadows = false,
  9426. plane = new Plane(),
  9427. viewNormalMatrix = new Matrix3(),
  9428. uniform = { value: null, needsUpdate: false };
  9429. this.uniform = uniform;
  9430. this.numPlanes = 0;
  9431. this.numIntersection = 0;
  9432. this.init = function ( planes, enableLocalClipping, camera ) {
  9433. var enabled =
  9434. planes.length !== 0 ||
  9435. enableLocalClipping ||
  9436. // enable state of previous frame - the clipping code has to
  9437. // run another frame in order to reset the state:
  9438. numGlobalPlanes !== 0 ||
  9439. localClippingEnabled;
  9440. localClippingEnabled = enableLocalClipping;
  9441. globalState = projectPlanes( planes, camera, 0 );
  9442. numGlobalPlanes = planes.length;
  9443. return enabled;
  9444. };
  9445. this.beginShadows = function () {
  9446. renderingShadows = true;
  9447. projectPlanes( null );
  9448. };
  9449. this.endShadows = function () {
  9450. renderingShadows = false;
  9451. resetGlobalState();
  9452. };
  9453. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9454. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9455. // there's no local clipping
  9456. if ( renderingShadows ) {
  9457. // there's no global clipping
  9458. projectPlanes( null );
  9459. } else {
  9460. resetGlobalState();
  9461. }
  9462. } else {
  9463. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9464. lGlobal = nGlobal * 4,
  9465. dstArray = cache.clippingState || null;
  9466. uniform.value = dstArray; // ensure unique state
  9467. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9468. for ( var i = 0; i !== lGlobal; ++ i ) {
  9469. dstArray[ i ] = globalState[ i ];
  9470. }
  9471. cache.clippingState = dstArray;
  9472. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9473. this.numPlanes += nGlobal;
  9474. }
  9475. };
  9476. function resetGlobalState() {
  9477. if ( uniform.value !== globalState ) {
  9478. uniform.value = globalState;
  9479. uniform.needsUpdate = numGlobalPlanes > 0;
  9480. }
  9481. scope.numPlanes = numGlobalPlanes;
  9482. scope.numIntersection = 0;
  9483. }
  9484. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9485. var nPlanes = planes !== null ? planes.length : 0,
  9486. dstArray = null;
  9487. if ( nPlanes !== 0 ) {
  9488. dstArray = uniform.value;
  9489. if ( skipTransform !== true || dstArray === null ) {
  9490. var flatSize = dstOffset + nPlanes * 4,
  9491. viewMatrix = camera.matrixWorldInverse;
  9492. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9493. if ( dstArray === null || dstArray.length < flatSize ) {
  9494. dstArray = new Float32Array( flatSize );
  9495. }
  9496. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9497. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9498. plane.normal.toArray( dstArray, i4 );
  9499. dstArray[ i4 + 3 ] = plane.constant;
  9500. }
  9501. }
  9502. uniform.value = dstArray;
  9503. uniform.needsUpdate = true;
  9504. }
  9505. scope.numPlanes = nPlanes;
  9506. return dstArray;
  9507. }
  9508. }
  9509. /**
  9510. * @author mrdoob / http://mrdoob.com/
  9511. */
  9512. function WebGLExtensions( gl ) {
  9513. var extensions = {};
  9514. return {
  9515. get: function ( name ) {
  9516. if ( extensions[ name ] !== undefined ) {
  9517. return extensions[ name ];
  9518. }
  9519. var extension;
  9520. switch ( name ) {
  9521. case 'WEBGL_depth_texture':
  9522. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9523. break;
  9524. case 'EXT_texture_filter_anisotropic':
  9525. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9526. break;
  9527. case 'WEBGL_compressed_texture_s3tc':
  9528. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9529. break;
  9530. case 'WEBGL_compressed_texture_pvrtc':
  9531. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9532. break;
  9533. default:
  9534. extension = gl.getExtension( name );
  9535. }
  9536. if ( extension === null ) {
  9537. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9538. }
  9539. extensions[ name ] = extension;
  9540. return extension;
  9541. }
  9542. };
  9543. }
  9544. /**
  9545. * @author mrdoob / http://mrdoob.com/
  9546. */
  9547. function WebGLGeometries( gl, attributes, info ) {
  9548. var geometries = {};
  9549. var wireframeAttributes = {};
  9550. function onGeometryDispose( event ) {
  9551. var geometry = event.target;
  9552. var buffergeometry = geometries[ geometry.id ];
  9553. if ( buffergeometry.index !== null ) {
  9554. attributes.remove( buffergeometry.index );
  9555. }
  9556. for ( var name in buffergeometry.attributes ) {
  9557. attributes.remove( buffergeometry.attributes[ name ] );
  9558. }
  9559. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9560. delete geometries[ geometry.id ];
  9561. var attribute = wireframeAttributes[ buffergeometry.id ];
  9562. if ( attribute ) {
  9563. attributes.remove( attribute );
  9564. delete wireframeAttributes[ buffergeometry.id ];
  9565. }
  9566. //
  9567. info.memory.geometries --;
  9568. }
  9569. function get( object, geometry ) {
  9570. var buffergeometry = geometries[ geometry.id ];
  9571. if ( buffergeometry ) return buffergeometry;
  9572. geometry.addEventListener( 'dispose', onGeometryDispose );
  9573. if ( geometry.isBufferGeometry ) {
  9574. buffergeometry = geometry;
  9575. } else if ( geometry.isGeometry ) {
  9576. if ( geometry._bufferGeometry === undefined ) {
  9577. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9578. }
  9579. buffergeometry = geometry._bufferGeometry;
  9580. }
  9581. geometries[ geometry.id ] = buffergeometry;
  9582. info.memory.geometries ++;
  9583. return buffergeometry;
  9584. }
  9585. function update( geometry ) {
  9586. var index = geometry.index;
  9587. var geometryAttributes = geometry.attributes;
  9588. if ( index !== null ) {
  9589. attributes.update( index, 34963 );
  9590. }
  9591. for ( var name in geometryAttributes ) {
  9592. attributes.update( geometryAttributes[ name ], 34962 );
  9593. }
  9594. // morph targets
  9595. var morphAttributes = geometry.morphAttributes;
  9596. for ( var name in morphAttributes ) {
  9597. var array = morphAttributes[ name ];
  9598. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9599. attributes.update( array[ i ], 34962 );
  9600. }
  9601. }
  9602. }
  9603. function updateWireframeAttribute( geometry ) {
  9604. var indices = [];
  9605. var geometryIndex = geometry.index;
  9606. var geometryPosition = geometry.attributes.position;
  9607. var version = 0;
  9608. if ( geometryIndex !== null ) {
  9609. var array = geometryIndex.array;
  9610. version = geometryIndex.version;
  9611. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9612. var a = array[ i + 0 ];
  9613. var b = array[ i + 1 ];
  9614. var c = array[ i + 2 ];
  9615. indices.push( a, b, b, c, c, a );
  9616. }
  9617. } else {
  9618. var array = geometryPosition.array;
  9619. version = geometryPosition.version;
  9620. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9621. var a = i + 0;
  9622. var b = i + 1;
  9623. var c = i + 2;
  9624. indices.push( a, b, b, c, c, a );
  9625. }
  9626. }
  9627. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9628. attribute.version = version;
  9629. attributes.update( attribute, 34963 );
  9630. //
  9631. var previousAttribute = wireframeAttributes[ geometry.id ];
  9632. if ( previousAttribute ) attributes.remove( previousAttribute );
  9633. //
  9634. wireframeAttributes[ geometry.id ] = attribute;
  9635. }
  9636. function getWireframeAttribute( geometry ) {
  9637. var currentAttribute = wireframeAttributes[ geometry.id ];
  9638. if ( currentAttribute ) {
  9639. var geometryIndex = geometry.index;
  9640. if ( geometryIndex !== null ) {
  9641. // if the attribute is obsolete, create a new one
  9642. if ( currentAttribute.version < geometryIndex.version ) {
  9643. updateWireframeAttribute( geometry );
  9644. }
  9645. }
  9646. } else {
  9647. updateWireframeAttribute( geometry );
  9648. }
  9649. return wireframeAttributes[ geometry.id ];
  9650. }
  9651. return {
  9652. get: get,
  9653. update: update,
  9654. getWireframeAttribute: getWireframeAttribute
  9655. };
  9656. }
  9657. /**
  9658. * @author mrdoob / http://mrdoob.com/
  9659. */
  9660. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9661. var mode;
  9662. function setMode( value ) {
  9663. mode = value;
  9664. }
  9665. var type, bytesPerElement;
  9666. function setIndex( value ) {
  9667. type = value.type;
  9668. bytesPerElement = value.bytesPerElement;
  9669. }
  9670. function render( start, count ) {
  9671. gl.drawElements( mode, count, type, start * bytesPerElement );
  9672. info.update( count, mode );
  9673. }
  9674. function renderInstances( geometry, start, count ) {
  9675. var extension;
  9676. if ( capabilities.isWebGL2 ) {
  9677. extension = gl;
  9678. } else {
  9679. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9680. if ( extension === null ) {
  9681. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9682. return;
  9683. }
  9684. }
  9685. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9686. info.update( count, mode, geometry.maxInstancedCount );
  9687. }
  9688. //
  9689. this.setMode = setMode;
  9690. this.setIndex = setIndex;
  9691. this.render = render;
  9692. this.renderInstances = renderInstances;
  9693. }
  9694. /**
  9695. * @author Mugen87 / https://github.com/Mugen87
  9696. */
  9697. function WebGLInfo( gl ) {
  9698. var memory = {
  9699. geometries: 0,
  9700. textures: 0
  9701. };
  9702. var render = {
  9703. frame: 0,
  9704. calls: 0,
  9705. triangles: 0,
  9706. points: 0,
  9707. lines: 0
  9708. };
  9709. function update( count, mode, instanceCount ) {
  9710. instanceCount = instanceCount || 1;
  9711. render.calls ++;
  9712. switch ( mode ) {
  9713. case 4:
  9714. render.triangles += instanceCount * ( count / 3 );
  9715. break;
  9716. case 5:
  9717. case 6:
  9718. render.triangles += instanceCount * ( count - 2 );
  9719. break;
  9720. case 1:
  9721. render.lines += instanceCount * ( count / 2 );
  9722. break;
  9723. case 3:
  9724. render.lines += instanceCount * ( count - 1 );
  9725. break;
  9726. case 2:
  9727. render.lines += instanceCount * count;
  9728. break;
  9729. case 0:
  9730. render.points += instanceCount * count;
  9731. break;
  9732. default:
  9733. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9734. break;
  9735. }
  9736. }
  9737. function reset() {
  9738. render.frame ++;
  9739. render.calls = 0;
  9740. render.triangles = 0;
  9741. render.points = 0;
  9742. render.lines = 0;
  9743. }
  9744. return {
  9745. memory: memory,
  9746. render: render,
  9747. programs: null,
  9748. autoReset: true,
  9749. reset: reset,
  9750. update: update
  9751. };
  9752. }
  9753. /**
  9754. * @author mrdoob / http://mrdoob.com/
  9755. */
  9756. function absNumericalSort( a, b ) {
  9757. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9758. }
  9759. function WebGLMorphtargets( gl ) {
  9760. var influencesList = {};
  9761. var morphInfluences = new Float32Array( 8 );
  9762. function update( object, geometry, material, program ) {
  9763. var objectInfluences = object.morphTargetInfluences;
  9764. var length = objectInfluences.length;
  9765. var influences = influencesList[ geometry.id ];
  9766. if ( influences === undefined ) {
  9767. // initialise list
  9768. influences = [];
  9769. for ( var i = 0; i < length; i ++ ) {
  9770. influences[ i ] = [ i, 0 ];
  9771. }
  9772. influencesList[ geometry.id ] = influences;
  9773. }
  9774. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9775. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9776. // Remove current morphAttributes
  9777. for ( var i = 0; i < length; i ++ ) {
  9778. var influence = influences[ i ];
  9779. if ( influence[ 1 ] !== 0 ) {
  9780. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9781. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9782. }
  9783. }
  9784. // Collect influences
  9785. for ( var i = 0; i < length; i ++ ) {
  9786. var influence = influences[ i ];
  9787. influence[ 0 ] = i;
  9788. influence[ 1 ] = objectInfluences[ i ];
  9789. }
  9790. influences.sort( absNumericalSort );
  9791. // Add morphAttributes
  9792. for ( var i = 0; i < 8; i ++ ) {
  9793. var influence = influences[ i ];
  9794. if ( influence ) {
  9795. var index = influence[ 0 ];
  9796. var value = influence[ 1 ];
  9797. if ( value ) {
  9798. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9799. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9800. morphInfluences[ i ] = value;
  9801. continue;
  9802. }
  9803. }
  9804. morphInfluences[ i ] = 0;
  9805. }
  9806. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9807. }
  9808. return {
  9809. update: update
  9810. };
  9811. }
  9812. /**
  9813. * @author mrdoob / http://mrdoob.com/
  9814. */
  9815. function WebGLObjects( geometries, info ) {
  9816. var updateList = {};
  9817. function update( object ) {
  9818. var frame = info.render.frame;
  9819. var geometry = object.geometry;
  9820. var buffergeometry = geometries.get( object, geometry );
  9821. // Update once per frame
  9822. if ( updateList[ buffergeometry.id ] !== frame ) {
  9823. if ( geometry.isGeometry ) {
  9824. buffergeometry.updateFromObject( object );
  9825. }
  9826. geometries.update( buffergeometry );
  9827. updateList[ buffergeometry.id ] = frame;
  9828. }
  9829. return buffergeometry;
  9830. }
  9831. function dispose() {
  9832. updateList = {};
  9833. }
  9834. return {
  9835. update: update,
  9836. dispose: dispose
  9837. };
  9838. }
  9839. /**
  9840. * @author mrdoob / http://mrdoob.com/
  9841. */
  9842. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9843. images = images !== undefined ? images : [];
  9844. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9845. format = format !== undefined ? format : RGBFormat;
  9846. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9847. this.flipY = false;
  9848. }
  9849. CubeTexture.prototype = Object.create( Texture.prototype );
  9850. CubeTexture.prototype.constructor = CubeTexture;
  9851. CubeTexture.prototype.isCubeTexture = true;
  9852. Object.defineProperty( CubeTexture.prototype, 'images', {
  9853. get: function () {
  9854. return this.image;
  9855. },
  9856. set: function ( value ) {
  9857. this.image = value;
  9858. }
  9859. } );
  9860. /**
  9861. * @author Takahiro https://github.com/takahirox
  9862. */
  9863. function DataTexture2DArray( data, width, height, depth ) {
  9864. Texture.call( this, null );
  9865. this.image = { data: data, width: width, height: height, depth: depth };
  9866. this.magFilter = NearestFilter;
  9867. this.minFilter = NearestFilter;
  9868. this.wrapR = ClampToEdgeWrapping;
  9869. this.generateMipmaps = false;
  9870. this.flipY = false;
  9871. }
  9872. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9873. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9874. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9875. /**
  9876. * @author Artur Trzesiok
  9877. */
  9878. function DataTexture3D( data, width, height, depth ) {
  9879. // We're going to add .setXXX() methods for setting properties later.
  9880. // Users can still set in DataTexture3D directly.
  9881. //
  9882. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9883. // texture.anisotropy = 16;
  9884. //
  9885. // See #14839
  9886. Texture.call( this, null );
  9887. this.image = { data: data, width: width, height: height, depth: depth };
  9888. this.magFilter = NearestFilter;
  9889. this.minFilter = NearestFilter;
  9890. this.wrapR = ClampToEdgeWrapping;
  9891. this.generateMipmaps = false;
  9892. this.flipY = false;
  9893. }
  9894. DataTexture3D.prototype = Object.create( Texture.prototype );
  9895. DataTexture3D.prototype.constructor = DataTexture3D;
  9896. DataTexture3D.prototype.isDataTexture3D = true;
  9897. /**
  9898. * @author tschw
  9899. * @author Mugen87 / https://github.com/Mugen87
  9900. * @author mrdoob / http://mrdoob.com/
  9901. *
  9902. * Uniforms of a program.
  9903. * Those form a tree structure with a special top-level container for the root,
  9904. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9905. *
  9906. *
  9907. * Properties of inner nodes including the top-level container:
  9908. *
  9909. * .seq - array of nested uniforms
  9910. * .map - nested uniforms by name
  9911. *
  9912. *
  9913. * Methods of all nodes except the top-level container:
  9914. *
  9915. * .setValue( gl, value, [textures] )
  9916. *
  9917. * uploads a uniform value(s)
  9918. * the 'textures' parameter is needed for sampler uniforms
  9919. *
  9920. *
  9921. * Static methods of the top-level container (textures factorizations):
  9922. *
  9923. * .upload( gl, seq, values, textures )
  9924. *
  9925. * sets uniforms in 'seq' to 'values[id].value'
  9926. *
  9927. * .seqWithValue( seq, values ) : filteredSeq
  9928. *
  9929. * filters 'seq' entries with corresponding entry in values
  9930. *
  9931. *
  9932. * Methods of the top-level container (textures factorizations):
  9933. *
  9934. * .setValue( gl, name, value, textures )
  9935. *
  9936. * sets uniform with name 'name' to 'value'
  9937. *
  9938. * .setOptional( gl, obj, prop )
  9939. *
  9940. * like .set for an optional property of the object
  9941. *
  9942. */
  9943. var emptyTexture = new Texture();
  9944. var emptyTexture2dArray = new DataTexture2DArray();
  9945. var emptyTexture3d = new DataTexture3D();
  9946. var emptyCubeTexture = new CubeTexture();
  9947. // --- Utilities ---
  9948. // Array Caches (provide typed arrays for temporary by size)
  9949. var arrayCacheF32 = [];
  9950. var arrayCacheI32 = [];
  9951. // Float32Array caches used for uploading Matrix uniforms
  9952. var mat4array = new Float32Array( 16 );
  9953. var mat3array = new Float32Array( 9 );
  9954. var mat2array = new Float32Array( 4 );
  9955. // Flattening for arrays of vectors and matrices
  9956. function flatten( array, nBlocks, blockSize ) {
  9957. var firstElem = array[ 0 ];
  9958. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9959. // unoptimized: ! isNaN( firstElem )
  9960. // see http://jacksondunstan.com/articles/983
  9961. var n = nBlocks * blockSize,
  9962. r = arrayCacheF32[ n ];
  9963. if ( r === undefined ) {
  9964. r = new Float32Array( n );
  9965. arrayCacheF32[ n ] = r;
  9966. }
  9967. if ( nBlocks !== 0 ) {
  9968. firstElem.toArray( r, 0 );
  9969. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9970. offset += blockSize;
  9971. array[ i ].toArray( r, offset );
  9972. }
  9973. }
  9974. return r;
  9975. }
  9976. function arraysEqual( a, b ) {
  9977. if ( a.length !== b.length ) return false;
  9978. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9979. if ( a[ i ] !== b[ i ] ) return false;
  9980. }
  9981. return true;
  9982. }
  9983. function copyArray( a, b ) {
  9984. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9985. a[ i ] = b[ i ];
  9986. }
  9987. }
  9988. // Texture unit allocation
  9989. function allocTexUnits( textures, n ) {
  9990. var r = arrayCacheI32[ n ];
  9991. if ( r === undefined ) {
  9992. r = new Int32Array( n );
  9993. arrayCacheI32[ n ] = r;
  9994. }
  9995. for ( var i = 0; i !== n; ++ i )
  9996. r[ i ] = textures.allocateTextureUnit();
  9997. return r;
  9998. }
  9999. // --- Setters ---
  10000. // Note: Defining these methods externally, because they come in a bunch
  10001. // and this way their names minify.
  10002. // Single scalar
  10003. function setValueV1f( gl, v ) {
  10004. var cache = this.cache;
  10005. if ( cache[ 0 ] === v ) return;
  10006. gl.uniform1f( this.addr, v );
  10007. cache[ 0 ] = v;
  10008. }
  10009. // Single float vector (from flat array or THREE.VectorN)
  10010. function setValueV2f( gl, v ) {
  10011. var cache = this.cache;
  10012. if ( v.x !== undefined ) {
  10013. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10014. gl.uniform2f( this.addr, v.x, v.y );
  10015. cache[ 0 ] = v.x;
  10016. cache[ 1 ] = v.y;
  10017. }
  10018. } else {
  10019. if ( arraysEqual( cache, v ) ) return;
  10020. gl.uniform2fv( this.addr, v );
  10021. copyArray( cache, v );
  10022. }
  10023. }
  10024. function setValueV3f( gl, v ) {
  10025. var cache = this.cache;
  10026. if ( v.x !== undefined ) {
  10027. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10028. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10029. cache[ 0 ] = v.x;
  10030. cache[ 1 ] = v.y;
  10031. cache[ 2 ] = v.z;
  10032. }
  10033. } else if ( v.r !== undefined ) {
  10034. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10035. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10036. cache[ 0 ] = v.r;
  10037. cache[ 1 ] = v.g;
  10038. cache[ 2 ] = v.b;
  10039. }
  10040. } else {
  10041. if ( arraysEqual( cache, v ) ) return;
  10042. gl.uniform3fv( this.addr, v );
  10043. copyArray( cache, v );
  10044. }
  10045. }
  10046. function setValueV4f( gl, v ) {
  10047. var cache = this.cache;
  10048. if ( v.x !== undefined ) {
  10049. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10050. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10051. cache[ 0 ] = v.x;
  10052. cache[ 1 ] = v.y;
  10053. cache[ 2 ] = v.z;
  10054. cache[ 3 ] = v.w;
  10055. }
  10056. } else {
  10057. if ( arraysEqual( cache, v ) ) return;
  10058. gl.uniform4fv( this.addr, v );
  10059. copyArray( cache, v );
  10060. }
  10061. }
  10062. // Single matrix (from flat array or MatrixN)
  10063. function setValueM2( gl, v ) {
  10064. var cache = this.cache;
  10065. var elements = v.elements;
  10066. if ( elements === undefined ) {
  10067. if ( arraysEqual( cache, v ) ) return;
  10068. gl.uniformMatrix2fv( this.addr, false, v );
  10069. copyArray( cache, v );
  10070. } else {
  10071. if ( arraysEqual( cache, elements ) ) return;
  10072. mat2array.set( elements );
  10073. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10074. copyArray( cache, elements );
  10075. }
  10076. }
  10077. function setValueM3( gl, v ) {
  10078. var cache = this.cache;
  10079. var elements = v.elements;
  10080. if ( elements === undefined ) {
  10081. if ( arraysEqual( cache, v ) ) return;
  10082. gl.uniformMatrix3fv( this.addr, false, v );
  10083. copyArray( cache, v );
  10084. } else {
  10085. if ( arraysEqual( cache, elements ) ) return;
  10086. mat3array.set( elements );
  10087. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10088. copyArray( cache, elements );
  10089. }
  10090. }
  10091. function setValueM4( gl, v ) {
  10092. var cache = this.cache;
  10093. var elements = v.elements;
  10094. if ( elements === undefined ) {
  10095. if ( arraysEqual( cache, v ) ) return;
  10096. gl.uniformMatrix4fv( this.addr, false, v );
  10097. copyArray( cache, v );
  10098. } else {
  10099. if ( arraysEqual( cache, elements ) ) return;
  10100. mat4array.set( elements );
  10101. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10102. copyArray( cache, elements );
  10103. }
  10104. }
  10105. // Single texture (2D / Cube)
  10106. function setValueT1( gl, v, textures ) {
  10107. var cache = this.cache;
  10108. var unit = textures.allocateTextureUnit();
  10109. if ( cache[ 0 ] !== unit ) {
  10110. gl.uniform1i( this.addr, unit );
  10111. cache[ 0 ] = unit;
  10112. }
  10113. textures.safeSetTexture2D( v || emptyTexture, unit );
  10114. }
  10115. function setValueT2DArray1( gl, v, textures ) {
  10116. var cache = this.cache;
  10117. var unit = textures.allocateTextureUnit();
  10118. if ( cache[ 0 ] !== unit ) {
  10119. gl.uniform1i( this.addr, unit );
  10120. cache[ 0 ] = unit;
  10121. }
  10122. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10123. }
  10124. function setValueT3D1( gl, v, textures ) {
  10125. var cache = this.cache;
  10126. var unit = textures.allocateTextureUnit();
  10127. if ( cache[ 0 ] !== unit ) {
  10128. gl.uniform1i( this.addr, unit );
  10129. cache[ 0 ] = unit;
  10130. }
  10131. textures.setTexture3D( v || emptyTexture3d, unit );
  10132. }
  10133. function setValueT6( gl, v, textures ) {
  10134. var cache = this.cache;
  10135. var unit = textures.allocateTextureUnit();
  10136. if ( cache[ 0 ] !== unit ) {
  10137. gl.uniform1i( this.addr, unit );
  10138. cache[ 0 ] = unit;
  10139. }
  10140. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10141. }
  10142. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10143. function setValueV1i( gl, v ) {
  10144. var cache = this.cache;
  10145. if ( cache[ 0 ] === v ) return;
  10146. gl.uniform1i( this.addr, v );
  10147. cache[ 0 ] = v;
  10148. }
  10149. function setValueV2i( gl, v ) {
  10150. var cache = this.cache;
  10151. if ( arraysEqual( cache, v ) ) return;
  10152. gl.uniform2iv( this.addr, v );
  10153. copyArray( cache, v );
  10154. }
  10155. function setValueV3i( gl, v ) {
  10156. var cache = this.cache;
  10157. if ( arraysEqual( cache, v ) ) return;
  10158. gl.uniform3iv( this.addr, v );
  10159. copyArray( cache, v );
  10160. }
  10161. function setValueV4i( gl, v ) {
  10162. var cache = this.cache;
  10163. if ( arraysEqual( cache, v ) ) return;
  10164. gl.uniform4iv( this.addr, v );
  10165. copyArray( cache, v );
  10166. }
  10167. // Helper to pick the right setter for the singular case
  10168. function getSingularSetter( type ) {
  10169. switch ( type ) {
  10170. case 0x1406: return setValueV1f; // FLOAT
  10171. case 0x8b50: return setValueV2f; // _VEC2
  10172. case 0x8b51: return setValueV3f; // _VEC3
  10173. case 0x8b52: return setValueV4f; // _VEC4
  10174. case 0x8b5a: return setValueM2; // _MAT2
  10175. case 0x8b5b: return setValueM3; // _MAT3
  10176. case 0x8b5c: return setValueM4; // _MAT4
  10177. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  10178. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  10179. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  10180. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  10181. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10182. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10183. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10184. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10185. }
  10186. }
  10187. // Array of scalars
  10188. function setValueV1fArray( gl, v ) {
  10189. gl.uniform1fv( this.addr, v );
  10190. }
  10191. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10192. function setValueV1iArray( gl, v ) {
  10193. gl.uniform1iv( this.addr, v );
  10194. }
  10195. function setValueV2iArray( gl, v ) {
  10196. gl.uniform2iv( this.addr, v );
  10197. }
  10198. function setValueV3iArray( gl, v ) {
  10199. gl.uniform3iv( this.addr, v );
  10200. }
  10201. function setValueV4iArray( gl, v ) {
  10202. gl.uniform4iv( this.addr, v );
  10203. }
  10204. // Array of vectors (flat or from THREE classes)
  10205. function setValueV2fArray( gl, v ) {
  10206. var data = flatten( v, this.size, 2 );
  10207. gl.uniform2fv( this.addr, data );
  10208. }
  10209. function setValueV3fArray( gl, v ) {
  10210. var data = flatten( v, this.size, 3 );
  10211. gl.uniform3fv( this.addr, data );
  10212. }
  10213. function setValueV4fArray( gl, v ) {
  10214. var data = flatten( v, this.size, 4 );
  10215. gl.uniform4fv( this.addr, data );
  10216. }
  10217. // Array of matrices (flat or from THREE clases)
  10218. function setValueM2Array( gl, v ) {
  10219. var data = flatten( v, this.size, 4 );
  10220. gl.uniformMatrix2fv( this.addr, false, data );
  10221. }
  10222. function setValueM3Array( gl, v ) {
  10223. var data = flatten( v, this.size, 9 );
  10224. gl.uniformMatrix3fv( this.addr, false, data );
  10225. }
  10226. function setValueM4Array( gl, v ) {
  10227. var data = flatten( v, this.size, 16 );
  10228. gl.uniformMatrix4fv( this.addr, false, data );
  10229. }
  10230. // Array of textures (2D / Cube)
  10231. function setValueT1Array( gl, v, textures ) {
  10232. var n = v.length;
  10233. var units = allocTexUnits( textures, n );
  10234. gl.uniform1iv( this.addr, units );
  10235. for ( var i = 0; i !== n; ++ i ) {
  10236. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10237. }
  10238. }
  10239. function setValueT6Array( gl, v, textures ) {
  10240. var n = v.length;
  10241. var units = allocTexUnits( textures, n );
  10242. gl.uniform1iv( this.addr, units );
  10243. for ( var i = 0; i !== n; ++ i ) {
  10244. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10245. }
  10246. }
  10247. // Helper to pick the right setter for a pure (bottom-level) array
  10248. function getPureArraySetter( type ) {
  10249. switch ( type ) {
  10250. case 0x1406: return setValueV1fArray; // FLOAT
  10251. case 0x8b50: return setValueV2fArray; // _VEC2
  10252. case 0x8b51: return setValueV3fArray; // _VEC3
  10253. case 0x8b52: return setValueV4fArray; // _VEC4
  10254. case 0x8b5a: return setValueM2Array; // _MAT2
  10255. case 0x8b5b: return setValueM3Array; // _MAT3
  10256. case 0x8b5c: return setValueM4Array; // _MAT4
  10257. case 0x8b5e: return setValueT1Array; // SAMPLER_2D
  10258. case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
  10259. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10260. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10261. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10262. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10263. }
  10264. }
  10265. // --- Uniform Classes ---
  10266. function SingleUniform( id, activeInfo, addr ) {
  10267. this.id = id;
  10268. this.addr = addr;
  10269. this.cache = [];
  10270. this.setValue = getSingularSetter( activeInfo.type );
  10271. // this.path = activeInfo.name; // DEBUG
  10272. }
  10273. function PureArrayUniform( id, activeInfo, addr ) {
  10274. this.id = id;
  10275. this.addr = addr;
  10276. this.cache = [];
  10277. this.size = activeInfo.size;
  10278. this.setValue = getPureArraySetter( activeInfo.type );
  10279. // this.path = activeInfo.name; // DEBUG
  10280. }
  10281. PureArrayUniform.prototype.updateCache = function ( data ) {
  10282. var cache = this.cache;
  10283. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10284. this.cache = new Float32Array( data.length );
  10285. }
  10286. copyArray( cache, data );
  10287. };
  10288. function StructuredUniform( id ) {
  10289. this.id = id;
  10290. this.seq = [];
  10291. this.map = {};
  10292. }
  10293. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10294. var seq = this.seq;
  10295. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10296. var u = seq[ i ];
  10297. u.setValue( gl, value[ u.id ], textures );
  10298. }
  10299. };
  10300. // --- Top-level ---
  10301. // Parser - builds up the property tree from the path strings
  10302. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10303. // extracts
  10304. // - the identifier (member name or array index)
  10305. // - followed by an optional right bracket (found when array index)
  10306. // - followed by an optional left bracket or dot (type of subscript)
  10307. //
  10308. // Note: These portions can be read in a non-overlapping fashion and
  10309. // allow straightforward parsing of the hierarchy that WebGL encodes
  10310. // in the uniform names.
  10311. function addUniform( container, uniformObject ) {
  10312. container.seq.push( uniformObject );
  10313. container.map[ uniformObject.id ] = uniformObject;
  10314. }
  10315. function parseUniform( activeInfo, addr, container ) {
  10316. var path = activeInfo.name,
  10317. pathLength = path.length;
  10318. // reset RegExp object, because of the early exit of a previous run
  10319. RePathPart.lastIndex = 0;
  10320. while ( true ) {
  10321. var match = RePathPart.exec( path ),
  10322. matchEnd = RePathPart.lastIndex,
  10323. id = match[ 1 ],
  10324. idIsIndex = match[ 2 ] === ']',
  10325. subscript = match[ 3 ];
  10326. if ( idIsIndex ) id = id | 0; // convert to integer
  10327. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10328. // bare name or "pure" bottom-level array "[0]" suffix
  10329. addUniform( container, subscript === undefined ?
  10330. new SingleUniform( id, activeInfo, addr ) :
  10331. new PureArrayUniform( id, activeInfo, addr ) );
  10332. break;
  10333. } else {
  10334. // step into inner node / create it in case it doesn't exist
  10335. var map = container.map, next = map[ id ];
  10336. if ( next === undefined ) {
  10337. next = new StructuredUniform( id );
  10338. addUniform( container, next );
  10339. }
  10340. container = next;
  10341. }
  10342. }
  10343. }
  10344. // Root Container
  10345. function WebGLUniforms( gl, program ) {
  10346. this.seq = [];
  10347. this.map = {};
  10348. var n = gl.getProgramParameter( program, 35718 );
  10349. for ( var i = 0; i < n; ++ i ) {
  10350. var info = gl.getActiveUniform( program, i ),
  10351. addr = gl.getUniformLocation( program, info.name );
  10352. parseUniform( info, addr, this );
  10353. }
  10354. }
  10355. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10356. var u = this.map[ name ];
  10357. if ( u !== undefined ) u.setValue( gl, value, textures );
  10358. };
  10359. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10360. var v = object[ name ];
  10361. if ( v !== undefined ) this.setValue( gl, name, v );
  10362. };
  10363. // Static interface
  10364. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10365. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10366. var u = seq[ i ],
  10367. v = values[ u.id ];
  10368. if ( v.needsUpdate !== false ) {
  10369. // note: always updating when .needsUpdate is undefined
  10370. u.setValue( gl, v.value, textures );
  10371. }
  10372. }
  10373. };
  10374. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10375. var r = [];
  10376. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10377. var u = seq[ i ];
  10378. if ( u.id in values ) r.push( u );
  10379. }
  10380. return r;
  10381. };
  10382. /**
  10383. * @author mrdoob / http://mrdoob.com/
  10384. */
  10385. function WebGLShader( gl, type, string ) {
  10386. var shader = gl.createShader( type );
  10387. gl.shaderSource( shader, string );
  10388. gl.compileShader( shader );
  10389. return shader;
  10390. }
  10391. /**
  10392. * @author mrdoob / http://mrdoob.com/
  10393. */
  10394. var programIdCount = 0;
  10395. function addLineNumbers( string ) {
  10396. var lines = string.split( '\n' );
  10397. for ( var i = 0; i < lines.length; i ++ ) {
  10398. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10399. }
  10400. return lines.join( '\n' );
  10401. }
  10402. function getEncodingComponents( encoding ) {
  10403. switch ( encoding ) {
  10404. case LinearEncoding:
  10405. return [ 'Linear', '( value )' ];
  10406. case sRGBEncoding:
  10407. return [ 'sRGB', '( value )' ];
  10408. case RGBEEncoding:
  10409. return [ 'RGBE', '( value )' ];
  10410. case RGBM7Encoding:
  10411. return [ 'RGBM', '( value, 7.0 )' ];
  10412. case RGBM16Encoding:
  10413. return [ 'RGBM', '( value, 16.0 )' ];
  10414. case RGBDEncoding:
  10415. return [ 'RGBD', '( value, 256.0 )' ];
  10416. case GammaEncoding:
  10417. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10418. case LogLuvEncoding:
  10419. return [ 'LogLuv', '( value )' ];
  10420. default:
  10421. throw new Error( 'unsupported encoding: ' + encoding );
  10422. }
  10423. }
  10424. function getShaderErrors( gl, shader, type ) {
  10425. var status = gl.getShaderParameter( shader, 35713 );
  10426. var log = gl.getShaderInfoLog( shader ).trim();
  10427. if ( status && log === '' ) return '';
  10428. // --enable-privileged-webgl-extension
  10429. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10430. var source = gl.getShaderSource( shader );
  10431. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10432. }
  10433. function getTexelDecodingFunction( functionName, encoding ) {
  10434. var components = getEncodingComponents( encoding );
  10435. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10436. }
  10437. function getTexelEncodingFunction( functionName, encoding ) {
  10438. var components = getEncodingComponents( encoding );
  10439. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10440. }
  10441. function getToneMappingFunction( functionName, toneMapping ) {
  10442. var toneMappingName;
  10443. switch ( toneMapping ) {
  10444. case LinearToneMapping:
  10445. toneMappingName = 'Linear';
  10446. break;
  10447. case ReinhardToneMapping:
  10448. toneMappingName = 'Reinhard';
  10449. break;
  10450. case Uncharted2ToneMapping:
  10451. toneMappingName = 'Uncharted2';
  10452. break;
  10453. case CineonToneMapping:
  10454. toneMappingName = 'OptimizedCineon';
  10455. break;
  10456. case ACESFilmicToneMapping:
  10457. toneMappingName = 'ACESFilmic';
  10458. break;
  10459. default:
  10460. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10461. }
  10462. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10463. }
  10464. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10465. extensions = extensions || {};
  10466. var chunks = [
  10467. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.clearCoatNormalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10468. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10469. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10470. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10471. ];
  10472. return chunks.filter( filterEmptyLine ).join( '\n' );
  10473. }
  10474. function generateDefines( defines ) {
  10475. var chunks = [];
  10476. for ( var name in defines ) {
  10477. var value = defines[ name ];
  10478. if ( value === false ) continue;
  10479. chunks.push( '#define ' + name + ' ' + value );
  10480. }
  10481. return chunks.join( '\n' );
  10482. }
  10483. function fetchAttributeLocations( gl, program ) {
  10484. var attributes = {};
  10485. var n = gl.getProgramParameter( program, 35721 );
  10486. for ( var i = 0; i < n; i ++ ) {
  10487. var info = gl.getActiveAttrib( program, i );
  10488. var name = info.name;
  10489. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10490. attributes[ name ] = gl.getAttribLocation( program, name );
  10491. }
  10492. return attributes;
  10493. }
  10494. function filterEmptyLine( string ) {
  10495. return string !== '';
  10496. }
  10497. function replaceLightNums( string, parameters ) {
  10498. return string
  10499. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10500. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10501. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10502. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10503. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  10504. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  10505. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  10506. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  10507. }
  10508. function replaceClippingPlaneNums( string, parameters ) {
  10509. return string
  10510. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10511. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10512. }
  10513. function parseIncludes( string ) {
  10514. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10515. function replace( match, include ) {
  10516. var replace = ShaderChunk[ include ];
  10517. if ( replace === undefined ) {
  10518. throw new Error( 'Can not resolve #include <' + include + '>' );
  10519. }
  10520. return parseIncludes( replace );
  10521. }
  10522. return string.replace( pattern, replace );
  10523. }
  10524. function unrollLoops( string ) {
  10525. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10526. function replace( match, start, end, snippet ) {
  10527. var unroll = '';
  10528. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10529. unroll += snippet
  10530. .replace( /\[ i \]/g, '[ ' + i + ' ]' )
  10531. .replace( /UNROLLED_LOOP_INDEX/g, i );
  10532. }
  10533. return unroll;
  10534. }
  10535. return string.replace( pattern, replace );
  10536. }
  10537. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  10538. var gl = renderer.getContext();
  10539. var defines = material.defines;
  10540. var vertexShader = shader.vertexShader;
  10541. var fragmentShader = shader.fragmentShader;
  10542. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10543. if ( parameters.shadowMapType === PCFShadowMap ) {
  10544. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10545. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10546. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10547. }
  10548. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10549. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10550. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10551. if ( parameters.envMap ) {
  10552. switch ( material.envMap.mapping ) {
  10553. case CubeReflectionMapping:
  10554. case CubeRefractionMapping:
  10555. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10556. break;
  10557. case CubeUVReflectionMapping:
  10558. case CubeUVRefractionMapping:
  10559. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10560. break;
  10561. case EquirectangularReflectionMapping:
  10562. case EquirectangularRefractionMapping:
  10563. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10564. break;
  10565. case SphericalReflectionMapping:
  10566. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10567. break;
  10568. }
  10569. switch ( material.envMap.mapping ) {
  10570. case CubeRefractionMapping:
  10571. case EquirectangularRefractionMapping:
  10572. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10573. break;
  10574. }
  10575. switch ( material.combine ) {
  10576. case MultiplyOperation:
  10577. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10578. break;
  10579. case MixOperation:
  10580. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10581. break;
  10582. case AddOperation:
  10583. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10584. break;
  10585. }
  10586. }
  10587. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10588. // console.log( 'building new program ' );
  10589. //
  10590. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10591. var customDefines = generateDefines( defines );
  10592. //
  10593. var program = gl.createProgram();
  10594. var prefixVertex, prefixFragment;
  10595. if ( material.isRawShaderMaterial ) {
  10596. prefixVertex = [
  10597. customDefines
  10598. ].filter( filterEmptyLine ).join( '\n' );
  10599. if ( prefixVertex.length > 0 ) {
  10600. prefixVertex += '\n';
  10601. }
  10602. prefixFragment = [
  10603. customExtensions,
  10604. customDefines
  10605. ].filter( filterEmptyLine ).join( '\n' );
  10606. if ( prefixFragment.length > 0 ) {
  10607. prefixFragment += '\n';
  10608. }
  10609. } else {
  10610. prefixVertex = [
  10611. 'precision ' + parameters.precision + ' float;',
  10612. 'precision ' + parameters.precision + ' int;',
  10613. '#define SHADER_NAME ' + shader.name,
  10614. customDefines,
  10615. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10616. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10617. '#define MAX_BONES ' + parameters.maxBones,
  10618. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10619. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10620. parameters.map ? '#define USE_MAP' : '',
  10621. parameters.envMap ? '#define USE_ENVMAP' : '',
  10622. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10623. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10624. parameters.aoMap ? '#define USE_AOMAP' : '',
  10625. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10626. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10627. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10628. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10629. parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10630. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10631. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10632. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10633. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10634. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10635. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10636. parameters.vertexColors ? '#define USE_COLOR' : '',
  10637. parameters.vertexUvs ? '#define USE_UV' : '',
  10638. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10639. parameters.skinning ? '#define USE_SKINNING' : '',
  10640. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10641. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10642. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10643. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10644. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10645. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10646. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10647. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10648. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10649. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10650. 'uniform mat4 modelMatrix;',
  10651. 'uniform mat4 modelViewMatrix;',
  10652. 'uniform mat4 projectionMatrix;',
  10653. 'uniform mat4 viewMatrix;',
  10654. 'uniform mat3 normalMatrix;',
  10655. 'uniform vec3 cameraPosition;',
  10656. 'attribute vec3 position;',
  10657. 'attribute vec3 normal;',
  10658. 'attribute vec2 uv;',
  10659. '#ifdef USE_TANGENT',
  10660. ' attribute vec4 tangent;',
  10661. '#endif',
  10662. '#ifdef USE_COLOR',
  10663. ' attribute vec3 color;',
  10664. '#endif',
  10665. '#ifdef USE_MORPHTARGETS',
  10666. ' attribute vec3 morphTarget0;',
  10667. ' attribute vec3 morphTarget1;',
  10668. ' attribute vec3 morphTarget2;',
  10669. ' attribute vec3 morphTarget3;',
  10670. ' #ifdef USE_MORPHNORMALS',
  10671. ' attribute vec3 morphNormal0;',
  10672. ' attribute vec3 morphNormal1;',
  10673. ' attribute vec3 morphNormal2;',
  10674. ' attribute vec3 morphNormal3;',
  10675. ' #else',
  10676. ' attribute vec3 morphTarget4;',
  10677. ' attribute vec3 morphTarget5;',
  10678. ' attribute vec3 morphTarget6;',
  10679. ' attribute vec3 morphTarget7;',
  10680. ' #endif',
  10681. '#endif',
  10682. '#ifdef USE_SKINNING',
  10683. ' attribute vec4 skinIndex;',
  10684. ' attribute vec4 skinWeight;',
  10685. '#endif',
  10686. '\n'
  10687. ].filter( filterEmptyLine ).join( '\n' );
  10688. prefixFragment = [
  10689. customExtensions,
  10690. 'precision ' + parameters.precision + ' float;',
  10691. 'precision ' + parameters.precision + ' int;',
  10692. '#define SHADER_NAME ' + shader.name,
  10693. customDefines,
  10694. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10695. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10696. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10697. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10698. parameters.map ? '#define USE_MAP' : '',
  10699. parameters.matcap ? '#define USE_MATCAP' : '',
  10700. parameters.envMap ? '#define USE_ENVMAP' : '',
  10701. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10702. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10703. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10704. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10705. parameters.aoMap ? '#define USE_AOMAP' : '',
  10706. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10707. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10708. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10709. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10710. parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10711. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10712. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10713. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10714. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10715. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10716. parameters.vertexColors ? '#define USE_COLOR' : '',
  10717. parameters.vertexUvs ? '#define USE_UV' : '',
  10718. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10719. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10720. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10721. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10722. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10723. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10724. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10725. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10726. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10727. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10728. ( ( material.extensions ? material.extensions.shaderTextureLOD : false ) || parameters.envMap ) && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10729. 'uniform mat4 viewMatrix;',
  10730. 'uniform vec3 cameraPosition;',
  10731. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10732. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10733. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10734. parameters.dithering ? '#define DITHERING' : '',
  10735. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10736. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10737. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10738. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10739. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10740. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10741. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10742. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10743. '\n'
  10744. ].filter( filterEmptyLine ).join( '\n' );
  10745. }
  10746. vertexShader = parseIncludes( vertexShader );
  10747. vertexShader = replaceLightNums( vertexShader, parameters );
  10748. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10749. fragmentShader = parseIncludes( fragmentShader );
  10750. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10751. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10752. vertexShader = unrollLoops( vertexShader );
  10753. fragmentShader = unrollLoops( fragmentShader );
  10754. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10755. var isGLSL3ShaderMaterial = false;
  10756. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10757. if ( material.isShaderMaterial &&
  10758. vertexShader.match( versionRegex ) !== null &&
  10759. fragmentShader.match( versionRegex ) !== null ) {
  10760. isGLSL3ShaderMaterial = true;
  10761. vertexShader = vertexShader.replace( versionRegex, '' );
  10762. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10763. }
  10764. // GLSL 3.0 conversion
  10765. prefixVertex = [
  10766. '#version 300 es\n',
  10767. '#define attribute in',
  10768. '#define varying out',
  10769. '#define texture2D texture'
  10770. ].join( '\n' ) + '\n' + prefixVertex;
  10771. prefixFragment = [
  10772. '#version 300 es\n',
  10773. '#define varying in',
  10774. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10775. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10776. '#define gl_FragDepthEXT gl_FragDepth',
  10777. '#define texture2D texture',
  10778. '#define textureCube texture',
  10779. '#define texture2DProj textureProj',
  10780. '#define texture2DLodEXT textureLod',
  10781. '#define texture2DProjLodEXT textureProjLod',
  10782. '#define textureCubeLodEXT textureLod',
  10783. '#define texture2DGradEXT textureGrad',
  10784. '#define texture2DProjGradEXT textureProjGrad',
  10785. '#define textureCubeGradEXT textureGrad'
  10786. ].join( '\n' ) + '\n' + prefixFragment;
  10787. }
  10788. var vertexGlsl = prefixVertex + vertexShader;
  10789. var fragmentGlsl = prefixFragment + fragmentShader;
  10790. // console.log( '*VERTEX*', vertexGlsl );
  10791. // console.log( '*FRAGMENT*', fragmentGlsl );
  10792. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10793. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10794. gl.attachShader( program, glVertexShader );
  10795. gl.attachShader( program, glFragmentShader );
  10796. // Force a particular attribute to index 0.
  10797. if ( material.index0AttributeName !== undefined ) {
  10798. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10799. } else if ( parameters.morphTargets === true ) {
  10800. // programs with morphTargets displace position out of attribute 0
  10801. gl.bindAttribLocation( program, 0, 'position' );
  10802. }
  10803. gl.linkProgram( program );
  10804. // check for link errors
  10805. if ( renderer.debug.checkShaderErrors ) {
  10806. var programLog = gl.getProgramInfoLog( program ).trim();
  10807. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10808. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10809. var runnable = true;
  10810. var haveDiagnostics = true;
  10811. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10812. runnable = false;
  10813. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10814. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10815. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10816. } else if ( programLog !== '' ) {
  10817. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10818. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10819. haveDiagnostics = false;
  10820. }
  10821. if ( haveDiagnostics ) {
  10822. this.diagnostics = {
  10823. runnable: runnable,
  10824. material: material,
  10825. programLog: programLog,
  10826. vertexShader: {
  10827. log: vertexLog,
  10828. prefix: prefixVertex
  10829. },
  10830. fragmentShader: {
  10831. log: fragmentLog,
  10832. prefix: prefixFragment
  10833. }
  10834. };
  10835. }
  10836. }
  10837. // clean up
  10838. gl.deleteShader( glVertexShader );
  10839. gl.deleteShader( glFragmentShader );
  10840. // set up caching for uniform locations
  10841. var cachedUniforms;
  10842. this.getUniforms = function () {
  10843. if ( cachedUniforms === undefined ) {
  10844. cachedUniforms = new WebGLUniforms( gl, program );
  10845. }
  10846. return cachedUniforms;
  10847. };
  10848. // set up caching for attribute locations
  10849. var cachedAttributes;
  10850. this.getAttributes = function () {
  10851. if ( cachedAttributes === undefined ) {
  10852. cachedAttributes = fetchAttributeLocations( gl, program );
  10853. }
  10854. return cachedAttributes;
  10855. };
  10856. // free resource
  10857. this.destroy = function () {
  10858. gl.deleteProgram( program );
  10859. this.program = undefined;
  10860. };
  10861. //
  10862. this.name = shader.name;
  10863. this.id = programIdCount ++;
  10864. this.code = code;
  10865. this.usedTimes = 1;
  10866. this.program = program;
  10867. this.vertexShader = glVertexShader;
  10868. this.fragmentShader = glFragmentShader;
  10869. return this;
  10870. }
  10871. /**
  10872. * @author mrdoob / http://mrdoob.com/
  10873. */
  10874. function WebGLPrograms( renderer, extensions, capabilities ) {
  10875. var programs = [];
  10876. var shaderIDs = {
  10877. MeshDepthMaterial: 'depth',
  10878. MeshDistanceMaterial: 'distanceRGBA',
  10879. MeshNormalMaterial: 'normal',
  10880. MeshBasicMaterial: 'basic',
  10881. MeshLambertMaterial: 'lambert',
  10882. MeshPhongMaterial: 'phong',
  10883. MeshToonMaterial: 'phong',
  10884. MeshStandardMaterial: 'physical',
  10885. MeshPhysicalMaterial: 'physical',
  10886. MeshMatcapMaterial: 'matcap',
  10887. LineBasicMaterial: 'basic',
  10888. LineDashedMaterial: 'dashed',
  10889. PointsMaterial: 'points',
  10890. ShadowMaterial: 'shadow',
  10891. SpriteMaterial: 'sprite'
  10892. };
  10893. var parameterNames = [
  10894. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10895. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "clearCoatNormalMap", "displacementMap", "specularMap",
  10896. "roughnessMap", "metalnessMap", "gradientMap",
  10897. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10898. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10899. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10900. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10901. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10902. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10903. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10904. ];
  10905. function allocateBones( object ) {
  10906. var skeleton = object.skeleton;
  10907. var bones = skeleton.bones;
  10908. if ( capabilities.floatVertexTextures ) {
  10909. return 1024;
  10910. } else {
  10911. // default for when object is not specified
  10912. // ( for example when prebuilding shader to be used with multiple objects )
  10913. //
  10914. // - leave some extra space for other uniforms
  10915. // - limit here is ANGLE's 254 max uniform vectors
  10916. // (up to 54 should be safe)
  10917. var nVertexUniforms = capabilities.maxVertexUniforms;
  10918. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10919. var maxBones = Math.min( nVertexMatrices, bones.length );
  10920. if ( maxBones < bones.length ) {
  10921. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10922. return 0;
  10923. }
  10924. return maxBones;
  10925. }
  10926. }
  10927. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10928. var encoding;
  10929. if ( ! map ) {
  10930. encoding = LinearEncoding;
  10931. } else if ( map.isTexture ) {
  10932. encoding = map.encoding;
  10933. } else if ( map.isWebGLRenderTarget ) {
  10934. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10935. encoding = map.texture.encoding;
  10936. }
  10937. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10938. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10939. encoding = GammaEncoding;
  10940. }
  10941. return encoding;
  10942. }
  10943. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10944. var shaderID = shaderIDs[ material.type ];
  10945. // heuristics to create shader parameters according to lights in the scene
  10946. // (not to blow over maxLights budget)
  10947. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10948. var precision = capabilities.precision;
  10949. if ( material.precision !== null ) {
  10950. precision = capabilities.getMaxPrecision( material.precision );
  10951. if ( precision !== material.precision ) {
  10952. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10953. }
  10954. }
  10955. var currentRenderTarget = renderer.getRenderTarget();
  10956. var parameters = {
  10957. shaderID: shaderID,
  10958. precision: precision,
  10959. supportsVertexTextures: capabilities.vertexTextures,
  10960. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10961. map: !! material.map,
  10962. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10963. matcap: !! material.matcap,
  10964. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10965. envMap: !! material.envMap,
  10966. envMapMode: material.envMap && material.envMap.mapping,
  10967. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10968. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10969. lightMap: !! material.lightMap,
  10970. aoMap: !! material.aoMap,
  10971. emissiveMap: !! material.emissiveMap,
  10972. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10973. bumpMap: !! material.bumpMap,
  10974. normalMap: !! material.normalMap,
  10975. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10976. clearCoatNormalMap: !! material.clearCoatNormalMap,
  10977. displacementMap: !! material.displacementMap,
  10978. roughnessMap: !! material.roughnessMap,
  10979. metalnessMap: !! material.metalnessMap,
  10980. specularMap: !! material.specularMap,
  10981. alphaMap: !! material.alphaMap,
  10982. gradientMap: !! material.gradientMap,
  10983. combine: material.combine,
  10984. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10985. vertexColors: material.vertexColors,
  10986. vertexUvs: !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearCoatNormalMap,
  10987. fog: !! fog,
  10988. useFog: material.fog,
  10989. fogExp: ( fog && fog.isFogExp2 ),
  10990. flatShading: material.flatShading,
  10991. sizeAttenuation: material.sizeAttenuation,
  10992. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10993. skinning: material.skinning && maxBones > 0,
  10994. maxBones: maxBones,
  10995. useVertexTexture: capabilities.floatVertexTextures,
  10996. morphTargets: material.morphTargets,
  10997. morphNormals: material.morphNormals,
  10998. maxMorphTargets: renderer.maxMorphTargets,
  10999. maxMorphNormals: renderer.maxMorphNormals,
  11000. numDirLights: lights.directional.length,
  11001. numPointLights: lights.point.length,
  11002. numSpotLights: lights.spot.length,
  11003. numRectAreaLights: lights.rectArea.length,
  11004. numHemiLights: lights.hemi.length,
  11005. numDirLightShadows: lights.directionalShadowMap.length,
  11006. numPointLightShadows: lights.pointShadowMap.length,
  11007. numSpotLightShadows: lights.spotShadowMap.length,
  11008. numClippingPlanes: nClipPlanes,
  11009. numClipIntersection: nClipIntersection,
  11010. dithering: material.dithering,
  11011. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  11012. shadowMapType: renderer.shadowMap.type,
  11013. toneMapping: renderer.toneMapping,
  11014. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11015. premultipliedAlpha: material.premultipliedAlpha,
  11016. alphaTest: material.alphaTest,
  11017. doubleSided: material.side === DoubleSide,
  11018. flipSided: material.side === BackSide,
  11019. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  11020. };
  11021. return parameters;
  11022. };
  11023. this.getProgramCode = function ( material, parameters ) {
  11024. var array = [];
  11025. if ( parameters.shaderID ) {
  11026. array.push( parameters.shaderID );
  11027. } else {
  11028. array.push( material.fragmentShader );
  11029. array.push( material.vertexShader );
  11030. }
  11031. if ( material.defines !== undefined ) {
  11032. for ( var name in material.defines ) {
  11033. array.push( name );
  11034. array.push( material.defines[ name ] );
  11035. }
  11036. }
  11037. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11038. array.push( parameters[ parameterNames[ i ] ] );
  11039. }
  11040. array.push( material.onBeforeCompile.toString() );
  11041. array.push( renderer.gammaOutput );
  11042. array.push( renderer.gammaFactor );
  11043. return array.join();
  11044. };
  11045. this.acquireProgram = function ( material, shader, parameters, code ) {
  11046. var program;
  11047. // Check if code has been already compiled
  11048. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11049. var programInfo = programs[ p ];
  11050. if ( programInfo.code === code ) {
  11051. program = programInfo;
  11052. ++ program.usedTimes;
  11053. break;
  11054. }
  11055. }
  11056. if ( program === undefined ) {
  11057. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  11058. programs.push( program );
  11059. }
  11060. return program;
  11061. };
  11062. this.releaseProgram = function ( program ) {
  11063. if ( -- program.usedTimes === 0 ) {
  11064. // Remove from unordered set
  11065. var i = programs.indexOf( program );
  11066. programs[ i ] = programs[ programs.length - 1 ];
  11067. programs.pop();
  11068. // Free WebGL resources
  11069. program.destroy();
  11070. }
  11071. };
  11072. // Exposed for resource monitoring & error feedback via renderer.info:
  11073. this.programs = programs;
  11074. }
  11075. /**
  11076. * @author fordacious / fordacious.github.io
  11077. */
  11078. function WebGLProperties() {
  11079. var properties = new WeakMap();
  11080. function get( object ) {
  11081. var map = properties.get( object );
  11082. if ( map === undefined ) {
  11083. map = {};
  11084. properties.set( object, map );
  11085. }
  11086. return map;
  11087. }
  11088. function remove( object ) {
  11089. properties.delete( object );
  11090. }
  11091. function update( object, key, value ) {
  11092. properties.get( object )[ key ] = value;
  11093. }
  11094. function dispose() {
  11095. properties = new WeakMap();
  11096. }
  11097. return {
  11098. get: get,
  11099. remove: remove,
  11100. update: update,
  11101. dispose: dispose
  11102. };
  11103. }
  11104. /**
  11105. * @author mrdoob / http://mrdoob.com/
  11106. */
  11107. function painterSortStable( a, b ) {
  11108. if ( a.groupOrder !== b.groupOrder ) {
  11109. return a.groupOrder - b.groupOrder;
  11110. } else if ( a.renderOrder !== b.renderOrder ) {
  11111. return a.renderOrder - b.renderOrder;
  11112. } else if ( a.program !== b.program ) {
  11113. return a.program.id - b.program.id;
  11114. } else if ( a.material.id !== b.material.id ) {
  11115. return a.material.id - b.material.id;
  11116. } else if ( a.z !== b.z ) {
  11117. return a.z - b.z;
  11118. } else {
  11119. return a.id - b.id;
  11120. }
  11121. }
  11122. function reversePainterSortStable( a, b ) {
  11123. if ( a.groupOrder !== b.groupOrder ) {
  11124. return a.groupOrder - b.groupOrder;
  11125. } else if ( a.renderOrder !== b.renderOrder ) {
  11126. return a.renderOrder - b.renderOrder;
  11127. } else if ( a.z !== b.z ) {
  11128. return b.z - a.z;
  11129. } else {
  11130. return a.id - b.id;
  11131. }
  11132. }
  11133. function WebGLRenderList() {
  11134. var renderItems = [];
  11135. var renderItemsIndex = 0;
  11136. var opaque = [];
  11137. var transparent = [];
  11138. var defaultProgram = { id: - 1 };
  11139. function init() {
  11140. renderItemsIndex = 0;
  11141. opaque.length = 0;
  11142. transparent.length = 0;
  11143. }
  11144. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11145. var renderItem = renderItems[ renderItemsIndex ];
  11146. if ( renderItem === undefined ) {
  11147. renderItem = {
  11148. id: object.id,
  11149. object: object,
  11150. geometry: geometry,
  11151. material: material,
  11152. program: material.program || defaultProgram,
  11153. groupOrder: groupOrder,
  11154. renderOrder: object.renderOrder,
  11155. z: z,
  11156. group: group
  11157. };
  11158. renderItems[ renderItemsIndex ] = renderItem;
  11159. } else {
  11160. renderItem.id = object.id;
  11161. renderItem.object = object;
  11162. renderItem.geometry = geometry;
  11163. renderItem.material = material;
  11164. renderItem.program = material.program || defaultProgram;
  11165. renderItem.groupOrder = groupOrder;
  11166. renderItem.renderOrder = object.renderOrder;
  11167. renderItem.z = z;
  11168. renderItem.group = group;
  11169. }
  11170. renderItemsIndex ++;
  11171. return renderItem;
  11172. }
  11173. function push( object, geometry, material, groupOrder, z, group ) {
  11174. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11175. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11176. }
  11177. function unshift( object, geometry, material, groupOrder, z, group ) {
  11178. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11179. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11180. }
  11181. function sort() {
  11182. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  11183. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  11184. }
  11185. return {
  11186. opaque: opaque,
  11187. transparent: transparent,
  11188. init: init,
  11189. push: push,
  11190. unshift: unshift,
  11191. sort: sort
  11192. };
  11193. }
  11194. function WebGLRenderLists() {
  11195. var lists = {};
  11196. function onSceneDispose( event ) {
  11197. var scene = event.target;
  11198. scene.removeEventListener( 'dispose', onSceneDispose );
  11199. delete lists[ scene.id ];
  11200. }
  11201. function get( scene, camera ) {
  11202. var cameras = lists[ scene.id ];
  11203. var list;
  11204. if ( cameras === undefined ) {
  11205. list = new WebGLRenderList();
  11206. lists[ scene.id ] = {};
  11207. lists[ scene.id ][ camera.id ] = list;
  11208. scene.addEventListener( 'dispose', onSceneDispose );
  11209. } else {
  11210. list = cameras[ camera.id ];
  11211. if ( list === undefined ) {
  11212. list = new WebGLRenderList();
  11213. cameras[ camera.id ] = list;
  11214. }
  11215. }
  11216. return list;
  11217. }
  11218. function dispose() {
  11219. lists = {};
  11220. }
  11221. return {
  11222. get: get,
  11223. dispose: dispose
  11224. };
  11225. }
  11226. /**
  11227. * @author mrdoob / http://mrdoob.com/
  11228. */
  11229. function UniformsCache() {
  11230. var lights = {};
  11231. return {
  11232. get: function ( light ) {
  11233. if ( lights[ light.id ] !== undefined ) {
  11234. return lights[ light.id ];
  11235. }
  11236. var uniforms;
  11237. switch ( light.type ) {
  11238. case 'DirectionalLight':
  11239. uniforms = {
  11240. direction: new Vector3(),
  11241. color: new Color(),
  11242. shadow: false,
  11243. shadowBias: 0,
  11244. shadowRadius: 1,
  11245. shadowMapSize: new Vector2()
  11246. };
  11247. break;
  11248. case 'SpotLight':
  11249. uniforms = {
  11250. position: new Vector3(),
  11251. direction: new Vector3(),
  11252. color: new Color(),
  11253. distance: 0,
  11254. coneCos: 0,
  11255. penumbraCos: 0,
  11256. decay: 0,
  11257. shadow: false,
  11258. shadowBias: 0,
  11259. shadowRadius: 1,
  11260. shadowMapSize: new Vector2()
  11261. };
  11262. break;
  11263. case 'PointLight':
  11264. uniforms = {
  11265. position: new Vector3(),
  11266. color: new Color(),
  11267. distance: 0,
  11268. decay: 0,
  11269. shadow: false,
  11270. shadowBias: 0,
  11271. shadowRadius: 1,
  11272. shadowMapSize: new Vector2(),
  11273. shadowCameraNear: 1,
  11274. shadowCameraFar: 1000
  11275. };
  11276. break;
  11277. case 'HemisphereLight':
  11278. uniforms = {
  11279. direction: new Vector3(),
  11280. skyColor: new Color(),
  11281. groundColor: new Color()
  11282. };
  11283. break;
  11284. case 'RectAreaLight':
  11285. uniforms = {
  11286. color: new Color(),
  11287. position: new Vector3(),
  11288. halfWidth: new Vector3(),
  11289. halfHeight: new Vector3()
  11290. // TODO (abelnation): set RectAreaLight shadow uniforms
  11291. };
  11292. break;
  11293. }
  11294. lights[ light.id ] = uniforms;
  11295. return uniforms;
  11296. }
  11297. };
  11298. }
  11299. var nextVersion = 0;
  11300. function shadowCastingLightsFirst( lightA, lightB ) {
  11301. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  11302. }
  11303. function WebGLLights() {
  11304. var cache = new UniformsCache();
  11305. var state = {
  11306. version: 0,
  11307. hash: {
  11308. directionalLength: - 1,
  11309. pointLength: - 1,
  11310. spotLength: - 1,
  11311. rectAreaLength: - 1,
  11312. hemiLength: - 1,
  11313. numDirectionalShadows: - 1,
  11314. numPointShadows: - 1,
  11315. numSpotShadows: - 1,
  11316. },
  11317. ambient: [ 0, 0, 0 ],
  11318. probe: [],
  11319. directional: [],
  11320. directionalShadowMap: [],
  11321. directionalShadowMatrix: [],
  11322. spot: [],
  11323. spotShadowMap: [],
  11324. spotShadowMatrix: [],
  11325. rectArea: [],
  11326. point: [],
  11327. pointShadowMap: [],
  11328. pointShadowMatrix: [],
  11329. hemi: [],
  11330. numDirectionalShadows: - 1,
  11331. numPointShadows: - 1,
  11332. numSpotShadows: - 1
  11333. };
  11334. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11335. var vector3 = new Vector3();
  11336. var matrix4 = new Matrix4();
  11337. var matrix42 = new Matrix4();
  11338. function setup( lights, shadows, camera ) {
  11339. var r = 0, g = 0, b = 0;
  11340. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11341. var directionalLength = 0;
  11342. var pointLength = 0;
  11343. var spotLength = 0;
  11344. var rectAreaLength = 0;
  11345. var hemiLength = 0;
  11346. var numDirectionalShadows = 0;
  11347. var numPointShadows = 0;
  11348. var numSpotShadows = 0;
  11349. var viewMatrix = camera.matrixWorldInverse;
  11350. lights.sort( shadowCastingLightsFirst );
  11351. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  11352. var light = lights[ i ];
  11353. var color = light.color;
  11354. var intensity = light.intensity;
  11355. var distance = light.distance;
  11356. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11357. if ( light.isAmbientLight ) {
  11358. r += color.r * intensity;
  11359. g += color.g * intensity;
  11360. b += color.b * intensity;
  11361. } else if ( light.isLightProbe ) {
  11362. for ( var j = 0; j < 9; j ++ ) {
  11363. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11364. }
  11365. } else if ( light.isDirectionalLight ) {
  11366. var uniforms = cache.get( light );
  11367. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11368. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11369. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11370. uniforms.direction.sub( vector3 );
  11371. uniforms.direction.transformDirection( viewMatrix );
  11372. uniforms.shadow = light.castShadow;
  11373. if ( light.castShadow ) {
  11374. var shadow = light.shadow;
  11375. uniforms.shadowBias = shadow.bias;
  11376. uniforms.shadowRadius = shadow.radius;
  11377. uniforms.shadowMapSize = shadow.mapSize;
  11378. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11379. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11380. numDirectionalShadows ++;
  11381. }
  11382. state.directional[ directionalLength ] = uniforms;
  11383. directionalLength ++;
  11384. } else if ( light.isSpotLight ) {
  11385. var uniforms = cache.get( light );
  11386. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11387. uniforms.position.applyMatrix4( viewMatrix );
  11388. uniforms.color.copy( color ).multiplyScalar( intensity );
  11389. uniforms.distance = distance;
  11390. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11391. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11392. uniforms.direction.sub( vector3 );
  11393. uniforms.direction.transformDirection( viewMatrix );
  11394. uniforms.coneCos = Math.cos( light.angle );
  11395. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11396. uniforms.decay = light.decay;
  11397. uniforms.shadow = light.castShadow;
  11398. if ( light.castShadow ) {
  11399. var shadow = light.shadow;
  11400. uniforms.shadowBias = shadow.bias;
  11401. uniforms.shadowRadius = shadow.radius;
  11402. uniforms.shadowMapSize = shadow.mapSize;
  11403. state.spotShadowMap[ spotLength ] = shadowMap;
  11404. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11405. numSpotShadows ++;
  11406. }
  11407. state.spot[ spotLength ] = uniforms;
  11408. spotLength ++;
  11409. } else if ( light.isRectAreaLight ) {
  11410. var uniforms = cache.get( light );
  11411. // (a) intensity is the total visible light emitted
  11412. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11413. // (b) intensity is the brightness of the light
  11414. uniforms.color.copy( color ).multiplyScalar( intensity );
  11415. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11416. uniforms.position.applyMatrix4( viewMatrix );
  11417. // extract local rotation of light to derive width/height half vectors
  11418. matrix42.identity();
  11419. matrix4.copy( light.matrixWorld );
  11420. matrix4.premultiply( viewMatrix );
  11421. matrix42.extractRotation( matrix4 );
  11422. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11423. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11424. uniforms.halfWidth.applyMatrix4( matrix42 );
  11425. uniforms.halfHeight.applyMatrix4( matrix42 );
  11426. // TODO (abelnation): RectAreaLight distance?
  11427. // uniforms.distance = distance;
  11428. state.rectArea[ rectAreaLength ] = uniforms;
  11429. rectAreaLength ++;
  11430. } else if ( light.isPointLight ) {
  11431. var uniforms = cache.get( light );
  11432. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11433. uniforms.position.applyMatrix4( viewMatrix );
  11434. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11435. uniforms.distance = light.distance;
  11436. uniforms.decay = light.decay;
  11437. uniforms.shadow = light.castShadow;
  11438. if ( light.castShadow ) {
  11439. var shadow = light.shadow;
  11440. uniforms.shadowBias = shadow.bias;
  11441. uniforms.shadowRadius = shadow.radius;
  11442. uniforms.shadowMapSize = shadow.mapSize;
  11443. uniforms.shadowCameraNear = shadow.camera.near;
  11444. uniforms.shadowCameraFar = shadow.camera.far;
  11445. state.pointShadowMap[ pointLength ] = shadowMap;
  11446. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11447. numPointShadows ++;
  11448. }
  11449. state.point[ pointLength ] = uniforms;
  11450. pointLength ++;
  11451. } else if ( light.isHemisphereLight ) {
  11452. var uniforms = cache.get( light );
  11453. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11454. uniforms.direction.transformDirection( viewMatrix );
  11455. uniforms.direction.normalize();
  11456. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11457. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11458. state.hemi[ hemiLength ] = uniforms;
  11459. hemiLength ++;
  11460. }
  11461. }
  11462. state.ambient[ 0 ] = r;
  11463. state.ambient[ 1 ] = g;
  11464. state.ambient[ 2 ] = b;
  11465. var hash = state.hash;
  11466. if ( hash.directionalLength !== directionalLength ||
  11467. hash.pointLength !== pointLength ||
  11468. hash.spotLength !== spotLength ||
  11469. hash.rectAreaLength !== rectAreaLength ||
  11470. hash.hemiLength !== hemiLength ||
  11471. hash.numDirectionalShadows !== numDirectionalShadows ||
  11472. hash.numPointShadows !== numPointShadows ||
  11473. hash.numSpotShadows !== numSpotShadows ) {
  11474. state.directional.length = directionalLength;
  11475. state.spot.length = spotLength;
  11476. state.rectArea.length = rectAreaLength;
  11477. state.point.length = pointLength;
  11478. state.hemi.length = hemiLength;
  11479. state.directionalShadowMap.length = numDirectionalShadows;
  11480. state.pointShadowMap.length = numPointShadows;
  11481. state.spotShadowMap.length = numSpotShadows;
  11482. state.directionalShadowMatrix.length = numDirectionalShadows;
  11483. state.pointShadowMatrix.length = numPointShadows;
  11484. state.spotShadowMatrix.length = numSpotShadows;
  11485. hash.directionalLength = directionalLength;
  11486. hash.pointLength = pointLength;
  11487. hash.spotLength = spotLength;
  11488. hash.rectAreaLength = rectAreaLength;
  11489. hash.hemiLength = hemiLength;
  11490. hash.numDirectionalShadows = numDirectionalShadows;
  11491. hash.numPointShadows = numPointShadows;
  11492. hash.numSpotShadows = numSpotShadows;
  11493. state.version = nextVersion ++;
  11494. }
  11495. }
  11496. return {
  11497. setup: setup,
  11498. state: state
  11499. };
  11500. }
  11501. /**
  11502. * @author Mugen87 / https://github.com/Mugen87
  11503. */
  11504. function WebGLRenderState() {
  11505. var lights = new WebGLLights();
  11506. var lightsArray = [];
  11507. var shadowsArray = [];
  11508. function init() {
  11509. lightsArray.length = 0;
  11510. shadowsArray.length = 0;
  11511. }
  11512. function pushLight( light ) {
  11513. lightsArray.push( light );
  11514. }
  11515. function pushShadow( shadowLight ) {
  11516. shadowsArray.push( shadowLight );
  11517. }
  11518. function setupLights( camera ) {
  11519. lights.setup( lightsArray, shadowsArray, camera );
  11520. }
  11521. var state = {
  11522. lightsArray: lightsArray,
  11523. shadowsArray: shadowsArray,
  11524. lights: lights
  11525. };
  11526. return {
  11527. init: init,
  11528. state: state,
  11529. setupLights: setupLights,
  11530. pushLight: pushLight,
  11531. pushShadow: pushShadow
  11532. };
  11533. }
  11534. function WebGLRenderStates() {
  11535. var renderStates = {};
  11536. function onSceneDispose( event ) {
  11537. var scene = event.target;
  11538. scene.removeEventListener( 'dispose', onSceneDispose );
  11539. delete renderStates[ scene.id ];
  11540. }
  11541. function get( scene, camera ) {
  11542. var renderState;
  11543. if ( renderStates[ scene.id ] === undefined ) {
  11544. renderState = new WebGLRenderState();
  11545. renderStates[ scene.id ] = {};
  11546. renderStates[ scene.id ][ camera.id ] = renderState;
  11547. scene.addEventListener( 'dispose', onSceneDispose );
  11548. } else {
  11549. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11550. renderState = new WebGLRenderState();
  11551. renderStates[ scene.id ][ camera.id ] = renderState;
  11552. } else {
  11553. renderState = renderStates[ scene.id ][ camera.id ];
  11554. }
  11555. }
  11556. return renderState;
  11557. }
  11558. function dispose() {
  11559. renderStates = {};
  11560. }
  11561. return {
  11562. get: get,
  11563. dispose: dispose
  11564. };
  11565. }
  11566. /**
  11567. * @author mrdoob / http://mrdoob.com/
  11568. * @author alteredq / http://alteredqualia.com/
  11569. * @author bhouston / https://clara.io
  11570. * @author WestLangley / http://github.com/WestLangley
  11571. *
  11572. * parameters = {
  11573. *
  11574. * opacity: <float>,
  11575. *
  11576. * map: new THREE.Texture( <Image> ),
  11577. *
  11578. * alphaMap: new THREE.Texture( <Image> ),
  11579. *
  11580. * displacementMap: new THREE.Texture( <Image> ),
  11581. * displacementScale: <float>,
  11582. * displacementBias: <float>,
  11583. *
  11584. * wireframe: <boolean>,
  11585. * wireframeLinewidth: <float>
  11586. * }
  11587. */
  11588. function MeshDepthMaterial( parameters ) {
  11589. Material.call( this );
  11590. this.type = 'MeshDepthMaterial';
  11591. this.depthPacking = BasicDepthPacking;
  11592. this.skinning = false;
  11593. this.morphTargets = false;
  11594. this.map = null;
  11595. this.alphaMap = null;
  11596. this.displacementMap = null;
  11597. this.displacementScale = 1;
  11598. this.displacementBias = 0;
  11599. this.wireframe = false;
  11600. this.wireframeLinewidth = 1;
  11601. this.fog = false;
  11602. this.lights = false;
  11603. this.setValues( parameters );
  11604. }
  11605. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11606. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11607. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11608. MeshDepthMaterial.prototype.copy = function ( source ) {
  11609. Material.prototype.copy.call( this, source );
  11610. this.depthPacking = source.depthPacking;
  11611. this.skinning = source.skinning;
  11612. this.morphTargets = source.morphTargets;
  11613. this.map = source.map;
  11614. this.alphaMap = source.alphaMap;
  11615. this.displacementMap = source.displacementMap;
  11616. this.displacementScale = source.displacementScale;
  11617. this.displacementBias = source.displacementBias;
  11618. this.wireframe = source.wireframe;
  11619. this.wireframeLinewidth = source.wireframeLinewidth;
  11620. return this;
  11621. };
  11622. /**
  11623. * @author WestLangley / http://github.com/WestLangley
  11624. *
  11625. * parameters = {
  11626. *
  11627. * referencePosition: <float>,
  11628. * nearDistance: <float>,
  11629. * farDistance: <float>,
  11630. *
  11631. * skinning: <bool>,
  11632. * morphTargets: <bool>,
  11633. *
  11634. * map: new THREE.Texture( <Image> ),
  11635. *
  11636. * alphaMap: new THREE.Texture( <Image> ),
  11637. *
  11638. * displacementMap: new THREE.Texture( <Image> ),
  11639. * displacementScale: <float>,
  11640. * displacementBias: <float>
  11641. *
  11642. * }
  11643. */
  11644. function MeshDistanceMaterial( parameters ) {
  11645. Material.call( this );
  11646. this.type = 'MeshDistanceMaterial';
  11647. this.referencePosition = new Vector3();
  11648. this.nearDistance = 1;
  11649. this.farDistance = 1000;
  11650. this.skinning = false;
  11651. this.morphTargets = false;
  11652. this.map = null;
  11653. this.alphaMap = null;
  11654. this.displacementMap = null;
  11655. this.displacementScale = 1;
  11656. this.displacementBias = 0;
  11657. this.fog = false;
  11658. this.lights = false;
  11659. this.setValues( parameters );
  11660. }
  11661. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11662. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11663. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11664. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11665. Material.prototype.copy.call( this, source );
  11666. this.referencePosition.copy( source.referencePosition );
  11667. this.nearDistance = source.nearDistance;
  11668. this.farDistance = source.farDistance;
  11669. this.skinning = source.skinning;
  11670. this.morphTargets = source.morphTargets;
  11671. this.map = source.map;
  11672. this.alphaMap = source.alphaMap;
  11673. this.displacementMap = source.displacementMap;
  11674. this.displacementScale = source.displacementScale;
  11675. this.displacementBias = source.displacementBias;
  11676. return this;
  11677. };
  11678. /**
  11679. * @author alteredq / http://alteredqualia.com/
  11680. * @author mrdoob / http://mrdoob.com/
  11681. */
  11682. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11683. var _frustum = new Frustum(),
  11684. _projScreenMatrix = new Matrix4(),
  11685. _shadowMapSize = new Vector2(),
  11686. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11687. _lookTarget = new Vector3(),
  11688. _lightPositionWorld = new Vector3(),
  11689. _MorphingFlag = 1,
  11690. _SkinningFlag = 2,
  11691. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11692. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11693. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11694. _materialCache = {};
  11695. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11696. var cubeDirections = [
  11697. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11698. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11699. ];
  11700. var cubeUps = [
  11701. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11702. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11703. ];
  11704. var cube2DViewPorts = [
  11705. new Vector4(), new Vector4(), new Vector4(),
  11706. new Vector4(), new Vector4(), new Vector4()
  11707. ];
  11708. // init
  11709. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11710. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11711. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11712. var depthMaterial = new MeshDepthMaterial( {
  11713. depthPacking: RGBADepthPacking,
  11714. morphTargets: useMorphing,
  11715. skinning: useSkinning
  11716. } );
  11717. _depthMaterials[ i ] = depthMaterial;
  11718. //
  11719. var distanceMaterial = new MeshDistanceMaterial( {
  11720. morphTargets: useMorphing,
  11721. skinning: useSkinning
  11722. } );
  11723. _distanceMaterials[ i ] = distanceMaterial;
  11724. }
  11725. //
  11726. var scope = this;
  11727. this.enabled = false;
  11728. this.autoUpdate = true;
  11729. this.needsUpdate = false;
  11730. this.type = PCFShadowMap;
  11731. this.render = function ( lights, scene, camera ) {
  11732. if ( scope.enabled === false ) return;
  11733. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11734. if ( lights.length === 0 ) return;
  11735. var currentRenderTarget = _renderer.getRenderTarget();
  11736. var activeCubeFace = _renderer.getActiveCubeFace();
  11737. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11738. var _state = _renderer.state;
  11739. // Set GL state for depth map.
  11740. _state.setBlending( NoBlending );
  11741. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11742. _state.buffers.depth.setTest( true );
  11743. _state.setScissorTest( false );
  11744. // render depth map
  11745. var faceCount;
  11746. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11747. var light = lights[ i ];
  11748. var shadow = light.shadow;
  11749. var isPointLight = light && light.isPointLight;
  11750. if ( shadow === undefined ) {
  11751. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11752. continue;
  11753. }
  11754. var shadowCamera = shadow.camera;
  11755. _shadowMapSize.copy( shadow.mapSize );
  11756. _shadowMapSize.min( _maxShadowMapSize );
  11757. if ( isPointLight ) {
  11758. var vpWidth = _shadowMapSize.x;
  11759. var vpHeight = _shadowMapSize.y;
  11760. // These viewports map a cube-map onto a 2D texture with the
  11761. // following orientation:
  11762. //
  11763. // xzXZ
  11764. // y Y
  11765. //
  11766. // X - Positive x direction
  11767. // x - Negative x direction
  11768. // Y - Positive y direction
  11769. // y - Negative y direction
  11770. // Z - Positive z direction
  11771. // z - Negative z direction
  11772. // positive X
  11773. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11774. // negative X
  11775. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11776. // positive Z
  11777. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11778. // negative Z
  11779. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11780. // positive Y
  11781. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11782. // negative Y
  11783. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11784. _shadowMapSize.x *= 4.0;
  11785. _shadowMapSize.y *= 2.0;
  11786. }
  11787. if ( shadow.map === null ) {
  11788. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11789. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11790. shadow.map.texture.name = light.name + ".shadowMap";
  11791. shadowCamera.updateProjectionMatrix();
  11792. }
  11793. if ( shadow.isSpotLightShadow ) {
  11794. shadow.update( light );
  11795. }
  11796. var shadowMap = shadow.map;
  11797. var shadowMatrix = shadow.matrix;
  11798. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11799. shadowCamera.position.copy( _lightPositionWorld );
  11800. if ( isPointLight ) {
  11801. faceCount = 6;
  11802. // for point lights we set the shadow matrix to be a translation-only matrix
  11803. // equal to inverse of the light's position
  11804. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11805. } else {
  11806. faceCount = 1;
  11807. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11808. shadowCamera.lookAt( _lookTarget );
  11809. shadowCamera.updateMatrixWorld();
  11810. // compute shadow matrix
  11811. shadowMatrix.set(
  11812. 0.5, 0.0, 0.0, 0.5,
  11813. 0.0, 0.5, 0.0, 0.5,
  11814. 0.0, 0.0, 0.5, 0.5,
  11815. 0.0, 0.0, 0.0, 1.0
  11816. );
  11817. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11818. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11819. }
  11820. _renderer.setRenderTarget( shadowMap );
  11821. _renderer.clear();
  11822. // render shadow map for each cube face (if omni-directional) or
  11823. // run a single pass if not
  11824. for ( var face = 0; face < faceCount; face ++ ) {
  11825. if ( isPointLight ) {
  11826. _lookTarget.copy( shadowCamera.position );
  11827. _lookTarget.add( cubeDirections[ face ] );
  11828. shadowCamera.up.copy( cubeUps[ face ] );
  11829. shadowCamera.lookAt( _lookTarget );
  11830. shadowCamera.updateMatrixWorld();
  11831. var vpDimensions = cube2DViewPorts[ face ];
  11832. _state.viewport( vpDimensions );
  11833. }
  11834. // update camera matrices and frustum
  11835. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11836. _frustum.setFromMatrix( _projScreenMatrix );
  11837. // set object matrices & frustum culling
  11838. renderObject( scene, camera, shadowCamera, isPointLight );
  11839. }
  11840. }
  11841. scope.needsUpdate = false;
  11842. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11843. };
  11844. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11845. var geometry = object.geometry;
  11846. var result = null;
  11847. var materialVariants = _depthMaterials;
  11848. var customMaterial = object.customDepthMaterial;
  11849. if ( isPointLight ) {
  11850. materialVariants = _distanceMaterials;
  11851. customMaterial = object.customDistanceMaterial;
  11852. }
  11853. if ( ! customMaterial ) {
  11854. var useMorphing = false;
  11855. if ( material.morphTargets ) {
  11856. if ( geometry && geometry.isBufferGeometry ) {
  11857. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11858. } else if ( geometry && geometry.isGeometry ) {
  11859. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11860. }
  11861. }
  11862. if ( object.isSkinnedMesh && material.skinning === false ) {
  11863. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11864. }
  11865. var useSkinning = object.isSkinnedMesh && material.skinning;
  11866. var variantIndex = 0;
  11867. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11868. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11869. result = materialVariants[ variantIndex ];
  11870. } else {
  11871. result = customMaterial;
  11872. }
  11873. if ( _renderer.localClippingEnabled &&
  11874. material.clipShadows === true &&
  11875. material.clippingPlanes.length !== 0 ) {
  11876. // in this case we need a unique material instance reflecting the
  11877. // appropriate state
  11878. var keyA = result.uuid, keyB = material.uuid;
  11879. var materialsForVariant = _materialCache[ keyA ];
  11880. if ( materialsForVariant === undefined ) {
  11881. materialsForVariant = {};
  11882. _materialCache[ keyA ] = materialsForVariant;
  11883. }
  11884. var cachedMaterial = materialsForVariant[ keyB ];
  11885. if ( cachedMaterial === undefined ) {
  11886. cachedMaterial = result.clone();
  11887. materialsForVariant[ keyB ] = cachedMaterial;
  11888. }
  11889. result = cachedMaterial;
  11890. }
  11891. result.visible = material.visible;
  11892. result.wireframe = material.wireframe;
  11893. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11894. result.clipShadows = material.clipShadows;
  11895. result.clippingPlanes = material.clippingPlanes;
  11896. result.clipIntersection = material.clipIntersection;
  11897. result.wireframeLinewidth = material.wireframeLinewidth;
  11898. result.linewidth = material.linewidth;
  11899. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11900. result.referencePosition.copy( lightPositionWorld );
  11901. result.nearDistance = shadowCameraNear;
  11902. result.farDistance = shadowCameraFar;
  11903. }
  11904. return result;
  11905. }
  11906. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11907. if ( object.visible === false ) return;
  11908. var visible = object.layers.test( camera.layers );
  11909. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11910. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11911. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11912. var geometry = _objects.update( object );
  11913. var material = object.material;
  11914. if ( Array.isArray( material ) ) {
  11915. var groups = geometry.groups;
  11916. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11917. var group = groups[ k ];
  11918. var groupMaterial = material[ group.materialIndex ];
  11919. if ( groupMaterial && groupMaterial.visible ) {
  11920. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11921. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11922. }
  11923. }
  11924. } else if ( material.visible ) {
  11925. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11926. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11927. }
  11928. }
  11929. }
  11930. var children = object.children;
  11931. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11932. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11933. }
  11934. }
  11935. }
  11936. /**
  11937. * @author mrdoob / http://mrdoob.com/
  11938. */
  11939. function WebGLState( gl, extensions, utils, capabilities ) {
  11940. function ColorBuffer() {
  11941. var locked = false;
  11942. var color = new Vector4();
  11943. var currentColorMask = null;
  11944. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11945. return {
  11946. setMask: function ( colorMask ) {
  11947. if ( currentColorMask !== colorMask && ! locked ) {
  11948. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11949. currentColorMask = colorMask;
  11950. }
  11951. },
  11952. setLocked: function ( lock ) {
  11953. locked = lock;
  11954. },
  11955. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11956. if ( premultipliedAlpha === true ) {
  11957. r *= a; g *= a; b *= a;
  11958. }
  11959. color.set( r, g, b, a );
  11960. if ( currentColorClear.equals( color ) === false ) {
  11961. gl.clearColor( r, g, b, a );
  11962. currentColorClear.copy( color );
  11963. }
  11964. },
  11965. reset: function () {
  11966. locked = false;
  11967. currentColorMask = null;
  11968. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11969. }
  11970. };
  11971. }
  11972. function DepthBuffer() {
  11973. var locked = false;
  11974. var currentDepthMask = null;
  11975. var currentDepthFunc = null;
  11976. var currentDepthClear = null;
  11977. return {
  11978. setTest: function ( depthTest ) {
  11979. if ( depthTest ) {
  11980. enable( 2929 );
  11981. } else {
  11982. disable( 2929 );
  11983. }
  11984. },
  11985. setMask: function ( depthMask ) {
  11986. if ( currentDepthMask !== depthMask && ! locked ) {
  11987. gl.depthMask( depthMask );
  11988. currentDepthMask = depthMask;
  11989. }
  11990. },
  11991. setFunc: function ( depthFunc ) {
  11992. if ( currentDepthFunc !== depthFunc ) {
  11993. if ( depthFunc ) {
  11994. switch ( depthFunc ) {
  11995. case NeverDepth:
  11996. gl.depthFunc( 512 );
  11997. break;
  11998. case AlwaysDepth:
  11999. gl.depthFunc( 519 );
  12000. break;
  12001. case LessDepth:
  12002. gl.depthFunc( 513 );
  12003. break;
  12004. case LessEqualDepth:
  12005. gl.depthFunc( 515 );
  12006. break;
  12007. case EqualDepth:
  12008. gl.depthFunc( 514 );
  12009. break;
  12010. case GreaterEqualDepth:
  12011. gl.depthFunc( 518 );
  12012. break;
  12013. case GreaterDepth:
  12014. gl.depthFunc( 516 );
  12015. break;
  12016. case NotEqualDepth:
  12017. gl.depthFunc( 517 );
  12018. break;
  12019. default:
  12020. gl.depthFunc( 515 );
  12021. }
  12022. } else {
  12023. gl.depthFunc( 515 );
  12024. }
  12025. currentDepthFunc = depthFunc;
  12026. }
  12027. },
  12028. setLocked: function ( lock ) {
  12029. locked = lock;
  12030. },
  12031. setClear: function ( depth ) {
  12032. if ( currentDepthClear !== depth ) {
  12033. gl.clearDepth( depth );
  12034. currentDepthClear = depth;
  12035. }
  12036. },
  12037. reset: function () {
  12038. locked = false;
  12039. currentDepthMask = null;
  12040. currentDepthFunc = null;
  12041. currentDepthClear = null;
  12042. }
  12043. };
  12044. }
  12045. function StencilBuffer() {
  12046. var locked = false;
  12047. var currentStencilMask = null;
  12048. var currentStencilFunc = null;
  12049. var currentStencilRef = null;
  12050. var currentStencilFuncMask = null;
  12051. var currentStencilFail = null;
  12052. var currentStencilZFail = null;
  12053. var currentStencilZPass = null;
  12054. var currentStencilClear = null;
  12055. return {
  12056. setTest: function ( stencilTest ) {
  12057. if ( ! locked ) {
  12058. if ( stencilTest ) {
  12059. enable( 2960 );
  12060. } else {
  12061. disable( 2960 );
  12062. }
  12063. }
  12064. },
  12065. setMask: function ( stencilMask ) {
  12066. if ( currentStencilMask !== stencilMask && ! locked ) {
  12067. gl.stencilMask( stencilMask );
  12068. currentStencilMask = stencilMask;
  12069. }
  12070. },
  12071. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12072. if ( currentStencilFunc !== stencilFunc ||
  12073. currentStencilRef !== stencilRef ||
  12074. currentStencilFuncMask !== stencilMask ) {
  12075. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12076. currentStencilFunc = stencilFunc;
  12077. currentStencilRef = stencilRef;
  12078. currentStencilFuncMask = stencilMask;
  12079. }
  12080. },
  12081. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12082. if ( currentStencilFail !== stencilFail ||
  12083. currentStencilZFail !== stencilZFail ||
  12084. currentStencilZPass !== stencilZPass ) {
  12085. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12086. currentStencilFail = stencilFail;
  12087. currentStencilZFail = stencilZFail;
  12088. currentStencilZPass = stencilZPass;
  12089. }
  12090. },
  12091. setLocked: function ( lock ) {
  12092. locked = lock;
  12093. },
  12094. setClear: function ( stencil ) {
  12095. if ( currentStencilClear !== stencil ) {
  12096. gl.clearStencil( stencil );
  12097. currentStencilClear = stencil;
  12098. }
  12099. },
  12100. reset: function () {
  12101. locked = false;
  12102. currentStencilMask = null;
  12103. currentStencilFunc = null;
  12104. currentStencilRef = null;
  12105. currentStencilFuncMask = null;
  12106. currentStencilFail = null;
  12107. currentStencilZFail = null;
  12108. currentStencilZPass = null;
  12109. currentStencilClear = null;
  12110. }
  12111. };
  12112. }
  12113. //
  12114. var colorBuffer = new ColorBuffer();
  12115. var depthBuffer = new DepthBuffer();
  12116. var stencilBuffer = new StencilBuffer();
  12117. var maxVertexAttributes = gl.getParameter( 34921 );
  12118. var newAttributes = new Uint8Array( maxVertexAttributes );
  12119. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  12120. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  12121. var enabledCapabilities = {};
  12122. var compressedTextureFormats = null;
  12123. var currentProgram = null;
  12124. var currentBlendingEnabled = null;
  12125. var currentBlending = null;
  12126. var currentBlendEquation = null;
  12127. var currentBlendSrc = null;
  12128. var currentBlendDst = null;
  12129. var currentBlendEquationAlpha = null;
  12130. var currentBlendSrcAlpha = null;
  12131. var currentBlendDstAlpha = null;
  12132. var currentPremultipledAlpha = false;
  12133. var currentFlipSided = null;
  12134. var currentCullFace = null;
  12135. var currentLineWidth = null;
  12136. var currentPolygonOffsetFactor = null;
  12137. var currentPolygonOffsetUnits = null;
  12138. var maxTextures = gl.getParameter( 35661 );
  12139. var lineWidthAvailable = false;
  12140. var version = 0;
  12141. var glVersion = gl.getParameter( 7938 );
  12142. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12143. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12144. lineWidthAvailable = ( version >= 1.0 );
  12145. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12146. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12147. lineWidthAvailable = ( version >= 2.0 );
  12148. }
  12149. var currentTextureSlot = null;
  12150. var currentBoundTextures = {};
  12151. var currentScissor = new Vector4();
  12152. var currentViewport = new Vector4();
  12153. function createTexture( type, target, count ) {
  12154. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12155. var texture = gl.createTexture();
  12156. gl.bindTexture( type, texture );
  12157. gl.texParameteri( type, 10241, 9728 );
  12158. gl.texParameteri( type, 10240, 9728 );
  12159. for ( var i = 0; i < count; i ++ ) {
  12160. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12161. }
  12162. return texture;
  12163. }
  12164. var emptyTextures = {};
  12165. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12166. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12167. // init
  12168. colorBuffer.setClear( 0, 0, 0, 1 );
  12169. depthBuffer.setClear( 1 );
  12170. stencilBuffer.setClear( 0 );
  12171. enable( 2929 );
  12172. depthBuffer.setFunc( LessEqualDepth );
  12173. setFlipSided( false );
  12174. setCullFace( CullFaceBack );
  12175. enable( 2884 );
  12176. setBlending( NoBlending );
  12177. //
  12178. function initAttributes() {
  12179. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  12180. newAttributes[ i ] = 0;
  12181. }
  12182. }
  12183. function enableAttribute( attribute ) {
  12184. enableAttributeAndDivisor( attribute, 0 );
  12185. }
  12186. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  12187. newAttributes[ attribute ] = 1;
  12188. if ( enabledAttributes[ attribute ] === 0 ) {
  12189. gl.enableVertexAttribArray( attribute );
  12190. enabledAttributes[ attribute ] = 1;
  12191. }
  12192. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  12193. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  12194. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  12195. attributeDivisors[ attribute ] = meshPerAttribute;
  12196. }
  12197. }
  12198. function disableUnusedAttributes() {
  12199. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  12200. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  12201. gl.disableVertexAttribArray( i );
  12202. enabledAttributes[ i ] = 0;
  12203. }
  12204. }
  12205. }
  12206. function enable( id ) {
  12207. if ( enabledCapabilities[ id ] !== true ) {
  12208. gl.enable( id );
  12209. enabledCapabilities[ id ] = true;
  12210. }
  12211. }
  12212. function disable( id ) {
  12213. if ( enabledCapabilities[ id ] !== false ) {
  12214. gl.disable( id );
  12215. enabledCapabilities[ id ] = false;
  12216. }
  12217. }
  12218. function getCompressedTextureFormats() {
  12219. if ( compressedTextureFormats === null ) {
  12220. compressedTextureFormats = [];
  12221. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  12222. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  12223. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  12224. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  12225. var formats = gl.getParameter( 34467 );
  12226. for ( var i = 0; i < formats.length; i ++ ) {
  12227. compressedTextureFormats.push( formats[ i ] );
  12228. }
  12229. }
  12230. }
  12231. return compressedTextureFormats;
  12232. }
  12233. function useProgram( program ) {
  12234. if ( currentProgram !== program ) {
  12235. gl.useProgram( program );
  12236. currentProgram = program;
  12237. return true;
  12238. }
  12239. return false;
  12240. }
  12241. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12242. if ( blending === NoBlending ) {
  12243. if ( currentBlendingEnabled ) {
  12244. disable( 3042 );
  12245. currentBlendingEnabled = false;
  12246. }
  12247. return;
  12248. }
  12249. if ( ! currentBlendingEnabled ) {
  12250. enable( 3042 );
  12251. currentBlendingEnabled = true;
  12252. }
  12253. if ( blending !== CustomBlending ) {
  12254. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12255. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12256. gl.blendEquation( 32774 );
  12257. currentBlendEquation = AddEquation;
  12258. currentBlendEquationAlpha = AddEquation;
  12259. }
  12260. if ( premultipliedAlpha ) {
  12261. switch ( blending ) {
  12262. case NormalBlending:
  12263. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12264. break;
  12265. case AdditiveBlending:
  12266. gl.blendFunc( 1, 1 );
  12267. break;
  12268. case SubtractiveBlending:
  12269. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12270. break;
  12271. case MultiplyBlending:
  12272. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12273. break;
  12274. default:
  12275. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12276. break;
  12277. }
  12278. } else {
  12279. switch ( blending ) {
  12280. case NormalBlending:
  12281. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12282. break;
  12283. case AdditiveBlending:
  12284. gl.blendFunc( 770, 1 );
  12285. break;
  12286. case SubtractiveBlending:
  12287. gl.blendFunc( 0, 769 );
  12288. break;
  12289. case MultiplyBlending:
  12290. gl.blendFunc( 0, 768 );
  12291. break;
  12292. default:
  12293. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12294. break;
  12295. }
  12296. }
  12297. currentBlendSrc = null;
  12298. currentBlendDst = null;
  12299. currentBlendSrcAlpha = null;
  12300. currentBlendDstAlpha = null;
  12301. currentBlending = blending;
  12302. currentPremultipledAlpha = premultipliedAlpha;
  12303. }
  12304. return;
  12305. }
  12306. // custom blending
  12307. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12308. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12309. blendDstAlpha = blendDstAlpha || blendDst;
  12310. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12311. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  12312. currentBlendEquation = blendEquation;
  12313. currentBlendEquationAlpha = blendEquationAlpha;
  12314. }
  12315. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12316. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  12317. currentBlendSrc = blendSrc;
  12318. currentBlendDst = blendDst;
  12319. currentBlendSrcAlpha = blendSrcAlpha;
  12320. currentBlendDstAlpha = blendDstAlpha;
  12321. }
  12322. currentBlending = blending;
  12323. currentPremultipledAlpha = null;
  12324. }
  12325. function setMaterial( material, frontFaceCW ) {
  12326. material.side === DoubleSide
  12327. ? disable( 2884 )
  12328. : enable( 2884 );
  12329. var flipSided = ( material.side === BackSide );
  12330. if ( frontFaceCW ) flipSided = ! flipSided;
  12331. setFlipSided( flipSided );
  12332. ( material.blending === NormalBlending && material.transparent === false )
  12333. ? setBlending( NoBlending )
  12334. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12335. depthBuffer.setFunc( material.depthFunc );
  12336. depthBuffer.setTest( material.depthTest );
  12337. depthBuffer.setMask( material.depthWrite );
  12338. colorBuffer.setMask( material.colorWrite );
  12339. var stencilWrite = material.stencilWrite;
  12340. stencilBuffer.setTest( stencilWrite );
  12341. if ( stencilWrite ) {
  12342. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilMask );
  12343. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12344. }
  12345. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12346. }
  12347. //
  12348. function setFlipSided( flipSided ) {
  12349. if ( currentFlipSided !== flipSided ) {
  12350. if ( flipSided ) {
  12351. gl.frontFace( 2304 );
  12352. } else {
  12353. gl.frontFace( 2305 );
  12354. }
  12355. currentFlipSided = flipSided;
  12356. }
  12357. }
  12358. function setCullFace( cullFace ) {
  12359. if ( cullFace !== CullFaceNone ) {
  12360. enable( 2884 );
  12361. if ( cullFace !== currentCullFace ) {
  12362. if ( cullFace === CullFaceBack ) {
  12363. gl.cullFace( 1029 );
  12364. } else if ( cullFace === CullFaceFront ) {
  12365. gl.cullFace( 1028 );
  12366. } else {
  12367. gl.cullFace( 1032 );
  12368. }
  12369. }
  12370. } else {
  12371. disable( 2884 );
  12372. }
  12373. currentCullFace = cullFace;
  12374. }
  12375. function setLineWidth( width ) {
  12376. if ( width !== currentLineWidth ) {
  12377. if ( lineWidthAvailable ) gl.lineWidth( width );
  12378. currentLineWidth = width;
  12379. }
  12380. }
  12381. function setPolygonOffset( polygonOffset, factor, units ) {
  12382. if ( polygonOffset ) {
  12383. enable( 32823 );
  12384. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12385. gl.polygonOffset( factor, units );
  12386. currentPolygonOffsetFactor = factor;
  12387. currentPolygonOffsetUnits = units;
  12388. }
  12389. } else {
  12390. disable( 32823 );
  12391. }
  12392. }
  12393. function setScissorTest( scissorTest ) {
  12394. if ( scissorTest ) {
  12395. enable( 3089 );
  12396. } else {
  12397. disable( 3089 );
  12398. }
  12399. }
  12400. // texture
  12401. function activeTexture( webglSlot ) {
  12402. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12403. if ( currentTextureSlot !== webglSlot ) {
  12404. gl.activeTexture( webglSlot );
  12405. currentTextureSlot = webglSlot;
  12406. }
  12407. }
  12408. function bindTexture( webglType, webglTexture ) {
  12409. if ( currentTextureSlot === null ) {
  12410. activeTexture();
  12411. }
  12412. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12413. if ( boundTexture === undefined ) {
  12414. boundTexture = { type: undefined, texture: undefined };
  12415. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12416. }
  12417. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12418. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12419. boundTexture.type = webglType;
  12420. boundTexture.texture = webglTexture;
  12421. }
  12422. }
  12423. function compressedTexImage2D() {
  12424. try {
  12425. gl.compressedTexImage2D.apply( gl, arguments );
  12426. } catch ( error ) {
  12427. console.error( 'THREE.WebGLState:', error );
  12428. }
  12429. }
  12430. function texImage2D() {
  12431. try {
  12432. gl.texImage2D.apply( gl, arguments );
  12433. } catch ( error ) {
  12434. console.error( 'THREE.WebGLState:', error );
  12435. }
  12436. }
  12437. function texImage3D() {
  12438. try {
  12439. gl.texImage3D.apply( gl, arguments );
  12440. } catch ( error ) {
  12441. console.error( 'THREE.WebGLState:', error );
  12442. }
  12443. }
  12444. //
  12445. function scissor( scissor ) {
  12446. if ( currentScissor.equals( scissor ) === false ) {
  12447. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12448. currentScissor.copy( scissor );
  12449. }
  12450. }
  12451. function viewport( viewport ) {
  12452. if ( currentViewport.equals( viewport ) === false ) {
  12453. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12454. currentViewport.copy( viewport );
  12455. }
  12456. }
  12457. //
  12458. function reset() {
  12459. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12460. if ( enabledAttributes[ i ] === 1 ) {
  12461. gl.disableVertexAttribArray( i );
  12462. enabledAttributes[ i ] = 0;
  12463. }
  12464. }
  12465. enabledCapabilities = {};
  12466. compressedTextureFormats = null;
  12467. currentTextureSlot = null;
  12468. currentBoundTextures = {};
  12469. currentProgram = null;
  12470. currentBlending = null;
  12471. currentFlipSided = null;
  12472. currentCullFace = null;
  12473. colorBuffer.reset();
  12474. depthBuffer.reset();
  12475. stencilBuffer.reset();
  12476. }
  12477. return {
  12478. buffers: {
  12479. color: colorBuffer,
  12480. depth: depthBuffer,
  12481. stencil: stencilBuffer
  12482. },
  12483. initAttributes: initAttributes,
  12484. enableAttribute: enableAttribute,
  12485. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12486. disableUnusedAttributes: disableUnusedAttributes,
  12487. enable: enable,
  12488. disable: disable,
  12489. getCompressedTextureFormats: getCompressedTextureFormats,
  12490. useProgram: useProgram,
  12491. setBlending: setBlending,
  12492. setMaterial: setMaterial,
  12493. setFlipSided: setFlipSided,
  12494. setCullFace: setCullFace,
  12495. setLineWidth: setLineWidth,
  12496. setPolygonOffset: setPolygonOffset,
  12497. setScissorTest: setScissorTest,
  12498. activeTexture: activeTexture,
  12499. bindTexture: bindTexture,
  12500. compressedTexImage2D: compressedTexImage2D,
  12501. texImage2D: texImage2D,
  12502. texImage3D: texImage3D,
  12503. scissor: scissor,
  12504. viewport: viewport,
  12505. reset: reset
  12506. };
  12507. }
  12508. /**
  12509. * @author mrdoob / http://mrdoob.com/
  12510. */
  12511. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12512. var _videoTextures = {};
  12513. var _canvas;
  12514. //
  12515. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12516. function createCanvas( width, height ) {
  12517. // Use OffscreenCanvas when available. Specially needed in web workers
  12518. return useOffscreenCanvas ?
  12519. new OffscreenCanvas( width, height ) :
  12520. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12521. }
  12522. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12523. var scale = 1;
  12524. // handle case if texture exceeds max size
  12525. if ( image.width > maxSize || image.height > maxSize ) {
  12526. scale = maxSize / Math.max( image.width, image.height );
  12527. }
  12528. // only perform resize if necessary
  12529. if ( scale < 1 || needsPowerOfTwo === true ) {
  12530. // only perform resize for certain image types
  12531. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12532. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12533. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12534. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12535. var width = floor( scale * image.width );
  12536. var height = floor( scale * image.height );
  12537. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12538. // cube textures can't reuse the same canvas
  12539. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12540. canvas.width = width;
  12541. canvas.height = height;
  12542. var context = canvas.getContext( '2d' );
  12543. context.drawImage( image, 0, 0, width, height );
  12544. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12545. return canvas;
  12546. } else {
  12547. if ( 'data' in image ) {
  12548. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12549. }
  12550. return image;
  12551. }
  12552. }
  12553. return image;
  12554. }
  12555. function isPowerOfTwo( image ) {
  12556. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12557. }
  12558. function textureNeedsPowerOfTwo( texture ) {
  12559. if ( capabilities.isWebGL2 ) return false;
  12560. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12561. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12562. }
  12563. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12564. return texture.generateMipmaps && supportsMips &&
  12565. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12566. }
  12567. function generateMipmap( target, texture, width, height ) {
  12568. _gl.generateMipmap( target );
  12569. var textureProperties = properties.get( texture );
  12570. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12571. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12572. }
  12573. function getInternalFormat( glFormat, glType ) {
  12574. if ( ! capabilities.isWebGL2 ) return glFormat;
  12575. var internalFormat = glFormat;
  12576. if ( glFormat === 6403 ) {
  12577. if ( glType === 5126 ) internalFormat = 33326;
  12578. if ( glType === 5131 ) internalFormat = 33325;
  12579. if ( glType === 5121 ) internalFormat = 33321;
  12580. }
  12581. if ( glFormat === 6407 ) {
  12582. if ( glType === 5126 ) internalFormat = 34837;
  12583. if ( glType === 5131 ) internalFormat = 34843;
  12584. if ( glType === 5121 ) internalFormat = 32849;
  12585. }
  12586. if ( glFormat === 6408 ) {
  12587. if ( glType === 5126 ) internalFormat = 34836;
  12588. if ( glType === 5131 ) internalFormat = 34842;
  12589. if ( glType === 5121 ) internalFormat = 32856;
  12590. }
  12591. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12592. internalFormat === 34842 || internalFormat === 34836 ) {
  12593. extensions.get( 'EXT_color_buffer_float' );
  12594. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12595. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12596. }
  12597. return internalFormat;
  12598. }
  12599. // Fallback filters for non-power-of-2 textures
  12600. function filterFallback( f ) {
  12601. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12602. return 9728;
  12603. }
  12604. return 9729;
  12605. }
  12606. //
  12607. function onTextureDispose( event ) {
  12608. var texture = event.target;
  12609. texture.removeEventListener( 'dispose', onTextureDispose );
  12610. deallocateTexture( texture );
  12611. if ( texture.isVideoTexture ) {
  12612. delete _videoTextures[ texture.id ];
  12613. }
  12614. info.memory.textures --;
  12615. }
  12616. function onRenderTargetDispose( event ) {
  12617. var renderTarget = event.target;
  12618. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12619. deallocateRenderTarget( renderTarget );
  12620. info.memory.textures --;
  12621. }
  12622. //
  12623. function deallocateTexture( texture ) {
  12624. var textureProperties = properties.get( texture );
  12625. if ( textureProperties.__webglInit === undefined ) return;
  12626. _gl.deleteTexture( textureProperties.__webglTexture );
  12627. properties.remove( texture );
  12628. }
  12629. function deallocateRenderTarget( renderTarget ) {
  12630. var renderTargetProperties = properties.get( renderTarget );
  12631. var textureProperties = properties.get( renderTarget.texture );
  12632. if ( ! renderTarget ) return;
  12633. if ( textureProperties.__webglTexture !== undefined ) {
  12634. _gl.deleteTexture( textureProperties.__webglTexture );
  12635. }
  12636. if ( renderTarget.depthTexture ) {
  12637. renderTarget.depthTexture.dispose();
  12638. }
  12639. if ( renderTarget.isWebGLRenderTargetCube ) {
  12640. for ( var i = 0; i < 6; i ++ ) {
  12641. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12642. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12643. }
  12644. } else {
  12645. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12646. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12647. }
  12648. properties.remove( renderTarget.texture );
  12649. properties.remove( renderTarget );
  12650. }
  12651. //
  12652. var textureUnits = 0;
  12653. function resetTextureUnits() {
  12654. textureUnits = 0;
  12655. }
  12656. function allocateTextureUnit() {
  12657. var textureUnit = textureUnits;
  12658. if ( textureUnit >= capabilities.maxTextures ) {
  12659. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12660. }
  12661. textureUnits += 1;
  12662. return textureUnit;
  12663. }
  12664. //
  12665. function setTexture2D( texture, slot ) {
  12666. var textureProperties = properties.get( texture );
  12667. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12668. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12669. var image = texture.image;
  12670. if ( image === undefined ) {
  12671. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12672. } else if ( image.complete === false ) {
  12673. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12674. } else {
  12675. uploadTexture( textureProperties, texture, slot );
  12676. return;
  12677. }
  12678. }
  12679. state.activeTexture( 33984 + slot );
  12680. state.bindTexture( 3553, textureProperties.__webglTexture );
  12681. }
  12682. function setTexture2DArray( texture, slot ) {
  12683. var textureProperties = properties.get( texture );
  12684. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12685. uploadTexture( textureProperties, texture, slot );
  12686. return;
  12687. }
  12688. state.activeTexture( 33984 + slot );
  12689. state.bindTexture( 35866, textureProperties.__webglTexture );
  12690. }
  12691. function setTexture3D( texture, slot ) {
  12692. var textureProperties = properties.get( texture );
  12693. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12694. uploadTexture( textureProperties, texture, slot );
  12695. return;
  12696. }
  12697. state.activeTexture( 33984 + slot );
  12698. state.bindTexture( 32879, textureProperties.__webglTexture );
  12699. }
  12700. function setTextureCube( texture, slot ) {
  12701. var textureProperties = properties.get( texture );
  12702. if ( texture.image.length === 6 ) {
  12703. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12704. initTexture( textureProperties, texture );
  12705. state.activeTexture( 33984 + slot );
  12706. state.bindTexture( 34067, textureProperties.__webglTexture );
  12707. _gl.pixelStorei( 37440, texture.flipY );
  12708. var isCompressed = ( texture && texture.isCompressedTexture );
  12709. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12710. var cubeImage = [];
  12711. for ( var i = 0; i < 6; i ++ ) {
  12712. if ( ! isCompressed && ! isDataTexture ) {
  12713. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12714. } else {
  12715. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12716. }
  12717. }
  12718. var image = cubeImage[ 0 ],
  12719. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12720. glFormat = utils.convert( texture.format ),
  12721. glType = utils.convert( texture.type ),
  12722. glInternalFormat = getInternalFormat( glFormat, glType );
  12723. setTextureParameters( 34067, texture, supportsMips );
  12724. var mipmaps = texture.mipmaps;
  12725. for ( var i = 0; i < 6; i ++ ) {
  12726. if ( ! isCompressed ) {
  12727. if ( isDataTexture ) {
  12728. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12729. for ( var j = 0; j < mipmaps.length; ++ j ) {
  12730. var mipmap = mipmaps[ j ];
  12731. var image = mipmap.image[ i ].image;
  12732. state.texImage2D( 34069 + i, j + 1, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12733. }
  12734. } else {
  12735. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12736. for ( var j = 0; j < mipmaps.length; ++ j ) {
  12737. var mipmap = mipmaps[ j ];
  12738. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  12739. }
  12740. }
  12741. } else {
  12742. var mipmaps = cubeImage[ i ].mipmaps;
  12743. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12744. var mipmap = mipmaps[ j ];
  12745. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12746. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12747. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12748. } else {
  12749. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12750. }
  12751. } else {
  12752. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12753. }
  12754. }
  12755. }
  12756. }
  12757. textureProperties.__maxMipLevel = isCompressed ? mipmaps.length - 1 : mipmaps.length;
  12758. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12759. // We assume images for cube map have the same size.
  12760. generateMipmap( 34067, texture, image.width, image.height );
  12761. }
  12762. textureProperties.__version = texture.version;
  12763. if ( texture.onUpdate ) texture.onUpdate( texture );
  12764. } else {
  12765. state.activeTexture( 33984 + slot );
  12766. state.bindTexture( 34067, textureProperties.__webglTexture );
  12767. }
  12768. }
  12769. }
  12770. function setTextureCubeDynamic( texture, slot ) {
  12771. state.activeTexture( 33984 + slot );
  12772. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12773. }
  12774. function setTextureParameters( textureType, texture, supportsMips ) {
  12775. var extension;
  12776. if ( supportsMips ) {
  12777. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12778. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12779. if ( textureType === 32879 || textureType === 35866 ) {
  12780. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12781. }
  12782. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12783. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12784. } else {
  12785. _gl.texParameteri( textureType, 10242, 33071 );
  12786. _gl.texParameteri( textureType, 10243, 33071 );
  12787. if ( textureType === 32879 || textureType === 35866 ) {
  12788. _gl.texParameteri( textureType, 32882, 33071 );
  12789. }
  12790. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12791. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12792. }
  12793. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12794. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12795. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12796. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12797. }
  12798. }
  12799. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12800. if ( extension ) {
  12801. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12802. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12803. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12804. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12805. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12806. }
  12807. }
  12808. }
  12809. function initTexture( textureProperties, texture ) {
  12810. if ( textureProperties.__webglInit === undefined ) {
  12811. textureProperties.__webglInit = true;
  12812. texture.addEventListener( 'dispose', onTextureDispose );
  12813. textureProperties.__webglTexture = _gl.createTexture();
  12814. info.memory.textures ++;
  12815. }
  12816. }
  12817. function uploadTexture( textureProperties, texture, slot ) {
  12818. var textureType = 3553;
  12819. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12820. if ( texture.isDataTexture3D ) textureType = 32879;
  12821. initTexture( textureProperties, texture );
  12822. state.activeTexture( 33984 + slot );
  12823. state.bindTexture( textureType, textureProperties.__webglTexture );
  12824. _gl.pixelStorei( 37440, texture.flipY );
  12825. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12826. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12827. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12828. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12829. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12830. glFormat = utils.convert( texture.format ),
  12831. glType = utils.convert( texture.type ),
  12832. glInternalFormat = getInternalFormat( glFormat, glType );
  12833. setTextureParameters( textureType, texture, supportsMips );
  12834. var mipmap, mipmaps = texture.mipmaps;
  12835. if ( texture.isDepthTexture ) {
  12836. // populate depth texture with dummy data
  12837. glInternalFormat = 6402;
  12838. if ( texture.type === FloatType ) {
  12839. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12840. glInternalFormat = 36012;
  12841. } else if ( capabilities.isWebGL2 ) {
  12842. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12843. glInternalFormat = 33189;
  12844. }
  12845. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12846. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12847. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12848. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12849. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12850. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12851. texture.type = UnsignedShortType;
  12852. glType = utils.convert( texture.type );
  12853. }
  12854. }
  12855. // Depth stencil textures need the DEPTH_STENCIL internal format
  12856. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12857. if ( texture.format === DepthStencilFormat ) {
  12858. glInternalFormat = 34041;
  12859. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12860. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12861. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12862. if ( texture.type !== UnsignedInt248Type ) {
  12863. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12864. texture.type = UnsignedInt248Type;
  12865. glType = utils.convert( texture.type );
  12866. }
  12867. }
  12868. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12869. } else if ( texture.isDataTexture ) {
  12870. // use manually created mipmaps if available
  12871. // if there are no manual mipmaps
  12872. // set 0 level mipmap and then use GL to generate other mipmap levels
  12873. if ( mipmaps.length > 0 && supportsMips ) {
  12874. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12875. mipmap = mipmaps[ i ];
  12876. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12877. }
  12878. texture.generateMipmaps = false;
  12879. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12880. } else {
  12881. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12882. textureProperties.__maxMipLevel = 0;
  12883. }
  12884. } else if ( texture.isCompressedTexture ) {
  12885. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12886. mipmap = mipmaps[ i ];
  12887. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12888. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12889. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12890. } else {
  12891. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12892. }
  12893. } else {
  12894. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12895. }
  12896. }
  12897. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12898. } else if ( texture.isDataTexture2DArray ) {
  12899. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12900. textureProperties.__maxMipLevel = 0;
  12901. } else if ( texture.isDataTexture3D ) {
  12902. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12903. textureProperties.__maxMipLevel = 0;
  12904. } else {
  12905. // regular Texture (image, video, canvas)
  12906. // use manually created mipmaps if available
  12907. // if there are no manual mipmaps
  12908. // set 0 level mipmap and then use GL to generate other mipmap levels
  12909. if ( mipmaps.length > 0 && supportsMips ) {
  12910. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12911. mipmap = mipmaps[ i ];
  12912. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12913. }
  12914. texture.generateMipmaps = false;
  12915. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12916. } else {
  12917. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12918. textureProperties.__maxMipLevel = 0;
  12919. }
  12920. }
  12921. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12922. generateMipmap( 3553, texture, image.width, image.height );
  12923. }
  12924. textureProperties.__version = texture.version;
  12925. if ( texture.onUpdate ) texture.onUpdate( texture );
  12926. }
  12927. // Render targets
  12928. // Setup storage for target texture and bind it to correct framebuffer
  12929. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12930. var glFormat = utils.convert( renderTarget.texture.format );
  12931. var glType = utils.convert( renderTarget.texture.type );
  12932. var glInternalFormat = getInternalFormat( glFormat, glType );
  12933. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12934. _gl.bindFramebuffer( 36160, framebuffer );
  12935. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12936. _gl.bindFramebuffer( 36160, null );
  12937. }
  12938. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12939. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12940. _gl.bindRenderbuffer( 36161, renderbuffer );
  12941. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12942. if ( isMultisample ) {
  12943. var samples = getRenderTargetSamples( renderTarget );
  12944. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12945. } else {
  12946. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12947. }
  12948. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12949. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12950. if ( isMultisample ) {
  12951. var samples = getRenderTargetSamples( renderTarget );
  12952. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  12953. } else {
  12954. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12955. }
  12956. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12957. } else {
  12958. var glFormat = utils.convert( renderTarget.texture.format );
  12959. var glType = utils.convert( renderTarget.texture.type );
  12960. var glInternalFormat = getInternalFormat( glFormat, glType );
  12961. if ( isMultisample ) {
  12962. var samples = getRenderTargetSamples( renderTarget );
  12963. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12964. } else {
  12965. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12966. }
  12967. }
  12968. _gl.bindRenderbuffer( 36161, null );
  12969. }
  12970. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12971. function setupDepthTexture( framebuffer, renderTarget ) {
  12972. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12973. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12974. _gl.bindFramebuffer( 36160, framebuffer );
  12975. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12976. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12977. }
  12978. // upload an empty depth texture with framebuffer size
  12979. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12980. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12981. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12982. renderTarget.depthTexture.image.width = renderTarget.width;
  12983. renderTarget.depthTexture.image.height = renderTarget.height;
  12984. renderTarget.depthTexture.needsUpdate = true;
  12985. }
  12986. setTexture2D( renderTarget.depthTexture, 0 );
  12987. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12988. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12989. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12990. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12991. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12992. } else {
  12993. throw new Error( 'Unknown depthTexture format' );
  12994. }
  12995. }
  12996. // Setup GL resources for a non-texture depth buffer
  12997. function setupDepthRenderbuffer( renderTarget ) {
  12998. var renderTargetProperties = properties.get( renderTarget );
  12999. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13000. if ( renderTarget.depthTexture ) {
  13001. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13002. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13003. } else {
  13004. if ( isCube ) {
  13005. renderTargetProperties.__webglDepthbuffer = [];
  13006. for ( var i = 0; i < 6; i ++ ) {
  13007. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13008. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13009. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  13010. }
  13011. } else {
  13012. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13013. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13014. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  13015. }
  13016. }
  13017. _gl.bindFramebuffer( 36160, null );
  13018. }
  13019. // Set up GL resources for the render target
  13020. function setupRenderTarget( renderTarget ) {
  13021. var renderTargetProperties = properties.get( renderTarget );
  13022. var textureProperties = properties.get( renderTarget.texture );
  13023. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13024. textureProperties.__webglTexture = _gl.createTexture();
  13025. info.memory.textures ++;
  13026. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13027. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13028. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13029. // Setup framebuffer
  13030. if ( isCube ) {
  13031. renderTargetProperties.__webglFramebuffer = [];
  13032. for ( var i = 0; i < 6; i ++ ) {
  13033. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13034. }
  13035. } else {
  13036. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13037. if ( isMultisample ) {
  13038. if ( capabilities.isWebGL2 ) {
  13039. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13040. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13041. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13042. var glFormat = utils.convert( renderTarget.texture.format );
  13043. var glType = utils.convert( renderTarget.texture.type );
  13044. var glInternalFormat = getInternalFormat( glFormat, glType );
  13045. var samples = getRenderTargetSamples( renderTarget );
  13046. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13047. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13048. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13049. _gl.bindRenderbuffer( 36161, null );
  13050. if ( renderTarget.depthBuffer ) {
  13051. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13052. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13053. }
  13054. _gl.bindFramebuffer( 36160, null );
  13055. } else {
  13056. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13057. }
  13058. }
  13059. }
  13060. // Setup color buffer
  13061. if ( isCube ) {
  13062. state.bindTexture( 34067, textureProperties.__webglTexture );
  13063. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13064. for ( var i = 0; i < 6; i ++ ) {
  13065. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13066. }
  13067. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13068. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13069. }
  13070. state.bindTexture( 34067, null );
  13071. } else {
  13072. state.bindTexture( 3553, textureProperties.__webglTexture );
  13073. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13074. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13075. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13076. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13077. }
  13078. state.bindTexture( 3553, null );
  13079. }
  13080. // Setup depth and stencil buffers
  13081. if ( renderTarget.depthBuffer ) {
  13082. setupDepthRenderbuffer( renderTarget );
  13083. }
  13084. }
  13085. function updateRenderTargetMipmap( renderTarget ) {
  13086. var texture = renderTarget.texture;
  13087. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13088. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13089. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  13090. var webglTexture = properties.get( texture ).__webglTexture;
  13091. state.bindTexture( target, webglTexture );
  13092. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13093. state.bindTexture( target, null );
  13094. }
  13095. }
  13096. function updateMultisampleRenderTarget( renderTarget ) {
  13097. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13098. if ( capabilities.isWebGL2 ) {
  13099. var renderTargetProperties = properties.get( renderTarget );
  13100. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13101. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13102. var width = renderTarget.width;
  13103. var height = renderTarget.height;
  13104. var mask = 16384;
  13105. if ( renderTarget.depthBuffer ) mask |= 256;
  13106. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13107. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13108. } else {
  13109. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13110. }
  13111. }
  13112. }
  13113. function getRenderTargetSamples( renderTarget ) {
  13114. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13115. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  13116. }
  13117. function updateVideoTexture( texture ) {
  13118. var id = texture.id;
  13119. var frame = info.render.frame;
  13120. // Check the last frame we updated the VideoTexture
  13121. if ( _videoTextures[ id ] !== frame ) {
  13122. _videoTextures[ id ] = frame;
  13123. texture.update();
  13124. }
  13125. }
  13126. // backwards compatibility
  13127. var warnedTexture2D = false;
  13128. var warnedTextureCube = false;
  13129. function safeSetTexture2D( texture, slot ) {
  13130. if ( texture && texture.isWebGLRenderTarget ) {
  13131. if ( warnedTexture2D === false ) {
  13132. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13133. warnedTexture2D = true;
  13134. }
  13135. texture = texture.texture;
  13136. }
  13137. setTexture2D( texture, slot );
  13138. }
  13139. function safeSetTextureCube( texture, slot ) {
  13140. if ( texture && texture.isWebGLRenderTargetCube ) {
  13141. if ( warnedTextureCube === false ) {
  13142. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13143. warnedTextureCube = true;
  13144. }
  13145. texture = texture.texture;
  13146. }
  13147. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13148. // TODO: unify these code paths
  13149. if ( ( texture && texture.isCubeTexture ) ||
  13150. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13151. // CompressedTexture can have Array in image :/
  13152. // this function alone should take care of cube textures
  13153. setTextureCube( texture, slot );
  13154. } else {
  13155. // assumed: texture property of THREE.WebGLRenderTargetCube
  13156. setTextureCubeDynamic( texture, slot );
  13157. }
  13158. }
  13159. //
  13160. this.allocateTextureUnit = allocateTextureUnit;
  13161. this.resetTextureUnits = resetTextureUnits;
  13162. this.setTexture2D = setTexture2D;
  13163. this.setTexture2DArray = setTexture2DArray;
  13164. this.setTexture3D = setTexture3D;
  13165. this.setTextureCube = setTextureCube;
  13166. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13167. this.setupRenderTarget = setupRenderTarget;
  13168. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13169. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13170. this.safeSetTexture2D = safeSetTexture2D;
  13171. this.safeSetTextureCube = safeSetTextureCube;
  13172. }
  13173. /**
  13174. * @author thespite / http://www.twitter.com/thespite
  13175. */
  13176. function WebGLUtils( gl, extensions, capabilities ) {
  13177. function convert( p ) {
  13178. var extension;
  13179. if ( p === RepeatWrapping ) return 10497;
  13180. if ( p === ClampToEdgeWrapping ) return 33071;
  13181. if ( p === MirroredRepeatWrapping ) return 33648;
  13182. if ( p === NearestFilter ) return 9728;
  13183. if ( p === NearestMipmapNearestFilter ) return 9984;
  13184. if ( p === NearestMipmapLinearFilter ) return 9986;
  13185. if ( p === LinearFilter ) return 9729;
  13186. if ( p === LinearMipmapNearestFilter ) return 9985;
  13187. if ( p === LinearMipmapLinearFilter ) return 9987;
  13188. if ( p === UnsignedByteType ) return 5121;
  13189. if ( p === UnsignedShort4444Type ) return 32819;
  13190. if ( p === UnsignedShort5551Type ) return 32820;
  13191. if ( p === UnsignedShort565Type ) return 33635;
  13192. if ( p === ByteType ) return 5120;
  13193. if ( p === ShortType ) return 5122;
  13194. if ( p === UnsignedShortType ) return 5123;
  13195. if ( p === IntType ) return 5124;
  13196. if ( p === UnsignedIntType ) return 5125;
  13197. if ( p === FloatType ) return 5126;
  13198. if ( p === HalfFloatType ) {
  13199. if ( capabilities.isWebGL2 ) return 5131;
  13200. extension = extensions.get( 'OES_texture_half_float' );
  13201. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  13202. }
  13203. if ( p === AlphaFormat ) return 6406;
  13204. if ( p === RGBFormat ) return 6407;
  13205. if ( p === RGBAFormat ) return 6408;
  13206. if ( p === LuminanceFormat ) return 6409;
  13207. if ( p === LuminanceAlphaFormat ) return 6410;
  13208. if ( p === DepthFormat ) return 6402;
  13209. if ( p === DepthStencilFormat ) return 34041;
  13210. if ( p === RedFormat ) return 6403;
  13211. if ( p === AddEquation ) return 32774;
  13212. if ( p === SubtractEquation ) return 32778;
  13213. if ( p === ReverseSubtractEquation ) return 32779;
  13214. if ( p === ZeroFactor ) return 0;
  13215. if ( p === OneFactor ) return 1;
  13216. if ( p === SrcColorFactor ) return 768;
  13217. if ( p === OneMinusSrcColorFactor ) return 769;
  13218. if ( p === SrcAlphaFactor ) return 770;
  13219. if ( p === OneMinusSrcAlphaFactor ) return 771;
  13220. if ( p === DstAlphaFactor ) return 772;
  13221. if ( p === OneMinusDstAlphaFactor ) return 773;
  13222. if ( p === DstColorFactor ) return 774;
  13223. if ( p === OneMinusDstColorFactor ) return 775;
  13224. if ( p === SrcAlphaSaturateFactor ) return 776;
  13225. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13226. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13227. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13228. if ( extension !== null ) {
  13229. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13230. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13231. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13232. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13233. }
  13234. }
  13235. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13236. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13237. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13238. if ( extension !== null ) {
  13239. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13240. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13241. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13242. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13243. }
  13244. }
  13245. if ( p === RGB_ETC1_Format ) {
  13246. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13247. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13248. }
  13249. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13250. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13251. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13252. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13253. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  13254. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13255. if ( extension !== null ) {
  13256. return p;
  13257. }
  13258. }
  13259. if ( p === MinEquation || p === MaxEquation ) {
  13260. if ( capabilities.isWebGL2 ) {
  13261. if ( p === MinEquation ) return 32775;
  13262. if ( p === MaxEquation ) return 32776;
  13263. }
  13264. extension = extensions.get( 'EXT_blend_minmax' );
  13265. if ( extension !== null ) {
  13266. if ( p === MinEquation ) return extension.MIN_EXT;
  13267. if ( p === MaxEquation ) return extension.MAX_EXT;
  13268. }
  13269. }
  13270. if ( p === UnsignedInt248Type ) {
  13271. if ( capabilities.isWebGL2 ) return 34042;
  13272. extension = extensions.get( 'WEBGL_depth_texture' );
  13273. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  13274. }
  13275. return 0;
  13276. }
  13277. return { convert: convert };
  13278. }
  13279. /**
  13280. * @author mrdoob / http://mrdoob.com/
  13281. */
  13282. function Group() {
  13283. Object3D.call( this );
  13284. this.type = 'Group';
  13285. }
  13286. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13287. constructor: Group,
  13288. isGroup: true
  13289. } );
  13290. /**
  13291. * @author mrdoob / http://mrdoob.com/
  13292. */
  13293. function ArrayCamera( array ) {
  13294. PerspectiveCamera.call( this );
  13295. this.cameras = array || [];
  13296. }
  13297. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13298. constructor: ArrayCamera,
  13299. isArrayCamera: true
  13300. } );
  13301. /**
  13302. * @author jsantell / https://www.jsantell.com/
  13303. * @author mrdoob / http://mrdoob.com/
  13304. */
  13305. var cameraLPos = new Vector3();
  13306. var cameraRPos = new Vector3();
  13307. /**
  13308. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13309. * the cameras' projection and world matrices have already been set.
  13310. * And that near and far planes are identical for both cameras.
  13311. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13312. */
  13313. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13314. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13315. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13316. var ipd = cameraLPos.distanceTo( cameraRPos );
  13317. var projL = cameraL.projectionMatrix.elements;
  13318. var projR = cameraR.projectionMatrix.elements;
  13319. // VR systems will have identical far and near planes, and
  13320. // most likely identical top and bottom frustum extents.
  13321. // Use the left camera for these values.
  13322. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13323. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13324. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13325. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13326. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13327. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13328. var left = near * leftFov;
  13329. var right = near * rightFov;
  13330. // Calculate the new camera's position offset from the
  13331. // left camera. xOffset should be roughly half `ipd`.
  13332. var zOffset = ipd / ( - leftFov + rightFov );
  13333. var xOffset = zOffset * - leftFov;
  13334. // TODO: Better way to apply this offset?
  13335. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13336. camera.translateX( xOffset );
  13337. camera.translateZ( zOffset );
  13338. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13339. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13340. // Find the union of the frustum values of the cameras and scale
  13341. // the values so that the near plane's position does not change in world space,
  13342. // although must now be relative to the new union camera.
  13343. var near2 = near + zOffset;
  13344. var far2 = far + zOffset;
  13345. var left2 = left - xOffset;
  13346. var right2 = right + ( ipd - xOffset );
  13347. var top2 = topFov * far / far2 * near2;
  13348. var bottom2 = bottomFov * far / far2 * near2;
  13349. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13350. }
  13351. /**
  13352. * @author mrdoob / http://mrdoob.com/
  13353. */
  13354. function WebVRManager( renderer ) {
  13355. var renderWidth, renderHeight;
  13356. var scope = this;
  13357. var device = null;
  13358. var frameData = null;
  13359. var poseTarget = null;
  13360. var controllers = [];
  13361. var standingMatrix = new Matrix4();
  13362. var standingMatrixInverse = new Matrix4();
  13363. var framebufferScaleFactor = 1.0;
  13364. var referenceSpaceType = 'local-floor';
  13365. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13366. frameData = new window.VRFrameData();
  13367. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13368. }
  13369. var matrixWorldInverse = new Matrix4();
  13370. var tempQuaternion = new Quaternion();
  13371. var tempPosition = new Vector3();
  13372. var cameraL = new PerspectiveCamera();
  13373. cameraL.viewport = new Vector4();
  13374. cameraL.layers.enable( 1 );
  13375. var cameraR = new PerspectiveCamera();
  13376. cameraR.viewport = new Vector4();
  13377. cameraR.layers.enable( 2 );
  13378. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13379. cameraVR.layers.enable( 1 );
  13380. cameraVR.layers.enable( 2 );
  13381. //
  13382. function isPresenting() {
  13383. return device !== null && device.isPresenting === true;
  13384. }
  13385. var currentSize = new Vector2(), currentPixelRatio;
  13386. function onVRDisplayPresentChange() {
  13387. if ( isPresenting() ) {
  13388. var eyeParameters = device.getEyeParameters( 'left' );
  13389. renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
  13390. renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13391. currentPixelRatio = renderer.getPixelRatio();
  13392. renderer.getSize( currentSize );
  13393. renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
  13394. cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
  13395. cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
  13396. animation.start();
  13397. scope.dispatchEvent( { type: 'sessionstart' } );
  13398. } else {
  13399. if ( scope.enabled ) {
  13400. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13401. }
  13402. animation.stop();
  13403. scope.dispatchEvent( { type: 'sessionend' } );
  13404. }
  13405. }
  13406. //
  13407. var triggers = [];
  13408. function findGamepad( id ) {
  13409. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13410. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13411. var gamepad = gamepads[ i ];
  13412. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13413. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13414. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13415. gamepad.id.startsWith( 'HTC Vive Focus' ) ||
  13416. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13417. if ( j === id ) return gamepad;
  13418. j ++;
  13419. }
  13420. }
  13421. }
  13422. function updateControllers() {
  13423. for ( var i = 0; i < controllers.length; i ++ ) {
  13424. var controller = controllers[ i ];
  13425. var gamepad = findGamepad( i );
  13426. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13427. if ( gamepad.pose === null ) return;
  13428. // Pose
  13429. var pose = gamepad.pose;
  13430. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13431. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13432. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13433. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13434. controller.matrix.premultiply( standingMatrix );
  13435. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13436. controller.matrixWorldNeedsUpdate = true;
  13437. controller.visible = true;
  13438. // Trigger
  13439. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13440. if ( triggers[ i ] === undefined ) triggers[ i ] = false;
  13441. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13442. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13443. if ( triggers[ i ] === true ) {
  13444. controller.dispatchEvent( { type: 'selectstart' } );
  13445. } else {
  13446. controller.dispatchEvent( { type: 'selectend' } );
  13447. controller.dispatchEvent( { type: 'select' } );
  13448. }
  13449. }
  13450. } else {
  13451. controller.visible = false;
  13452. }
  13453. }
  13454. }
  13455. function updateViewportFromBounds( viewport, bounds ) {
  13456. if ( bounds !== null && bounds.length === 4 ) {
  13457. viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
  13458. }
  13459. }
  13460. //
  13461. this.enabled = false;
  13462. this.getController = function ( id ) {
  13463. var controller = controllers[ id ];
  13464. if ( controller === undefined ) {
  13465. controller = new Group();
  13466. controller.matrixAutoUpdate = false;
  13467. controller.visible = false;
  13468. controllers[ id ] = controller;
  13469. }
  13470. return controller;
  13471. };
  13472. this.getDevice = function () {
  13473. return device;
  13474. };
  13475. this.setDevice = function ( value ) {
  13476. if ( value !== undefined ) device = value;
  13477. animation.setContext( value );
  13478. };
  13479. this.setFramebufferScaleFactor = function ( value ) {
  13480. framebufferScaleFactor = value;
  13481. };
  13482. this.setReferenceSpaceType = function ( value ) {
  13483. referenceSpaceType = value;
  13484. };
  13485. this.setPoseTarget = function ( object ) {
  13486. if ( object !== undefined ) poseTarget = object;
  13487. };
  13488. this.getCamera = function ( camera ) {
  13489. var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
  13490. if ( isPresenting() === false ) {
  13491. camera.position.set( 0, userHeight, 0 );
  13492. camera.rotation.set( 0, 0, 0 );
  13493. return camera;
  13494. }
  13495. device.depthNear = camera.near;
  13496. device.depthFar = camera.far;
  13497. device.getFrameData( frameData );
  13498. //
  13499. if ( referenceSpaceType === 'local-floor' ) {
  13500. var stageParameters = device.stageParameters;
  13501. if ( stageParameters ) {
  13502. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13503. } else {
  13504. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13505. }
  13506. }
  13507. var pose = frameData.pose;
  13508. var poseObject = poseTarget !== null ? poseTarget : camera;
  13509. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13510. poseObject.matrix.copy( standingMatrix );
  13511. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13512. if ( pose.orientation !== null ) {
  13513. tempQuaternion.fromArray( pose.orientation );
  13514. poseObject.quaternion.multiply( tempQuaternion );
  13515. }
  13516. if ( pose.position !== null ) {
  13517. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13518. tempPosition.fromArray( pose.position );
  13519. tempPosition.applyQuaternion( tempQuaternion );
  13520. poseObject.position.add( tempPosition );
  13521. }
  13522. poseObject.updateMatrixWorld();
  13523. //
  13524. cameraL.near = camera.near;
  13525. cameraR.near = camera.near;
  13526. cameraL.far = camera.far;
  13527. cameraR.far = camera.far;
  13528. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13529. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13530. // TODO (mrdoob) Double check this code
  13531. standingMatrixInverse.getInverse( standingMatrix );
  13532. if ( referenceSpaceType === 'local-floor' ) {
  13533. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13534. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13535. }
  13536. var parent = poseObject.parent;
  13537. if ( parent !== null ) {
  13538. matrixWorldInverse.getInverse( parent.matrixWorld );
  13539. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13540. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13541. }
  13542. // envMap and Mirror needs camera.matrixWorld
  13543. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13544. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13545. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13546. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13547. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13548. //
  13549. var layers = device.getLayers();
  13550. if ( layers.length ) {
  13551. var layer = layers[ 0 ];
  13552. updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
  13553. updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
  13554. }
  13555. updateControllers();
  13556. return cameraVR;
  13557. };
  13558. this.getStandingMatrix = function () {
  13559. return standingMatrix;
  13560. };
  13561. this.isPresenting = isPresenting;
  13562. // Animation Loop
  13563. var animation = new WebGLAnimation();
  13564. this.setAnimationLoop = function ( callback ) {
  13565. animation.setAnimationLoop( callback );
  13566. if ( isPresenting() ) animation.start();
  13567. };
  13568. this.submitFrame = function () {
  13569. if ( isPresenting() ) device.submitFrame();
  13570. };
  13571. this.dispose = function () {
  13572. if ( typeof window !== 'undefined' ) {
  13573. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13574. }
  13575. };
  13576. // DEPRECATED
  13577. this.setFrameOfReferenceType = function () {
  13578. console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
  13579. };
  13580. }
  13581. Object.assign( WebVRManager.prototype, EventDispatcher.prototype );
  13582. /**
  13583. * @author mrdoob / http://mrdoob.com/
  13584. */
  13585. function WebXRManager( renderer, gl ) {
  13586. var scope = this;
  13587. var session = null;
  13588. var referenceSpace = null;
  13589. var referenceSpaceType = 'local-floor';
  13590. var pose = null;
  13591. var controllers = [];
  13592. var inputSources = [];
  13593. function isPresenting() {
  13594. return session !== null && referenceSpace !== null;
  13595. }
  13596. //
  13597. var cameraL = new PerspectiveCamera();
  13598. cameraL.layers.enable( 1 );
  13599. cameraL.viewport = new Vector4();
  13600. var cameraR = new PerspectiveCamera();
  13601. cameraR.layers.enable( 2 );
  13602. cameraR.viewport = new Vector4();
  13603. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13604. cameraVR.layers.enable( 1 );
  13605. cameraVR.layers.enable( 2 );
  13606. //
  13607. this.enabled = false;
  13608. this.getController = function ( id ) {
  13609. var controller = controllers[ id ];
  13610. if ( controller === undefined ) {
  13611. controller = new Group();
  13612. controller.matrixAutoUpdate = false;
  13613. controller.visible = false;
  13614. controllers[ id ] = controller;
  13615. }
  13616. return controller;
  13617. };
  13618. //
  13619. function onSessionEvent( event ) {
  13620. for ( var i = 0; i < controllers.length; i ++ ) {
  13621. if ( inputSources[ i ] === event.inputSource ) {
  13622. controllers[ i ].dispatchEvent( { type: event.type } );
  13623. }
  13624. }
  13625. }
  13626. function onSessionEnd() {
  13627. renderer.setFramebuffer( null );
  13628. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13629. animation.stop();
  13630. scope.dispatchEvent( { type: 'sessionend' } );
  13631. }
  13632. function onRequestReferenceSpace( value ) {
  13633. referenceSpace = value;
  13634. animation.setContext( session );
  13635. animation.start();
  13636. scope.dispatchEvent( { type: 'sessionstart' } );
  13637. }
  13638. this.setFramebufferScaleFactor = function ( value ) {
  13639. };
  13640. this.setReferenceSpaceType = function ( value ) {
  13641. referenceSpaceType = value;
  13642. };
  13643. this.getSession = function () {
  13644. return session;
  13645. };
  13646. this.setSession = function ( value ) {
  13647. session = value;
  13648. if ( session !== null ) {
  13649. session.addEventListener( 'select', onSessionEvent );
  13650. session.addEventListener( 'selectstart', onSessionEvent );
  13651. session.addEventListener( 'selectend', onSessionEvent );
  13652. session.addEventListener( 'end', onSessionEnd );
  13653. session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
  13654. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13655. //
  13656. inputSources = session.inputSources;
  13657. session.addEventListener( 'inputsourceschange', function () {
  13658. inputSources = session.inputSources;
  13659. console.log( inputSources );
  13660. for ( var i = 0; i < controllers.length; i ++ ) {
  13661. var controller = controllers[ i ];
  13662. controller.userData.inputSource = inputSources[ i ];
  13663. }
  13664. } );
  13665. }
  13666. };
  13667. function updateCamera( camera, parent ) {
  13668. if ( parent === null ) {
  13669. camera.matrixWorld.copy( camera.matrix );
  13670. } else {
  13671. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13672. }
  13673. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13674. }
  13675. this.getCamera = function ( camera ) {
  13676. if ( isPresenting() ) {
  13677. var parent = camera.parent;
  13678. var cameras = cameraVR.cameras;
  13679. updateCamera( cameraVR, parent );
  13680. for ( var i = 0; i < cameras.length; i ++ ) {
  13681. updateCamera( cameras[ i ], parent );
  13682. }
  13683. // update camera and its children
  13684. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13685. var children = camera.children;
  13686. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13687. children[ i ].updateMatrixWorld( true );
  13688. }
  13689. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13690. return cameraVR;
  13691. }
  13692. return camera;
  13693. };
  13694. this.isPresenting = isPresenting;
  13695. // Animation Loop
  13696. var onAnimationFrameCallback = null;
  13697. function onAnimationFrame( time, frame ) {
  13698. pose = frame.getViewerPose( referenceSpace );
  13699. if ( pose !== null ) {
  13700. var views = pose.views;
  13701. var baseLayer = session.renderState.baseLayer;
  13702. renderer.setFramebuffer( baseLayer.framebuffer );
  13703. for ( var i = 0; i < views.length; i ++ ) {
  13704. var view = views[ i ];
  13705. var viewport = baseLayer.getViewport( view );
  13706. var viewMatrix = view.transform.inverse.matrix;
  13707. var camera = cameraVR.cameras[ i ];
  13708. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13709. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13710. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13711. if ( i === 0 ) {
  13712. cameraVR.matrix.copy( camera.matrix );
  13713. }
  13714. }
  13715. }
  13716. //
  13717. for ( var i = 0; i < controllers.length; i ++ ) {
  13718. var controller = controllers[ i ];
  13719. var inputSource = inputSources[ i ];
  13720. if ( inputSource ) {
  13721. var inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13722. if ( inputPose !== null ) {
  13723. controller.matrix.fromArray( inputPose.transform.matrix );
  13724. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13725. controller.visible = true;
  13726. continue;
  13727. }
  13728. }
  13729. controller.visible = false;
  13730. }
  13731. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13732. }
  13733. var animation = new WebGLAnimation();
  13734. animation.setAnimationLoop( onAnimationFrame );
  13735. this.setAnimationLoop = function ( callback ) {
  13736. onAnimationFrameCallback = callback;
  13737. };
  13738. this.dispose = function () {};
  13739. // DEPRECATED
  13740. this.getStandingMatrix = function () {
  13741. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13742. return new Matrix4();
  13743. };
  13744. this.getDevice = function () {
  13745. console.warn( 'THREE.WebXRManager: getDevice() has been deprecated.' );
  13746. };
  13747. this.setDevice = function () {
  13748. console.warn( 'THREE.WebXRManager: setDevice() has been deprecated.' );
  13749. };
  13750. this.setFrameOfReferenceType = function () {
  13751. console.warn( 'THREE.WebXRManager: setFrameOfReferenceType() has been deprecated.' );
  13752. };
  13753. this.submitFrame = function () {};
  13754. }
  13755. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  13756. /**
  13757. * @author supereggbert / http://www.paulbrunt.co.uk/
  13758. * @author mrdoob / http://mrdoob.com/
  13759. * @author alteredq / http://alteredqualia.com/
  13760. * @author szimek / https://github.com/szimek/
  13761. * @author tschw
  13762. */
  13763. function WebGLRenderer( parameters ) {
  13764. parameters = parameters || {};
  13765. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13766. _context = parameters.context !== undefined ? parameters.context : null,
  13767. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13768. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13769. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13770. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13771. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13772. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13773. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13774. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13775. var currentRenderList = null;
  13776. var currentRenderState = null;
  13777. // public properties
  13778. this.domElement = _canvas;
  13779. // Debug configuration container
  13780. this.debug = {
  13781. /**
  13782. * Enables error checking and reporting when shader programs are being compiled
  13783. * @type {boolean}
  13784. */
  13785. checkShaderErrors: true
  13786. };
  13787. // clearing
  13788. this.autoClear = true;
  13789. this.autoClearColor = true;
  13790. this.autoClearDepth = true;
  13791. this.autoClearStencil = true;
  13792. // scene graph
  13793. this.sortObjects = true;
  13794. // user-defined clipping
  13795. this.clippingPlanes = [];
  13796. this.localClippingEnabled = false;
  13797. // physically based shading
  13798. this.gammaFactor = 2.0; // for backwards compatibility
  13799. this.gammaInput = false;
  13800. this.gammaOutput = false;
  13801. // physical lights
  13802. this.physicallyCorrectLights = false;
  13803. // tone mapping
  13804. this.toneMapping = LinearToneMapping;
  13805. this.toneMappingExposure = 1.0;
  13806. this.toneMappingWhitePoint = 1.0;
  13807. // morphs
  13808. this.maxMorphTargets = 8;
  13809. this.maxMorphNormals = 4;
  13810. // internal properties
  13811. var _this = this,
  13812. _isContextLost = false,
  13813. // internal state cache
  13814. _framebuffer = null,
  13815. _currentActiveCubeFace = 0,
  13816. _currentActiveMipmapLevel = 0,
  13817. _currentRenderTarget = null,
  13818. _currentFramebuffer = null,
  13819. _currentMaterialId = - 1,
  13820. // geometry and program caching
  13821. _currentGeometryProgram = {
  13822. geometry: null,
  13823. program: null,
  13824. wireframe: false
  13825. },
  13826. _currentCamera = null,
  13827. _currentArrayCamera = null,
  13828. _currentViewport = new Vector4(),
  13829. _currentScissor = new Vector4(),
  13830. _currentScissorTest = null,
  13831. //
  13832. _width = _canvas.width,
  13833. _height = _canvas.height,
  13834. _pixelRatio = 1,
  13835. _viewport = new Vector4( 0, 0, _width, _height ),
  13836. _scissor = new Vector4( 0, 0, _width, _height ),
  13837. _scissorTest = false,
  13838. // frustum
  13839. _frustum = new Frustum(),
  13840. // clipping
  13841. _clipping = new WebGLClipping(),
  13842. _clippingEnabled = false,
  13843. _localClippingEnabled = false,
  13844. // camera matrices cache
  13845. _projScreenMatrix = new Matrix4(),
  13846. _vector3 = new Vector3();
  13847. function getTargetPixelRatio() {
  13848. return _currentRenderTarget === null ? _pixelRatio : 1;
  13849. }
  13850. // initialize
  13851. var _gl;
  13852. try {
  13853. var contextAttributes = {
  13854. alpha: _alpha,
  13855. depth: _depth,
  13856. stencil: _stencil,
  13857. antialias: _antialias,
  13858. premultipliedAlpha: _premultipliedAlpha,
  13859. preserveDrawingBuffer: _preserveDrawingBuffer,
  13860. powerPreference: _powerPreference,
  13861. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
  13862. xrCompatible: true
  13863. };
  13864. // event listeners must be registered before WebGL context is created, see #12753
  13865. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13866. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13867. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13868. if ( _gl === null ) {
  13869. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13870. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13871. } else {
  13872. throw new Error( 'Error creating WebGL context.' );
  13873. }
  13874. }
  13875. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13876. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13877. _gl.getShaderPrecisionFormat = function () {
  13878. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13879. };
  13880. }
  13881. } catch ( error ) {
  13882. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13883. throw error;
  13884. }
  13885. var extensions, capabilities, state, info;
  13886. var properties, textures, attributes, geometries, objects;
  13887. var programCache, renderLists, renderStates;
  13888. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13889. var utils;
  13890. function initGLContext() {
  13891. extensions = new WebGLExtensions( _gl );
  13892. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13893. if ( ! capabilities.isWebGL2 ) {
  13894. extensions.get( 'WEBGL_depth_texture' );
  13895. extensions.get( 'OES_texture_float' );
  13896. extensions.get( 'OES_texture_half_float' );
  13897. extensions.get( 'OES_texture_half_float_linear' );
  13898. extensions.get( 'OES_standard_derivatives' );
  13899. extensions.get( 'OES_element_index_uint' );
  13900. extensions.get( 'ANGLE_instanced_arrays' );
  13901. }
  13902. extensions.get( 'OES_texture_float_linear' );
  13903. utils = new WebGLUtils( _gl, extensions, capabilities );
  13904. state = new WebGLState( _gl, extensions, utils, capabilities );
  13905. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  13906. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  13907. info = new WebGLInfo( _gl );
  13908. properties = new WebGLProperties();
  13909. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13910. attributes = new WebGLAttributes( _gl );
  13911. geometries = new WebGLGeometries( _gl, attributes, info );
  13912. objects = new WebGLObjects( geometries, info );
  13913. morphtargets = new WebGLMorphtargets( _gl );
  13914. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13915. renderLists = new WebGLRenderLists();
  13916. renderStates = new WebGLRenderStates();
  13917. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13918. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13919. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13920. info.programs = programCache.programs;
  13921. _this.capabilities = capabilities;
  13922. _this.extensions = extensions;
  13923. _this.properties = properties;
  13924. _this.renderLists = renderLists;
  13925. _this.state = state;
  13926. _this.info = info;
  13927. }
  13928. initGLContext();
  13929. // vr
  13930. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator && 'supportsSession' in navigator.xr ) ? new WebXRManager( _this, _gl ) : new WebVRManager( _this );
  13931. this.vr = vr;
  13932. // shadow map
  13933. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13934. this.shadowMap = shadowMap;
  13935. // API
  13936. this.getContext = function () {
  13937. return _gl;
  13938. };
  13939. this.getContextAttributes = function () {
  13940. return _gl.getContextAttributes();
  13941. };
  13942. this.forceContextLoss = function () {
  13943. var extension = extensions.get( 'WEBGL_lose_context' );
  13944. if ( extension ) extension.loseContext();
  13945. };
  13946. this.forceContextRestore = function () {
  13947. var extension = extensions.get( 'WEBGL_lose_context' );
  13948. if ( extension ) extension.restoreContext();
  13949. };
  13950. this.getPixelRatio = function () {
  13951. return _pixelRatio;
  13952. };
  13953. this.setPixelRatio = function ( value ) {
  13954. if ( value === undefined ) return;
  13955. _pixelRatio = value;
  13956. this.setSize( _width, _height, false );
  13957. };
  13958. this.getSize = function ( target ) {
  13959. if ( target === undefined ) {
  13960. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13961. target = new Vector2();
  13962. }
  13963. return target.set( _width, _height );
  13964. };
  13965. this.setSize = function ( width, height, updateStyle ) {
  13966. if ( vr.isPresenting() ) {
  13967. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13968. return;
  13969. }
  13970. _width = width;
  13971. _height = height;
  13972. _canvas.width = Math.floor( width * _pixelRatio );
  13973. _canvas.height = Math.floor( height * _pixelRatio );
  13974. if ( updateStyle !== false ) {
  13975. _canvas.style.width = width + 'px';
  13976. _canvas.style.height = height + 'px';
  13977. }
  13978. this.setViewport( 0, 0, width, height );
  13979. };
  13980. this.getDrawingBufferSize = function ( target ) {
  13981. if ( target === undefined ) {
  13982. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13983. target = new Vector2();
  13984. }
  13985. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  13986. };
  13987. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13988. _width = width;
  13989. _height = height;
  13990. _pixelRatio = pixelRatio;
  13991. _canvas.width = Math.floor( width * pixelRatio );
  13992. _canvas.height = Math.floor( height * pixelRatio );
  13993. this.setViewport( 0, 0, width, height );
  13994. };
  13995. this.getCurrentViewport = function ( target ) {
  13996. if ( target === undefined ) {
  13997. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13998. target = new Vector4();
  13999. }
  14000. return target.copy( _currentViewport );
  14001. };
  14002. this.getViewport = function ( target ) {
  14003. return target.copy( _viewport );
  14004. };
  14005. this.setViewport = function ( x, y, width, height ) {
  14006. if ( x.isVector4 ) {
  14007. _viewport.set( x.x, x.y, x.z, x.w );
  14008. } else {
  14009. _viewport.set( x, y, width, height );
  14010. }
  14011. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14012. };
  14013. this.getScissor = function ( target ) {
  14014. return target.copy( _scissor );
  14015. };
  14016. this.setScissor = function ( x, y, width, height ) {
  14017. if ( x.isVector4 ) {
  14018. _scissor.set( x.x, x.y, x.z, x.w );
  14019. } else {
  14020. _scissor.set( x, y, width, height );
  14021. }
  14022. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14023. };
  14024. this.getScissorTest = function () {
  14025. return _scissorTest;
  14026. };
  14027. this.setScissorTest = function ( boolean ) {
  14028. state.setScissorTest( _scissorTest = boolean );
  14029. };
  14030. // Clearing
  14031. this.getClearColor = function () {
  14032. return background.getClearColor();
  14033. };
  14034. this.setClearColor = function () {
  14035. background.setClearColor.apply( background, arguments );
  14036. };
  14037. this.getClearAlpha = function () {
  14038. return background.getClearAlpha();
  14039. };
  14040. this.setClearAlpha = function () {
  14041. background.setClearAlpha.apply( background, arguments );
  14042. };
  14043. this.clear = function ( color, depth, stencil ) {
  14044. var bits = 0;
  14045. if ( color === undefined || color ) bits |= 16384;
  14046. if ( depth === undefined || depth ) bits |= 256;
  14047. if ( stencil === undefined || stencil ) bits |= 1024;
  14048. _gl.clear( bits );
  14049. };
  14050. this.clearColor = function () {
  14051. this.clear( true, false, false );
  14052. };
  14053. this.clearDepth = function () {
  14054. this.clear( false, true, false );
  14055. };
  14056. this.clearStencil = function () {
  14057. this.clear( false, false, true );
  14058. };
  14059. //
  14060. this.dispose = function () {
  14061. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14062. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14063. renderLists.dispose();
  14064. renderStates.dispose();
  14065. properties.dispose();
  14066. objects.dispose();
  14067. vr.dispose();
  14068. animation.stop();
  14069. };
  14070. // Events
  14071. function onContextLost( event ) {
  14072. event.preventDefault();
  14073. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14074. _isContextLost = true;
  14075. }
  14076. function onContextRestore( /* event */ ) {
  14077. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14078. _isContextLost = false;
  14079. initGLContext();
  14080. }
  14081. function onMaterialDispose( event ) {
  14082. var material = event.target;
  14083. material.removeEventListener( 'dispose', onMaterialDispose );
  14084. deallocateMaterial( material );
  14085. }
  14086. // Buffer deallocation
  14087. function deallocateMaterial( material ) {
  14088. releaseMaterialProgramReference( material );
  14089. properties.remove( material );
  14090. }
  14091. function releaseMaterialProgramReference( material ) {
  14092. var programInfo = properties.get( material ).program;
  14093. material.program = undefined;
  14094. if ( programInfo !== undefined ) {
  14095. programCache.releaseProgram( programInfo );
  14096. }
  14097. }
  14098. // Buffer rendering
  14099. function renderObjectImmediate( object, program ) {
  14100. object.render( function ( object ) {
  14101. _this.renderBufferImmediate( object, program );
  14102. } );
  14103. }
  14104. this.renderBufferImmediate = function ( object, program ) {
  14105. state.initAttributes();
  14106. var buffers = properties.get( object );
  14107. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14108. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14109. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14110. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14111. var programAttributes = program.getAttributes();
  14112. if ( object.hasPositions ) {
  14113. _gl.bindBuffer( 34962, buffers.position );
  14114. _gl.bufferData( 34962, object.positionArray, 35048 );
  14115. state.enableAttribute( programAttributes.position );
  14116. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14117. }
  14118. if ( object.hasNormals ) {
  14119. _gl.bindBuffer( 34962, buffers.normal );
  14120. _gl.bufferData( 34962, object.normalArray, 35048 );
  14121. state.enableAttribute( programAttributes.normal );
  14122. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14123. }
  14124. if ( object.hasUvs ) {
  14125. _gl.bindBuffer( 34962, buffers.uv );
  14126. _gl.bufferData( 34962, object.uvArray, 35048 );
  14127. state.enableAttribute( programAttributes.uv );
  14128. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14129. }
  14130. if ( object.hasColors ) {
  14131. _gl.bindBuffer( 34962, buffers.color );
  14132. _gl.bufferData( 34962, object.colorArray, 35048 );
  14133. state.enableAttribute( programAttributes.color );
  14134. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14135. }
  14136. state.disableUnusedAttributes();
  14137. _gl.drawArrays( 4, 0, object.count );
  14138. object.count = 0;
  14139. };
  14140. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14141. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14142. state.setMaterial( material, frontFaceCW );
  14143. var program = setProgram( camera, fog, material, object );
  14144. var updateBuffers = false;
  14145. if ( _currentGeometryProgram.geometry !== geometry.id ||
  14146. _currentGeometryProgram.program !== program.id ||
  14147. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  14148. _currentGeometryProgram.geometry = geometry.id;
  14149. _currentGeometryProgram.program = program.id;
  14150. _currentGeometryProgram.wireframe = material.wireframe === true;
  14151. updateBuffers = true;
  14152. }
  14153. if ( object.morphTargetInfluences ) {
  14154. morphtargets.update( object, geometry, material, program );
  14155. updateBuffers = true;
  14156. }
  14157. //
  14158. var index = geometry.index;
  14159. var position = geometry.attributes.position;
  14160. var rangeFactor = 1;
  14161. if ( material.wireframe === true ) {
  14162. index = geometries.getWireframeAttribute( geometry );
  14163. rangeFactor = 2;
  14164. }
  14165. var attribute;
  14166. var renderer = bufferRenderer;
  14167. if ( index !== null ) {
  14168. attribute = attributes.get( index );
  14169. renderer = indexedBufferRenderer;
  14170. renderer.setIndex( attribute );
  14171. }
  14172. if ( updateBuffers ) {
  14173. setupVertexAttributes( material, program, geometry );
  14174. if ( index !== null ) {
  14175. _gl.bindBuffer( 34963, attribute.buffer );
  14176. }
  14177. }
  14178. //
  14179. var dataCount = Infinity;
  14180. if ( index !== null ) {
  14181. dataCount = index.count;
  14182. } else if ( position !== undefined ) {
  14183. dataCount = position.count;
  14184. }
  14185. var rangeStart = geometry.drawRange.start * rangeFactor;
  14186. var rangeCount = geometry.drawRange.count * rangeFactor;
  14187. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14188. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14189. var drawStart = Math.max( rangeStart, groupStart );
  14190. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14191. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14192. if ( drawCount === 0 ) return;
  14193. //
  14194. if ( object.isMesh ) {
  14195. if ( material.wireframe === true ) {
  14196. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14197. renderer.setMode( 1 );
  14198. } else {
  14199. switch ( object.drawMode ) {
  14200. case TrianglesDrawMode:
  14201. renderer.setMode( 4 );
  14202. break;
  14203. case TriangleStripDrawMode:
  14204. renderer.setMode( 5 );
  14205. break;
  14206. case TriangleFanDrawMode:
  14207. renderer.setMode( 6 );
  14208. break;
  14209. }
  14210. }
  14211. } else if ( object.isLine ) {
  14212. var lineWidth = material.linewidth;
  14213. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14214. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14215. if ( object.isLineSegments ) {
  14216. renderer.setMode( 1 );
  14217. } else if ( object.isLineLoop ) {
  14218. renderer.setMode( 2 );
  14219. } else {
  14220. renderer.setMode( 3 );
  14221. }
  14222. } else if ( object.isPoints ) {
  14223. renderer.setMode( 0 );
  14224. } else if ( object.isSprite ) {
  14225. renderer.setMode( 4 );
  14226. }
  14227. if ( geometry && geometry.isInstancedBufferGeometry ) {
  14228. if ( geometry.maxInstancedCount > 0 ) {
  14229. renderer.renderInstances( geometry, drawStart, drawCount );
  14230. }
  14231. } else {
  14232. renderer.render( drawStart, drawCount );
  14233. }
  14234. };
  14235. function setupVertexAttributes( material, program, geometry ) {
  14236. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  14237. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  14238. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14239. return;
  14240. }
  14241. }
  14242. state.initAttributes();
  14243. var geometryAttributes = geometry.attributes;
  14244. var programAttributes = program.getAttributes();
  14245. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14246. for ( var name in programAttributes ) {
  14247. var programAttribute = programAttributes[ name ];
  14248. if ( programAttribute >= 0 ) {
  14249. var geometryAttribute = geometryAttributes[ name ];
  14250. if ( geometryAttribute !== undefined ) {
  14251. var normalized = geometryAttribute.normalized;
  14252. var size = geometryAttribute.itemSize;
  14253. var attribute = attributes.get( geometryAttribute );
  14254. // TODO Attribute may not be available on context restore
  14255. if ( attribute === undefined ) continue;
  14256. var buffer = attribute.buffer;
  14257. var type = attribute.type;
  14258. var bytesPerElement = attribute.bytesPerElement;
  14259. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14260. var data = geometryAttribute.data;
  14261. var stride = data.stride;
  14262. var offset = geometryAttribute.offset;
  14263. if ( data && data.isInstancedInterleavedBuffer ) {
  14264. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14265. if ( geometry.maxInstancedCount === undefined ) {
  14266. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14267. }
  14268. } else {
  14269. state.enableAttribute( programAttribute );
  14270. }
  14271. _gl.bindBuffer( 34962, buffer );
  14272. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14273. } else {
  14274. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14275. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14276. if ( geometry.maxInstancedCount === undefined ) {
  14277. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14278. }
  14279. } else {
  14280. state.enableAttribute( programAttribute );
  14281. }
  14282. _gl.bindBuffer( 34962, buffer );
  14283. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14284. }
  14285. } else if ( materialDefaultAttributeValues !== undefined ) {
  14286. var value = materialDefaultAttributeValues[ name ];
  14287. if ( value !== undefined ) {
  14288. switch ( value.length ) {
  14289. case 2:
  14290. _gl.vertexAttrib2fv( programAttribute, value );
  14291. break;
  14292. case 3:
  14293. _gl.vertexAttrib3fv( programAttribute, value );
  14294. break;
  14295. case 4:
  14296. _gl.vertexAttrib4fv( programAttribute, value );
  14297. break;
  14298. default:
  14299. _gl.vertexAttrib1fv( programAttribute, value );
  14300. }
  14301. }
  14302. }
  14303. }
  14304. }
  14305. state.disableUnusedAttributes();
  14306. }
  14307. // Compile
  14308. this.compile = function ( scene, camera ) {
  14309. currentRenderState = renderStates.get( scene, camera );
  14310. currentRenderState.init();
  14311. scene.traverse( function ( object ) {
  14312. if ( object.isLight ) {
  14313. currentRenderState.pushLight( object );
  14314. if ( object.castShadow ) {
  14315. currentRenderState.pushShadow( object );
  14316. }
  14317. }
  14318. } );
  14319. currentRenderState.setupLights( camera );
  14320. scene.traverse( function ( object ) {
  14321. if ( object.material ) {
  14322. if ( Array.isArray( object.material ) ) {
  14323. for ( var i = 0; i < object.material.length; i ++ ) {
  14324. initMaterial( object.material[ i ], scene.fog, object );
  14325. }
  14326. } else {
  14327. initMaterial( object.material, scene.fog, object );
  14328. }
  14329. }
  14330. } );
  14331. };
  14332. // Animation Loop
  14333. var onAnimationFrameCallback = null;
  14334. function onAnimationFrame( time ) {
  14335. if ( vr.isPresenting() ) return;
  14336. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14337. }
  14338. var animation = new WebGLAnimation();
  14339. animation.setAnimationLoop( onAnimationFrame );
  14340. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14341. this.setAnimationLoop = function ( callback ) {
  14342. onAnimationFrameCallback = callback;
  14343. vr.setAnimationLoop( callback );
  14344. animation.start();
  14345. };
  14346. // Rendering
  14347. this.render = function ( scene, camera ) {
  14348. var renderTarget, forceClear;
  14349. if ( arguments[ 2 ] !== undefined ) {
  14350. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14351. renderTarget = arguments[ 2 ];
  14352. }
  14353. if ( arguments[ 3 ] !== undefined ) {
  14354. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14355. forceClear = arguments[ 3 ];
  14356. }
  14357. if ( ! ( camera && camera.isCamera ) ) {
  14358. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14359. return;
  14360. }
  14361. if ( _isContextLost ) return;
  14362. // reset caching for this frame
  14363. _currentGeometryProgram.geometry = null;
  14364. _currentGeometryProgram.program = null;
  14365. _currentGeometryProgram.wireframe = false;
  14366. _currentMaterialId = - 1;
  14367. _currentCamera = null;
  14368. // update scene graph
  14369. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14370. // update camera matrices and frustum
  14371. if ( camera.parent === null ) camera.updateMatrixWorld();
  14372. if ( vr.enabled ) {
  14373. camera = vr.getCamera( camera );
  14374. }
  14375. //
  14376. currentRenderState = renderStates.get( scene, camera );
  14377. currentRenderState.init();
  14378. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14379. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14380. _frustum.setFromMatrix( _projScreenMatrix );
  14381. _localClippingEnabled = this.localClippingEnabled;
  14382. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14383. currentRenderList = renderLists.get( scene, camera );
  14384. currentRenderList.init();
  14385. projectObject( scene, camera, 0, _this.sortObjects );
  14386. if ( _this.sortObjects === true ) {
  14387. currentRenderList.sort();
  14388. }
  14389. //
  14390. if ( _clippingEnabled ) _clipping.beginShadows();
  14391. var shadowsArray = currentRenderState.state.shadowsArray;
  14392. shadowMap.render( shadowsArray, scene, camera );
  14393. currentRenderState.setupLights( camera );
  14394. if ( _clippingEnabled ) _clipping.endShadows();
  14395. //
  14396. if ( this.info.autoReset ) this.info.reset();
  14397. if ( renderTarget !== undefined ) {
  14398. this.setRenderTarget( renderTarget );
  14399. }
  14400. //
  14401. background.render( currentRenderList, scene, camera, forceClear );
  14402. // render scene
  14403. var opaqueObjects = currentRenderList.opaque;
  14404. var transparentObjects = currentRenderList.transparent;
  14405. if ( scene.overrideMaterial ) {
  14406. var overrideMaterial = scene.overrideMaterial;
  14407. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14408. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14409. } else {
  14410. // opaque pass (front-to-back order)
  14411. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14412. // transparent pass (back-to-front order)
  14413. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14414. }
  14415. //
  14416. scene.onAfterRender( _this, scene, camera );
  14417. //
  14418. if ( _currentRenderTarget !== null ) {
  14419. // Generate mipmap if we're using any kind of mipmap filtering
  14420. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14421. // resolve multisample renderbuffers to a single-sample texture if necessary
  14422. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14423. }
  14424. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14425. state.buffers.depth.setTest( true );
  14426. state.buffers.depth.setMask( true );
  14427. state.buffers.color.setMask( true );
  14428. state.setPolygonOffset( false );
  14429. if ( vr.enabled ) {
  14430. vr.submitFrame();
  14431. }
  14432. // _gl.finish();
  14433. currentRenderList = null;
  14434. currentRenderState = null;
  14435. };
  14436. function projectObject( object, camera, groupOrder, sortObjects ) {
  14437. if ( object.visible === false ) return;
  14438. var visible = object.layers.test( camera.layers );
  14439. if ( visible ) {
  14440. if ( object.isGroup ) {
  14441. groupOrder = object.renderOrder;
  14442. } else if ( object.isLOD ) {
  14443. if ( object.autoUpdate === true ) object.update( camera );
  14444. } else if ( object.isLight ) {
  14445. currentRenderState.pushLight( object );
  14446. if ( object.castShadow ) {
  14447. currentRenderState.pushShadow( object );
  14448. }
  14449. } else if ( object.isSprite ) {
  14450. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14451. if ( sortObjects ) {
  14452. _vector3.setFromMatrixPosition( object.matrixWorld )
  14453. .applyMatrix4( _projScreenMatrix );
  14454. }
  14455. var geometry = objects.update( object );
  14456. var material = object.material;
  14457. if ( material.visible ) {
  14458. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14459. }
  14460. }
  14461. } else if ( object.isImmediateRenderObject ) {
  14462. if ( sortObjects ) {
  14463. _vector3.setFromMatrixPosition( object.matrixWorld )
  14464. .applyMatrix4( _projScreenMatrix );
  14465. }
  14466. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14467. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14468. if ( object.isSkinnedMesh ) {
  14469. object.skeleton.update();
  14470. }
  14471. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14472. if ( sortObjects ) {
  14473. _vector3.setFromMatrixPosition( object.matrixWorld )
  14474. .applyMatrix4( _projScreenMatrix );
  14475. }
  14476. var geometry = objects.update( object );
  14477. var material = object.material;
  14478. if ( Array.isArray( material ) ) {
  14479. var groups = geometry.groups;
  14480. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14481. var group = groups[ i ];
  14482. var groupMaterial = material[ group.materialIndex ];
  14483. if ( groupMaterial && groupMaterial.visible ) {
  14484. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14485. }
  14486. }
  14487. } else if ( material.visible ) {
  14488. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14489. }
  14490. }
  14491. }
  14492. }
  14493. var children = object.children;
  14494. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14495. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14496. }
  14497. }
  14498. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14499. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14500. var renderItem = renderList[ i ];
  14501. var object = renderItem.object;
  14502. var geometry = renderItem.geometry;
  14503. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14504. var group = renderItem.group;
  14505. if ( camera.isArrayCamera ) {
  14506. _currentArrayCamera = camera;
  14507. var cameras = camera.cameras;
  14508. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14509. var camera2 = cameras[ j ];
  14510. if ( object.layers.test( camera2.layers ) ) {
  14511. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14512. currentRenderState.setupLights( camera2 );
  14513. renderObject( object, scene, camera2, geometry, material, group );
  14514. }
  14515. }
  14516. } else {
  14517. _currentArrayCamera = null;
  14518. renderObject( object, scene, camera, geometry, material, group );
  14519. }
  14520. }
  14521. }
  14522. function renderObject( object, scene, camera, geometry, material, group ) {
  14523. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14524. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14525. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14526. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14527. if ( object.isImmediateRenderObject ) {
  14528. state.setMaterial( material );
  14529. var program = setProgram( camera, scene.fog, material, object );
  14530. _currentGeometryProgram.geometry = null;
  14531. _currentGeometryProgram.program = null;
  14532. _currentGeometryProgram.wireframe = false;
  14533. renderObjectImmediate( object, program );
  14534. } else {
  14535. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14536. }
  14537. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14538. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14539. }
  14540. function initMaterial( material, fog, object ) {
  14541. var materialProperties = properties.get( material );
  14542. var lights = currentRenderState.state.lights;
  14543. var shadowsArray = currentRenderState.state.shadowsArray;
  14544. var lightsStateVersion = lights.state.version;
  14545. var parameters = programCache.getParameters(
  14546. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14547. var code = programCache.getProgramCode( material, parameters );
  14548. var program = materialProperties.program;
  14549. var programChange = true;
  14550. if ( program === undefined ) {
  14551. // new material
  14552. material.addEventListener( 'dispose', onMaterialDispose );
  14553. } else if ( program.code !== code ) {
  14554. // changed glsl or parameters
  14555. releaseMaterialProgramReference( material );
  14556. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  14557. materialProperties.lightsStateVersion = lightsStateVersion;
  14558. programChange = false;
  14559. } else if ( parameters.shaderID !== undefined ) {
  14560. // same glsl and uniform list
  14561. return;
  14562. } else {
  14563. // only rebuild uniform list
  14564. programChange = false;
  14565. }
  14566. if ( programChange ) {
  14567. if ( parameters.shaderID ) {
  14568. var shader = ShaderLib[ parameters.shaderID ];
  14569. materialProperties.shader = {
  14570. name: material.type,
  14571. uniforms: cloneUniforms( shader.uniforms ),
  14572. vertexShader: shader.vertexShader,
  14573. fragmentShader: shader.fragmentShader
  14574. };
  14575. } else {
  14576. materialProperties.shader = {
  14577. name: material.type,
  14578. uniforms: material.uniforms,
  14579. vertexShader: material.vertexShader,
  14580. fragmentShader: material.fragmentShader
  14581. };
  14582. }
  14583. material.onBeforeCompile( materialProperties.shader, _this );
  14584. // Computing code again as onBeforeCompile may have changed the shaders
  14585. code = programCache.getProgramCode( material, parameters );
  14586. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14587. materialProperties.program = program;
  14588. material.program = program;
  14589. }
  14590. var programAttributes = program.getAttributes();
  14591. if ( material.morphTargets ) {
  14592. material.numSupportedMorphTargets = 0;
  14593. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14594. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14595. material.numSupportedMorphTargets ++;
  14596. }
  14597. }
  14598. }
  14599. if ( material.morphNormals ) {
  14600. material.numSupportedMorphNormals = 0;
  14601. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14602. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14603. material.numSupportedMorphNormals ++;
  14604. }
  14605. }
  14606. }
  14607. var uniforms = materialProperties.shader.uniforms;
  14608. if ( ! material.isShaderMaterial &&
  14609. ! material.isRawShaderMaterial ||
  14610. material.clipping === true ) {
  14611. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14612. materialProperties.numIntersection = _clipping.numIntersection;
  14613. uniforms.clippingPlanes = _clipping.uniform;
  14614. }
  14615. materialProperties.fog = fog;
  14616. // store the light setup it was created for
  14617. materialProperties.lightsStateVersion = lightsStateVersion;
  14618. if ( material.lights ) {
  14619. // wire up the material to this renderer's lighting state
  14620. uniforms.ambientLightColor.value = lights.state.ambient;
  14621. uniforms.lightProbe.value = lights.state.probe;
  14622. uniforms.directionalLights.value = lights.state.directional;
  14623. uniforms.spotLights.value = lights.state.spot;
  14624. uniforms.rectAreaLights.value = lights.state.rectArea;
  14625. uniforms.pointLights.value = lights.state.point;
  14626. uniforms.hemisphereLights.value = lights.state.hemi;
  14627. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14628. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14629. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14630. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14631. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14632. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14633. // TODO (abelnation): add area lights shadow info to uniforms
  14634. }
  14635. var progUniforms = materialProperties.program.getUniforms(),
  14636. uniformsList =
  14637. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14638. materialProperties.uniformsList = uniformsList;
  14639. }
  14640. function setProgram( camera, fog, material, object ) {
  14641. textures.resetTextureUnits();
  14642. var materialProperties = properties.get( material );
  14643. var lights = currentRenderState.state.lights;
  14644. if ( _clippingEnabled ) {
  14645. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14646. var useCache =
  14647. camera === _currentCamera &&
  14648. material.id === _currentMaterialId;
  14649. // we might want to call this function with some ClippingGroup
  14650. // object instead of the material, once it becomes feasible
  14651. // (#8465, #8379)
  14652. _clipping.setState(
  14653. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14654. camera, materialProperties, useCache );
  14655. }
  14656. }
  14657. if ( material.needsUpdate === false ) {
  14658. if ( materialProperties.program === undefined ) {
  14659. material.needsUpdate = true;
  14660. } else if ( material.fog && materialProperties.fog !== fog ) {
  14661. material.needsUpdate = true;
  14662. } else if ( material.lights && materialProperties.lightsStateVersion !== lights.state.version ) {
  14663. material.needsUpdate = true;
  14664. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14665. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14666. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14667. material.needsUpdate = true;
  14668. }
  14669. }
  14670. if ( material.needsUpdate ) {
  14671. initMaterial( material, fog, object );
  14672. material.needsUpdate = false;
  14673. }
  14674. var refreshProgram = false;
  14675. var refreshMaterial = false;
  14676. var refreshLights = false;
  14677. var program = materialProperties.program,
  14678. p_uniforms = program.getUniforms(),
  14679. m_uniforms = materialProperties.shader.uniforms;
  14680. if ( state.useProgram( program.program ) ) {
  14681. refreshProgram = true;
  14682. refreshMaterial = true;
  14683. refreshLights = true;
  14684. }
  14685. if ( material.id !== _currentMaterialId ) {
  14686. _currentMaterialId = material.id;
  14687. refreshMaterial = true;
  14688. }
  14689. if ( refreshProgram || _currentCamera !== camera ) {
  14690. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14691. if ( capabilities.logarithmicDepthBuffer ) {
  14692. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14693. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14694. }
  14695. if ( _currentCamera !== camera ) {
  14696. _currentCamera = camera;
  14697. // lighting uniforms depend on the camera so enforce an update
  14698. // now, in case this material supports lights - or later, when
  14699. // the next material that does gets activated:
  14700. refreshMaterial = true; // set to true on material change
  14701. refreshLights = true; // remains set until update done
  14702. }
  14703. // load material specific uniforms
  14704. // (shader material also gets them for the sake of genericity)
  14705. if ( material.isShaderMaterial ||
  14706. material.isMeshPhongMaterial ||
  14707. material.isMeshStandardMaterial ||
  14708. material.envMap ) {
  14709. var uCamPos = p_uniforms.map.cameraPosition;
  14710. if ( uCamPos !== undefined ) {
  14711. uCamPos.setValue( _gl,
  14712. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14713. }
  14714. }
  14715. if ( material.isMeshPhongMaterial ||
  14716. material.isMeshLambertMaterial ||
  14717. material.isMeshBasicMaterial ||
  14718. material.isMeshStandardMaterial ||
  14719. material.isShaderMaterial ||
  14720. material.skinning ) {
  14721. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14722. }
  14723. }
  14724. // skinning uniforms must be set even if material didn't change
  14725. // auto-setting of texture unit for bone texture must go before other textures
  14726. // not sure why, but otherwise weird things happen
  14727. if ( material.skinning ) {
  14728. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14729. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14730. var skeleton = object.skeleton;
  14731. if ( skeleton ) {
  14732. var bones = skeleton.bones;
  14733. if ( capabilities.floatVertexTextures ) {
  14734. if ( skeleton.boneTexture === undefined ) {
  14735. // layout (1 matrix = 4 pixels)
  14736. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14737. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14738. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14739. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14740. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14741. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14742. size = _Math.ceilPowerOfTwo( size );
  14743. size = Math.max( size, 4 );
  14744. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14745. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14746. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14747. boneTexture.needsUpdate = true;
  14748. skeleton.boneMatrices = boneMatrices;
  14749. skeleton.boneTexture = boneTexture;
  14750. skeleton.boneTextureSize = size;
  14751. }
  14752. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14753. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14754. } else {
  14755. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14756. }
  14757. }
  14758. }
  14759. if ( refreshMaterial ) {
  14760. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14761. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14762. if ( material.lights ) {
  14763. // the current material requires lighting info
  14764. // note: all lighting uniforms are always set correctly
  14765. // they simply reference the renderer's state for their
  14766. // values
  14767. //
  14768. // use the current material's .needsUpdate flags to set
  14769. // the GL state when required
  14770. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14771. }
  14772. // refresh uniforms common to several materials
  14773. if ( fog && material.fog ) {
  14774. refreshUniformsFog( m_uniforms, fog );
  14775. }
  14776. if ( material.isMeshBasicMaterial ) {
  14777. refreshUniformsCommon( m_uniforms, material );
  14778. } else if ( material.isMeshLambertMaterial ) {
  14779. refreshUniformsCommon( m_uniforms, material );
  14780. refreshUniformsLambert( m_uniforms, material );
  14781. } else if ( material.isMeshPhongMaterial ) {
  14782. refreshUniformsCommon( m_uniforms, material );
  14783. if ( material.isMeshToonMaterial ) {
  14784. refreshUniformsToon( m_uniforms, material );
  14785. } else {
  14786. refreshUniformsPhong( m_uniforms, material );
  14787. }
  14788. } else if ( material.isMeshStandardMaterial ) {
  14789. refreshUniformsCommon( m_uniforms, material );
  14790. if ( material.isMeshPhysicalMaterial ) {
  14791. refreshUniformsPhysical( m_uniforms, material );
  14792. } else {
  14793. refreshUniformsStandard( m_uniforms, material );
  14794. }
  14795. } else if ( material.isMeshMatcapMaterial ) {
  14796. refreshUniformsCommon( m_uniforms, material );
  14797. refreshUniformsMatcap( m_uniforms, material );
  14798. } else if ( material.isMeshDepthMaterial ) {
  14799. refreshUniformsCommon( m_uniforms, material );
  14800. refreshUniformsDepth( m_uniforms, material );
  14801. } else if ( material.isMeshDistanceMaterial ) {
  14802. refreshUniformsCommon( m_uniforms, material );
  14803. refreshUniformsDistance( m_uniforms, material );
  14804. } else if ( material.isMeshNormalMaterial ) {
  14805. refreshUniformsCommon( m_uniforms, material );
  14806. refreshUniformsNormal( m_uniforms, material );
  14807. } else if ( material.isLineBasicMaterial ) {
  14808. refreshUniformsLine( m_uniforms, material );
  14809. if ( material.isLineDashedMaterial ) {
  14810. refreshUniformsDash( m_uniforms, material );
  14811. }
  14812. } else if ( material.isPointsMaterial ) {
  14813. refreshUniformsPoints( m_uniforms, material );
  14814. } else if ( material.isSpriteMaterial ) {
  14815. refreshUniformsSprites( m_uniforms, material );
  14816. } else if ( material.isShadowMaterial ) {
  14817. m_uniforms.color.value.copy( material.color );
  14818. m_uniforms.opacity.value = material.opacity;
  14819. }
  14820. // RectAreaLight Texture
  14821. // TODO (mrdoob): Find a nicer implementation
  14822. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14823. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14824. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14825. }
  14826. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14827. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14828. material.uniformsNeedUpdate = false;
  14829. }
  14830. if ( material.isSpriteMaterial ) {
  14831. p_uniforms.setValue( _gl, 'center', object.center );
  14832. }
  14833. // common matrices
  14834. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14835. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14836. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14837. return program;
  14838. }
  14839. // Uniforms (refresh uniforms objects)
  14840. function refreshUniformsCommon( uniforms, material ) {
  14841. uniforms.opacity.value = material.opacity;
  14842. if ( material.color ) {
  14843. uniforms.diffuse.value.copy( material.color );
  14844. }
  14845. if ( material.emissive ) {
  14846. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14847. }
  14848. if ( material.map ) {
  14849. uniforms.map.value = material.map;
  14850. }
  14851. if ( material.alphaMap ) {
  14852. uniforms.alphaMap.value = material.alphaMap;
  14853. }
  14854. if ( material.specularMap ) {
  14855. uniforms.specularMap.value = material.specularMap;
  14856. }
  14857. if ( material.envMap ) {
  14858. uniforms.envMap.value = material.envMap;
  14859. // don't flip CubeTexture envMaps, flip everything else:
  14860. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14861. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14862. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14863. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14864. uniforms.reflectivity.value = material.reflectivity;
  14865. uniforms.refractionRatio.value = material.refractionRatio;
  14866. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14867. }
  14868. if ( material.lightMap ) {
  14869. uniforms.lightMap.value = material.lightMap;
  14870. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14871. }
  14872. if ( material.aoMap ) {
  14873. uniforms.aoMap.value = material.aoMap;
  14874. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14875. }
  14876. // uv repeat and offset setting priorities
  14877. // 1. color map
  14878. // 2. specular map
  14879. // 3. normal map
  14880. // 4. bump map
  14881. // 5. alpha map
  14882. // 6. emissive map
  14883. var uvScaleMap;
  14884. if ( material.map ) {
  14885. uvScaleMap = material.map;
  14886. } else if ( material.specularMap ) {
  14887. uvScaleMap = material.specularMap;
  14888. } else if ( material.displacementMap ) {
  14889. uvScaleMap = material.displacementMap;
  14890. } else if ( material.normalMap ) {
  14891. uvScaleMap = material.normalMap;
  14892. } else if ( material.bumpMap ) {
  14893. uvScaleMap = material.bumpMap;
  14894. } else if ( material.roughnessMap ) {
  14895. uvScaleMap = material.roughnessMap;
  14896. } else if ( material.metalnessMap ) {
  14897. uvScaleMap = material.metalnessMap;
  14898. } else if ( material.alphaMap ) {
  14899. uvScaleMap = material.alphaMap;
  14900. } else if ( material.emissiveMap ) {
  14901. uvScaleMap = material.emissiveMap;
  14902. }
  14903. if ( uvScaleMap !== undefined ) {
  14904. // backwards compatibility
  14905. if ( uvScaleMap.isWebGLRenderTarget ) {
  14906. uvScaleMap = uvScaleMap.texture;
  14907. }
  14908. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14909. uvScaleMap.updateMatrix();
  14910. }
  14911. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14912. }
  14913. }
  14914. function refreshUniformsLine( uniforms, material ) {
  14915. uniforms.diffuse.value.copy( material.color );
  14916. uniforms.opacity.value = material.opacity;
  14917. }
  14918. function refreshUniformsDash( uniforms, material ) {
  14919. uniforms.dashSize.value = material.dashSize;
  14920. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14921. uniforms.scale.value = material.scale;
  14922. }
  14923. function refreshUniformsPoints( uniforms, material ) {
  14924. uniforms.diffuse.value.copy( material.color );
  14925. uniforms.opacity.value = material.opacity;
  14926. uniforms.size.value = material.size * _pixelRatio;
  14927. uniforms.scale.value = _height * 0.5;
  14928. uniforms.map.value = material.map;
  14929. if ( material.map !== null ) {
  14930. if ( material.map.matrixAutoUpdate === true ) {
  14931. material.map.updateMatrix();
  14932. }
  14933. uniforms.uvTransform.value.copy( material.map.matrix );
  14934. }
  14935. }
  14936. function refreshUniformsSprites( uniforms, material ) {
  14937. uniforms.diffuse.value.copy( material.color );
  14938. uniforms.opacity.value = material.opacity;
  14939. uniforms.rotation.value = material.rotation;
  14940. uniforms.map.value = material.map;
  14941. if ( material.map !== null ) {
  14942. if ( material.map.matrixAutoUpdate === true ) {
  14943. material.map.updateMatrix();
  14944. }
  14945. uniforms.uvTransform.value.copy( material.map.matrix );
  14946. }
  14947. }
  14948. function refreshUniformsFog( uniforms, fog ) {
  14949. uniforms.fogColor.value.copy( fog.color );
  14950. if ( fog.isFog ) {
  14951. uniforms.fogNear.value = fog.near;
  14952. uniforms.fogFar.value = fog.far;
  14953. } else if ( fog.isFogExp2 ) {
  14954. uniforms.fogDensity.value = fog.density;
  14955. }
  14956. }
  14957. function refreshUniformsLambert( uniforms, material ) {
  14958. if ( material.emissiveMap ) {
  14959. uniforms.emissiveMap.value = material.emissiveMap;
  14960. }
  14961. }
  14962. function refreshUniformsPhong( uniforms, material ) {
  14963. uniforms.specular.value.copy( material.specular );
  14964. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14965. if ( material.emissiveMap ) {
  14966. uniforms.emissiveMap.value = material.emissiveMap;
  14967. }
  14968. if ( material.bumpMap ) {
  14969. uniforms.bumpMap.value = material.bumpMap;
  14970. uniforms.bumpScale.value = material.bumpScale;
  14971. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14972. }
  14973. if ( material.normalMap ) {
  14974. uniforms.normalMap.value = material.normalMap;
  14975. uniforms.normalScale.value.copy( material.normalScale );
  14976. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14977. }
  14978. if ( material.displacementMap ) {
  14979. uniforms.displacementMap.value = material.displacementMap;
  14980. uniforms.displacementScale.value = material.displacementScale;
  14981. uniforms.displacementBias.value = material.displacementBias;
  14982. }
  14983. }
  14984. function refreshUniformsToon( uniforms, material ) {
  14985. refreshUniformsPhong( uniforms, material );
  14986. if ( material.gradientMap ) {
  14987. uniforms.gradientMap.value = material.gradientMap;
  14988. }
  14989. }
  14990. function refreshUniformsStandard( uniforms, material ) {
  14991. uniforms.roughness.value = material.roughness;
  14992. uniforms.metalness.value = material.metalness;
  14993. if ( material.roughnessMap ) {
  14994. uniforms.roughnessMap.value = material.roughnessMap;
  14995. }
  14996. if ( material.metalnessMap ) {
  14997. uniforms.metalnessMap.value = material.metalnessMap;
  14998. }
  14999. if ( material.emissiveMap ) {
  15000. uniforms.emissiveMap.value = material.emissiveMap;
  15001. }
  15002. if ( material.bumpMap ) {
  15003. uniforms.bumpMap.value = material.bumpMap;
  15004. uniforms.bumpScale.value = material.bumpScale;
  15005. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15006. }
  15007. if ( material.normalMap ) {
  15008. uniforms.normalMap.value = material.normalMap;
  15009. uniforms.normalScale.value.copy( material.normalScale );
  15010. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15011. }
  15012. if ( material.displacementMap ) {
  15013. uniforms.displacementMap.value = material.displacementMap;
  15014. uniforms.displacementScale.value = material.displacementScale;
  15015. uniforms.displacementBias.value = material.displacementBias;
  15016. }
  15017. if ( material.envMap ) {
  15018. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15019. uniforms.envMapIntensity.value = material.envMapIntensity;
  15020. }
  15021. }
  15022. function refreshUniformsPhysical( uniforms, material ) {
  15023. refreshUniformsStandard( uniforms, material );
  15024. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  15025. uniforms.clearCoat.value = material.clearCoat;
  15026. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15027. if ( material.clearCoatNormalMap ) {
  15028. uniforms.clearCoatNormalScale.value.copy( material.clearCoatNormalScale );
  15029. uniforms.clearCoatNormalMap.value = material.clearCoatNormalMap;
  15030. if ( material.side === BackSide ) {
  15031. uniforms.clearCoatNormalScale.value.negate();
  15032. }
  15033. }
  15034. }
  15035. function refreshUniformsMatcap( uniforms, material ) {
  15036. if ( material.matcap ) {
  15037. uniforms.matcap.value = material.matcap;
  15038. }
  15039. if ( material.bumpMap ) {
  15040. uniforms.bumpMap.value = material.bumpMap;
  15041. uniforms.bumpScale.value = material.bumpScale;
  15042. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15043. }
  15044. if ( material.normalMap ) {
  15045. uniforms.normalMap.value = material.normalMap;
  15046. uniforms.normalScale.value.copy( material.normalScale );
  15047. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15048. }
  15049. if ( material.displacementMap ) {
  15050. uniforms.displacementMap.value = material.displacementMap;
  15051. uniforms.displacementScale.value = material.displacementScale;
  15052. uniforms.displacementBias.value = material.displacementBias;
  15053. }
  15054. }
  15055. function refreshUniformsDepth( uniforms, material ) {
  15056. if ( material.displacementMap ) {
  15057. uniforms.displacementMap.value = material.displacementMap;
  15058. uniforms.displacementScale.value = material.displacementScale;
  15059. uniforms.displacementBias.value = material.displacementBias;
  15060. }
  15061. }
  15062. function refreshUniformsDistance( uniforms, material ) {
  15063. if ( material.displacementMap ) {
  15064. uniforms.displacementMap.value = material.displacementMap;
  15065. uniforms.displacementScale.value = material.displacementScale;
  15066. uniforms.displacementBias.value = material.displacementBias;
  15067. }
  15068. uniforms.referencePosition.value.copy( material.referencePosition );
  15069. uniforms.nearDistance.value = material.nearDistance;
  15070. uniforms.farDistance.value = material.farDistance;
  15071. }
  15072. function refreshUniformsNormal( uniforms, material ) {
  15073. if ( material.bumpMap ) {
  15074. uniforms.bumpMap.value = material.bumpMap;
  15075. uniforms.bumpScale.value = material.bumpScale;
  15076. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15077. }
  15078. if ( material.normalMap ) {
  15079. uniforms.normalMap.value = material.normalMap;
  15080. uniforms.normalScale.value.copy( material.normalScale );
  15081. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15082. }
  15083. if ( material.displacementMap ) {
  15084. uniforms.displacementMap.value = material.displacementMap;
  15085. uniforms.displacementScale.value = material.displacementScale;
  15086. uniforms.displacementBias.value = material.displacementBias;
  15087. }
  15088. }
  15089. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15090. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15091. uniforms.ambientLightColor.needsUpdate = value;
  15092. uniforms.lightProbe.needsUpdate = value;
  15093. uniforms.directionalLights.needsUpdate = value;
  15094. uniforms.pointLights.needsUpdate = value;
  15095. uniforms.spotLights.needsUpdate = value;
  15096. uniforms.rectAreaLights.needsUpdate = value;
  15097. uniforms.hemisphereLights.needsUpdate = value;
  15098. }
  15099. //
  15100. this.setFramebuffer = function ( value ) {
  15101. if ( _framebuffer !== value ) _gl.bindFramebuffer( 36160, value );
  15102. _framebuffer = value;
  15103. };
  15104. this.getActiveCubeFace = function () {
  15105. return _currentActiveCubeFace;
  15106. };
  15107. this.getActiveMipmapLevel = function () {
  15108. return _currentActiveMipmapLevel;
  15109. };
  15110. this.getRenderTarget = function () {
  15111. return _currentRenderTarget;
  15112. };
  15113. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15114. _currentRenderTarget = renderTarget;
  15115. _currentActiveCubeFace = activeCubeFace;
  15116. _currentActiveMipmapLevel = activeMipmapLevel;
  15117. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15118. textures.setupRenderTarget( renderTarget );
  15119. }
  15120. var framebuffer = _framebuffer;
  15121. var isCube = false;
  15122. if ( renderTarget ) {
  15123. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15124. if ( renderTarget.isWebGLRenderTargetCube ) {
  15125. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15126. isCube = true;
  15127. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15128. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15129. } else {
  15130. framebuffer = __webglFramebuffer;
  15131. }
  15132. _currentViewport.copy( renderTarget.viewport );
  15133. _currentScissor.copy( renderTarget.scissor );
  15134. _currentScissorTest = renderTarget.scissorTest;
  15135. } else {
  15136. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15137. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15138. _currentScissorTest = _scissorTest;
  15139. }
  15140. if ( _currentFramebuffer !== framebuffer ) {
  15141. _gl.bindFramebuffer( 36160, framebuffer );
  15142. _currentFramebuffer = framebuffer;
  15143. }
  15144. state.viewport( _currentViewport );
  15145. state.scissor( _currentScissor );
  15146. state.setScissorTest( _currentScissorTest );
  15147. if ( isCube ) {
  15148. var textureProperties = properties.get( renderTarget.texture );
  15149. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15150. }
  15151. };
  15152. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15153. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15154. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15155. return;
  15156. }
  15157. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15158. if ( renderTarget.isWebGLRenderTargetCube && activeCubeFaceIndex !== undefined ) {
  15159. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15160. }
  15161. if ( framebuffer ) {
  15162. var restore = false;
  15163. if ( framebuffer !== _currentFramebuffer ) {
  15164. _gl.bindFramebuffer( 36160, framebuffer );
  15165. restore = true;
  15166. }
  15167. try {
  15168. var texture = renderTarget.texture;
  15169. var textureFormat = texture.format;
  15170. var textureType = texture.type;
  15171. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15172. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15173. return;
  15174. }
  15175. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15176. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15177. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15178. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15179. return;
  15180. }
  15181. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15182. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15183. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15184. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15185. }
  15186. } else {
  15187. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15188. }
  15189. } finally {
  15190. if ( restore ) {
  15191. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15192. }
  15193. }
  15194. }
  15195. };
  15196. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15197. var width = texture.image.width;
  15198. var height = texture.image.height;
  15199. var glFormat = utils.convert( texture.format );
  15200. textures.setTexture2D( texture, 0 );
  15201. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  15202. };
  15203. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15204. var width = srcTexture.image.width;
  15205. var height = srcTexture.image.height;
  15206. var glFormat = utils.convert( dstTexture.format );
  15207. var glType = utils.convert( dstTexture.type );
  15208. textures.setTexture2D( dstTexture, 0 );
  15209. if ( srcTexture.isDataTexture ) {
  15210. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15211. } else {
  15212. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  15213. }
  15214. };
  15215. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15216. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15217. }
  15218. }
  15219. /**
  15220. * @author mrdoob / http://mrdoob.com/
  15221. * @author alteredq / http://alteredqualia.com/
  15222. */
  15223. function FogExp2( color, density ) {
  15224. this.name = '';
  15225. this.color = new Color( color );
  15226. this.density = ( density !== undefined ) ? density : 0.00025;
  15227. }
  15228. Object.assign( FogExp2.prototype, {
  15229. isFogExp2: true,
  15230. clone: function () {
  15231. return new FogExp2( this.color, this.density );
  15232. },
  15233. toJSON: function ( /* meta */ ) {
  15234. return {
  15235. type: 'FogExp2',
  15236. color: this.color.getHex(),
  15237. density: this.density
  15238. };
  15239. }
  15240. } );
  15241. /**
  15242. * @author mrdoob / http://mrdoob.com/
  15243. * @author alteredq / http://alteredqualia.com/
  15244. */
  15245. function Fog( color, near, far ) {
  15246. this.name = '';
  15247. this.color = new Color( color );
  15248. this.near = ( near !== undefined ) ? near : 1;
  15249. this.far = ( far !== undefined ) ? far : 1000;
  15250. }
  15251. Object.assign( Fog.prototype, {
  15252. isFog: true,
  15253. clone: function () {
  15254. return new Fog( this.color, this.near, this.far );
  15255. },
  15256. toJSON: function ( /* meta */ ) {
  15257. return {
  15258. type: 'Fog',
  15259. color: this.color.getHex(),
  15260. near: this.near,
  15261. far: this.far
  15262. };
  15263. }
  15264. } );
  15265. /**
  15266. * @author benaadams / https://twitter.com/ben_a_adams
  15267. */
  15268. function InterleavedBuffer( array, stride ) {
  15269. this.array = array;
  15270. this.stride = stride;
  15271. this.count = array !== undefined ? array.length / stride : 0;
  15272. this.dynamic = false;
  15273. this.updateRange = { offset: 0, count: - 1 };
  15274. this.version = 0;
  15275. }
  15276. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15277. set: function ( value ) {
  15278. if ( value === true ) this.version ++;
  15279. }
  15280. } );
  15281. Object.assign( InterleavedBuffer.prototype, {
  15282. isInterleavedBuffer: true,
  15283. onUploadCallback: function () {},
  15284. setArray: function ( array ) {
  15285. if ( Array.isArray( array ) ) {
  15286. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15287. }
  15288. this.count = array !== undefined ? array.length / this.stride : 0;
  15289. this.array = array;
  15290. return this;
  15291. },
  15292. setDynamic: function ( value ) {
  15293. this.dynamic = value;
  15294. return this;
  15295. },
  15296. copy: function ( source ) {
  15297. this.array = new source.array.constructor( source.array );
  15298. this.count = source.count;
  15299. this.stride = source.stride;
  15300. this.dynamic = source.dynamic;
  15301. return this;
  15302. },
  15303. copyAt: function ( index1, attribute, index2 ) {
  15304. index1 *= this.stride;
  15305. index2 *= attribute.stride;
  15306. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15307. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15308. }
  15309. return this;
  15310. },
  15311. set: function ( value, offset ) {
  15312. if ( offset === undefined ) offset = 0;
  15313. this.array.set( value, offset );
  15314. return this;
  15315. },
  15316. clone: function () {
  15317. return new this.constructor().copy( this );
  15318. },
  15319. onUpload: function ( callback ) {
  15320. this.onUploadCallback = callback;
  15321. return this;
  15322. }
  15323. } );
  15324. /**
  15325. * @author benaadams / https://twitter.com/ben_a_adams
  15326. */
  15327. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15328. this.data = interleavedBuffer;
  15329. this.itemSize = itemSize;
  15330. this.offset = offset;
  15331. this.normalized = normalized === true;
  15332. }
  15333. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15334. count: {
  15335. get: function () {
  15336. return this.data.count;
  15337. }
  15338. },
  15339. array: {
  15340. get: function () {
  15341. return this.data.array;
  15342. }
  15343. }
  15344. } );
  15345. Object.assign( InterleavedBufferAttribute.prototype, {
  15346. isInterleavedBufferAttribute: true,
  15347. setX: function ( index, x ) {
  15348. this.data.array[ index * this.data.stride + this.offset ] = x;
  15349. return this;
  15350. },
  15351. setY: function ( index, y ) {
  15352. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15353. return this;
  15354. },
  15355. setZ: function ( index, z ) {
  15356. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15357. return this;
  15358. },
  15359. setW: function ( index, w ) {
  15360. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15361. return this;
  15362. },
  15363. getX: function ( index ) {
  15364. return this.data.array[ index * this.data.stride + this.offset ];
  15365. },
  15366. getY: function ( index ) {
  15367. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15368. },
  15369. getZ: function ( index ) {
  15370. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15371. },
  15372. getW: function ( index ) {
  15373. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15374. },
  15375. setXY: function ( index, x, y ) {
  15376. index = index * this.data.stride + this.offset;
  15377. this.data.array[ index + 0 ] = x;
  15378. this.data.array[ index + 1 ] = y;
  15379. return this;
  15380. },
  15381. setXYZ: function ( index, x, y, z ) {
  15382. index = index * this.data.stride + this.offset;
  15383. this.data.array[ index + 0 ] = x;
  15384. this.data.array[ index + 1 ] = y;
  15385. this.data.array[ index + 2 ] = z;
  15386. return this;
  15387. },
  15388. setXYZW: function ( index, x, y, z, w ) {
  15389. index = index * this.data.stride + this.offset;
  15390. this.data.array[ index + 0 ] = x;
  15391. this.data.array[ index + 1 ] = y;
  15392. this.data.array[ index + 2 ] = z;
  15393. this.data.array[ index + 3 ] = w;
  15394. return this;
  15395. }
  15396. } );
  15397. /**
  15398. * @author alteredq / http://alteredqualia.com/
  15399. *
  15400. * parameters = {
  15401. * color: <hex>,
  15402. * map: new THREE.Texture( <Image> ),
  15403. * rotation: <float>,
  15404. * sizeAttenuation: <bool>
  15405. * }
  15406. */
  15407. function SpriteMaterial( parameters ) {
  15408. Material.call( this );
  15409. this.type = 'SpriteMaterial';
  15410. this.color = new Color( 0xffffff );
  15411. this.map = null;
  15412. this.rotation = 0;
  15413. this.sizeAttenuation = true;
  15414. this.lights = false;
  15415. this.transparent = true;
  15416. this.setValues( parameters );
  15417. }
  15418. SpriteMaterial.prototype = Object.create( Material.prototype );
  15419. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15420. SpriteMaterial.prototype.isSpriteMaterial = true;
  15421. SpriteMaterial.prototype.copy = function ( source ) {
  15422. Material.prototype.copy.call( this, source );
  15423. this.color.copy( source.color );
  15424. this.map = source.map;
  15425. this.rotation = source.rotation;
  15426. this.sizeAttenuation = source.sizeAttenuation;
  15427. return this;
  15428. };
  15429. /**
  15430. * @author mikael emtinger / http://gomo.se/
  15431. * @author alteredq / http://alteredqualia.com/
  15432. */
  15433. var _geometry;
  15434. var _intersectPoint, _worldScale, _mvPosition;
  15435. var _alignedPosition, _rotatedPosition, _viewWorldMatrix;
  15436. var _vA$1, _vB$1, _vC$1;
  15437. var _uvA$1, _uvB$1, _uvC$1;
  15438. function Sprite( material ) {
  15439. Object3D.call( this );
  15440. this.type = 'Sprite';
  15441. if ( _geometry === undefined ) {
  15442. _geometry = new BufferGeometry();
  15443. var float32Array = new Float32Array( [
  15444. - 0.5, - 0.5, 0, 0, 0,
  15445. 0.5, - 0.5, 0, 1, 0,
  15446. 0.5, 0.5, 0, 1, 1,
  15447. - 0.5, 0.5, 0, 0, 1
  15448. ] );
  15449. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15450. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15451. _geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15452. _geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15453. }
  15454. this.geometry = _geometry;
  15455. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15456. this.center = new Vector2( 0.5, 0.5 );
  15457. }
  15458. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15459. constructor: Sprite,
  15460. isSprite: true,
  15461. raycast: function ( raycaster, intersects ) {
  15462. if ( _uvC$1 === undefined ) {
  15463. _intersectPoint = new Vector3();
  15464. _worldScale = new Vector3();
  15465. _mvPosition = new Vector3();
  15466. _alignedPosition = new Vector2();
  15467. _rotatedPosition = new Vector2();
  15468. _viewWorldMatrix = new Matrix4();
  15469. _vA$1 = new Vector3();
  15470. _vB$1 = new Vector3();
  15471. _vC$1 = new Vector3();
  15472. _uvA$1 = new Vector2();
  15473. _uvB$1 = new Vector2();
  15474. _uvC$1 = new Vector2();
  15475. }
  15476. _worldScale.setFromMatrixScale( this.matrixWorld );
  15477. _viewWorldMatrix.copy( raycaster._camera.matrixWorld );
  15478. this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
  15479. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15480. if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15481. _worldScale.multiplyScalar( - _mvPosition.z );
  15482. }
  15483. var rotation = this.material.rotation;
  15484. var sin, cos;
  15485. if ( rotation !== 0 ) {
  15486. cos = Math.cos( rotation );
  15487. sin = Math.sin( rotation );
  15488. }
  15489. var center = this.center;
  15490. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15491. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15492. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15493. _uvA$1.set( 0, 0 );
  15494. _uvB$1.set( 1, 0 );
  15495. _uvC$1.set( 1, 1 );
  15496. // check first triangle
  15497. var intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  15498. if ( intersect === null ) {
  15499. // check second triangle
  15500. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15501. _uvB$1.set( 0, 1 );
  15502. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  15503. if ( intersect === null ) {
  15504. return;
  15505. }
  15506. }
  15507. var distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  15508. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15509. intersects.push( {
  15510. distance: distance,
  15511. point: _intersectPoint.clone(),
  15512. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  15513. face: null,
  15514. object: this
  15515. } );
  15516. },
  15517. clone: function () {
  15518. return new this.constructor( this.material ).copy( this );
  15519. },
  15520. copy: function ( source ) {
  15521. Object3D.prototype.copy.call( this, source );
  15522. if ( source.center !== undefined ) this.center.copy( source.center );
  15523. return this;
  15524. }
  15525. } );
  15526. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15527. // compute position in camera space
  15528. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15529. // to check if rotation is not zero
  15530. if ( sin !== undefined ) {
  15531. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  15532. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  15533. } else {
  15534. _rotatedPosition.copy( _alignedPosition );
  15535. }
  15536. vertexPosition.copy( mvPosition );
  15537. vertexPosition.x += _rotatedPosition.x;
  15538. vertexPosition.y += _rotatedPosition.y;
  15539. // transform to world space
  15540. vertexPosition.applyMatrix4( _viewWorldMatrix );
  15541. }
  15542. /**
  15543. * @author mikael emtinger / http://gomo.se/
  15544. * @author alteredq / http://alteredqualia.com/
  15545. * @author mrdoob / http://mrdoob.com/
  15546. */
  15547. var _v1$4, _v2$2;
  15548. function LOD() {
  15549. Object3D.call( this );
  15550. this.type = 'LOD';
  15551. Object.defineProperties( this, {
  15552. levels: {
  15553. enumerable: true,
  15554. value: []
  15555. }
  15556. } );
  15557. this.autoUpdate = true;
  15558. }
  15559. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15560. constructor: LOD,
  15561. isLOD: true,
  15562. copy: function ( source ) {
  15563. Object3D.prototype.copy.call( this, source, false );
  15564. var levels = source.levels;
  15565. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15566. var level = levels[ i ];
  15567. this.addLevel( level.object.clone(), level.distance );
  15568. }
  15569. return this;
  15570. },
  15571. addLevel: function ( object, distance ) {
  15572. if ( distance === undefined ) distance = 0;
  15573. distance = Math.abs( distance );
  15574. var levels = this.levels;
  15575. for ( var l = 0; l < levels.length; l ++ ) {
  15576. if ( distance < levels[ l ].distance ) {
  15577. break;
  15578. }
  15579. }
  15580. levels.splice( l, 0, { distance: distance, object: object } );
  15581. this.add( object );
  15582. return this;
  15583. },
  15584. getObjectForDistance: function ( distance ) {
  15585. var levels = this.levels;
  15586. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15587. if ( distance < levels[ i ].distance ) {
  15588. break;
  15589. }
  15590. }
  15591. return levels[ i - 1 ].object;
  15592. },
  15593. raycast: function ( raycaster, intersects ) {
  15594. if ( _v1$4 === undefined ) _v1$4 = new Vector3();
  15595. _v1$4.setFromMatrixPosition( this.matrixWorld );
  15596. var distance = raycaster.ray.origin.distanceTo( _v1$4 );
  15597. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15598. },
  15599. update: function ( camera ) {
  15600. if ( _v2$2 === undefined ) {
  15601. _v1$4 = new Vector3();
  15602. _v2$2 = new Vector3();
  15603. }
  15604. var levels = this.levels;
  15605. if ( levels.length > 1 ) {
  15606. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  15607. _v2$2.setFromMatrixPosition( this.matrixWorld );
  15608. var distance = _v1$4.distanceTo( _v2$2 );
  15609. levels[ 0 ].object.visible = true;
  15610. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15611. if ( distance >= levels[ i ].distance ) {
  15612. levels[ i - 1 ].object.visible = false;
  15613. levels[ i ].object.visible = true;
  15614. } else {
  15615. break;
  15616. }
  15617. }
  15618. for ( ; i < l; i ++ ) {
  15619. levels[ i ].object.visible = false;
  15620. }
  15621. }
  15622. },
  15623. toJSON: function ( meta ) {
  15624. var data = Object3D.prototype.toJSON.call( this, meta );
  15625. data.object.levels = [];
  15626. var levels = this.levels;
  15627. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15628. var level = levels[ i ];
  15629. data.object.levels.push( {
  15630. object: level.object.uuid,
  15631. distance: level.distance
  15632. } );
  15633. }
  15634. return data;
  15635. }
  15636. } );
  15637. /**
  15638. * @author mikael emtinger / http://gomo.se/
  15639. * @author alteredq / http://alteredqualia.com/
  15640. * @author ikerr / http://verold.com
  15641. */
  15642. function SkinnedMesh( geometry, material ) {
  15643. if ( geometry && geometry.isGeometry ) {
  15644. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15645. }
  15646. Mesh.call( this, geometry, material );
  15647. this.type = 'SkinnedMesh';
  15648. this.bindMode = 'attached';
  15649. this.bindMatrix = new Matrix4();
  15650. this.bindMatrixInverse = new Matrix4();
  15651. }
  15652. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15653. constructor: SkinnedMesh,
  15654. isSkinnedMesh: true,
  15655. bind: function ( skeleton, bindMatrix ) {
  15656. this.skeleton = skeleton;
  15657. if ( bindMatrix === undefined ) {
  15658. this.updateMatrixWorld( true );
  15659. this.skeleton.calculateInverses();
  15660. bindMatrix = this.matrixWorld;
  15661. }
  15662. this.bindMatrix.copy( bindMatrix );
  15663. this.bindMatrixInverse.getInverse( bindMatrix );
  15664. },
  15665. pose: function () {
  15666. this.skeleton.pose();
  15667. },
  15668. normalizeSkinWeights: function () {
  15669. var vector = new Vector4();
  15670. var skinWeight = this.geometry.attributes.skinWeight;
  15671. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15672. vector.x = skinWeight.getX( i );
  15673. vector.y = skinWeight.getY( i );
  15674. vector.z = skinWeight.getZ( i );
  15675. vector.w = skinWeight.getW( i );
  15676. var scale = 1.0 / vector.manhattanLength();
  15677. if ( scale !== Infinity ) {
  15678. vector.multiplyScalar( scale );
  15679. } else {
  15680. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15681. }
  15682. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15683. }
  15684. },
  15685. updateMatrixWorld: function ( force ) {
  15686. Mesh.prototype.updateMatrixWorld.call( this, force );
  15687. if ( this.bindMode === 'attached' ) {
  15688. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15689. } else if ( this.bindMode === 'detached' ) {
  15690. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15691. } else {
  15692. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15693. }
  15694. },
  15695. clone: function () {
  15696. return new this.constructor( this.geometry, this.material ).copy( this );
  15697. }
  15698. } );
  15699. /**
  15700. * @author mikael emtinger / http://gomo.se/
  15701. * @author alteredq / http://alteredqualia.com/
  15702. * @author michael guerrero / http://realitymeltdown.com
  15703. * @author ikerr / http://verold.com
  15704. */
  15705. var _offsetMatrix, _identityMatrix;
  15706. function Skeleton( bones, boneInverses ) {
  15707. // copy the bone array
  15708. bones = bones || [];
  15709. this.bones = bones.slice( 0 );
  15710. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15711. // use the supplied bone inverses or calculate the inverses
  15712. if ( boneInverses === undefined ) {
  15713. this.calculateInverses();
  15714. } else {
  15715. if ( this.bones.length === boneInverses.length ) {
  15716. this.boneInverses = boneInverses.slice( 0 );
  15717. } else {
  15718. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15719. this.boneInverses = [];
  15720. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15721. this.boneInverses.push( new Matrix4() );
  15722. }
  15723. }
  15724. }
  15725. }
  15726. Object.assign( Skeleton.prototype, {
  15727. calculateInverses: function () {
  15728. this.boneInverses = [];
  15729. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15730. var inverse = new Matrix4();
  15731. if ( this.bones[ i ] ) {
  15732. inverse.getInverse( this.bones[ i ].matrixWorld );
  15733. }
  15734. this.boneInverses.push( inverse );
  15735. }
  15736. },
  15737. pose: function () {
  15738. var bone, i, il;
  15739. // recover the bind-time world matrices
  15740. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15741. bone = this.bones[ i ];
  15742. if ( bone ) {
  15743. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15744. }
  15745. }
  15746. // compute the local matrices, positions, rotations and scales
  15747. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15748. bone = this.bones[ i ];
  15749. if ( bone ) {
  15750. if ( bone.parent && bone.parent.isBone ) {
  15751. bone.matrix.getInverse( bone.parent.matrixWorld );
  15752. bone.matrix.multiply( bone.matrixWorld );
  15753. } else {
  15754. bone.matrix.copy( bone.matrixWorld );
  15755. }
  15756. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15757. }
  15758. }
  15759. },
  15760. update: function () {
  15761. if ( _identityMatrix === undefined ) {
  15762. _offsetMatrix = new Matrix4();
  15763. _identityMatrix = new Matrix4();
  15764. }
  15765. var bones = this.bones;
  15766. var boneInverses = this.boneInverses;
  15767. var boneMatrices = this.boneMatrices;
  15768. var boneTexture = this.boneTexture;
  15769. // flatten bone matrices to array
  15770. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15771. // compute the offset between the current and the original transform
  15772. var matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  15773. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15774. _offsetMatrix.toArray( boneMatrices, i * 16 );
  15775. }
  15776. if ( boneTexture !== undefined ) {
  15777. boneTexture.needsUpdate = true;
  15778. }
  15779. },
  15780. clone: function () {
  15781. return new Skeleton( this.bones, this.boneInverses );
  15782. },
  15783. getBoneByName: function ( name ) {
  15784. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15785. var bone = this.bones[ i ];
  15786. if ( bone.name === name ) {
  15787. return bone;
  15788. }
  15789. }
  15790. return undefined;
  15791. }
  15792. } );
  15793. /**
  15794. * @author mikael emtinger / http://gomo.se/
  15795. * @author alteredq / http://alteredqualia.com/
  15796. * @author ikerr / http://verold.com
  15797. */
  15798. function Bone() {
  15799. Object3D.call( this );
  15800. this.type = 'Bone';
  15801. }
  15802. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15803. constructor: Bone,
  15804. isBone: true
  15805. } );
  15806. /**
  15807. * @author mrdoob / http://mrdoob.com/
  15808. * @author alteredq / http://alteredqualia.com/
  15809. *
  15810. * parameters = {
  15811. * color: <hex>,
  15812. * opacity: <float>,
  15813. *
  15814. * linewidth: <float>,
  15815. * linecap: "round",
  15816. * linejoin: "round"
  15817. * }
  15818. */
  15819. function LineBasicMaterial( parameters ) {
  15820. Material.call( this );
  15821. this.type = 'LineBasicMaterial';
  15822. this.color = new Color( 0xffffff );
  15823. this.linewidth = 1;
  15824. this.linecap = 'round';
  15825. this.linejoin = 'round';
  15826. this.lights = false;
  15827. this.setValues( parameters );
  15828. }
  15829. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15830. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15831. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15832. LineBasicMaterial.prototype.copy = function ( source ) {
  15833. Material.prototype.copy.call( this, source );
  15834. this.color.copy( source.color );
  15835. this.linewidth = source.linewidth;
  15836. this.linecap = source.linecap;
  15837. this.linejoin = source.linejoin;
  15838. return this;
  15839. };
  15840. /**
  15841. * @author mrdoob / http://mrdoob.com/
  15842. */
  15843. var _start, _end;
  15844. var _inverseMatrix$1, _ray$1, _sphere$2;
  15845. function Line( geometry, material, mode ) {
  15846. if ( mode === 1 ) {
  15847. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15848. }
  15849. Object3D.call( this );
  15850. this.type = 'Line';
  15851. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15852. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15853. }
  15854. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15855. constructor: Line,
  15856. isLine: true,
  15857. computeLineDistances: function () {
  15858. if ( _end === undefined ) {
  15859. _start = new Vector3();
  15860. _end = new Vector3();
  15861. }
  15862. var geometry = this.geometry;
  15863. if ( geometry.isBufferGeometry ) {
  15864. // we assume non-indexed geometry
  15865. if ( geometry.index === null ) {
  15866. var positionAttribute = geometry.attributes.position;
  15867. var lineDistances = [ 0 ];
  15868. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15869. _start.fromBufferAttribute( positionAttribute, i - 1 );
  15870. _end.fromBufferAttribute( positionAttribute, i );
  15871. lineDistances[ i ] = lineDistances[ i - 1 ];
  15872. lineDistances[ i ] += _start.distanceTo( _end );
  15873. }
  15874. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15875. } else {
  15876. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15877. }
  15878. } else if ( geometry.isGeometry ) {
  15879. var vertices = geometry.vertices;
  15880. var lineDistances = geometry.lineDistances;
  15881. lineDistances[ 0 ] = 0;
  15882. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15883. lineDistances[ i ] = lineDistances[ i - 1 ];
  15884. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15885. }
  15886. }
  15887. return this;
  15888. },
  15889. raycast: function ( raycaster, intersects ) {
  15890. if ( _sphere$2 === undefined ) {
  15891. _inverseMatrix$1 = new Matrix4();
  15892. _ray$1 = new Ray();
  15893. _sphere$2 = new Sphere();
  15894. }
  15895. var precision = raycaster.linePrecision;
  15896. var geometry = this.geometry;
  15897. var matrixWorld = this.matrixWorld;
  15898. // Checking boundingSphere distance to ray
  15899. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15900. _sphere$2.copy( geometry.boundingSphere );
  15901. _sphere$2.applyMatrix4( matrixWorld );
  15902. _sphere$2.radius += precision;
  15903. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
  15904. //
  15905. _inverseMatrix$1.getInverse( matrixWorld );
  15906. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  15907. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15908. var localPrecisionSq = localPrecision * localPrecision;
  15909. var vStart = new Vector3();
  15910. var vEnd = new Vector3();
  15911. var interSegment = new Vector3();
  15912. var interRay = new Vector3();
  15913. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15914. if ( geometry.isBufferGeometry ) {
  15915. var index = geometry.index;
  15916. var attributes = geometry.attributes;
  15917. var positions = attributes.position.array;
  15918. if ( index !== null ) {
  15919. var indices = index.array;
  15920. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15921. var a = indices[ i ];
  15922. var b = indices[ i + 1 ];
  15923. vStart.fromArray( positions, a * 3 );
  15924. vEnd.fromArray( positions, b * 3 );
  15925. var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15926. if ( distSq > localPrecisionSq ) continue;
  15927. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15928. var distance = raycaster.ray.origin.distanceTo( interRay );
  15929. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15930. intersects.push( {
  15931. distance: distance,
  15932. // What do we want? intersection point on the ray or on the segment??
  15933. // point: raycaster.ray.at( distance ),
  15934. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15935. index: i,
  15936. face: null,
  15937. faceIndex: null,
  15938. object: this
  15939. } );
  15940. }
  15941. } else {
  15942. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15943. vStart.fromArray( positions, 3 * i );
  15944. vEnd.fromArray( positions, 3 * i + 3 );
  15945. var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15946. if ( distSq > localPrecisionSq ) continue;
  15947. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15948. var distance = raycaster.ray.origin.distanceTo( interRay );
  15949. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15950. intersects.push( {
  15951. distance: distance,
  15952. // What do we want? intersection point on the ray or on the segment??
  15953. // point: raycaster.ray.at( distance ),
  15954. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15955. index: i,
  15956. face: null,
  15957. faceIndex: null,
  15958. object: this
  15959. } );
  15960. }
  15961. }
  15962. } else if ( geometry.isGeometry ) {
  15963. var vertices = geometry.vertices;
  15964. var nbVertices = vertices.length;
  15965. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15966. var distSq = _ray$1.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15967. if ( distSq > localPrecisionSq ) continue;
  15968. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15969. var distance = raycaster.ray.origin.distanceTo( interRay );
  15970. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15971. intersects.push( {
  15972. distance: distance,
  15973. // What do we want? intersection point on the ray or on the segment??
  15974. // point: raycaster.ray.at( distance ),
  15975. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15976. index: i,
  15977. face: null,
  15978. faceIndex: null,
  15979. object: this
  15980. } );
  15981. }
  15982. }
  15983. },
  15984. clone: function () {
  15985. return new this.constructor( this.geometry, this.material ).copy( this );
  15986. }
  15987. } );
  15988. /**
  15989. * @author mrdoob / http://mrdoob.com/
  15990. */
  15991. var _start$1, _end$1;
  15992. function LineSegments( geometry, material ) {
  15993. Line.call( this, geometry, material );
  15994. this.type = 'LineSegments';
  15995. }
  15996. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15997. constructor: LineSegments,
  15998. isLineSegments: true,
  15999. computeLineDistances: function () {
  16000. if ( _end$1 === undefined ) {
  16001. _start$1 = new Vector3();
  16002. _end$1 = new Vector3();
  16003. }
  16004. var geometry = this.geometry;
  16005. if ( geometry.isBufferGeometry ) {
  16006. // we assume non-indexed geometry
  16007. if ( geometry.index === null ) {
  16008. var positionAttribute = geometry.attributes.position;
  16009. var lineDistances = [];
  16010. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16011. _start$1.fromBufferAttribute( positionAttribute, i );
  16012. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  16013. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16014. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16015. }
  16016. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16017. } else {
  16018. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16019. }
  16020. } else if ( geometry.isGeometry ) {
  16021. var vertices = geometry.vertices;
  16022. var lineDistances = geometry.lineDistances;
  16023. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  16024. _start$1.copy( vertices[ i ] );
  16025. _end$1.copy( vertices[ i + 1 ] );
  16026. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16027. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16028. }
  16029. }
  16030. return this;
  16031. }
  16032. } );
  16033. /**
  16034. * @author mgreter / http://github.com/mgreter
  16035. */
  16036. function LineLoop( geometry, material ) {
  16037. Line.call( this, geometry, material );
  16038. this.type = 'LineLoop';
  16039. }
  16040. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16041. constructor: LineLoop,
  16042. isLineLoop: true,
  16043. } );
  16044. /**
  16045. * @author mrdoob / http://mrdoob.com/
  16046. * @author alteredq / http://alteredqualia.com/
  16047. *
  16048. * parameters = {
  16049. * color: <hex>,
  16050. * opacity: <float>,
  16051. * map: new THREE.Texture( <Image> ),
  16052. *
  16053. * size: <float>,
  16054. * sizeAttenuation: <bool>
  16055. *
  16056. * morphTargets: <bool>
  16057. * }
  16058. */
  16059. function PointsMaterial( parameters ) {
  16060. Material.call( this );
  16061. this.type = 'PointsMaterial';
  16062. this.color = new Color( 0xffffff );
  16063. this.map = null;
  16064. this.size = 1;
  16065. this.sizeAttenuation = true;
  16066. this.morphTargets = false;
  16067. this.lights = false;
  16068. this.setValues( parameters );
  16069. }
  16070. PointsMaterial.prototype = Object.create( Material.prototype );
  16071. PointsMaterial.prototype.constructor = PointsMaterial;
  16072. PointsMaterial.prototype.isPointsMaterial = true;
  16073. PointsMaterial.prototype.copy = function ( source ) {
  16074. Material.prototype.copy.call( this, source );
  16075. this.color.copy( source.color );
  16076. this.map = source.map;
  16077. this.size = source.size;
  16078. this.sizeAttenuation = source.sizeAttenuation;
  16079. this.morphTargets = source.morphTargets;
  16080. return this;
  16081. };
  16082. /**
  16083. * @author alteredq / http://alteredqualia.com/
  16084. */
  16085. var _inverseMatrix$2, _ray$2, _sphere$3;
  16086. function Points( geometry, material ) {
  16087. Object3D.call( this );
  16088. this.type = 'Points';
  16089. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16090. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  16091. this.updateMorphTargets();
  16092. }
  16093. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16094. constructor: Points,
  16095. isPoints: true,
  16096. raycast: function ( raycaster, intersects ) {
  16097. if ( _sphere$3 === undefined ) {
  16098. _inverseMatrix$2 = new Matrix4();
  16099. _ray$2 = new Ray();
  16100. _sphere$3 = new Sphere();
  16101. }
  16102. var object = this;
  16103. var geometry = this.geometry;
  16104. var matrixWorld = this.matrixWorld;
  16105. var threshold = raycaster.params.Points.threshold;
  16106. // Checking boundingSphere distance to ray
  16107. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16108. _sphere$3.copy( geometry.boundingSphere );
  16109. _sphere$3.applyMatrix4( matrixWorld );
  16110. _sphere$3.radius += threshold;
  16111. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  16112. //
  16113. _inverseMatrix$2.getInverse( matrixWorld );
  16114. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  16115. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16116. var localThresholdSq = localThreshold * localThreshold;
  16117. var position = new Vector3();
  16118. var intersectPoint = new Vector3();
  16119. function testPoint( point, index ) {
  16120. var rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  16121. if ( rayPointDistanceSq < localThresholdSq ) {
  16122. _ray$2.closestPointToPoint( point, intersectPoint );
  16123. intersectPoint.applyMatrix4( matrixWorld );
  16124. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16125. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16126. intersects.push( {
  16127. distance: distance,
  16128. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16129. point: intersectPoint.clone(),
  16130. index: index,
  16131. face: null,
  16132. object: object
  16133. } );
  16134. }
  16135. }
  16136. if ( geometry.isBufferGeometry ) {
  16137. var index = geometry.index;
  16138. var attributes = geometry.attributes;
  16139. var positions = attributes.position.array;
  16140. if ( index !== null ) {
  16141. var indices = index.array;
  16142. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  16143. var a = indices[ i ];
  16144. position.fromArray( positions, a * 3 );
  16145. testPoint( position, a );
  16146. }
  16147. } else {
  16148. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  16149. position.fromArray( positions, i * 3 );
  16150. testPoint( position, i );
  16151. }
  16152. }
  16153. } else {
  16154. var vertices = geometry.vertices;
  16155. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  16156. testPoint( vertices[ i ], i );
  16157. }
  16158. }
  16159. },
  16160. updateMorphTargets: function () {
  16161. var geometry = this.geometry;
  16162. var m, ml, name;
  16163. if ( geometry.isBufferGeometry ) {
  16164. var morphAttributes = geometry.morphAttributes;
  16165. var keys = Object.keys( morphAttributes );
  16166. if ( keys.length > 0 ) {
  16167. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16168. if ( morphAttribute !== undefined ) {
  16169. this.morphTargetInfluences = [];
  16170. this.morphTargetDictionary = {};
  16171. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16172. name = morphAttribute[ m ].name || String( m );
  16173. this.morphTargetInfluences.push( 0 );
  16174. this.morphTargetDictionary[ name ] = m;
  16175. }
  16176. }
  16177. }
  16178. } else {
  16179. var morphTargets = geometry.morphTargets;
  16180. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16181. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16182. }
  16183. }
  16184. },
  16185. clone: function () {
  16186. return new this.constructor( this.geometry, this.material ).copy( this );
  16187. }
  16188. } );
  16189. /**
  16190. * @author mrdoob / http://mrdoob.com/
  16191. */
  16192. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16193. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16194. this.format = format !== undefined ? format : RGBFormat;
  16195. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16196. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16197. this.generateMipmaps = false;
  16198. }
  16199. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16200. constructor: VideoTexture,
  16201. isVideoTexture: true,
  16202. update: function () {
  16203. var video = this.image;
  16204. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  16205. this.needsUpdate = true;
  16206. }
  16207. }
  16208. } );
  16209. /**
  16210. * @author alteredq / http://alteredqualia.com/
  16211. */
  16212. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16213. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16214. this.image = { width: width, height: height };
  16215. this.mipmaps = mipmaps;
  16216. // no flipping for cube textures
  16217. // (also flipping doesn't work for compressed textures )
  16218. this.flipY = false;
  16219. // can't generate mipmaps for compressed textures
  16220. // mips must be embedded in DDS files
  16221. this.generateMipmaps = false;
  16222. }
  16223. CompressedTexture.prototype = Object.create( Texture.prototype );
  16224. CompressedTexture.prototype.constructor = CompressedTexture;
  16225. CompressedTexture.prototype.isCompressedTexture = true;
  16226. /**
  16227. * @author mrdoob / http://mrdoob.com/
  16228. */
  16229. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16230. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16231. this.needsUpdate = true;
  16232. }
  16233. CanvasTexture.prototype = Object.create( Texture.prototype );
  16234. CanvasTexture.prototype.constructor = CanvasTexture;
  16235. CanvasTexture.prototype.isCanvasTexture = true;
  16236. /**
  16237. * @author Matt DesLauriers / @mattdesl
  16238. * @author atix / arthursilber.de
  16239. */
  16240. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16241. format = format !== undefined ? format : DepthFormat;
  16242. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16243. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16244. }
  16245. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16246. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16247. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16248. this.image = { width: width, height: height };
  16249. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16250. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16251. this.flipY = false;
  16252. this.generateMipmaps = false;
  16253. }
  16254. DepthTexture.prototype = Object.create( Texture.prototype );
  16255. DepthTexture.prototype.constructor = DepthTexture;
  16256. DepthTexture.prototype.isDepthTexture = true;
  16257. /**
  16258. * @author mrdoob / http://mrdoob.com/
  16259. * @author Mugen87 / https://github.com/Mugen87
  16260. */
  16261. function WireframeGeometry( geometry ) {
  16262. BufferGeometry.call( this );
  16263. this.type = 'WireframeGeometry';
  16264. // buffer
  16265. var vertices = [];
  16266. // helper variables
  16267. var i, j, l, o, ol;
  16268. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16269. var key, keys = [ 'a', 'b', 'c' ];
  16270. var vertex;
  16271. // different logic for Geometry and BufferGeometry
  16272. if ( geometry && geometry.isGeometry ) {
  16273. // create a data structure that contains all edges without duplicates
  16274. var faces = geometry.faces;
  16275. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16276. var face = faces[ i ];
  16277. for ( j = 0; j < 3; j ++ ) {
  16278. edge1 = face[ keys[ j ] ];
  16279. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16280. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16281. edge[ 1 ] = Math.max( edge1, edge2 );
  16282. key = edge[ 0 ] + ',' + edge[ 1 ];
  16283. if ( edges[ key ] === undefined ) {
  16284. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16285. }
  16286. }
  16287. }
  16288. // generate vertices
  16289. for ( key in edges ) {
  16290. e = edges[ key ];
  16291. vertex = geometry.vertices[ e.index1 ];
  16292. vertices.push( vertex.x, vertex.y, vertex.z );
  16293. vertex = geometry.vertices[ e.index2 ];
  16294. vertices.push( vertex.x, vertex.y, vertex.z );
  16295. }
  16296. } else if ( geometry && geometry.isBufferGeometry ) {
  16297. var position, indices, groups;
  16298. var group, start, count;
  16299. var index1, index2;
  16300. vertex = new Vector3();
  16301. if ( geometry.index !== null ) {
  16302. // indexed BufferGeometry
  16303. position = geometry.attributes.position;
  16304. indices = geometry.index;
  16305. groups = geometry.groups;
  16306. if ( groups.length === 0 ) {
  16307. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16308. }
  16309. // create a data structure that contains all eges without duplicates
  16310. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16311. group = groups[ o ];
  16312. start = group.start;
  16313. count = group.count;
  16314. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16315. for ( j = 0; j < 3; j ++ ) {
  16316. edge1 = indices.getX( i + j );
  16317. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16318. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16319. edge[ 1 ] = Math.max( edge1, edge2 );
  16320. key = edge[ 0 ] + ',' + edge[ 1 ];
  16321. if ( edges[ key ] === undefined ) {
  16322. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16323. }
  16324. }
  16325. }
  16326. }
  16327. // generate vertices
  16328. for ( key in edges ) {
  16329. e = edges[ key ];
  16330. vertex.fromBufferAttribute( position, e.index1 );
  16331. vertices.push( vertex.x, vertex.y, vertex.z );
  16332. vertex.fromBufferAttribute( position, e.index2 );
  16333. vertices.push( vertex.x, vertex.y, vertex.z );
  16334. }
  16335. } else {
  16336. // non-indexed BufferGeometry
  16337. position = geometry.attributes.position;
  16338. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16339. for ( j = 0; j < 3; j ++ ) {
  16340. // three edges per triangle, an edge is represented as (index1, index2)
  16341. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16342. index1 = 3 * i + j;
  16343. vertex.fromBufferAttribute( position, index1 );
  16344. vertices.push( vertex.x, vertex.y, vertex.z );
  16345. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16346. vertex.fromBufferAttribute( position, index2 );
  16347. vertices.push( vertex.x, vertex.y, vertex.z );
  16348. }
  16349. }
  16350. }
  16351. }
  16352. // build geometry
  16353. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16354. }
  16355. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16356. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16357. /**
  16358. * @author zz85 / https://github.com/zz85
  16359. * @author Mugen87 / https://github.com/Mugen87
  16360. *
  16361. * Parametric Surfaces Geometry
  16362. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16363. */
  16364. // ParametricGeometry
  16365. function ParametricGeometry( func, slices, stacks ) {
  16366. Geometry.call( this );
  16367. this.type = 'ParametricGeometry';
  16368. this.parameters = {
  16369. func: func,
  16370. slices: slices,
  16371. stacks: stacks
  16372. };
  16373. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16374. this.mergeVertices();
  16375. }
  16376. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16377. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16378. // ParametricBufferGeometry
  16379. function ParametricBufferGeometry( func, slices, stacks ) {
  16380. BufferGeometry.call( this );
  16381. this.type = 'ParametricBufferGeometry';
  16382. this.parameters = {
  16383. func: func,
  16384. slices: slices,
  16385. stacks: stacks
  16386. };
  16387. // buffers
  16388. var indices = [];
  16389. var vertices = [];
  16390. var normals = [];
  16391. var uvs = [];
  16392. var EPS = 0.00001;
  16393. var normal = new Vector3();
  16394. var p0 = new Vector3(), p1 = new Vector3();
  16395. var pu = new Vector3(), pv = new Vector3();
  16396. var i, j;
  16397. if ( func.length < 3 ) {
  16398. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16399. }
  16400. // generate vertices, normals and uvs
  16401. var sliceCount = slices + 1;
  16402. for ( i = 0; i <= stacks; i ++ ) {
  16403. var v = i / stacks;
  16404. for ( j = 0; j <= slices; j ++ ) {
  16405. var u = j / slices;
  16406. // vertex
  16407. func( u, v, p0 );
  16408. vertices.push( p0.x, p0.y, p0.z );
  16409. // normal
  16410. // approximate tangent vectors via finite differences
  16411. if ( u - EPS >= 0 ) {
  16412. func( u - EPS, v, p1 );
  16413. pu.subVectors( p0, p1 );
  16414. } else {
  16415. func( u + EPS, v, p1 );
  16416. pu.subVectors( p1, p0 );
  16417. }
  16418. if ( v - EPS >= 0 ) {
  16419. func( u, v - EPS, p1 );
  16420. pv.subVectors( p0, p1 );
  16421. } else {
  16422. func( u, v + EPS, p1 );
  16423. pv.subVectors( p1, p0 );
  16424. }
  16425. // cross product of tangent vectors returns surface normal
  16426. normal.crossVectors( pu, pv ).normalize();
  16427. normals.push( normal.x, normal.y, normal.z );
  16428. // uv
  16429. uvs.push( u, v );
  16430. }
  16431. }
  16432. // generate indices
  16433. for ( i = 0; i < stacks; i ++ ) {
  16434. for ( j = 0; j < slices; j ++ ) {
  16435. var a = i * sliceCount + j;
  16436. var b = i * sliceCount + j + 1;
  16437. var c = ( i + 1 ) * sliceCount + j + 1;
  16438. var d = ( i + 1 ) * sliceCount + j;
  16439. // faces one and two
  16440. indices.push( a, b, d );
  16441. indices.push( b, c, d );
  16442. }
  16443. }
  16444. // build geometry
  16445. this.setIndex( indices );
  16446. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16447. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16448. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16449. }
  16450. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16451. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16452. /**
  16453. * @author clockworkgeek / https://github.com/clockworkgeek
  16454. * @author timothypratley / https://github.com/timothypratley
  16455. * @author WestLangley / http://github.com/WestLangley
  16456. * @author Mugen87 / https://github.com/Mugen87
  16457. */
  16458. // PolyhedronGeometry
  16459. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16460. Geometry.call( this );
  16461. this.type = 'PolyhedronGeometry';
  16462. this.parameters = {
  16463. vertices: vertices,
  16464. indices: indices,
  16465. radius: radius,
  16466. detail: detail
  16467. };
  16468. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16469. this.mergeVertices();
  16470. }
  16471. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16472. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16473. // PolyhedronBufferGeometry
  16474. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16475. BufferGeometry.call( this );
  16476. this.type = 'PolyhedronBufferGeometry';
  16477. this.parameters = {
  16478. vertices: vertices,
  16479. indices: indices,
  16480. radius: radius,
  16481. detail: detail
  16482. };
  16483. radius = radius || 1;
  16484. detail = detail || 0;
  16485. // default buffer data
  16486. var vertexBuffer = [];
  16487. var uvBuffer = [];
  16488. // the subdivision creates the vertex buffer data
  16489. subdivide( detail );
  16490. // all vertices should lie on a conceptual sphere with a given radius
  16491. applyRadius( radius );
  16492. // finally, create the uv data
  16493. generateUVs();
  16494. // build non-indexed geometry
  16495. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16496. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16497. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16498. if ( detail === 0 ) {
  16499. this.computeVertexNormals(); // flat normals
  16500. } else {
  16501. this.normalizeNormals(); // smooth normals
  16502. }
  16503. // helper functions
  16504. function subdivide( detail ) {
  16505. var a = new Vector3();
  16506. var b = new Vector3();
  16507. var c = new Vector3();
  16508. // iterate over all faces and apply a subdivison with the given detail value
  16509. for ( var i = 0; i < indices.length; i += 3 ) {
  16510. // get the vertices of the face
  16511. getVertexByIndex( indices[ i + 0 ], a );
  16512. getVertexByIndex( indices[ i + 1 ], b );
  16513. getVertexByIndex( indices[ i + 2 ], c );
  16514. // perform subdivision
  16515. subdivideFace( a, b, c, detail );
  16516. }
  16517. }
  16518. function subdivideFace( a, b, c, detail ) {
  16519. var cols = Math.pow( 2, detail );
  16520. // we use this multidimensional array as a data structure for creating the subdivision
  16521. var v = [];
  16522. var i, j;
  16523. // construct all of the vertices for this subdivision
  16524. for ( i = 0; i <= cols; i ++ ) {
  16525. v[ i ] = [];
  16526. var aj = a.clone().lerp( c, i / cols );
  16527. var bj = b.clone().lerp( c, i / cols );
  16528. var rows = cols - i;
  16529. for ( j = 0; j <= rows; j ++ ) {
  16530. if ( j === 0 && i === cols ) {
  16531. v[ i ][ j ] = aj;
  16532. } else {
  16533. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16534. }
  16535. }
  16536. }
  16537. // construct all of the faces
  16538. for ( i = 0; i < cols; i ++ ) {
  16539. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16540. var k = Math.floor( j / 2 );
  16541. if ( j % 2 === 0 ) {
  16542. pushVertex( v[ i ][ k + 1 ] );
  16543. pushVertex( v[ i + 1 ][ k ] );
  16544. pushVertex( v[ i ][ k ] );
  16545. } else {
  16546. pushVertex( v[ i ][ k + 1 ] );
  16547. pushVertex( v[ i + 1 ][ k + 1 ] );
  16548. pushVertex( v[ i + 1 ][ k ] );
  16549. }
  16550. }
  16551. }
  16552. }
  16553. function applyRadius( radius ) {
  16554. var vertex = new Vector3();
  16555. // iterate over the entire buffer and apply the radius to each vertex
  16556. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16557. vertex.x = vertexBuffer[ i + 0 ];
  16558. vertex.y = vertexBuffer[ i + 1 ];
  16559. vertex.z = vertexBuffer[ i + 2 ];
  16560. vertex.normalize().multiplyScalar( radius );
  16561. vertexBuffer[ i + 0 ] = vertex.x;
  16562. vertexBuffer[ i + 1 ] = vertex.y;
  16563. vertexBuffer[ i + 2 ] = vertex.z;
  16564. }
  16565. }
  16566. function generateUVs() {
  16567. var vertex = new Vector3();
  16568. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16569. vertex.x = vertexBuffer[ i + 0 ];
  16570. vertex.y = vertexBuffer[ i + 1 ];
  16571. vertex.z = vertexBuffer[ i + 2 ];
  16572. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16573. var v = inclination( vertex ) / Math.PI + 0.5;
  16574. uvBuffer.push( u, 1 - v );
  16575. }
  16576. correctUVs();
  16577. correctSeam();
  16578. }
  16579. function correctSeam() {
  16580. // handle case when face straddles the seam, see #3269
  16581. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16582. // uv data of a single face
  16583. var x0 = uvBuffer[ i + 0 ];
  16584. var x1 = uvBuffer[ i + 2 ];
  16585. var x2 = uvBuffer[ i + 4 ];
  16586. var max = Math.max( x0, x1, x2 );
  16587. var min = Math.min( x0, x1, x2 );
  16588. // 0.9 is somewhat arbitrary
  16589. if ( max > 0.9 && min < 0.1 ) {
  16590. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16591. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16592. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16593. }
  16594. }
  16595. }
  16596. function pushVertex( vertex ) {
  16597. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16598. }
  16599. function getVertexByIndex( index, vertex ) {
  16600. var stride = index * 3;
  16601. vertex.x = vertices[ stride + 0 ];
  16602. vertex.y = vertices[ stride + 1 ];
  16603. vertex.z = vertices[ stride + 2 ];
  16604. }
  16605. function correctUVs() {
  16606. var a = new Vector3();
  16607. var b = new Vector3();
  16608. var c = new Vector3();
  16609. var centroid = new Vector3();
  16610. var uvA = new Vector2();
  16611. var uvB = new Vector2();
  16612. var uvC = new Vector2();
  16613. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16614. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16615. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16616. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16617. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16618. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16619. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16620. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16621. var azi = azimuth( centroid );
  16622. correctUV( uvA, j + 0, a, azi );
  16623. correctUV( uvB, j + 2, b, azi );
  16624. correctUV( uvC, j + 4, c, azi );
  16625. }
  16626. }
  16627. function correctUV( uv, stride, vector, azimuth ) {
  16628. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16629. uvBuffer[ stride ] = uv.x - 1;
  16630. }
  16631. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16632. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16633. }
  16634. }
  16635. // Angle around the Y axis, counter-clockwise when looking from above.
  16636. function azimuth( vector ) {
  16637. return Math.atan2( vector.z, - vector.x );
  16638. }
  16639. // Angle above the XZ plane.
  16640. function inclination( vector ) {
  16641. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16642. }
  16643. }
  16644. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16645. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16646. /**
  16647. * @author timothypratley / https://github.com/timothypratley
  16648. * @author Mugen87 / https://github.com/Mugen87
  16649. */
  16650. // TetrahedronGeometry
  16651. function TetrahedronGeometry( radius, detail ) {
  16652. Geometry.call( this );
  16653. this.type = 'TetrahedronGeometry';
  16654. this.parameters = {
  16655. radius: radius,
  16656. detail: detail
  16657. };
  16658. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16659. this.mergeVertices();
  16660. }
  16661. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16662. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16663. // TetrahedronBufferGeometry
  16664. function TetrahedronBufferGeometry( radius, detail ) {
  16665. var vertices = [
  16666. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16667. ];
  16668. var indices = [
  16669. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16670. ];
  16671. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16672. this.type = 'TetrahedronBufferGeometry';
  16673. this.parameters = {
  16674. radius: radius,
  16675. detail: detail
  16676. };
  16677. }
  16678. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16679. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16680. /**
  16681. * @author timothypratley / https://github.com/timothypratley
  16682. * @author Mugen87 / https://github.com/Mugen87
  16683. */
  16684. // OctahedronGeometry
  16685. function OctahedronGeometry( radius, detail ) {
  16686. Geometry.call( this );
  16687. this.type = 'OctahedronGeometry';
  16688. this.parameters = {
  16689. radius: radius,
  16690. detail: detail
  16691. };
  16692. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16693. this.mergeVertices();
  16694. }
  16695. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16696. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16697. // OctahedronBufferGeometry
  16698. function OctahedronBufferGeometry( radius, detail ) {
  16699. var vertices = [
  16700. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16701. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16702. ];
  16703. var indices = [
  16704. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16705. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16706. 1, 3, 4, 1, 4, 2
  16707. ];
  16708. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16709. this.type = 'OctahedronBufferGeometry';
  16710. this.parameters = {
  16711. radius: radius,
  16712. detail: detail
  16713. };
  16714. }
  16715. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16716. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16717. /**
  16718. * @author timothypratley / https://github.com/timothypratley
  16719. * @author Mugen87 / https://github.com/Mugen87
  16720. */
  16721. // IcosahedronGeometry
  16722. function IcosahedronGeometry( radius, detail ) {
  16723. Geometry.call( this );
  16724. this.type = 'IcosahedronGeometry';
  16725. this.parameters = {
  16726. radius: radius,
  16727. detail: detail
  16728. };
  16729. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16730. this.mergeVertices();
  16731. }
  16732. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16733. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16734. // IcosahedronBufferGeometry
  16735. function IcosahedronBufferGeometry( radius, detail ) {
  16736. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16737. var vertices = [
  16738. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16739. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16740. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16741. ];
  16742. var indices = [
  16743. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16744. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16745. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16746. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16747. ];
  16748. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16749. this.type = 'IcosahedronBufferGeometry';
  16750. this.parameters = {
  16751. radius: radius,
  16752. detail: detail
  16753. };
  16754. }
  16755. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16756. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16757. /**
  16758. * @author Abe Pazos / https://hamoid.com
  16759. * @author Mugen87 / https://github.com/Mugen87
  16760. */
  16761. // DodecahedronGeometry
  16762. function DodecahedronGeometry( radius, detail ) {
  16763. Geometry.call( this );
  16764. this.type = 'DodecahedronGeometry';
  16765. this.parameters = {
  16766. radius: radius,
  16767. detail: detail
  16768. };
  16769. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16770. this.mergeVertices();
  16771. }
  16772. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16773. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16774. // DodecahedronBufferGeometry
  16775. function DodecahedronBufferGeometry( radius, detail ) {
  16776. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16777. var r = 1 / t;
  16778. var vertices = [
  16779. // (±1, ±1, ±1)
  16780. - 1, - 1, - 1, - 1, - 1, 1,
  16781. - 1, 1, - 1, - 1, 1, 1,
  16782. 1, - 1, - 1, 1, - 1, 1,
  16783. 1, 1, - 1, 1, 1, 1,
  16784. // (0, ±1/φ, ±φ)
  16785. 0, - r, - t, 0, - r, t,
  16786. 0, r, - t, 0, r, t,
  16787. // (±1/φ, ±φ, 0)
  16788. - r, - t, 0, - r, t, 0,
  16789. r, - t, 0, r, t, 0,
  16790. // (±φ, 0, ±1/φ)
  16791. - t, 0, - r, t, 0, - r,
  16792. - t, 0, r, t, 0, r
  16793. ];
  16794. var indices = [
  16795. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16796. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16797. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16798. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16799. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16800. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16801. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16802. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16803. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16804. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16805. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16806. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16807. ];
  16808. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16809. this.type = 'DodecahedronBufferGeometry';
  16810. this.parameters = {
  16811. radius: radius,
  16812. detail: detail
  16813. };
  16814. }
  16815. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16816. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16817. /**
  16818. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16819. * @author WestLangley / https://github.com/WestLangley
  16820. * @author zz85 / https://github.com/zz85
  16821. * @author miningold / https://github.com/miningold
  16822. * @author jonobr1 / https://github.com/jonobr1
  16823. * @author Mugen87 / https://github.com/Mugen87
  16824. *
  16825. */
  16826. // TubeGeometry
  16827. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16828. Geometry.call( this );
  16829. this.type = 'TubeGeometry';
  16830. this.parameters = {
  16831. path: path,
  16832. tubularSegments: tubularSegments,
  16833. radius: radius,
  16834. radialSegments: radialSegments,
  16835. closed: closed
  16836. };
  16837. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16838. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16839. // expose internals
  16840. this.tangents = bufferGeometry.tangents;
  16841. this.normals = bufferGeometry.normals;
  16842. this.binormals = bufferGeometry.binormals;
  16843. // create geometry
  16844. this.fromBufferGeometry( bufferGeometry );
  16845. this.mergeVertices();
  16846. }
  16847. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16848. TubeGeometry.prototype.constructor = TubeGeometry;
  16849. // TubeBufferGeometry
  16850. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16851. BufferGeometry.call( this );
  16852. this.type = 'TubeBufferGeometry';
  16853. this.parameters = {
  16854. path: path,
  16855. tubularSegments: tubularSegments,
  16856. radius: radius,
  16857. radialSegments: radialSegments,
  16858. closed: closed
  16859. };
  16860. tubularSegments = tubularSegments || 64;
  16861. radius = radius || 1;
  16862. radialSegments = radialSegments || 8;
  16863. closed = closed || false;
  16864. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16865. // expose internals
  16866. this.tangents = frames.tangents;
  16867. this.normals = frames.normals;
  16868. this.binormals = frames.binormals;
  16869. // helper variables
  16870. var vertex = new Vector3();
  16871. var normal = new Vector3();
  16872. var uv = new Vector2();
  16873. var P = new Vector3();
  16874. var i, j;
  16875. // buffer
  16876. var vertices = [];
  16877. var normals = [];
  16878. var uvs = [];
  16879. var indices = [];
  16880. // create buffer data
  16881. generateBufferData();
  16882. // build geometry
  16883. this.setIndex( indices );
  16884. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16885. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16886. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16887. // functions
  16888. function generateBufferData() {
  16889. for ( i = 0; i < tubularSegments; i ++ ) {
  16890. generateSegment( i );
  16891. }
  16892. // if the geometry is not closed, generate the last row of vertices and normals
  16893. // at the regular position on the given path
  16894. //
  16895. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16896. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16897. // uvs are generated in a separate function.
  16898. // this makes it easy compute correct values for closed geometries
  16899. generateUVs();
  16900. // finally create faces
  16901. generateIndices();
  16902. }
  16903. function generateSegment( i ) {
  16904. // we use getPointAt to sample evenly distributed points from the given path
  16905. P = path.getPointAt( i / tubularSegments, P );
  16906. // retrieve corresponding normal and binormal
  16907. var N = frames.normals[ i ];
  16908. var B = frames.binormals[ i ];
  16909. // generate normals and vertices for the current segment
  16910. for ( j = 0; j <= radialSegments; j ++ ) {
  16911. var v = j / radialSegments * Math.PI * 2;
  16912. var sin = Math.sin( v );
  16913. var cos = - Math.cos( v );
  16914. // normal
  16915. normal.x = ( cos * N.x + sin * B.x );
  16916. normal.y = ( cos * N.y + sin * B.y );
  16917. normal.z = ( cos * N.z + sin * B.z );
  16918. normal.normalize();
  16919. normals.push( normal.x, normal.y, normal.z );
  16920. // vertex
  16921. vertex.x = P.x + radius * normal.x;
  16922. vertex.y = P.y + radius * normal.y;
  16923. vertex.z = P.z + radius * normal.z;
  16924. vertices.push( vertex.x, vertex.y, vertex.z );
  16925. }
  16926. }
  16927. function generateIndices() {
  16928. for ( j = 1; j <= tubularSegments; j ++ ) {
  16929. for ( i = 1; i <= radialSegments; i ++ ) {
  16930. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16931. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16932. var c = ( radialSegments + 1 ) * j + i;
  16933. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16934. // faces
  16935. indices.push( a, b, d );
  16936. indices.push( b, c, d );
  16937. }
  16938. }
  16939. }
  16940. function generateUVs() {
  16941. for ( i = 0; i <= tubularSegments; i ++ ) {
  16942. for ( j = 0; j <= radialSegments; j ++ ) {
  16943. uv.x = i / tubularSegments;
  16944. uv.y = j / radialSegments;
  16945. uvs.push( uv.x, uv.y );
  16946. }
  16947. }
  16948. }
  16949. }
  16950. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16951. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16952. TubeBufferGeometry.prototype.toJSON = function () {
  16953. var data = BufferGeometry.prototype.toJSON.call( this );
  16954. data.path = this.parameters.path.toJSON();
  16955. return data;
  16956. };
  16957. /**
  16958. * @author oosmoxiecode
  16959. * @author Mugen87 / https://github.com/Mugen87
  16960. *
  16961. * based on http://www.blackpawn.com/texts/pqtorus/
  16962. */
  16963. // TorusKnotGeometry
  16964. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16965. Geometry.call( this );
  16966. this.type = 'TorusKnotGeometry';
  16967. this.parameters = {
  16968. radius: radius,
  16969. tube: tube,
  16970. tubularSegments: tubularSegments,
  16971. radialSegments: radialSegments,
  16972. p: p,
  16973. q: q
  16974. };
  16975. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16976. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16977. this.mergeVertices();
  16978. }
  16979. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16980. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16981. // TorusKnotBufferGeometry
  16982. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16983. BufferGeometry.call( this );
  16984. this.type = 'TorusKnotBufferGeometry';
  16985. this.parameters = {
  16986. radius: radius,
  16987. tube: tube,
  16988. tubularSegments: tubularSegments,
  16989. radialSegments: radialSegments,
  16990. p: p,
  16991. q: q
  16992. };
  16993. radius = radius || 1;
  16994. tube = tube || 0.4;
  16995. tubularSegments = Math.floor( tubularSegments ) || 64;
  16996. radialSegments = Math.floor( radialSegments ) || 8;
  16997. p = p || 2;
  16998. q = q || 3;
  16999. // buffers
  17000. var indices = [];
  17001. var vertices = [];
  17002. var normals = [];
  17003. var uvs = [];
  17004. // helper variables
  17005. var i, j;
  17006. var vertex = new Vector3();
  17007. var normal = new Vector3();
  17008. var P1 = new Vector3();
  17009. var P2 = new Vector3();
  17010. var B = new Vector3();
  17011. var T = new Vector3();
  17012. var N = new Vector3();
  17013. // generate vertices, normals and uvs
  17014. for ( i = 0; i <= tubularSegments; ++ i ) {
  17015. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17016. var u = i / tubularSegments * p * Math.PI * 2;
  17017. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17018. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17019. calculatePositionOnCurve( u, p, q, radius, P1 );
  17020. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17021. // calculate orthonormal basis
  17022. T.subVectors( P2, P1 );
  17023. N.addVectors( P2, P1 );
  17024. B.crossVectors( T, N );
  17025. N.crossVectors( B, T );
  17026. // normalize B, N. T can be ignored, we don't use it
  17027. B.normalize();
  17028. N.normalize();
  17029. for ( j = 0; j <= radialSegments; ++ j ) {
  17030. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17031. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17032. var v = j / radialSegments * Math.PI * 2;
  17033. var cx = - tube * Math.cos( v );
  17034. var cy = tube * Math.sin( v );
  17035. // now calculate the final vertex position.
  17036. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17037. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17038. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17039. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17040. vertices.push( vertex.x, vertex.y, vertex.z );
  17041. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17042. normal.subVectors( vertex, P1 ).normalize();
  17043. normals.push( normal.x, normal.y, normal.z );
  17044. // uv
  17045. uvs.push( i / tubularSegments );
  17046. uvs.push( j / radialSegments );
  17047. }
  17048. }
  17049. // generate indices
  17050. for ( j = 1; j <= tubularSegments; j ++ ) {
  17051. for ( i = 1; i <= radialSegments; i ++ ) {
  17052. // indices
  17053. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17054. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17055. var c = ( radialSegments + 1 ) * j + i;
  17056. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17057. // faces
  17058. indices.push( a, b, d );
  17059. indices.push( b, c, d );
  17060. }
  17061. }
  17062. // build geometry
  17063. this.setIndex( indices );
  17064. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17065. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17066. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17067. // this function calculates the current position on the torus curve
  17068. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17069. var cu = Math.cos( u );
  17070. var su = Math.sin( u );
  17071. var quOverP = q / p * u;
  17072. var cs = Math.cos( quOverP );
  17073. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17074. position.y = radius * ( 2 + cs ) * su * 0.5;
  17075. position.z = radius * Math.sin( quOverP ) * 0.5;
  17076. }
  17077. }
  17078. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17079. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17080. /**
  17081. * @author oosmoxiecode
  17082. * @author mrdoob / http://mrdoob.com/
  17083. * @author Mugen87 / https://github.com/Mugen87
  17084. */
  17085. // TorusGeometry
  17086. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17087. Geometry.call( this );
  17088. this.type = 'TorusGeometry';
  17089. this.parameters = {
  17090. radius: radius,
  17091. tube: tube,
  17092. radialSegments: radialSegments,
  17093. tubularSegments: tubularSegments,
  17094. arc: arc
  17095. };
  17096. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17097. this.mergeVertices();
  17098. }
  17099. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17100. TorusGeometry.prototype.constructor = TorusGeometry;
  17101. // TorusBufferGeometry
  17102. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17103. BufferGeometry.call( this );
  17104. this.type = 'TorusBufferGeometry';
  17105. this.parameters = {
  17106. radius: radius,
  17107. tube: tube,
  17108. radialSegments: radialSegments,
  17109. tubularSegments: tubularSegments,
  17110. arc: arc
  17111. };
  17112. radius = radius || 1;
  17113. tube = tube || 0.4;
  17114. radialSegments = Math.floor( radialSegments ) || 8;
  17115. tubularSegments = Math.floor( tubularSegments ) || 6;
  17116. arc = arc || Math.PI * 2;
  17117. // buffers
  17118. var indices = [];
  17119. var vertices = [];
  17120. var normals = [];
  17121. var uvs = [];
  17122. // helper variables
  17123. var center = new Vector3();
  17124. var vertex = new Vector3();
  17125. var normal = new Vector3();
  17126. var j, i;
  17127. // generate vertices, normals and uvs
  17128. for ( j = 0; j <= radialSegments; j ++ ) {
  17129. for ( i = 0; i <= tubularSegments; i ++ ) {
  17130. var u = i / tubularSegments * arc;
  17131. var v = j / radialSegments * Math.PI * 2;
  17132. // vertex
  17133. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  17134. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  17135. vertex.z = tube * Math.sin( v );
  17136. vertices.push( vertex.x, vertex.y, vertex.z );
  17137. // normal
  17138. center.x = radius * Math.cos( u );
  17139. center.y = radius * Math.sin( u );
  17140. normal.subVectors( vertex, center ).normalize();
  17141. normals.push( normal.x, normal.y, normal.z );
  17142. // uv
  17143. uvs.push( i / tubularSegments );
  17144. uvs.push( j / radialSegments );
  17145. }
  17146. }
  17147. // generate indices
  17148. for ( j = 1; j <= radialSegments; j ++ ) {
  17149. for ( i = 1; i <= tubularSegments; i ++ ) {
  17150. // indices
  17151. var a = ( tubularSegments + 1 ) * j + i - 1;
  17152. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  17153. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  17154. var d = ( tubularSegments + 1 ) * j + i;
  17155. // faces
  17156. indices.push( a, b, d );
  17157. indices.push( b, c, d );
  17158. }
  17159. }
  17160. // build geometry
  17161. this.setIndex( indices );
  17162. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17163. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17164. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17165. }
  17166. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17167. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  17168. /**
  17169. * @author Mugen87 / https://github.com/Mugen87
  17170. * Port from https://github.com/mapbox/earcut (v2.1.5)
  17171. */
  17172. var Earcut = {
  17173. triangulate: function ( data, holeIndices, dim ) {
  17174. dim = dim || 2;
  17175. var hasHoles = holeIndices && holeIndices.length,
  17176. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  17177. outerNode = linkedList( data, 0, outerLen, dim, true ),
  17178. triangles = [];
  17179. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  17180. var minX, minY, maxX, maxY, x, y, invSize;
  17181. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  17182. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17183. if ( data.length > 80 * dim ) {
  17184. minX = maxX = data[ 0 ];
  17185. minY = maxY = data[ 1 ];
  17186. for ( var i = dim; i < outerLen; i += dim ) {
  17187. x = data[ i ];
  17188. y = data[ i + 1 ];
  17189. if ( x < minX ) minX = x;
  17190. if ( y < minY ) minY = y;
  17191. if ( x > maxX ) maxX = x;
  17192. if ( y > maxY ) maxY = y;
  17193. }
  17194. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17195. invSize = Math.max( maxX - minX, maxY - minY );
  17196. invSize = invSize !== 0 ? 1 / invSize : 0;
  17197. }
  17198. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  17199. return triangles;
  17200. }
  17201. };
  17202. // create a circular doubly linked list from polygon points in the specified winding order
  17203. function linkedList( data, start, end, dim, clockwise ) {
  17204. var i, last;
  17205. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  17206. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17207. } else {
  17208. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17209. }
  17210. if ( last && equals( last, last.next ) ) {
  17211. removeNode( last );
  17212. last = last.next;
  17213. }
  17214. return last;
  17215. }
  17216. // eliminate colinear or duplicate points
  17217. function filterPoints( start, end ) {
  17218. if ( ! start ) return start;
  17219. if ( ! end ) end = start;
  17220. var p = start,
  17221. again;
  17222. do {
  17223. again = false;
  17224. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17225. removeNode( p );
  17226. p = end = p.prev;
  17227. if ( p === p.next ) break;
  17228. again = true;
  17229. } else {
  17230. p = p.next;
  17231. }
  17232. } while ( again || p !== end );
  17233. return end;
  17234. }
  17235. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17236. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17237. if ( ! ear ) return;
  17238. // interlink polygon nodes in z-order
  17239. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17240. var stop = ear,
  17241. prev, next;
  17242. // iterate through ears, slicing them one by one
  17243. while ( ear.prev !== ear.next ) {
  17244. prev = ear.prev;
  17245. next = ear.next;
  17246. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17247. // cut off the triangle
  17248. triangles.push( prev.i / dim );
  17249. triangles.push( ear.i / dim );
  17250. triangles.push( next.i / dim );
  17251. removeNode( ear );
  17252. // skipping the next vertex leads to less sliver triangles
  17253. ear = next.next;
  17254. stop = next.next;
  17255. continue;
  17256. }
  17257. ear = next;
  17258. // if we looped through the whole remaining polygon and can't find any more ears
  17259. if ( ear === stop ) {
  17260. // try filtering points and slicing again
  17261. if ( ! pass ) {
  17262. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17263. // if this didn't work, try curing all small self-intersections locally
  17264. } else if ( pass === 1 ) {
  17265. ear = cureLocalIntersections( ear, triangles, dim );
  17266. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17267. // as a last resort, try splitting the remaining polygon into two
  17268. } else if ( pass === 2 ) {
  17269. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17270. }
  17271. break;
  17272. }
  17273. }
  17274. }
  17275. // check whether a polygon node forms a valid ear with adjacent nodes
  17276. function isEar( ear ) {
  17277. var a = ear.prev,
  17278. b = ear,
  17279. c = ear.next;
  17280. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17281. // now make sure we don't have other points inside the potential ear
  17282. var p = ear.next.next;
  17283. while ( p !== ear.prev ) {
  17284. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17285. area( p.prev, p, p.next ) >= 0 ) return false;
  17286. p = p.next;
  17287. }
  17288. return true;
  17289. }
  17290. function isEarHashed( ear, minX, minY, invSize ) {
  17291. var a = ear.prev,
  17292. b = ear,
  17293. c = ear.next;
  17294. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17295. // triangle bbox; min & max are calculated like this for speed
  17296. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17297. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17298. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17299. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17300. // z-order range for the current triangle bbox;
  17301. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17302. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17303. var p = ear.prevZ,
  17304. n = ear.nextZ;
  17305. // look for points inside the triangle in both directions
  17306. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  17307. if ( p !== ear.prev && p !== ear.next &&
  17308. 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.prevZ;
  17311. if ( n !== ear.prev && n !== ear.next &&
  17312. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17313. area( n.prev, n, n.next ) >= 0 ) return false;
  17314. n = n.nextZ;
  17315. }
  17316. // look for remaining points in decreasing z-order
  17317. while ( p && p.z >= minZ ) {
  17318. if ( p !== ear.prev && p !== ear.next &&
  17319. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17320. area( p.prev, p, p.next ) >= 0 ) return false;
  17321. p = p.prevZ;
  17322. }
  17323. // look for remaining points in increasing z-order
  17324. while ( n && n.z <= maxZ ) {
  17325. if ( n !== ear.prev && n !== ear.next &&
  17326. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17327. area( n.prev, n, n.next ) >= 0 ) return false;
  17328. n = n.nextZ;
  17329. }
  17330. return true;
  17331. }
  17332. // go through all polygon nodes and cure small local self-intersections
  17333. function cureLocalIntersections( start, triangles, dim ) {
  17334. var p = start;
  17335. do {
  17336. var a = p.prev,
  17337. b = p.next.next;
  17338. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17339. triangles.push( a.i / dim );
  17340. triangles.push( p.i / dim );
  17341. triangles.push( b.i / dim );
  17342. // remove two nodes involved
  17343. removeNode( p );
  17344. removeNode( p.next );
  17345. p = start = b;
  17346. }
  17347. p = p.next;
  17348. } while ( p !== start );
  17349. return p;
  17350. }
  17351. // try splitting polygon into two and triangulate them independently
  17352. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17353. // look for a valid diagonal that divides the polygon into two
  17354. var a = start;
  17355. do {
  17356. var b = a.next.next;
  17357. while ( b !== a.prev ) {
  17358. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17359. // split the polygon in two by the diagonal
  17360. var c = splitPolygon( a, b );
  17361. // filter colinear points around the cuts
  17362. a = filterPoints( a, a.next );
  17363. c = filterPoints( c, c.next );
  17364. // run earcut on each half
  17365. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17366. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17367. return;
  17368. }
  17369. b = b.next;
  17370. }
  17371. a = a.next;
  17372. } while ( a !== start );
  17373. }
  17374. // link every hole into the outer loop, producing a single-ring polygon without holes
  17375. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17376. var queue = [],
  17377. i, len, start, end, list;
  17378. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17379. start = holeIndices[ i ] * dim;
  17380. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17381. list = linkedList( data, start, end, dim, false );
  17382. if ( list === list.next ) list.steiner = true;
  17383. queue.push( getLeftmost( list ) );
  17384. }
  17385. queue.sort( compareX );
  17386. // process holes from left to right
  17387. for ( i = 0; i < queue.length; i ++ ) {
  17388. eliminateHole( queue[ i ], outerNode );
  17389. outerNode = filterPoints( outerNode, outerNode.next );
  17390. }
  17391. return outerNode;
  17392. }
  17393. function compareX( a, b ) {
  17394. return a.x - b.x;
  17395. }
  17396. // find a bridge between vertices that connects hole with an outer ring and and link it
  17397. function eliminateHole( hole, outerNode ) {
  17398. outerNode = findHoleBridge( hole, outerNode );
  17399. if ( outerNode ) {
  17400. var b = splitPolygon( outerNode, hole );
  17401. filterPoints( b, b.next );
  17402. }
  17403. }
  17404. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17405. function findHoleBridge( hole, outerNode ) {
  17406. var p = outerNode,
  17407. hx = hole.x,
  17408. hy = hole.y,
  17409. qx = - Infinity,
  17410. m;
  17411. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17412. // segment's endpoint with lesser x will be potential connection point
  17413. do {
  17414. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17415. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17416. if ( x <= hx && x > qx ) {
  17417. qx = x;
  17418. if ( x === hx ) {
  17419. if ( hy === p.y ) return p;
  17420. if ( hy === p.next.y ) return p.next;
  17421. }
  17422. m = p.x < p.next.x ? p : p.next;
  17423. }
  17424. }
  17425. p = p.next;
  17426. } while ( p !== outerNode );
  17427. if ( ! m ) return null;
  17428. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17429. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17430. // if there are no points found, we have a valid connection;
  17431. // otherwise choose the point of the minimum angle with the ray as connection point
  17432. var stop = m,
  17433. mx = m.x,
  17434. my = m.y,
  17435. tanMin = Infinity,
  17436. tan;
  17437. p = m.next;
  17438. while ( p !== stop ) {
  17439. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17440. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17441. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17442. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17443. m = p;
  17444. tanMin = tan;
  17445. }
  17446. }
  17447. p = p.next;
  17448. }
  17449. return m;
  17450. }
  17451. // interlink polygon nodes in z-order
  17452. function indexCurve( start, minX, minY, invSize ) {
  17453. var p = start;
  17454. do {
  17455. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17456. p.prevZ = p.prev;
  17457. p.nextZ = p.next;
  17458. p = p.next;
  17459. } while ( p !== start );
  17460. p.prevZ.nextZ = null;
  17461. p.prevZ = null;
  17462. sortLinked( p );
  17463. }
  17464. // Simon Tatham's linked list merge sort algorithm
  17465. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17466. function sortLinked( list ) {
  17467. var i, p, q, e, tail, numMerges, pSize, qSize,
  17468. inSize = 1;
  17469. do {
  17470. p = list;
  17471. list = null;
  17472. tail = null;
  17473. numMerges = 0;
  17474. while ( p ) {
  17475. numMerges ++;
  17476. q = p;
  17477. pSize = 0;
  17478. for ( i = 0; i < inSize; i ++ ) {
  17479. pSize ++;
  17480. q = q.nextZ;
  17481. if ( ! q ) break;
  17482. }
  17483. qSize = inSize;
  17484. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17485. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17486. e = p;
  17487. p = p.nextZ;
  17488. pSize --;
  17489. } else {
  17490. e = q;
  17491. q = q.nextZ;
  17492. qSize --;
  17493. }
  17494. if ( tail ) tail.nextZ = e;
  17495. else list = e;
  17496. e.prevZ = tail;
  17497. tail = e;
  17498. }
  17499. p = q;
  17500. }
  17501. tail.nextZ = null;
  17502. inSize *= 2;
  17503. } while ( numMerges > 1 );
  17504. return list;
  17505. }
  17506. // z-order of a point given coords and inverse of the longer side of data bbox
  17507. function zOrder( x, y, minX, minY, invSize ) {
  17508. // coords are transformed into non-negative 15-bit integer range
  17509. x = 32767 * ( x - minX ) * invSize;
  17510. y = 32767 * ( y - minY ) * invSize;
  17511. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17512. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17513. x = ( x | ( x << 2 ) ) & 0x33333333;
  17514. x = ( x | ( x << 1 ) ) & 0x55555555;
  17515. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17516. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17517. y = ( y | ( y << 2 ) ) & 0x33333333;
  17518. y = ( y | ( y << 1 ) ) & 0x55555555;
  17519. return x | ( y << 1 );
  17520. }
  17521. // find the leftmost node of a polygon ring
  17522. function getLeftmost( start ) {
  17523. var p = start,
  17524. leftmost = start;
  17525. do {
  17526. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  17527. p = p.next;
  17528. } while ( p !== start );
  17529. return leftmost;
  17530. }
  17531. // check if a point lies within a convex triangle
  17532. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17533. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17534. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17535. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17536. }
  17537. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17538. function isValidDiagonal( a, b ) {
  17539. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17540. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17541. }
  17542. // signed area of a triangle
  17543. function area( p, q, r ) {
  17544. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17545. }
  17546. // check if two points are equal
  17547. function equals( p1, p2 ) {
  17548. return p1.x === p2.x && p1.y === p2.y;
  17549. }
  17550. // check if two segments intersect
  17551. function intersects( p1, q1, p2, q2 ) {
  17552. if ( ( equals( p1, p2 ) && equals( q1, q2 ) ) ||
  17553. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17554. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17555. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17556. }
  17557. // check if a polygon diagonal intersects any polygon segments
  17558. function intersectsPolygon( a, b ) {
  17559. var p = a;
  17560. do {
  17561. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17562. intersects( p, p.next, a, b ) ) return true;
  17563. p = p.next;
  17564. } while ( p !== a );
  17565. return false;
  17566. }
  17567. // check if a polygon diagonal is locally inside the polygon
  17568. function locallyInside( a, b ) {
  17569. return area( a.prev, a, a.next ) < 0 ?
  17570. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17571. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17572. }
  17573. // check if the middle point of a polygon diagonal is inside the polygon
  17574. function middleInside( a, b ) {
  17575. var p = a,
  17576. inside = false,
  17577. px = ( a.x + b.x ) / 2,
  17578. py = ( a.y + b.y ) / 2;
  17579. do {
  17580. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17581. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  17582. inside = ! inside;
  17583. p = p.next;
  17584. } while ( p !== a );
  17585. return inside;
  17586. }
  17587. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17588. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17589. function splitPolygon( a, b ) {
  17590. var a2 = new Node( a.i, a.x, a.y ),
  17591. b2 = new Node( b.i, b.x, b.y ),
  17592. an = a.next,
  17593. bp = b.prev;
  17594. a.next = b;
  17595. b.prev = a;
  17596. a2.next = an;
  17597. an.prev = a2;
  17598. b2.next = a2;
  17599. a2.prev = b2;
  17600. bp.next = b2;
  17601. b2.prev = bp;
  17602. return b2;
  17603. }
  17604. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17605. function insertNode( i, x, y, last ) {
  17606. var p = new Node( i, x, y );
  17607. if ( ! last ) {
  17608. p.prev = p;
  17609. p.next = p;
  17610. } else {
  17611. p.next = last.next;
  17612. p.prev = last;
  17613. last.next.prev = p;
  17614. last.next = p;
  17615. }
  17616. return p;
  17617. }
  17618. function removeNode( p ) {
  17619. p.next.prev = p.prev;
  17620. p.prev.next = p.next;
  17621. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17622. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17623. }
  17624. function Node( i, x, y ) {
  17625. // vertex index in coordinates array
  17626. this.i = i;
  17627. // vertex coordinates
  17628. this.x = x;
  17629. this.y = y;
  17630. // previous and next vertex nodes in a polygon ring
  17631. this.prev = null;
  17632. this.next = null;
  17633. // z-order curve value
  17634. this.z = null;
  17635. // previous and next nodes in z-order
  17636. this.prevZ = null;
  17637. this.nextZ = null;
  17638. // indicates whether this is a steiner point
  17639. this.steiner = false;
  17640. }
  17641. function signedArea( data, start, end, dim ) {
  17642. var sum = 0;
  17643. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17644. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17645. j = i;
  17646. }
  17647. return sum;
  17648. }
  17649. /**
  17650. * @author zz85 / http://www.lab4games.net/zz85/blog
  17651. */
  17652. var ShapeUtils = {
  17653. // calculate area of the contour polygon
  17654. area: function ( contour ) {
  17655. var n = contour.length;
  17656. var a = 0.0;
  17657. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17658. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17659. }
  17660. return a * 0.5;
  17661. },
  17662. isClockWise: function ( pts ) {
  17663. return ShapeUtils.area( pts ) < 0;
  17664. },
  17665. triangulateShape: function ( contour, holes ) {
  17666. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17667. var holeIndices = []; // array of hole indices
  17668. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17669. removeDupEndPts( contour );
  17670. addContour( vertices, contour );
  17671. //
  17672. var holeIndex = contour.length;
  17673. holes.forEach( removeDupEndPts );
  17674. for ( var i = 0; i < holes.length; i ++ ) {
  17675. holeIndices.push( holeIndex );
  17676. holeIndex += holes[ i ].length;
  17677. addContour( vertices, holes[ i ] );
  17678. }
  17679. //
  17680. var triangles = Earcut.triangulate( vertices, holeIndices );
  17681. //
  17682. for ( var i = 0; i < triangles.length; i += 3 ) {
  17683. faces.push( triangles.slice( i, i + 3 ) );
  17684. }
  17685. return faces;
  17686. }
  17687. };
  17688. function removeDupEndPts( points ) {
  17689. var l = points.length;
  17690. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17691. points.pop();
  17692. }
  17693. }
  17694. function addContour( vertices, contour ) {
  17695. for ( var i = 0; i < contour.length; i ++ ) {
  17696. vertices.push( contour[ i ].x );
  17697. vertices.push( contour[ i ].y );
  17698. }
  17699. }
  17700. /**
  17701. * @author zz85 / http://www.lab4games.net/zz85/blog
  17702. *
  17703. * Creates extruded geometry from a path shape.
  17704. *
  17705. * parameters = {
  17706. *
  17707. * curveSegments: <int>, // number of points on the curves
  17708. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17709. * depth: <float>, // Depth to extrude the shape
  17710. *
  17711. * bevelEnabled: <bool>, // turn on bevel
  17712. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17713. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17714. * bevelOffset: <float>, // how far from shape outline does bevel start
  17715. * bevelSegments: <int>, // number of bevel layers
  17716. *
  17717. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17718. *
  17719. * UVGenerator: <Object> // object that provides UV generator functions
  17720. *
  17721. * }
  17722. */
  17723. // ExtrudeGeometry
  17724. function ExtrudeGeometry( shapes, options ) {
  17725. Geometry.call( this );
  17726. this.type = 'ExtrudeGeometry';
  17727. this.parameters = {
  17728. shapes: shapes,
  17729. options: options
  17730. };
  17731. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17732. this.mergeVertices();
  17733. }
  17734. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17735. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17736. ExtrudeGeometry.prototype.toJSON = function () {
  17737. var data = Geometry.prototype.toJSON.call( this );
  17738. var shapes = this.parameters.shapes;
  17739. var options = this.parameters.options;
  17740. return toJSON( shapes, options, data );
  17741. };
  17742. // ExtrudeBufferGeometry
  17743. function ExtrudeBufferGeometry( shapes, options ) {
  17744. BufferGeometry.call( this );
  17745. this.type = 'ExtrudeBufferGeometry';
  17746. this.parameters = {
  17747. shapes: shapes,
  17748. options: options
  17749. };
  17750. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17751. var scope = this;
  17752. var verticesArray = [];
  17753. var uvArray = [];
  17754. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17755. var shape = shapes[ i ];
  17756. addShape( shape );
  17757. }
  17758. // build geometry
  17759. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17760. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17761. this.computeVertexNormals();
  17762. // functions
  17763. function addShape( shape ) {
  17764. var placeholder = [];
  17765. // options
  17766. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17767. var steps = options.steps !== undefined ? options.steps : 1;
  17768. var depth = options.depth !== undefined ? options.depth : 100;
  17769. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17770. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17771. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17772. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17773. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17774. var extrudePath = options.extrudePath;
  17775. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17776. // deprecated options
  17777. if ( options.amount !== undefined ) {
  17778. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17779. depth = options.amount;
  17780. }
  17781. //
  17782. var extrudePts, extrudeByPath = false;
  17783. var splineTube, binormal, normal, position2;
  17784. if ( extrudePath ) {
  17785. extrudePts = extrudePath.getSpacedPoints( steps );
  17786. extrudeByPath = true;
  17787. bevelEnabled = false; // bevels not supported for path extrusion
  17788. // SETUP TNB variables
  17789. // TODO1 - have a .isClosed in spline?
  17790. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17791. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17792. binormal = new Vector3();
  17793. normal = new Vector3();
  17794. position2 = new Vector3();
  17795. }
  17796. // Safeguards if bevels are not enabled
  17797. if ( ! bevelEnabled ) {
  17798. bevelSegments = 0;
  17799. bevelThickness = 0;
  17800. bevelSize = 0;
  17801. bevelOffset = 0;
  17802. }
  17803. // Variables initialization
  17804. var ahole, h, hl; // looping of holes
  17805. var shapePoints = shape.extractPoints( curveSegments );
  17806. var vertices = shapePoints.shape;
  17807. var holes = shapePoints.holes;
  17808. var reverse = ! ShapeUtils.isClockWise( vertices );
  17809. if ( reverse ) {
  17810. vertices = vertices.reverse();
  17811. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17812. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17813. ahole = holes[ h ];
  17814. if ( ShapeUtils.isClockWise( ahole ) ) {
  17815. holes[ h ] = ahole.reverse();
  17816. }
  17817. }
  17818. }
  17819. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17820. /* Vertices */
  17821. var contour = vertices; // vertices has all points but contour has only points of circumference
  17822. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17823. ahole = holes[ h ];
  17824. vertices = vertices.concat( ahole );
  17825. }
  17826. function scalePt2( pt, vec, size ) {
  17827. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17828. return vec.clone().multiplyScalar( size ).add( pt );
  17829. }
  17830. var b, bs, t, z,
  17831. vert, vlen = vertices.length,
  17832. face, flen = faces.length;
  17833. // Find directions for point movement
  17834. function getBevelVec( inPt, inPrev, inNext ) {
  17835. // computes for inPt the corresponding point inPt' on a new contour
  17836. // shifted by 1 unit (length of normalized vector) to the left
  17837. // if we walk along contour clockwise, this new contour is outside the old one
  17838. //
  17839. // inPt' is the intersection of the two lines parallel to the two
  17840. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17841. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17842. // good reading for geometry algorithms (here: line-line intersection)
  17843. // http://geomalgorithms.com/a05-_intersect-1.html
  17844. var v_prev_x = inPt.x - inPrev.x,
  17845. v_prev_y = inPt.y - inPrev.y;
  17846. var v_next_x = inNext.x - inPt.x,
  17847. v_next_y = inNext.y - inPt.y;
  17848. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17849. // check for collinear edges
  17850. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17851. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17852. // not collinear
  17853. // length of vectors for normalizing
  17854. var v_prev_len = Math.sqrt( v_prev_lensq );
  17855. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17856. // shift adjacent points by unit vectors to the left
  17857. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17858. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17859. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17860. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17861. // scaling factor for v_prev to intersection point
  17862. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17863. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17864. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17865. // vector from inPt to intersection point
  17866. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17867. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17868. // Don't normalize!, otherwise sharp corners become ugly
  17869. // but prevent crazy spikes
  17870. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17871. if ( v_trans_lensq <= 2 ) {
  17872. return new Vector2( v_trans_x, v_trans_y );
  17873. } else {
  17874. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17875. }
  17876. } else {
  17877. // handle special case of collinear edges
  17878. var direction_eq = false; // assumes: opposite
  17879. if ( v_prev_x > Number.EPSILON ) {
  17880. if ( v_next_x > Number.EPSILON ) {
  17881. direction_eq = true;
  17882. }
  17883. } else {
  17884. if ( v_prev_x < - Number.EPSILON ) {
  17885. if ( v_next_x < - Number.EPSILON ) {
  17886. direction_eq = true;
  17887. }
  17888. } else {
  17889. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17890. direction_eq = true;
  17891. }
  17892. }
  17893. }
  17894. if ( direction_eq ) {
  17895. // console.log("Warning: lines are a straight sequence");
  17896. v_trans_x = - v_prev_y;
  17897. v_trans_y = v_prev_x;
  17898. shrink_by = Math.sqrt( v_prev_lensq );
  17899. } else {
  17900. // console.log("Warning: lines are a straight spike");
  17901. v_trans_x = v_prev_x;
  17902. v_trans_y = v_prev_y;
  17903. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17904. }
  17905. }
  17906. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17907. }
  17908. var contourMovements = [];
  17909. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17910. if ( j === il ) j = 0;
  17911. if ( k === il ) k = 0;
  17912. // (j)---(i)---(k)
  17913. // console.log('i,j,k', i, j , k)
  17914. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17915. }
  17916. var holesMovements = [],
  17917. oneHoleMovements, verticesMovements = contourMovements.concat();
  17918. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17919. ahole = holes[ h ];
  17920. oneHoleMovements = [];
  17921. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17922. if ( j === il ) j = 0;
  17923. if ( k === il ) k = 0;
  17924. // (j)---(i)---(k)
  17925. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17926. }
  17927. holesMovements.push( oneHoleMovements );
  17928. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17929. }
  17930. // Loop bevelSegments, 1 for the front, 1 for the back
  17931. for ( b = 0; b < bevelSegments; b ++ ) {
  17932. //for ( b = bevelSegments; b > 0; b -- ) {
  17933. t = b / bevelSegments;
  17934. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17935. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17936. // contract shape
  17937. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17938. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17939. v( vert.x, vert.y, - z );
  17940. }
  17941. // expand holes
  17942. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17943. ahole = holes[ h ];
  17944. oneHoleMovements = holesMovements[ h ];
  17945. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17946. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17947. v( vert.x, vert.y, - z );
  17948. }
  17949. }
  17950. }
  17951. bs = bevelSize + bevelOffset;
  17952. // Back facing vertices
  17953. for ( i = 0; i < vlen; i ++ ) {
  17954. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17955. if ( ! extrudeByPath ) {
  17956. v( vert.x, vert.y, 0 );
  17957. } else {
  17958. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17959. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17960. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17961. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17962. v( position2.x, position2.y, position2.z );
  17963. }
  17964. }
  17965. // Add stepped vertices...
  17966. // Including front facing vertices
  17967. var s;
  17968. for ( s = 1; s <= steps; s ++ ) {
  17969. for ( i = 0; i < vlen; i ++ ) {
  17970. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17971. if ( ! extrudeByPath ) {
  17972. v( vert.x, vert.y, depth / steps * s );
  17973. } else {
  17974. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17975. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17976. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17977. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17978. v( position2.x, position2.y, position2.z );
  17979. }
  17980. }
  17981. }
  17982. // Add bevel segments planes
  17983. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17984. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17985. t = b / bevelSegments;
  17986. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17987. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17988. // contract shape
  17989. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17990. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17991. v( vert.x, vert.y, depth + z );
  17992. }
  17993. // expand holes
  17994. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17995. ahole = holes[ h ];
  17996. oneHoleMovements = holesMovements[ h ];
  17997. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17998. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17999. if ( ! extrudeByPath ) {
  18000. v( vert.x, vert.y, depth + z );
  18001. } else {
  18002. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18003. }
  18004. }
  18005. }
  18006. }
  18007. /* Faces */
  18008. // Top and bottom faces
  18009. buildLidFaces();
  18010. // Sides faces
  18011. buildSideFaces();
  18012. ///// Internal functions
  18013. function buildLidFaces() {
  18014. var start = verticesArray.length / 3;
  18015. if ( bevelEnabled ) {
  18016. var layer = 0; // steps + 1
  18017. var offset = vlen * layer;
  18018. // Bottom faces
  18019. for ( i = 0; i < flen; i ++ ) {
  18020. face = faces[ i ];
  18021. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18022. }
  18023. layer = steps + bevelSegments * 2;
  18024. offset = vlen * layer;
  18025. // Top faces
  18026. for ( i = 0; i < flen; i ++ ) {
  18027. face = faces[ i ];
  18028. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18029. }
  18030. } else {
  18031. // Bottom faces
  18032. for ( i = 0; i < flen; i ++ ) {
  18033. face = faces[ i ];
  18034. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18035. }
  18036. // Top faces
  18037. for ( i = 0; i < flen; i ++ ) {
  18038. face = faces[ i ];
  18039. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18040. }
  18041. }
  18042. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18043. }
  18044. // Create faces for the z-sides of the shape
  18045. function buildSideFaces() {
  18046. var start = verticesArray.length / 3;
  18047. var layeroffset = 0;
  18048. sidewalls( contour, layeroffset );
  18049. layeroffset += contour.length;
  18050. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18051. ahole = holes[ h ];
  18052. sidewalls( ahole, layeroffset );
  18053. //, true
  18054. layeroffset += ahole.length;
  18055. }
  18056. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18057. }
  18058. function sidewalls( contour, layeroffset ) {
  18059. var j, k;
  18060. i = contour.length;
  18061. while ( -- i >= 0 ) {
  18062. j = i;
  18063. k = i - 1;
  18064. if ( k < 0 ) k = contour.length - 1;
  18065. //console.log('b', i,j, i-1, k,vertices.length);
  18066. var s = 0,
  18067. sl = steps + bevelSegments * 2;
  18068. for ( s = 0; s < sl; s ++ ) {
  18069. var slen1 = vlen * s;
  18070. var slen2 = vlen * ( s + 1 );
  18071. var a = layeroffset + j + slen1,
  18072. b = layeroffset + k + slen1,
  18073. c = layeroffset + k + slen2,
  18074. d = layeroffset + j + slen2;
  18075. f4( a, b, c, d );
  18076. }
  18077. }
  18078. }
  18079. function v( x, y, z ) {
  18080. placeholder.push( x );
  18081. placeholder.push( y );
  18082. placeholder.push( z );
  18083. }
  18084. function f3( a, b, c ) {
  18085. addVertex( a );
  18086. addVertex( b );
  18087. addVertex( c );
  18088. var nextIndex = verticesArray.length / 3;
  18089. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18090. addUV( uvs[ 0 ] );
  18091. addUV( uvs[ 1 ] );
  18092. addUV( uvs[ 2 ] );
  18093. }
  18094. function f4( a, b, c, d ) {
  18095. addVertex( a );
  18096. addVertex( b );
  18097. addVertex( d );
  18098. addVertex( b );
  18099. addVertex( c );
  18100. addVertex( d );
  18101. var nextIndex = verticesArray.length / 3;
  18102. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18103. addUV( uvs[ 0 ] );
  18104. addUV( uvs[ 1 ] );
  18105. addUV( uvs[ 3 ] );
  18106. addUV( uvs[ 1 ] );
  18107. addUV( uvs[ 2 ] );
  18108. addUV( uvs[ 3 ] );
  18109. }
  18110. function addVertex( index ) {
  18111. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18112. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18113. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18114. }
  18115. function addUV( vector2 ) {
  18116. uvArray.push( vector2.x );
  18117. uvArray.push( vector2.y );
  18118. }
  18119. }
  18120. }
  18121. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18122. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  18123. ExtrudeBufferGeometry.prototype.toJSON = function () {
  18124. var data = BufferGeometry.prototype.toJSON.call( this );
  18125. var shapes = this.parameters.shapes;
  18126. var options = this.parameters.options;
  18127. return toJSON( shapes, options, data );
  18128. };
  18129. //
  18130. var WorldUVGenerator = {
  18131. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18132. var a_x = vertices[ indexA * 3 ];
  18133. var a_y = vertices[ indexA * 3 + 1 ];
  18134. var b_x = vertices[ indexB * 3 ];
  18135. var b_y = vertices[ indexB * 3 + 1 ];
  18136. var c_x = vertices[ indexC * 3 ];
  18137. var c_y = vertices[ indexC * 3 + 1 ];
  18138. return [
  18139. new Vector2( a_x, a_y ),
  18140. new Vector2( b_x, b_y ),
  18141. new Vector2( c_x, c_y )
  18142. ];
  18143. },
  18144. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  18145. var a_x = vertices[ indexA * 3 ];
  18146. var a_y = vertices[ indexA * 3 + 1 ];
  18147. var a_z = vertices[ indexA * 3 + 2 ];
  18148. var b_x = vertices[ indexB * 3 ];
  18149. var b_y = vertices[ indexB * 3 + 1 ];
  18150. var b_z = vertices[ indexB * 3 + 2 ];
  18151. var c_x = vertices[ indexC * 3 ];
  18152. var c_y = vertices[ indexC * 3 + 1 ];
  18153. var c_z = vertices[ indexC * 3 + 2 ];
  18154. var d_x = vertices[ indexD * 3 ];
  18155. var d_y = vertices[ indexD * 3 + 1 ];
  18156. var d_z = vertices[ indexD * 3 + 2 ];
  18157. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  18158. return [
  18159. new Vector2( a_x, 1 - a_z ),
  18160. new Vector2( b_x, 1 - b_z ),
  18161. new Vector2( c_x, 1 - c_z ),
  18162. new Vector2( d_x, 1 - d_z )
  18163. ];
  18164. } else {
  18165. return [
  18166. new Vector2( a_y, 1 - a_z ),
  18167. new Vector2( b_y, 1 - b_z ),
  18168. new Vector2( c_y, 1 - c_z ),
  18169. new Vector2( d_y, 1 - d_z )
  18170. ];
  18171. }
  18172. }
  18173. };
  18174. function toJSON( shapes, options, data ) {
  18175. //
  18176. data.shapes = [];
  18177. if ( Array.isArray( shapes ) ) {
  18178. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18179. var shape = shapes[ i ];
  18180. data.shapes.push( shape.uuid );
  18181. }
  18182. } else {
  18183. data.shapes.push( shapes.uuid );
  18184. }
  18185. //
  18186. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18187. return data;
  18188. }
  18189. /**
  18190. * @author zz85 / http://www.lab4games.net/zz85/blog
  18191. * @author alteredq / http://alteredqualia.com/
  18192. *
  18193. * Text = 3D Text
  18194. *
  18195. * parameters = {
  18196. * font: <THREE.Font>, // font
  18197. *
  18198. * size: <float>, // size of the text
  18199. * height: <float>, // thickness to extrude text
  18200. * curveSegments: <int>, // number of points on the curves
  18201. *
  18202. * bevelEnabled: <bool>, // turn on bevel
  18203. * bevelThickness: <float>, // how deep into text bevel goes
  18204. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18205. * bevelOffset: <float> // how far from text outline does bevel start
  18206. * }
  18207. */
  18208. // TextGeometry
  18209. function TextGeometry( text, parameters ) {
  18210. Geometry.call( this );
  18211. this.type = 'TextGeometry';
  18212. this.parameters = {
  18213. text: text,
  18214. parameters: parameters
  18215. };
  18216. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  18217. this.mergeVertices();
  18218. }
  18219. TextGeometry.prototype = Object.create( Geometry.prototype );
  18220. TextGeometry.prototype.constructor = TextGeometry;
  18221. // TextBufferGeometry
  18222. function TextBufferGeometry( text, parameters ) {
  18223. parameters = parameters || {};
  18224. var font = parameters.font;
  18225. if ( ! ( font && font.isFont ) ) {
  18226. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18227. return new Geometry();
  18228. }
  18229. var shapes = font.generateShapes( text, parameters.size );
  18230. // translate parameters to ExtrudeGeometry API
  18231. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18232. // defaults
  18233. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18234. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18235. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18236. ExtrudeBufferGeometry.call( this, shapes, parameters );
  18237. this.type = 'TextBufferGeometry';
  18238. }
  18239. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  18240. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  18241. /**
  18242. * @author mrdoob / http://mrdoob.com/
  18243. * @author benaadams / https://twitter.com/ben_a_adams
  18244. * @author Mugen87 / https://github.com/Mugen87
  18245. */
  18246. // SphereGeometry
  18247. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18248. Geometry.call( this );
  18249. this.type = 'SphereGeometry';
  18250. this.parameters = {
  18251. radius: radius,
  18252. widthSegments: widthSegments,
  18253. heightSegments: heightSegments,
  18254. phiStart: phiStart,
  18255. phiLength: phiLength,
  18256. thetaStart: thetaStart,
  18257. thetaLength: thetaLength
  18258. };
  18259. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  18260. this.mergeVertices();
  18261. }
  18262. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18263. SphereGeometry.prototype.constructor = SphereGeometry;
  18264. // SphereBufferGeometry
  18265. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18266. BufferGeometry.call( this );
  18267. this.type = 'SphereBufferGeometry';
  18268. this.parameters = {
  18269. radius: radius,
  18270. widthSegments: widthSegments,
  18271. heightSegments: heightSegments,
  18272. phiStart: phiStart,
  18273. phiLength: phiLength,
  18274. thetaStart: thetaStart,
  18275. thetaLength: thetaLength
  18276. };
  18277. radius = radius || 1;
  18278. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18279. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18280. phiStart = phiStart !== undefined ? phiStart : 0;
  18281. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18282. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18283. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18284. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18285. var ix, iy;
  18286. var index = 0;
  18287. var grid = [];
  18288. var vertex = new Vector3();
  18289. var normal = new Vector3();
  18290. // buffers
  18291. var indices = [];
  18292. var vertices = [];
  18293. var normals = [];
  18294. var uvs = [];
  18295. // generate vertices, normals and uvs
  18296. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18297. var verticesRow = [];
  18298. var v = iy / heightSegments;
  18299. // special case for the poles
  18300. var uOffset = 0;
  18301. if ( iy == 0 && thetaStart == 0 ) {
  18302. uOffset = 0.5 / widthSegments;
  18303. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18304. uOffset = - 0.5 / widthSegments;
  18305. }
  18306. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18307. var u = ix / widthSegments;
  18308. // vertex
  18309. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18310. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18311. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18312. vertices.push( vertex.x, vertex.y, vertex.z );
  18313. // normal
  18314. normal.copy( vertex ).normalize();
  18315. normals.push( normal.x, normal.y, normal.z );
  18316. // uv
  18317. uvs.push( u + uOffset, 1 - v );
  18318. verticesRow.push( index ++ );
  18319. }
  18320. grid.push( verticesRow );
  18321. }
  18322. // indices
  18323. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18324. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18325. var a = grid[ iy ][ ix + 1 ];
  18326. var b = grid[ iy ][ ix ];
  18327. var c = grid[ iy + 1 ][ ix ];
  18328. var d = grid[ iy + 1 ][ ix + 1 ];
  18329. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18330. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18331. }
  18332. }
  18333. // build geometry
  18334. this.setIndex( indices );
  18335. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18336. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18337. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18338. }
  18339. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18340. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18341. /**
  18342. * @author Kaleb Murphy
  18343. * @author Mugen87 / https://github.com/Mugen87
  18344. */
  18345. // RingGeometry
  18346. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18347. Geometry.call( this );
  18348. this.type = 'RingGeometry';
  18349. this.parameters = {
  18350. innerRadius: innerRadius,
  18351. outerRadius: outerRadius,
  18352. thetaSegments: thetaSegments,
  18353. phiSegments: phiSegments,
  18354. thetaStart: thetaStart,
  18355. thetaLength: thetaLength
  18356. };
  18357. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18358. this.mergeVertices();
  18359. }
  18360. RingGeometry.prototype = Object.create( Geometry.prototype );
  18361. RingGeometry.prototype.constructor = RingGeometry;
  18362. // RingBufferGeometry
  18363. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18364. BufferGeometry.call( this );
  18365. this.type = 'RingBufferGeometry';
  18366. this.parameters = {
  18367. innerRadius: innerRadius,
  18368. outerRadius: outerRadius,
  18369. thetaSegments: thetaSegments,
  18370. phiSegments: phiSegments,
  18371. thetaStart: thetaStart,
  18372. thetaLength: thetaLength
  18373. };
  18374. innerRadius = innerRadius || 0.5;
  18375. outerRadius = outerRadius || 1;
  18376. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18377. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18378. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18379. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18380. // buffers
  18381. var indices = [];
  18382. var vertices = [];
  18383. var normals = [];
  18384. var uvs = [];
  18385. // some helper variables
  18386. var segment;
  18387. var radius = innerRadius;
  18388. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18389. var vertex = new Vector3();
  18390. var uv = new Vector2();
  18391. var j, i;
  18392. // generate vertices, normals and uvs
  18393. for ( j = 0; j <= phiSegments; j ++ ) {
  18394. for ( i = 0; i <= thetaSegments; i ++ ) {
  18395. // values are generate from the inside of the ring to the outside
  18396. segment = thetaStart + i / thetaSegments * thetaLength;
  18397. // vertex
  18398. vertex.x = radius * Math.cos( segment );
  18399. vertex.y = radius * Math.sin( segment );
  18400. vertices.push( vertex.x, vertex.y, vertex.z );
  18401. // normal
  18402. normals.push( 0, 0, 1 );
  18403. // uv
  18404. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18405. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18406. uvs.push( uv.x, uv.y );
  18407. }
  18408. // increase the radius for next row of vertices
  18409. radius += radiusStep;
  18410. }
  18411. // indices
  18412. for ( j = 0; j < phiSegments; j ++ ) {
  18413. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18414. for ( i = 0; i < thetaSegments; i ++ ) {
  18415. segment = i + thetaSegmentLevel;
  18416. var a = segment;
  18417. var b = segment + thetaSegments + 1;
  18418. var c = segment + thetaSegments + 2;
  18419. var d = segment + 1;
  18420. // faces
  18421. indices.push( a, b, d );
  18422. indices.push( b, c, d );
  18423. }
  18424. }
  18425. // build geometry
  18426. this.setIndex( indices );
  18427. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18428. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18429. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18430. }
  18431. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18432. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18433. /**
  18434. * @author zz85 / https://github.com/zz85
  18435. * @author bhouston / http://clara.io
  18436. * @author Mugen87 / https://github.com/Mugen87
  18437. */
  18438. // LatheGeometry
  18439. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18440. Geometry.call( this );
  18441. this.type = 'LatheGeometry';
  18442. this.parameters = {
  18443. points: points,
  18444. segments: segments,
  18445. phiStart: phiStart,
  18446. phiLength: phiLength
  18447. };
  18448. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18449. this.mergeVertices();
  18450. }
  18451. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18452. LatheGeometry.prototype.constructor = LatheGeometry;
  18453. // LatheBufferGeometry
  18454. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18455. BufferGeometry.call( this );
  18456. this.type = 'LatheBufferGeometry';
  18457. this.parameters = {
  18458. points: points,
  18459. segments: segments,
  18460. phiStart: phiStart,
  18461. phiLength: phiLength
  18462. };
  18463. segments = Math.floor( segments ) || 12;
  18464. phiStart = phiStart || 0;
  18465. phiLength = phiLength || Math.PI * 2;
  18466. // clamp phiLength so it's in range of [ 0, 2PI ]
  18467. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18468. // buffers
  18469. var indices = [];
  18470. var vertices = [];
  18471. var uvs = [];
  18472. // helper variables
  18473. var base;
  18474. var inverseSegments = 1.0 / segments;
  18475. var vertex = new Vector3();
  18476. var uv = new Vector2();
  18477. var i, j;
  18478. // generate vertices and uvs
  18479. for ( i = 0; i <= segments; i ++ ) {
  18480. var phi = phiStart + i * inverseSegments * phiLength;
  18481. var sin = Math.sin( phi );
  18482. var cos = Math.cos( phi );
  18483. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18484. // vertex
  18485. vertex.x = points[ j ].x * sin;
  18486. vertex.y = points[ j ].y;
  18487. vertex.z = points[ j ].x * cos;
  18488. vertices.push( vertex.x, vertex.y, vertex.z );
  18489. // uv
  18490. uv.x = i / segments;
  18491. uv.y = j / ( points.length - 1 );
  18492. uvs.push( uv.x, uv.y );
  18493. }
  18494. }
  18495. // indices
  18496. for ( i = 0; i < segments; i ++ ) {
  18497. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18498. base = j + i * points.length;
  18499. var a = base;
  18500. var b = base + points.length;
  18501. var c = base + points.length + 1;
  18502. var d = base + 1;
  18503. // faces
  18504. indices.push( a, b, d );
  18505. indices.push( b, c, d );
  18506. }
  18507. }
  18508. // build geometry
  18509. this.setIndex( indices );
  18510. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18511. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18512. // generate normals
  18513. this.computeVertexNormals();
  18514. // if the geometry is closed, we need to average the normals along the seam.
  18515. // because the corresponding vertices are identical (but still have different UVs).
  18516. if ( phiLength === Math.PI * 2 ) {
  18517. var normals = this.attributes.normal.array;
  18518. var n1 = new Vector3();
  18519. var n2 = new Vector3();
  18520. var n = new Vector3();
  18521. // this is the buffer offset for the last line of vertices
  18522. base = segments * points.length * 3;
  18523. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18524. // select the normal of the vertex in the first line
  18525. n1.x = normals[ j + 0 ];
  18526. n1.y = normals[ j + 1 ];
  18527. n1.z = normals[ j + 2 ];
  18528. // select the normal of the vertex in the last line
  18529. n2.x = normals[ base + j + 0 ];
  18530. n2.y = normals[ base + j + 1 ];
  18531. n2.z = normals[ base + j + 2 ];
  18532. // average normals
  18533. n.addVectors( n1, n2 ).normalize();
  18534. // assign the new values to both normals
  18535. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18536. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18537. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18538. }
  18539. }
  18540. }
  18541. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18542. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18543. /**
  18544. * @author jonobr1 / http://jonobr1.com
  18545. * @author Mugen87 / https://github.com/Mugen87
  18546. */
  18547. // ShapeGeometry
  18548. function ShapeGeometry( shapes, curveSegments ) {
  18549. Geometry.call( this );
  18550. this.type = 'ShapeGeometry';
  18551. if ( typeof curveSegments === 'object' ) {
  18552. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18553. curveSegments = curveSegments.curveSegments;
  18554. }
  18555. this.parameters = {
  18556. shapes: shapes,
  18557. curveSegments: curveSegments
  18558. };
  18559. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18560. this.mergeVertices();
  18561. }
  18562. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18563. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18564. ShapeGeometry.prototype.toJSON = function () {
  18565. var data = Geometry.prototype.toJSON.call( this );
  18566. var shapes = this.parameters.shapes;
  18567. return toJSON$1( shapes, data );
  18568. };
  18569. // ShapeBufferGeometry
  18570. function ShapeBufferGeometry( shapes, curveSegments ) {
  18571. BufferGeometry.call( this );
  18572. this.type = 'ShapeBufferGeometry';
  18573. this.parameters = {
  18574. shapes: shapes,
  18575. curveSegments: curveSegments
  18576. };
  18577. curveSegments = curveSegments || 12;
  18578. // buffers
  18579. var indices = [];
  18580. var vertices = [];
  18581. var normals = [];
  18582. var uvs = [];
  18583. // helper variables
  18584. var groupStart = 0;
  18585. var groupCount = 0;
  18586. // allow single and array values for "shapes" parameter
  18587. if ( Array.isArray( shapes ) === false ) {
  18588. addShape( shapes );
  18589. } else {
  18590. for ( var i = 0; i < shapes.length; i ++ ) {
  18591. addShape( shapes[ i ] );
  18592. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18593. groupStart += groupCount;
  18594. groupCount = 0;
  18595. }
  18596. }
  18597. // build geometry
  18598. this.setIndex( indices );
  18599. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18600. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18601. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18602. // helper functions
  18603. function addShape( shape ) {
  18604. var i, l, shapeHole;
  18605. var indexOffset = vertices.length / 3;
  18606. var points = shape.extractPoints( curveSegments );
  18607. var shapeVertices = points.shape;
  18608. var shapeHoles = points.holes;
  18609. // check direction of vertices
  18610. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18611. shapeVertices = shapeVertices.reverse();
  18612. }
  18613. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18614. shapeHole = shapeHoles[ i ];
  18615. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18616. shapeHoles[ i ] = shapeHole.reverse();
  18617. }
  18618. }
  18619. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18620. // join vertices of inner and outer paths to a single array
  18621. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18622. shapeHole = shapeHoles[ i ];
  18623. shapeVertices = shapeVertices.concat( shapeHole );
  18624. }
  18625. // vertices, normals, uvs
  18626. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18627. var vertex = shapeVertices[ i ];
  18628. vertices.push( vertex.x, vertex.y, 0 );
  18629. normals.push( 0, 0, 1 );
  18630. uvs.push( vertex.x, vertex.y ); // world uvs
  18631. }
  18632. // incides
  18633. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18634. var face = faces[ i ];
  18635. var a = face[ 0 ] + indexOffset;
  18636. var b = face[ 1 ] + indexOffset;
  18637. var c = face[ 2 ] + indexOffset;
  18638. indices.push( a, b, c );
  18639. groupCount += 3;
  18640. }
  18641. }
  18642. }
  18643. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18644. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18645. ShapeBufferGeometry.prototype.toJSON = function () {
  18646. var data = BufferGeometry.prototype.toJSON.call( this );
  18647. var shapes = this.parameters.shapes;
  18648. return toJSON$1( shapes, data );
  18649. };
  18650. //
  18651. function toJSON$1( shapes, data ) {
  18652. data.shapes = [];
  18653. if ( Array.isArray( shapes ) ) {
  18654. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18655. var shape = shapes[ i ];
  18656. data.shapes.push( shape.uuid );
  18657. }
  18658. } else {
  18659. data.shapes.push( shapes.uuid );
  18660. }
  18661. return data;
  18662. }
  18663. /**
  18664. * @author WestLangley / http://github.com/WestLangley
  18665. * @author Mugen87 / https://github.com/Mugen87
  18666. */
  18667. function EdgesGeometry( geometry, thresholdAngle ) {
  18668. BufferGeometry.call( this );
  18669. this.type = 'EdgesGeometry';
  18670. this.parameters = {
  18671. thresholdAngle: thresholdAngle
  18672. };
  18673. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18674. // buffer
  18675. var vertices = [];
  18676. // helper variables
  18677. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18678. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18679. var key, keys = [ 'a', 'b', 'c' ];
  18680. // prepare source geometry
  18681. var geometry2;
  18682. if ( geometry.isBufferGeometry ) {
  18683. geometry2 = new Geometry();
  18684. geometry2.fromBufferGeometry( geometry );
  18685. } else {
  18686. geometry2 = geometry.clone();
  18687. }
  18688. geometry2.mergeVertices();
  18689. geometry2.computeFaceNormals();
  18690. var sourceVertices = geometry2.vertices;
  18691. var faces = geometry2.faces;
  18692. // now create a data structure where each entry represents an edge with its adjoining faces
  18693. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18694. var face = faces[ i ];
  18695. for ( var j = 0; j < 3; j ++ ) {
  18696. edge1 = face[ keys[ j ] ];
  18697. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18698. edge[ 0 ] = Math.min( edge1, edge2 );
  18699. edge[ 1 ] = Math.max( edge1, edge2 );
  18700. key = edge[ 0 ] + ',' + edge[ 1 ];
  18701. if ( edges[ key ] === undefined ) {
  18702. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18703. } else {
  18704. edges[ key ].face2 = i;
  18705. }
  18706. }
  18707. }
  18708. // generate vertices
  18709. for ( key in edges ) {
  18710. var e = edges[ key ];
  18711. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18712. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18713. var vertex = sourceVertices[ e.index1 ];
  18714. vertices.push( vertex.x, vertex.y, vertex.z );
  18715. vertex = sourceVertices[ e.index2 ];
  18716. vertices.push( vertex.x, vertex.y, vertex.z );
  18717. }
  18718. }
  18719. // build geometry
  18720. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18721. }
  18722. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18723. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18724. /**
  18725. * @author mrdoob / http://mrdoob.com/
  18726. * @author Mugen87 / https://github.com/Mugen87
  18727. */
  18728. // CylinderGeometry
  18729. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18730. Geometry.call( this );
  18731. this.type = 'CylinderGeometry';
  18732. this.parameters = {
  18733. radiusTop: radiusTop,
  18734. radiusBottom: radiusBottom,
  18735. height: height,
  18736. radialSegments: radialSegments,
  18737. heightSegments: heightSegments,
  18738. openEnded: openEnded,
  18739. thetaStart: thetaStart,
  18740. thetaLength: thetaLength
  18741. };
  18742. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18743. this.mergeVertices();
  18744. }
  18745. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18746. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18747. // CylinderBufferGeometry
  18748. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18749. BufferGeometry.call( this );
  18750. this.type = 'CylinderBufferGeometry';
  18751. this.parameters = {
  18752. radiusTop: radiusTop,
  18753. radiusBottom: radiusBottom,
  18754. height: height,
  18755. radialSegments: radialSegments,
  18756. heightSegments: heightSegments,
  18757. openEnded: openEnded,
  18758. thetaStart: thetaStart,
  18759. thetaLength: thetaLength
  18760. };
  18761. var scope = this;
  18762. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18763. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18764. height = height || 1;
  18765. radialSegments = Math.floor( radialSegments ) || 8;
  18766. heightSegments = Math.floor( heightSegments ) || 1;
  18767. openEnded = openEnded !== undefined ? openEnded : false;
  18768. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18769. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18770. // buffers
  18771. var indices = [];
  18772. var vertices = [];
  18773. var normals = [];
  18774. var uvs = [];
  18775. // helper variables
  18776. var index = 0;
  18777. var indexArray = [];
  18778. var halfHeight = height / 2;
  18779. var groupStart = 0;
  18780. // generate geometry
  18781. generateTorso();
  18782. if ( openEnded === false ) {
  18783. if ( radiusTop > 0 ) generateCap( true );
  18784. if ( radiusBottom > 0 ) generateCap( false );
  18785. }
  18786. // build geometry
  18787. this.setIndex( indices );
  18788. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18789. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18790. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18791. function generateTorso() {
  18792. var x, y;
  18793. var normal = new Vector3();
  18794. var vertex = new Vector3();
  18795. var groupCount = 0;
  18796. // this will be used to calculate the normal
  18797. var slope = ( radiusBottom - radiusTop ) / height;
  18798. // generate vertices, normals and uvs
  18799. for ( y = 0; y <= heightSegments; y ++ ) {
  18800. var indexRow = [];
  18801. var v = y / heightSegments;
  18802. // calculate the radius of the current row
  18803. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18804. for ( x = 0; x <= radialSegments; x ++ ) {
  18805. var u = x / radialSegments;
  18806. var theta = u * thetaLength + thetaStart;
  18807. var sinTheta = Math.sin( theta );
  18808. var cosTheta = Math.cos( theta );
  18809. // vertex
  18810. vertex.x = radius * sinTheta;
  18811. vertex.y = - v * height + halfHeight;
  18812. vertex.z = radius * cosTheta;
  18813. vertices.push( vertex.x, vertex.y, vertex.z );
  18814. // normal
  18815. normal.set( sinTheta, slope, cosTheta ).normalize();
  18816. normals.push( normal.x, normal.y, normal.z );
  18817. // uv
  18818. uvs.push( u, 1 - v );
  18819. // save index of vertex in respective row
  18820. indexRow.push( index ++ );
  18821. }
  18822. // now save vertices of the row in our index array
  18823. indexArray.push( indexRow );
  18824. }
  18825. // generate indices
  18826. for ( x = 0; x < radialSegments; x ++ ) {
  18827. for ( y = 0; y < heightSegments; y ++ ) {
  18828. // we use the index array to access the correct indices
  18829. var a = indexArray[ y ][ x ];
  18830. var b = indexArray[ y + 1 ][ x ];
  18831. var c = indexArray[ y + 1 ][ x + 1 ];
  18832. var d = indexArray[ y ][ x + 1 ];
  18833. // faces
  18834. indices.push( a, b, d );
  18835. indices.push( b, c, d );
  18836. // update group counter
  18837. groupCount += 6;
  18838. }
  18839. }
  18840. // add a group to the geometry. this will ensure multi material support
  18841. scope.addGroup( groupStart, groupCount, 0 );
  18842. // calculate new start value for groups
  18843. groupStart += groupCount;
  18844. }
  18845. function generateCap( top ) {
  18846. var x, centerIndexStart, centerIndexEnd;
  18847. var uv = new Vector2();
  18848. var vertex = new Vector3();
  18849. var groupCount = 0;
  18850. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18851. var sign = ( top === true ) ? 1 : - 1;
  18852. // save the index of the first center vertex
  18853. centerIndexStart = index;
  18854. // first we generate the center vertex data of the cap.
  18855. // because the geometry needs one set of uvs per face,
  18856. // we must generate a center vertex per face/segment
  18857. for ( x = 1; x <= radialSegments; x ++ ) {
  18858. // vertex
  18859. vertices.push( 0, halfHeight * sign, 0 );
  18860. // normal
  18861. normals.push( 0, sign, 0 );
  18862. // uv
  18863. uvs.push( 0.5, 0.5 );
  18864. // increase index
  18865. index ++;
  18866. }
  18867. // save the index of the last center vertex
  18868. centerIndexEnd = index;
  18869. // now we generate the surrounding vertices, normals and uvs
  18870. for ( x = 0; x <= radialSegments; x ++ ) {
  18871. var u = x / radialSegments;
  18872. var theta = u * thetaLength + thetaStart;
  18873. var cosTheta = Math.cos( theta );
  18874. var sinTheta = Math.sin( theta );
  18875. // vertex
  18876. vertex.x = radius * sinTheta;
  18877. vertex.y = halfHeight * sign;
  18878. vertex.z = radius * cosTheta;
  18879. vertices.push( vertex.x, vertex.y, vertex.z );
  18880. // normal
  18881. normals.push( 0, sign, 0 );
  18882. // uv
  18883. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18884. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18885. uvs.push( uv.x, uv.y );
  18886. // increase index
  18887. index ++;
  18888. }
  18889. // generate indices
  18890. for ( x = 0; x < radialSegments; x ++ ) {
  18891. var c = centerIndexStart + x;
  18892. var i = centerIndexEnd + x;
  18893. if ( top === true ) {
  18894. // face top
  18895. indices.push( i, i + 1, c );
  18896. } else {
  18897. // face bottom
  18898. indices.push( i + 1, i, c );
  18899. }
  18900. groupCount += 3;
  18901. }
  18902. // add a group to the geometry. this will ensure multi material support
  18903. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18904. // calculate new start value for groups
  18905. groupStart += groupCount;
  18906. }
  18907. }
  18908. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18909. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18910. /**
  18911. * @author abelnation / http://github.com/abelnation
  18912. */
  18913. // ConeGeometry
  18914. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18915. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18916. this.type = 'ConeGeometry';
  18917. this.parameters = {
  18918. radius: radius,
  18919. height: height,
  18920. radialSegments: radialSegments,
  18921. heightSegments: heightSegments,
  18922. openEnded: openEnded,
  18923. thetaStart: thetaStart,
  18924. thetaLength: thetaLength
  18925. };
  18926. }
  18927. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18928. ConeGeometry.prototype.constructor = ConeGeometry;
  18929. // ConeBufferGeometry
  18930. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18931. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18932. this.type = 'ConeBufferGeometry';
  18933. this.parameters = {
  18934. radius: radius,
  18935. height: height,
  18936. radialSegments: radialSegments,
  18937. heightSegments: heightSegments,
  18938. openEnded: openEnded,
  18939. thetaStart: thetaStart,
  18940. thetaLength: thetaLength
  18941. };
  18942. }
  18943. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18944. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18945. /**
  18946. * @author benaadams / https://twitter.com/ben_a_adams
  18947. * @author Mugen87 / https://github.com/Mugen87
  18948. * @author hughes
  18949. */
  18950. // CircleGeometry
  18951. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18952. Geometry.call( this );
  18953. this.type = 'CircleGeometry';
  18954. this.parameters = {
  18955. radius: radius,
  18956. segments: segments,
  18957. thetaStart: thetaStart,
  18958. thetaLength: thetaLength
  18959. };
  18960. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18961. this.mergeVertices();
  18962. }
  18963. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18964. CircleGeometry.prototype.constructor = CircleGeometry;
  18965. // CircleBufferGeometry
  18966. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18967. BufferGeometry.call( this );
  18968. this.type = 'CircleBufferGeometry';
  18969. this.parameters = {
  18970. radius: radius,
  18971. segments: segments,
  18972. thetaStart: thetaStart,
  18973. thetaLength: thetaLength
  18974. };
  18975. radius = radius || 1;
  18976. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18977. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18978. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18979. // buffers
  18980. var indices = [];
  18981. var vertices = [];
  18982. var normals = [];
  18983. var uvs = [];
  18984. // helper variables
  18985. var i, s;
  18986. var vertex = new Vector3();
  18987. var uv = new Vector2();
  18988. // center point
  18989. vertices.push( 0, 0, 0 );
  18990. normals.push( 0, 0, 1 );
  18991. uvs.push( 0.5, 0.5 );
  18992. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18993. var segment = thetaStart + s / segments * thetaLength;
  18994. // vertex
  18995. vertex.x = radius * Math.cos( segment );
  18996. vertex.y = radius * Math.sin( segment );
  18997. vertices.push( vertex.x, vertex.y, vertex.z );
  18998. // normal
  18999. normals.push( 0, 0, 1 );
  19000. // uvs
  19001. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19002. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19003. uvs.push( uv.x, uv.y );
  19004. }
  19005. // indices
  19006. for ( i = 1; i <= segments; i ++ ) {
  19007. indices.push( i, i + 1, 0 );
  19008. }
  19009. // build geometry
  19010. this.setIndex( indices );
  19011. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19012. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19013. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19014. }
  19015. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19016. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19017. var Geometries = /*#__PURE__*/Object.freeze({
  19018. WireframeGeometry: WireframeGeometry,
  19019. ParametricGeometry: ParametricGeometry,
  19020. ParametricBufferGeometry: ParametricBufferGeometry,
  19021. TetrahedronGeometry: TetrahedronGeometry,
  19022. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19023. OctahedronGeometry: OctahedronGeometry,
  19024. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19025. IcosahedronGeometry: IcosahedronGeometry,
  19026. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19027. DodecahedronGeometry: DodecahedronGeometry,
  19028. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19029. PolyhedronGeometry: PolyhedronGeometry,
  19030. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19031. TubeGeometry: TubeGeometry,
  19032. TubeBufferGeometry: TubeBufferGeometry,
  19033. TorusKnotGeometry: TorusKnotGeometry,
  19034. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19035. TorusGeometry: TorusGeometry,
  19036. TorusBufferGeometry: TorusBufferGeometry,
  19037. TextGeometry: TextGeometry,
  19038. TextBufferGeometry: TextBufferGeometry,
  19039. SphereGeometry: SphereGeometry,
  19040. SphereBufferGeometry: SphereBufferGeometry,
  19041. RingGeometry: RingGeometry,
  19042. RingBufferGeometry: RingBufferGeometry,
  19043. PlaneGeometry: PlaneGeometry,
  19044. PlaneBufferGeometry: PlaneBufferGeometry,
  19045. LatheGeometry: LatheGeometry,
  19046. LatheBufferGeometry: LatheBufferGeometry,
  19047. ShapeGeometry: ShapeGeometry,
  19048. ShapeBufferGeometry: ShapeBufferGeometry,
  19049. ExtrudeGeometry: ExtrudeGeometry,
  19050. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19051. EdgesGeometry: EdgesGeometry,
  19052. ConeGeometry: ConeGeometry,
  19053. ConeBufferGeometry: ConeBufferGeometry,
  19054. CylinderGeometry: CylinderGeometry,
  19055. CylinderBufferGeometry: CylinderBufferGeometry,
  19056. CircleGeometry: CircleGeometry,
  19057. CircleBufferGeometry: CircleBufferGeometry,
  19058. BoxGeometry: BoxGeometry,
  19059. BoxBufferGeometry: BoxBufferGeometry
  19060. });
  19061. /**
  19062. * @author mrdoob / http://mrdoob.com/
  19063. *
  19064. * parameters = {
  19065. * color: <THREE.Color>
  19066. * }
  19067. */
  19068. function ShadowMaterial( parameters ) {
  19069. Material.call( this );
  19070. this.type = 'ShadowMaterial';
  19071. this.color = new Color( 0x000000 );
  19072. this.transparent = true;
  19073. this.setValues( parameters );
  19074. }
  19075. ShadowMaterial.prototype = Object.create( Material.prototype );
  19076. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19077. ShadowMaterial.prototype.isShadowMaterial = true;
  19078. ShadowMaterial.prototype.copy = function ( source ) {
  19079. Material.prototype.copy.call( this, source );
  19080. this.color.copy( source.color );
  19081. return this;
  19082. };
  19083. /**
  19084. * @author mrdoob / http://mrdoob.com/
  19085. */
  19086. function RawShaderMaterial( parameters ) {
  19087. ShaderMaterial.call( this, parameters );
  19088. this.type = 'RawShaderMaterial';
  19089. }
  19090. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19091. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19092. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19093. /**
  19094. * @author WestLangley / http://github.com/WestLangley
  19095. *
  19096. * parameters = {
  19097. * color: <hex>,
  19098. * roughness: <float>,
  19099. * metalness: <float>,
  19100. * opacity: <float>,
  19101. *
  19102. * map: new THREE.Texture( <Image> ),
  19103. *
  19104. * lightMap: new THREE.Texture( <Image> ),
  19105. * lightMapIntensity: <float>
  19106. *
  19107. * aoMap: new THREE.Texture( <Image> ),
  19108. * aoMapIntensity: <float>
  19109. *
  19110. * emissive: <hex>,
  19111. * emissiveIntensity: <float>
  19112. * emissiveMap: new THREE.Texture( <Image> ),
  19113. *
  19114. * bumpMap: new THREE.Texture( <Image> ),
  19115. * bumpScale: <float>,
  19116. *
  19117. * normalMap: new THREE.Texture( <Image> ),
  19118. * normalMapType: THREE.TangentSpaceNormalMap,
  19119. * normalScale: <Vector2>,
  19120. *
  19121. * displacementMap: new THREE.Texture( <Image> ),
  19122. * displacementScale: <float>,
  19123. * displacementBias: <float>,
  19124. *
  19125. * roughnessMap: new THREE.Texture( <Image> ),
  19126. *
  19127. * metalnessMap: new THREE.Texture( <Image> ),
  19128. *
  19129. * alphaMap: new THREE.Texture( <Image> ),
  19130. *
  19131. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19132. * envMapIntensity: <float>
  19133. *
  19134. * refractionRatio: <float>,
  19135. *
  19136. * wireframe: <boolean>,
  19137. * wireframeLinewidth: <float>,
  19138. *
  19139. * skinning: <bool>,
  19140. * morphTargets: <bool>,
  19141. * morphNormals: <bool>
  19142. * }
  19143. */
  19144. function MeshStandardMaterial( parameters ) {
  19145. Material.call( this );
  19146. this.defines = { 'STANDARD': '' };
  19147. this.type = 'MeshStandardMaterial';
  19148. this.color = new Color( 0xffffff ); // diffuse
  19149. this.roughness = 0.5;
  19150. this.metalness = 0.5;
  19151. this.map = null;
  19152. this.lightMap = null;
  19153. this.lightMapIntensity = 1.0;
  19154. this.aoMap = null;
  19155. this.aoMapIntensity = 1.0;
  19156. this.emissive = new Color( 0x000000 );
  19157. this.emissiveIntensity = 1.0;
  19158. this.emissiveMap = null;
  19159. this.bumpMap = null;
  19160. this.bumpScale = 1;
  19161. this.normalMap = null;
  19162. this.normalMapType = TangentSpaceNormalMap;
  19163. this.normalScale = new Vector2( 1, 1 );
  19164. this.displacementMap = null;
  19165. this.displacementScale = 1;
  19166. this.displacementBias = 0;
  19167. this.roughnessMap = null;
  19168. this.metalnessMap = null;
  19169. this.alphaMap = null;
  19170. this.envMap = null;
  19171. this.envMapIntensity = 1.0;
  19172. this.refractionRatio = 0.98;
  19173. this.wireframe = false;
  19174. this.wireframeLinewidth = 1;
  19175. this.wireframeLinecap = 'round';
  19176. this.wireframeLinejoin = 'round';
  19177. this.skinning = false;
  19178. this.morphTargets = false;
  19179. this.morphNormals = false;
  19180. this.setValues( parameters );
  19181. }
  19182. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  19183. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19184. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19185. MeshStandardMaterial.prototype.copy = function ( source ) {
  19186. Material.prototype.copy.call( this, source );
  19187. this.defines = { 'STANDARD': '' };
  19188. this.color.copy( source.color );
  19189. this.roughness = source.roughness;
  19190. this.metalness = source.metalness;
  19191. this.map = source.map;
  19192. this.lightMap = source.lightMap;
  19193. this.lightMapIntensity = source.lightMapIntensity;
  19194. this.aoMap = source.aoMap;
  19195. this.aoMapIntensity = source.aoMapIntensity;
  19196. this.emissive.copy( source.emissive );
  19197. this.emissiveMap = source.emissiveMap;
  19198. this.emissiveIntensity = source.emissiveIntensity;
  19199. this.bumpMap = source.bumpMap;
  19200. this.bumpScale = source.bumpScale;
  19201. this.normalMap = source.normalMap;
  19202. this.normalMapType = source.normalMapType;
  19203. this.normalScale.copy( source.normalScale );
  19204. this.displacementMap = source.displacementMap;
  19205. this.displacementScale = source.displacementScale;
  19206. this.displacementBias = source.displacementBias;
  19207. this.roughnessMap = source.roughnessMap;
  19208. this.metalnessMap = source.metalnessMap;
  19209. this.alphaMap = source.alphaMap;
  19210. this.envMap = source.envMap;
  19211. this.envMapIntensity = source.envMapIntensity;
  19212. this.refractionRatio = source.refractionRatio;
  19213. this.wireframe = source.wireframe;
  19214. this.wireframeLinewidth = source.wireframeLinewidth;
  19215. this.wireframeLinecap = source.wireframeLinecap;
  19216. this.wireframeLinejoin = source.wireframeLinejoin;
  19217. this.skinning = source.skinning;
  19218. this.morphTargets = source.morphTargets;
  19219. this.morphNormals = source.morphNormals;
  19220. return this;
  19221. };
  19222. /**
  19223. * @author WestLangley / http://github.com/WestLangley
  19224. *
  19225. * parameters = {
  19226. * reflectivity: <float>
  19227. * clearCoat: <float>
  19228. * clearCoatRoughness: <float>
  19229. *
  19230. * clearCoatNormalScale: <Vector2>,
  19231. * clearCoatNormalMap: new THREE.Texture( <Image> ),
  19232. * }
  19233. */
  19234. function MeshPhysicalMaterial( parameters ) {
  19235. MeshStandardMaterial.call( this );
  19236. this.defines = { 'PHYSICAL': '' };
  19237. this.type = 'MeshPhysicalMaterial';
  19238. this.reflectivity = 0.5; // maps to F0 = 0.04
  19239. this.clearCoat = 0.0;
  19240. this.clearCoatRoughness = 0.0;
  19241. this.clearCoatNormalScale = new Vector2( 1, 1 );
  19242. this.clearCoatNormalMap = null;
  19243. this.setValues( parameters );
  19244. }
  19245. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  19246. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19247. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19248. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  19249. MeshStandardMaterial.prototype.copy.call( this, source );
  19250. this.defines = { 'PHYSICAL': '' };
  19251. this.reflectivity = source.reflectivity;
  19252. this.clearCoat = source.clearCoat;
  19253. this.clearCoatRoughness = source.clearCoatRoughness;
  19254. this.clearCoatNormalMap = source.clearCoatNormalMap;
  19255. this.clearCoatNormalScale.copy( source.clearCoatNormalScale );
  19256. return this;
  19257. };
  19258. /**
  19259. * @author mrdoob / http://mrdoob.com/
  19260. * @author alteredq / http://alteredqualia.com/
  19261. *
  19262. * parameters = {
  19263. * color: <hex>,
  19264. * specular: <hex>,
  19265. * shininess: <float>,
  19266. * opacity: <float>,
  19267. *
  19268. * map: new THREE.Texture( <Image> ),
  19269. *
  19270. * lightMap: new THREE.Texture( <Image> ),
  19271. * lightMapIntensity: <float>
  19272. *
  19273. * aoMap: new THREE.Texture( <Image> ),
  19274. * aoMapIntensity: <float>
  19275. *
  19276. * emissive: <hex>,
  19277. * emissiveIntensity: <float>
  19278. * emissiveMap: new THREE.Texture( <Image> ),
  19279. *
  19280. * bumpMap: new THREE.Texture( <Image> ),
  19281. * bumpScale: <float>,
  19282. *
  19283. * normalMap: new THREE.Texture( <Image> ),
  19284. * normalMapType: THREE.TangentSpaceNormalMap,
  19285. * normalScale: <Vector2>,
  19286. *
  19287. * displacementMap: new THREE.Texture( <Image> ),
  19288. * displacementScale: <float>,
  19289. * displacementBias: <float>,
  19290. *
  19291. * specularMap: new THREE.Texture( <Image> ),
  19292. *
  19293. * alphaMap: new THREE.Texture( <Image> ),
  19294. *
  19295. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19296. * combine: THREE.Multiply,
  19297. * reflectivity: <float>,
  19298. * refractionRatio: <float>,
  19299. *
  19300. * wireframe: <boolean>,
  19301. * wireframeLinewidth: <float>,
  19302. *
  19303. * skinning: <bool>,
  19304. * morphTargets: <bool>,
  19305. * morphNormals: <bool>
  19306. * }
  19307. */
  19308. function MeshPhongMaterial( parameters ) {
  19309. Material.call( this );
  19310. this.type = 'MeshPhongMaterial';
  19311. this.color = new Color( 0xffffff ); // diffuse
  19312. this.specular = new Color( 0x111111 );
  19313. this.shininess = 30;
  19314. this.map = null;
  19315. this.lightMap = null;
  19316. this.lightMapIntensity = 1.0;
  19317. this.aoMap = null;
  19318. this.aoMapIntensity = 1.0;
  19319. this.emissive = new Color( 0x000000 );
  19320. this.emissiveIntensity = 1.0;
  19321. this.emissiveMap = null;
  19322. this.bumpMap = null;
  19323. this.bumpScale = 1;
  19324. this.normalMap = null;
  19325. this.normalMapType = TangentSpaceNormalMap;
  19326. this.normalScale = new Vector2( 1, 1 );
  19327. this.displacementMap = null;
  19328. this.displacementScale = 1;
  19329. this.displacementBias = 0;
  19330. this.specularMap = null;
  19331. this.alphaMap = null;
  19332. this.envMap = null;
  19333. this.combine = MultiplyOperation;
  19334. this.reflectivity = 1;
  19335. this.refractionRatio = 0.98;
  19336. this.wireframe = false;
  19337. this.wireframeLinewidth = 1;
  19338. this.wireframeLinecap = 'round';
  19339. this.wireframeLinejoin = 'round';
  19340. this.skinning = false;
  19341. this.morphTargets = false;
  19342. this.morphNormals = false;
  19343. this.setValues( parameters );
  19344. }
  19345. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19346. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19347. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19348. MeshPhongMaterial.prototype.copy = function ( source ) {
  19349. Material.prototype.copy.call( this, source );
  19350. this.color.copy( source.color );
  19351. this.specular.copy( source.specular );
  19352. this.shininess = source.shininess;
  19353. this.map = source.map;
  19354. this.lightMap = source.lightMap;
  19355. this.lightMapIntensity = source.lightMapIntensity;
  19356. this.aoMap = source.aoMap;
  19357. this.aoMapIntensity = source.aoMapIntensity;
  19358. this.emissive.copy( source.emissive );
  19359. this.emissiveMap = source.emissiveMap;
  19360. this.emissiveIntensity = source.emissiveIntensity;
  19361. this.bumpMap = source.bumpMap;
  19362. this.bumpScale = source.bumpScale;
  19363. this.normalMap = source.normalMap;
  19364. this.normalMapType = source.normalMapType;
  19365. this.normalScale.copy( source.normalScale );
  19366. this.displacementMap = source.displacementMap;
  19367. this.displacementScale = source.displacementScale;
  19368. this.displacementBias = source.displacementBias;
  19369. this.specularMap = source.specularMap;
  19370. this.alphaMap = source.alphaMap;
  19371. this.envMap = source.envMap;
  19372. this.combine = source.combine;
  19373. this.reflectivity = source.reflectivity;
  19374. this.refractionRatio = source.refractionRatio;
  19375. this.wireframe = source.wireframe;
  19376. this.wireframeLinewidth = source.wireframeLinewidth;
  19377. this.wireframeLinecap = source.wireframeLinecap;
  19378. this.wireframeLinejoin = source.wireframeLinejoin;
  19379. this.skinning = source.skinning;
  19380. this.morphTargets = source.morphTargets;
  19381. this.morphNormals = source.morphNormals;
  19382. return this;
  19383. };
  19384. /**
  19385. * @author takahirox / http://github.com/takahirox
  19386. *
  19387. * parameters = {
  19388. * gradientMap: new THREE.Texture( <Image> )
  19389. * }
  19390. */
  19391. function MeshToonMaterial( parameters ) {
  19392. MeshPhongMaterial.call( this );
  19393. this.defines = { 'TOON': '' };
  19394. this.type = 'MeshToonMaterial';
  19395. this.gradientMap = null;
  19396. this.setValues( parameters );
  19397. }
  19398. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19399. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19400. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19401. MeshToonMaterial.prototype.copy = function ( source ) {
  19402. MeshPhongMaterial.prototype.copy.call( this, source );
  19403. this.gradientMap = source.gradientMap;
  19404. return this;
  19405. };
  19406. /**
  19407. * @author mrdoob / http://mrdoob.com/
  19408. * @author WestLangley / http://github.com/WestLangley
  19409. *
  19410. * parameters = {
  19411. * opacity: <float>,
  19412. *
  19413. * bumpMap: new THREE.Texture( <Image> ),
  19414. * bumpScale: <float>,
  19415. *
  19416. * normalMap: new THREE.Texture( <Image> ),
  19417. * normalMapType: THREE.TangentSpaceNormalMap,
  19418. * normalScale: <Vector2>,
  19419. *
  19420. * displacementMap: new THREE.Texture( <Image> ),
  19421. * displacementScale: <float>,
  19422. * displacementBias: <float>,
  19423. *
  19424. * wireframe: <boolean>,
  19425. * wireframeLinewidth: <float>
  19426. *
  19427. * skinning: <bool>,
  19428. * morphTargets: <bool>,
  19429. * morphNormals: <bool>
  19430. * }
  19431. */
  19432. function MeshNormalMaterial( parameters ) {
  19433. Material.call( this );
  19434. this.type = 'MeshNormalMaterial';
  19435. this.bumpMap = null;
  19436. this.bumpScale = 1;
  19437. this.normalMap = null;
  19438. this.normalMapType = TangentSpaceNormalMap;
  19439. this.normalScale = new Vector2( 1, 1 );
  19440. this.displacementMap = null;
  19441. this.displacementScale = 1;
  19442. this.displacementBias = 0;
  19443. this.wireframe = false;
  19444. this.wireframeLinewidth = 1;
  19445. this.fog = false;
  19446. this.lights = false;
  19447. this.skinning = false;
  19448. this.morphTargets = false;
  19449. this.morphNormals = false;
  19450. this.setValues( parameters );
  19451. }
  19452. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19453. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19454. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19455. MeshNormalMaterial.prototype.copy = function ( source ) {
  19456. Material.prototype.copy.call( this, source );
  19457. this.bumpMap = source.bumpMap;
  19458. this.bumpScale = source.bumpScale;
  19459. this.normalMap = source.normalMap;
  19460. this.normalMapType = source.normalMapType;
  19461. this.normalScale.copy( source.normalScale );
  19462. this.displacementMap = source.displacementMap;
  19463. this.displacementScale = source.displacementScale;
  19464. this.displacementBias = source.displacementBias;
  19465. this.wireframe = source.wireframe;
  19466. this.wireframeLinewidth = source.wireframeLinewidth;
  19467. this.skinning = source.skinning;
  19468. this.morphTargets = source.morphTargets;
  19469. this.morphNormals = source.morphNormals;
  19470. return this;
  19471. };
  19472. /**
  19473. * @author mrdoob / http://mrdoob.com/
  19474. * @author alteredq / http://alteredqualia.com/
  19475. *
  19476. * parameters = {
  19477. * color: <hex>,
  19478. * opacity: <float>,
  19479. *
  19480. * map: new THREE.Texture( <Image> ),
  19481. *
  19482. * lightMap: new THREE.Texture( <Image> ),
  19483. * lightMapIntensity: <float>
  19484. *
  19485. * aoMap: new THREE.Texture( <Image> ),
  19486. * aoMapIntensity: <float>
  19487. *
  19488. * emissive: <hex>,
  19489. * emissiveIntensity: <float>
  19490. * emissiveMap: new THREE.Texture( <Image> ),
  19491. *
  19492. * specularMap: new THREE.Texture( <Image> ),
  19493. *
  19494. * alphaMap: new THREE.Texture( <Image> ),
  19495. *
  19496. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19497. * combine: THREE.Multiply,
  19498. * reflectivity: <float>,
  19499. * refractionRatio: <float>,
  19500. *
  19501. * wireframe: <boolean>,
  19502. * wireframeLinewidth: <float>,
  19503. *
  19504. * skinning: <bool>,
  19505. * morphTargets: <bool>,
  19506. * morphNormals: <bool>
  19507. * }
  19508. */
  19509. function MeshLambertMaterial( parameters ) {
  19510. Material.call( this );
  19511. this.type = 'MeshLambertMaterial';
  19512. this.color = new Color( 0xffffff ); // diffuse
  19513. this.map = null;
  19514. this.lightMap = null;
  19515. this.lightMapIntensity = 1.0;
  19516. this.aoMap = null;
  19517. this.aoMapIntensity = 1.0;
  19518. this.emissive = new Color( 0x000000 );
  19519. this.emissiveIntensity = 1.0;
  19520. this.emissiveMap = null;
  19521. this.specularMap = null;
  19522. this.alphaMap = null;
  19523. this.envMap = null;
  19524. this.combine = MultiplyOperation;
  19525. this.reflectivity = 1;
  19526. this.refractionRatio = 0.98;
  19527. this.wireframe = false;
  19528. this.wireframeLinewidth = 1;
  19529. this.wireframeLinecap = 'round';
  19530. this.wireframeLinejoin = 'round';
  19531. this.skinning = false;
  19532. this.morphTargets = false;
  19533. this.morphNormals = false;
  19534. this.setValues( parameters );
  19535. }
  19536. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19537. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19538. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19539. MeshLambertMaterial.prototype.copy = function ( source ) {
  19540. Material.prototype.copy.call( this, source );
  19541. this.color.copy( source.color );
  19542. this.map = source.map;
  19543. this.lightMap = source.lightMap;
  19544. this.lightMapIntensity = source.lightMapIntensity;
  19545. this.aoMap = source.aoMap;
  19546. this.aoMapIntensity = source.aoMapIntensity;
  19547. this.emissive.copy( source.emissive );
  19548. this.emissiveMap = source.emissiveMap;
  19549. this.emissiveIntensity = source.emissiveIntensity;
  19550. this.specularMap = source.specularMap;
  19551. this.alphaMap = source.alphaMap;
  19552. this.envMap = source.envMap;
  19553. this.combine = source.combine;
  19554. this.reflectivity = source.reflectivity;
  19555. this.refractionRatio = source.refractionRatio;
  19556. this.wireframe = source.wireframe;
  19557. this.wireframeLinewidth = source.wireframeLinewidth;
  19558. this.wireframeLinecap = source.wireframeLinecap;
  19559. this.wireframeLinejoin = source.wireframeLinejoin;
  19560. this.skinning = source.skinning;
  19561. this.morphTargets = source.morphTargets;
  19562. this.morphNormals = source.morphNormals;
  19563. return this;
  19564. };
  19565. /**
  19566. * @author WestLangley / http://github.com/WestLangley
  19567. *
  19568. * parameters = {
  19569. * color: <hex>,
  19570. * opacity: <float>,
  19571. *
  19572. * matcap: new THREE.Texture( <Image> ),
  19573. *
  19574. * map: new THREE.Texture( <Image> ),
  19575. *
  19576. * bumpMap: new THREE.Texture( <Image> ),
  19577. * bumpScale: <float>,
  19578. *
  19579. * normalMap: new THREE.Texture( <Image> ),
  19580. * normalMapType: THREE.TangentSpaceNormalMap,
  19581. * normalScale: <Vector2>,
  19582. *
  19583. * displacementMap: new THREE.Texture( <Image> ),
  19584. * displacementScale: <float>,
  19585. * displacementBias: <float>,
  19586. *
  19587. * alphaMap: new THREE.Texture( <Image> ),
  19588. *
  19589. * skinning: <bool>,
  19590. * morphTargets: <bool>,
  19591. * morphNormals: <bool>
  19592. * }
  19593. */
  19594. function MeshMatcapMaterial( parameters ) {
  19595. Material.call( this );
  19596. this.defines = { 'MATCAP': '' };
  19597. this.type = 'MeshMatcapMaterial';
  19598. this.color = new Color( 0xffffff ); // diffuse
  19599. this.matcap = null;
  19600. this.map = null;
  19601. this.bumpMap = null;
  19602. this.bumpScale = 1;
  19603. this.normalMap = null;
  19604. this.normalMapType = TangentSpaceNormalMap;
  19605. this.normalScale = new Vector2( 1, 1 );
  19606. this.displacementMap = null;
  19607. this.displacementScale = 1;
  19608. this.displacementBias = 0;
  19609. this.alphaMap = null;
  19610. this.skinning = false;
  19611. this.morphTargets = false;
  19612. this.morphNormals = false;
  19613. this.lights = false;
  19614. this.setValues( parameters );
  19615. }
  19616. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19617. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19618. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19619. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19620. Material.prototype.copy.call( this, source );
  19621. this.defines = { 'MATCAP': '' };
  19622. this.color.copy( source.color );
  19623. this.matcap = source.matcap;
  19624. this.map = source.map;
  19625. this.bumpMap = source.bumpMap;
  19626. this.bumpScale = source.bumpScale;
  19627. this.normalMap = source.normalMap;
  19628. this.normalMapType = source.normalMapType;
  19629. this.normalScale.copy( source.normalScale );
  19630. this.displacementMap = source.displacementMap;
  19631. this.displacementScale = source.displacementScale;
  19632. this.displacementBias = source.displacementBias;
  19633. this.alphaMap = source.alphaMap;
  19634. this.skinning = source.skinning;
  19635. this.morphTargets = source.morphTargets;
  19636. this.morphNormals = source.morphNormals;
  19637. return this;
  19638. };
  19639. /**
  19640. * @author alteredq / http://alteredqualia.com/
  19641. *
  19642. * parameters = {
  19643. * color: <hex>,
  19644. * opacity: <float>,
  19645. *
  19646. * linewidth: <float>,
  19647. *
  19648. * scale: <float>,
  19649. * dashSize: <float>,
  19650. * gapSize: <float>
  19651. * }
  19652. */
  19653. function LineDashedMaterial( parameters ) {
  19654. LineBasicMaterial.call( this );
  19655. this.type = 'LineDashedMaterial';
  19656. this.scale = 1;
  19657. this.dashSize = 3;
  19658. this.gapSize = 1;
  19659. this.setValues( parameters );
  19660. }
  19661. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19662. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19663. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19664. LineDashedMaterial.prototype.copy = function ( source ) {
  19665. LineBasicMaterial.prototype.copy.call( this, source );
  19666. this.scale = source.scale;
  19667. this.dashSize = source.dashSize;
  19668. this.gapSize = source.gapSize;
  19669. return this;
  19670. };
  19671. var Materials = /*#__PURE__*/Object.freeze({
  19672. ShadowMaterial: ShadowMaterial,
  19673. SpriteMaterial: SpriteMaterial,
  19674. RawShaderMaterial: RawShaderMaterial,
  19675. ShaderMaterial: ShaderMaterial,
  19676. PointsMaterial: PointsMaterial,
  19677. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19678. MeshStandardMaterial: MeshStandardMaterial,
  19679. MeshPhongMaterial: MeshPhongMaterial,
  19680. MeshToonMaterial: MeshToonMaterial,
  19681. MeshNormalMaterial: MeshNormalMaterial,
  19682. MeshLambertMaterial: MeshLambertMaterial,
  19683. MeshDepthMaterial: MeshDepthMaterial,
  19684. MeshDistanceMaterial: MeshDistanceMaterial,
  19685. MeshBasicMaterial: MeshBasicMaterial,
  19686. MeshMatcapMaterial: MeshMatcapMaterial,
  19687. LineDashedMaterial: LineDashedMaterial,
  19688. LineBasicMaterial: LineBasicMaterial,
  19689. Material: Material
  19690. });
  19691. /**
  19692. * @author tschw
  19693. * @author Ben Houston / http://clara.io/
  19694. * @author David Sarno / http://lighthaus.us/
  19695. */
  19696. var AnimationUtils = {
  19697. // same as Array.prototype.slice, but also works on typed arrays
  19698. arraySlice: function ( array, from, to ) {
  19699. if ( AnimationUtils.isTypedArray( array ) ) {
  19700. // in ios9 array.subarray(from, undefined) will return empty array
  19701. // but array.subarray(from) or array.subarray(from, len) is correct
  19702. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19703. }
  19704. return array.slice( from, to );
  19705. },
  19706. // converts an array to a specific type
  19707. convertArray: function ( array, type, forceClone ) {
  19708. if ( ! array || // let 'undefined' and 'null' pass
  19709. ! forceClone && array.constructor === type ) return array;
  19710. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19711. return new type( array ); // create typed array
  19712. }
  19713. return Array.prototype.slice.call( array ); // create Array
  19714. },
  19715. isTypedArray: function ( object ) {
  19716. return ArrayBuffer.isView( object ) &&
  19717. ! ( object instanceof DataView );
  19718. },
  19719. // returns an array by which times and values can be sorted
  19720. getKeyframeOrder: function ( times ) {
  19721. function compareTime( i, j ) {
  19722. return times[ i ] - times[ j ];
  19723. }
  19724. var n = times.length;
  19725. var result = new Array( n );
  19726. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19727. result.sort( compareTime );
  19728. return result;
  19729. },
  19730. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19731. sortedArray: function ( values, stride, order ) {
  19732. var nValues = values.length;
  19733. var result = new values.constructor( nValues );
  19734. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19735. var srcOffset = order[ i ] * stride;
  19736. for ( var j = 0; j !== stride; ++ j ) {
  19737. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19738. }
  19739. }
  19740. return result;
  19741. },
  19742. // function for parsing AOS keyframe formats
  19743. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19744. var i = 1, key = jsonKeys[ 0 ];
  19745. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19746. key = jsonKeys[ i ++ ];
  19747. }
  19748. if ( key === undefined ) return; // no data
  19749. var value = key[ valuePropertyName ];
  19750. if ( value === undefined ) return; // no data
  19751. if ( Array.isArray( value ) ) {
  19752. do {
  19753. value = key[ valuePropertyName ];
  19754. if ( value !== undefined ) {
  19755. times.push( key.time );
  19756. values.push.apply( values, value ); // push all elements
  19757. }
  19758. key = jsonKeys[ i ++ ];
  19759. } while ( key !== undefined );
  19760. } else if ( value.toArray !== undefined ) {
  19761. // ...assume THREE.Math-ish
  19762. do {
  19763. value = key[ valuePropertyName ];
  19764. if ( value !== undefined ) {
  19765. times.push( key.time );
  19766. value.toArray( values, values.length );
  19767. }
  19768. key = jsonKeys[ i ++ ];
  19769. } while ( key !== undefined );
  19770. } else {
  19771. // otherwise push as-is
  19772. do {
  19773. value = key[ valuePropertyName ];
  19774. if ( value !== undefined ) {
  19775. times.push( key.time );
  19776. values.push( value );
  19777. }
  19778. key = jsonKeys[ i ++ ];
  19779. } while ( key !== undefined );
  19780. }
  19781. }
  19782. };
  19783. /**
  19784. * Abstract base class of interpolants over parametric samples.
  19785. *
  19786. * The parameter domain is one dimensional, typically the time or a path
  19787. * along a curve defined by the data.
  19788. *
  19789. * The sample values can have any dimensionality and derived classes may
  19790. * apply special interpretations to the data.
  19791. *
  19792. * This class provides the interval seek in a Template Method, deferring
  19793. * the actual interpolation to derived classes.
  19794. *
  19795. * Time complexity is O(1) for linear access crossing at most two points
  19796. * and O(log N) for random access, where N is the number of positions.
  19797. *
  19798. * References:
  19799. *
  19800. * http://www.oodesign.com/template-method-pattern.html
  19801. *
  19802. * @author tschw
  19803. */
  19804. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19805. this.parameterPositions = parameterPositions;
  19806. this._cachedIndex = 0;
  19807. this.resultBuffer = resultBuffer !== undefined ?
  19808. resultBuffer : new sampleValues.constructor( sampleSize );
  19809. this.sampleValues = sampleValues;
  19810. this.valueSize = sampleSize;
  19811. }
  19812. Object.assign( Interpolant.prototype, {
  19813. evaluate: function ( t ) {
  19814. var pp = this.parameterPositions,
  19815. i1 = this._cachedIndex,
  19816. t1 = pp[ i1 ],
  19817. t0 = pp[ i1 - 1 ];
  19818. validate_interval: {
  19819. seek: {
  19820. var right;
  19821. linear_scan: {
  19822. //- See http://jsperf.com/comparison-to-undefined/3
  19823. //- slower code:
  19824. //-
  19825. //- if ( t >= t1 || t1 === undefined ) {
  19826. forward_scan: if ( ! ( t < t1 ) ) {
  19827. for ( var giveUpAt = i1 + 2; ; ) {
  19828. if ( t1 === undefined ) {
  19829. if ( t < t0 ) break forward_scan;
  19830. // after end
  19831. i1 = pp.length;
  19832. this._cachedIndex = i1;
  19833. return this.afterEnd_( i1 - 1, t, t0 );
  19834. }
  19835. if ( i1 === giveUpAt ) break; // this loop
  19836. t0 = t1;
  19837. t1 = pp[ ++ i1 ];
  19838. if ( t < t1 ) {
  19839. // we have arrived at the sought interval
  19840. break seek;
  19841. }
  19842. }
  19843. // prepare binary search on the right side of the index
  19844. right = pp.length;
  19845. break linear_scan;
  19846. }
  19847. //- slower code:
  19848. //- if ( t < t0 || t0 === undefined ) {
  19849. if ( ! ( t >= t0 ) ) {
  19850. // looping?
  19851. var t1global = pp[ 1 ];
  19852. if ( t < t1global ) {
  19853. i1 = 2; // + 1, using the scan for the details
  19854. t0 = t1global;
  19855. }
  19856. // linear reverse scan
  19857. for ( var giveUpAt = i1 - 2; ; ) {
  19858. if ( t0 === undefined ) {
  19859. // before start
  19860. this._cachedIndex = 0;
  19861. return this.beforeStart_( 0, t, t1 );
  19862. }
  19863. if ( i1 === giveUpAt ) break; // this loop
  19864. t1 = t0;
  19865. t0 = pp[ -- i1 - 1 ];
  19866. if ( t >= t0 ) {
  19867. // we have arrived at the sought interval
  19868. break seek;
  19869. }
  19870. }
  19871. // prepare binary search on the left side of the index
  19872. right = i1;
  19873. i1 = 0;
  19874. break linear_scan;
  19875. }
  19876. // the interval is valid
  19877. break validate_interval;
  19878. } // linear scan
  19879. // binary search
  19880. while ( i1 < right ) {
  19881. var mid = ( i1 + right ) >>> 1;
  19882. if ( t < pp[ mid ] ) {
  19883. right = mid;
  19884. } else {
  19885. i1 = mid + 1;
  19886. }
  19887. }
  19888. t1 = pp[ i1 ];
  19889. t0 = pp[ i1 - 1 ];
  19890. // check boundary cases, again
  19891. if ( t0 === undefined ) {
  19892. this._cachedIndex = 0;
  19893. return this.beforeStart_( 0, t, t1 );
  19894. }
  19895. if ( t1 === undefined ) {
  19896. i1 = pp.length;
  19897. this._cachedIndex = i1;
  19898. return this.afterEnd_( i1 - 1, t0, t );
  19899. }
  19900. } // seek
  19901. this._cachedIndex = i1;
  19902. this.intervalChanged_( i1, t0, t1 );
  19903. } // validate_interval
  19904. return this.interpolate_( i1, t0, t, t1 );
  19905. },
  19906. settings: null, // optional, subclass-specific settings structure
  19907. // Note: The indirection allows central control of many interpolants.
  19908. // --- Protected interface
  19909. DefaultSettings_: {},
  19910. getSettings_: function () {
  19911. return this.settings || this.DefaultSettings_;
  19912. },
  19913. copySampleValue_: function ( index ) {
  19914. // copies a sample value to the result buffer
  19915. var result = this.resultBuffer,
  19916. values = this.sampleValues,
  19917. stride = this.valueSize,
  19918. offset = index * stride;
  19919. for ( var i = 0; i !== stride; ++ i ) {
  19920. result[ i ] = values[ offset + i ];
  19921. }
  19922. return result;
  19923. },
  19924. // Template methods for derived classes:
  19925. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19926. throw new Error( 'call to abstract method' );
  19927. // implementations shall return this.resultBuffer
  19928. },
  19929. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19930. // empty
  19931. }
  19932. } );
  19933. //!\ DECLARE ALIAS AFTER assign prototype !
  19934. Object.assign( Interpolant.prototype, {
  19935. //( 0, t, t0 ), returns this.resultBuffer
  19936. beforeStart_: Interpolant.prototype.copySampleValue_,
  19937. //( N-1, tN-1, t ), returns this.resultBuffer
  19938. afterEnd_: Interpolant.prototype.copySampleValue_,
  19939. } );
  19940. /**
  19941. * Fast and simple cubic spline interpolant.
  19942. *
  19943. * It was derived from a Hermitian construction setting the first derivative
  19944. * at each sample position to the linear slope between neighboring positions
  19945. * over their parameter interval.
  19946. *
  19947. * @author tschw
  19948. */
  19949. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19950. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19951. this._weightPrev = - 0;
  19952. this._offsetPrev = - 0;
  19953. this._weightNext = - 0;
  19954. this._offsetNext = - 0;
  19955. }
  19956. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19957. constructor: CubicInterpolant,
  19958. DefaultSettings_: {
  19959. endingStart: ZeroCurvatureEnding,
  19960. endingEnd: ZeroCurvatureEnding
  19961. },
  19962. intervalChanged_: function ( i1, t0, t1 ) {
  19963. var pp = this.parameterPositions,
  19964. iPrev = i1 - 2,
  19965. iNext = i1 + 1,
  19966. tPrev = pp[ iPrev ],
  19967. tNext = pp[ iNext ];
  19968. if ( tPrev === undefined ) {
  19969. switch ( this.getSettings_().endingStart ) {
  19970. case ZeroSlopeEnding:
  19971. // f'(t0) = 0
  19972. iPrev = i1;
  19973. tPrev = 2 * t0 - t1;
  19974. break;
  19975. case WrapAroundEnding:
  19976. // use the other end of the curve
  19977. iPrev = pp.length - 2;
  19978. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19979. break;
  19980. default: // ZeroCurvatureEnding
  19981. // f''(t0) = 0 a.k.a. Natural Spline
  19982. iPrev = i1;
  19983. tPrev = t1;
  19984. }
  19985. }
  19986. if ( tNext === undefined ) {
  19987. switch ( this.getSettings_().endingEnd ) {
  19988. case ZeroSlopeEnding:
  19989. // f'(tN) = 0
  19990. iNext = i1;
  19991. tNext = 2 * t1 - t0;
  19992. break;
  19993. case WrapAroundEnding:
  19994. // use the other end of the curve
  19995. iNext = 1;
  19996. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19997. break;
  19998. default: // ZeroCurvatureEnding
  19999. // f''(tN) = 0, a.k.a. Natural Spline
  20000. iNext = i1 - 1;
  20001. tNext = t0;
  20002. }
  20003. }
  20004. var halfDt = ( t1 - t0 ) * 0.5,
  20005. stride = this.valueSize;
  20006. this._weightPrev = halfDt / ( t0 - tPrev );
  20007. this._weightNext = halfDt / ( tNext - t1 );
  20008. this._offsetPrev = iPrev * stride;
  20009. this._offsetNext = iNext * stride;
  20010. },
  20011. interpolate_: function ( i1, t0, t, t1 ) {
  20012. var result = this.resultBuffer,
  20013. values = this.sampleValues,
  20014. stride = this.valueSize,
  20015. o1 = i1 * stride, o0 = o1 - stride,
  20016. oP = this._offsetPrev, oN = this._offsetNext,
  20017. wP = this._weightPrev, wN = this._weightNext,
  20018. p = ( t - t0 ) / ( t1 - t0 ),
  20019. pp = p * p,
  20020. ppp = pp * p;
  20021. // evaluate polynomials
  20022. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20023. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20024. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20025. var sN = wN * ppp - wN * pp;
  20026. // combine data linearly
  20027. for ( var i = 0; i !== stride; ++ i ) {
  20028. result[ i ] =
  20029. sP * values[ oP + i ] +
  20030. s0 * values[ o0 + i ] +
  20031. s1 * values[ o1 + i ] +
  20032. sN * values[ oN + i ];
  20033. }
  20034. return result;
  20035. }
  20036. } );
  20037. /**
  20038. * @author tschw
  20039. */
  20040. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20041. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20042. }
  20043. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20044. constructor: LinearInterpolant,
  20045. interpolate_: function ( i1, t0, t, t1 ) {
  20046. var result = this.resultBuffer,
  20047. values = this.sampleValues,
  20048. stride = this.valueSize,
  20049. offset1 = i1 * stride,
  20050. offset0 = offset1 - stride,
  20051. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20052. weight0 = 1 - weight1;
  20053. for ( var i = 0; i !== stride; ++ i ) {
  20054. result[ i ] =
  20055. values[ offset0 + i ] * weight0 +
  20056. values[ offset1 + i ] * weight1;
  20057. }
  20058. return result;
  20059. }
  20060. } );
  20061. /**
  20062. *
  20063. * Interpolant that evaluates to the sample value at the position preceeding
  20064. * the parameter.
  20065. *
  20066. * @author tschw
  20067. */
  20068. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20069. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20070. }
  20071. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20072. constructor: DiscreteInterpolant,
  20073. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20074. return this.copySampleValue_( i1 - 1 );
  20075. }
  20076. } );
  20077. /**
  20078. *
  20079. * A timed sequence of keyframes for a specific property.
  20080. *
  20081. *
  20082. * @author Ben Houston / http://clara.io/
  20083. * @author David Sarno / http://lighthaus.us/
  20084. * @author tschw
  20085. */
  20086. function KeyframeTrack( name, times, values, interpolation ) {
  20087. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20088. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20089. this.name = name;
  20090. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20091. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20092. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20093. }
  20094. // Static methods
  20095. Object.assign( KeyframeTrack, {
  20096. // Serialization (in static context, because of constructor invocation
  20097. // and automatic invocation of .toJSON):
  20098. toJSON: function ( track ) {
  20099. var trackType = track.constructor;
  20100. var json;
  20101. // derived classes can define a static toJSON method
  20102. if ( trackType.toJSON !== undefined ) {
  20103. json = trackType.toJSON( track );
  20104. } else {
  20105. // by default, we assume the data can be serialized as-is
  20106. json = {
  20107. 'name': track.name,
  20108. 'times': AnimationUtils.convertArray( track.times, Array ),
  20109. 'values': AnimationUtils.convertArray( track.values, Array )
  20110. };
  20111. var interpolation = track.getInterpolation();
  20112. if ( interpolation !== track.DefaultInterpolation ) {
  20113. json.interpolation = interpolation;
  20114. }
  20115. }
  20116. json.type = track.ValueTypeName; // mandatory
  20117. return json;
  20118. }
  20119. } );
  20120. Object.assign( KeyframeTrack.prototype, {
  20121. constructor: KeyframeTrack,
  20122. TimeBufferType: Float32Array,
  20123. ValueBufferType: Float32Array,
  20124. DefaultInterpolation: InterpolateLinear,
  20125. InterpolantFactoryMethodDiscrete: function ( result ) {
  20126. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20127. },
  20128. InterpolantFactoryMethodLinear: function ( result ) {
  20129. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20130. },
  20131. InterpolantFactoryMethodSmooth: function ( result ) {
  20132. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  20133. },
  20134. setInterpolation: function ( interpolation ) {
  20135. var factoryMethod;
  20136. switch ( interpolation ) {
  20137. case InterpolateDiscrete:
  20138. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20139. break;
  20140. case InterpolateLinear:
  20141. factoryMethod = this.InterpolantFactoryMethodLinear;
  20142. break;
  20143. case InterpolateSmooth:
  20144. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20145. break;
  20146. }
  20147. if ( factoryMethod === undefined ) {
  20148. var message = "unsupported interpolation for " +
  20149. this.ValueTypeName + " keyframe track named " + this.name;
  20150. if ( this.createInterpolant === undefined ) {
  20151. // fall back to default, unless the default itself is messed up
  20152. if ( interpolation !== this.DefaultInterpolation ) {
  20153. this.setInterpolation( this.DefaultInterpolation );
  20154. } else {
  20155. throw new Error( message ); // fatal, in this case
  20156. }
  20157. }
  20158. console.warn( 'THREE.KeyframeTrack:', message );
  20159. return this;
  20160. }
  20161. this.createInterpolant = factoryMethod;
  20162. return this;
  20163. },
  20164. getInterpolation: function () {
  20165. switch ( this.createInterpolant ) {
  20166. case this.InterpolantFactoryMethodDiscrete:
  20167. return InterpolateDiscrete;
  20168. case this.InterpolantFactoryMethodLinear:
  20169. return InterpolateLinear;
  20170. case this.InterpolantFactoryMethodSmooth:
  20171. return InterpolateSmooth;
  20172. }
  20173. },
  20174. getValueSize: function () {
  20175. return this.values.length / this.times.length;
  20176. },
  20177. // move all keyframes either forwards or backwards in time
  20178. shift: function ( timeOffset ) {
  20179. if ( timeOffset !== 0.0 ) {
  20180. var times = this.times;
  20181. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20182. times[ i ] += timeOffset;
  20183. }
  20184. }
  20185. return this;
  20186. },
  20187. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20188. scale: function ( timeScale ) {
  20189. if ( timeScale !== 1.0 ) {
  20190. var times = this.times;
  20191. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20192. times[ i ] *= timeScale;
  20193. }
  20194. }
  20195. return this;
  20196. },
  20197. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20198. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20199. trim: function ( startTime, endTime ) {
  20200. var times = this.times,
  20201. nKeys = times.length,
  20202. from = 0,
  20203. to = nKeys - 1;
  20204. while ( from !== nKeys && times[ from ] < startTime ) {
  20205. ++ from;
  20206. }
  20207. while ( to !== - 1 && times[ to ] > endTime ) {
  20208. -- to;
  20209. }
  20210. ++ to; // inclusive -> exclusive bound
  20211. if ( from !== 0 || to !== nKeys ) {
  20212. // empty tracks are forbidden, so keep at least one keyframe
  20213. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  20214. var stride = this.getValueSize();
  20215. this.times = AnimationUtils.arraySlice( times, from, to );
  20216. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  20217. }
  20218. return this;
  20219. },
  20220. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20221. validate: function () {
  20222. var valid = true;
  20223. var valueSize = this.getValueSize();
  20224. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  20225. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  20226. valid = false;
  20227. }
  20228. var times = this.times,
  20229. values = this.values,
  20230. nKeys = times.length;
  20231. if ( nKeys === 0 ) {
  20232. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20233. valid = false;
  20234. }
  20235. var prevTime = null;
  20236. for ( var i = 0; i !== nKeys; i ++ ) {
  20237. var currTime = times[ i ];
  20238. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20239. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20240. valid = false;
  20241. break;
  20242. }
  20243. if ( prevTime !== null && prevTime > currTime ) {
  20244. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20245. valid = false;
  20246. break;
  20247. }
  20248. prevTime = currTime;
  20249. }
  20250. if ( values !== undefined ) {
  20251. if ( AnimationUtils.isTypedArray( values ) ) {
  20252. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20253. var value = values[ i ];
  20254. if ( isNaN( value ) ) {
  20255. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20256. valid = false;
  20257. break;
  20258. }
  20259. }
  20260. }
  20261. }
  20262. return valid;
  20263. },
  20264. // removes equivalent sequential keys as common in morph target sequences
  20265. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20266. optimize: function () {
  20267. var times = this.times,
  20268. values = this.values,
  20269. stride = this.getValueSize(),
  20270. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20271. writeIndex = 1,
  20272. lastIndex = times.length - 1;
  20273. for ( var i = 1; i < lastIndex; ++ i ) {
  20274. var keep = false;
  20275. var time = times[ i ];
  20276. var timeNext = times[ i + 1 ];
  20277. // remove adjacent keyframes scheduled at the same time
  20278. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20279. if ( ! smoothInterpolation ) {
  20280. // remove unnecessary keyframes same as their neighbors
  20281. var offset = i * stride,
  20282. offsetP = offset - stride,
  20283. offsetN = offset + stride;
  20284. for ( var j = 0; j !== stride; ++ j ) {
  20285. var value = values[ offset + j ];
  20286. if ( value !== values[ offsetP + j ] ||
  20287. value !== values[ offsetN + j ] ) {
  20288. keep = true;
  20289. break;
  20290. }
  20291. }
  20292. } else {
  20293. keep = true;
  20294. }
  20295. }
  20296. // in-place compaction
  20297. if ( keep ) {
  20298. if ( i !== writeIndex ) {
  20299. times[ writeIndex ] = times[ i ];
  20300. var readOffset = i * stride,
  20301. writeOffset = writeIndex * stride;
  20302. for ( var j = 0; j !== stride; ++ j ) {
  20303. values[ writeOffset + j ] = values[ readOffset + j ];
  20304. }
  20305. }
  20306. ++ writeIndex;
  20307. }
  20308. }
  20309. // flush last keyframe (compaction looks ahead)
  20310. if ( lastIndex > 0 ) {
  20311. times[ writeIndex ] = times[ lastIndex ];
  20312. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20313. values[ writeOffset + j ] = values[ readOffset + j ];
  20314. }
  20315. ++ writeIndex;
  20316. }
  20317. if ( writeIndex !== times.length ) {
  20318. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20319. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20320. }
  20321. return this;
  20322. },
  20323. clone: function () {
  20324. var times = AnimationUtils.arraySlice( this.times, 0 );
  20325. var values = AnimationUtils.arraySlice( this.values, 0 );
  20326. var TypedKeyframeTrack = this.constructor;
  20327. var track = new TypedKeyframeTrack( this.name, times, values );
  20328. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20329. track.createInterpolant = this.createInterpolant;
  20330. return track;
  20331. }
  20332. } );
  20333. /**
  20334. *
  20335. * A Track of Boolean keyframe values.
  20336. *
  20337. *
  20338. * @author Ben Houston / http://clara.io/
  20339. * @author David Sarno / http://lighthaus.us/
  20340. * @author tschw
  20341. */
  20342. function BooleanKeyframeTrack( name, times, values ) {
  20343. KeyframeTrack.call( this, name, times, values );
  20344. }
  20345. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20346. constructor: BooleanKeyframeTrack,
  20347. ValueTypeName: 'bool',
  20348. ValueBufferType: Array,
  20349. DefaultInterpolation: InterpolateDiscrete,
  20350. InterpolantFactoryMethodLinear: undefined,
  20351. InterpolantFactoryMethodSmooth: undefined
  20352. // Note: Actually this track could have a optimized / compressed
  20353. // representation of a single value and a custom interpolant that
  20354. // computes "firstValue ^ isOdd( index )".
  20355. } );
  20356. /**
  20357. *
  20358. * A Track of keyframe values that represent color.
  20359. *
  20360. *
  20361. * @author Ben Houston / http://clara.io/
  20362. * @author David Sarno / http://lighthaus.us/
  20363. * @author tschw
  20364. */
  20365. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20366. KeyframeTrack.call( this, name, times, values, interpolation );
  20367. }
  20368. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20369. constructor: ColorKeyframeTrack,
  20370. ValueTypeName: 'color'
  20371. // ValueBufferType is inherited
  20372. // DefaultInterpolation is inherited
  20373. // Note: Very basic implementation and nothing special yet.
  20374. // However, this is the place for color space parameterization.
  20375. } );
  20376. /**
  20377. *
  20378. * A Track of numeric keyframe values.
  20379. *
  20380. * @author Ben Houston / http://clara.io/
  20381. * @author David Sarno / http://lighthaus.us/
  20382. * @author tschw
  20383. */
  20384. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20385. KeyframeTrack.call( this, name, times, values, interpolation );
  20386. }
  20387. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20388. constructor: NumberKeyframeTrack,
  20389. ValueTypeName: 'number'
  20390. // ValueBufferType is inherited
  20391. // DefaultInterpolation is inherited
  20392. } );
  20393. /**
  20394. * Spherical linear unit quaternion interpolant.
  20395. *
  20396. * @author tschw
  20397. */
  20398. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20399. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20400. }
  20401. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20402. constructor: QuaternionLinearInterpolant,
  20403. interpolate_: function ( i1, t0, t, t1 ) {
  20404. var result = this.resultBuffer,
  20405. values = this.sampleValues,
  20406. stride = this.valueSize,
  20407. offset = i1 * stride,
  20408. alpha = ( t - t0 ) / ( t1 - t0 );
  20409. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20410. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20411. }
  20412. return result;
  20413. }
  20414. } );
  20415. /**
  20416. *
  20417. * A Track of quaternion keyframe values.
  20418. *
  20419. * @author Ben Houston / http://clara.io/
  20420. * @author David Sarno / http://lighthaus.us/
  20421. * @author tschw
  20422. */
  20423. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20424. KeyframeTrack.call( this, name, times, values, interpolation );
  20425. }
  20426. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20427. constructor: QuaternionKeyframeTrack,
  20428. ValueTypeName: 'quaternion',
  20429. // ValueBufferType is inherited
  20430. DefaultInterpolation: InterpolateLinear,
  20431. InterpolantFactoryMethodLinear: function ( result ) {
  20432. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20433. },
  20434. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20435. } );
  20436. /**
  20437. *
  20438. * A Track that interpolates Strings
  20439. *
  20440. *
  20441. * @author Ben Houston / http://clara.io/
  20442. * @author David Sarno / http://lighthaus.us/
  20443. * @author tschw
  20444. */
  20445. function StringKeyframeTrack( name, times, values, interpolation ) {
  20446. KeyframeTrack.call( this, name, times, values, interpolation );
  20447. }
  20448. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20449. constructor: StringKeyframeTrack,
  20450. ValueTypeName: 'string',
  20451. ValueBufferType: Array,
  20452. DefaultInterpolation: InterpolateDiscrete,
  20453. InterpolantFactoryMethodLinear: undefined,
  20454. InterpolantFactoryMethodSmooth: undefined
  20455. } );
  20456. /**
  20457. *
  20458. * A Track of vectored keyframe values.
  20459. *
  20460. *
  20461. * @author Ben Houston / http://clara.io/
  20462. * @author David Sarno / http://lighthaus.us/
  20463. * @author tschw
  20464. */
  20465. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20466. KeyframeTrack.call( this, name, times, values, interpolation );
  20467. }
  20468. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20469. constructor: VectorKeyframeTrack,
  20470. ValueTypeName: 'vector'
  20471. // ValueBufferType is inherited
  20472. // DefaultInterpolation is inherited
  20473. } );
  20474. /**
  20475. *
  20476. * Reusable set of Tracks that represent an animation.
  20477. *
  20478. * @author Ben Houston / http://clara.io/
  20479. * @author David Sarno / http://lighthaus.us/
  20480. */
  20481. function AnimationClip( name, duration, tracks ) {
  20482. this.name = name;
  20483. this.tracks = tracks;
  20484. this.duration = ( duration !== undefined ) ? duration : - 1;
  20485. this.uuid = _Math.generateUUID();
  20486. // this means it should figure out its duration by scanning the tracks
  20487. if ( this.duration < 0 ) {
  20488. this.resetDuration();
  20489. }
  20490. }
  20491. function getTrackTypeForValueTypeName( typeName ) {
  20492. switch ( typeName.toLowerCase() ) {
  20493. case 'scalar':
  20494. case 'double':
  20495. case 'float':
  20496. case 'number':
  20497. case 'integer':
  20498. return NumberKeyframeTrack;
  20499. case 'vector':
  20500. case 'vector2':
  20501. case 'vector3':
  20502. case 'vector4':
  20503. return VectorKeyframeTrack;
  20504. case 'color':
  20505. return ColorKeyframeTrack;
  20506. case 'quaternion':
  20507. return QuaternionKeyframeTrack;
  20508. case 'bool':
  20509. case 'boolean':
  20510. return BooleanKeyframeTrack;
  20511. case 'string':
  20512. return StringKeyframeTrack;
  20513. }
  20514. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20515. }
  20516. function parseKeyframeTrack( json ) {
  20517. if ( json.type === undefined ) {
  20518. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20519. }
  20520. var trackType = getTrackTypeForValueTypeName( json.type );
  20521. if ( json.times === undefined ) {
  20522. var times = [], values = [];
  20523. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20524. json.times = times;
  20525. json.values = values;
  20526. }
  20527. // derived classes can define a static parse method
  20528. if ( trackType.parse !== undefined ) {
  20529. return trackType.parse( json );
  20530. } else {
  20531. // by default, we assume a constructor compatible with the base
  20532. return new trackType( json.name, json.times, json.values, json.interpolation );
  20533. }
  20534. }
  20535. Object.assign( AnimationClip, {
  20536. parse: function ( json ) {
  20537. var tracks = [],
  20538. jsonTracks = json.tracks,
  20539. frameTime = 1.0 / ( json.fps || 1.0 );
  20540. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20541. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20542. }
  20543. return new AnimationClip( json.name, json.duration, tracks );
  20544. },
  20545. toJSON: function ( clip ) {
  20546. var tracks = [],
  20547. clipTracks = clip.tracks;
  20548. var json = {
  20549. 'name': clip.name,
  20550. 'duration': clip.duration,
  20551. 'tracks': tracks,
  20552. 'uuid': clip.uuid
  20553. };
  20554. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20555. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20556. }
  20557. return json;
  20558. },
  20559. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20560. var numMorphTargets = morphTargetSequence.length;
  20561. var tracks = [];
  20562. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20563. var times = [];
  20564. var values = [];
  20565. times.push(
  20566. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20567. i,
  20568. ( i + 1 ) % numMorphTargets );
  20569. values.push( 0, 1, 0 );
  20570. var order = AnimationUtils.getKeyframeOrder( times );
  20571. times = AnimationUtils.sortedArray( times, 1, order );
  20572. values = AnimationUtils.sortedArray( values, 1, order );
  20573. // if there is a key at the first frame, duplicate it as the
  20574. // last frame as well for perfect loop.
  20575. if ( ! noLoop && times[ 0 ] === 0 ) {
  20576. times.push( numMorphTargets );
  20577. values.push( values[ 0 ] );
  20578. }
  20579. tracks.push(
  20580. new NumberKeyframeTrack(
  20581. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20582. times, values
  20583. ).scale( 1.0 / fps ) );
  20584. }
  20585. return new AnimationClip( name, - 1, tracks );
  20586. },
  20587. findByName: function ( objectOrClipArray, name ) {
  20588. var clipArray = objectOrClipArray;
  20589. if ( ! Array.isArray( objectOrClipArray ) ) {
  20590. var o = objectOrClipArray;
  20591. clipArray = o.geometry && o.geometry.animations || o.animations;
  20592. }
  20593. for ( var i = 0; i < clipArray.length; i ++ ) {
  20594. if ( clipArray[ i ].name === name ) {
  20595. return clipArray[ i ];
  20596. }
  20597. }
  20598. return null;
  20599. },
  20600. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20601. var animationToMorphTargets = {};
  20602. // tested with https://regex101.com/ on trick sequences
  20603. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20604. var pattern = /^([\w-]*?)([\d]+)$/;
  20605. // sort morph target names into animation groups based
  20606. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20607. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20608. var morphTarget = morphTargets[ i ];
  20609. var parts = morphTarget.name.match( pattern );
  20610. if ( parts && parts.length > 1 ) {
  20611. var name = parts[ 1 ];
  20612. var animationMorphTargets = animationToMorphTargets[ name ];
  20613. if ( ! animationMorphTargets ) {
  20614. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20615. }
  20616. animationMorphTargets.push( morphTarget );
  20617. }
  20618. }
  20619. var clips = [];
  20620. for ( var name in animationToMorphTargets ) {
  20621. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20622. }
  20623. return clips;
  20624. },
  20625. // parse the animation.hierarchy format
  20626. parseAnimation: function ( animation, bones ) {
  20627. if ( ! animation ) {
  20628. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20629. return null;
  20630. }
  20631. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20632. // only return track if there are actually keys.
  20633. if ( animationKeys.length !== 0 ) {
  20634. var times = [];
  20635. var values = [];
  20636. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20637. // empty keys are filtered out, so check again
  20638. if ( times.length !== 0 ) {
  20639. destTracks.push( new trackType( trackName, times, values ) );
  20640. }
  20641. }
  20642. };
  20643. var tracks = [];
  20644. var clipName = animation.name || 'default';
  20645. // automatic length determination in AnimationClip.
  20646. var duration = animation.length || - 1;
  20647. var fps = animation.fps || 30;
  20648. var hierarchyTracks = animation.hierarchy || [];
  20649. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20650. var animationKeys = hierarchyTracks[ h ].keys;
  20651. // skip empty tracks
  20652. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20653. // process morph targets
  20654. if ( animationKeys[ 0 ].morphTargets ) {
  20655. // figure out all morph targets used in this track
  20656. var morphTargetNames = {};
  20657. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20658. if ( animationKeys[ k ].morphTargets ) {
  20659. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20660. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20661. }
  20662. }
  20663. }
  20664. // create a track for each morph target with all zero
  20665. // morphTargetInfluences except for the keys in which
  20666. // the morphTarget is named.
  20667. for ( var morphTargetName in morphTargetNames ) {
  20668. var times = [];
  20669. var values = [];
  20670. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20671. var animationKey = animationKeys[ k ];
  20672. times.push( animationKey.time );
  20673. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20674. }
  20675. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20676. }
  20677. duration = morphTargetNames.length * ( fps || 1.0 );
  20678. } else {
  20679. // ...assume skeletal animation
  20680. var boneName = '.bones[' + bones[ h ].name + ']';
  20681. addNonemptyTrack(
  20682. VectorKeyframeTrack, boneName + '.position',
  20683. animationKeys, 'pos', tracks );
  20684. addNonemptyTrack(
  20685. QuaternionKeyframeTrack, boneName + '.quaternion',
  20686. animationKeys, 'rot', tracks );
  20687. addNonemptyTrack(
  20688. VectorKeyframeTrack, boneName + '.scale',
  20689. animationKeys, 'scl', tracks );
  20690. }
  20691. }
  20692. if ( tracks.length === 0 ) {
  20693. return null;
  20694. }
  20695. var clip = new AnimationClip( clipName, duration, tracks );
  20696. return clip;
  20697. }
  20698. } );
  20699. Object.assign( AnimationClip.prototype, {
  20700. resetDuration: function () {
  20701. var tracks = this.tracks, duration = 0;
  20702. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20703. var track = this.tracks[ i ];
  20704. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20705. }
  20706. this.duration = duration;
  20707. return this;
  20708. },
  20709. trim: function () {
  20710. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20711. this.tracks[ i ].trim( 0, this.duration );
  20712. }
  20713. return this;
  20714. },
  20715. validate: function () {
  20716. var valid = true;
  20717. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20718. valid = valid && this.tracks[ i ].validate();
  20719. }
  20720. return valid;
  20721. },
  20722. optimize: function () {
  20723. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20724. this.tracks[ i ].optimize();
  20725. }
  20726. return this;
  20727. },
  20728. clone: function () {
  20729. var tracks = [];
  20730. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20731. tracks.push( this.tracks[ i ].clone() );
  20732. }
  20733. return new AnimationClip( this.name, this.duration, tracks );
  20734. }
  20735. } );
  20736. /**
  20737. * @author mrdoob / http://mrdoob.com/
  20738. */
  20739. var Cache = {
  20740. enabled: false,
  20741. files: {},
  20742. add: function ( key, file ) {
  20743. if ( this.enabled === false ) return;
  20744. // console.log( 'THREE.Cache', 'Adding key:', key );
  20745. this.files[ key ] = file;
  20746. },
  20747. get: function ( key ) {
  20748. if ( this.enabled === false ) return;
  20749. // console.log( 'THREE.Cache', 'Checking key:', key );
  20750. return this.files[ key ];
  20751. },
  20752. remove: function ( key ) {
  20753. delete this.files[ key ];
  20754. },
  20755. clear: function () {
  20756. this.files = {};
  20757. }
  20758. };
  20759. /**
  20760. * @author mrdoob / http://mrdoob.com/
  20761. */
  20762. function LoadingManager( onLoad, onProgress, onError ) {
  20763. var scope = this;
  20764. var isLoading = false;
  20765. var itemsLoaded = 0;
  20766. var itemsTotal = 0;
  20767. var urlModifier = undefined;
  20768. // Refer to #5689 for the reason why we don't set .onStart
  20769. // in the constructor
  20770. this.onStart = undefined;
  20771. this.onLoad = onLoad;
  20772. this.onProgress = onProgress;
  20773. this.onError = onError;
  20774. this.itemStart = function ( url ) {
  20775. itemsTotal ++;
  20776. if ( isLoading === false ) {
  20777. if ( scope.onStart !== undefined ) {
  20778. scope.onStart( url, itemsLoaded, itemsTotal );
  20779. }
  20780. }
  20781. isLoading = true;
  20782. };
  20783. this.itemEnd = function ( url ) {
  20784. itemsLoaded ++;
  20785. if ( scope.onProgress !== undefined ) {
  20786. scope.onProgress( url, itemsLoaded, itemsTotal );
  20787. }
  20788. if ( itemsLoaded === itemsTotal ) {
  20789. isLoading = false;
  20790. if ( scope.onLoad !== undefined ) {
  20791. scope.onLoad();
  20792. }
  20793. }
  20794. };
  20795. this.itemError = function ( url ) {
  20796. if ( scope.onError !== undefined ) {
  20797. scope.onError( url );
  20798. }
  20799. };
  20800. this.resolveURL = function ( url ) {
  20801. if ( urlModifier ) {
  20802. return urlModifier( url );
  20803. }
  20804. return url;
  20805. };
  20806. this.setURLModifier = function ( transform ) {
  20807. urlModifier = transform;
  20808. return this;
  20809. };
  20810. }
  20811. var DefaultLoadingManager = new LoadingManager();
  20812. /**
  20813. * @author mrdoob / http://mrdoob.com/
  20814. */
  20815. var loading = {};
  20816. function FileLoader( manager ) {
  20817. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20818. }
  20819. Object.assign( FileLoader.prototype, {
  20820. load: function ( url, onLoad, onProgress, onError ) {
  20821. if ( url === undefined ) url = '';
  20822. if ( this.path !== undefined ) url = this.path + url;
  20823. url = this.manager.resolveURL( url );
  20824. var scope = this;
  20825. var cached = Cache.get( url );
  20826. if ( cached !== undefined ) {
  20827. scope.manager.itemStart( url );
  20828. setTimeout( function () {
  20829. if ( onLoad ) onLoad( cached );
  20830. scope.manager.itemEnd( url );
  20831. }, 0 );
  20832. return cached;
  20833. }
  20834. // Check if request is duplicate
  20835. if ( loading[ url ] !== undefined ) {
  20836. loading[ url ].push( {
  20837. onLoad: onLoad,
  20838. onProgress: onProgress,
  20839. onError: onError
  20840. } );
  20841. return;
  20842. }
  20843. // Check for data: URI
  20844. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20845. var dataUriRegexResult = url.match( dataUriRegex );
  20846. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20847. if ( dataUriRegexResult ) {
  20848. var mimeType = dataUriRegexResult[ 1 ];
  20849. var isBase64 = !! dataUriRegexResult[ 2 ];
  20850. var data = dataUriRegexResult[ 3 ];
  20851. data = decodeURIComponent( data );
  20852. if ( isBase64 ) data = atob( data );
  20853. try {
  20854. var response;
  20855. var responseType = ( this.responseType || '' ).toLowerCase();
  20856. switch ( responseType ) {
  20857. case 'arraybuffer':
  20858. case 'blob':
  20859. var view = new Uint8Array( data.length );
  20860. for ( var i = 0; i < data.length; i ++ ) {
  20861. view[ i ] = data.charCodeAt( i );
  20862. }
  20863. if ( responseType === 'blob' ) {
  20864. response = new Blob( [ view.buffer ], { type: mimeType } );
  20865. } else {
  20866. response = view.buffer;
  20867. }
  20868. break;
  20869. case 'document':
  20870. var parser = new DOMParser();
  20871. response = parser.parseFromString( data, mimeType );
  20872. break;
  20873. case 'json':
  20874. response = JSON.parse( data );
  20875. break;
  20876. default: // 'text' or other
  20877. response = data;
  20878. break;
  20879. }
  20880. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20881. setTimeout( function () {
  20882. if ( onLoad ) onLoad( response );
  20883. scope.manager.itemEnd( url );
  20884. }, 0 );
  20885. } catch ( error ) {
  20886. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20887. setTimeout( function () {
  20888. if ( onError ) onError( error );
  20889. scope.manager.itemError( url );
  20890. scope.manager.itemEnd( url );
  20891. }, 0 );
  20892. }
  20893. } else {
  20894. // Initialise array for duplicate requests
  20895. loading[ url ] = [];
  20896. loading[ url ].push( {
  20897. onLoad: onLoad,
  20898. onProgress: onProgress,
  20899. onError: onError
  20900. } );
  20901. var request = new XMLHttpRequest();
  20902. request.open( 'GET', url, true );
  20903. request.addEventListener( 'load', function ( event ) {
  20904. var response = this.response;
  20905. Cache.add( url, response );
  20906. var callbacks = loading[ url ];
  20907. delete loading[ url ];
  20908. if ( this.status === 200 || this.status === 0 ) {
  20909. // Some browsers return HTTP Status 0 when using non-http protocol
  20910. // e.g. 'file://' or 'data://'. Handle as success.
  20911. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20912. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20913. var callback = callbacks[ i ];
  20914. if ( callback.onLoad ) callback.onLoad( response );
  20915. }
  20916. scope.manager.itemEnd( url );
  20917. } else {
  20918. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20919. var callback = callbacks[ i ];
  20920. if ( callback.onError ) callback.onError( event );
  20921. }
  20922. scope.manager.itemError( url );
  20923. scope.manager.itemEnd( url );
  20924. }
  20925. }, false );
  20926. request.addEventListener( 'progress', function ( event ) {
  20927. var callbacks = loading[ url ];
  20928. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20929. var callback = callbacks[ i ];
  20930. if ( callback.onProgress ) callback.onProgress( event );
  20931. }
  20932. }, false );
  20933. request.addEventListener( 'error', function ( event ) {
  20934. var callbacks = loading[ url ];
  20935. delete loading[ url ];
  20936. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20937. var callback = callbacks[ i ];
  20938. if ( callback.onError ) callback.onError( event );
  20939. }
  20940. scope.manager.itemError( url );
  20941. scope.manager.itemEnd( url );
  20942. }, false );
  20943. request.addEventListener( 'abort', function ( event ) {
  20944. var callbacks = loading[ url ];
  20945. delete loading[ url ];
  20946. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20947. var callback = callbacks[ i ];
  20948. if ( callback.onError ) callback.onError( event );
  20949. }
  20950. scope.manager.itemError( url );
  20951. scope.manager.itemEnd( url );
  20952. }, false );
  20953. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20954. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20955. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20956. for ( var header in this.requestHeader ) {
  20957. request.setRequestHeader( header, this.requestHeader[ header ] );
  20958. }
  20959. request.send( null );
  20960. }
  20961. scope.manager.itemStart( url );
  20962. return request;
  20963. },
  20964. setPath: function ( value ) {
  20965. this.path = value;
  20966. return this;
  20967. },
  20968. setResponseType: function ( value ) {
  20969. this.responseType = value;
  20970. return this;
  20971. },
  20972. setWithCredentials: function ( value ) {
  20973. this.withCredentials = value;
  20974. return this;
  20975. },
  20976. setMimeType: function ( value ) {
  20977. this.mimeType = value;
  20978. return this;
  20979. },
  20980. setRequestHeader: function ( value ) {
  20981. this.requestHeader = value;
  20982. return this;
  20983. }
  20984. } );
  20985. /**
  20986. * @author bhouston / http://clara.io/
  20987. */
  20988. function AnimationLoader( manager ) {
  20989. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20990. }
  20991. Object.assign( AnimationLoader.prototype, {
  20992. load: function ( url, onLoad, onProgress, onError ) {
  20993. var scope = this;
  20994. var loader = new FileLoader( scope.manager );
  20995. loader.setPath( scope.path );
  20996. loader.load( url, function ( text ) {
  20997. onLoad( scope.parse( JSON.parse( text ) ) );
  20998. }, onProgress, onError );
  20999. },
  21000. parse: function ( json ) {
  21001. var animations = [];
  21002. for ( var i = 0; i < json.length; i ++ ) {
  21003. var clip = AnimationClip.parse( json[ i ] );
  21004. animations.push( clip );
  21005. }
  21006. return animations;
  21007. },
  21008. setPath: function ( value ) {
  21009. this.path = value;
  21010. return this;
  21011. }
  21012. } );
  21013. /**
  21014. * @author mrdoob / http://mrdoob.com/
  21015. *
  21016. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21017. */
  21018. function CompressedTextureLoader( manager ) {
  21019. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21020. // override in sub classes
  21021. this._parser = null;
  21022. }
  21023. Object.assign( CompressedTextureLoader.prototype, {
  21024. load: function ( url, onLoad, onProgress, onError ) {
  21025. var scope = this;
  21026. var images = [];
  21027. var texture = new CompressedTexture();
  21028. texture.image = images;
  21029. var loader = new FileLoader( this.manager );
  21030. loader.setPath( this.path );
  21031. loader.setResponseType( 'arraybuffer' );
  21032. function loadTexture( i ) {
  21033. loader.load( url[ i ], function ( buffer ) {
  21034. var texDatas = scope._parser( buffer, true );
  21035. images[ i ] = {
  21036. width: texDatas.width,
  21037. height: texDatas.height,
  21038. format: texDatas.format,
  21039. mipmaps: texDatas.mipmaps
  21040. };
  21041. loaded += 1;
  21042. if ( loaded === 6 ) {
  21043. if ( texDatas.mipmapCount === 1 )
  21044. texture.minFilter = LinearFilter;
  21045. texture.format = texDatas.format;
  21046. texture.needsUpdate = true;
  21047. if ( onLoad ) onLoad( texture );
  21048. }
  21049. }, onProgress, onError );
  21050. }
  21051. if ( Array.isArray( url ) ) {
  21052. var loaded = 0;
  21053. for ( var i = 0, il = url.length; i < il; ++ i ) {
  21054. loadTexture( i );
  21055. }
  21056. } else {
  21057. // compressed cubemap texture stored in a single DDS file
  21058. loader.load( url, function ( buffer ) {
  21059. var texDatas = scope._parser( buffer, true );
  21060. if ( texDatas.isCubemap ) {
  21061. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21062. for ( var f = 0; f < faces; f ++ ) {
  21063. images[ f ] = { mipmaps: [] };
  21064. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  21065. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  21066. images[ f ].format = texDatas.format;
  21067. images[ f ].width = texDatas.width;
  21068. images[ f ].height = texDatas.height;
  21069. }
  21070. }
  21071. } else {
  21072. texture.image.width = texDatas.width;
  21073. texture.image.height = texDatas.height;
  21074. texture.mipmaps = texDatas.mipmaps;
  21075. }
  21076. if ( texDatas.mipmapCount === 1 ) {
  21077. texture.minFilter = LinearFilter;
  21078. }
  21079. texture.format = texDatas.format;
  21080. texture.needsUpdate = true;
  21081. if ( onLoad ) onLoad( texture );
  21082. }, onProgress, onError );
  21083. }
  21084. return texture;
  21085. },
  21086. setPath: function ( value ) {
  21087. this.path = value;
  21088. return this;
  21089. }
  21090. } );
  21091. /**
  21092. * @author Nikos M. / https://github.com/foo123/
  21093. *
  21094. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21095. */
  21096. function DataTextureLoader( manager ) {
  21097. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21098. // override in sub classes
  21099. this._parser = null;
  21100. }
  21101. Object.assign( DataTextureLoader.prototype, {
  21102. load: function ( url, onLoad, onProgress, onError ) {
  21103. var scope = this;
  21104. var texture = new DataTexture();
  21105. var loader = new FileLoader( this.manager );
  21106. loader.setResponseType( 'arraybuffer' );
  21107. loader.setPath( this.path );
  21108. loader.load( url, function ( buffer ) {
  21109. var texData = scope._parser( buffer );
  21110. if ( ! texData ) return;
  21111. if ( texData.image !== undefined ) {
  21112. texture.image = texData.image;
  21113. } else if ( texData.data !== undefined ) {
  21114. texture.image.width = texData.width;
  21115. texture.image.height = texData.height;
  21116. texture.image.data = texData.data;
  21117. }
  21118. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21119. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21120. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21121. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipmapLinearFilter;
  21122. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21123. if ( texData.format !== undefined ) {
  21124. texture.format = texData.format;
  21125. }
  21126. if ( texData.type !== undefined ) {
  21127. texture.type = texData.type;
  21128. }
  21129. if ( texData.mipmaps !== undefined ) {
  21130. texture.mipmaps = texData.mipmaps;
  21131. }
  21132. if ( texData.mipmapCount === 1 ) {
  21133. texture.minFilter = LinearFilter;
  21134. }
  21135. texture.needsUpdate = true;
  21136. if ( onLoad ) onLoad( texture, texData );
  21137. }, onProgress, onError );
  21138. return texture;
  21139. },
  21140. setPath: function ( value ) {
  21141. this.path = value;
  21142. return this;
  21143. }
  21144. } );
  21145. /**
  21146. * @author mrdoob / http://mrdoob.com/
  21147. */
  21148. function ImageLoader( manager ) {
  21149. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21150. }
  21151. Object.assign( ImageLoader.prototype, {
  21152. crossOrigin: 'anonymous',
  21153. load: function ( url, onLoad, onProgress, onError ) {
  21154. if ( url === undefined ) url = '';
  21155. if ( this.path !== undefined ) url = this.path + url;
  21156. url = this.manager.resolveURL( url );
  21157. var scope = this;
  21158. var cached = Cache.get( url );
  21159. if ( cached !== undefined ) {
  21160. scope.manager.itemStart( url );
  21161. setTimeout( function () {
  21162. if ( onLoad ) onLoad( cached );
  21163. scope.manager.itemEnd( url );
  21164. }, 0 );
  21165. return cached;
  21166. }
  21167. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  21168. function onImageLoad() {
  21169. image.removeEventListener( 'load', onImageLoad, false );
  21170. image.removeEventListener( 'error', onImageError, false );
  21171. Cache.add( url, this );
  21172. if ( onLoad ) onLoad( this );
  21173. scope.manager.itemEnd( url );
  21174. }
  21175. function onImageError( event ) {
  21176. image.removeEventListener( 'load', onImageLoad, false );
  21177. image.removeEventListener( 'error', onImageError, false );
  21178. if ( onError ) onError( event );
  21179. scope.manager.itemError( url );
  21180. scope.manager.itemEnd( url );
  21181. }
  21182. image.addEventListener( 'load', onImageLoad, false );
  21183. image.addEventListener( 'error', onImageError, false );
  21184. if ( url.substr( 0, 5 ) !== 'data:' ) {
  21185. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  21186. }
  21187. scope.manager.itemStart( url );
  21188. image.src = url;
  21189. return image;
  21190. },
  21191. setCrossOrigin: function ( value ) {
  21192. this.crossOrigin = value;
  21193. return this;
  21194. },
  21195. setPath: function ( value ) {
  21196. this.path = value;
  21197. return this;
  21198. }
  21199. } );
  21200. /**
  21201. * @author mrdoob / http://mrdoob.com/
  21202. */
  21203. function CubeTextureLoader( manager ) {
  21204. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21205. }
  21206. Object.assign( CubeTextureLoader.prototype, {
  21207. crossOrigin: 'anonymous',
  21208. load: function ( urls, onLoad, onProgress, onError ) {
  21209. var texture = new CubeTexture();
  21210. var loader = new ImageLoader( this.manager );
  21211. loader.setCrossOrigin( this.crossOrigin );
  21212. loader.setPath( this.path );
  21213. var loaded = 0;
  21214. function loadTexture( i ) {
  21215. loader.load( urls[ i ], function ( image ) {
  21216. texture.images[ i ] = image;
  21217. loaded ++;
  21218. if ( loaded === 6 ) {
  21219. texture.needsUpdate = true;
  21220. if ( onLoad ) onLoad( texture );
  21221. }
  21222. }, undefined, onError );
  21223. }
  21224. for ( var i = 0; i < urls.length; ++ i ) {
  21225. loadTexture( i );
  21226. }
  21227. return texture;
  21228. },
  21229. setCrossOrigin: function ( value ) {
  21230. this.crossOrigin = value;
  21231. return this;
  21232. },
  21233. setPath: function ( value ) {
  21234. this.path = value;
  21235. return this;
  21236. }
  21237. } );
  21238. /**
  21239. * @author mrdoob / http://mrdoob.com/
  21240. */
  21241. function TextureLoader( manager ) {
  21242. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21243. }
  21244. Object.assign( TextureLoader.prototype, {
  21245. crossOrigin: 'anonymous',
  21246. load: function ( url, onLoad, onProgress, onError ) {
  21247. var texture = new Texture();
  21248. var loader = new ImageLoader( this.manager );
  21249. loader.setCrossOrigin( this.crossOrigin );
  21250. loader.setPath( this.path );
  21251. loader.load( url, function ( image ) {
  21252. texture.image = image;
  21253. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21254. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  21255. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21256. texture.needsUpdate = true;
  21257. if ( onLoad !== undefined ) {
  21258. onLoad( texture );
  21259. }
  21260. }, onProgress, onError );
  21261. return texture;
  21262. },
  21263. setCrossOrigin: function ( value ) {
  21264. this.crossOrigin = value;
  21265. return this;
  21266. },
  21267. setPath: function ( value ) {
  21268. this.path = value;
  21269. return this;
  21270. }
  21271. } );
  21272. /**
  21273. * @author zz85 / http://www.lab4games.net/zz85/blog
  21274. * Extensible curve object
  21275. *
  21276. * Some common of curve methods:
  21277. * .getPoint( t, optionalTarget ), .getTangent( t )
  21278. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  21279. * .getPoints(), .getSpacedPoints()
  21280. * .getLength()
  21281. * .updateArcLengths()
  21282. *
  21283. * This following curves inherit from THREE.Curve:
  21284. *
  21285. * -- 2D curves --
  21286. * THREE.ArcCurve
  21287. * THREE.CubicBezierCurve
  21288. * THREE.EllipseCurve
  21289. * THREE.LineCurve
  21290. * THREE.QuadraticBezierCurve
  21291. * THREE.SplineCurve
  21292. *
  21293. * -- 3D curves --
  21294. * THREE.CatmullRomCurve3
  21295. * THREE.CubicBezierCurve3
  21296. * THREE.LineCurve3
  21297. * THREE.QuadraticBezierCurve3
  21298. *
  21299. * A series of curves can be represented as a THREE.CurvePath.
  21300. *
  21301. **/
  21302. /**************************************************************
  21303. * Abstract Curve base class
  21304. **************************************************************/
  21305. function Curve() {
  21306. this.type = 'Curve';
  21307. this.arcLengthDivisions = 200;
  21308. }
  21309. Object.assign( Curve.prototype, {
  21310. // Virtual base class method to overwrite and implement in subclasses
  21311. // - t [0 .. 1]
  21312. getPoint: function ( /* t, optionalTarget */ ) {
  21313. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21314. return null;
  21315. },
  21316. // Get point at relative position in curve according to arc length
  21317. // - u [0 .. 1]
  21318. getPointAt: function ( u, optionalTarget ) {
  21319. var t = this.getUtoTmapping( u );
  21320. return this.getPoint( t, optionalTarget );
  21321. },
  21322. // Get sequence of points using getPoint( t )
  21323. getPoints: function ( divisions ) {
  21324. if ( divisions === undefined ) divisions = 5;
  21325. var points = [];
  21326. for ( var d = 0; d <= divisions; d ++ ) {
  21327. points.push( this.getPoint( d / divisions ) );
  21328. }
  21329. return points;
  21330. },
  21331. // Get sequence of points using getPointAt( u )
  21332. getSpacedPoints: function ( divisions ) {
  21333. if ( divisions === undefined ) divisions = 5;
  21334. var points = [];
  21335. for ( var d = 0; d <= divisions; d ++ ) {
  21336. points.push( this.getPointAt( d / divisions ) );
  21337. }
  21338. return points;
  21339. },
  21340. // Get total curve arc length
  21341. getLength: function () {
  21342. var lengths = this.getLengths();
  21343. return lengths[ lengths.length - 1 ];
  21344. },
  21345. // Get list of cumulative segment lengths
  21346. getLengths: function ( divisions ) {
  21347. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21348. if ( this.cacheArcLengths &&
  21349. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21350. ! this.needsUpdate ) {
  21351. return this.cacheArcLengths;
  21352. }
  21353. this.needsUpdate = false;
  21354. var cache = [];
  21355. var current, last = this.getPoint( 0 );
  21356. var p, sum = 0;
  21357. cache.push( 0 );
  21358. for ( p = 1; p <= divisions; p ++ ) {
  21359. current = this.getPoint( p / divisions );
  21360. sum += current.distanceTo( last );
  21361. cache.push( sum );
  21362. last = current;
  21363. }
  21364. this.cacheArcLengths = cache;
  21365. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21366. },
  21367. updateArcLengths: function () {
  21368. this.needsUpdate = true;
  21369. this.getLengths();
  21370. },
  21371. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21372. getUtoTmapping: function ( u, distance ) {
  21373. var arcLengths = this.getLengths();
  21374. var i = 0, il = arcLengths.length;
  21375. var targetArcLength; // The targeted u distance value to get
  21376. if ( distance ) {
  21377. targetArcLength = distance;
  21378. } else {
  21379. targetArcLength = u * arcLengths[ il - 1 ];
  21380. }
  21381. // binary search for the index with largest value smaller than target u distance
  21382. var low = 0, high = il - 1, comparison;
  21383. while ( low <= high ) {
  21384. 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
  21385. comparison = arcLengths[ i ] - targetArcLength;
  21386. if ( comparison < 0 ) {
  21387. low = i + 1;
  21388. } else if ( comparison > 0 ) {
  21389. high = i - 1;
  21390. } else {
  21391. high = i;
  21392. break;
  21393. // DONE
  21394. }
  21395. }
  21396. i = high;
  21397. if ( arcLengths[ i ] === targetArcLength ) {
  21398. return i / ( il - 1 );
  21399. }
  21400. // we could get finer grain at lengths, or use simple interpolation between two points
  21401. var lengthBefore = arcLengths[ i ];
  21402. var lengthAfter = arcLengths[ i + 1 ];
  21403. var segmentLength = lengthAfter - lengthBefore;
  21404. // determine where we are between the 'before' and 'after' points
  21405. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21406. // add that fractional amount to t
  21407. var t = ( i + segmentFraction ) / ( il - 1 );
  21408. return t;
  21409. },
  21410. // Returns a unit vector tangent at t
  21411. // In case any sub curve does not implement its tangent derivation,
  21412. // 2 points a small delta apart will be used to find its gradient
  21413. // which seems to give a reasonable approximation
  21414. getTangent: function ( t ) {
  21415. var delta = 0.0001;
  21416. var t1 = t - delta;
  21417. var t2 = t + delta;
  21418. // Capping in case of danger
  21419. if ( t1 < 0 ) t1 = 0;
  21420. if ( t2 > 1 ) t2 = 1;
  21421. var pt1 = this.getPoint( t1 );
  21422. var pt2 = this.getPoint( t2 );
  21423. var vec = pt2.clone().sub( pt1 );
  21424. return vec.normalize();
  21425. },
  21426. getTangentAt: function ( u ) {
  21427. var t = this.getUtoTmapping( u );
  21428. return this.getTangent( t );
  21429. },
  21430. computeFrenetFrames: function ( segments, closed ) {
  21431. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21432. var normal = new Vector3();
  21433. var tangents = [];
  21434. var normals = [];
  21435. var binormals = [];
  21436. var vec = new Vector3();
  21437. var mat = new Matrix4();
  21438. var i, u, theta;
  21439. // compute the tangent vectors for each segment on the curve
  21440. for ( i = 0; i <= segments; i ++ ) {
  21441. u = i / segments;
  21442. tangents[ i ] = this.getTangentAt( u );
  21443. tangents[ i ].normalize();
  21444. }
  21445. // select an initial normal vector perpendicular to the first tangent vector,
  21446. // and in the direction of the minimum tangent xyz component
  21447. normals[ 0 ] = new Vector3();
  21448. binormals[ 0 ] = new Vector3();
  21449. var min = Number.MAX_VALUE;
  21450. var tx = Math.abs( tangents[ 0 ].x );
  21451. var ty = Math.abs( tangents[ 0 ].y );
  21452. var tz = Math.abs( tangents[ 0 ].z );
  21453. if ( tx <= min ) {
  21454. min = tx;
  21455. normal.set( 1, 0, 0 );
  21456. }
  21457. if ( ty <= min ) {
  21458. min = ty;
  21459. normal.set( 0, 1, 0 );
  21460. }
  21461. if ( tz <= min ) {
  21462. normal.set( 0, 0, 1 );
  21463. }
  21464. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21465. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21466. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21467. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21468. for ( i = 1; i <= segments; i ++ ) {
  21469. normals[ i ] = normals[ i - 1 ].clone();
  21470. binormals[ i ] = binormals[ i - 1 ].clone();
  21471. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21472. if ( vec.length() > Number.EPSILON ) {
  21473. vec.normalize();
  21474. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21475. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21476. }
  21477. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21478. }
  21479. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21480. if ( closed === true ) {
  21481. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21482. theta /= segments;
  21483. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21484. theta = - theta;
  21485. }
  21486. for ( i = 1; i <= segments; i ++ ) {
  21487. // twist a little...
  21488. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21489. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21490. }
  21491. }
  21492. return {
  21493. tangents: tangents,
  21494. normals: normals,
  21495. binormals: binormals
  21496. };
  21497. },
  21498. clone: function () {
  21499. return new this.constructor().copy( this );
  21500. },
  21501. copy: function ( source ) {
  21502. this.arcLengthDivisions = source.arcLengthDivisions;
  21503. return this;
  21504. },
  21505. toJSON: function () {
  21506. var data = {
  21507. metadata: {
  21508. version: 4.5,
  21509. type: 'Curve',
  21510. generator: 'Curve.toJSON'
  21511. }
  21512. };
  21513. data.arcLengthDivisions = this.arcLengthDivisions;
  21514. data.type = this.type;
  21515. return data;
  21516. },
  21517. fromJSON: function ( json ) {
  21518. this.arcLengthDivisions = json.arcLengthDivisions;
  21519. return this;
  21520. }
  21521. } );
  21522. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21523. Curve.call( this );
  21524. this.type = 'EllipseCurve';
  21525. this.aX = aX || 0;
  21526. this.aY = aY || 0;
  21527. this.xRadius = xRadius || 1;
  21528. this.yRadius = yRadius || 1;
  21529. this.aStartAngle = aStartAngle || 0;
  21530. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21531. this.aClockwise = aClockwise || false;
  21532. this.aRotation = aRotation || 0;
  21533. }
  21534. EllipseCurve.prototype = Object.create( Curve.prototype );
  21535. EllipseCurve.prototype.constructor = EllipseCurve;
  21536. EllipseCurve.prototype.isEllipseCurve = true;
  21537. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21538. var point = optionalTarget || new Vector2();
  21539. var twoPi = Math.PI * 2;
  21540. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21541. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21542. // ensures that deltaAngle is 0 .. 2 PI
  21543. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21544. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21545. if ( deltaAngle < Number.EPSILON ) {
  21546. if ( samePoints ) {
  21547. deltaAngle = 0;
  21548. } else {
  21549. deltaAngle = twoPi;
  21550. }
  21551. }
  21552. if ( this.aClockwise === true && ! samePoints ) {
  21553. if ( deltaAngle === twoPi ) {
  21554. deltaAngle = - twoPi;
  21555. } else {
  21556. deltaAngle = deltaAngle - twoPi;
  21557. }
  21558. }
  21559. var angle = this.aStartAngle + t * deltaAngle;
  21560. var x = this.aX + this.xRadius * Math.cos( angle );
  21561. var y = this.aY + this.yRadius * Math.sin( angle );
  21562. if ( this.aRotation !== 0 ) {
  21563. var cos = Math.cos( this.aRotation );
  21564. var sin = Math.sin( this.aRotation );
  21565. var tx = x - this.aX;
  21566. var ty = y - this.aY;
  21567. // Rotate the point about the center of the ellipse.
  21568. x = tx * cos - ty * sin + this.aX;
  21569. y = tx * sin + ty * cos + this.aY;
  21570. }
  21571. return point.set( x, y );
  21572. };
  21573. EllipseCurve.prototype.copy = function ( source ) {
  21574. Curve.prototype.copy.call( this, source );
  21575. this.aX = source.aX;
  21576. this.aY = source.aY;
  21577. this.xRadius = source.xRadius;
  21578. this.yRadius = source.yRadius;
  21579. this.aStartAngle = source.aStartAngle;
  21580. this.aEndAngle = source.aEndAngle;
  21581. this.aClockwise = source.aClockwise;
  21582. this.aRotation = source.aRotation;
  21583. return this;
  21584. };
  21585. EllipseCurve.prototype.toJSON = function () {
  21586. var data = Curve.prototype.toJSON.call( this );
  21587. data.aX = this.aX;
  21588. data.aY = this.aY;
  21589. data.xRadius = this.xRadius;
  21590. data.yRadius = this.yRadius;
  21591. data.aStartAngle = this.aStartAngle;
  21592. data.aEndAngle = this.aEndAngle;
  21593. data.aClockwise = this.aClockwise;
  21594. data.aRotation = this.aRotation;
  21595. return data;
  21596. };
  21597. EllipseCurve.prototype.fromJSON = function ( json ) {
  21598. Curve.prototype.fromJSON.call( this, json );
  21599. this.aX = json.aX;
  21600. this.aY = json.aY;
  21601. this.xRadius = json.xRadius;
  21602. this.yRadius = json.yRadius;
  21603. this.aStartAngle = json.aStartAngle;
  21604. this.aEndAngle = json.aEndAngle;
  21605. this.aClockwise = json.aClockwise;
  21606. this.aRotation = json.aRotation;
  21607. return this;
  21608. };
  21609. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21610. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21611. this.type = 'ArcCurve';
  21612. }
  21613. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21614. ArcCurve.prototype.constructor = ArcCurve;
  21615. ArcCurve.prototype.isArcCurve = true;
  21616. /**
  21617. * @author zz85 https://github.com/zz85
  21618. *
  21619. * Centripetal CatmullRom Curve - which is useful for avoiding
  21620. * cusps and self-intersections in non-uniform catmull rom curves.
  21621. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21622. *
  21623. * curve.type accepts centripetal(default), chordal and catmullrom
  21624. * curve.tension is used for catmullrom which defaults to 0.5
  21625. */
  21626. /*
  21627. Based on an optimized c++ solution in
  21628. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21629. - http://ideone.com/NoEbVM
  21630. This CubicPoly class could be used for reusing some variables and calculations,
  21631. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21632. which can be placed in CurveUtils.
  21633. */
  21634. function CubicPoly() {
  21635. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21636. /*
  21637. * Compute coefficients for a cubic polynomial
  21638. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21639. * such that
  21640. * p(0) = x0, p(1) = x1
  21641. * and
  21642. * p'(0) = t0, p'(1) = t1.
  21643. */
  21644. function init( x0, x1, t0, t1 ) {
  21645. c0 = x0;
  21646. c1 = t0;
  21647. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21648. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21649. }
  21650. return {
  21651. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21652. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21653. },
  21654. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21655. // compute tangents when parameterized in [t1,t2]
  21656. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21657. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21658. // rescale tangents for parametrization in [0,1]
  21659. t1 *= dt1;
  21660. t2 *= dt1;
  21661. init( x1, x2, t1, t2 );
  21662. },
  21663. calc: function ( t ) {
  21664. var t2 = t * t;
  21665. var t3 = t2 * t;
  21666. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21667. }
  21668. };
  21669. }
  21670. //
  21671. var tmp = new Vector3();
  21672. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21673. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21674. Curve.call( this );
  21675. this.type = 'CatmullRomCurve3';
  21676. this.points = points || [];
  21677. this.closed = closed || false;
  21678. this.curveType = curveType || 'centripetal';
  21679. this.tension = tension || 0.5;
  21680. }
  21681. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21682. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21683. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21684. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21685. var point = optionalTarget || new Vector3();
  21686. var points = this.points;
  21687. var l = points.length;
  21688. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21689. var intPoint = Math.floor( p );
  21690. var weight = p - intPoint;
  21691. if ( this.closed ) {
  21692. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21693. } else if ( weight === 0 && intPoint === l - 1 ) {
  21694. intPoint = l - 2;
  21695. weight = 1;
  21696. }
  21697. var p0, p1, p2, p3; // 4 points
  21698. if ( this.closed || intPoint > 0 ) {
  21699. p0 = points[ ( intPoint - 1 ) % l ];
  21700. } else {
  21701. // extrapolate first point
  21702. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21703. p0 = tmp;
  21704. }
  21705. p1 = points[ intPoint % l ];
  21706. p2 = points[ ( intPoint + 1 ) % l ];
  21707. if ( this.closed || intPoint + 2 < l ) {
  21708. p3 = points[ ( intPoint + 2 ) % l ];
  21709. } else {
  21710. // extrapolate last point
  21711. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21712. p3 = tmp;
  21713. }
  21714. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21715. // init Centripetal / Chordal Catmull-Rom
  21716. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21717. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21718. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21719. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21720. // safety check for repeated points
  21721. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21722. if ( dt0 < 1e-4 ) dt0 = dt1;
  21723. if ( dt2 < 1e-4 ) dt2 = dt1;
  21724. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21725. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21726. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21727. } else if ( this.curveType === 'catmullrom' ) {
  21728. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21729. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21730. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21731. }
  21732. point.set(
  21733. px.calc( weight ),
  21734. py.calc( weight ),
  21735. pz.calc( weight )
  21736. );
  21737. return point;
  21738. };
  21739. CatmullRomCurve3.prototype.copy = function ( source ) {
  21740. Curve.prototype.copy.call( this, source );
  21741. this.points = [];
  21742. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21743. var point = source.points[ i ];
  21744. this.points.push( point.clone() );
  21745. }
  21746. this.closed = source.closed;
  21747. this.curveType = source.curveType;
  21748. this.tension = source.tension;
  21749. return this;
  21750. };
  21751. CatmullRomCurve3.prototype.toJSON = function () {
  21752. var data = Curve.prototype.toJSON.call( this );
  21753. data.points = [];
  21754. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21755. var point = this.points[ i ];
  21756. data.points.push( point.toArray() );
  21757. }
  21758. data.closed = this.closed;
  21759. data.curveType = this.curveType;
  21760. data.tension = this.tension;
  21761. return data;
  21762. };
  21763. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21764. Curve.prototype.fromJSON.call( this, json );
  21765. this.points = [];
  21766. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21767. var point = json.points[ i ];
  21768. this.points.push( new Vector3().fromArray( point ) );
  21769. }
  21770. this.closed = json.closed;
  21771. this.curveType = json.curveType;
  21772. this.tension = json.tension;
  21773. return this;
  21774. };
  21775. /**
  21776. * @author zz85 / http://www.lab4games.net/zz85/blog
  21777. *
  21778. * Bezier Curves formulas obtained from
  21779. * http://en.wikipedia.org/wiki/Bézier_curve
  21780. */
  21781. function CatmullRom( t, p0, p1, p2, p3 ) {
  21782. var v0 = ( p2 - p0 ) * 0.5;
  21783. var v1 = ( p3 - p1 ) * 0.5;
  21784. var t2 = t * t;
  21785. var t3 = t * t2;
  21786. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21787. }
  21788. //
  21789. function QuadraticBezierP0( t, p ) {
  21790. var k = 1 - t;
  21791. return k * k * p;
  21792. }
  21793. function QuadraticBezierP1( t, p ) {
  21794. return 2 * ( 1 - t ) * t * p;
  21795. }
  21796. function QuadraticBezierP2( t, p ) {
  21797. return t * t * p;
  21798. }
  21799. function QuadraticBezier( t, p0, p1, p2 ) {
  21800. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21801. QuadraticBezierP2( t, p2 );
  21802. }
  21803. //
  21804. function CubicBezierP0( t, p ) {
  21805. var k = 1 - t;
  21806. return k * k * k * p;
  21807. }
  21808. function CubicBezierP1( t, p ) {
  21809. var k = 1 - t;
  21810. return 3 * k * k * t * p;
  21811. }
  21812. function CubicBezierP2( t, p ) {
  21813. return 3 * ( 1 - t ) * t * t * p;
  21814. }
  21815. function CubicBezierP3( t, p ) {
  21816. return t * t * t * p;
  21817. }
  21818. function CubicBezier( t, p0, p1, p2, p3 ) {
  21819. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21820. CubicBezierP3( t, p3 );
  21821. }
  21822. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21823. Curve.call( this );
  21824. this.type = 'CubicBezierCurve';
  21825. this.v0 = v0 || new Vector2();
  21826. this.v1 = v1 || new Vector2();
  21827. this.v2 = v2 || new Vector2();
  21828. this.v3 = v3 || new Vector2();
  21829. }
  21830. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21831. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21832. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21833. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21834. var point = optionalTarget || new Vector2();
  21835. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21836. point.set(
  21837. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21838. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21839. );
  21840. return point;
  21841. };
  21842. CubicBezierCurve.prototype.copy = function ( source ) {
  21843. Curve.prototype.copy.call( this, source );
  21844. this.v0.copy( source.v0 );
  21845. this.v1.copy( source.v1 );
  21846. this.v2.copy( source.v2 );
  21847. this.v3.copy( source.v3 );
  21848. return this;
  21849. };
  21850. CubicBezierCurve.prototype.toJSON = function () {
  21851. var data = Curve.prototype.toJSON.call( this );
  21852. data.v0 = this.v0.toArray();
  21853. data.v1 = this.v1.toArray();
  21854. data.v2 = this.v2.toArray();
  21855. data.v3 = this.v3.toArray();
  21856. return data;
  21857. };
  21858. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21859. Curve.prototype.fromJSON.call( this, json );
  21860. this.v0.fromArray( json.v0 );
  21861. this.v1.fromArray( json.v1 );
  21862. this.v2.fromArray( json.v2 );
  21863. this.v3.fromArray( json.v3 );
  21864. return this;
  21865. };
  21866. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21867. Curve.call( this );
  21868. this.type = 'CubicBezierCurve3';
  21869. this.v0 = v0 || new Vector3();
  21870. this.v1 = v1 || new Vector3();
  21871. this.v2 = v2 || new Vector3();
  21872. this.v3 = v3 || new Vector3();
  21873. }
  21874. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21875. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21876. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21877. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21878. var point = optionalTarget || new Vector3();
  21879. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21880. point.set(
  21881. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21882. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21883. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21884. );
  21885. return point;
  21886. };
  21887. CubicBezierCurve3.prototype.copy = function ( source ) {
  21888. Curve.prototype.copy.call( this, source );
  21889. this.v0.copy( source.v0 );
  21890. this.v1.copy( source.v1 );
  21891. this.v2.copy( source.v2 );
  21892. this.v3.copy( source.v3 );
  21893. return this;
  21894. };
  21895. CubicBezierCurve3.prototype.toJSON = function () {
  21896. var data = Curve.prototype.toJSON.call( this );
  21897. data.v0 = this.v0.toArray();
  21898. data.v1 = this.v1.toArray();
  21899. data.v2 = this.v2.toArray();
  21900. data.v3 = this.v3.toArray();
  21901. return data;
  21902. };
  21903. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21904. Curve.prototype.fromJSON.call( this, json );
  21905. this.v0.fromArray( json.v0 );
  21906. this.v1.fromArray( json.v1 );
  21907. this.v2.fromArray( json.v2 );
  21908. this.v3.fromArray( json.v3 );
  21909. return this;
  21910. };
  21911. function LineCurve( v1, v2 ) {
  21912. Curve.call( this );
  21913. this.type = 'LineCurve';
  21914. this.v1 = v1 || new Vector2();
  21915. this.v2 = v2 || new Vector2();
  21916. }
  21917. LineCurve.prototype = Object.create( Curve.prototype );
  21918. LineCurve.prototype.constructor = LineCurve;
  21919. LineCurve.prototype.isLineCurve = true;
  21920. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21921. var point = optionalTarget || new Vector2();
  21922. if ( t === 1 ) {
  21923. point.copy( this.v2 );
  21924. } else {
  21925. point.copy( this.v2 ).sub( this.v1 );
  21926. point.multiplyScalar( t ).add( this.v1 );
  21927. }
  21928. return point;
  21929. };
  21930. // Line curve is linear, so we can overwrite default getPointAt
  21931. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21932. return this.getPoint( u, optionalTarget );
  21933. };
  21934. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21935. var tangent = this.v2.clone().sub( this.v1 );
  21936. return tangent.normalize();
  21937. };
  21938. LineCurve.prototype.copy = function ( source ) {
  21939. Curve.prototype.copy.call( this, source );
  21940. this.v1.copy( source.v1 );
  21941. this.v2.copy( source.v2 );
  21942. return this;
  21943. };
  21944. LineCurve.prototype.toJSON = function () {
  21945. var data = Curve.prototype.toJSON.call( this );
  21946. data.v1 = this.v1.toArray();
  21947. data.v2 = this.v2.toArray();
  21948. return data;
  21949. };
  21950. LineCurve.prototype.fromJSON = function ( json ) {
  21951. Curve.prototype.fromJSON.call( this, json );
  21952. this.v1.fromArray( json.v1 );
  21953. this.v2.fromArray( json.v2 );
  21954. return this;
  21955. };
  21956. function LineCurve3( v1, v2 ) {
  21957. Curve.call( this );
  21958. this.type = 'LineCurve3';
  21959. this.v1 = v1 || new Vector3();
  21960. this.v2 = v2 || new Vector3();
  21961. }
  21962. LineCurve3.prototype = Object.create( Curve.prototype );
  21963. LineCurve3.prototype.constructor = LineCurve3;
  21964. LineCurve3.prototype.isLineCurve3 = true;
  21965. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21966. var point = optionalTarget || new Vector3();
  21967. if ( t === 1 ) {
  21968. point.copy( this.v2 );
  21969. } else {
  21970. point.copy( this.v2 ).sub( this.v1 );
  21971. point.multiplyScalar( t ).add( this.v1 );
  21972. }
  21973. return point;
  21974. };
  21975. // Line curve is linear, so we can overwrite default getPointAt
  21976. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21977. return this.getPoint( u, optionalTarget );
  21978. };
  21979. LineCurve3.prototype.copy = function ( source ) {
  21980. Curve.prototype.copy.call( this, source );
  21981. this.v1.copy( source.v1 );
  21982. this.v2.copy( source.v2 );
  21983. return this;
  21984. };
  21985. LineCurve3.prototype.toJSON = function () {
  21986. var data = Curve.prototype.toJSON.call( this );
  21987. data.v1 = this.v1.toArray();
  21988. data.v2 = this.v2.toArray();
  21989. return data;
  21990. };
  21991. LineCurve3.prototype.fromJSON = function ( json ) {
  21992. Curve.prototype.fromJSON.call( this, json );
  21993. this.v1.fromArray( json.v1 );
  21994. this.v2.fromArray( json.v2 );
  21995. return this;
  21996. };
  21997. function QuadraticBezierCurve( v0, v1, v2 ) {
  21998. Curve.call( this );
  21999. this.type = 'QuadraticBezierCurve';
  22000. this.v0 = v0 || new Vector2();
  22001. this.v1 = v1 || new Vector2();
  22002. this.v2 = v2 || new Vector2();
  22003. }
  22004. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  22005. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22006. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22007. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22008. var point = optionalTarget || new Vector2();
  22009. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22010. point.set(
  22011. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22012. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22013. );
  22014. return point;
  22015. };
  22016. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22017. Curve.prototype.copy.call( this, source );
  22018. this.v0.copy( source.v0 );
  22019. this.v1.copy( source.v1 );
  22020. this.v2.copy( source.v2 );
  22021. return this;
  22022. };
  22023. QuadraticBezierCurve.prototype.toJSON = function () {
  22024. var data = Curve.prototype.toJSON.call( this );
  22025. data.v0 = this.v0.toArray();
  22026. data.v1 = this.v1.toArray();
  22027. data.v2 = this.v2.toArray();
  22028. return data;
  22029. };
  22030. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22031. Curve.prototype.fromJSON.call( this, json );
  22032. this.v0.fromArray( json.v0 );
  22033. this.v1.fromArray( json.v1 );
  22034. this.v2.fromArray( json.v2 );
  22035. return this;
  22036. };
  22037. function QuadraticBezierCurve3( v0, v1, v2 ) {
  22038. Curve.call( this );
  22039. this.type = 'QuadraticBezierCurve3';
  22040. this.v0 = v0 || new Vector3();
  22041. this.v1 = v1 || new Vector3();
  22042. this.v2 = v2 || new Vector3();
  22043. }
  22044. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22045. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22046. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22047. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22048. var point = optionalTarget || new Vector3();
  22049. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22050. point.set(
  22051. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22052. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22053. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22054. );
  22055. return point;
  22056. };
  22057. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22058. Curve.prototype.copy.call( this, source );
  22059. this.v0.copy( source.v0 );
  22060. this.v1.copy( source.v1 );
  22061. this.v2.copy( source.v2 );
  22062. return this;
  22063. };
  22064. QuadraticBezierCurve3.prototype.toJSON = function () {
  22065. var data = Curve.prototype.toJSON.call( this );
  22066. data.v0 = this.v0.toArray();
  22067. data.v1 = this.v1.toArray();
  22068. data.v2 = this.v2.toArray();
  22069. return data;
  22070. };
  22071. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  22072. Curve.prototype.fromJSON.call( this, json );
  22073. this.v0.fromArray( json.v0 );
  22074. this.v1.fromArray( json.v1 );
  22075. this.v2.fromArray( json.v2 );
  22076. return this;
  22077. };
  22078. function SplineCurve( points /* array of Vector2 */ ) {
  22079. Curve.call( this );
  22080. this.type = 'SplineCurve';
  22081. this.points = points || [];
  22082. }
  22083. SplineCurve.prototype = Object.create( Curve.prototype );
  22084. SplineCurve.prototype.constructor = SplineCurve;
  22085. SplineCurve.prototype.isSplineCurve = true;
  22086. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22087. var point = optionalTarget || new Vector2();
  22088. var points = this.points;
  22089. var p = ( points.length - 1 ) * t;
  22090. var intPoint = Math.floor( p );
  22091. var weight = p - intPoint;
  22092. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  22093. var p1 = points[ intPoint ];
  22094. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  22095. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  22096. point.set(
  22097. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  22098. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  22099. );
  22100. return point;
  22101. };
  22102. SplineCurve.prototype.copy = function ( source ) {
  22103. Curve.prototype.copy.call( this, source );
  22104. this.points = [];
  22105. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22106. var point = source.points[ i ];
  22107. this.points.push( point.clone() );
  22108. }
  22109. return this;
  22110. };
  22111. SplineCurve.prototype.toJSON = function () {
  22112. var data = Curve.prototype.toJSON.call( this );
  22113. data.points = [];
  22114. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22115. var point = this.points[ i ];
  22116. data.points.push( point.toArray() );
  22117. }
  22118. return data;
  22119. };
  22120. SplineCurve.prototype.fromJSON = function ( json ) {
  22121. Curve.prototype.fromJSON.call( this, json );
  22122. this.points = [];
  22123. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22124. var point = json.points[ i ];
  22125. this.points.push( new Vector2().fromArray( point ) );
  22126. }
  22127. return this;
  22128. };
  22129. var Curves = /*#__PURE__*/Object.freeze({
  22130. ArcCurve: ArcCurve,
  22131. CatmullRomCurve3: CatmullRomCurve3,
  22132. CubicBezierCurve: CubicBezierCurve,
  22133. CubicBezierCurve3: CubicBezierCurve3,
  22134. EllipseCurve: EllipseCurve,
  22135. LineCurve: LineCurve,
  22136. LineCurve3: LineCurve3,
  22137. QuadraticBezierCurve: QuadraticBezierCurve,
  22138. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22139. SplineCurve: SplineCurve
  22140. });
  22141. /**
  22142. * @author zz85 / http://www.lab4games.net/zz85/blog
  22143. *
  22144. **/
  22145. /**************************************************************
  22146. * Curved Path - a curve path is simply a array of connected
  22147. * curves, but retains the api of a curve
  22148. **************************************************************/
  22149. function CurvePath() {
  22150. Curve.call( this );
  22151. this.type = 'CurvePath';
  22152. this.curves = [];
  22153. this.autoClose = false; // Automatically closes the path
  22154. }
  22155. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  22156. constructor: CurvePath,
  22157. add: function ( curve ) {
  22158. this.curves.push( curve );
  22159. },
  22160. closePath: function () {
  22161. // Add a line curve if start and end of lines are not connected
  22162. var startPoint = this.curves[ 0 ].getPoint( 0 );
  22163. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  22164. if ( ! startPoint.equals( endPoint ) ) {
  22165. this.curves.push( new LineCurve( endPoint, startPoint ) );
  22166. }
  22167. },
  22168. // To get accurate point with reference to
  22169. // entire path distance at time t,
  22170. // following has to be done:
  22171. // 1. Length of each sub path have to be known
  22172. // 2. Locate and identify type of curve
  22173. // 3. Get t for the curve
  22174. // 4. Return curve.getPointAt(t')
  22175. getPoint: function ( t ) {
  22176. var d = t * this.getLength();
  22177. var curveLengths = this.getCurveLengths();
  22178. var i = 0;
  22179. // To think about boundaries points.
  22180. while ( i < curveLengths.length ) {
  22181. if ( curveLengths[ i ] >= d ) {
  22182. var diff = curveLengths[ i ] - d;
  22183. var curve = this.curves[ i ];
  22184. var segmentLength = curve.getLength();
  22185. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22186. return curve.getPointAt( u );
  22187. }
  22188. i ++;
  22189. }
  22190. return null;
  22191. // loop where sum != 0, sum > d , sum+1 <d
  22192. },
  22193. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22194. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22195. // getPoint() depends on getLength
  22196. getLength: function () {
  22197. var lens = this.getCurveLengths();
  22198. return lens[ lens.length - 1 ];
  22199. },
  22200. // cacheLengths must be recalculated.
  22201. updateArcLengths: function () {
  22202. this.needsUpdate = true;
  22203. this.cacheLengths = null;
  22204. this.getCurveLengths();
  22205. },
  22206. // Compute lengths and cache them
  22207. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22208. getCurveLengths: function () {
  22209. // We use cache values if curves and cache array are same length
  22210. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  22211. return this.cacheLengths;
  22212. }
  22213. // Get length of sub-curve
  22214. // Push sums into cached array
  22215. var lengths = [], sums = 0;
  22216. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22217. sums += this.curves[ i ].getLength();
  22218. lengths.push( sums );
  22219. }
  22220. this.cacheLengths = lengths;
  22221. return lengths;
  22222. },
  22223. getSpacedPoints: function ( divisions ) {
  22224. if ( divisions === undefined ) divisions = 40;
  22225. var points = [];
  22226. for ( var i = 0; i <= divisions; i ++ ) {
  22227. points.push( this.getPoint( i / divisions ) );
  22228. }
  22229. if ( this.autoClose ) {
  22230. points.push( points[ 0 ] );
  22231. }
  22232. return points;
  22233. },
  22234. getPoints: function ( divisions ) {
  22235. divisions = divisions || 12;
  22236. var points = [], last;
  22237. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  22238. var curve = curves[ i ];
  22239. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  22240. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  22241. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  22242. : divisions;
  22243. var pts = curve.getPoints( resolution );
  22244. for ( var j = 0; j < pts.length; j ++ ) {
  22245. var point = pts[ j ];
  22246. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  22247. points.push( point );
  22248. last = point;
  22249. }
  22250. }
  22251. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  22252. points.push( points[ 0 ] );
  22253. }
  22254. return points;
  22255. },
  22256. copy: function ( source ) {
  22257. Curve.prototype.copy.call( this, source );
  22258. this.curves = [];
  22259. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  22260. var curve = source.curves[ i ];
  22261. this.curves.push( curve.clone() );
  22262. }
  22263. this.autoClose = source.autoClose;
  22264. return this;
  22265. },
  22266. toJSON: function () {
  22267. var data = Curve.prototype.toJSON.call( this );
  22268. data.autoClose = this.autoClose;
  22269. data.curves = [];
  22270. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22271. var curve = this.curves[ i ];
  22272. data.curves.push( curve.toJSON() );
  22273. }
  22274. return data;
  22275. },
  22276. fromJSON: function ( json ) {
  22277. Curve.prototype.fromJSON.call( this, json );
  22278. this.autoClose = json.autoClose;
  22279. this.curves = [];
  22280. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  22281. var curve = json.curves[ i ];
  22282. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22283. }
  22284. return this;
  22285. }
  22286. } );
  22287. /**
  22288. * @author zz85 / http://www.lab4games.net/zz85/blog
  22289. * Creates free form 2d path using series of points, lines or curves.
  22290. **/
  22291. function Path( points ) {
  22292. CurvePath.call( this );
  22293. this.type = 'Path';
  22294. this.currentPoint = new Vector2();
  22295. if ( points ) {
  22296. this.setFromPoints( points );
  22297. }
  22298. }
  22299. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22300. constructor: Path,
  22301. setFromPoints: function ( points ) {
  22302. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22303. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22304. this.lineTo( points[ i ].x, points[ i ].y );
  22305. }
  22306. },
  22307. moveTo: function ( x, y ) {
  22308. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22309. },
  22310. lineTo: function ( x, y ) {
  22311. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22312. this.curves.push( curve );
  22313. this.currentPoint.set( x, y );
  22314. },
  22315. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22316. var curve = new QuadraticBezierCurve(
  22317. this.currentPoint.clone(),
  22318. new Vector2( aCPx, aCPy ),
  22319. new Vector2( aX, aY )
  22320. );
  22321. this.curves.push( curve );
  22322. this.currentPoint.set( aX, aY );
  22323. },
  22324. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22325. var curve = new CubicBezierCurve(
  22326. this.currentPoint.clone(),
  22327. new Vector2( aCP1x, aCP1y ),
  22328. new Vector2( aCP2x, aCP2y ),
  22329. new Vector2( aX, aY )
  22330. );
  22331. this.curves.push( curve );
  22332. this.currentPoint.set( aX, aY );
  22333. },
  22334. splineThru: function ( pts /*Array of Vector*/ ) {
  22335. var npts = [ this.currentPoint.clone() ].concat( pts );
  22336. var curve = new SplineCurve( npts );
  22337. this.curves.push( curve );
  22338. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22339. },
  22340. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22341. var x0 = this.currentPoint.x;
  22342. var y0 = this.currentPoint.y;
  22343. this.absarc( aX + x0, aY + y0, aRadius,
  22344. aStartAngle, aEndAngle, aClockwise );
  22345. },
  22346. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22347. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22348. },
  22349. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22350. var x0 = this.currentPoint.x;
  22351. var y0 = this.currentPoint.y;
  22352. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22353. },
  22354. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22355. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22356. if ( this.curves.length > 0 ) {
  22357. // if a previous curve is present, attempt to join
  22358. var firstPoint = curve.getPoint( 0 );
  22359. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22360. this.lineTo( firstPoint.x, firstPoint.y );
  22361. }
  22362. }
  22363. this.curves.push( curve );
  22364. var lastPoint = curve.getPoint( 1 );
  22365. this.currentPoint.copy( lastPoint );
  22366. },
  22367. copy: function ( source ) {
  22368. CurvePath.prototype.copy.call( this, source );
  22369. this.currentPoint.copy( source.currentPoint );
  22370. return this;
  22371. },
  22372. toJSON: function () {
  22373. var data = CurvePath.prototype.toJSON.call( this );
  22374. data.currentPoint = this.currentPoint.toArray();
  22375. return data;
  22376. },
  22377. fromJSON: function ( json ) {
  22378. CurvePath.prototype.fromJSON.call( this, json );
  22379. this.currentPoint.fromArray( json.currentPoint );
  22380. return this;
  22381. }
  22382. } );
  22383. /**
  22384. * @author zz85 / http://www.lab4games.net/zz85/blog
  22385. * Defines a 2d shape plane using paths.
  22386. **/
  22387. // STEP 1 Create a path.
  22388. // STEP 2 Turn path into shape.
  22389. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22390. // STEP 3a - Extract points from each shape, turn to vertices
  22391. // STEP 3b - Triangulate each shape, add faces.
  22392. function Shape( points ) {
  22393. Path.call( this, points );
  22394. this.uuid = _Math.generateUUID();
  22395. this.type = 'Shape';
  22396. this.holes = [];
  22397. }
  22398. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22399. constructor: Shape,
  22400. getPointsHoles: function ( divisions ) {
  22401. var holesPts = [];
  22402. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22403. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22404. }
  22405. return holesPts;
  22406. },
  22407. // get points of shape and holes (keypoints based on segments parameter)
  22408. extractPoints: function ( divisions ) {
  22409. return {
  22410. shape: this.getPoints( divisions ),
  22411. holes: this.getPointsHoles( divisions )
  22412. };
  22413. },
  22414. copy: function ( source ) {
  22415. Path.prototype.copy.call( this, source );
  22416. this.holes = [];
  22417. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22418. var hole = source.holes[ i ];
  22419. this.holes.push( hole.clone() );
  22420. }
  22421. return this;
  22422. },
  22423. toJSON: function () {
  22424. var data = Path.prototype.toJSON.call( this );
  22425. data.uuid = this.uuid;
  22426. data.holes = [];
  22427. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22428. var hole = this.holes[ i ];
  22429. data.holes.push( hole.toJSON() );
  22430. }
  22431. return data;
  22432. },
  22433. fromJSON: function ( json ) {
  22434. Path.prototype.fromJSON.call( this, json );
  22435. this.uuid = json.uuid;
  22436. this.holes = [];
  22437. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22438. var hole = json.holes[ i ];
  22439. this.holes.push( new Path().fromJSON( hole ) );
  22440. }
  22441. return this;
  22442. }
  22443. } );
  22444. /**
  22445. * @author mrdoob / http://mrdoob.com/
  22446. * @author alteredq / http://alteredqualia.com/
  22447. */
  22448. function Light( color, intensity ) {
  22449. Object3D.call( this );
  22450. this.type = 'Light';
  22451. this.color = new Color( color );
  22452. this.intensity = intensity !== undefined ? intensity : 1;
  22453. this.receiveShadow = undefined;
  22454. }
  22455. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22456. constructor: Light,
  22457. isLight: true,
  22458. copy: function ( source ) {
  22459. Object3D.prototype.copy.call( this, source );
  22460. this.color.copy( source.color );
  22461. this.intensity = source.intensity;
  22462. return this;
  22463. },
  22464. toJSON: function ( meta ) {
  22465. var data = Object3D.prototype.toJSON.call( this, meta );
  22466. data.object.color = this.color.getHex();
  22467. data.object.intensity = this.intensity;
  22468. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22469. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22470. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22471. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22472. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22473. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22474. return data;
  22475. }
  22476. } );
  22477. /**
  22478. * @author alteredq / http://alteredqualia.com/
  22479. */
  22480. function HemisphereLight( skyColor, groundColor, intensity ) {
  22481. Light.call( this, skyColor, intensity );
  22482. this.type = 'HemisphereLight';
  22483. this.castShadow = undefined;
  22484. this.position.copy( Object3D.DefaultUp );
  22485. this.updateMatrix();
  22486. this.groundColor = new Color( groundColor );
  22487. }
  22488. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22489. constructor: HemisphereLight,
  22490. isHemisphereLight: true,
  22491. copy: function ( source ) {
  22492. Light.prototype.copy.call( this, source );
  22493. this.groundColor.copy( source.groundColor );
  22494. return this;
  22495. }
  22496. } );
  22497. /**
  22498. * @author mrdoob / http://mrdoob.com/
  22499. */
  22500. function LightShadow( camera ) {
  22501. this.camera = camera;
  22502. this.bias = 0;
  22503. this.radius = 1;
  22504. this.mapSize = new Vector2( 512, 512 );
  22505. this.map = null;
  22506. this.matrix = new Matrix4();
  22507. }
  22508. Object.assign( LightShadow.prototype, {
  22509. copy: function ( source ) {
  22510. this.camera = source.camera.clone();
  22511. this.bias = source.bias;
  22512. this.radius = source.radius;
  22513. this.mapSize.copy( source.mapSize );
  22514. return this;
  22515. },
  22516. clone: function () {
  22517. return new this.constructor().copy( this );
  22518. },
  22519. toJSON: function () {
  22520. var object = {};
  22521. if ( this.bias !== 0 ) object.bias = this.bias;
  22522. if ( this.radius !== 1 ) object.radius = this.radius;
  22523. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22524. object.camera = this.camera.toJSON( false ).object;
  22525. delete object.camera.matrix;
  22526. return object;
  22527. }
  22528. } );
  22529. /**
  22530. * @author mrdoob / http://mrdoob.com/
  22531. */
  22532. function SpotLightShadow() {
  22533. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22534. }
  22535. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22536. constructor: SpotLightShadow,
  22537. isSpotLightShadow: true,
  22538. update: function ( light ) {
  22539. var camera = this.camera;
  22540. var fov = _Math.RAD2DEG * 2 * light.angle;
  22541. var aspect = this.mapSize.width / this.mapSize.height;
  22542. var far = light.distance || camera.far;
  22543. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22544. camera.fov = fov;
  22545. camera.aspect = aspect;
  22546. camera.far = far;
  22547. camera.updateProjectionMatrix();
  22548. }
  22549. }
  22550. } );
  22551. /**
  22552. * @author alteredq / http://alteredqualia.com/
  22553. */
  22554. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22555. Light.call( this, color, intensity );
  22556. this.type = 'SpotLight';
  22557. this.position.copy( Object3D.DefaultUp );
  22558. this.updateMatrix();
  22559. this.target = new Object3D();
  22560. Object.defineProperty( this, 'power', {
  22561. get: function () {
  22562. // intensity = power per solid angle.
  22563. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22564. return this.intensity * Math.PI;
  22565. },
  22566. set: function ( power ) {
  22567. // intensity = power per solid angle.
  22568. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22569. this.intensity = power / Math.PI;
  22570. }
  22571. } );
  22572. this.distance = ( distance !== undefined ) ? distance : 0;
  22573. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22574. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22575. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22576. this.shadow = new SpotLightShadow();
  22577. }
  22578. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22579. constructor: SpotLight,
  22580. isSpotLight: true,
  22581. copy: function ( source ) {
  22582. Light.prototype.copy.call( this, source );
  22583. this.distance = source.distance;
  22584. this.angle = source.angle;
  22585. this.penumbra = source.penumbra;
  22586. this.decay = source.decay;
  22587. this.target = source.target.clone();
  22588. this.shadow = source.shadow.clone();
  22589. return this;
  22590. }
  22591. } );
  22592. /**
  22593. * @author mrdoob / http://mrdoob.com/
  22594. */
  22595. function PointLight( color, intensity, distance, decay ) {
  22596. Light.call( this, color, intensity );
  22597. this.type = 'PointLight';
  22598. Object.defineProperty( this, 'power', {
  22599. get: function () {
  22600. // intensity = power per solid angle.
  22601. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22602. return this.intensity * 4 * Math.PI;
  22603. },
  22604. set: function ( power ) {
  22605. // intensity = power per solid angle.
  22606. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22607. this.intensity = power / ( 4 * Math.PI );
  22608. }
  22609. } );
  22610. this.distance = ( distance !== undefined ) ? distance : 0;
  22611. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22612. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22613. }
  22614. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22615. constructor: PointLight,
  22616. isPointLight: true,
  22617. copy: function ( source ) {
  22618. Light.prototype.copy.call( this, source );
  22619. this.distance = source.distance;
  22620. this.decay = source.decay;
  22621. this.shadow = source.shadow.clone();
  22622. return this;
  22623. }
  22624. } );
  22625. /**
  22626. * @author alteredq / http://alteredqualia.com/
  22627. * @author arose / http://github.com/arose
  22628. */
  22629. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22630. Camera.call( this );
  22631. this.type = 'OrthographicCamera';
  22632. this.zoom = 1;
  22633. this.view = null;
  22634. this.left = ( left !== undefined ) ? left : - 1;
  22635. this.right = ( right !== undefined ) ? right : 1;
  22636. this.top = ( top !== undefined ) ? top : 1;
  22637. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22638. this.near = ( near !== undefined ) ? near : 0.1;
  22639. this.far = ( far !== undefined ) ? far : 2000;
  22640. this.updateProjectionMatrix();
  22641. }
  22642. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22643. constructor: OrthographicCamera,
  22644. isOrthographicCamera: true,
  22645. copy: function ( source, recursive ) {
  22646. Camera.prototype.copy.call( this, source, recursive );
  22647. this.left = source.left;
  22648. this.right = source.right;
  22649. this.top = source.top;
  22650. this.bottom = source.bottom;
  22651. this.near = source.near;
  22652. this.far = source.far;
  22653. this.zoom = source.zoom;
  22654. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22655. return this;
  22656. },
  22657. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22658. if ( this.view === null ) {
  22659. this.view = {
  22660. enabled: true,
  22661. fullWidth: 1,
  22662. fullHeight: 1,
  22663. offsetX: 0,
  22664. offsetY: 0,
  22665. width: 1,
  22666. height: 1
  22667. };
  22668. }
  22669. this.view.enabled = true;
  22670. this.view.fullWidth = fullWidth;
  22671. this.view.fullHeight = fullHeight;
  22672. this.view.offsetX = x;
  22673. this.view.offsetY = y;
  22674. this.view.width = width;
  22675. this.view.height = height;
  22676. this.updateProjectionMatrix();
  22677. },
  22678. clearViewOffset: function () {
  22679. if ( this.view !== null ) {
  22680. this.view.enabled = false;
  22681. }
  22682. this.updateProjectionMatrix();
  22683. },
  22684. updateProjectionMatrix: function () {
  22685. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22686. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22687. var cx = ( this.right + this.left ) / 2;
  22688. var cy = ( this.top + this.bottom ) / 2;
  22689. var left = cx - dx;
  22690. var right = cx + dx;
  22691. var top = cy + dy;
  22692. var bottom = cy - dy;
  22693. if ( this.view !== null && this.view.enabled ) {
  22694. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22695. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22696. var scaleW = ( this.right - this.left ) / this.view.width;
  22697. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22698. left += scaleW * ( this.view.offsetX / zoomW );
  22699. right = left + scaleW * ( this.view.width / zoomW );
  22700. top -= scaleH * ( this.view.offsetY / zoomH );
  22701. bottom = top - scaleH * ( this.view.height / zoomH );
  22702. }
  22703. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22704. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22705. },
  22706. toJSON: function ( meta ) {
  22707. var data = Object3D.prototype.toJSON.call( this, meta );
  22708. data.object.zoom = this.zoom;
  22709. data.object.left = this.left;
  22710. data.object.right = this.right;
  22711. data.object.top = this.top;
  22712. data.object.bottom = this.bottom;
  22713. data.object.near = this.near;
  22714. data.object.far = this.far;
  22715. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22716. return data;
  22717. }
  22718. } );
  22719. /**
  22720. * @author mrdoob / http://mrdoob.com/
  22721. */
  22722. function DirectionalLightShadow( ) {
  22723. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22724. }
  22725. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22726. constructor: DirectionalLightShadow
  22727. } );
  22728. /**
  22729. * @author mrdoob / http://mrdoob.com/
  22730. * @author alteredq / http://alteredqualia.com/
  22731. */
  22732. function DirectionalLight( color, intensity ) {
  22733. Light.call( this, color, intensity );
  22734. this.type = 'DirectionalLight';
  22735. this.position.copy( Object3D.DefaultUp );
  22736. this.updateMatrix();
  22737. this.target = new Object3D();
  22738. this.shadow = new DirectionalLightShadow();
  22739. }
  22740. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22741. constructor: DirectionalLight,
  22742. isDirectionalLight: true,
  22743. copy: function ( source ) {
  22744. Light.prototype.copy.call( this, source );
  22745. this.target = source.target.clone();
  22746. this.shadow = source.shadow.clone();
  22747. return this;
  22748. }
  22749. } );
  22750. /**
  22751. * @author mrdoob / http://mrdoob.com/
  22752. */
  22753. function AmbientLight( color, intensity ) {
  22754. Light.call( this, color, intensity );
  22755. this.type = 'AmbientLight';
  22756. this.castShadow = undefined;
  22757. }
  22758. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22759. constructor: AmbientLight,
  22760. isAmbientLight: true
  22761. } );
  22762. /**
  22763. * @author abelnation / http://github.com/abelnation
  22764. */
  22765. function RectAreaLight( color, intensity, width, height ) {
  22766. Light.call( this, color, intensity );
  22767. this.type = 'RectAreaLight';
  22768. this.width = ( width !== undefined ) ? width : 10;
  22769. this.height = ( height !== undefined ) ? height : 10;
  22770. }
  22771. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22772. constructor: RectAreaLight,
  22773. isRectAreaLight: true,
  22774. copy: function ( source ) {
  22775. Light.prototype.copy.call( this, source );
  22776. this.width = source.width;
  22777. this.height = source.height;
  22778. return this;
  22779. },
  22780. toJSON: function ( meta ) {
  22781. var data = Light.prototype.toJSON.call( this, meta );
  22782. data.object.width = this.width;
  22783. data.object.height = this.height;
  22784. return data;
  22785. }
  22786. } );
  22787. /**
  22788. * @author mrdoob / http://mrdoob.com/
  22789. */
  22790. function MaterialLoader( manager ) {
  22791. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22792. this.textures = {};
  22793. }
  22794. Object.assign( MaterialLoader.prototype, {
  22795. load: function ( url, onLoad, onProgress, onError ) {
  22796. var scope = this;
  22797. var loader = new FileLoader( scope.manager );
  22798. loader.setPath( scope.path );
  22799. loader.load( url, function ( text ) {
  22800. onLoad( scope.parse( JSON.parse( text ) ) );
  22801. }, onProgress, onError );
  22802. },
  22803. parse: function ( json ) {
  22804. var textures = this.textures;
  22805. function getTexture( name ) {
  22806. if ( textures[ name ] === undefined ) {
  22807. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22808. }
  22809. return textures[ name ];
  22810. }
  22811. var material = new Materials[ json.type ]();
  22812. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22813. if ( json.name !== undefined ) material.name = json.name;
  22814. if ( json.color !== undefined ) material.color.setHex( json.color );
  22815. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22816. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22817. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22818. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22819. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22820. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22821. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22822. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22823. if ( json.fog !== undefined ) material.fog = json.fog;
  22824. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22825. if ( json.blending !== undefined ) material.blending = json.blending;
  22826. if ( json.combine !== undefined ) material.combine = json.combine;
  22827. if ( json.side !== undefined ) material.side = json.side;
  22828. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22829. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22830. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22831. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22832. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22833. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22834. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22835. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22836. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22837. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22838. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22839. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22840. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22841. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22842. if ( json.scale !== undefined ) material.scale = json.scale;
  22843. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22844. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22845. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22846. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22847. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22848. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  22849. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22850. if ( json.visible !== undefined ) material.visible = json.visible;
  22851. if ( json.userData !== undefined ) material.userData = json.userData;
  22852. // Shader Material
  22853. if ( json.uniforms !== undefined ) {
  22854. for ( var name in json.uniforms ) {
  22855. var uniform = json.uniforms[ name ];
  22856. material.uniforms[ name ] = {};
  22857. switch ( uniform.type ) {
  22858. case 't':
  22859. material.uniforms[ name ].value = getTexture( uniform.value );
  22860. break;
  22861. case 'c':
  22862. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22863. break;
  22864. case 'v2':
  22865. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22866. break;
  22867. case 'v3':
  22868. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22869. break;
  22870. case 'v4':
  22871. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22872. break;
  22873. case 'm3':
  22874. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22875. case 'm4':
  22876. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22877. break;
  22878. default:
  22879. material.uniforms[ name ].value = uniform.value;
  22880. }
  22881. }
  22882. }
  22883. if ( json.defines !== undefined ) material.defines = json.defines;
  22884. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22885. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22886. if ( json.extensions !== undefined ) {
  22887. for ( var key in json.extensions ) {
  22888. material.extensions[ key ] = json.extensions[ key ];
  22889. }
  22890. }
  22891. // Deprecated
  22892. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22893. // for PointsMaterial
  22894. if ( json.size !== undefined ) material.size = json.size;
  22895. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22896. // maps
  22897. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22898. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22899. if ( json.alphaMap !== undefined ) {
  22900. material.alphaMap = getTexture( json.alphaMap );
  22901. material.transparent = true;
  22902. }
  22903. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22904. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22905. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22906. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22907. if ( json.normalScale !== undefined ) {
  22908. var normalScale = json.normalScale;
  22909. if ( Array.isArray( normalScale ) === false ) {
  22910. // Blender exporter used to export a scalar. See #7459
  22911. normalScale = [ normalScale, normalScale ];
  22912. }
  22913. material.normalScale = new Vector2().fromArray( normalScale );
  22914. }
  22915. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22916. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22917. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22918. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22919. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22920. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22921. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22922. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22923. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22924. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22925. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22926. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  22927. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22928. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22929. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22930. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22931. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22932. if ( json.clearCoatNormalMap !== undefined ) material.clearCoatNormalMap = getTexture( json.clearCoatNormalMap );
  22933. if ( json.clearCoatNormalScale !== undefined ) material.clearCoatNormalScale = new Vector2().fromArray( json.clearCoatNormalScale );
  22934. return material;
  22935. },
  22936. setPath: function ( value ) {
  22937. this.path = value;
  22938. return this;
  22939. },
  22940. setTextures: function ( value ) {
  22941. this.textures = value;
  22942. return this;
  22943. }
  22944. } );
  22945. /**
  22946. * @author Don McCurdy / https://www.donmccurdy.com
  22947. */
  22948. var LoaderUtils = {
  22949. decodeText: function ( array ) {
  22950. if ( typeof TextDecoder !== 'undefined' ) {
  22951. return new TextDecoder().decode( array );
  22952. }
  22953. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22954. // throws a "maximum call stack size exceeded" error for large arrays.
  22955. var s = '';
  22956. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22957. // Implicitly assumes little-endian.
  22958. s += String.fromCharCode( array[ i ] );
  22959. }
  22960. try {
  22961. // merges multi-byte utf-8 characters.
  22962. return decodeURIComponent( escape( s ) );
  22963. } catch ( e ) { // see #16358
  22964. return s;
  22965. }
  22966. },
  22967. extractUrlBase: function ( url ) {
  22968. var index = url.lastIndexOf( '/' );
  22969. if ( index === - 1 ) return './';
  22970. return url.substr( 0, index + 1 );
  22971. }
  22972. };
  22973. /**
  22974. * @author benaadams / https://twitter.com/ben_a_adams
  22975. */
  22976. function InstancedBufferGeometry() {
  22977. BufferGeometry.call( this );
  22978. this.type = 'InstancedBufferGeometry';
  22979. this.maxInstancedCount = undefined;
  22980. }
  22981. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  22982. constructor: InstancedBufferGeometry,
  22983. isInstancedBufferGeometry: true,
  22984. copy: function ( source ) {
  22985. BufferGeometry.prototype.copy.call( this, source );
  22986. this.maxInstancedCount = source.maxInstancedCount;
  22987. return this;
  22988. },
  22989. clone: function () {
  22990. return new this.constructor().copy( this );
  22991. },
  22992. toJSON: function () {
  22993. var data = BufferGeometry.prototype.toJSON.call( this );
  22994. data.maxInstancedCount = this.maxInstancedCount;
  22995. data.isInstancedBufferGeometry = true;
  22996. return data;
  22997. }
  22998. } );
  22999. /**
  23000. * @author benaadams / https://twitter.com/ben_a_adams
  23001. */
  23002. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  23003. if ( typeof ( normalized ) === 'number' ) {
  23004. meshPerAttribute = normalized;
  23005. normalized = false;
  23006. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  23007. }
  23008. BufferAttribute.call( this, array, itemSize, normalized );
  23009. this.meshPerAttribute = meshPerAttribute || 1;
  23010. }
  23011. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23012. constructor: InstancedBufferAttribute,
  23013. isInstancedBufferAttribute: true,
  23014. copy: function ( source ) {
  23015. BufferAttribute.prototype.copy.call( this, source );
  23016. this.meshPerAttribute = source.meshPerAttribute;
  23017. return this;
  23018. },
  23019. toJSON: function () {
  23020. var data = BufferAttribute.prototype.toJSON.call( this );
  23021. data.meshPerAttribute = this.meshPerAttribute;
  23022. data.isInstancedBufferAttribute = true;
  23023. return data;
  23024. }
  23025. } );
  23026. /**
  23027. * @author mrdoob / http://mrdoob.com/
  23028. */
  23029. function BufferGeometryLoader( manager ) {
  23030. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23031. }
  23032. Object.assign( BufferGeometryLoader.prototype, {
  23033. load: function ( url, onLoad, onProgress, onError ) {
  23034. var scope = this;
  23035. var loader = new FileLoader( scope.manager );
  23036. loader.setPath( scope.path );
  23037. loader.load( url, function ( text ) {
  23038. onLoad( scope.parse( JSON.parse( text ) ) );
  23039. }, onProgress, onError );
  23040. },
  23041. parse: function ( json ) {
  23042. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23043. var index = json.data.index;
  23044. if ( index !== undefined ) {
  23045. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  23046. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  23047. }
  23048. var attributes = json.data.attributes;
  23049. for ( var key in attributes ) {
  23050. var attribute = attributes[ key ];
  23051. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23052. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23053. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  23054. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23055. geometry.addAttribute( key, bufferAttribute );
  23056. }
  23057. var morphAttributes = json.data.morphAttributes;
  23058. if ( morphAttributes ) {
  23059. for ( var key in morphAttributes ) {
  23060. var attributeArray = morphAttributes[ key ];
  23061. var array = [];
  23062. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  23063. var attribute = attributeArray[ i ];
  23064. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23065. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  23066. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23067. array.push( bufferAttribute );
  23068. }
  23069. geometry.morphAttributes[ key ] = array;
  23070. }
  23071. }
  23072. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23073. if ( groups !== undefined ) {
  23074. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  23075. var group = groups[ i ];
  23076. geometry.addGroup( group.start, group.count, group.materialIndex );
  23077. }
  23078. }
  23079. var boundingSphere = json.data.boundingSphere;
  23080. if ( boundingSphere !== undefined ) {
  23081. var center = new Vector3();
  23082. if ( boundingSphere.center !== undefined ) {
  23083. center.fromArray( boundingSphere.center );
  23084. }
  23085. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  23086. }
  23087. if ( json.name ) geometry.name = json.name;
  23088. if ( json.userData ) geometry.userData = json.userData;
  23089. return geometry;
  23090. },
  23091. setPath: function ( value ) {
  23092. this.path = value;
  23093. return this;
  23094. }
  23095. } );
  23096. var TYPED_ARRAYS = {
  23097. Int8Array: Int8Array,
  23098. Uint8Array: Uint8Array,
  23099. // Workaround for IE11 pre KB2929437. See #11440
  23100. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  23101. Int16Array: Int16Array,
  23102. Uint16Array: Uint16Array,
  23103. Int32Array: Int32Array,
  23104. Uint32Array: Uint32Array,
  23105. Float32Array: Float32Array,
  23106. Float64Array: Float64Array
  23107. };
  23108. /**
  23109. * @author mrdoob / http://mrdoob.com/
  23110. */
  23111. function ObjectLoader( manager ) {
  23112. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23113. this.resourcePath = '';
  23114. }
  23115. Object.assign( ObjectLoader.prototype, {
  23116. crossOrigin: 'anonymous',
  23117. load: function ( url, onLoad, onProgress, onError ) {
  23118. var scope = this;
  23119. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  23120. this.resourcePath = this.resourcePath || path;
  23121. var loader = new FileLoader( scope.manager );
  23122. loader.setPath( this.path );
  23123. loader.load( url, function ( text ) {
  23124. var json = null;
  23125. try {
  23126. json = JSON.parse( text );
  23127. } catch ( error ) {
  23128. if ( onError !== undefined ) onError( error );
  23129. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  23130. return;
  23131. }
  23132. var metadata = json.metadata;
  23133. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  23134. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  23135. return;
  23136. }
  23137. scope.parse( json, onLoad );
  23138. }, onProgress, onError );
  23139. },
  23140. setPath: function ( value ) {
  23141. this.path = value;
  23142. return this;
  23143. },
  23144. setResourcePath: function ( value ) {
  23145. this.resourcePath = value;
  23146. return this;
  23147. },
  23148. setCrossOrigin: function ( value ) {
  23149. this.crossOrigin = value;
  23150. return this;
  23151. },
  23152. parse: function ( json, onLoad ) {
  23153. var shapes = this.parseShape( json.shapes );
  23154. var geometries = this.parseGeometries( json.geometries, shapes );
  23155. var images = this.parseImages( json.images, function () {
  23156. if ( onLoad !== undefined ) onLoad( object );
  23157. } );
  23158. var textures = this.parseTextures( json.textures, images );
  23159. var materials = this.parseMaterials( json.materials, textures );
  23160. var object = this.parseObject( json.object, geometries, materials );
  23161. if ( json.animations ) {
  23162. object.animations = this.parseAnimations( json.animations );
  23163. }
  23164. if ( json.images === undefined || json.images.length === 0 ) {
  23165. if ( onLoad !== undefined ) onLoad( object );
  23166. }
  23167. return object;
  23168. },
  23169. parseShape: function ( json ) {
  23170. var shapes = {};
  23171. if ( json !== undefined ) {
  23172. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23173. var shape = new Shape().fromJSON( json[ i ] );
  23174. shapes[ shape.uuid ] = shape;
  23175. }
  23176. }
  23177. return shapes;
  23178. },
  23179. parseGeometries: function ( json, shapes ) {
  23180. var geometries = {};
  23181. if ( json !== undefined ) {
  23182. var bufferGeometryLoader = new BufferGeometryLoader();
  23183. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23184. var geometry;
  23185. var data = json[ i ];
  23186. switch ( data.type ) {
  23187. case 'PlaneGeometry':
  23188. case 'PlaneBufferGeometry':
  23189. geometry = new Geometries[ data.type ](
  23190. data.width,
  23191. data.height,
  23192. data.widthSegments,
  23193. data.heightSegments
  23194. );
  23195. break;
  23196. case 'BoxGeometry':
  23197. case 'BoxBufferGeometry':
  23198. case 'CubeGeometry': // backwards compatible
  23199. geometry = new Geometries[ data.type ](
  23200. data.width,
  23201. data.height,
  23202. data.depth,
  23203. data.widthSegments,
  23204. data.heightSegments,
  23205. data.depthSegments
  23206. );
  23207. break;
  23208. case 'CircleGeometry':
  23209. case 'CircleBufferGeometry':
  23210. geometry = new Geometries[ data.type ](
  23211. data.radius,
  23212. data.segments,
  23213. data.thetaStart,
  23214. data.thetaLength
  23215. );
  23216. break;
  23217. case 'CylinderGeometry':
  23218. case 'CylinderBufferGeometry':
  23219. geometry = new Geometries[ data.type ](
  23220. data.radiusTop,
  23221. data.radiusBottom,
  23222. data.height,
  23223. data.radialSegments,
  23224. data.heightSegments,
  23225. data.openEnded,
  23226. data.thetaStart,
  23227. data.thetaLength
  23228. );
  23229. break;
  23230. case 'ConeGeometry':
  23231. case 'ConeBufferGeometry':
  23232. geometry = new Geometries[ data.type ](
  23233. data.radius,
  23234. data.height,
  23235. data.radialSegments,
  23236. data.heightSegments,
  23237. data.openEnded,
  23238. data.thetaStart,
  23239. data.thetaLength
  23240. );
  23241. break;
  23242. case 'SphereGeometry':
  23243. case 'SphereBufferGeometry':
  23244. geometry = new Geometries[ data.type ](
  23245. data.radius,
  23246. data.widthSegments,
  23247. data.heightSegments,
  23248. data.phiStart,
  23249. data.phiLength,
  23250. data.thetaStart,
  23251. data.thetaLength
  23252. );
  23253. break;
  23254. case 'DodecahedronGeometry':
  23255. case 'DodecahedronBufferGeometry':
  23256. case 'IcosahedronGeometry':
  23257. case 'IcosahedronBufferGeometry':
  23258. case 'OctahedronGeometry':
  23259. case 'OctahedronBufferGeometry':
  23260. case 'TetrahedronGeometry':
  23261. case 'TetrahedronBufferGeometry':
  23262. geometry = new Geometries[ data.type ](
  23263. data.radius,
  23264. data.detail
  23265. );
  23266. break;
  23267. case 'RingGeometry':
  23268. case 'RingBufferGeometry':
  23269. geometry = new Geometries[ data.type ](
  23270. data.innerRadius,
  23271. data.outerRadius,
  23272. data.thetaSegments,
  23273. data.phiSegments,
  23274. data.thetaStart,
  23275. data.thetaLength
  23276. );
  23277. break;
  23278. case 'TorusGeometry':
  23279. case 'TorusBufferGeometry':
  23280. geometry = new Geometries[ data.type ](
  23281. data.radius,
  23282. data.tube,
  23283. data.radialSegments,
  23284. data.tubularSegments,
  23285. data.arc
  23286. );
  23287. break;
  23288. case 'TorusKnotGeometry':
  23289. case 'TorusKnotBufferGeometry':
  23290. geometry = new Geometries[ data.type ](
  23291. data.radius,
  23292. data.tube,
  23293. data.tubularSegments,
  23294. data.radialSegments,
  23295. data.p,
  23296. data.q
  23297. );
  23298. break;
  23299. case 'TubeGeometry':
  23300. case 'TubeBufferGeometry':
  23301. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23302. // User defined curves or instances of CurvePath will not be deserialized.
  23303. geometry = new Geometries[ data.type ](
  23304. new Curves[ data.path.type ]().fromJSON( data.path ),
  23305. data.tubularSegments,
  23306. data.radius,
  23307. data.radialSegments,
  23308. data.closed
  23309. );
  23310. break;
  23311. case 'LatheGeometry':
  23312. case 'LatheBufferGeometry':
  23313. geometry = new Geometries[ data.type ](
  23314. data.points,
  23315. data.segments,
  23316. data.phiStart,
  23317. data.phiLength
  23318. );
  23319. break;
  23320. case 'PolyhedronGeometry':
  23321. case 'PolyhedronBufferGeometry':
  23322. geometry = new Geometries[ data.type ](
  23323. data.vertices,
  23324. data.indices,
  23325. data.radius,
  23326. data.details
  23327. );
  23328. break;
  23329. case 'ShapeGeometry':
  23330. case 'ShapeBufferGeometry':
  23331. var geometryShapes = [];
  23332. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23333. var shape = shapes[ data.shapes[ j ] ];
  23334. geometryShapes.push( shape );
  23335. }
  23336. geometry = new Geometries[ data.type ](
  23337. geometryShapes,
  23338. data.curveSegments
  23339. );
  23340. break;
  23341. case 'ExtrudeGeometry':
  23342. case 'ExtrudeBufferGeometry':
  23343. var geometryShapes = [];
  23344. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23345. var shape = shapes[ data.shapes[ j ] ];
  23346. geometryShapes.push( shape );
  23347. }
  23348. var extrudePath = data.options.extrudePath;
  23349. if ( extrudePath !== undefined ) {
  23350. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23351. }
  23352. geometry = new Geometries[ data.type ](
  23353. geometryShapes,
  23354. data.options
  23355. );
  23356. break;
  23357. case 'BufferGeometry':
  23358. case 'InstancedBufferGeometry':
  23359. geometry = bufferGeometryLoader.parse( data );
  23360. break;
  23361. case 'Geometry':
  23362. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23363. var geometryLoader = new THREE.LegacyJSONLoader();
  23364. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23365. } else {
  23366. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23367. }
  23368. break;
  23369. default:
  23370. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23371. continue;
  23372. }
  23373. geometry.uuid = data.uuid;
  23374. if ( data.name !== undefined ) geometry.name = data.name;
  23375. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23376. geometries[ data.uuid ] = geometry;
  23377. }
  23378. }
  23379. return geometries;
  23380. },
  23381. parseMaterials: function ( json, textures ) {
  23382. var cache = {}; // MultiMaterial
  23383. var materials = {};
  23384. if ( json !== undefined ) {
  23385. var loader = new MaterialLoader();
  23386. loader.setTextures( textures );
  23387. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23388. var data = json[ i ];
  23389. if ( data.type === 'MultiMaterial' ) {
  23390. // Deprecated
  23391. var array = [];
  23392. for ( var j = 0; j < data.materials.length; j ++ ) {
  23393. var material = data.materials[ j ];
  23394. if ( cache[ material.uuid ] === undefined ) {
  23395. cache[ material.uuid ] = loader.parse( material );
  23396. }
  23397. array.push( cache[ material.uuid ] );
  23398. }
  23399. materials[ data.uuid ] = array;
  23400. } else {
  23401. if ( cache[ data.uuid ] === undefined ) {
  23402. cache[ data.uuid ] = loader.parse( data );
  23403. }
  23404. materials[ data.uuid ] = cache[ data.uuid ];
  23405. }
  23406. }
  23407. }
  23408. return materials;
  23409. },
  23410. parseAnimations: function ( json ) {
  23411. var animations = [];
  23412. for ( var i = 0; i < json.length; i ++ ) {
  23413. var data = json[ i ];
  23414. var clip = AnimationClip.parse( data );
  23415. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23416. animations.push( clip );
  23417. }
  23418. return animations;
  23419. },
  23420. parseImages: function ( json, onLoad ) {
  23421. var scope = this;
  23422. var images = {};
  23423. function loadImage( url ) {
  23424. scope.manager.itemStart( url );
  23425. return loader.load( url, function () {
  23426. scope.manager.itemEnd( url );
  23427. }, undefined, function () {
  23428. scope.manager.itemError( url );
  23429. scope.manager.itemEnd( url );
  23430. } );
  23431. }
  23432. if ( json !== undefined && json.length > 0 ) {
  23433. var manager = new LoadingManager( onLoad );
  23434. var loader = new ImageLoader( manager );
  23435. loader.setCrossOrigin( this.crossOrigin );
  23436. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23437. var image = json[ i ];
  23438. var url = image.url;
  23439. if ( Array.isArray( url ) ) {
  23440. // load array of images e.g CubeTexture
  23441. images[ image.uuid ] = [];
  23442. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23443. var currentUrl = url[ j ];
  23444. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23445. images[ image.uuid ].push( loadImage( path ) );
  23446. }
  23447. } else {
  23448. // load single image
  23449. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23450. images[ image.uuid ] = loadImage( path );
  23451. }
  23452. }
  23453. }
  23454. return images;
  23455. },
  23456. parseTextures: function ( json, images ) {
  23457. function parseConstant( value, type ) {
  23458. if ( typeof value === 'number' ) return value;
  23459. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23460. return type[ value ];
  23461. }
  23462. var textures = {};
  23463. if ( json !== undefined ) {
  23464. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23465. var data = json[ i ];
  23466. if ( data.image === undefined ) {
  23467. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23468. }
  23469. if ( images[ data.image ] === undefined ) {
  23470. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23471. }
  23472. var texture;
  23473. if ( Array.isArray( images[ data.image ] ) ) {
  23474. texture = new CubeTexture( images[ data.image ] );
  23475. } else {
  23476. texture = new Texture( images[ data.image ] );
  23477. }
  23478. texture.needsUpdate = true;
  23479. texture.uuid = data.uuid;
  23480. if ( data.name !== undefined ) texture.name = data.name;
  23481. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23482. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23483. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23484. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23485. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23486. if ( data.wrap !== undefined ) {
  23487. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23488. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23489. }
  23490. if ( data.format !== undefined ) texture.format = data.format;
  23491. if ( data.type !== undefined ) texture.type = data.type;
  23492. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23493. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23494. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23495. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23496. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23497. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23498. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23499. textures[ data.uuid ] = texture;
  23500. }
  23501. }
  23502. return textures;
  23503. },
  23504. parseObject: function ( data, geometries, materials ) {
  23505. var object;
  23506. function getGeometry( name ) {
  23507. if ( geometries[ name ] === undefined ) {
  23508. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23509. }
  23510. return geometries[ name ];
  23511. }
  23512. function getMaterial( name ) {
  23513. if ( name === undefined ) return undefined;
  23514. if ( Array.isArray( name ) ) {
  23515. var array = [];
  23516. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23517. var uuid = name[ i ];
  23518. if ( materials[ uuid ] === undefined ) {
  23519. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23520. }
  23521. array.push( materials[ uuid ] );
  23522. }
  23523. return array;
  23524. }
  23525. if ( materials[ name ] === undefined ) {
  23526. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23527. }
  23528. return materials[ name ];
  23529. }
  23530. switch ( data.type ) {
  23531. case 'Scene':
  23532. object = new Scene();
  23533. if ( data.background !== undefined ) {
  23534. if ( Number.isInteger( data.background ) ) {
  23535. object.background = new Color( data.background );
  23536. }
  23537. }
  23538. if ( data.fog !== undefined ) {
  23539. if ( data.fog.type === 'Fog' ) {
  23540. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23541. } else if ( data.fog.type === 'FogExp2' ) {
  23542. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23543. }
  23544. }
  23545. break;
  23546. case 'PerspectiveCamera':
  23547. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23548. if ( data.focus !== undefined ) object.focus = data.focus;
  23549. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23550. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23551. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23552. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23553. break;
  23554. case 'OrthographicCamera':
  23555. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23556. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23557. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23558. break;
  23559. case 'AmbientLight':
  23560. object = new AmbientLight( data.color, data.intensity );
  23561. break;
  23562. case 'DirectionalLight':
  23563. object = new DirectionalLight( data.color, data.intensity );
  23564. break;
  23565. case 'PointLight':
  23566. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23567. break;
  23568. case 'RectAreaLight':
  23569. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23570. break;
  23571. case 'SpotLight':
  23572. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23573. break;
  23574. case 'HemisphereLight':
  23575. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23576. break;
  23577. case 'SkinnedMesh':
  23578. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23579. case 'Mesh':
  23580. var geometry = getGeometry( data.geometry );
  23581. var material = getMaterial( data.material );
  23582. if ( geometry.bones && geometry.bones.length > 0 ) {
  23583. object = new SkinnedMesh( geometry, material );
  23584. } else {
  23585. object = new Mesh( geometry, material );
  23586. }
  23587. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23588. break;
  23589. case 'LOD':
  23590. object = new LOD();
  23591. break;
  23592. case 'Line':
  23593. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23594. break;
  23595. case 'LineLoop':
  23596. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23597. break;
  23598. case 'LineSegments':
  23599. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23600. break;
  23601. case 'PointCloud':
  23602. case 'Points':
  23603. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23604. break;
  23605. case 'Sprite':
  23606. object = new Sprite( getMaterial( data.material ) );
  23607. break;
  23608. case 'Group':
  23609. object = new Group();
  23610. break;
  23611. default:
  23612. object = new Object3D();
  23613. }
  23614. object.uuid = data.uuid;
  23615. if ( data.name !== undefined ) object.name = data.name;
  23616. if ( data.matrix !== undefined ) {
  23617. object.matrix.fromArray( data.matrix );
  23618. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23619. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23620. } else {
  23621. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23622. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23623. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23624. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23625. }
  23626. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23627. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23628. if ( data.shadow ) {
  23629. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23630. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23631. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23632. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23633. }
  23634. if ( data.visible !== undefined ) object.visible = data.visible;
  23635. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23636. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23637. if ( data.userData !== undefined ) object.userData = data.userData;
  23638. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23639. if ( data.children !== undefined ) {
  23640. var children = data.children;
  23641. for ( var i = 0; i < children.length; i ++ ) {
  23642. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23643. }
  23644. }
  23645. if ( data.type === 'LOD' ) {
  23646. var levels = data.levels;
  23647. for ( var l = 0; l < levels.length; l ++ ) {
  23648. var level = levels[ l ];
  23649. var child = object.getObjectByProperty( 'uuid', level.object );
  23650. if ( child !== undefined ) {
  23651. object.addLevel( child, level.distance );
  23652. }
  23653. }
  23654. }
  23655. return object;
  23656. }
  23657. } );
  23658. var TEXTURE_MAPPING = {
  23659. UVMapping: UVMapping,
  23660. CubeReflectionMapping: CubeReflectionMapping,
  23661. CubeRefractionMapping: CubeRefractionMapping,
  23662. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23663. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23664. SphericalReflectionMapping: SphericalReflectionMapping,
  23665. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23666. CubeUVRefractionMapping: CubeUVRefractionMapping
  23667. };
  23668. var TEXTURE_WRAPPING = {
  23669. RepeatWrapping: RepeatWrapping,
  23670. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23671. MirroredRepeatWrapping: MirroredRepeatWrapping
  23672. };
  23673. var TEXTURE_FILTER = {
  23674. NearestFilter: NearestFilter,
  23675. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  23676. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  23677. LinearFilter: LinearFilter,
  23678. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  23679. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  23680. };
  23681. /**
  23682. * @author thespite / http://clicktorelease.com/
  23683. */
  23684. function ImageBitmapLoader( manager ) {
  23685. if ( typeof createImageBitmap === 'undefined' ) {
  23686. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23687. }
  23688. if ( typeof fetch === 'undefined' ) {
  23689. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23690. }
  23691. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23692. this.options = undefined;
  23693. }
  23694. ImageBitmapLoader.prototype = {
  23695. constructor: ImageBitmapLoader,
  23696. setOptions: function setOptions( options ) {
  23697. this.options = options;
  23698. return this;
  23699. },
  23700. load: function ( url, onLoad, onProgress, onError ) {
  23701. if ( url === undefined ) url = '';
  23702. if ( this.path !== undefined ) url = this.path + url;
  23703. url = this.manager.resolveURL( url );
  23704. var scope = this;
  23705. var cached = Cache.get( url );
  23706. if ( cached !== undefined ) {
  23707. scope.manager.itemStart( url );
  23708. setTimeout( function () {
  23709. if ( onLoad ) onLoad( cached );
  23710. scope.manager.itemEnd( url );
  23711. }, 0 );
  23712. return cached;
  23713. }
  23714. fetch( url ).then( function ( res ) {
  23715. return res.blob();
  23716. } ).then( function ( blob ) {
  23717. if ( scope.options === undefined ) {
  23718. // Workaround for FireFox. It causes an error if you pass options.
  23719. return createImageBitmap( blob );
  23720. } else {
  23721. return createImageBitmap( blob, scope.options );
  23722. }
  23723. } ).then( function ( imageBitmap ) {
  23724. Cache.add( url, imageBitmap );
  23725. if ( onLoad ) onLoad( imageBitmap );
  23726. scope.manager.itemEnd( url );
  23727. } ).catch( function ( e ) {
  23728. if ( onError ) onError( e );
  23729. scope.manager.itemError( url );
  23730. scope.manager.itemEnd( url );
  23731. } );
  23732. scope.manager.itemStart( url );
  23733. },
  23734. setCrossOrigin: function ( /* value */ ) {
  23735. return this;
  23736. },
  23737. setPath: function ( value ) {
  23738. this.path = value;
  23739. return this;
  23740. }
  23741. };
  23742. /**
  23743. * @author zz85 / http://www.lab4games.net/zz85/blog
  23744. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23745. **/
  23746. function ShapePath() {
  23747. this.type = 'ShapePath';
  23748. this.color = new Color();
  23749. this.subPaths = [];
  23750. this.currentPath = null;
  23751. }
  23752. Object.assign( ShapePath.prototype, {
  23753. moveTo: function ( x, y ) {
  23754. this.currentPath = new Path();
  23755. this.subPaths.push( this.currentPath );
  23756. this.currentPath.moveTo( x, y );
  23757. },
  23758. lineTo: function ( x, y ) {
  23759. this.currentPath.lineTo( x, y );
  23760. },
  23761. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23762. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23763. },
  23764. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23765. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23766. },
  23767. splineThru: function ( pts ) {
  23768. this.currentPath.splineThru( pts );
  23769. },
  23770. toShapes: function ( isCCW, noHoles ) {
  23771. function toShapesNoHoles( inSubpaths ) {
  23772. var shapes = [];
  23773. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23774. var tmpPath = inSubpaths[ i ];
  23775. var tmpShape = new Shape();
  23776. tmpShape.curves = tmpPath.curves;
  23777. shapes.push( tmpShape );
  23778. }
  23779. return shapes;
  23780. }
  23781. function isPointInsidePolygon( inPt, inPolygon ) {
  23782. var polyLen = inPolygon.length;
  23783. // inPt on polygon contour => immediate success or
  23784. // toggling of inside/outside at every single! intersection point of an edge
  23785. // with the horizontal line through inPt, left of inPt
  23786. // not counting lowerY endpoints of edges and whole edges on that line
  23787. var inside = false;
  23788. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23789. var edgeLowPt = inPolygon[ p ];
  23790. var edgeHighPt = inPolygon[ q ];
  23791. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23792. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23793. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23794. // not parallel
  23795. if ( edgeDy < 0 ) {
  23796. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23797. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23798. }
  23799. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23800. if ( inPt.y === edgeLowPt.y ) {
  23801. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23802. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23803. } else {
  23804. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23805. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23806. if ( perpEdge < 0 ) continue;
  23807. inside = ! inside; // true intersection left of inPt
  23808. }
  23809. } else {
  23810. // parallel or collinear
  23811. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23812. // edge lies on the same horizontal line as inPt
  23813. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23814. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23815. // continue;
  23816. }
  23817. }
  23818. return inside;
  23819. }
  23820. var isClockWise = ShapeUtils.isClockWise;
  23821. var subPaths = this.subPaths;
  23822. if ( subPaths.length === 0 ) return [];
  23823. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23824. var solid, tmpPath, tmpShape, shapes = [];
  23825. if ( subPaths.length === 1 ) {
  23826. tmpPath = subPaths[ 0 ];
  23827. tmpShape = new Shape();
  23828. tmpShape.curves = tmpPath.curves;
  23829. shapes.push( tmpShape );
  23830. return shapes;
  23831. }
  23832. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23833. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23834. // console.log("Holes first", holesFirst);
  23835. var betterShapeHoles = [];
  23836. var newShapes = [];
  23837. var newShapeHoles = [];
  23838. var mainIdx = 0;
  23839. var tmpPoints;
  23840. newShapes[ mainIdx ] = undefined;
  23841. newShapeHoles[ mainIdx ] = [];
  23842. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23843. tmpPath = subPaths[ i ];
  23844. tmpPoints = tmpPath.getPoints();
  23845. solid = isClockWise( tmpPoints );
  23846. solid = isCCW ? ! solid : solid;
  23847. if ( solid ) {
  23848. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23849. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23850. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23851. if ( holesFirst ) mainIdx ++;
  23852. newShapeHoles[ mainIdx ] = [];
  23853. //console.log('cw', i);
  23854. } else {
  23855. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23856. //console.log('ccw', i);
  23857. }
  23858. }
  23859. // only Holes? -> probably all Shapes with wrong orientation
  23860. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23861. if ( newShapes.length > 1 ) {
  23862. var ambiguous = false;
  23863. var toChange = [];
  23864. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23865. betterShapeHoles[ sIdx ] = [];
  23866. }
  23867. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23868. var sho = newShapeHoles[ sIdx ];
  23869. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23870. var ho = sho[ hIdx ];
  23871. var hole_unassigned = true;
  23872. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23873. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23874. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23875. if ( hole_unassigned ) {
  23876. hole_unassigned = false;
  23877. betterShapeHoles[ s2Idx ].push( ho );
  23878. } else {
  23879. ambiguous = true;
  23880. }
  23881. }
  23882. }
  23883. if ( hole_unassigned ) {
  23884. betterShapeHoles[ sIdx ].push( ho );
  23885. }
  23886. }
  23887. }
  23888. // console.log("ambiguous: ", ambiguous);
  23889. if ( toChange.length > 0 ) {
  23890. // console.log("to change: ", toChange);
  23891. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23892. }
  23893. }
  23894. var tmpHoles;
  23895. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23896. tmpShape = newShapes[ i ].s;
  23897. shapes.push( tmpShape );
  23898. tmpHoles = newShapeHoles[ i ];
  23899. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23900. tmpShape.holes.push( tmpHoles[ j ].h );
  23901. }
  23902. }
  23903. //console.log("shape", shapes);
  23904. return shapes;
  23905. }
  23906. } );
  23907. /**
  23908. * @author zz85 / http://www.lab4games.net/zz85/blog
  23909. * @author mrdoob / http://mrdoob.com/
  23910. */
  23911. function Font( data ) {
  23912. this.type = 'Font';
  23913. this.data = data;
  23914. }
  23915. Object.assign( Font.prototype, {
  23916. isFont: true,
  23917. generateShapes: function ( text, size ) {
  23918. if ( size === undefined ) size = 100;
  23919. var shapes = [];
  23920. var paths = createPaths( text, size, this.data );
  23921. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23922. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23923. }
  23924. return shapes;
  23925. }
  23926. } );
  23927. function createPaths( text, size, data ) {
  23928. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23929. var scale = size / data.resolution;
  23930. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23931. var paths = [];
  23932. var offsetX = 0, offsetY = 0;
  23933. for ( var i = 0; i < chars.length; i ++ ) {
  23934. var char = chars[ i ];
  23935. if ( char === '\n' ) {
  23936. offsetX = 0;
  23937. offsetY -= line_height;
  23938. } else {
  23939. var ret = createPath( char, scale, offsetX, offsetY, data );
  23940. offsetX += ret.offsetX;
  23941. paths.push( ret.path );
  23942. }
  23943. }
  23944. return paths;
  23945. }
  23946. function createPath( char, scale, offsetX, offsetY, data ) {
  23947. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23948. if ( ! glyph ) {
  23949. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  23950. return;
  23951. }
  23952. var path = new ShapePath();
  23953. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23954. if ( glyph.o ) {
  23955. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23956. for ( var i = 0, l = outline.length; i < l; ) {
  23957. var action = outline[ i ++ ];
  23958. switch ( action ) {
  23959. case 'm': // moveTo
  23960. x = outline[ i ++ ] * scale + offsetX;
  23961. y = outline[ i ++ ] * scale + offsetY;
  23962. path.moveTo( x, y );
  23963. break;
  23964. case 'l': // lineTo
  23965. x = outline[ i ++ ] * scale + offsetX;
  23966. y = outline[ i ++ ] * scale + offsetY;
  23967. path.lineTo( x, y );
  23968. break;
  23969. case 'q': // quadraticCurveTo
  23970. cpx = outline[ i ++ ] * scale + offsetX;
  23971. cpy = outline[ i ++ ] * scale + offsetY;
  23972. cpx1 = outline[ i ++ ] * scale + offsetX;
  23973. cpy1 = outline[ i ++ ] * scale + offsetY;
  23974. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23975. break;
  23976. case 'b': // bezierCurveTo
  23977. cpx = outline[ i ++ ] * scale + offsetX;
  23978. cpy = outline[ i ++ ] * scale + offsetY;
  23979. cpx1 = outline[ i ++ ] * scale + offsetX;
  23980. cpy1 = outline[ i ++ ] * scale + offsetY;
  23981. cpx2 = outline[ i ++ ] * scale + offsetX;
  23982. cpy2 = outline[ i ++ ] * scale + offsetY;
  23983. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23984. break;
  23985. }
  23986. }
  23987. }
  23988. return { offsetX: glyph.ha * scale, path: path };
  23989. }
  23990. /**
  23991. * @author mrdoob / http://mrdoob.com/
  23992. */
  23993. function FontLoader( manager ) {
  23994. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23995. }
  23996. Object.assign( FontLoader.prototype, {
  23997. load: function ( url, onLoad, onProgress, onError ) {
  23998. var scope = this;
  23999. var loader = new FileLoader( this.manager );
  24000. loader.setPath( this.path );
  24001. loader.load( url, function ( text ) {
  24002. var json;
  24003. try {
  24004. json = JSON.parse( text );
  24005. } catch ( e ) {
  24006. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  24007. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  24008. }
  24009. var font = scope.parse( json );
  24010. if ( onLoad ) onLoad( font );
  24011. }, onProgress, onError );
  24012. },
  24013. parse: function ( json ) {
  24014. return new Font( json );
  24015. },
  24016. setPath: function ( value ) {
  24017. this.path = value;
  24018. return this;
  24019. }
  24020. } );
  24021. /**
  24022. * @author alteredq / http://alteredqualia.com/
  24023. */
  24024. var _BlendingMode, _color, _textureLoader, _materialLoader;
  24025. function Loader() {}
  24026. Loader.Handlers = {
  24027. handlers: [],
  24028. add: function ( regex, loader ) {
  24029. this.handlers.push( regex, loader );
  24030. },
  24031. get: function ( file ) {
  24032. var handlers = this.handlers;
  24033. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  24034. var regex = handlers[ i ];
  24035. var loader = handlers[ i + 1 ];
  24036. if ( regex.test( file ) ) {
  24037. return loader;
  24038. }
  24039. }
  24040. return null;
  24041. }
  24042. };
  24043. Object.assign( Loader.prototype, {
  24044. crossOrigin: 'anonymous',
  24045. onLoadStart: function () {},
  24046. onLoadProgress: function () {},
  24047. onLoadComplete: function () {},
  24048. initMaterials: function ( materials, texturePath, crossOrigin ) {
  24049. var array = [];
  24050. for ( var i = 0; i < materials.length; ++ i ) {
  24051. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  24052. }
  24053. return array;
  24054. },
  24055. createMaterial: function ( m, texturePath, crossOrigin ) {
  24056. if ( _materialLoader === undefined ) {
  24057. _BlendingMode = {
  24058. NoBlending: NoBlending,
  24059. NormalBlending: NormalBlending,
  24060. AdditiveBlending: AdditiveBlending,
  24061. SubtractiveBlending: SubtractiveBlending,
  24062. MultiplyBlending: MultiplyBlending,
  24063. CustomBlending: CustomBlending
  24064. };
  24065. _color = new Color();
  24066. _textureLoader = new TextureLoader();
  24067. _materialLoader = new MaterialLoader();
  24068. }
  24069. // convert from old material format
  24070. var textures = {};
  24071. //
  24072. var json = {
  24073. uuid: _Math.generateUUID(),
  24074. type: 'MeshLambertMaterial'
  24075. };
  24076. for ( var name in m ) {
  24077. var value = m[ name ];
  24078. switch ( name ) {
  24079. case 'DbgColor':
  24080. case 'DbgIndex':
  24081. case 'opticalDensity':
  24082. case 'illumination':
  24083. break;
  24084. case 'DbgName':
  24085. json.name = value;
  24086. break;
  24087. case 'blending':
  24088. json.blending = _BlendingMode[ value ];
  24089. break;
  24090. case 'colorAmbient':
  24091. case 'mapAmbient':
  24092. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  24093. break;
  24094. case 'colorDiffuse':
  24095. json.color = _color.fromArray( value ).getHex();
  24096. break;
  24097. case 'colorSpecular':
  24098. json.specular = _color.fromArray( value ).getHex();
  24099. break;
  24100. case 'colorEmissive':
  24101. json.emissive = _color.fromArray( value ).getHex();
  24102. break;
  24103. case 'specularCoef':
  24104. json.shininess = value;
  24105. break;
  24106. case 'shading':
  24107. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  24108. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  24109. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  24110. break;
  24111. case 'mapDiffuse':
  24112. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy, textures, texturePath, crossOrigin );
  24113. break;
  24114. case 'mapDiffuseRepeat':
  24115. case 'mapDiffuseOffset':
  24116. case 'mapDiffuseWrap':
  24117. case 'mapDiffuseAnisotropy':
  24118. break;
  24119. case 'mapEmissive':
  24120. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy, textures, texturePath, crossOrigin );
  24121. break;
  24122. case 'mapEmissiveRepeat':
  24123. case 'mapEmissiveOffset':
  24124. case 'mapEmissiveWrap':
  24125. case 'mapEmissiveAnisotropy':
  24126. break;
  24127. case 'mapLight':
  24128. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy, textures, texturePath, crossOrigin );
  24129. break;
  24130. case 'mapLightRepeat':
  24131. case 'mapLightOffset':
  24132. case 'mapLightWrap':
  24133. case 'mapLightAnisotropy':
  24134. break;
  24135. case 'mapAO':
  24136. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy, textures, texturePath, crossOrigin );
  24137. break;
  24138. case 'mapAORepeat':
  24139. case 'mapAOOffset':
  24140. case 'mapAOWrap':
  24141. case 'mapAOAnisotropy':
  24142. break;
  24143. case 'mapBump':
  24144. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy, textures, texturePath, crossOrigin );
  24145. break;
  24146. case 'mapBumpScale':
  24147. json.bumpScale = value;
  24148. break;
  24149. case 'mapBumpRepeat':
  24150. case 'mapBumpOffset':
  24151. case 'mapBumpWrap':
  24152. case 'mapBumpAnisotropy':
  24153. break;
  24154. case 'mapNormal':
  24155. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy, textures, texturePath, crossOrigin );
  24156. break;
  24157. case 'mapNormalFactor':
  24158. json.normalScale = value;
  24159. break;
  24160. case 'mapNormalRepeat':
  24161. case 'mapNormalOffset':
  24162. case 'mapNormalWrap':
  24163. case 'mapNormalAnisotropy':
  24164. break;
  24165. case 'mapSpecular':
  24166. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy, textures, texturePath, crossOrigin );
  24167. break;
  24168. case 'mapSpecularRepeat':
  24169. case 'mapSpecularOffset':
  24170. case 'mapSpecularWrap':
  24171. case 'mapSpecularAnisotropy':
  24172. break;
  24173. case 'mapMetalness':
  24174. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy, textures, texturePath, crossOrigin );
  24175. break;
  24176. case 'mapMetalnessRepeat':
  24177. case 'mapMetalnessOffset':
  24178. case 'mapMetalnessWrap':
  24179. case 'mapMetalnessAnisotropy':
  24180. break;
  24181. case 'mapRoughness':
  24182. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy, textures, texturePath, crossOrigin );
  24183. break;
  24184. case 'mapRoughnessRepeat':
  24185. case 'mapRoughnessOffset':
  24186. case 'mapRoughnessWrap':
  24187. case 'mapRoughnessAnisotropy':
  24188. break;
  24189. case 'mapAlpha':
  24190. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy, textures, texturePath, crossOrigin );
  24191. break;
  24192. case 'mapAlphaRepeat':
  24193. case 'mapAlphaOffset':
  24194. case 'mapAlphaWrap':
  24195. case 'mapAlphaAnisotropy':
  24196. break;
  24197. case 'flipSided':
  24198. json.side = BackSide;
  24199. break;
  24200. case 'doubleSided':
  24201. json.side = DoubleSide;
  24202. break;
  24203. case 'transparency':
  24204. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  24205. json.opacity = value;
  24206. break;
  24207. case 'depthTest':
  24208. case 'depthWrite':
  24209. case 'colorWrite':
  24210. case 'opacity':
  24211. case 'reflectivity':
  24212. case 'transparent':
  24213. case 'visible':
  24214. case 'wireframe':
  24215. json[ name ] = value;
  24216. break;
  24217. case 'vertexColors':
  24218. if ( value === true ) json.vertexColors = VertexColors;
  24219. if ( value === 'face' ) json.vertexColors = FaceColors;
  24220. break;
  24221. default:
  24222. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  24223. break;
  24224. }
  24225. }
  24226. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  24227. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  24228. if ( json.opacity < 1 ) json.transparent = true;
  24229. _materialLoader.setTextures( textures );
  24230. return _materialLoader.parse( json );
  24231. }
  24232. } );
  24233. function loadTexture( path, repeat, offset, wrap, anisotropy, textures, texturePath, crossOrigin ) {
  24234. var fullPath = texturePath + path;
  24235. var loader = Loader.Handlers.get( fullPath );
  24236. var texture;
  24237. if ( loader !== null ) {
  24238. texture = loader.load( fullPath );
  24239. } else {
  24240. _textureLoader.setCrossOrigin( crossOrigin );
  24241. texture = _textureLoader.load( fullPath );
  24242. }
  24243. if ( repeat !== undefined ) {
  24244. texture.repeat.fromArray( repeat );
  24245. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  24246. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  24247. }
  24248. if ( offset !== undefined ) {
  24249. texture.offset.fromArray( offset );
  24250. }
  24251. if ( wrap !== undefined ) {
  24252. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  24253. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  24254. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  24255. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  24256. }
  24257. if ( anisotropy !== undefined ) {
  24258. texture.anisotropy = anisotropy;
  24259. }
  24260. var uuid = _Math.generateUUID();
  24261. textures[ uuid ] = texture;
  24262. return uuid;
  24263. }
  24264. /**
  24265. * @author mrdoob / http://mrdoob.com/
  24266. */
  24267. var _context;
  24268. var AudioContext = {
  24269. getContext: function () {
  24270. if ( _context === undefined ) {
  24271. _context = new ( window.AudioContext || window.webkitAudioContext )();
  24272. }
  24273. return _context;
  24274. },
  24275. setContext: function ( value ) {
  24276. _context = value;
  24277. }
  24278. };
  24279. /**
  24280. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24281. */
  24282. function AudioLoader( manager ) {
  24283. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  24284. }
  24285. Object.assign( AudioLoader.prototype, {
  24286. load: function ( url, onLoad, onProgress, onError ) {
  24287. var loader = new FileLoader( this.manager );
  24288. loader.setResponseType( 'arraybuffer' );
  24289. loader.setPath( this.path );
  24290. loader.load( url, function ( buffer ) {
  24291. // Create a copy of the buffer. The `decodeAudioData` method
  24292. // detaches the buffer when complete, preventing reuse.
  24293. var bufferCopy = buffer.slice( 0 );
  24294. var context = AudioContext.getContext();
  24295. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  24296. onLoad( audioBuffer );
  24297. } );
  24298. }, onProgress, onError );
  24299. },
  24300. setPath: function ( value ) {
  24301. this.path = value;
  24302. return this;
  24303. }
  24304. } );
  24305. /**
  24306. * @author bhouston / http://clara.io
  24307. * @author WestLangley / http://github.com/WestLangley
  24308. *
  24309. * Primary reference:
  24310. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24311. *
  24312. * Secondary reference:
  24313. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24314. */
  24315. // 3-band SH defined by 9 coefficients
  24316. function SphericalHarmonics3() {
  24317. this.coefficients = [];
  24318. for ( var i = 0; i < 9; i ++ ) {
  24319. this.coefficients.push( new Vector3() );
  24320. }
  24321. }
  24322. Object.assign( SphericalHarmonics3.prototype, {
  24323. isSphericalHarmonics3: true,
  24324. set: function ( coefficients ) {
  24325. for ( var i = 0; i < 9; i ++ ) {
  24326. this.coefficients[ i ].copy( coefficients[ i ] );
  24327. }
  24328. return this;
  24329. },
  24330. zero: function () {
  24331. for ( var i = 0; i < 9; i ++ ) {
  24332. this.coefficients[ i ].set( 0, 0, 0 );
  24333. }
  24334. return this;
  24335. },
  24336. // get the radiance in the direction of the normal
  24337. // target is a Vector3
  24338. getAt: function ( normal, target ) {
  24339. // normal is assumed to be unit length
  24340. var x = normal.x, y = normal.y, z = normal.z;
  24341. var coeff = this.coefficients;
  24342. // band 0
  24343. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  24344. // band 1
  24345. target.addScale( coeff[ 1 ], 0.488603 * y );
  24346. target.addScale( coeff[ 2 ], 0.488603 * z );
  24347. target.addScale( coeff[ 3 ], 0.488603 * x );
  24348. // band 2
  24349. target.addScale( coeff[ 4 ], 1.092548 * ( x * y ) );
  24350. target.addScale( coeff[ 5 ], 1.092548 * ( y * z ) );
  24351. target.addScale( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  24352. target.addScale( coeff[ 7 ], 1.092548 * ( x * z ) );
  24353. target.addScale( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  24354. return target;
  24355. },
  24356. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24357. // target is a Vector3
  24358. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24359. getIrradianceAt: 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.886227 ); // π * 0.282095
  24365. // band 1
  24366. target.addScale( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  24367. target.addScale( coeff[ 2 ], 2.0 * 0.511664 * z );
  24368. target.addScale( coeff[ 3 ], 2.0 * 0.511664 * x );
  24369. // band 2
  24370. target.addScale( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  24371. target.addScale( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  24372. target.addScale( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24373. target.addScale( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  24374. target.addScale( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  24375. return target;
  24376. },
  24377. add: function ( sh ) {
  24378. for ( var i = 0; i < 9; i ++ ) {
  24379. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24380. }
  24381. return this;
  24382. },
  24383. scale: function ( s ) {
  24384. for ( var i = 0; i < 9; i ++ ) {
  24385. this.coefficients[ i ].multiplyScalar( s );
  24386. }
  24387. return this;
  24388. },
  24389. lerp: function ( sh, alpha ) {
  24390. for ( var i = 0; i < 9; i ++ ) {
  24391. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24392. }
  24393. return this;
  24394. },
  24395. equals: function ( sh ) {
  24396. for ( var i = 0; i < 9; i ++ ) {
  24397. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24398. return false;
  24399. }
  24400. }
  24401. return true;
  24402. },
  24403. copy: function ( sh ) {
  24404. return this.set( sh.coefficients );
  24405. },
  24406. clone: function () {
  24407. return new this.constructor().copy( this );
  24408. },
  24409. fromArray: function ( array ) {
  24410. var coefficients = this.coefficients;
  24411. for ( var i = 0; i < 9; i ++ ) {
  24412. coefficients[ i ].fromArray( array, i * 3 );
  24413. }
  24414. return this;
  24415. },
  24416. toArray: function () {
  24417. var array = [];
  24418. var coefficients = this.coefficients;
  24419. for ( var i = 0; i < 9; i ++ ) {
  24420. coefficients[ i ].toArray( array, i * 3 );
  24421. }
  24422. return array;
  24423. }
  24424. } );
  24425. Object.assign( SphericalHarmonics3, {
  24426. // evaluate the basis functions
  24427. // shBasis is an Array[ 9 ]
  24428. getBasisAt: function ( normal, shBasis ) {
  24429. // normal is assumed to be unit length
  24430. var x = normal.x, y = normal.y, z = normal.z;
  24431. // band 0
  24432. shBasis[ 0 ] = 0.282095;
  24433. // band 1
  24434. shBasis[ 1 ] = 0.488603 * y;
  24435. shBasis[ 2 ] = 0.488603 * z;
  24436. shBasis[ 3 ] = 0.488603 * x;
  24437. // band 2
  24438. shBasis[ 4 ] = 1.092548 * x * y;
  24439. shBasis[ 5 ] = 1.092548 * y * z;
  24440. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24441. shBasis[ 7 ] = 1.092548 * x * z;
  24442. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24443. }
  24444. } );
  24445. /**
  24446. * @author WestLangley / http://github.com/WestLangley
  24447. *
  24448. * A LightProbe is a source of indirect-diffuse light
  24449. */
  24450. function LightProbe( sh, intensity ) {
  24451. Light.call( this, undefined, intensity );
  24452. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24453. }
  24454. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24455. constructor: LightProbe,
  24456. isLightProbe: true,
  24457. copy: function ( source ) {
  24458. Light.prototype.copy.call( this, source );
  24459. this.sh.copy( source.sh );
  24460. this.intensity = source.intensity;
  24461. return this;
  24462. },
  24463. toJSON: function ( meta ) {
  24464. var data = Light.prototype.toJSON.call( this, meta );
  24465. // data.sh = this.sh.toArray(); // todo
  24466. return data;
  24467. }
  24468. } );
  24469. /**
  24470. * @author WestLangley / http://github.com/WestLangley
  24471. */
  24472. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24473. LightProbe.call( this, undefined, intensity );
  24474. var color1 = new Color().set( skyColor );
  24475. var color2 = new Color().set( groundColor );
  24476. var sky = new Vector3( color1.r, color1.g, color1.b );
  24477. var ground = new Vector3( color2.r, color2.g, color2.b );
  24478. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24479. var c0 = Math.sqrt( Math.PI );
  24480. var c1 = c0 * Math.sqrt( 0.75 );
  24481. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24482. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24483. }
  24484. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24485. constructor: HemisphereLightProbe,
  24486. isHemisphereLightProbe: true,
  24487. copy: function ( source ) { // modifying colors not currently supported
  24488. LightProbe.prototype.copy.call( this, source );
  24489. return this;
  24490. },
  24491. toJSON: function ( meta ) {
  24492. var data = LightProbe.prototype.toJSON.call( this, meta );
  24493. // data.sh = this.sh.toArray(); // todo
  24494. return data;
  24495. }
  24496. } );
  24497. /**
  24498. * @author WestLangley / http://github.com/WestLangley
  24499. */
  24500. function AmbientLightProbe( color, intensity ) {
  24501. LightProbe.call( this, undefined, intensity );
  24502. var color1 = new Color().set( color );
  24503. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24504. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24505. }
  24506. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24507. constructor: AmbientLightProbe,
  24508. isAmbientLightProbe: true,
  24509. copy: function ( source ) { // modifying color not currently supported
  24510. LightProbe.prototype.copy.call( this, source );
  24511. return this;
  24512. },
  24513. toJSON: function ( meta ) {
  24514. var data = LightProbe.prototype.toJSON.call( this, meta );
  24515. // data.sh = this.sh.toArray(); // todo
  24516. return data;
  24517. }
  24518. } );
  24519. var _eyeRight, _eyeLeft;
  24520. /**
  24521. * @author mrdoob / http://mrdoob.com/
  24522. */
  24523. function StereoCamera() {
  24524. this.type = 'StereoCamera';
  24525. this.aspect = 1;
  24526. this.eyeSep = 0.064;
  24527. this.cameraL = new PerspectiveCamera();
  24528. this.cameraL.layers.enable( 1 );
  24529. this.cameraL.matrixAutoUpdate = false;
  24530. this.cameraR = new PerspectiveCamera();
  24531. this.cameraR.layers.enable( 2 );
  24532. this.cameraR.matrixAutoUpdate = false;
  24533. this._cache = {
  24534. focus: null,
  24535. fov: null,
  24536. aspect: null,
  24537. near: null,
  24538. far: null,
  24539. zoom: null,
  24540. eyeSep: null
  24541. };
  24542. }
  24543. Object.assign( StereoCamera.prototype, {
  24544. update: function ( camera ) {
  24545. if ( _eyeRight === undefined ) {
  24546. _eyeRight = new Matrix4();
  24547. _eyeLeft = new Matrix4();
  24548. }
  24549. var cache = this._cache;
  24550. var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  24551. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  24552. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  24553. if ( needsUpdate ) {
  24554. cache.focus = camera.focus;
  24555. cache.fov = camera.fov;
  24556. cache.aspect = camera.aspect * this.aspect;
  24557. cache.near = camera.near;
  24558. cache.far = camera.far;
  24559. cache.zoom = camera.zoom;
  24560. cache.eyeSep = this.eyeSep;
  24561. // Off-axis stereoscopic effect based on
  24562. // http://paulbourke.net/stereographics/stereorender/
  24563. var projectionMatrix = camera.projectionMatrix.clone();
  24564. var eyeSepHalf = cache.eyeSep / 2;
  24565. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  24566. var ymax = ( cache.near * Math.tan( _Math.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  24567. var xmin, xmax;
  24568. // translate xOffset
  24569. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  24570. _eyeRight.elements[ 12 ] = eyeSepHalf;
  24571. // for left eye
  24572. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  24573. xmax = ymax * cache.aspect + eyeSepOnProjection;
  24574. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24575. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24576. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24577. // for right eye
  24578. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  24579. xmax = ymax * cache.aspect - eyeSepOnProjection;
  24580. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24581. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24582. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24583. }
  24584. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  24585. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  24586. }
  24587. } );
  24588. /**
  24589. * @author alteredq / http://alteredqualia.com/
  24590. */
  24591. function Clock( autoStart ) {
  24592. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24593. this.startTime = 0;
  24594. this.oldTime = 0;
  24595. this.elapsedTime = 0;
  24596. this.running = false;
  24597. }
  24598. Object.assign( Clock.prototype, {
  24599. start: function () {
  24600. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24601. this.oldTime = this.startTime;
  24602. this.elapsedTime = 0;
  24603. this.running = true;
  24604. },
  24605. stop: function () {
  24606. this.getElapsedTime();
  24607. this.running = false;
  24608. this.autoStart = false;
  24609. },
  24610. getElapsedTime: function () {
  24611. this.getDelta();
  24612. return this.elapsedTime;
  24613. },
  24614. getDelta: function () {
  24615. var diff = 0;
  24616. if ( this.autoStart && ! this.running ) {
  24617. this.start();
  24618. return 0;
  24619. }
  24620. if ( this.running ) {
  24621. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24622. diff = ( newTime - this.oldTime ) / 1000;
  24623. this.oldTime = newTime;
  24624. this.elapsedTime += diff;
  24625. }
  24626. return diff;
  24627. }
  24628. } );
  24629. /**
  24630. * @author mrdoob / http://mrdoob.com/
  24631. */
  24632. var _position$1, _quaternion$3, _scale$1;
  24633. var _orientation;
  24634. function AudioListener() {
  24635. Object3D.call( this );
  24636. this.type = 'AudioListener';
  24637. this.context = AudioContext.getContext();
  24638. this.gain = this.context.createGain();
  24639. this.gain.connect( this.context.destination );
  24640. this.filter = null;
  24641. this.timeDelta = 0;
  24642. // private
  24643. this._clock = new Clock();
  24644. }
  24645. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24646. constructor: AudioListener,
  24647. getInput: function () {
  24648. return this.gain;
  24649. },
  24650. removeFilter: function ( ) {
  24651. if ( this.filter !== null ) {
  24652. this.gain.disconnect( this.filter );
  24653. this.filter.disconnect( this.context.destination );
  24654. this.gain.connect( this.context.destination );
  24655. this.filter = null;
  24656. }
  24657. return this;
  24658. },
  24659. getFilter: function () {
  24660. return this.filter;
  24661. },
  24662. setFilter: function ( value ) {
  24663. if ( this.filter !== null ) {
  24664. this.gain.disconnect( this.filter );
  24665. this.filter.disconnect( this.context.destination );
  24666. } else {
  24667. this.gain.disconnect( this.context.destination );
  24668. }
  24669. this.filter = value;
  24670. this.gain.connect( this.filter );
  24671. this.filter.connect( this.context.destination );
  24672. return this;
  24673. },
  24674. getMasterVolume: function () {
  24675. return this.gain.gain.value;
  24676. },
  24677. setMasterVolume: function ( value ) {
  24678. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24679. return this;
  24680. },
  24681. updateMatrixWorld: function ( force ) {
  24682. Object3D.prototype.updateMatrixWorld.call( this, force );
  24683. if ( _position$1 === undefined ) {
  24684. _position$1 = new Vector3();
  24685. _quaternion$3 = new Quaternion();
  24686. _scale$1 = new Vector3();
  24687. _orientation = new Vector3();
  24688. }
  24689. var listener = this.context.listener;
  24690. var up = this.up;
  24691. this.timeDelta = this._clock.getDelta();
  24692. this.matrixWorld.decompose( _position$1, _quaternion$3, _scale$1 );
  24693. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  24694. if ( listener.positionX ) {
  24695. // code path for Chrome (see #14393)
  24696. var endTime = this.context.currentTime + this.timeDelta;
  24697. listener.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  24698. listener.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  24699. listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  24700. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  24701. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  24702. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  24703. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24704. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24705. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24706. } else {
  24707. listener.setPosition( _position$1.x, _position$1.y, _position$1.z );
  24708. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  24709. }
  24710. }
  24711. } );
  24712. /**
  24713. * @author mrdoob / http://mrdoob.com/
  24714. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24715. */
  24716. function Audio( listener ) {
  24717. Object3D.call( this );
  24718. this.type = 'Audio';
  24719. this.listener = listener;
  24720. this.context = listener.context;
  24721. this.gain = this.context.createGain();
  24722. this.gain.connect( listener.getInput() );
  24723. this.autoplay = false;
  24724. this.buffer = null;
  24725. this.detune = 0;
  24726. this.loop = false;
  24727. this.startTime = 0;
  24728. this.offset = 0;
  24729. this.playbackRate = 1;
  24730. this.isPlaying = false;
  24731. this.hasPlaybackControl = true;
  24732. this.sourceType = 'empty';
  24733. this.filters = [];
  24734. }
  24735. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24736. constructor: Audio,
  24737. getOutput: function () {
  24738. return this.gain;
  24739. },
  24740. setNodeSource: function ( audioNode ) {
  24741. this.hasPlaybackControl = false;
  24742. this.sourceType = 'audioNode';
  24743. this.source = audioNode;
  24744. this.connect();
  24745. return this;
  24746. },
  24747. setMediaElementSource: function ( mediaElement ) {
  24748. this.hasPlaybackControl = false;
  24749. this.sourceType = 'mediaNode';
  24750. this.source = this.context.createMediaElementSource( mediaElement );
  24751. this.connect();
  24752. return this;
  24753. },
  24754. setBuffer: function ( audioBuffer ) {
  24755. this.buffer = audioBuffer;
  24756. this.sourceType = 'buffer';
  24757. if ( this.autoplay ) this.play();
  24758. return this;
  24759. },
  24760. play: function () {
  24761. if ( this.isPlaying === true ) {
  24762. console.warn( 'THREE.Audio: Audio is already playing.' );
  24763. return;
  24764. }
  24765. if ( this.hasPlaybackControl === false ) {
  24766. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24767. return;
  24768. }
  24769. var source = this.context.createBufferSource();
  24770. source.buffer = this.buffer;
  24771. source.loop = this.loop;
  24772. source.onended = this.onEnded.bind( this );
  24773. this.startTime = this.context.currentTime;
  24774. source.start( this.startTime, this.offset );
  24775. this.isPlaying = true;
  24776. this.source = source;
  24777. this.setDetune( this.detune );
  24778. this.setPlaybackRate( this.playbackRate );
  24779. return this.connect();
  24780. },
  24781. pause: function () {
  24782. if ( this.hasPlaybackControl === false ) {
  24783. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24784. return;
  24785. }
  24786. if ( this.isPlaying === true ) {
  24787. this.source.stop();
  24788. this.source.onended = null;
  24789. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24790. this.isPlaying = false;
  24791. }
  24792. return this;
  24793. },
  24794. stop: function () {
  24795. if ( this.hasPlaybackControl === false ) {
  24796. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24797. return;
  24798. }
  24799. this.source.stop();
  24800. this.source.onended = null;
  24801. this.offset = 0;
  24802. this.isPlaying = false;
  24803. return this;
  24804. },
  24805. connect: function () {
  24806. if ( this.filters.length > 0 ) {
  24807. this.source.connect( this.filters[ 0 ] );
  24808. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24809. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24810. }
  24811. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24812. } else {
  24813. this.source.connect( this.getOutput() );
  24814. }
  24815. return this;
  24816. },
  24817. disconnect: function () {
  24818. if ( this.filters.length > 0 ) {
  24819. this.source.disconnect( this.filters[ 0 ] );
  24820. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24821. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24822. }
  24823. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24824. } else {
  24825. this.source.disconnect( this.getOutput() );
  24826. }
  24827. return this;
  24828. },
  24829. getFilters: function () {
  24830. return this.filters;
  24831. },
  24832. setFilters: function ( value ) {
  24833. if ( ! value ) value = [];
  24834. if ( this.isPlaying === true ) {
  24835. this.disconnect();
  24836. this.filters = value;
  24837. this.connect();
  24838. } else {
  24839. this.filters = value;
  24840. }
  24841. return this;
  24842. },
  24843. setDetune: function ( value ) {
  24844. this.detune = value;
  24845. if ( this.source.detune === undefined ) return; // only set detune when available
  24846. if ( this.isPlaying === true ) {
  24847. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24848. }
  24849. return this;
  24850. },
  24851. getDetune: function () {
  24852. return this.detune;
  24853. },
  24854. getFilter: function () {
  24855. return this.getFilters()[ 0 ];
  24856. },
  24857. setFilter: function ( filter ) {
  24858. return this.setFilters( filter ? [ filter ] : [] );
  24859. },
  24860. setPlaybackRate: function ( value ) {
  24861. if ( this.hasPlaybackControl === false ) {
  24862. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24863. return;
  24864. }
  24865. this.playbackRate = value;
  24866. if ( this.isPlaying === true ) {
  24867. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24868. }
  24869. return this;
  24870. },
  24871. getPlaybackRate: function () {
  24872. return this.playbackRate;
  24873. },
  24874. onEnded: function () {
  24875. this.isPlaying = false;
  24876. },
  24877. getLoop: function () {
  24878. if ( this.hasPlaybackControl === false ) {
  24879. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24880. return false;
  24881. }
  24882. return this.loop;
  24883. },
  24884. setLoop: function ( value ) {
  24885. if ( this.hasPlaybackControl === false ) {
  24886. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24887. return;
  24888. }
  24889. this.loop = value;
  24890. if ( this.isPlaying === true ) {
  24891. this.source.loop = this.loop;
  24892. }
  24893. return this;
  24894. },
  24895. getVolume: function () {
  24896. return this.gain.gain.value;
  24897. },
  24898. setVolume: function ( value ) {
  24899. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24900. return this;
  24901. }
  24902. } );
  24903. /**
  24904. * @author mrdoob / http://mrdoob.com/
  24905. */
  24906. var _position$2, _quaternion$4, _scale$2;
  24907. var _orientation$1;
  24908. function PositionalAudio( listener ) {
  24909. Audio.call( this, listener );
  24910. this.panner = this.context.createPanner();
  24911. this.panner.panningModel = 'HRTF';
  24912. this.panner.connect( this.gain );
  24913. }
  24914. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24915. constructor: PositionalAudio,
  24916. getOutput: function () {
  24917. return this.panner;
  24918. },
  24919. getRefDistance: function () {
  24920. return this.panner.refDistance;
  24921. },
  24922. setRefDistance: function ( value ) {
  24923. this.panner.refDistance = value;
  24924. return this;
  24925. },
  24926. getRolloffFactor: function () {
  24927. return this.panner.rolloffFactor;
  24928. },
  24929. setRolloffFactor: function ( value ) {
  24930. this.panner.rolloffFactor = value;
  24931. return this;
  24932. },
  24933. getDistanceModel: function () {
  24934. return this.panner.distanceModel;
  24935. },
  24936. setDistanceModel: function ( value ) {
  24937. this.panner.distanceModel = value;
  24938. return this;
  24939. },
  24940. getMaxDistance: function () {
  24941. return this.panner.maxDistance;
  24942. },
  24943. setMaxDistance: function ( value ) {
  24944. this.panner.maxDistance = value;
  24945. return this;
  24946. },
  24947. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24948. this.panner.coneInnerAngle = coneInnerAngle;
  24949. this.panner.coneOuterAngle = coneOuterAngle;
  24950. this.panner.coneOuterGain = coneOuterGain;
  24951. return this;
  24952. },
  24953. updateMatrixWorld: function ( force ) {
  24954. Object3D.prototype.updateMatrixWorld.call( this, force );
  24955. if ( _position$2 === undefined ) {
  24956. _position$2 = new Vector3();
  24957. _quaternion$4 = new Quaternion();
  24958. _scale$2 = new Vector3();
  24959. _orientation$1 = new Vector3();
  24960. }
  24961. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24962. this.matrixWorld.decompose( _position$2, _quaternion$4, _scale$2 );
  24963. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  24964. var panner = this.panner;
  24965. if ( panner.positionX ) {
  24966. // code path for Chrome and Firefox (see #14393)
  24967. var endTime = this.context.currentTime + this.listener.timeDelta;
  24968. panner.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  24969. panner.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  24970. panner.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  24971. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  24972. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  24973. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  24974. } else {
  24975. panner.setPosition( _position$2.x, _position$2.y, _position$2.z );
  24976. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  24977. }
  24978. }
  24979. } );
  24980. /**
  24981. * @author mrdoob / http://mrdoob.com/
  24982. */
  24983. function AudioAnalyser( audio, fftSize ) {
  24984. this.analyser = audio.context.createAnalyser();
  24985. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24986. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24987. audio.getOutput().connect( this.analyser );
  24988. }
  24989. Object.assign( AudioAnalyser.prototype, {
  24990. getFrequencyData: function () {
  24991. this.analyser.getByteFrequencyData( this.data );
  24992. return this.data;
  24993. },
  24994. getAverageFrequency: function () {
  24995. var value = 0, data = this.getFrequencyData();
  24996. for ( var i = 0; i < data.length; i ++ ) {
  24997. value += data[ i ];
  24998. }
  24999. return value / data.length;
  25000. }
  25001. } );
  25002. /**
  25003. *
  25004. * Buffered scene graph property that allows weighted accumulation.
  25005. *
  25006. *
  25007. * @author Ben Houston / http://clara.io/
  25008. * @author David Sarno / http://lighthaus.us/
  25009. * @author tschw
  25010. */
  25011. function PropertyMixer( binding, typeName, valueSize ) {
  25012. this.binding = binding;
  25013. this.valueSize = valueSize;
  25014. var bufferType = Float64Array,
  25015. mixFunction;
  25016. switch ( typeName ) {
  25017. case 'quaternion':
  25018. mixFunction = this._slerp;
  25019. break;
  25020. case 'string':
  25021. case 'bool':
  25022. bufferType = Array;
  25023. mixFunction = this._select;
  25024. break;
  25025. default:
  25026. mixFunction = this._lerp;
  25027. }
  25028. this.buffer = new bufferType( valueSize * 4 );
  25029. // layout: [ incoming | accu0 | accu1 | orig ]
  25030. //
  25031. // interpolators can use .buffer as their .result
  25032. // the data then goes to 'incoming'
  25033. //
  25034. // 'accu0' and 'accu1' are used frame-interleaved for
  25035. // the cumulative result and are compared to detect
  25036. // changes
  25037. //
  25038. // 'orig' stores the original state of the property
  25039. this._mixBufferRegion = mixFunction;
  25040. this.cumulativeWeight = 0;
  25041. this.useCount = 0;
  25042. this.referenceCount = 0;
  25043. }
  25044. Object.assign( PropertyMixer.prototype, {
  25045. // accumulate data in the 'incoming' region into 'accu<i>'
  25046. accumulate: function ( accuIndex, weight ) {
  25047. // note: happily accumulating nothing when weight = 0, the caller knows
  25048. // the weight and shouldn't have made the call in the first place
  25049. var buffer = this.buffer,
  25050. stride = this.valueSize,
  25051. offset = accuIndex * stride + stride,
  25052. currentWeight = this.cumulativeWeight;
  25053. if ( currentWeight === 0 ) {
  25054. // accuN := incoming * weight
  25055. for ( var i = 0; i !== stride; ++ i ) {
  25056. buffer[ offset + i ] = buffer[ i ];
  25057. }
  25058. currentWeight = weight;
  25059. } else {
  25060. // accuN := accuN + incoming * weight
  25061. currentWeight += weight;
  25062. var mix = weight / currentWeight;
  25063. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25064. }
  25065. this.cumulativeWeight = currentWeight;
  25066. },
  25067. // apply the state of 'accu<i>' to the binding when accus differ
  25068. apply: function ( accuIndex ) {
  25069. var stride = this.valueSize,
  25070. buffer = this.buffer,
  25071. offset = accuIndex * stride + stride,
  25072. weight = this.cumulativeWeight,
  25073. binding = this.binding;
  25074. this.cumulativeWeight = 0;
  25075. if ( weight < 1 ) {
  25076. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25077. var originalValueOffset = stride * 3;
  25078. this._mixBufferRegion(
  25079. buffer, offset, originalValueOffset, 1 - weight, stride );
  25080. }
  25081. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  25082. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25083. // value has changed -> update scene graph
  25084. binding.setValue( buffer, offset );
  25085. break;
  25086. }
  25087. }
  25088. },
  25089. // remember the state of the bound property and copy it to both accus
  25090. saveOriginalState: function () {
  25091. var binding = this.binding;
  25092. var buffer = this.buffer,
  25093. stride = this.valueSize,
  25094. originalValueOffset = stride * 3;
  25095. binding.getValue( buffer, originalValueOffset );
  25096. // accu[0..1] := orig -- initially detect changes against the original
  25097. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25098. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25099. }
  25100. this.cumulativeWeight = 0;
  25101. },
  25102. // apply the state previously taken via 'saveOriginalState' to the binding
  25103. restoreOriginalState: function () {
  25104. var originalValueOffset = this.valueSize * 3;
  25105. this.binding.setValue( this.buffer, originalValueOffset );
  25106. },
  25107. // mix functions
  25108. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25109. if ( t >= 0.5 ) {
  25110. for ( var i = 0; i !== stride; ++ i ) {
  25111. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  25112. }
  25113. }
  25114. },
  25115. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  25116. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  25117. },
  25118. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25119. var s = 1 - t;
  25120. for ( var i = 0; i !== stride; ++ i ) {
  25121. var j = dstOffset + i;
  25122. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  25123. }
  25124. }
  25125. } );
  25126. /**
  25127. *
  25128. * A reference to a real property in the scene graph.
  25129. *
  25130. *
  25131. * @author Ben Houston / http://clara.io/
  25132. * @author David Sarno / http://lighthaus.us/
  25133. * @author tschw
  25134. */
  25135. // Characters [].:/ are reserved for track binding syntax.
  25136. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25137. var _reservedRe;
  25138. var _trackRe, _supportedObjectNames;
  25139. function Composite( targetGroup, path, optionalParsedPath ) {
  25140. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  25141. this._targetGroup = targetGroup;
  25142. this._bindings = targetGroup.subscribe_( path, parsedPath );
  25143. }
  25144. Object.assign( Composite.prototype, {
  25145. getValue: function ( array, offset ) {
  25146. this.bind(); // bind all binding
  25147. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25148. binding = this._bindings[ firstValidIndex ];
  25149. // and only call .getValue on the first
  25150. if ( binding !== undefined ) binding.getValue( array, offset );
  25151. },
  25152. setValue: function ( array, offset ) {
  25153. var bindings = this._bindings;
  25154. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25155. bindings[ i ].setValue( array, offset );
  25156. }
  25157. },
  25158. bind: function () {
  25159. var bindings = this._bindings;
  25160. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25161. bindings[ i ].bind();
  25162. }
  25163. },
  25164. unbind: function () {
  25165. var bindings = this._bindings;
  25166. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25167. bindings[ i ].unbind();
  25168. }
  25169. }
  25170. } );
  25171. function PropertyBinding( rootNode, path, parsedPath ) {
  25172. this.path = path;
  25173. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  25174. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  25175. this.rootNode = rootNode;
  25176. }
  25177. Object.assign( PropertyBinding, {
  25178. Composite: Composite,
  25179. create: function ( root, path, parsedPath ) {
  25180. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  25181. return new PropertyBinding( root, path, parsedPath );
  25182. } else {
  25183. return new PropertyBinding.Composite( root, path, parsedPath );
  25184. }
  25185. },
  25186. /**
  25187. * Replaces spaces with underscores and removes unsupported characters from
  25188. * node names, to ensure compatibility with parseTrackName().
  25189. *
  25190. * @param {string} name Node name to be sanitized.
  25191. * @return {string}
  25192. */
  25193. sanitizeNodeName: function ( name ) {
  25194. if ( _reservedRe === undefined ) {
  25195. _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  25196. }
  25197. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  25198. },
  25199. parseTrackName: function ( trackName ) {
  25200. if ( _supportedObjectNames === undefined ) {
  25201. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25202. // only latin characters, and the unicode \p{L} is not yet supported. So
  25203. // instead, we exclude reserved characters and match everything else.
  25204. var wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25205. var wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  25206. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25207. // be matched to parse the rest of the track name.
  25208. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  25209. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25210. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  25211. // Object on target node, and accessor. May not contain reserved
  25212. // characters. Accessor may contain any character except closing bracket.
  25213. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  25214. // Property and accessor. May not contain reserved characters. Accessor may
  25215. // contain any non-bracket characters.
  25216. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  25217. _trackRe = new RegExp( ''
  25218. + '^'
  25219. + directoryRe
  25220. + nodeRe
  25221. + objectRe
  25222. + propertyRe
  25223. + '$'
  25224. );
  25225. _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  25226. }
  25227. var matches = _trackRe.exec( trackName );
  25228. if ( ! matches ) {
  25229. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  25230. }
  25231. var results = {
  25232. // directoryName: matches[ 1 ], // (tschw) currently unused
  25233. nodeName: matches[ 2 ],
  25234. objectName: matches[ 3 ],
  25235. objectIndex: matches[ 4 ],
  25236. propertyName: matches[ 5 ], // required
  25237. propertyIndex: matches[ 6 ]
  25238. };
  25239. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  25240. if ( lastDot !== undefined && lastDot !== - 1 ) {
  25241. var objectName = results.nodeName.substring( lastDot + 1 );
  25242. // Object names must be checked against a whitelist. Otherwise, there
  25243. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25244. // 'bar' could be the objectName, or part of a nodeName (which can
  25245. // include '.' characters).
  25246. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  25247. results.nodeName = results.nodeName.substring( 0, lastDot );
  25248. results.objectName = objectName;
  25249. }
  25250. }
  25251. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  25252. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  25253. }
  25254. return results;
  25255. },
  25256. findNode: function ( root, nodeName ) {
  25257. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  25258. return root;
  25259. }
  25260. // search into skeleton bones.
  25261. if ( root.skeleton ) {
  25262. var bone = root.skeleton.getBoneByName( nodeName );
  25263. if ( bone !== undefined ) {
  25264. return bone;
  25265. }
  25266. }
  25267. // search into node subtree.
  25268. if ( root.children ) {
  25269. var searchNodeSubtree = function ( children ) {
  25270. for ( var i = 0; i < children.length; i ++ ) {
  25271. var childNode = children[ i ];
  25272. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  25273. return childNode;
  25274. }
  25275. var result = searchNodeSubtree( childNode.children );
  25276. if ( result ) return result;
  25277. }
  25278. return null;
  25279. };
  25280. var subTreeNode = searchNodeSubtree( root.children );
  25281. if ( subTreeNode ) {
  25282. return subTreeNode;
  25283. }
  25284. }
  25285. return null;
  25286. }
  25287. } );
  25288. Object.assign( PropertyBinding.prototype, { // prototype, continued
  25289. // these are used to "bind" a nonexistent property
  25290. _getValue_unavailable: function () {},
  25291. _setValue_unavailable: function () {},
  25292. BindingType: {
  25293. Direct: 0,
  25294. EntireArray: 1,
  25295. ArrayElement: 2,
  25296. HasFromToArray: 3
  25297. },
  25298. Versioning: {
  25299. None: 0,
  25300. NeedsUpdate: 1,
  25301. MatrixWorldNeedsUpdate: 2
  25302. },
  25303. GetterByBindingType: [
  25304. function getValue_direct( buffer, offset ) {
  25305. buffer[ offset ] = this.node[ this.propertyName ];
  25306. },
  25307. function getValue_array( buffer, offset ) {
  25308. var source = this.resolvedProperty;
  25309. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25310. buffer[ offset ++ ] = source[ i ];
  25311. }
  25312. },
  25313. function getValue_arrayElement( buffer, offset ) {
  25314. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25315. },
  25316. function getValue_toArray( buffer, offset ) {
  25317. this.resolvedProperty.toArray( buffer, offset );
  25318. }
  25319. ],
  25320. SetterByBindingTypeAndVersioning: [
  25321. [
  25322. // Direct
  25323. function setValue_direct( buffer, offset ) {
  25324. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25325. },
  25326. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25327. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25328. this.targetObject.needsUpdate = true;
  25329. },
  25330. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25331. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25332. this.targetObject.matrixWorldNeedsUpdate = true;
  25333. }
  25334. ], [
  25335. // EntireArray
  25336. function setValue_array( buffer, offset ) {
  25337. var dest = this.resolvedProperty;
  25338. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25339. dest[ i ] = buffer[ offset ++ ];
  25340. }
  25341. },
  25342. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25343. var dest = this.resolvedProperty;
  25344. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25345. dest[ i ] = buffer[ offset ++ ];
  25346. }
  25347. this.targetObject.needsUpdate = true;
  25348. },
  25349. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25350. var dest = this.resolvedProperty;
  25351. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25352. dest[ i ] = buffer[ offset ++ ];
  25353. }
  25354. this.targetObject.matrixWorldNeedsUpdate = true;
  25355. }
  25356. ], [
  25357. // ArrayElement
  25358. function setValue_arrayElement( buffer, offset ) {
  25359. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25360. },
  25361. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25362. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25363. this.targetObject.needsUpdate = true;
  25364. },
  25365. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25366. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25367. this.targetObject.matrixWorldNeedsUpdate = true;
  25368. }
  25369. ], [
  25370. // HasToFromArray
  25371. function setValue_fromArray( buffer, offset ) {
  25372. this.resolvedProperty.fromArray( buffer, offset );
  25373. },
  25374. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25375. this.resolvedProperty.fromArray( buffer, offset );
  25376. this.targetObject.needsUpdate = true;
  25377. },
  25378. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25379. this.resolvedProperty.fromArray( buffer, offset );
  25380. this.targetObject.matrixWorldNeedsUpdate = true;
  25381. }
  25382. ]
  25383. ],
  25384. getValue: function getValue_unbound( targetArray, offset ) {
  25385. this.bind();
  25386. this.getValue( targetArray, offset );
  25387. // Note: This class uses a State pattern on a per-method basis:
  25388. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25389. // prototype version of these methods with one that represents
  25390. // the bound state. When the property is not found, the methods
  25391. // become no-ops.
  25392. },
  25393. setValue: function getValue_unbound( sourceArray, offset ) {
  25394. this.bind();
  25395. this.setValue( sourceArray, offset );
  25396. },
  25397. // create getter / setter pair for a property in the scene graph
  25398. bind: function () {
  25399. var targetObject = this.node,
  25400. parsedPath = this.parsedPath,
  25401. objectName = parsedPath.objectName,
  25402. propertyName = parsedPath.propertyName,
  25403. propertyIndex = parsedPath.propertyIndex;
  25404. if ( ! targetObject ) {
  25405. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25406. this.node = targetObject;
  25407. }
  25408. // set fail state so we can just 'return' on error
  25409. this.getValue = this._getValue_unavailable;
  25410. this.setValue = this._setValue_unavailable;
  25411. // ensure there is a value node
  25412. if ( ! targetObject ) {
  25413. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25414. return;
  25415. }
  25416. if ( objectName ) {
  25417. var objectIndex = parsedPath.objectIndex;
  25418. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25419. switch ( objectName ) {
  25420. case 'materials':
  25421. if ( ! targetObject.material ) {
  25422. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25423. return;
  25424. }
  25425. if ( ! targetObject.material.materials ) {
  25426. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25427. return;
  25428. }
  25429. targetObject = targetObject.material.materials;
  25430. break;
  25431. case 'bones':
  25432. if ( ! targetObject.skeleton ) {
  25433. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25434. return;
  25435. }
  25436. // potential future optimization: skip this if propertyIndex is already an integer
  25437. // and convert the integer string to a true integer.
  25438. targetObject = targetObject.skeleton.bones;
  25439. // support resolving morphTarget names into indices.
  25440. for ( var i = 0; i < targetObject.length; i ++ ) {
  25441. if ( targetObject[ i ].name === objectIndex ) {
  25442. objectIndex = i;
  25443. break;
  25444. }
  25445. }
  25446. break;
  25447. default:
  25448. if ( targetObject[ objectName ] === undefined ) {
  25449. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25450. return;
  25451. }
  25452. targetObject = targetObject[ objectName ];
  25453. }
  25454. if ( objectIndex !== undefined ) {
  25455. if ( targetObject[ objectIndex ] === undefined ) {
  25456. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25457. return;
  25458. }
  25459. targetObject = targetObject[ objectIndex ];
  25460. }
  25461. }
  25462. // resolve property
  25463. var nodeProperty = targetObject[ propertyName ];
  25464. if ( nodeProperty === undefined ) {
  25465. var nodeName = parsedPath.nodeName;
  25466. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25467. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25468. return;
  25469. }
  25470. // determine versioning scheme
  25471. var versioning = this.Versioning.None;
  25472. this.targetObject = targetObject;
  25473. if ( targetObject.needsUpdate !== undefined ) { // material
  25474. versioning = this.Versioning.NeedsUpdate;
  25475. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25476. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25477. }
  25478. // determine how the property gets bound
  25479. var bindingType = this.BindingType.Direct;
  25480. if ( propertyIndex !== undefined ) {
  25481. // access a sub element of the property array (only primitives are supported right now)
  25482. if ( propertyName === "morphTargetInfluences" ) {
  25483. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25484. // support resolving morphTarget names into indices.
  25485. if ( ! targetObject.geometry ) {
  25486. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25487. return;
  25488. }
  25489. if ( targetObject.geometry.isBufferGeometry ) {
  25490. if ( ! targetObject.geometry.morphAttributes ) {
  25491. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25492. return;
  25493. }
  25494. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25495. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25496. propertyIndex = i;
  25497. break;
  25498. }
  25499. }
  25500. } else {
  25501. if ( ! targetObject.geometry.morphTargets ) {
  25502. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25503. return;
  25504. }
  25505. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25506. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25507. propertyIndex = i;
  25508. break;
  25509. }
  25510. }
  25511. }
  25512. }
  25513. bindingType = this.BindingType.ArrayElement;
  25514. this.resolvedProperty = nodeProperty;
  25515. this.propertyIndex = propertyIndex;
  25516. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25517. // must use copy for Object3D.Euler/Quaternion
  25518. bindingType = this.BindingType.HasFromToArray;
  25519. this.resolvedProperty = nodeProperty;
  25520. } else if ( Array.isArray( nodeProperty ) ) {
  25521. bindingType = this.BindingType.EntireArray;
  25522. this.resolvedProperty = nodeProperty;
  25523. } else {
  25524. this.propertyName = propertyName;
  25525. }
  25526. // select getter / setter
  25527. this.getValue = this.GetterByBindingType[ bindingType ];
  25528. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25529. },
  25530. unbind: function () {
  25531. this.node = null;
  25532. // back to the prototype version of getValue / setValue
  25533. // note: avoiding to mutate the shape of 'this' via 'delete'
  25534. this.getValue = this._getValue_unbound;
  25535. this.setValue = this._setValue_unbound;
  25536. }
  25537. } );
  25538. //!\ DECLARE ALIAS AFTER assign prototype !
  25539. Object.assign( PropertyBinding.prototype, {
  25540. // initial state of these methods that calls 'bind'
  25541. _getValue_unbound: PropertyBinding.prototype.getValue,
  25542. _setValue_unbound: PropertyBinding.prototype.setValue,
  25543. } );
  25544. /**
  25545. *
  25546. * A group of objects that receives a shared animation state.
  25547. *
  25548. * Usage:
  25549. *
  25550. * - Add objects you would otherwise pass as 'root' to the
  25551. * constructor or the .clipAction method of AnimationMixer.
  25552. *
  25553. * - Instead pass this object as 'root'.
  25554. *
  25555. * - You can also add and remove objects later when the mixer
  25556. * is running.
  25557. *
  25558. * Note:
  25559. *
  25560. * Objects of this class appear as one object to the mixer,
  25561. * so cache control of the individual objects must be done
  25562. * on the group.
  25563. *
  25564. * Limitation:
  25565. *
  25566. * - The animated properties must be compatible among the
  25567. * all objects in the group.
  25568. *
  25569. * - A single property can either be controlled through a
  25570. * target group or directly, but not both.
  25571. *
  25572. * @author tschw
  25573. */
  25574. function AnimationObjectGroup() {
  25575. this.uuid = _Math.generateUUID();
  25576. // cached objects followed by the active ones
  25577. this._objects = Array.prototype.slice.call( arguments );
  25578. this.nCachedObjects_ = 0; // threshold
  25579. // note: read by PropertyBinding.Composite
  25580. var indices = {};
  25581. this._indicesByUUID = indices; // for bookkeeping
  25582. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25583. indices[ arguments[ i ].uuid ] = i;
  25584. }
  25585. this._paths = []; // inside: string
  25586. this._parsedPaths = []; // inside: { we don't care, here }
  25587. this._bindings = []; // inside: Array< PropertyBinding >
  25588. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25589. var scope = this;
  25590. this.stats = {
  25591. objects: {
  25592. get total() {
  25593. return scope._objects.length;
  25594. },
  25595. get inUse() {
  25596. return this.total - scope.nCachedObjects_;
  25597. }
  25598. },
  25599. get bindingsPerObject() {
  25600. return scope._bindings.length;
  25601. }
  25602. };
  25603. }
  25604. Object.assign( AnimationObjectGroup.prototype, {
  25605. isAnimationObjectGroup: true,
  25606. add: function () {
  25607. var objects = this._objects,
  25608. nObjects = objects.length,
  25609. nCachedObjects = this.nCachedObjects_,
  25610. indicesByUUID = this._indicesByUUID,
  25611. paths = this._paths,
  25612. parsedPaths = this._parsedPaths,
  25613. bindings = this._bindings,
  25614. nBindings = bindings.length,
  25615. knownObject = undefined;
  25616. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25617. var object = arguments[ i ],
  25618. uuid = object.uuid,
  25619. index = indicesByUUID[ uuid ];
  25620. if ( index === undefined ) {
  25621. // unknown object -> add it to the ACTIVE region
  25622. index = nObjects ++;
  25623. indicesByUUID[ uuid ] = index;
  25624. objects.push( object );
  25625. // accounting is done, now do the same for all bindings
  25626. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25627. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25628. }
  25629. } else if ( index < nCachedObjects ) {
  25630. knownObject = objects[ index ];
  25631. // move existing object to the ACTIVE region
  25632. var firstActiveIndex = -- nCachedObjects,
  25633. lastCachedObject = objects[ firstActiveIndex ];
  25634. indicesByUUID[ lastCachedObject.uuid ] = index;
  25635. objects[ index ] = lastCachedObject;
  25636. indicesByUUID[ uuid ] = firstActiveIndex;
  25637. objects[ firstActiveIndex ] = object;
  25638. // accounting is done, now do the same for all bindings
  25639. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25640. var bindingsForPath = bindings[ j ],
  25641. lastCached = bindingsForPath[ firstActiveIndex ],
  25642. binding = bindingsForPath[ index ];
  25643. bindingsForPath[ index ] = lastCached;
  25644. if ( binding === undefined ) {
  25645. // since we do not bother to create new bindings
  25646. // for objects that are cached, the binding may
  25647. // or may not exist
  25648. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25649. }
  25650. bindingsForPath[ firstActiveIndex ] = binding;
  25651. }
  25652. } else if ( objects[ index ] !== knownObject ) {
  25653. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25654. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25655. } // else the object is already where we want it to be
  25656. } // for arguments
  25657. this.nCachedObjects_ = nCachedObjects;
  25658. },
  25659. remove: function () {
  25660. var objects = this._objects,
  25661. nCachedObjects = this.nCachedObjects_,
  25662. indicesByUUID = this._indicesByUUID,
  25663. bindings = this._bindings,
  25664. nBindings = bindings.length;
  25665. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25666. var object = arguments[ i ],
  25667. uuid = object.uuid,
  25668. index = indicesByUUID[ uuid ];
  25669. if ( index !== undefined && index >= nCachedObjects ) {
  25670. // move existing object into the CACHED region
  25671. var lastCachedIndex = nCachedObjects ++,
  25672. firstActiveObject = objects[ lastCachedIndex ];
  25673. indicesByUUID[ firstActiveObject.uuid ] = index;
  25674. objects[ index ] = firstActiveObject;
  25675. indicesByUUID[ uuid ] = lastCachedIndex;
  25676. objects[ lastCachedIndex ] = object;
  25677. // accounting is done, now do the same for all bindings
  25678. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25679. var bindingsForPath = bindings[ j ],
  25680. firstActive = bindingsForPath[ lastCachedIndex ],
  25681. binding = bindingsForPath[ index ];
  25682. bindingsForPath[ index ] = firstActive;
  25683. bindingsForPath[ lastCachedIndex ] = binding;
  25684. }
  25685. }
  25686. } // for arguments
  25687. this.nCachedObjects_ = nCachedObjects;
  25688. },
  25689. // remove & forget
  25690. uncache: function () {
  25691. var objects = this._objects,
  25692. nObjects = objects.length,
  25693. nCachedObjects = this.nCachedObjects_,
  25694. indicesByUUID = this._indicesByUUID,
  25695. bindings = this._bindings,
  25696. nBindings = bindings.length;
  25697. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25698. var object = arguments[ i ],
  25699. uuid = object.uuid,
  25700. index = indicesByUUID[ uuid ];
  25701. if ( index !== undefined ) {
  25702. delete indicesByUUID[ uuid ];
  25703. if ( index < nCachedObjects ) {
  25704. // object is cached, shrink the CACHED region
  25705. var firstActiveIndex = -- nCachedObjects,
  25706. lastCachedObject = objects[ firstActiveIndex ],
  25707. lastIndex = -- nObjects,
  25708. lastObject = objects[ lastIndex ];
  25709. // last cached object takes this object's place
  25710. indicesByUUID[ lastCachedObject.uuid ] = index;
  25711. objects[ index ] = lastCachedObject;
  25712. // last object goes to the activated slot and pop
  25713. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25714. objects[ firstActiveIndex ] = lastObject;
  25715. objects.pop();
  25716. // accounting is done, now do the same for all bindings
  25717. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25718. var bindingsForPath = bindings[ j ],
  25719. lastCached = bindingsForPath[ firstActiveIndex ],
  25720. last = bindingsForPath[ lastIndex ];
  25721. bindingsForPath[ index ] = lastCached;
  25722. bindingsForPath[ firstActiveIndex ] = last;
  25723. bindingsForPath.pop();
  25724. }
  25725. } else {
  25726. // object is active, just swap with the last and pop
  25727. var lastIndex = -- nObjects,
  25728. lastObject = objects[ lastIndex ];
  25729. indicesByUUID[ lastObject.uuid ] = index;
  25730. objects[ index ] = lastObject;
  25731. objects.pop();
  25732. // accounting is done, now do the same for all bindings
  25733. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25734. var bindingsForPath = bindings[ j ];
  25735. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25736. bindingsForPath.pop();
  25737. }
  25738. } // cached or active
  25739. } // if object is known
  25740. } // for arguments
  25741. this.nCachedObjects_ = nCachedObjects;
  25742. },
  25743. // Internal interface used by befriended PropertyBinding.Composite:
  25744. subscribe_: function ( path, parsedPath ) {
  25745. // returns an array of bindings for the given path that is changed
  25746. // according to the contained objects in the group
  25747. var indicesByPath = this._bindingsIndicesByPath,
  25748. index = indicesByPath[ path ],
  25749. bindings = this._bindings;
  25750. if ( index !== undefined ) return bindings[ index ];
  25751. var paths = this._paths,
  25752. parsedPaths = this._parsedPaths,
  25753. objects = this._objects,
  25754. nObjects = objects.length,
  25755. nCachedObjects = this.nCachedObjects_,
  25756. bindingsForPath = new Array( nObjects );
  25757. index = bindings.length;
  25758. indicesByPath[ path ] = index;
  25759. paths.push( path );
  25760. parsedPaths.push( parsedPath );
  25761. bindings.push( bindingsForPath );
  25762. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25763. var object = objects[ i ];
  25764. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25765. }
  25766. return bindingsForPath;
  25767. },
  25768. unsubscribe_: function ( path ) {
  25769. // tells the group to forget about a property path and no longer
  25770. // update the array previously obtained with 'subscribe_'
  25771. var indicesByPath = this._bindingsIndicesByPath,
  25772. index = indicesByPath[ path ];
  25773. if ( index !== undefined ) {
  25774. var paths = this._paths,
  25775. parsedPaths = this._parsedPaths,
  25776. bindings = this._bindings,
  25777. lastBindingsIndex = bindings.length - 1,
  25778. lastBindings = bindings[ lastBindingsIndex ],
  25779. lastBindingsPath = path[ lastBindingsIndex ];
  25780. indicesByPath[ lastBindingsPath ] = index;
  25781. bindings[ index ] = lastBindings;
  25782. bindings.pop();
  25783. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25784. parsedPaths.pop();
  25785. paths[ index ] = paths[ lastBindingsIndex ];
  25786. paths.pop();
  25787. }
  25788. }
  25789. } );
  25790. /**
  25791. *
  25792. * Action provided by AnimationMixer for scheduling clip playback on specific
  25793. * objects.
  25794. *
  25795. * @author Ben Houston / http://clara.io/
  25796. * @author David Sarno / http://lighthaus.us/
  25797. * @author tschw
  25798. *
  25799. */
  25800. function AnimationAction( mixer, clip, localRoot ) {
  25801. this._mixer = mixer;
  25802. this._clip = clip;
  25803. this._localRoot = localRoot || null;
  25804. var tracks = clip.tracks,
  25805. nTracks = tracks.length,
  25806. interpolants = new Array( nTracks );
  25807. var interpolantSettings = {
  25808. endingStart: ZeroCurvatureEnding,
  25809. endingEnd: ZeroCurvatureEnding
  25810. };
  25811. for ( var i = 0; i !== nTracks; ++ i ) {
  25812. var interpolant = tracks[ i ].createInterpolant( null );
  25813. interpolants[ i ] = interpolant;
  25814. interpolant.settings = interpolantSettings;
  25815. }
  25816. this._interpolantSettings = interpolantSettings;
  25817. this._interpolants = interpolants; // bound by the mixer
  25818. // inside: PropertyMixer (managed by the mixer)
  25819. this._propertyBindings = new Array( nTracks );
  25820. this._cacheIndex = null; // for the memory manager
  25821. this._byClipCacheIndex = null; // for the memory manager
  25822. this._timeScaleInterpolant = null;
  25823. this._weightInterpolant = null;
  25824. this.loop = LoopRepeat;
  25825. this._loopCount = - 1;
  25826. // global mixer time when the action is to be started
  25827. // it's set back to 'null' upon start of the action
  25828. this._startTime = null;
  25829. // scaled local time of the action
  25830. // gets clamped or wrapped to 0..clip.duration according to loop
  25831. this.time = 0;
  25832. this.timeScale = 1;
  25833. this._effectiveTimeScale = 1;
  25834. this.weight = 1;
  25835. this._effectiveWeight = 1;
  25836. this.repetitions = Infinity; // no. of repetitions when looping
  25837. this.paused = false; // true -> zero effective time scale
  25838. this.enabled = true; // false -> zero effective weight
  25839. this.clampWhenFinished = false;// keep feeding the last frame?
  25840. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25841. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25842. }
  25843. Object.assign( AnimationAction.prototype, {
  25844. // State & Scheduling
  25845. play: function () {
  25846. this._mixer._activateAction( this );
  25847. return this;
  25848. },
  25849. stop: function () {
  25850. this._mixer._deactivateAction( this );
  25851. return this.reset();
  25852. },
  25853. reset: function () {
  25854. this.paused = false;
  25855. this.enabled = true;
  25856. this.time = 0; // restart clip
  25857. this._loopCount = - 1;// forget previous loops
  25858. this._startTime = null;// forget scheduling
  25859. return this.stopFading().stopWarping();
  25860. },
  25861. isRunning: function () {
  25862. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25863. this._startTime === null && this._mixer._isActiveAction( this );
  25864. },
  25865. // return true when play has been called
  25866. isScheduled: function () {
  25867. return this._mixer._isActiveAction( this );
  25868. },
  25869. startAt: function ( time ) {
  25870. this._startTime = time;
  25871. return this;
  25872. },
  25873. setLoop: function ( mode, repetitions ) {
  25874. this.loop = mode;
  25875. this.repetitions = repetitions;
  25876. return this;
  25877. },
  25878. // Weight
  25879. // set the weight stopping any scheduled fading
  25880. // although .enabled = false yields an effective weight of zero, this
  25881. // method does *not* change .enabled, because it would be confusing
  25882. setEffectiveWeight: function ( weight ) {
  25883. this.weight = weight;
  25884. // note: same logic as when updated at runtime
  25885. this._effectiveWeight = this.enabled ? weight : 0;
  25886. return this.stopFading();
  25887. },
  25888. // return the weight considering fading and .enabled
  25889. getEffectiveWeight: function () {
  25890. return this._effectiveWeight;
  25891. },
  25892. fadeIn: function ( duration ) {
  25893. return this._scheduleFading( duration, 0, 1 );
  25894. },
  25895. fadeOut: function ( duration ) {
  25896. return this._scheduleFading( duration, 1, 0 );
  25897. },
  25898. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25899. fadeOutAction.fadeOut( duration );
  25900. this.fadeIn( duration );
  25901. if ( warp ) {
  25902. var fadeInDuration = this._clip.duration,
  25903. fadeOutDuration = fadeOutAction._clip.duration,
  25904. startEndRatio = fadeOutDuration / fadeInDuration,
  25905. endStartRatio = fadeInDuration / fadeOutDuration;
  25906. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25907. this.warp( endStartRatio, 1.0, duration );
  25908. }
  25909. return this;
  25910. },
  25911. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25912. return fadeInAction.crossFadeFrom( this, duration, warp );
  25913. },
  25914. stopFading: function () {
  25915. var weightInterpolant = this._weightInterpolant;
  25916. if ( weightInterpolant !== null ) {
  25917. this._weightInterpolant = null;
  25918. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25919. }
  25920. return this;
  25921. },
  25922. // Time Scale Control
  25923. // set the time scale stopping any scheduled warping
  25924. // although .paused = true yields an effective time scale of zero, this
  25925. // method does *not* change .paused, because it would be confusing
  25926. setEffectiveTimeScale: function ( timeScale ) {
  25927. this.timeScale = timeScale;
  25928. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25929. return this.stopWarping();
  25930. },
  25931. // return the time scale considering warping and .paused
  25932. getEffectiveTimeScale: function () {
  25933. return this._effectiveTimeScale;
  25934. },
  25935. setDuration: function ( duration ) {
  25936. this.timeScale = this._clip.duration / duration;
  25937. return this.stopWarping();
  25938. },
  25939. syncWith: function ( action ) {
  25940. this.time = action.time;
  25941. this.timeScale = action.timeScale;
  25942. return this.stopWarping();
  25943. },
  25944. halt: function ( duration ) {
  25945. return this.warp( this._effectiveTimeScale, 0, duration );
  25946. },
  25947. warp: function ( startTimeScale, endTimeScale, duration ) {
  25948. var mixer = this._mixer, now = mixer.time,
  25949. interpolant = this._timeScaleInterpolant,
  25950. timeScale = this.timeScale;
  25951. if ( interpolant === null ) {
  25952. interpolant = mixer._lendControlInterpolant();
  25953. this._timeScaleInterpolant = interpolant;
  25954. }
  25955. var times = interpolant.parameterPositions,
  25956. values = interpolant.sampleValues;
  25957. times[ 0 ] = now;
  25958. times[ 1 ] = now + duration;
  25959. values[ 0 ] = startTimeScale / timeScale;
  25960. values[ 1 ] = endTimeScale / timeScale;
  25961. return this;
  25962. },
  25963. stopWarping: function () {
  25964. var timeScaleInterpolant = this._timeScaleInterpolant;
  25965. if ( timeScaleInterpolant !== null ) {
  25966. this._timeScaleInterpolant = null;
  25967. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25968. }
  25969. return this;
  25970. },
  25971. // Object Accessors
  25972. getMixer: function () {
  25973. return this._mixer;
  25974. },
  25975. getClip: function () {
  25976. return this._clip;
  25977. },
  25978. getRoot: function () {
  25979. return this._localRoot || this._mixer._root;
  25980. },
  25981. // Interna
  25982. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25983. // called by the mixer
  25984. if ( ! this.enabled ) {
  25985. // call ._updateWeight() to update ._effectiveWeight
  25986. this._updateWeight( time );
  25987. return;
  25988. }
  25989. var startTime = this._startTime;
  25990. if ( startTime !== null ) {
  25991. // check for scheduled start of action
  25992. var timeRunning = ( time - startTime ) * timeDirection;
  25993. if ( timeRunning < 0 || timeDirection === 0 ) {
  25994. return; // yet to come / don't decide when delta = 0
  25995. }
  25996. // start
  25997. this._startTime = null; // unschedule
  25998. deltaTime = timeDirection * timeRunning;
  25999. }
  26000. // apply time scale and advance time
  26001. deltaTime *= this._updateTimeScale( time );
  26002. var clipTime = this._updateTime( deltaTime );
  26003. // note: _updateTime may disable the action resulting in
  26004. // an effective weight of 0
  26005. var weight = this._updateWeight( time );
  26006. if ( weight > 0 ) {
  26007. var interpolants = this._interpolants;
  26008. var propertyMixers = this._propertyBindings;
  26009. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  26010. interpolants[ j ].evaluate( clipTime );
  26011. propertyMixers[ j ].accumulate( accuIndex, weight );
  26012. }
  26013. }
  26014. },
  26015. _updateWeight: function ( time ) {
  26016. var weight = 0;
  26017. if ( this.enabled ) {
  26018. weight = this.weight;
  26019. var interpolant = this._weightInterpolant;
  26020. if ( interpolant !== null ) {
  26021. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26022. weight *= interpolantValue;
  26023. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26024. this.stopFading();
  26025. if ( interpolantValue === 0 ) {
  26026. // faded out, disable
  26027. this.enabled = false;
  26028. }
  26029. }
  26030. }
  26031. }
  26032. this._effectiveWeight = weight;
  26033. return weight;
  26034. },
  26035. _updateTimeScale: function ( time ) {
  26036. var timeScale = 0;
  26037. if ( ! this.paused ) {
  26038. timeScale = this.timeScale;
  26039. var interpolant = this._timeScaleInterpolant;
  26040. if ( interpolant !== null ) {
  26041. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26042. timeScale *= interpolantValue;
  26043. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26044. this.stopWarping();
  26045. if ( timeScale === 0 ) {
  26046. // motion has halted, pause
  26047. this.paused = true;
  26048. } else {
  26049. // warp done - apply final time scale
  26050. this.timeScale = timeScale;
  26051. }
  26052. }
  26053. }
  26054. }
  26055. this._effectiveTimeScale = timeScale;
  26056. return timeScale;
  26057. },
  26058. _updateTime: function ( deltaTime ) {
  26059. var time = this.time + deltaTime;
  26060. var duration = this._clip.duration;
  26061. var loop = this.loop;
  26062. var loopCount = this._loopCount;
  26063. var pingPong = ( loop === LoopPingPong );
  26064. if ( deltaTime === 0 ) {
  26065. if ( loopCount === - 1 ) return time;
  26066. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26067. }
  26068. if ( loop === LoopOnce ) {
  26069. if ( loopCount === - 1 ) {
  26070. // just started
  26071. this._loopCount = 0;
  26072. this._setEndings( true, true, false );
  26073. }
  26074. handle_stop: {
  26075. if ( time >= duration ) {
  26076. time = duration;
  26077. } else if ( time < 0 ) {
  26078. time = 0;
  26079. } else {
  26080. this.time = time;
  26081. break handle_stop;
  26082. }
  26083. if ( this.clampWhenFinished ) this.paused = true;
  26084. else this.enabled = false;
  26085. this.time = time;
  26086. this._mixer.dispatchEvent( {
  26087. type: 'finished', action: this,
  26088. direction: deltaTime < 0 ? - 1 : 1
  26089. } );
  26090. }
  26091. } else { // repetitive Repeat or PingPong
  26092. if ( loopCount === - 1 ) {
  26093. // just started
  26094. if ( deltaTime >= 0 ) {
  26095. loopCount = 0;
  26096. this._setEndings( true, this.repetitions === 0, pingPong );
  26097. } else {
  26098. // when looping in reverse direction, the initial
  26099. // transition through zero counts as a repetition,
  26100. // so leave loopCount at -1
  26101. this._setEndings( this.repetitions === 0, true, pingPong );
  26102. }
  26103. }
  26104. if ( time >= duration || time < 0 ) {
  26105. // wrap around
  26106. var loopDelta = Math.floor( time / duration ); // signed
  26107. time -= duration * loopDelta;
  26108. loopCount += Math.abs( loopDelta );
  26109. var pending = this.repetitions - loopCount;
  26110. if ( pending <= 0 ) {
  26111. // have to stop (switch state, clamp time, fire event)
  26112. if ( this.clampWhenFinished ) this.paused = true;
  26113. else this.enabled = false;
  26114. time = deltaTime > 0 ? duration : 0;
  26115. this.time = time;
  26116. this._mixer.dispatchEvent( {
  26117. type: 'finished', action: this,
  26118. direction: deltaTime > 0 ? 1 : - 1
  26119. } );
  26120. } else {
  26121. // keep running
  26122. if ( pending === 1 ) {
  26123. // entering the last round
  26124. var atStart = deltaTime < 0;
  26125. this._setEndings( atStart, ! atStart, pingPong );
  26126. } else {
  26127. this._setEndings( false, false, pingPong );
  26128. }
  26129. this._loopCount = loopCount;
  26130. this.time = time;
  26131. this._mixer.dispatchEvent( {
  26132. type: 'loop', action: this, loopDelta: loopDelta
  26133. } );
  26134. }
  26135. } else {
  26136. this.time = time;
  26137. }
  26138. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  26139. // invert time for the "pong round"
  26140. return duration - time;
  26141. }
  26142. }
  26143. return time;
  26144. },
  26145. _setEndings: function ( atStart, atEnd, pingPong ) {
  26146. var settings = this._interpolantSettings;
  26147. if ( pingPong ) {
  26148. settings.endingStart = ZeroSlopeEnding;
  26149. settings.endingEnd = ZeroSlopeEnding;
  26150. } else {
  26151. // assuming for LoopOnce atStart == atEnd == true
  26152. if ( atStart ) {
  26153. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26154. } else {
  26155. settings.endingStart = WrapAroundEnding;
  26156. }
  26157. if ( atEnd ) {
  26158. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26159. } else {
  26160. settings.endingEnd = WrapAroundEnding;
  26161. }
  26162. }
  26163. },
  26164. _scheduleFading: function ( duration, weightNow, weightThen ) {
  26165. var mixer = this._mixer, now = mixer.time,
  26166. interpolant = this._weightInterpolant;
  26167. if ( interpolant === null ) {
  26168. interpolant = mixer._lendControlInterpolant();
  26169. this._weightInterpolant = interpolant;
  26170. }
  26171. var times = interpolant.parameterPositions,
  26172. values = interpolant.sampleValues;
  26173. times[ 0 ] = now;
  26174. values[ 0 ] = weightNow;
  26175. times[ 1 ] = now + duration;
  26176. values[ 1 ] = weightThen;
  26177. return this;
  26178. }
  26179. } );
  26180. /**
  26181. *
  26182. * Player for AnimationClips.
  26183. *
  26184. *
  26185. * @author Ben Houston / http://clara.io/
  26186. * @author David Sarno / http://lighthaus.us/
  26187. * @author tschw
  26188. */
  26189. function AnimationMixer( root ) {
  26190. this._root = root;
  26191. this._initMemoryManager();
  26192. this._accuIndex = 0;
  26193. this.time = 0;
  26194. this.timeScale = 1.0;
  26195. }
  26196. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  26197. constructor: AnimationMixer,
  26198. _bindAction: function ( action, prototypeAction ) {
  26199. var root = action._localRoot || this._root,
  26200. tracks = action._clip.tracks,
  26201. nTracks = tracks.length,
  26202. bindings = action._propertyBindings,
  26203. interpolants = action._interpolants,
  26204. rootUuid = root.uuid,
  26205. bindingsByRoot = this._bindingsByRootAndName,
  26206. bindingsByName = bindingsByRoot[ rootUuid ];
  26207. if ( bindingsByName === undefined ) {
  26208. bindingsByName = {};
  26209. bindingsByRoot[ rootUuid ] = bindingsByName;
  26210. }
  26211. for ( var i = 0; i !== nTracks; ++ i ) {
  26212. var track = tracks[ i ],
  26213. trackName = track.name,
  26214. binding = bindingsByName[ trackName ];
  26215. if ( binding !== undefined ) {
  26216. bindings[ i ] = binding;
  26217. } else {
  26218. binding = bindings[ i ];
  26219. if ( binding !== undefined ) {
  26220. // existing binding, make sure the cache knows
  26221. if ( binding._cacheIndex === null ) {
  26222. ++ binding.referenceCount;
  26223. this._addInactiveBinding( binding, rootUuid, trackName );
  26224. }
  26225. continue;
  26226. }
  26227. var path = prototypeAction && prototypeAction.
  26228. _propertyBindings[ i ].binding.parsedPath;
  26229. binding = new PropertyMixer(
  26230. PropertyBinding.create( root, trackName, path ),
  26231. track.ValueTypeName, track.getValueSize() );
  26232. ++ binding.referenceCount;
  26233. this._addInactiveBinding( binding, rootUuid, trackName );
  26234. bindings[ i ] = binding;
  26235. }
  26236. interpolants[ i ].resultBuffer = binding.buffer;
  26237. }
  26238. },
  26239. _activateAction: function ( action ) {
  26240. if ( ! this._isActiveAction( action ) ) {
  26241. if ( action._cacheIndex === null ) {
  26242. // this action has been forgotten by the cache, but the user
  26243. // appears to be still using it -> rebind
  26244. var rootUuid = ( action._localRoot || this._root ).uuid,
  26245. clipUuid = action._clip.uuid,
  26246. actionsForClip = this._actionsByClip[ clipUuid ];
  26247. this._bindAction( action,
  26248. actionsForClip && actionsForClip.knownActions[ 0 ] );
  26249. this._addInactiveAction( action, clipUuid, rootUuid );
  26250. }
  26251. var bindings = action._propertyBindings;
  26252. // increment reference counts / sort out state
  26253. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26254. var binding = bindings[ i ];
  26255. if ( binding.useCount ++ === 0 ) {
  26256. this._lendBinding( binding );
  26257. binding.saveOriginalState();
  26258. }
  26259. }
  26260. this._lendAction( action );
  26261. }
  26262. },
  26263. _deactivateAction: function ( action ) {
  26264. if ( this._isActiveAction( action ) ) {
  26265. var bindings = action._propertyBindings;
  26266. // decrement reference counts / sort out state
  26267. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26268. var binding = bindings[ i ];
  26269. if ( -- binding.useCount === 0 ) {
  26270. binding.restoreOriginalState();
  26271. this._takeBackBinding( binding );
  26272. }
  26273. }
  26274. this._takeBackAction( action );
  26275. }
  26276. },
  26277. // Memory manager
  26278. _initMemoryManager: function () {
  26279. this._actions = []; // 'nActiveActions' followed by inactive ones
  26280. this._nActiveActions = 0;
  26281. this._actionsByClip = {};
  26282. // inside:
  26283. // {
  26284. // knownActions: Array< AnimationAction > - used as prototypes
  26285. // actionByRoot: AnimationAction - lookup
  26286. // }
  26287. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26288. this._nActiveBindings = 0;
  26289. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26290. this._controlInterpolants = []; // same game as above
  26291. this._nActiveControlInterpolants = 0;
  26292. var scope = this;
  26293. this.stats = {
  26294. actions: {
  26295. get total() {
  26296. return scope._actions.length;
  26297. },
  26298. get inUse() {
  26299. return scope._nActiveActions;
  26300. }
  26301. },
  26302. bindings: {
  26303. get total() {
  26304. return scope._bindings.length;
  26305. },
  26306. get inUse() {
  26307. return scope._nActiveBindings;
  26308. }
  26309. },
  26310. controlInterpolants: {
  26311. get total() {
  26312. return scope._controlInterpolants.length;
  26313. },
  26314. get inUse() {
  26315. return scope._nActiveControlInterpolants;
  26316. }
  26317. }
  26318. };
  26319. },
  26320. // Memory management for AnimationAction objects
  26321. _isActiveAction: function ( action ) {
  26322. var index = action._cacheIndex;
  26323. return index !== null && index < this._nActiveActions;
  26324. },
  26325. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26326. var actions = this._actions,
  26327. actionsByClip = this._actionsByClip,
  26328. actionsForClip = actionsByClip[ clipUuid ];
  26329. if ( actionsForClip === undefined ) {
  26330. actionsForClip = {
  26331. knownActions: [ action ],
  26332. actionByRoot: {}
  26333. };
  26334. action._byClipCacheIndex = 0;
  26335. actionsByClip[ clipUuid ] = actionsForClip;
  26336. } else {
  26337. var knownActions = actionsForClip.knownActions;
  26338. action._byClipCacheIndex = knownActions.length;
  26339. knownActions.push( action );
  26340. }
  26341. action._cacheIndex = actions.length;
  26342. actions.push( action );
  26343. actionsForClip.actionByRoot[ rootUuid ] = action;
  26344. },
  26345. _removeInactiveAction: function ( action ) {
  26346. var actions = this._actions,
  26347. lastInactiveAction = actions[ actions.length - 1 ],
  26348. cacheIndex = action._cacheIndex;
  26349. lastInactiveAction._cacheIndex = cacheIndex;
  26350. actions[ cacheIndex ] = lastInactiveAction;
  26351. actions.pop();
  26352. action._cacheIndex = null;
  26353. var clipUuid = action._clip.uuid,
  26354. actionsByClip = this._actionsByClip,
  26355. actionsForClip = actionsByClip[ clipUuid ],
  26356. knownActionsForClip = actionsForClip.knownActions,
  26357. lastKnownAction =
  26358. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26359. byClipCacheIndex = action._byClipCacheIndex;
  26360. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26361. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26362. knownActionsForClip.pop();
  26363. action._byClipCacheIndex = null;
  26364. var actionByRoot = actionsForClip.actionByRoot,
  26365. rootUuid = ( action._localRoot || this._root ).uuid;
  26366. delete actionByRoot[ rootUuid ];
  26367. if ( knownActionsForClip.length === 0 ) {
  26368. delete actionsByClip[ clipUuid ];
  26369. }
  26370. this._removeInactiveBindingsForAction( action );
  26371. },
  26372. _removeInactiveBindingsForAction: function ( action ) {
  26373. var bindings = action._propertyBindings;
  26374. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26375. var binding = bindings[ i ];
  26376. if ( -- binding.referenceCount === 0 ) {
  26377. this._removeInactiveBinding( binding );
  26378. }
  26379. }
  26380. },
  26381. _lendAction: function ( action ) {
  26382. // [ active actions | inactive actions ]
  26383. // [ active actions >| inactive actions ]
  26384. // s a
  26385. // <-swap->
  26386. // a s
  26387. var actions = this._actions,
  26388. prevIndex = action._cacheIndex,
  26389. lastActiveIndex = this._nActiveActions ++,
  26390. firstInactiveAction = actions[ lastActiveIndex ];
  26391. action._cacheIndex = lastActiveIndex;
  26392. actions[ lastActiveIndex ] = action;
  26393. firstInactiveAction._cacheIndex = prevIndex;
  26394. actions[ prevIndex ] = firstInactiveAction;
  26395. },
  26396. _takeBackAction: function ( action ) {
  26397. // [ active actions | inactive actions ]
  26398. // [ active actions |< inactive actions ]
  26399. // a s
  26400. // <-swap->
  26401. // s a
  26402. var actions = this._actions,
  26403. prevIndex = action._cacheIndex,
  26404. firstInactiveIndex = -- this._nActiveActions,
  26405. lastActiveAction = actions[ firstInactiveIndex ];
  26406. action._cacheIndex = firstInactiveIndex;
  26407. actions[ firstInactiveIndex ] = action;
  26408. lastActiveAction._cacheIndex = prevIndex;
  26409. actions[ prevIndex ] = lastActiveAction;
  26410. },
  26411. // Memory management for PropertyMixer objects
  26412. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26413. var bindingsByRoot = this._bindingsByRootAndName,
  26414. bindingByName = bindingsByRoot[ rootUuid ],
  26415. bindings = this._bindings;
  26416. if ( bindingByName === undefined ) {
  26417. bindingByName = {};
  26418. bindingsByRoot[ rootUuid ] = bindingByName;
  26419. }
  26420. bindingByName[ trackName ] = binding;
  26421. binding._cacheIndex = bindings.length;
  26422. bindings.push( binding );
  26423. },
  26424. _removeInactiveBinding: function ( binding ) {
  26425. var bindings = this._bindings,
  26426. propBinding = binding.binding,
  26427. rootUuid = propBinding.rootNode.uuid,
  26428. trackName = propBinding.path,
  26429. bindingsByRoot = this._bindingsByRootAndName,
  26430. bindingByName = bindingsByRoot[ rootUuid ],
  26431. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26432. cacheIndex = binding._cacheIndex;
  26433. lastInactiveBinding._cacheIndex = cacheIndex;
  26434. bindings[ cacheIndex ] = lastInactiveBinding;
  26435. bindings.pop();
  26436. delete bindingByName[ trackName ];
  26437. if ( Object.keys( bindingByName ).length === 0 ) {
  26438. delete bindingsByRoot[ rootUuid ];
  26439. }
  26440. },
  26441. _lendBinding: function ( binding ) {
  26442. var bindings = this._bindings,
  26443. prevIndex = binding._cacheIndex,
  26444. lastActiveIndex = this._nActiveBindings ++,
  26445. firstInactiveBinding = bindings[ lastActiveIndex ];
  26446. binding._cacheIndex = lastActiveIndex;
  26447. bindings[ lastActiveIndex ] = binding;
  26448. firstInactiveBinding._cacheIndex = prevIndex;
  26449. bindings[ prevIndex ] = firstInactiveBinding;
  26450. },
  26451. _takeBackBinding: function ( binding ) {
  26452. var bindings = this._bindings,
  26453. prevIndex = binding._cacheIndex,
  26454. firstInactiveIndex = -- this._nActiveBindings,
  26455. lastActiveBinding = bindings[ firstInactiveIndex ];
  26456. binding._cacheIndex = firstInactiveIndex;
  26457. bindings[ firstInactiveIndex ] = binding;
  26458. lastActiveBinding._cacheIndex = prevIndex;
  26459. bindings[ prevIndex ] = lastActiveBinding;
  26460. },
  26461. // Memory management of Interpolants for weight and time scale
  26462. _lendControlInterpolant: function () {
  26463. var interpolants = this._controlInterpolants,
  26464. lastActiveIndex = this._nActiveControlInterpolants ++,
  26465. interpolant = interpolants[ lastActiveIndex ];
  26466. if ( interpolant === undefined ) {
  26467. interpolant = new LinearInterpolant(
  26468. new Float32Array( 2 ), new Float32Array( 2 ),
  26469. 1, this._controlInterpolantsResultBuffer );
  26470. interpolant.__cacheIndex = lastActiveIndex;
  26471. interpolants[ lastActiveIndex ] = interpolant;
  26472. }
  26473. return interpolant;
  26474. },
  26475. _takeBackControlInterpolant: function ( interpolant ) {
  26476. var interpolants = this._controlInterpolants,
  26477. prevIndex = interpolant.__cacheIndex,
  26478. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26479. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26480. interpolant.__cacheIndex = firstInactiveIndex;
  26481. interpolants[ firstInactiveIndex ] = interpolant;
  26482. lastActiveInterpolant.__cacheIndex = prevIndex;
  26483. interpolants[ prevIndex ] = lastActiveInterpolant;
  26484. },
  26485. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26486. // return an action for a clip optionally using a custom root target
  26487. // object (this method allocates a lot of dynamic memory in case a
  26488. // previously unknown clip/root combination is specified)
  26489. clipAction: function ( clip, optionalRoot ) {
  26490. var root = optionalRoot || this._root,
  26491. rootUuid = root.uuid,
  26492. clipObject = typeof clip === 'string' ?
  26493. AnimationClip.findByName( root, clip ) : clip,
  26494. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26495. actionsForClip = this._actionsByClip[ clipUuid ],
  26496. prototypeAction = null;
  26497. if ( actionsForClip !== undefined ) {
  26498. var existingAction =
  26499. actionsForClip.actionByRoot[ rootUuid ];
  26500. if ( existingAction !== undefined ) {
  26501. return existingAction;
  26502. }
  26503. // we know the clip, so we don't have to parse all
  26504. // the bindings again but can just copy
  26505. prototypeAction = actionsForClip.knownActions[ 0 ];
  26506. // also, take the clip from the prototype action
  26507. if ( clipObject === null )
  26508. clipObject = prototypeAction._clip;
  26509. }
  26510. // clip must be known when specified via string
  26511. if ( clipObject === null ) return null;
  26512. // allocate all resources required to run it
  26513. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26514. this._bindAction( newAction, prototypeAction );
  26515. // and make the action known to the memory manager
  26516. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26517. return newAction;
  26518. },
  26519. // get an existing action
  26520. existingAction: function ( clip, optionalRoot ) {
  26521. var root = optionalRoot || this._root,
  26522. rootUuid = root.uuid,
  26523. clipObject = typeof clip === 'string' ?
  26524. AnimationClip.findByName( root, clip ) : clip,
  26525. clipUuid = clipObject ? clipObject.uuid : clip,
  26526. actionsForClip = this._actionsByClip[ clipUuid ];
  26527. if ( actionsForClip !== undefined ) {
  26528. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26529. }
  26530. return null;
  26531. },
  26532. // deactivates all previously scheduled actions
  26533. stopAllAction: function () {
  26534. var actions = this._actions,
  26535. nActions = this._nActiveActions,
  26536. bindings = this._bindings,
  26537. nBindings = this._nActiveBindings;
  26538. this._nActiveActions = 0;
  26539. this._nActiveBindings = 0;
  26540. for ( var i = 0; i !== nActions; ++ i ) {
  26541. actions[ i ].reset();
  26542. }
  26543. for ( var i = 0; i !== nBindings; ++ i ) {
  26544. bindings[ i ].useCount = 0;
  26545. }
  26546. return this;
  26547. },
  26548. // advance the time and update apply the animation
  26549. update: function ( deltaTime ) {
  26550. deltaTime *= this.timeScale;
  26551. var actions = this._actions,
  26552. nActions = this._nActiveActions,
  26553. time = this.time += deltaTime,
  26554. timeDirection = Math.sign( deltaTime ),
  26555. accuIndex = this._accuIndex ^= 1;
  26556. // run active actions
  26557. for ( var i = 0; i !== nActions; ++ i ) {
  26558. var action = actions[ i ];
  26559. action._update( time, deltaTime, timeDirection, accuIndex );
  26560. }
  26561. // update scene graph
  26562. var bindings = this._bindings,
  26563. nBindings = this._nActiveBindings;
  26564. for ( var i = 0; i !== nBindings; ++ i ) {
  26565. bindings[ i ].apply( accuIndex );
  26566. }
  26567. return this;
  26568. },
  26569. // return this mixer's root target object
  26570. getRoot: function () {
  26571. return this._root;
  26572. },
  26573. // free all resources specific to a particular clip
  26574. uncacheClip: function ( clip ) {
  26575. var actions = this._actions,
  26576. clipUuid = clip.uuid,
  26577. actionsByClip = this._actionsByClip,
  26578. actionsForClip = actionsByClip[ clipUuid ];
  26579. if ( actionsForClip !== undefined ) {
  26580. // note: just calling _removeInactiveAction would mess up the
  26581. // iteration state and also require updating the state we can
  26582. // just throw away
  26583. var actionsToRemove = actionsForClip.knownActions;
  26584. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26585. var action = actionsToRemove[ i ];
  26586. this._deactivateAction( action );
  26587. var cacheIndex = action._cacheIndex,
  26588. lastInactiveAction = actions[ actions.length - 1 ];
  26589. action._cacheIndex = null;
  26590. action._byClipCacheIndex = null;
  26591. lastInactiveAction._cacheIndex = cacheIndex;
  26592. actions[ cacheIndex ] = lastInactiveAction;
  26593. actions.pop();
  26594. this._removeInactiveBindingsForAction( action );
  26595. }
  26596. delete actionsByClip[ clipUuid ];
  26597. }
  26598. },
  26599. // free all resources specific to a particular root target object
  26600. uncacheRoot: function ( root ) {
  26601. var rootUuid = root.uuid,
  26602. actionsByClip = this._actionsByClip;
  26603. for ( var clipUuid in actionsByClip ) {
  26604. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26605. action = actionByRoot[ rootUuid ];
  26606. if ( action !== undefined ) {
  26607. this._deactivateAction( action );
  26608. this._removeInactiveAction( action );
  26609. }
  26610. }
  26611. var bindingsByRoot = this._bindingsByRootAndName,
  26612. bindingByName = bindingsByRoot[ rootUuid ];
  26613. if ( bindingByName !== undefined ) {
  26614. for ( var trackName in bindingByName ) {
  26615. var binding = bindingByName[ trackName ];
  26616. binding.restoreOriginalState();
  26617. this._removeInactiveBinding( binding );
  26618. }
  26619. }
  26620. },
  26621. // remove a targeted clip from the cache
  26622. uncacheAction: function ( clip, optionalRoot ) {
  26623. var action = this.existingAction( clip, optionalRoot );
  26624. if ( action !== null ) {
  26625. this._deactivateAction( action );
  26626. this._removeInactiveAction( action );
  26627. }
  26628. }
  26629. } );
  26630. /**
  26631. * @author mrdoob / http://mrdoob.com/
  26632. */
  26633. function Uniform( value ) {
  26634. if ( typeof value === 'string' ) {
  26635. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26636. value = arguments[ 1 ];
  26637. }
  26638. this.value = value;
  26639. }
  26640. Uniform.prototype.clone = function () {
  26641. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26642. };
  26643. /**
  26644. * @author benaadams / https://twitter.com/ben_a_adams
  26645. */
  26646. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26647. InterleavedBuffer.call( this, array, stride );
  26648. this.meshPerAttribute = meshPerAttribute || 1;
  26649. }
  26650. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26651. constructor: InstancedInterleavedBuffer,
  26652. isInstancedInterleavedBuffer: true,
  26653. copy: function ( source ) {
  26654. InterleavedBuffer.prototype.copy.call( this, source );
  26655. this.meshPerAttribute = source.meshPerAttribute;
  26656. return this;
  26657. }
  26658. } );
  26659. /**
  26660. * @author mrdoob / http://mrdoob.com/
  26661. * @author bhouston / http://clara.io/
  26662. * @author stephomi / http://stephaneginier.com/
  26663. */
  26664. function Raycaster( origin, direction, near, far ) {
  26665. this.ray = new Ray( origin, direction );
  26666. // direction is assumed to be normalized (for accurate distance calculations)
  26667. this.near = near || 0;
  26668. this.far = far || Infinity;
  26669. this.params = {
  26670. Mesh: {},
  26671. Line: {},
  26672. LOD: {},
  26673. Points: { threshold: 1 },
  26674. Sprite: {}
  26675. };
  26676. Object.defineProperties( this.params, {
  26677. PointCloud: {
  26678. get: function () {
  26679. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26680. return this.Points;
  26681. }
  26682. }
  26683. } );
  26684. }
  26685. function ascSort( a, b ) {
  26686. return a.distance - b.distance;
  26687. }
  26688. function intersectObject( object, raycaster, intersects, recursive ) {
  26689. if ( object.visible === false ) return;
  26690. object.raycast( raycaster, intersects );
  26691. if ( recursive === true ) {
  26692. var children = object.children;
  26693. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26694. intersectObject( children[ i ], raycaster, intersects, true );
  26695. }
  26696. }
  26697. }
  26698. Object.assign( Raycaster.prototype, {
  26699. linePrecision: 1,
  26700. set: function ( origin, direction ) {
  26701. // direction is assumed to be normalized (for accurate distance calculations)
  26702. this.ray.set( origin, direction );
  26703. },
  26704. setFromCamera: function ( coords, camera ) {
  26705. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26706. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26707. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26708. this._camera = camera;
  26709. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26710. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26711. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26712. this._camera = camera;
  26713. } else {
  26714. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26715. }
  26716. },
  26717. intersectObject: function ( object, recursive, optionalTarget ) {
  26718. var intersects = optionalTarget || [];
  26719. intersectObject( object, this, intersects, recursive );
  26720. intersects.sort( ascSort );
  26721. return intersects;
  26722. },
  26723. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26724. var intersects = optionalTarget || [];
  26725. if ( Array.isArray( objects ) === false ) {
  26726. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26727. return intersects;
  26728. }
  26729. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26730. intersectObject( objects[ i ], this, intersects, recursive );
  26731. }
  26732. intersects.sort( ascSort );
  26733. return intersects;
  26734. }
  26735. } );
  26736. /**
  26737. * @author bhouston / http://clara.io
  26738. * @author WestLangley / http://github.com/WestLangley
  26739. *
  26740. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26741. *
  26742. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26743. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26744. */
  26745. function Spherical( radius, phi, theta ) {
  26746. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26747. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26748. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26749. return this;
  26750. }
  26751. Object.assign( Spherical.prototype, {
  26752. set: function ( radius, phi, theta ) {
  26753. this.radius = radius;
  26754. this.phi = phi;
  26755. this.theta = theta;
  26756. return this;
  26757. },
  26758. clone: function () {
  26759. return new this.constructor().copy( this );
  26760. },
  26761. copy: function ( other ) {
  26762. this.radius = other.radius;
  26763. this.phi = other.phi;
  26764. this.theta = other.theta;
  26765. return this;
  26766. },
  26767. // restrict phi to be betwee EPS and PI-EPS
  26768. makeSafe: function () {
  26769. var EPS = 0.000001;
  26770. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26771. return this;
  26772. },
  26773. setFromVector3: function ( v ) {
  26774. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26775. },
  26776. setFromCartesianCoords: function ( x, y, z ) {
  26777. this.radius = Math.sqrt( x * x + y * y + z * z );
  26778. if ( this.radius === 0 ) {
  26779. this.theta = 0;
  26780. this.phi = 0;
  26781. } else {
  26782. this.theta = Math.atan2( x, z );
  26783. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26784. }
  26785. return this;
  26786. }
  26787. } );
  26788. /**
  26789. * @author Mugen87 / https://github.com/Mugen87
  26790. *
  26791. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26792. *
  26793. */
  26794. function Cylindrical( radius, theta, y ) {
  26795. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26796. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26797. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26798. return this;
  26799. }
  26800. Object.assign( Cylindrical.prototype, {
  26801. set: function ( radius, theta, y ) {
  26802. this.radius = radius;
  26803. this.theta = theta;
  26804. this.y = y;
  26805. return this;
  26806. },
  26807. clone: function () {
  26808. return new this.constructor().copy( this );
  26809. },
  26810. copy: function ( other ) {
  26811. this.radius = other.radius;
  26812. this.theta = other.theta;
  26813. this.y = other.y;
  26814. return this;
  26815. },
  26816. setFromVector3: function ( v ) {
  26817. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26818. },
  26819. setFromCartesianCoords: function ( x, y, z ) {
  26820. this.radius = Math.sqrt( x * x + z * z );
  26821. this.theta = Math.atan2( x, z );
  26822. this.y = y;
  26823. return this;
  26824. }
  26825. } );
  26826. /**
  26827. * @author bhouston / http://clara.io
  26828. */
  26829. var _vector$6;
  26830. function Box2( min, max ) {
  26831. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26832. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26833. }
  26834. Object.assign( Box2.prototype, {
  26835. set: function ( min, max ) {
  26836. this.min.copy( min );
  26837. this.max.copy( max );
  26838. return this;
  26839. },
  26840. setFromPoints: function ( points ) {
  26841. this.makeEmpty();
  26842. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26843. this.expandByPoint( points[ i ] );
  26844. }
  26845. return this;
  26846. },
  26847. setFromCenterAndSize: function ( center, size ) {
  26848. if ( _vector$6 === undefined ) _vector$6 = new Vector2();
  26849. var halfSize = _vector$6.copy( size ).multiplyScalar( 0.5 );
  26850. this.min.copy( center ).sub( halfSize );
  26851. this.max.copy( center ).add( halfSize );
  26852. return this;
  26853. },
  26854. clone: function () {
  26855. return new this.constructor().copy( this );
  26856. },
  26857. copy: function ( box ) {
  26858. this.min.copy( box.min );
  26859. this.max.copy( box.max );
  26860. return this;
  26861. },
  26862. makeEmpty: function () {
  26863. this.min.x = this.min.y = + Infinity;
  26864. this.max.x = this.max.y = - Infinity;
  26865. return this;
  26866. },
  26867. isEmpty: function () {
  26868. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26869. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26870. },
  26871. getCenter: function ( target ) {
  26872. if ( target === undefined ) {
  26873. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26874. target = new Vector2();
  26875. }
  26876. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26877. },
  26878. getSize: function ( target ) {
  26879. if ( target === undefined ) {
  26880. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26881. target = new Vector2();
  26882. }
  26883. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26884. },
  26885. expandByPoint: function ( point ) {
  26886. this.min.min( point );
  26887. this.max.max( point );
  26888. return this;
  26889. },
  26890. expandByVector: function ( vector ) {
  26891. this.min.sub( vector );
  26892. this.max.add( vector );
  26893. return this;
  26894. },
  26895. expandByScalar: function ( scalar ) {
  26896. this.min.addScalar( - scalar );
  26897. this.max.addScalar( scalar );
  26898. return this;
  26899. },
  26900. containsPoint: function ( point ) {
  26901. return point.x < this.min.x || point.x > this.max.x ||
  26902. point.y < this.min.y || point.y > this.max.y ? false : true;
  26903. },
  26904. containsBox: function ( box ) {
  26905. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26906. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26907. },
  26908. getParameter: function ( point, target ) {
  26909. // This can potentially have a divide by zero if the box
  26910. // has a size dimension of 0.
  26911. if ( target === undefined ) {
  26912. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26913. target = new Vector2();
  26914. }
  26915. return target.set(
  26916. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26917. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26918. );
  26919. },
  26920. intersectsBox: function ( box ) {
  26921. // using 4 splitting planes to rule out intersections
  26922. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26923. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26924. },
  26925. clampPoint: function ( point, target ) {
  26926. if ( target === undefined ) {
  26927. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26928. target = new Vector2();
  26929. }
  26930. return target.copy( point ).clamp( this.min, this.max );
  26931. },
  26932. distanceToPoint: function ( point ) {
  26933. if ( _vector$6 === undefined ) _vector$6 = new Vector2();
  26934. var clampedPoint = _vector$6.copy( point ).clamp( this.min, this.max );
  26935. return clampedPoint.sub( point ).length();
  26936. },
  26937. intersect: function ( box ) {
  26938. this.min.max( box.min );
  26939. this.max.min( box.max );
  26940. return this;
  26941. },
  26942. union: function ( box ) {
  26943. this.min.min( box.min );
  26944. this.max.max( box.max );
  26945. return this;
  26946. },
  26947. translate: function ( offset ) {
  26948. this.min.add( offset );
  26949. this.max.add( offset );
  26950. return this;
  26951. },
  26952. equals: function ( box ) {
  26953. return box.min.equals( this.min ) && box.max.equals( this.max );
  26954. }
  26955. } );
  26956. /**
  26957. * @author bhouston / http://clara.io
  26958. */
  26959. var _startP, _startEnd;
  26960. function Line3( start, end ) {
  26961. this.start = ( start !== undefined ) ? start : new Vector3();
  26962. this.end = ( end !== undefined ) ? end : new Vector3();
  26963. }
  26964. Object.assign( Line3.prototype, {
  26965. set: function ( start, end ) {
  26966. this.start.copy( start );
  26967. this.end.copy( end );
  26968. return this;
  26969. },
  26970. clone: function () {
  26971. return new this.constructor().copy( this );
  26972. },
  26973. copy: function ( line ) {
  26974. this.start.copy( line.start );
  26975. this.end.copy( line.end );
  26976. return this;
  26977. },
  26978. getCenter: function ( target ) {
  26979. if ( target === undefined ) {
  26980. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26981. target = new Vector3();
  26982. }
  26983. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26984. },
  26985. delta: function ( target ) {
  26986. if ( target === undefined ) {
  26987. console.warn( 'THREE.Line3: .delta() target is now required' );
  26988. target = new Vector3();
  26989. }
  26990. return target.subVectors( this.end, this.start );
  26991. },
  26992. distanceSq: function () {
  26993. return this.start.distanceToSquared( this.end );
  26994. },
  26995. distance: function () {
  26996. return this.start.distanceTo( this.end );
  26997. },
  26998. at: function ( t, target ) {
  26999. if ( target === undefined ) {
  27000. console.warn( 'THREE.Line3: .at() target is now required' );
  27001. target = new Vector3();
  27002. }
  27003. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27004. },
  27005. closestPointToPointParameter: function ( point, clampToLine ) {
  27006. if ( _startP === undefined ) {
  27007. _startP = new Vector3();
  27008. _startEnd = new Vector3();
  27009. }
  27010. _startP.subVectors( point, this.start );
  27011. _startEnd.subVectors( this.end, this.start );
  27012. var startEnd2 = _startEnd.dot( _startEnd );
  27013. var startEnd_startP = _startEnd.dot( _startP );
  27014. var t = startEnd_startP / startEnd2;
  27015. if ( clampToLine ) {
  27016. t = _Math.clamp( t, 0, 1 );
  27017. }
  27018. return t;
  27019. },
  27020. closestPointToPoint: function ( point, clampToLine, target ) {
  27021. var t = this.closestPointToPointParameter( point, clampToLine );
  27022. if ( target === undefined ) {
  27023. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27024. target = new Vector3();
  27025. }
  27026. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27027. },
  27028. applyMatrix4: function ( matrix ) {
  27029. this.start.applyMatrix4( matrix );
  27030. this.end.applyMatrix4( matrix );
  27031. return this;
  27032. },
  27033. equals: function ( line ) {
  27034. return line.start.equals( this.start ) && line.end.equals( this.end );
  27035. }
  27036. } );
  27037. /**
  27038. * @author alteredq / http://alteredqualia.com/
  27039. */
  27040. function ImmediateRenderObject( material ) {
  27041. Object3D.call( this );
  27042. this.material = material;
  27043. this.render = function ( /* renderCallback */ ) {};
  27044. }
  27045. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27046. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27047. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27048. /**
  27049. * @author mrdoob / http://mrdoob.com/
  27050. * @author WestLangley / http://github.com/WestLangley
  27051. */
  27052. var _v1$5, _v2$3, _normalMatrix$1, _keys;
  27053. function VertexNormalsHelper( object, size, hex, linewidth ) {
  27054. this.object = object;
  27055. this.size = ( size !== undefined ) ? size : 1;
  27056. var color = ( hex !== undefined ) ? hex : 0xff0000;
  27057. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27058. //
  27059. var nNormals = 0;
  27060. var objGeometry = this.object.geometry;
  27061. if ( objGeometry && objGeometry.isGeometry ) {
  27062. nNormals = objGeometry.faces.length * 3;
  27063. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27064. nNormals = objGeometry.attributes.normal.count;
  27065. }
  27066. //
  27067. var geometry = new BufferGeometry();
  27068. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27069. geometry.addAttribute( 'position', positions );
  27070. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27071. //
  27072. this.matrixAutoUpdate = false;
  27073. this.update();
  27074. }
  27075. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27076. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  27077. VertexNormalsHelper.prototype.update = function () {
  27078. if ( _normalMatrix$1 === undefined ) {
  27079. _v1$5 = new Vector3();
  27080. _v2$3 = new Vector3();
  27081. _normalMatrix$1 = new Matrix3();
  27082. _keys = [ 'a', 'b', 'c' ];
  27083. }
  27084. this.object.updateMatrixWorld( true );
  27085. _normalMatrix$1.getNormalMatrix( this.object.matrixWorld );
  27086. var matrixWorld = this.object.matrixWorld;
  27087. var position = this.geometry.attributes.position;
  27088. //
  27089. var objGeometry = this.object.geometry;
  27090. if ( objGeometry && objGeometry.isGeometry ) {
  27091. var vertices = objGeometry.vertices;
  27092. var faces = objGeometry.faces;
  27093. var idx = 0;
  27094. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27095. var face = faces[ i ];
  27096. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  27097. var vertex = vertices[ face[ _keys[ j ] ] ];
  27098. var normal = face.vertexNormals[ j ];
  27099. _v1$5.copy( vertex ).applyMatrix4( matrixWorld );
  27100. _v2$3.copy( normal ).applyMatrix3( _normalMatrix$1 ).normalize().multiplyScalar( this.size ).add( _v1$5 );
  27101. position.setXYZ( idx, _v1$5.x, _v1$5.y, _v1$5.z );
  27102. idx = idx + 1;
  27103. position.setXYZ( idx, _v2$3.x, _v2$3.y, _v2$3.z );
  27104. idx = idx + 1;
  27105. }
  27106. }
  27107. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27108. var objPos = objGeometry.attributes.position;
  27109. var objNorm = objGeometry.attributes.normal;
  27110. var idx = 0;
  27111. // for simplicity, ignore index and drawcalls, and render every normal
  27112. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  27113. _v1$5.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  27114. _v2$3.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  27115. _v2$3.applyMatrix3( _normalMatrix$1 ).normalize().multiplyScalar( this.size ).add( _v1$5 );
  27116. position.setXYZ( idx, _v1$5.x, _v1$5.y, _v1$5.z );
  27117. idx = idx + 1;
  27118. position.setXYZ( idx, _v2$3.x, _v2$3.y, _v2$3.z );
  27119. idx = idx + 1;
  27120. }
  27121. }
  27122. position.needsUpdate = true;
  27123. };
  27124. /**
  27125. * @author alteredq / http://alteredqualia.com/
  27126. * @author mrdoob / http://mrdoob.com/
  27127. * @author WestLangley / http://github.com/WestLangley
  27128. */
  27129. var _vector$7;
  27130. function SpotLightHelper( light, color ) {
  27131. Object3D.call( this );
  27132. this.light = light;
  27133. this.light.updateMatrixWorld();
  27134. this.matrix = light.matrixWorld;
  27135. this.matrixAutoUpdate = false;
  27136. this.color = color;
  27137. var geometry = new BufferGeometry();
  27138. var positions = [
  27139. 0, 0, 0, 0, 0, 1,
  27140. 0, 0, 0, 1, 0, 1,
  27141. 0, 0, 0, - 1, 0, 1,
  27142. 0, 0, 0, 0, 1, 1,
  27143. 0, 0, 0, 0, - 1, 1
  27144. ];
  27145. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27146. var p1 = ( i / l ) * Math.PI * 2;
  27147. var p2 = ( j / l ) * Math.PI * 2;
  27148. positions.push(
  27149. Math.cos( p1 ), Math.sin( p1 ), 1,
  27150. Math.cos( p2 ), Math.sin( p2 ), 1
  27151. );
  27152. }
  27153. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27154. var material = new LineBasicMaterial( { fog: false } );
  27155. this.cone = new LineSegments( geometry, material );
  27156. this.add( this.cone );
  27157. this.update();
  27158. }
  27159. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  27160. SpotLightHelper.prototype.constructor = SpotLightHelper;
  27161. SpotLightHelper.prototype.dispose = function () {
  27162. this.cone.geometry.dispose();
  27163. this.cone.material.dispose();
  27164. };
  27165. SpotLightHelper.prototype.update = function () {
  27166. if ( _vector$7 === undefined ) _vector$7 = new Vector3();
  27167. this.light.updateMatrixWorld();
  27168. var coneLength = this.light.distance ? this.light.distance : 1000;
  27169. var coneWidth = coneLength * Math.tan( this.light.angle );
  27170. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  27171. _vector$7.setFromMatrixPosition( this.light.target.matrixWorld );
  27172. this.cone.lookAt( _vector$7 );
  27173. if ( this.color !== undefined ) {
  27174. this.cone.material.color.set( this.color );
  27175. } else {
  27176. this.cone.material.color.copy( this.light.color );
  27177. }
  27178. };
  27179. /**
  27180. * @author Sean Griffin / http://twitter.com/sgrif
  27181. * @author Michael Guerrero / http://realitymeltdown.com
  27182. * @author mrdoob / http://mrdoob.com/
  27183. * @author ikerr / http://verold.com
  27184. * @author Mugen87 / https://github.com/Mugen87
  27185. */
  27186. var _vector$8, _boneMatrix, _matrixWorldInv;
  27187. function getBoneList( object ) {
  27188. var boneList = [];
  27189. if ( object && object.isBone ) {
  27190. boneList.push( object );
  27191. }
  27192. for ( var i = 0; i < object.children.length; i ++ ) {
  27193. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  27194. }
  27195. return boneList;
  27196. }
  27197. function SkeletonHelper( object ) {
  27198. var bones = getBoneList( object );
  27199. var geometry = new BufferGeometry();
  27200. var vertices = [];
  27201. var colors = [];
  27202. var color1 = new Color( 0, 0, 1 );
  27203. var color2 = new Color( 0, 1, 0 );
  27204. for ( var i = 0; i < bones.length; i ++ ) {
  27205. var bone = bones[ i ];
  27206. if ( bone.parent && bone.parent.isBone ) {
  27207. vertices.push( 0, 0, 0 );
  27208. vertices.push( 0, 0, 0 );
  27209. colors.push( color1.r, color1.g, color1.b );
  27210. colors.push( color2.r, color2.g, color2.b );
  27211. }
  27212. }
  27213. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27214. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27215. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  27216. LineSegments.call( this, geometry, material );
  27217. this.root = object;
  27218. this.bones = bones;
  27219. this.matrix = object.matrixWorld;
  27220. this.matrixAutoUpdate = false;
  27221. }
  27222. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  27223. SkeletonHelper.prototype.constructor = SkeletonHelper;
  27224. SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
  27225. if ( _matrixWorldInv === undefined ) {
  27226. _vector$8 = new Vector3();
  27227. _boneMatrix = new Matrix4();
  27228. _matrixWorldInv = new Matrix4();
  27229. }
  27230. var bones = this.bones;
  27231. var geometry = this.geometry;
  27232. var position = geometry.getAttribute( 'position' );
  27233. _matrixWorldInv.getInverse( this.root.matrixWorld );
  27234. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  27235. var bone = bones[ i ];
  27236. if ( bone.parent && bone.parent.isBone ) {
  27237. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  27238. _vector$8.setFromMatrixPosition( _boneMatrix );
  27239. position.setXYZ( j, _vector$8.x, _vector$8.y, _vector$8.z );
  27240. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  27241. _vector$8.setFromMatrixPosition( _boneMatrix );
  27242. position.setXYZ( j + 1, _vector$8.x, _vector$8.y, _vector$8.z );
  27243. j += 2;
  27244. }
  27245. }
  27246. geometry.getAttribute( 'position' ).needsUpdate = true;
  27247. Object3D.prototype.updateMatrixWorld.call( this, force );
  27248. };
  27249. /**
  27250. * @author alteredq / http://alteredqualia.com/
  27251. * @author mrdoob / http://mrdoob.com/
  27252. */
  27253. function PointLightHelper( light, sphereSize, color ) {
  27254. this.light = light;
  27255. this.light.updateMatrixWorld();
  27256. this.color = color;
  27257. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  27258. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27259. Mesh.call( this, geometry, material );
  27260. this.matrix = this.light.matrixWorld;
  27261. this.matrixAutoUpdate = false;
  27262. this.update();
  27263. /*
  27264. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27265. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27266. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27267. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27268. var d = light.distance;
  27269. if ( d === 0.0 ) {
  27270. this.lightDistance.visible = false;
  27271. } else {
  27272. this.lightDistance.scale.set( d, d, d );
  27273. }
  27274. this.add( this.lightDistance );
  27275. */
  27276. }
  27277. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27278. PointLightHelper.prototype.constructor = PointLightHelper;
  27279. PointLightHelper.prototype.dispose = function () {
  27280. this.geometry.dispose();
  27281. this.material.dispose();
  27282. };
  27283. PointLightHelper.prototype.update = function () {
  27284. if ( this.color !== undefined ) {
  27285. this.material.color.set( this.color );
  27286. } else {
  27287. this.material.color.copy( this.light.color );
  27288. }
  27289. /*
  27290. var d = this.light.distance;
  27291. if ( d === 0.0 ) {
  27292. this.lightDistance.visible = false;
  27293. } else {
  27294. this.lightDistance.visible = true;
  27295. this.lightDistance.scale.set( d, d, d );
  27296. }
  27297. */
  27298. };
  27299. /**
  27300. * @author abelnation / http://github.com/abelnation
  27301. * @author Mugen87 / http://github.com/Mugen87
  27302. * @author WestLangley / http://github.com/WestLangley
  27303. *
  27304. * This helper must be added as a child of the light
  27305. */
  27306. function RectAreaLightHelper( light, color ) {
  27307. this.type = 'RectAreaLightHelper';
  27308. this.light = light;
  27309. this.color = color; // optional hardwired color for the helper
  27310. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27311. var geometry = new BufferGeometry();
  27312. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27313. geometry.computeBoundingSphere();
  27314. var material = new LineBasicMaterial( { fog: false } );
  27315. Line.call( this, geometry, material );
  27316. //
  27317. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27318. var geometry2 = new BufferGeometry();
  27319. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27320. geometry2.computeBoundingSphere();
  27321. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27322. this.update();
  27323. }
  27324. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27325. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27326. RectAreaLightHelper.prototype.update = function () {
  27327. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27328. if ( this.color !== undefined ) {
  27329. this.material.color.set( this.color );
  27330. this.children[ 0 ].material.color.set( this.color );
  27331. } else {
  27332. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27333. // prevent hue shift
  27334. var c = this.material.color;
  27335. var max = Math.max( c.r, c.g, c.b );
  27336. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27337. this.children[ 0 ].material.color.copy( this.material.color );
  27338. }
  27339. };
  27340. RectAreaLightHelper.prototype.dispose = function () {
  27341. this.geometry.dispose();
  27342. this.material.dispose();
  27343. this.children[ 0 ].geometry.dispose();
  27344. this.children[ 0 ].material.dispose();
  27345. };
  27346. /**
  27347. * @author alteredq / http://alteredqualia.com/
  27348. * @author mrdoob / http://mrdoob.com/
  27349. * @author Mugen87 / https://github.com/Mugen87
  27350. */
  27351. var _vector$9, _color1, _color2;
  27352. function HemisphereLightHelper( light, size, color ) {
  27353. Object3D.call( this );
  27354. this.light = light;
  27355. this.light.updateMatrixWorld();
  27356. this.matrix = light.matrixWorld;
  27357. this.matrixAutoUpdate = false;
  27358. this.color = color;
  27359. var geometry = new OctahedronBufferGeometry( size );
  27360. geometry.rotateY( Math.PI * 0.5 );
  27361. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27362. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27363. var position = geometry.getAttribute( 'position' );
  27364. var colors = new Float32Array( position.count * 3 );
  27365. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27366. this.add( new Mesh( geometry, this.material ) );
  27367. this.update();
  27368. }
  27369. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27370. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27371. HemisphereLightHelper.prototype.dispose = function () {
  27372. this.children[ 0 ].geometry.dispose();
  27373. this.children[ 0 ].material.dispose();
  27374. };
  27375. HemisphereLightHelper.prototype.update = function () {
  27376. if ( _color2 === undefined ) {
  27377. _vector$9 = new Vector3();
  27378. _color1 = new Color();
  27379. _color2 = new Color();
  27380. }
  27381. var mesh = this.children[ 0 ];
  27382. if ( this.color !== undefined ) {
  27383. this.material.color.set( this.color );
  27384. } else {
  27385. var colors = mesh.geometry.getAttribute( 'color' );
  27386. _color1.copy( this.light.color );
  27387. _color2.copy( this.light.groundColor );
  27388. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27389. var color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  27390. colors.setXYZ( i, color.r, color.g, color.b );
  27391. }
  27392. colors.needsUpdate = true;
  27393. }
  27394. mesh.lookAt( _vector$9.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27395. };
  27396. /**
  27397. * @author WestLangley / http://github.com/WestLangley
  27398. */
  27399. function LightProbeHelper( lightProbe, size ) {
  27400. this.lightProbe = lightProbe;
  27401. this.size = size;
  27402. var defines = {};
  27403. defines[ 'GAMMA_OUTPUT' ] = "";
  27404. // material
  27405. var material = new ShaderMaterial( {
  27406. defines: defines,
  27407. uniforms: {
  27408. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  27409. intensity: { value: this.lightProbe.intensity }
  27410. },
  27411. vertexShader: [
  27412. 'varying vec3 vNormal;',
  27413. 'void main() {',
  27414. ' vNormal = normalize( normalMatrix * normal );',
  27415. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  27416. '}',
  27417. ].join( '\n' ),
  27418. fragmentShader: [
  27419. '#define RECIPROCAL_PI 0.318309886',
  27420. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  27421. ' // matrix is assumed to be orthogonal',
  27422. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  27423. '}',
  27424. 'vec3 linearToOutput( in vec3 a ) {',
  27425. ' #ifdef GAMMA_OUTPUT',
  27426. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  27427. ' #else',
  27428. ' return a;',
  27429. ' #endif',
  27430. '}',
  27431. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  27432. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  27433. ' // normal is assumed to have unit length',
  27434. ' float x = normal.x, y = normal.y, z = normal.z;',
  27435. ' // band 0',
  27436. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  27437. ' // band 1',
  27438. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  27439. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  27440. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  27441. ' // band 2',
  27442. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  27443. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  27444. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  27445. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  27446. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  27447. ' return result;',
  27448. '}',
  27449. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  27450. 'uniform float intensity; // light probe intensity',
  27451. 'varying vec3 vNormal;',
  27452. 'void main() {',
  27453. ' vec3 normal = normalize( vNormal );',
  27454. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  27455. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  27456. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  27457. ' outgoingLight = linearToOutput( outgoingLight );',
  27458. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  27459. '}'
  27460. ].join( '\n' )
  27461. } );
  27462. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  27463. Mesh.call( this, geometry, material );
  27464. this.onBeforeRender();
  27465. }
  27466. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  27467. LightProbeHelper.prototype.constructor = LightProbeHelper;
  27468. LightProbeHelper.prototype.dispose = function () {
  27469. this.geometry.dispose();
  27470. this.material.dispose();
  27471. };
  27472. LightProbeHelper.prototype.onBeforeRender = function () {
  27473. this.position.copy( this.lightProbe.position );
  27474. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  27475. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  27476. };
  27477. /**
  27478. * @author mrdoob / http://mrdoob.com/
  27479. */
  27480. function GridHelper( size, divisions, color1, color2 ) {
  27481. size = size || 10;
  27482. divisions = divisions || 10;
  27483. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27484. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27485. var center = divisions / 2;
  27486. var step = size / divisions;
  27487. var halfSize = size / 2;
  27488. var vertices = [], colors = [];
  27489. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27490. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27491. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27492. var color = i === center ? color1 : color2;
  27493. color.toArray( colors, j ); j += 3;
  27494. color.toArray( colors, j ); j += 3;
  27495. color.toArray( colors, j ); j += 3;
  27496. color.toArray( colors, j ); j += 3;
  27497. }
  27498. var geometry = new BufferGeometry();
  27499. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27500. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27501. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27502. LineSegments.call( this, geometry, material );
  27503. }
  27504. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27505. constructor: GridHelper,
  27506. copy: function ( source ) {
  27507. LineSegments.prototype.copy.call( this, source );
  27508. this.geometry.copy( source.geometry );
  27509. this.material.copy( source.material );
  27510. return this;
  27511. },
  27512. clone: function () {
  27513. return new this.constructor().copy( this );
  27514. }
  27515. } );
  27516. /**
  27517. * @author mrdoob / http://mrdoob.com/
  27518. * @author Mugen87 / http://github.com/Mugen87
  27519. * @author Hectate / http://www.github.com/Hectate
  27520. */
  27521. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27522. radius = radius || 10;
  27523. radials = radials || 16;
  27524. circles = circles || 8;
  27525. divisions = divisions || 64;
  27526. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27527. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27528. var vertices = [];
  27529. var colors = [];
  27530. var x, z;
  27531. var v, i, j, r, color;
  27532. // create the radials
  27533. for ( i = 0; i <= radials; i ++ ) {
  27534. v = ( i / radials ) * ( Math.PI * 2 );
  27535. x = Math.sin( v ) * radius;
  27536. z = Math.cos( v ) * radius;
  27537. vertices.push( 0, 0, 0 );
  27538. vertices.push( x, 0, z );
  27539. color = ( i & 1 ) ? color1 : color2;
  27540. colors.push( color.r, color.g, color.b );
  27541. colors.push( color.r, color.g, color.b );
  27542. }
  27543. // create the circles
  27544. for ( i = 0; i <= circles; i ++ ) {
  27545. color = ( i & 1 ) ? color1 : color2;
  27546. r = radius - ( radius / circles * i );
  27547. for ( j = 0; j < divisions; j ++ ) {
  27548. // first vertex
  27549. v = ( j / divisions ) * ( Math.PI * 2 );
  27550. x = Math.sin( v ) * r;
  27551. z = Math.cos( v ) * r;
  27552. vertices.push( x, 0, z );
  27553. colors.push( color.r, color.g, color.b );
  27554. // second vertex
  27555. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27556. x = Math.sin( v ) * r;
  27557. z = Math.cos( v ) * r;
  27558. vertices.push( x, 0, z );
  27559. colors.push( color.r, color.g, color.b );
  27560. }
  27561. }
  27562. var geometry = new BufferGeometry();
  27563. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27564. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27565. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27566. LineSegments.call( this, geometry, material );
  27567. }
  27568. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27569. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27570. /**
  27571. * @author Mugen87 / http://github.com/Mugen87
  27572. */
  27573. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27574. this.audio = audio;
  27575. this.range = range || 1;
  27576. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27577. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27578. var geometry = new BufferGeometry();
  27579. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27580. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27581. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27582. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27583. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27584. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27585. this.update();
  27586. }
  27587. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27588. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27589. PositionalAudioHelper.prototype.update = function () {
  27590. var audio = this.audio;
  27591. var range = this.range;
  27592. var divisionsInnerAngle = this.divisionsInnerAngle;
  27593. var divisionsOuterAngle = this.divisionsOuterAngle;
  27594. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27595. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27596. var halfConeInnerAngle = coneInnerAngle / 2;
  27597. var halfConeOuterAngle = coneOuterAngle / 2;
  27598. var start = 0;
  27599. var count = 0;
  27600. var i, stride;
  27601. var geometry = this.geometry;
  27602. var positionAttribute = geometry.attributes.position;
  27603. geometry.clearGroups();
  27604. //
  27605. function generateSegment( from, to, divisions, materialIndex ) {
  27606. var step = ( to - from ) / divisions;
  27607. positionAttribute.setXYZ( start, 0, 0, 0 );
  27608. count ++;
  27609. for ( i = from; i < to; i += step ) {
  27610. stride = start + count;
  27611. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27612. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27613. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27614. count += 3;
  27615. }
  27616. geometry.addGroup( start, count, materialIndex );
  27617. start += count;
  27618. count = 0;
  27619. }
  27620. //
  27621. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27622. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27623. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27624. //
  27625. positionAttribute.needsUpdate = true;
  27626. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27627. };
  27628. PositionalAudioHelper.prototype.dispose = function () {
  27629. this.geometry.dispose();
  27630. this.material[ 0 ].dispose();
  27631. this.material[ 1 ].dispose();
  27632. };
  27633. /**
  27634. * @author mrdoob / http://mrdoob.com/
  27635. * @author WestLangley / http://github.com/WestLangley
  27636. */
  27637. var _v1$6, _v2$4, _normalMatrix$2;
  27638. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27639. // FaceNormalsHelper only supports THREE.Geometry
  27640. this.object = object;
  27641. this.size = ( size !== undefined ) ? size : 1;
  27642. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27643. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27644. //
  27645. var nNormals = 0;
  27646. var objGeometry = this.object.geometry;
  27647. if ( objGeometry && objGeometry.isGeometry ) {
  27648. nNormals = objGeometry.faces.length;
  27649. } else {
  27650. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27651. }
  27652. //
  27653. var geometry = new BufferGeometry();
  27654. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27655. geometry.addAttribute( 'position', positions );
  27656. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27657. //
  27658. this.matrixAutoUpdate = false;
  27659. this.update();
  27660. }
  27661. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27662. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27663. FaceNormalsHelper.prototype.update = function () {
  27664. if ( _normalMatrix$2 === undefined ) {
  27665. _v1$6 = new Vector3();
  27666. _v2$4 = new Vector3();
  27667. _normalMatrix$2 = new Matrix3();
  27668. }
  27669. this.object.updateMatrixWorld( true );
  27670. _normalMatrix$2.getNormalMatrix( this.object.matrixWorld );
  27671. var matrixWorld = this.object.matrixWorld;
  27672. var position = this.geometry.attributes.position;
  27673. //
  27674. var objGeometry = this.object.geometry;
  27675. var vertices = objGeometry.vertices;
  27676. var faces = objGeometry.faces;
  27677. var idx = 0;
  27678. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27679. var face = faces[ i ];
  27680. var normal = face.normal;
  27681. _v1$6.copy( vertices[ face.a ] )
  27682. .add( vertices[ face.b ] )
  27683. .add( vertices[ face.c ] )
  27684. .divideScalar( 3 )
  27685. .applyMatrix4( matrixWorld );
  27686. _v2$4.copy( normal ).applyMatrix3( _normalMatrix$2 ).normalize().multiplyScalar( this.size ).add( _v1$6 );
  27687. position.setXYZ( idx, _v1$6.x, _v1$6.y, _v1$6.z );
  27688. idx = idx + 1;
  27689. position.setXYZ( idx, _v2$4.x, _v2$4.y, _v2$4.z );
  27690. idx = idx + 1;
  27691. }
  27692. position.needsUpdate = true;
  27693. };
  27694. /**
  27695. * @author alteredq / http://alteredqualia.com/
  27696. * @author mrdoob / http://mrdoob.com/
  27697. * @author WestLangley / http://github.com/WestLangley
  27698. */
  27699. var _v1$7, _v2$5, _v3$1;
  27700. function DirectionalLightHelper( light, size, color ) {
  27701. Object3D.call( this );
  27702. this.light = light;
  27703. this.light.updateMatrixWorld();
  27704. this.matrix = light.matrixWorld;
  27705. this.matrixAutoUpdate = false;
  27706. this.color = color;
  27707. if ( size === undefined ) size = 1;
  27708. var geometry = new BufferGeometry();
  27709. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27710. - size, size, 0,
  27711. size, size, 0,
  27712. size, - size, 0,
  27713. - size, - size, 0,
  27714. - size, size, 0
  27715. ], 3 ) );
  27716. var material = new LineBasicMaterial( { fog: false } );
  27717. this.lightPlane = new Line( geometry, material );
  27718. this.add( this.lightPlane );
  27719. geometry = new BufferGeometry();
  27720. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27721. this.targetLine = new Line( geometry, material );
  27722. this.add( this.targetLine );
  27723. this.update();
  27724. }
  27725. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27726. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27727. DirectionalLightHelper.prototype.dispose = function () {
  27728. this.lightPlane.geometry.dispose();
  27729. this.lightPlane.material.dispose();
  27730. this.targetLine.geometry.dispose();
  27731. this.targetLine.material.dispose();
  27732. };
  27733. DirectionalLightHelper.prototype.update = function () {
  27734. if ( _v3$1 === undefined ) {
  27735. _v1$7 = new Vector3();
  27736. _v2$5 = new Vector3();
  27737. _v3$1 = new Vector3();
  27738. }
  27739. _v1$7.setFromMatrixPosition( this.light.matrixWorld );
  27740. _v2$5.setFromMatrixPosition( this.light.target.matrixWorld );
  27741. _v3$1.subVectors( _v2$5, _v1$7 );
  27742. this.lightPlane.lookAt( _v2$5 );
  27743. if ( this.color !== undefined ) {
  27744. this.lightPlane.material.color.set( this.color );
  27745. this.targetLine.material.color.set( this.color );
  27746. } else {
  27747. this.lightPlane.material.color.copy( this.light.color );
  27748. this.targetLine.material.color.copy( this.light.color );
  27749. }
  27750. this.targetLine.lookAt( _v2$5 );
  27751. this.targetLine.scale.z = _v3$1.length();
  27752. };
  27753. /**
  27754. * @author alteredq / http://alteredqualia.com/
  27755. * @author Mugen87 / https://github.com/Mugen87
  27756. *
  27757. * - shows frustum, line of sight and up of the camera
  27758. * - suitable for fast updates
  27759. * - based on frustum visualization in lightgl.js shadowmap example
  27760. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27761. */
  27762. var _vector$a, _camera;
  27763. function CameraHelper( camera ) {
  27764. var geometry = new BufferGeometry();
  27765. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27766. var vertices = [];
  27767. var colors = [];
  27768. var pointMap = {};
  27769. // colors
  27770. var colorFrustum = new Color( 0xffaa00 );
  27771. var colorCone = new Color( 0xff0000 );
  27772. var colorUp = new Color( 0x00aaff );
  27773. var colorTarget = new Color( 0xffffff );
  27774. var colorCross = new Color( 0x333333 );
  27775. // near
  27776. addLine( 'n1', 'n2', colorFrustum );
  27777. addLine( 'n2', 'n4', colorFrustum );
  27778. addLine( 'n4', 'n3', colorFrustum );
  27779. addLine( 'n3', 'n1', colorFrustum );
  27780. // far
  27781. addLine( 'f1', 'f2', colorFrustum );
  27782. addLine( 'f2', 'f4', colorFrustum );
  27783. addLine( 'f4', 'f3', colorFrustum );
  27784. addLine( 'f3', 'f1', colorFrustum );
  27785. // sides
  27786. addLine( 'n1', 'f1', colorFrustum );
  27787. addLine( 'n2', 'f2', colorFrustum );
  27788. addLine( 'n3', 'f3', colorFrustum );
  27789. addLine( 'n4', 'f4', colorFrustum );
  27790. // cone
  27791. addLine( 'p', 'n1', colorCone );
  27792. addLine( 'p', 'n2', colorCone );
  27793. addLine( 'p', 'n3', colorCone );
  27794. addLine( 'p', 'n4', colorCone );
  27795. // up
  27796. addLine( 'u1', 'u2', colorUp );
  27797. addLine( 'u2', 'u3', colorUp );
  27798. addLine( 'u3', 'u1', colorUp );
  27799. // target
  27800. addLine( 'c', 't', colorTarget );
  27801. addLine( 'p', 'c', colorCross );
  27802. // cross
  27803. addLine( 'cn1', 'cn2', colorCross );
  27804. addLine( 'cn3', 'cn4', colorCross );
  27805. addLine( 'cf1', 'cf2', colorCross );
  27806. addLine( 'cf3', 'cf4', colorCross );
  27807. function addLine( a, b, color ) {
  27808. addPoint( a, color );
  27809. addPoint( b, color );
  27810. }
  27811. function addPoint( id, color ) {
  27812. vertices.push( 0, 0, 0 );
  27813. colors.push( color.r, color.g, color.b );
  27814. if ( pointMap[ id ] === undefined ) {
  27815. pointMap[ id ] = [];
  27816. }
  27817. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27818. }
  27819. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27820. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27821. LineSegments.call( this, geometry, material );
  27822. this.camera = camera;
  27823. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27824. this.matrix = camera.matrixWorld;
  27825. this.matrixAutoUpdate = false;
  27826. this.pointMap = pointMap;
  27827. this.update();
  27828. }
  27829. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27830. CameraHelper.prototype.constructor = CameraHelper;
  27831. CameraHelper.prototype.update = function () {
  27832. if ( _camera === undefined ) _camera = new Camera();
  27833. var geometry = this.geometry;
  27834. var pointMap = this.pointMap;
  27835. var w = 1, h = 1;
  27836. // we need just camera projection matrix inverse
  27837. // world matrix must be identity
  27838. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27839. // center / target
  27840. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  27841. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  27842. // near
  27843. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  27844. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  27845. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  27846. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  27847. // far
  27848. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  27849. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  27850. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  27851. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  27852. // up
  27853. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  27854. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  27855. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  27856. // cross
  27857. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  27858. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  27859. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  27860. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  27861. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  27862. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  27863. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  27864. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  27865. geometry.getAttribute( 'position' ).needsUpdate = true;
  27866. };
  27867. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  27868. if ( _vector$a === undefined ) _vector$a = new Vector3();
  27869. _vector$a.set( x, y, z ).unproject( camera );
  27870. var points = pointMap[ point ];
  27871. if ( points !== undefined ) {
  27872. var position = geometry.getAttribute( 'position' );
  27873. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27874. position.setXYZ( points[ i ], _vector$a.x, _vector$a.y, _vector$a.z );
  27875. }
  27876. }
  27877. }
  27878. /**
  27879. * @author mrdoob / http://mrdoob.com/
  27880. * @author Mugen87 / http://github.com/Mugen87
  27881. */
  27882. var _box$2;
  27883. function BoxHelper( object, color ) {
  27884. this.object = object;
  27885. if ( color === undefined ) color = 0xffff00;
  27886. 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 ] );
  27887. var positions = new Float32Array( 8 * 3 );
  27888. var geometry = new BufferGeometry();
  27889. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27890. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27891. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27892. this.matrixAutoUpdate = false;
  27893. this.update();
  27894. }
  27895. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27896. BoxHelper.prototype.constructor = BoxHelper;
  27897. BoxHelper.prototype.update = function ( object ) {
  27898. if ( _box$2 === undefined ) _box$2 = new Box3();
  27899. if ( object !== undefined ) {
  27900. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27901. }
  27902. if ( this.object !== undefined ) {
  27903. _box$2.setFromObject( this.object );
  27904. }
  27905. if ( _box$2.isEmpty() ) return;
  27906. var min = _box$2.min;
  27907. var max = _box$2.max;
  27908. /*
  27909. 5____4
  27910. 1/___0/|
  27911. | 6__|_7
  27912. 2/___3/
  27913. 0: max.x, max.y, max.z
  27914. 1: min.x, max.y, max.z
  27915. 2: min.x, min.y, max.z
  27916. 3: max.x, min.y, max.z
  27917. 4: max.x, max.y, min.z
  27918. 5: min.x, max.y, min.z
  27919. 6: min.x, min.y, min.z
  27920. 7: max.x, min.y, min.z
  27921. */
  27922. var position = this.geometry.attributes.position;
  27923. var array = position.array;
  27924. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27925. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27926. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27927. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27928. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27929. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27930. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27931. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27932. position.needsUpdate = true;
  27933. this.geometry.computeBoundingSphere();
  27934. };
  27935. BoxHelper.prototype.setFromObject = function ( object ) {
  27936. this.object = object;
  27937. this.update();
  27938. return this;
  27939. };
  27940. BoxHelper.prototype.copy = function ( source ) {
  27941. LineSegments.prototype.copy.call( this, source );
  27942. this.object = source.object;
  27943. return this;
  27944. };
  27945. BoxHelper.prototype.clone = function () {
  27946. return new this.constructor().copy( this );
  27947. };
  27948. /**
  27949. * @author WestLangley / http://github.com/WestLangley
  27950. */
  27951. function Box3Helper( box, color ) {
  27952. this.type = 'Box3Helper';
  27953. this.box = box;
  27954. color = color || 0xffff00;
  27955. 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 ] );
  27956. 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 ];
  27957. var geometry = new BufferGeometry();
  27958. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27959. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27960. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27961. this.geometry.computeBoundingSphere();
  27962. }
  27963. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27964. Box3Helper.prototype.constructor = Box3Helper;
  27965. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27966. var box = this.box;
  27967. if ( box.isEmpty() ) return;
  27968. box.getCenter( this.position );
  27969. box.getSize( this.scale );
  27970. this.scale.multiplyScalar( 0.5 );
  27971. Object3D.prototype.updateMatrixWorld.call( this, force );
  27972. };
  27973. /**
  27974. * @author WestLangley / http://github.com/WestLangley
  27975. */
  27976. function PlaneHelper( plane, size, hex ) {
  27977. this.type = 'PlaneHelper';
  27978. this.plane = plane;
  27979. this.size = ( size === undefined ) ? 1 : size;
  27980. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27981. 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 ];
  27982. var geometry = new BufferGeometry();
  27983. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27984. geometry.computeBoundingSphere();
  27985. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27986. //
  27987. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27988. var geometry2 = new BufferGeometry();
  27989. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27990. geometry2.computeBoundingSphere();
  27991. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27992. }
  27993. PlaneHelper.prototype = Object.create( Line.prototype );
  27994. PlaneHelper.prototype.constructor = PlaneHelper;
  27995. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27996. var scale = - this.plane.constant;
  27997. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27998. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27999. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28000. this.lookAt( this.plane.normal );
  28001. Object3D.prototype.updateMatrixWorld.call( this, force );
  28002. };
  28003. /**
  28004. * @author WestLangley / http://github.com/WestLangley
  28005. * @author zz85 / http://github.com/zz85
  28006. * @author bhouston / http://clara.io
  28007. *
  28008. * Creates an arrow for visualizing directions
  28009. *
  28010. * Parameters:
  28011. * dir - Vector3
  28012. * origin - Vector3
  28013. * length - Number
  28014. * color - color in hex value
  28015. * headLength - Number
  28016. * headWidth - Number
  28017. */
  28018. var _axis;
  28019. var _lineGeometry, _coneGeometry;
  28020. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  28021. // dir is assumed to be normalized
  28022. Object3D.call( this );
  28023. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28024. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28025. if ( length === undefined ) length = 1;
  28026. if ( color === undefined ) color = 0xffff00;
  28027. if ( headLength === undefined ) headLength = 0.2 * length;
  28028. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28029. if ( _lineGeometry === undefined ) {
  28030. _lineGeometry = new BufferGeometry();
  28031. _lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28032. _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28033. _coneGeometry.translate( 0, - 0.5, 0 );
  28034. }
  28035. this.position.copy( origin );
  28036. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color } ) );
  28037. this.line.matrixAutoUpdate = false;
  28038. this.add( this.line );
  28039. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color } ) );
  28040. this.cone.matrixAutoUpdate = false;
  28041. this.add( this.cone );
  28042. this.setDirection( dir );
  28043. this.setLength( length, headLength, headWidth );
  28044. }
  28045. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28046. ArrowHelper.prototype.constructor = ArrowHelper;
  28047. ArrowHelper.prototype.setDirection = function ( dir ) {
  28048. if ( _axis === undefined ) _axis = new Vector3();
  28049. // dir is assumed to be normalized
  28050. if ( dir.y > 0.99999 ) {
  28051. this.quaternion.set( 0, 0, 0, 1 );
  28052. } else if ( dir.y < - 0.99999 ) {
  28053. this.quaternion.set( 1, 0, 0, 0 );
  28054. } else {
  28055. _axis.set( dir.z, 0, - dir.x ).normalize();
  28056. var radians = Math.acos( dir.y );
  28057. this.quaternion.setFromAxisAngle( _axis, radians );
  28058. }
  28059. };
  28060. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28061. if ( headLength === undefined ) headLength = 0.2 * length;
  28062. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28063. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  28064. this.line.updateMatrix();
  28065. this.cone.scale.set( headWidth, headLength, headWidth );
  28066. this.cone.position.y = length;
  28067. this.cone.updateMatrix();
  28068. };
  28069. ArrowHelper.prototype.setColor = function ( color ) {
  28070. this.line.material.color.set( color );
  28071. this.cone.material.color.set( color );
  28072. };
  28073. ArrowHelper.prototype.copy = function ( source ) {
  28074. Object3D.prototype.copy.call( this, source, false );
  28075. this.line.copy( source.line );
  28076. this.cone.copy( source.cone );
  28077. return this;
  28078. };
  28079. ArrowHelper.prototype.clone = function () {
  28080. return new this.constructor().copy( this );
  28081. };
  28082. /**
  28083. * @author sroucheray / http://sroucheray.org/
  28084. * @author mrdoob / http://mrdoob.com/
  28085. */
  28086. function AxesHelper( size ) {
  28087. size = size || 1;
  28088. var vertices = [
  28089. 0, 0, 0, size, 0, 0,
  28090. 0, 0, 0, 0, size, 0,
  28091. 0, 0, 0, 0, 0, size
  28092. ];
  28093. var colors = [
  28094. 1, 0, 0, 1, 0.6, 0,
  28095. 0, 1, 0, 0.6, 1, 0,
  28096. 0, 0, 1, 0, 0.6, 1
  28097. ];
  28098. var geometry = new BufferGeometry();
  28099. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28100. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28101. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28102. LineSegments.call( this, geometry, material );
  28103. }
  28104. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28105. AxesHelper.prototype.constructor = AxesHelper;
  28106. /**
  28107. * @author mrdoob / http://mrdoob.com/
  28108. */
  28109. function Face4( a, b, c, d, normal, color, materialIndex ) {
  28110. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  28111. return new Face3( a, b, c, normal, color, materialIndex );
  28112. }
  28113. var LineStrip = 0;
  28114. var LinePieces = 1;
  28115. function MeshFaceMaterial( materials ) {
  28116. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28117. return materials;
  28118. }
  28119. function MultiMaterial( materials ) {
  28120. if ( materials === undefined ) materials = [];
  28121. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28122. materials.isMultiMaterial = true;
  28123. materials.materials = materials;
  28124. materials.clone = function () {
  28125. return materials.slice();
  28126. };
  28127. return materials;
  28128. }
  28129. function PointCloud( geometry, material ) {
  28130. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28131. return new Points( geometry, material );
  28132. }
  28133. function Particle( material ) {
  28134. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28135. return new Sprite( material );
  28136. }
  28137. function ParticleSystem( geometry, material ) {
  28138. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28139. return new Points( geometry, material );
  28140. }
  28141. function PointCloudMaterial( parameters ) {
  28142. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28143. return new PointsMaterial( parameters );
  28144. }
  28145. function ParticleBasicMaterial( parameters ) {
  28146. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28147. return new PointsMaterial( parameters );
  28148. }
  28149. function ParticleSystemMaterial( parameters ) {
  28150. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  28151. return new PointsMaterial( parameters );
  28152. }
  28153. function Vertex( x, y, z ) {
  28154. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  28155. return new Vector3( x, y, z );
  28156. }
  28157. //
  28158. function DynamicBufferAttribute( array, itemSize ) {
  28159. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  28160. return new BufferAttribute( array, itemSize ).setDynamic( true );
  28161. }
  28162. function Int8Attribute( array, itemSize ) {
  28163. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  28164. return new Int8BufferAttribute( array, itemSize );
  28165. }
  28166. function Uint8Attribute( array, itemSize ) {
  28167. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  28168. return new Uint8BufferAttribute( array, itemSize );
  28169. }
  28170. function Uint8ClampedAttribute( array, itemSize ) {
  28171. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  28172. return new Uint8ClampedBufferAttribute( array, itemSize );
  28173. }
  28174. function Int16Attribute( array, itemSize ) {
  28175. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  28176. return new Int16BufferAttribute( array, itemSize );
  28177. }
  28178. function Uint16Attribute( array, itemSize ) {
  28179. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  28180. return new Uint16BufferAttribute( array, itemSize );
  28181. }
  28182. function Int32Attribute( array, itemSize ) {
  28183. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28184. return new Int32BufferAttribute( array, itemSize );
  28185. }
  28186. function Uint32Attribute( array, itemSize ) {
  28187. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28188. return new Uint32BufferAttribute( array, itemSize );
  28189. }
  28190. function Float32Attribute( array, itemSize ) {
  28191. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28192. return new Float32BufferAttribute( array, itemSize );
  28193. }
  28194. function Float64Attribute( array, itemSize ) {
  28195. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28196. return new Float64BufferAttribute( array, itemSize );
  28197. }
  28198. //
  28199. Curve.create = function ( construct, getPoint ) {
  28200. console.log( 'THREE.Curve.create() has been deprecated' );
  28201. construct.prototype = Object.create( Curve.prototype );
  28202. construct.prototype.constructor = construct;
  28203. construct.prototype.getPoint = getPoint;
  28204. return construct;
  28205. };
  28206. //
  28207. Object.assign( CurvePath.prototype, {
  28208. createPointsGeometry: function ( divisions ) {
  28209. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28210. // generate geometry from path points (for Line or Points objects)
  28211. var pts = this.getPoints( divisions );
  28212. return this.createGeometry( pts );
  28213. },
  28214. createSpacedPointsGeometry: function ( divisions ) {
  28215. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28216. // generate geometry from equidistant sampling along the path
  28217. var pts = this.getSpacedPoints( divisions );
  28218. return this.createGeometry( pts );
  28219. },
  28220. createGeometry: function ( points ) {
  28221. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28222. var geometry = new Geometry();
  28223. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28224. var point = points[ i ];
  28225. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  28226. }
  28227. return geometry;
  28228. }
  28229. } );
  28230. //
  28231. Object.assign( Path.prototype, {
  28232. fromPoints: function ( points ) {
  28233. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28234. this.setFromPoints( points );
  28235. }
  28236. } );
  28237. //
  28238. function ClosedSplineCurve3( points ) {
  28239. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28240. CatmullRomCurve3.call( this, points );
  28241. this.type = 'catmullrom';
  28242. this.closed = true;
  28243. }
  28244. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28245. //
  28246. function SplineCurve3( points ) {
  28247. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28248. CatmullRomCurve3.call( this, points );
  28249. this.type = 'catmullrom';
  28250. }
  28251. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28252. //
  28253. function Spline( points ) {
  28254. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28255. CatmullRomCurve3.call( this, points );
  28256. this.type = 'catmullrom';
  28257. }
  28258. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28259. Object.assign( Spline.prototype, {
  28260. initFromArray: function ( /* a */ ) {
  28261. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28262. },
  28263. getControlPointsArray: function ( /* optionalTarget */ ) {
  28264. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28265. },
  28266. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  28267. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  28268. }
  28269. } );
  28270. //
  28271. function AxisHelper( size ) {
  28272. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28273. return new AxesHelper( size );
  28274. }
  28275. function BoundingBoxHelper( object, color ) {
  28276. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28277. return new BoxHelper( object, color );
  28278. }
  28279. function EdgesHelper( object, hex ) {
  28280. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28281. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28282. }
  28283. GridHelper.prototype.setColors = function () {
  28284. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28285. };
  28286. SkeletonHelper.prototype.update = function () {
  28287. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28288. };
  28289. function WireframeHelper( object, hex ) {
  28290. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28291. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28292. }
  28293. //
  28294. Object.assign( Loader.prototype, {
  28295. extractUrlBase: function ( url ) {
  28296. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28297. return LoaderUtils.extractUrlBase( url );
  28298. }
  28299. } );
  28300. function XHRLoader( manager ) {
  28301. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28302. return new FileLoader( manager );
  28303. }
  28304. function BinaryTextureLoader( manager ) {
  28305. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28306. return new DataTextureLoader( manager );
  28307. }
  28308. Object.assign( ObjectLoader.prototype, {
  28309. setTexturePath: function ( value ) {
  28310. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  28311. return this.setResourcePath( value );
  28312. }
  28313. } );
  28314. //
  28315. Object.assign( Box2.prototype, {
  28316. center: function ( optionalTarget ) {
  28317. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28318. return this.getCenter( optionalTarget );
  28319. },
  28320. empty: function () {
  28321. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28322. return this.isEmpty();
  28323. },
  28324. isIntersectionBox: function ( box ) {
  28325. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28326. return this.intersectsBox( box );
  28327. },
  28328. size: function ( optionalTarget ) {
  28329. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28330. return this.getSize( optionalTarget );
  28331. }
  28332. } );
  28333. Object.assign( Box3.prototype, {
  28334. center: function ( optionalTarget ) {
  28335. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28336. return this.getCenter( optionalTarget );
  28337. },
  28338. empty: function () {
  28339. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28340. return this.isEmpty();
  28341. },
  28342. isIntersectionBox: function ( box ) {
  28343. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28344. return this.intersectsBox( box );
  28345. },
  28346. isIntersectionSphere: function ( sphere ) {
  28347. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28348. return this.intersectsSphere( sphere );
  28349. },
  28350. size: function ( optionalTarget ) {
  28351. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28352. return this.getSize( optionalTarget );
  28353. }
  28354. } );
  28355. Line3.prototype.center = function ( optionalTarget ) {
  28356. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28357. return this.getCenter( optionalTarget );
  28358. };
  28359. Object.assign( _Math, {
  28360. random16: function () {
  28361. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28362. return Math.random();
  28363. },
  28364. nearestPowerOfTwo: function ( value ) {
  28365. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28366. return _Math.floorPowerOfTwo( value );
  28367. },
  28368. nextPowerOfTwo: function ( value ) {
  28369. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28370. return _Math.ceilPowerOfTwo( value );
  28371. }
  28372. } );
  28373. Object.assign( Matrix3.prototype, {
  28374. flattenToArrayOffset: function ( array, offset ) {
  28375. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28376. return this.toArray( array, offset );
  28377. },
  28378. multiplyVector3: function ( vector ) {
  28379. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28380. return vector.applyMatrix3( this );
  28381. },
  28382. multiplyVector3Array: function ( /* a */ ) {
  28383. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28384. },
  28385. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28386. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28387. return this.applyToBufferAttribute( buffer );
  28388. },
  28389. applyToVector3Array: function ( /* array, offset, length */ ) {
  28390. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28391. }
  28392. } );
  28393. Object.assign( Matrix4.prototype, {
  28394. extractPosition: function ( m ) {
  28395. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28396. return this.copyPosition( m );
  28397. },
  28398. flattenToArrayOffset: function ( array, offset ) {
  28399. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28400. return this.toArray( array, offset );
  28401. },
  28402. getPosition: function () {
  28403. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28404. return new Vector3().setFromMatrixColumn( this, 3 );
  28405. },
  28406. setRotationFromQuaternion: function ( q ) {
  28407. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28408. return this.makeRotationFromQuaternion( q );
  28409. },
  28410. multiplyToArray: function () {
  28411. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28412. },
  28413. multiplyVector3: function ( vector ) {
  28414. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28415. return vector.applyMatrix4( this );
  28416. },
  28417. multiplyVector4: function ( vector ) {
  28418. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28419. return vector.applyMatrix4( this );
  28420. },
  28421. multiplyVector3Array: function ( /* a */ ) {
  28422. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28423. },
  28424. rotateAxis: function ( v ) {
  28425. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28426. v.transformDirection( this );
  28427. },
  28428. crossVector: function ( vector ) {
  28429. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28430. return vector.applyMatrix4( this );
  28431. },
  28432. translate: function () {
  28433. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28434. },
  28435. rotateX: function () {
  28436. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28437. },
  28438. rotateY: function () {
  28439. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28440. },
  28441. rotateZ: function () {
  28442. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28443. },
  28444. rotateByAxis: function () {
  28445. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28446. },
  28447. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28448. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28449. return this.applyToBufferAttribute( buffer );
  28450. },
  28451. applyToVector3Array: function ( /* array, offset, length */ ) {
  28452. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28453. },
  28454. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28455. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28456. return this.makePerspective( left, right, top, bottom, near, far );
  28457. }
  28458. } );
  28459. Plane.prototype.isIntersectionLine = function ( line ) {
  28460. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28461. return this.intersectsLine( line );
  28462. };
  28463. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28464. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28465. return vector.applyQuaternion( this );
  28466. };
  28467. Object.assign( Ray.prototype, {
  28468. isIntersectionBox: function ( box ) {
  28469. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28470. return this.intersectsBox( box );
  28471. },
  28472. isIntersectionPlane: function ( plane ) {
  28473. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28474. return this.intersectsPlane( plane );
  28475. },
  28476. isIntersectionSphere: function ( sphere ) {
  28477. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28478. return this.intersectsSphere( sphere );
  28479. }
  28480. } );
  28481. Object.assign( Triangle.prototype, {
  28482. area: function () {
  28483. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28484. return this.getArea();
  28485. },
  28486. barycoordFromPoint: function ( point, target ) {
  28487. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28488. return this.getBarycoord( point, target );
  28489. },
  28490. midpoint: function ( target ) {
  28491. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28492. return this.getMidpoint( target );
  28493. },
  28494. normal: function ( target ) {
  28495. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28496. return this.getNormal( target );
  28497. },
  28498. plane: function ( target ) {
  28499. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28500. return this.getPlane( target );
  28501. }
  28502. } );
  28503. Object.assign( Triangle, {
  28504. barycoordFromPoint: function ( point, a, b, c, target ) {
  28505. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28506. return Triangle.getBarycoord( point, a, b, c, target );
  28507. },
  28508. normal: function ( a, b, c, target ) {
  28509. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28510. return Triangle.getNormal( a, b, c, target );
  28511. }
  28512. } );
  28513. Object.assign( Shape.prototype, {
  28514. extractAllPoints: function ( divisions ) {
  28515. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28516. return this.extractPoints( divisions );
  28517. },
  28518. extrude: function ( options ) {
  28519. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28520. return new ExtrudeGeometry( this, options );
  28521. },
  28522. makeGeometry: function ( options ) {
  28523. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28524. return new ShapeGeometry( this, options );
  28525. }
  28526. } );
  28527. Object.assign( Vector2.prototype, {
  28528. fromAttribute: function ( attribute, index, offset ) {
  28529. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28530. return this.fromBufferAttribute( attribute, index, offset );
  28531. },
  28532. distanceToManhattan: function ( v ) {
  28533. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28534. return this.manhattanDistanceTo( v );
  28535. },
  28536. lengthManhattan: function () {
  28537. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28538. return this.manhattanLength();
  28539. }
  28540. } );
  28541. Object.assign( Vector3.prototype, {
  28542. setEulerFromRotationMatrix: function () {
  28543. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28544. },
  28545. setEulerFromQuaternion: function () {
  28546. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28547. },
  28548. getPositionFromMatrix: function ( m ) {
  28549. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28550. return this.setFromMatrixPosition( m );
  28551. },
  28552. getScaleFromMatrix: function ( m ) {
  28553. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28554. return this.setFromMatrixScale( m );
  28555. },
  28556. getColumnFromMatrix: function ( index, matrix ) {
  28557. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28558. return this.setFromMatrixColumn( matrix, index );
  28559. },
  28560. applyProjection: function ( m ) {
  28561. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28562. return this.applyMatrix4( m );
  28563. },
  28564. fromAttribute: function ( attribute, index, offset ) {
  28565. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28566. return this.fromBufferAttribute( attribute, index, offset );
  28567. },
  28568. distanceToManhattan: function ( v ) {
  28569. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28570. return this.manhattanDistanceTo( v );
  28571. },
  28572. lengthManhattan: function () {
  28573. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28574. return this.manhattanLength();
  28575. }
  28576. } );
  28577. Object.assign( Vector4.prototype, {
  28578. fromAttribute: function ( attribute, index, offset ) {
  28579. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28580. return this.fromBufferAttribute( attribute, index, offset );
  28581. },
  28582. lengthManhattan: function () {
  28583. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28584. return this.manhattanLength();
  28585. }
  28586. } );
  28587. //
  28588. Object.assign( Geometry.prototype, {
  28589. computeTangents: function () {
  28590. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28591. },
  28592. computeLineDistances: function () {
  28593. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28594. }
  28595. } );
  28596. Object.assign( Object3D.prototype, {
  28597. getChildByName: function ( name ) {
  28598. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28599. return this.getObjectByName( name );
  28600. },
  28601. renderDepth: function () {
  28602. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28603. },
  28604. translate: function ( distance, axis ) {
  28605. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28606. return this.translateOnAxis( axis, distance );
  28607. },
  28608. getWorldRotation: function () {
  28609. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28610. }
  28611. } );
  28612. Object.defineProperties( Object3D.prototype, {
  28613. eulerOrder: {
  28614. get: function () {
  28615. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28616. return this.rotation.order;
  28617. },
  28618. set: function ( value ) {
  28619. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28620. this.rotation.order = value;
  28621. }
  28622. },
  28623. useQuaternion: {
  28624. get: function () {
  28625. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28626. },
  28627. set: function () {
  28628. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28629. }
  28630. }
  28631. } );
  28632. Object.defineProperties( LOD.prototype, {
  28633. objects: {
  28634. get: function () {
  28635. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28636. return this.levels;
  28637. }
  28638. }
  28639. } );
  28640. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28641. get: function () {
  28642. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28643. },
  28644. set: function () {
  28645. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28646. }
  28647. } );
  28648. SkinnedMesh.prototype.initBones = function () {
  28649. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28650. };
  28651. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28652. get: function () {
  28653. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28654. return this.arcLengthDivisions;
  28655. },
  28656. set: function ( value ) {
  28657. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28658. this.arcLengthDivisions = value;
  28659. }
  28660. } );
  28661. //
  28662. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28663. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28664. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28665. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28666. this.setFocalLength( focalLength );
  28667. };
  28668. //
  28669. Object.defineProperties( Light.prototype, {
  28670. onlyShadow: {
  28671. set: function () {
  28672. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28673. }
  28674. },
  28675. shadowCameraFov: {
  28676. set: function ( value ) {
  28677. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28678. this.shadow.camera.fov = value;
  28679. }
  28680. },
  28681. shadowCameraLeft: {
  28682. set: function ( value ) {
  28683. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28684. this.shadow.camera.left = value;
  28685. }
  28686. },
  28687. shadowCameraRight: {
  28688. set: function ( value ) {
  28689. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28690. this.shadow.camera.right = value;
  28691. }
  28692. },
  28693. shadowCameraTop: {
  28694. set: function ( value ) {
  28695. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28696. this.shadow.camera.top = value;
  28697. }
  28698. },
  28699. shadowCameraBottom: {
  28700. set: function ( value ) {
  28701. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28702. this.shadow.camera.bottom = value;
  28703. }
  28704. },
  28705. shadowCameraNear: {
  28706. set: function ( value ) {
  28707. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28708. this.shadow.camera.near = value;
  28709. }
  28710. },
  28711. shadowCameraFar: {
  28712. set: function ( value ) {
  28713. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28714. this.shadow.camera.far = value;
  28715. }
  28716. },
  28717. shadowCameraVisible: {
  28718. set: function () {
  28719. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28720. }
  28721. },
  28722. shadowBias: {
  28723. set: function ( value ) {
  28724. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28725. this.shadow.bias = value;
  28726. }
  28727. },
  28728. shadowDarkness: {
  28729. set: function () {
  28730. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28731. }
  28732. },
  28733. shadowMapWidth: {
  28734. set: function ( value ) {
  28735. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28736. this.shadow.mapSize.width = value;
  28737. }
  28738. },
  28739. shadowMapHeight: {
  28740. set: function ( value ) {
  28741. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28742. this.shadow.mapSize.height = value;
  28743. }
  28744. }
  28745. } );
  28746. //
  28747. Object.defineProperties( BufferAttribute.prototype, {
  28748. length: {
  28749. get: function () {
  28750. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28751. return this.array.length;
  28752. }
  28753. },
  28754. copyIndicesArray: function ( /* indices */ ) {
  28755. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28756. }
  28757. } );
  28758. Object.assign( BufferGeometry.prototype, {
  28759. addIndex: function ( index ) {
  28760. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28761. this.setIndex( index );
  28762. },
  28763. addDrawCall: function ( start, count, indexOffset ) {
  28764. if ( indexOffset !== undefined ) {
  28765. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28766. }
  28767. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28768. this.addGroup( start, count );
  28769. },
  28770. clearDrawCalls: function () {
  28771. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28772. this.clearGroups();
  28773. },
  28774. computeTangents: function () {
  28775. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28776. },
  28777. computeOffsets: function () {
  28778. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28779. }
  28780. } );
  28781. Object.defineProperties( BufferGeometry.prototype, {
  28782. drawcalls: {
  28783. get: function () {
  28784. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28785. return this.groups;
  28786. }
  28787. },
  28788. offsets: {
  28789. get: function () {
  28790. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28791. return this.groups;
  28792. }
  28793. }
  28794. } );
  28795. //
  28796. Object.assign( ExtrudeBufferGeometry.prototype, {
  28797. getArrays: function () {
  28798. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28799. },
  28800. addShapeList: function () {
  28801. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28802. },
  28803. addShape: function () {
  28804. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28805. }
  28806. } );
  28807. //
  28808. Object.defineProperties( Uniform.prototype, {
  28809. dynamic: {
  28810. set: function () {
  28811. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28812. }
  28813. },
  28814. onUpdate: {
  28815. value: function () {
  28816. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28817. return this;
  28818. }
  28819. }
  28820. } );
  28821. //
  28822. Object.defineProperties( Material.prototype, {
  28823. wrapAround: {
  28824. get: function () {
  28825. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28826. },
  28827. set: function () {
  28828. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28829. }
  28830. },
  28831. overdraw: {
  28832. get: function () {
  28833. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28834. },
  28835. set: function () {
  28836. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28837. }
  28838. },
  28839. wrapRGB: {
  28840. get: function () {
  28841. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28842. return new Color();
  28843. }
  28844. },
  28845. shading: {
  28846. get: function () {
  28847. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28848. },
  28849. set: function ( value ) {
  28850. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28851. this.flatShading = ( value === FlatShading );
  28852. }
  28853. }
  28854. } );
  28855. Object.defineProperties( MeshPhongMaterial.prototype, {
  28856. metal: {
  28857. get: function () {
  28858. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28859. return false;
  28860. },
  28861. set: function () {
  28862. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28863. }
  28864. }
  28865. } );
  28866. Object.defineProperties( ShaderMaterial.prototype, {
  28867. derivatives: {
  28868. get: function () {
  28869. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28870. return this.extensions.derivatives;
  28871. },
  28872. set: function ( value ) {
  28873. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28874. this.extensions.derivatives = value;
  28875. }
  28876. }
  28877. } );
  28878. //
  28879. Object.assign( WebGLRenderer.prototype, {
  28880. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28881. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28882. this.setRenderTarget( renderTarget );
  28883. this.clear( color, depth, stencil );
  28884. },
  28885. animate: function ( callback ) {
  28886. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28887. this.setAnimationLoop( callback );
  28888. },
  28889. getCurrentRenderTarget: function () {
  28890. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28891. return this.getRenderTarget();
  28892. },
  28893. getMaxAnisotropy: function () {
  28894. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28895. return this.capabilities.getMaxAnisotropy();
  28896. },
  28897. getPrecision: function () {
  28898. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28899. return this.capabilities.precision;
  28900. },
  28901. resetGLState: function () {
  28902. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28903. return this.state.reset();
  28904. },
  28905. supportsFloatTextures: function () {
  28906. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28907. return this.extensions.get( 'OES_texture_float' );
  28908. },
  28909. supportsHalfFloatTextures: function () {
  28910. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28911. return this.extensions.get( 'OES_texture_half_float' );
  28912. },
  28913. supportsStandardDerivatives: function () {
  28914. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28915. return this.extensions.get( 'OES_standard_derivatives' );
  28916. },
  28917. supportsCompressedTextureS3TC: function () {
  28918. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28919. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28920. },
  28921. supportsCompressedTexturePVRTC: function () {
  28922. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28923. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28924. },
  28925. supportsBlendMinMax: function () {
  28926. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28927. return this.extensions.get( 'EXT_blend_minmax' );
  28928. },
  28929. supportsVertexTextures: function () {
  28930. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28931. return this.capabilities.vertexTextures;
  28932. },
  28933. supportsInstancedArrays: function () {
  28934. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28935. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28936. },
  28937. enableScissorTest: function ( boolean ) {
  28938. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28939. this.setScissorTest( boolean );
  28940. },
  28941. initMaterial: function () {
  28942. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28943. },
  28944. addPrePlugin: function () {
  28945. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28946. },
  28947. addPostPlugin: function () {
  28948. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28949. },
  28950. updateShadowMap: function () {
  28951. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28952. },
  28953. setFaceCulling: function () {
  28954. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28955. },
  28956. allocTextureUnit: function () {
  28957. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28958. },
  28959. setTexture: function () {
  28960. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28961. },
  28962. setTexture2D: function () {
  28963. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28964. },
  28965. setTextureCube: function () {
  28966. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28967. },
  28968. getActiveMipMapLevel: function () {
  28969. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  28970. return this.getActiveMipmapLevel();
  28971. }
  28972. } );
  28973. Object.defineProperties( WebGLRenderer.prototype, {
  28974. shadowMapEnabled: {
  28975. get: function () {
  28976. return this.shadowMap.enabled;
  28977. },
  28978. set: function ( value ) {
  28979. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28980. this.shadowMap.enabled = value;
  28981. }
  28982. },
  28983. shadowMapType: {
  28984. get: function () {
  28985. return this.shadowMap.type;
  28986. },
  28987. set: function ( value ) {
  28988. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28989. this.shadowMap.type = value;
  28990. }
  28991. },
  28992. shadowMapCullFace: {
  28993. get: function () {
  28994. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28995. return undefined;
  28996. },
  28997. set: function ( /* value */ ) {
  28998. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28999. }
  29000. },
  29001. context: {
  29002. get: function () {
  29003. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  29004. return this.getContext();
  29005. }
  29006. }
  29007. } );
  29008. Object.defineProperties( WebGLShadowMap.prototype, {
  29009. cullFace: {
  29010. get: function () {
  29011. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29012. return undefined;
  29013. },
  29014. set: function ( /* cullFace */ ) {
  29015. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29016. }
  29017. },
  29018. renderReverseSided: {
  29019. get: function () {
  29020. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29021. return undefined;
  29022. },
  29023. set: function () {
  29024. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29025. }
  29026. },
  29027. renderSingleSided: {
  29028. get: function () {
  29029. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29030. return undefined;
  29031. },
  29032. set: function () {
  29033. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29034. }
  29035. }
  29036. } );
  29037. //
  29038. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  29039. activeCubeFace: {
  29040. set: function ( /* value */ ) {
  29041. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  29042. }
  29043. },
  29044. activeMipMapLevel: {
  29045. set: function ( /* value */ ) {
  29046. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  29047. }
  29048. }
  29049. } );
  29050. //
  29051. Object.defineProperties( WebGLRenderTarget.prototype, {
  29052. wrapS: {
  29053. get: function () {
  29054. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29055. return this.texture.wrapS;
  29056. },
  29057. set: function ( value ) {
  29058. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29059. this.texture.wrapS = value;
  29060. }
  29061. },
  29062. wrapT: {
  29063. get: function () {
  29064. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29065. return this.texture.wrapT;
  29066. },
  29067. set: function ( value ) {
  29068. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29069. this.texture.wrapT = value;
  29070. }
  29071. },
  29072. magFilter: {
  29073. get: function () {
  29074. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29075. return this.texture.magFilter;
  29076. },
  29077. set: function ( value ) {
  29078. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29079. this.texture.magFilter = value;
  29080. }
  29081. },
  29082. minFilter: {
  29083. get: function () {
  29084. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29085. return this.texture.minFilter;
  29086. },
  29087. set: function ( value ) {
  29088. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29089. this.texture.minFilter = value;
  29090. }
  29091. },
  29092. anisotropy: {
  29093. get: function () {
  29094. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29095. return this.texture.anisotropy;
  29096. },
  29097. set: function ( value ) {
  29098. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29099. this.texture.anisotropy = value;
  29100. }
  29101. },
  29102. offset: {
  29103. get: function () {
  29104. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29105. return this.texture.offset;
  29106. },
  29107. set: function ( value ) {
  29108. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29109. this.texture.offset = value;
  29110. }
  29111. },
  29112. repeat: {
  29113. get: function () {
  29114. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29115. return this.texture.repeat;
  29116. },
  29117. set: function ( value ) {
  29118. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29119. this.texture.repeat = value;
  29120. }
  29121. },
  29122. format: {
  29123. get: function () {
  29124. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29125. return this.texture.format;
  29126. },
  29127. set: function ( value ) {
  29128. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29129. this.texture.format = value;
  29130. }
  29131. },
  29132. type: {
  29133. get: function () {
  29134. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29135. return this.texture.type;
  29136. },
  29137. set: function ( value ) {
  29138. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29139. this.texture.type = value;
  29140. }
  29141. },
  29142. generateMipmaps: {
  29143. get: function () {
  29144. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29145. return this.texture.generateMipmaps;
  29146. },
  29147. set: function ( value ) {
  29148. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29149. this.texture.generateMipmaps = value;
  29150. }
  29151. }
  29152. } );
  29153. //
  29154. Object.defineProperties( WebVRManager.prototype, {
  29155. standing: {
  29156. set: function ( /* value */ ) {
  29157. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  29158. }
  29159. },
  29160. userHeight: {
  29161. set: function ( /* value */ ) {
  29162. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  29163. }
  29164. }
  29165. } );
  29166. //
  29167. Audio.prototype.load = function ( file ) {
  29168. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  29169. var scope = this;
  29170. var audioLoader = new AudioLoader();
  29171. audioLoader.load( file, function ( buffer ) {
  29172. scope.setBuffer( buffer );
  29173. } );
  29174. return this;
  29175. };
  29176. AudioAnalyser.prototype.getData = function () {
  29177. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  29178. return this.getFrequencyData();
  29179. };
  29180. //
  29181. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  29182. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  29183. return this.update( renderer, scene );
  29184. };
  29185. //
  29186. var GeometryUtils = {
  29187. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  29188. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  29189. var matrix;
  29190. if ( geometry2.isMesh ) {
  29191. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  29192. matrix = geometry2.matrix;
  29193. geometry2 = geometry2.geometry;
  29194. }
  29195. geometry1.merge( geometry2, matrix, materialIndexOffset );
  29196. },
  29197. center: function ( geometry ) {
  29198. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  29199. return geometry.center();
  29200. }
  29201. };
  29202. ImageUtils.crossOrigin = undefined;
  29203. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29204. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29205. var loader = new TextureLoader();
  29206. loader.setCrossOrigin( this.crossOrigin );
  29207. var texture = loader.load( url, onLoad, undefined, onError );
  29208. if ( mapping ) texture.mapping = mapping;
  29209. return texture;
  29210. };
  29211. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29212. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29213. var loader = new CubeTextureLoader();
  29214. loader.setCrossOrigin( this.crossOrigin );
  29215. var texture = loader.load( urls, onLoad, undefined, onError );
  29216. if ( mapping ) texture.mapping = mapping;
  29217. return texture;
  29218. };
  29219. ImageUtils.loadCompressedTexture = function () {
  29220. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29221. };
  29222. ImageUtils.loadCompressedTextureCube = function () {
  29223. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29224. };
  29225. //
  29226. function CanvasRenderer() {
  29227. console.error( 'THREE.CanvasRenderer has been removed' );
  29228. }
  29229. //
  29230. function JSONLoader() {
  29231. console.error( 'THREE.JSONLoader has been removed.' );
  29232. }
  29233. //
  29234. var SceneUtils = {
  29235. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29236. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29237. },
  29238. detach: function ( /* child, parent, scene */ ) {
  29239. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29240. },
  29241. attach: function ( /* child, scene, parent */ ) {
  29242. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29243. }
  29244. };
  29245. //
  29246. function LensFlare() {
  29247. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  29248. }
  29249. 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 };