three.module.js 974 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380
  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 ( Function.prototype.name === undefined ) {
  20. // Missing in IE
  21. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  22. Object.defineProperty( Function.prototype, 'name', {
  23. get: function () {
  24. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  25. }
  26. } );
  27. }
  28. if ( Object.assign === undefined ) {
  29. // Missing in IE
  30. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  31. ( function () {
  32. Object.assign = function ( target ) {
  33. 'use strict';
  34. if ( target === undefined || target === null ) {
  35. throw new TypeError( 'Cannot convert undefined or null to object' );
  36. }
  37. var output = Object( target );
  38. for ( var index = 1; index < arguments.length; index ++ ) {
  39. var source = arguments[ index ];
  40. if ( source !== undefined && source !== null ) {
  41. for ( var nextKey in source ) {
  42. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  43. output[ nextKey ] = source[ nextKey ];
  44. }
  45. }
  46. }
  47. }
  48. return output;
  49. };
  50. } )();
  51. }
  52. /**
  53. * https://github.com/mrdoob/eventdispatcher.js/
  54. */
  55. function EventDispatcher() {}
  56. Object.assign( EventDispatcher.prototype, {
  57. addEventListener: function ( type, listener ) {
  58. if ( this._listeners === undefined ) this._listeners = {};
  59. var listeners = this._listeners;
  60. if ( listeners[ type ] === undefined ) {
  61. listeners[ type ] = [];
  62. }
  63. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  64. listeners[ type ].push( listener );
  65. }
  66. },
  67. hasEventListener: function ( type, listener ) {
  68. if ( this._listeners === undefined ) return false;
  69. var listeners = this._listeners;
  70. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  71. },
  72. removeEventListener: function ( type, listener ) {
  73. if ( this._listeners === undefined ) return;
  74. var listeners = this._listeners;
  75. var listenerArray = listeners[ type ];
  76. if ( listenerArray !== undefined ) {
  77. var index = listenerArray.indexOf( listener );
  78. if ( index !== - 1 ) {
  79. listenerArray.splice( index, 1 );
  80. }
  81. }
  82. },
  83. dispatchEvent: function ( event ) {
  84. if ( this._listeners === undefined ) return;
  85. var listeners = this._listeners;
  86. var listenerArray = listeners[ event.type ];
  87. if ( listenerArray !== undefined ) {
  88. event.target = this;
  89. var array = [], i = 0;
  90. var length = listenerArray.length;
  91. for ( i = 0; i < length; i ++ ) {
  92. array[ i ] = listenerArray[ i ];
  93. }
  94. for ( i = 0; i < length; i ++ ) {
  95. array[ i ].call( this, event );
  96. }
  97. }
  98. }
  99. } );
  100. var REVISION = '86dev';
  101. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  102. var CullFaceNone = 0;
  103. var CullFaceBack = 1;
  104. var CullFaceFront = 2;
  105. var CullFaceFrontBack = 3;
  106. var FrontFaceDirectionCW = 0;
  107. var FrontFaceDirectionCCW = 1;
  108. var BasicShadowMap = 0;
  109. var PCFShadowMap = 1;
  110. var PCFSoftShadowMap = 2;
  111. var FrontSide = 0;
  112. var BackSide = 1;
  113. var DoubleSide = 2;
  114. var FlatShading = 1;
  115. var SmoothShading = 2;
  116. var NoColors = 0;
  117. var FaceColors = 1;
  118. var VertexColors = 2;
  119. var NoBlending = 0;
  120. var NormalBlending = 1;
  121. var AdditiveBlending = 2;
  122. var SubtractiveBlending = 3;
  123. var MultiplyBlending = 4;
  124. var CustomBlending = 5;
  125. var AddEquation = 100;
  126. var SubtractEquation = 101;
  127. var ReverseSubtractEquation = 102;
  128. var MinEquation = 103;
  129. var MaxEquation = 104;
  130. var ZeroFactor = 200;
  131. var OneFactor = 201;
  132. var SrcColorFactor = 202;
  133. var OneMinusSrcColorFactor = 203;
  134. var SrcAlphaFactor = 204;
  135. var OneMinusSrcAlphaFactor = 205;
  136. var DstAlphaFactor = 206;
  137. var OneMinusDstAlphaFactor = 207;
  138. var DstColorFactor = 208;
  139. var OneMinusDstColorFactor = 209;
  140. var SrcAlphaSaturateFactor = 210;
  141. var NeverDepth = 0;
  142. var AlwaysDepth = 1;
  143. var LessDepth = 2;
  144. var LessEqualDepth = 3;
  145. var EqualDepth = 4;
  146. var GreaterEqualDepth = 5;
  147. var GreaterDepth = 6;
  148. var NotEqualDepth = 7;
  149. var MultiplyOperation = 0;
  150. var MixOperation = 1;
  151. var AddOperation = 2;
  152. var NoToneMapping = 0;
  153. var LinearToneMapping = 1;
  154. var ReinhardToneMapping = 2;
  155. var Uncharted2ToneMapping = 3;
  156. var CineonToneMapping = 4;
  157. var UVMapping = 300;
  158. var CubeReflectionMapping = 301;
  159. var CubeRefractionMapping = 302;
  160. var EquirectangularReflectionMapping = 303;
  161. var EquirectangularRefractionMapping = 304;
  162. var SphericalReflectionMapping = 305;
  163. var CubeUVReflectionMapping = 306;
  164. var CubeUVRefractionMapping = 307;
  165. var RepeatWrapping = 1000;
  166. var ClampToEdgeWrapping = 1001;
  167. var MirroredRepeatWrapping = 1002;
  168. var NearestFilter = 1003;
  169. var NearestMipMapNearestFilter = 1004;
  170. var NearestMipMapLinearFilter = 1005;
  171. var LinearFilter = 1006;
  172. var LinearMipMapNearestFilter = 1007;
  173. var LinearMipMapLinearFilter = 1008;
  174. var UnsignedByteType = 1009;
  175. var ByteType = 1010;
  176. var ShortType = 1011;
  177. var UnsignedShortType = 1012;
  178. var IntType = 1013;
  179. var UnsignedIntType = 1014;
  180. var FloatType = 1015;
  181. var HalfFloatType = 1016;
  182. var UnsignedShort4444Type = 1017;
  183. var UnsignedShort5551Type = 1018;
  184. var UnsignedShort565Type = 1019;
  185. var UnsignedInt248Type = 1020;
  186. var AlphaFormat = 1021;
  187. var RGBFormat = 1022;
  188. var RGBAFormat = 1023;
  189. var LuminanceFormat = 1024;
  190. var LuminanceAlphaFormat = 1025;
  191. var RGBEFormat = RGBAFormat;
  192. var DepthFormat = 1026;
  193. var DepthStencilFormat = 1027;
  194. var RGB_S3TC_DXT1_Format = 2001;
  195. var RGBA_S3TC_DXT1_Format = 2002;
  196. var RGBA_S3TC_DXT3_Format = 2003;
  197. var RGBA_S3TC_DXT5_Format = 2004;
  198. var RGB_PVRTC_4BPPV1_Format = 2100;
  199. var RGB_PVRTC_2BPPV1_Format = 2101;
  200. var RGBA_PVRTC_4BPPV1_Format = 2102;
  201. var RGBA_PVRTC_2BPPV1_Format = 2103;
  202. var RGB_ETC1_Format = 2151;
  203. var LoopOnce = 2200;
  204. var LoopRepeat = 2201;
  205. var LoopPingPong = 2202;
  206. var InterpolateDiscrete = 2300;
  207. var InterpolateLinear = 2301;
  208. var InterpolateSmooth = 2302;
  209. var ZeroCurvatureEnding = 2400;
  210. var ZeroSlopeEnding = 2401;
  211. var WrapAroundEnding = 2402;
  212. var TrianglesDrawMode = 0;
  213. var TriangleStripDrawMode = 1;
  214. var TriangleFanDrawMode = 2;
  215. var LinearEncoding = 3000;
  216. var sRGBEncoding = 3001;
  217. var GammaEncoding = 3007;
  218. var RGBEEncoding = 3002;
  219. var LogLuvEncoding = 3003;
  220. var RGBM7Encoding = 3004;
  221. var RGBM16Encoding = 3005;
  222. var RGBDEncoding = 3006;
  223. var BasicDepthPacking = 3200;
  224. var RGBADepthPacking = 3201;
  225. /**
  226. * @author alteredq / http://alteredqualia.com/
  227. * @author mrdoob / http://mrdoob.com/
  228. */
  229. var _Math = {
  230. DEG2RAD: Math.PI / 180,
  231. RAD2DEG: 180 / Math.PI,
  232. generateUUID: function () {
  233. // http://www.broofa.com/Tools/Math.uuid.htm
  234. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  235. var uuid = new Array( 36 );
  236. var rnd = 0, r;
  237. return function generateUUID() {
  238. for ( var i = 0; i < 36; i ++ ) {
  239. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  240. uuid[ i ] = '-';
  241. } else if ( i === 14 ) {
  242. uuid[ i ] = '4';
  243. } else {
  244. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  245. r = rnd & 0xf;
  246. rnd = rnd >> 4;
  247. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  248. }
  249. }
  250. return uuid.join( '' );
  251. };
  252. }(),
  253. clamp: function ( value, min, max ) {
  254. return Math.max( min, Math.min( max, value ) );
  255. },
  256. // compute euclidian modulo of m % n
  257. // https://en.wikipedia.org/wiki/Modulo_operation
  258. euclideanModulo: function ( n, m ) {
  259. return ( ( n % m ) + m ) % m;
  260. },
  261. // Linear mapping from range <a1, a2> to range <b1, b2>
  262. mapLinear: function ( x, a1, a2, b1, b2 ) {
  263. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  264. },
  265. // https://en.wikipedia.org/wiki/Linear_interpolation
  266. lerp: function ( x, y, t ) {
  267. return ( 1 - t ) * x + t * y;
  268. },
  269. // http://en.wikipedia.org/wiki/Smoothstep
  270. smoothstep: function ( x, min, max ) {
  271. if ( x <= min ) return 0;
  272. if ( x >= max ) return 1;
  273. x = ( x - min ) / ( max - min );
  274. return x * x * ( 3 - 2 * x );
  275. },
  276. smootherstep: function ( x, min, max ) {
  277. if ( x <= min ) return 0;
  278. if ( x >= max ) return 1;
  279. x = ( x - min ) / ( max - min );
  280. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  281. },
  282. // Random integer from <low, high> interval
  283. randInt: function ( low, high ) {
  284. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  285. },
  286. // Random float from <low, high> interval
  287. randFloat: function ( low, high ) {
  288. return low + Math.random() * ( high - low );
  289. },
  290. // Random float from <-range/2, range/2> interval
  291. randFloatSpread: function ( range ) {
  292. return range * ( 0.5 - Math.random() );
  293. },
  294. degToRad: function ( degrees ) {
  295. return degrees * _Math.DEG2RAD;
  296. },
  297. radToDeg: function ( radians ) {
  298. return radians * _Math.RAD2DEG;
  299. },
  300. isPowerOfTwo: function ( value ) {
  301. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  302. },
  303. nearestPowerOfTwo: function ( value ) {
  304. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  305. },
  306. nextPowerOfTwo: function ( value ) {
  307. value --;
  308. value |= value >> 1;
  309. value |= value >> 2;
  310. value |= value >> 4;
  311. value |= value >> 8;
  312. value |= value >> 16;
  313. value ++;
  314. return value;
  315. }
  316. };
  317. /**
  318. * @author mrdoob / http://mrdoob.com/
  319. * @author philogb / http://blog.thejit.org/
  320. * @author egraether / http://egraether.com/
  321. * @author zz85 / http://www.lab4games.net/zz85/blog
  322. */
  323. function Vector2( x, y ) {
  324. this.x = x || 0;
  325. this.y = y || 0;
  326. }
  327. Object.defineProperties( Vector2.prototype, {
  328. "width" : {
  329. get: function () {
  330. return this.x;
  331. },
  332. set: function ( value ) {
  333. this.x = value;
  334. }
  335. },
  336. "height" : {
  337. get: function () {
  338. return this.y;
  339. },
  340. set: function ( value ) {
  341. this.y = value;
  342. }
  343. }
  344. } );
  345. Object.assign( Vector2.prototype, {
  346. isVector2: true,
  347. set: function ( x, y ) {
  348. this.x = x;
  349. this.y = y;
  350. return this;
  351. },
  352. setScalar: function ( scalar ) {
  353. this.x = scalar;
  354. this.y = scalar;
  355. return this;
  356. },
  357. setX: function ( x ) {
  358. this.x = x;
  359. return this;
  360. },
  361. setY: function ( y ) {
  362. this.y = y;
  363. return this;
  364. },
  365. setComponent: function ( index, value ) {
  366. switch ( index ) {
  367. case 0: this.x = value; break;
  368. case 1: this.y = value; break;
  369. default: throw new Error( 'index is out of range: ' + index );
  370. }
  371. return this;
  372. },
  373. getComponent: function ( index ) {
  374. switch ( index ) {
  375. case 0: return this.x;
  376. case 1: return this.y;
  377. default: throw new Error( 'index is out of range: ' + index );
  378. }
  379. },
  380. clone: function () {
  381. return new this.constructor( this.x, this.y );
  382. },
  383. copy: function ( v ) {
  384. this.x = v.x;
  385. this.y = v.y;
  386. return this;
  387. },
  388. add: function ( v, w ) {
  389. if ( w !== undefined ) {
  390. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  391. return this.addVectors( v, w );
  392. }
  393. this.x += v.x;
  394. this.y += v.y;
  395. return this;
  396. },
  397. addScalar: function ( s ) {
  398. this.x += s;
  399. this.y += s;
  400. return this;
  401. },
  402. addVectors: function ( a, b ) {
  403. this.x = a.x + b.x;
  404. this.y = a.y + b.y;
  405. return this;
  406. },
  407. addScaledVector: function ( v, s ) {
  408. this.x += v.x * s;
  409. this.y += v.y * s;
  410. return this;
  411. },
  412. sub: function ( v, w ) {
  413. if ( w !== undefined ) {
  414. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  415. return this.subVectors( v, w );
  416. }
  417. this.x -= v.x;
  418. this.y -= v.y;
  419. return this;
  420. },
  421. subScalar: function ( s ) {
  422. this.x -= s;
  423. this.y -= s;
  424. return this;
  425. },
  426. subVectors: function ( a, b ) {
  427. this.x = a.x - b.x;
  428. this.y = a.y - b.y;
  429. return this;
  430. },
  431. multiply: function ( v ) {
  432. this.x *= v.x;
  433. this.y *= v.y;
  434. return this;
  435. },
  436. multiplyScalar: function ( scalar ) {
  437. this.x *= scalar;
  438. this.y *= scalar;
  439. return this;
  440. },
  441. divide: function ( v ) {
  442. this.x /= v.x;
  443. this.y /= v.y;
  444. return this;
  445. },
  446. divideScalar: function ( scalar ) {
  447. return this.multiplyScalar( 1 / scalar );
  448. },
  449. min: function ( v ) {
  450. this.x = Math.min( this.x, v.x );
  451. this.y = Math.min( this.y, v.y );
  452. return this;
  453. },
  454. max: function ( v ) {
  455. this.x = Math.max( this.x, v.x );
  456. this.y = Math.max( this.y, v.y );
  457. return this;
  458. },
  459. clamp: function ( min, max ) {
  460. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  461. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  462. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  463. return this;
  464. },
  465. clampScalar: function () {
  466. var min = new Vector2();
  467. var max = new Vector2();
  468. return function clampScalar( minVal, maxVal ) {
  469. min.set( minVal, minVal );
  470. max.set( maxVal, maxVal );
  471. return this.clamp( min, max );
  472. };
  473. }(),
  474. clampLength: function ( min, max ) {
  475. var length = this.length();
  476. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  477. },
  478. floor: function () {
  479. this.x = Math.floor( this.x );
  480. this.y = Math.floor( this.y );
  481. return this;
  482. },
  483. ceil: function () {
  484. this.x = Math.ceil( this.x );
  485. this.y = Math.ceil( this.y );
  486. return this;
  487. },
  488. round: function () {
  489. this.x = Math.round( this.x );
  490. this.y = Math.round( this.y );
  491. return this;
  492. },
  493. roundToZero: function () {
  494. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  495. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  496. return this;
  497. },
  498. negate: function () {
  499. this.x = - this.x;
  500. this.y = - this.y;
  501. return this;
  502. },
  503. dot: function ( v ) {
  504. return this.x * v.x + this.y * v.y;
  505. },
  506. lengthSq: function () {
  507. return this.x * this.x + this.y * this.y;
  508. },
  509. length: function () {
  510. return Math.sqrt( this.x * this.x + this.y * this.y );
  511. },
  512. lengthManhattan: function() {
  513. return Math.abs( this.x ) + Math.abs( this.y );
  514. },
  515. normalize: function () {
  516. return this.divideScalar( this.length() );
  517. },
  518. angle: function () {
  519. // computes the angle in radians with respect to the positive x-axis
  520. var angle = Math.atan2( this.y, this.x );
  521. if ( angle < 0 ) angle += 2 * Math.PI;
  522. return angle;
  523. },
  524. distanceTo: function ( v ) {
  525. return Math.sqrt( this.distanceToSquared( v ) );
  526. },
  527. distanceToSquared: function ( v ) {
  528. var dx = this.x - v.x, dy = this.y - v.y;
  529. return dx * dx + dy * dy;
  530. },
  531. distanceToManhattan: function ( v ) {
  532. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  533. },
  534. setLength: function ( length ) {
  535. return this.multiplyScalar( length / this.length() );
  536. },
  537. lerp: function ( v, alpha ) {
  538. this.x += ( v.x - this.x ) * alpha;
  539. this.y += ( v.y - this.y ) * alpha;
  540. return this;
  541. },
  542. lerpVectors: function ( v1, v2, alpha ) {
  543. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  544. },
  545. equals: function ( v ) {
  546. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  547. },
  548. fromArray: function ( array, offset ) {
  549. if ( offset === undefined ) offset = 0;
  550. this.x = array[ offset ];
  551. this.y = array[ offset + 1 ];
  552. return this;
  553. },
  554. toArray: function ( array, offset ) {
  555. if ( array === undefined ) array = [];
  556. if ( offset === undefined ) offset = 0;
  557. array[ offset ] = this.x;
  558. array[ offset + 1 ] = this.y;
  559. return array;
  560. },
  561. fromBufferAttribute: function ( attribute, index, offset ) {
  562. if ( offset !== undefined ) {
  563. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  564. }
  565. this.x = attribute.getX( index );
  566. this.y = attribute.getY( index );
  567. return this;
  568. },
  569. rotateAround: function ( center, angle ) {
  570. var c = Math.cos( angle ), s = Math.sin( angle );
  571. var x = this.x - center.x;
  572. var y = this.y - center.y;
  573. this.x = x * c - y * s + center.x;
  574. this.y = x * s + y * c + center.y;
  575. return this;
  576. }
  577. } );
  578. /**
  579. * @author mrdoob / http://mrdoob.com/
  580. * @author alteredq / http://alteredqualia.com/
  581. * @author szimek / https://github.com/szimek/
  582. */
  583. var textureId = 0;
  584. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  585. Object.defineProperty( this, 'id', { value: textureId ++ } );
  586. this.uuid = _Math.generateUUID();
  587. this.name = '';
  588. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  589. this.mipmaps = [];
  590. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  591. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  592. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  593. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  594. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  595. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  596. this.format = format !== undefined ? format : RGBAFormat;
  597. this.type = type !== undefined ? type : UnsignedByteType;
  598. this.offset = new Vector2( 0, 0 );
  599. this.repeat = new Vector2( 1, 1 );
  600. this.generateMipmaps = true;
  601. this.premultiplyAlpha = false;
  602. this.flipY = true;
  603. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  604. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  605. //
  606. // Also changing the encoding after already used by a Material will not automatically make the Material
  607. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  608. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  609. this.version = 0;
  610. this.onUpdate = null;
  611. }
  612. Texture.DEFAULT_IMAGE = undefined;
  613. Texture.DEFAULT_MAPPING = UVMapping;
  614. Object.defineProperty( Texture.prototype, "needsUpdate", {
  615. set: function ( value ) {
  616. if ( value === true ) this.version ++;
  617. }
  618. } );
  619. Object.assign( Texture.prototype, EventDispatcher.prototype, {
  620. constructor: Texture,
  621. isTexture: true,
  622. clone: function () {
  623. return new this.constructor().copy( this );
  624. },
  625. copy: function ( source ) {
  626. this.name = source.name;
  627. this.image = source.image;
  628. this.mipmaps = source.mipmaps.slice( 0 );
  629. this.mapping = source.mapping;
  630. this.wrapS = source.wrapS;
  631. this.wrapT = source.wrapT;
  632. this.magFilter = source.magFilter;
  633. this.minFilter = source.minFilter;
  634. this.anisotropy = source.anisotropy;
  635. this.format = source.format;
  636. this.type = source.type;
  637. this.offset.copy( source.offset );
  638. this.repeat.copy( source.repeat );
  639. this.generateMipmaps = source.generateMipmaps;
  640. this.premultiplyAlpha = source.premultiplyAlpha;
  641. this.flipY = source.flipY;
  642. this.unpackAlignment = source.unpackAlignment;
  643. this.encoding = source.encoding;
  644. return this;
  645. },
  646. toJSON: function ( meta ) {
  647. if ( meta.textures[ this.uuid ] !== undefined ) {
  648. return meta.textures[ this.uuid ];
  649. }
  650. function getDataURL( image ) {
  651. var canvas;
  652. if ( image.toDataURL !== undefined ) {
  653. canvas = image;
  654. } else {
  655. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  656. canvas.width = image.width;
  657. canvas.height = image.height;
  658. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  659. }
  660. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  661. return canvas.toDataURL( 'image/jpeg', 0.6 );
  662. } else {
  663. return canvas.toDataURL( 'image/png' );
  664. }
  665. }
  666. var output = {
  667. metadata: {
  668. version: 4.5,
  669. type: 'Texture',
  670. generator: 'Texture.toJSON'
  671. },
  672. uuid: this.uuid,
  673. name: this.name,
  674. mapping: this.mapping,
  675. repeat: [ this.repeat.x, this.repeat.y ],
  676. offset: [ this.offset.x, this.offset.y ],
  677. wrap: [ this.wrapS, this.wrapT ],
  678. minFilter: this.minFilter,
  679. magFilter: this.magFilter,
  680. anisotropy: this.anisotropy,
  681. flipY: this.flipY
  682. };
  683. if ( this.image !== undefined ) {
  684. // TODO: Move to THREE.Image
  685. var image = this.image;
  686. if ( image.uuid === undefined ) {
  687. image.uuid = _Math.generateUUID(); // UGH
  688. }
  689. if ( meta.images[ image.uuid ] === undefined ) {
  690. meta.images[ image.uuid ] = {
  691. uuid: image.uuid,
  692. url: getDataURL( image )
  693. };
  694. }
  695. output.image = image.uuid;
  696. }
  697. meta.textures[ this.uuid ] = output;
  698. return output;
  699. },
  700. dispose: function () {
  701. this.dispatchEvent( { type: 'dispose' } );
  702. },
  703. transformUv: function ( uv ) {
  704. if ( this.mapping !== UVMapping ) return;
  705. uv.multiply( this.repeat );
  706. uv.add( this.offset );
  707. if ( uv.x < 0 || uv.x > 1 ) {
  708. switch ( this.wrapS ) {
  709. case RepeatWrapping:
  710. uv.x = uv.x - Math.floor( uv.x );
  711. break;
  712. case ClampToEdgeWrapping:
  713. uv.x = uv.x < 0 ? 0 : 1;
  714. break;
  715. case MirroredRepeatWrapping:
  716. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  717. uv.x = Math.ceil( uv.x ) - uv.x;
  718. } else {
  719. uv.x = uv.x - Math.floor( uv.x );
  720. }
  721. break;
  722. }
  723. }
  724. if ( uv.y < 0 || uv.y > 1 ) {
  725. switch ( this.wrapT ) {
  726. case RepeatWrapping:
  727. uv.y = uv.y - Math.floor( uv.y );
  728. break;
  729. case ClampToEdgeWrapping:
  730. uv.y = uv.y < 0 ? 0 : 1;
  731. break;
  732. case MirroredRepeatWrapping:
  733. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  734. uv.y = Math.ceil( uv.y ) - uv.y;
  735. } else {
  736. uv.y = uv.y - Math.floor( uv.y );
  737. }
  738. break;
  739. }
  740. }
  741. if ( this.flipY ) {
  742. uv.y = 1 - uv.y;
  743. }
  744. }
  745. } );
  746. /**
  747. * @author supereggbert / http://www.paulbrunt.co.uk/
  748. * @author philogb / http://blog.thejit.org/
  749. * @author mikael emtinger / http://gomo.se/
  750. * @author egraether / http://egraether.com/
  751. * @author WestLangley / http://github.com/WestLangley
  752. */
  753. function Vector4( x, y, z, w ) {
  754. this.x = x || 0;
  755. this.y = y || 0;
  756. this.z = z || 0;
  757. this.w = ( w !== undefined ) ? w : 1;
  758. }
  759. Object.assign( Vector4.prototype, {
  760. isVector4: true,
  761. set: function ( x, y, z, w ) {
  762. this.x = x;
  763. this.y = y;
  764. this.z = z;
  765. this.w = w;
  766. return this;
  767. },
  768. setScalar: function ( scalar ) {
  769. this.x = scalar;
  770. this.y = scalar;
  771. this.z = scalar;
  772. this.w = scalar;
  773. return this;
  774. },
  775. setX: function ( x ) {
  776. this.x = x;
  777. return this;
  778. },
  779. setY: function ( y ) {
  780. this.y = y;
  781. return this;
  782. },
  783. setZ: function ( z ) {
  784. this.z = z;
  785. return this;
  786. },
  787. setW: function ( w ) {
  788. this.w = w;
  789. return this;
  790. },
  791. setComponent: function ( index, value ) {
  792. switch ( index ) {
  793. case 0: this.x = value; break;
  794. case 1: this.y = value; break;
  795. case 2: this.z = value; break;
  796. case 3: this.w = value; break;
  797. default: throw new Error( 'index is out of range: ' + index );
  798. }
  799. return this;
  800. },
  801. getComponent: function ( index ) {
  802. switch ( index ) {
  803. case 0: return this.x;
  804. case 1: return this.y;
  805. case 2: return this.z;
  806. case 3: return this.w;
  807. default: throw new Error( 'index is out of range: ' + index );
  808. }
  809. },
  810. clone: function () {
  811. return new this.constructor( this.x, this.y, this.z, this.w );
  812. },
  813. copy: function ( v ) {
  814. this.x = v.x;
  815. this.y = v.y;
  816. this.z = v.z;
  817. this.w = ( v.w !== undefined ) ? v.w : 1;
  818. return this;
  819. },
  820. add: function ( v, w ) {
  821. if ( w !== undefined ) {
  822. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  823. return this.addVectors( v, w );
  824. }
  825. this.x += v.x;
  826. this.y += v.y;
  827. this.z += v.z;
  828. this.w += v.w;
  829. return this;
  830. },
  831. addScalar: function ( s ) {
  832. this.x += s;
  833. this.y += s;
  834. this.z += s;
  835. this.w += s;
  836. return this;
  837. },
  838. addVectors: function ( a, b ) {
  839. this.x = a.x + b.x;
  840. this.y = a.y + b.y;
  841. this.z = a.z + b.z;
  842. this.w = a.w + b.w;
  843. return this;
  844. },
  845. addScaledVector: function ( v, s ) {
  846. this.x += v.x * s;
  847. this.y += v.y * s;
  848. this.z += v.z * s;
  849. this.w += v.w * s;
  850. return this;
  851. },
  852. sub: function ( v, w ) {
  853. if ( w !== undefined ) {
  854. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  855. return this.subVectors( v, w );
  856. }
  857. this.x -= v.x;
  858. this.y -= v.y;
  859. this.z -= v.z;
  860. this.w -= v.w;
  861. return this;
  862. },
  863. subScalar: function ( s ) {
  864. this.x -= s;
  865. this.y -= s;
  866. this.z -= s;
  867. this.w -= s;
  868. return this;
  869. },
  870. subVectors: function ( a, b ) {
  871. this.x = a.x - b.x;
  872. this.y = a.y - b.y;
  873. this.z = a.z - b.z;
  874. this.w = a.w - b.w;
  875. return this;
  876. },
  877. multiplyScalar: function ( scalar ) {
  878. this.x *= scalar;
  879. this.y *= scalar;
  880. this.z *= scalar;
  881. this.w *= scalar;
  882. return this;
  883. },
  884. applyMatrix4: function ( m ) {
  885. var x = this.x, y = this.y, z = this.z, w = this.w;
  886. var e = m.elements;
  887. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  888. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  889. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  890. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  891. return this;
  892. },
  893. divideScalar: function ( scalar ) {
  894. return this.multiplyScalar( 1 / scalar );
  895. },
  896. setAxisAngleFromQuaternion: function ( q ) {
  897. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  898. // q is assumed to be normalized
  899. this.w = 2 * Math.acos( q.w );
  900. var s = Math.sqrt( 1 - q.w * q.w );
  901. if ( s < 0.0001 ) {
  902. this.x = 1;
  903. this.y = 0;
  904. this.z = 0;
  905. } else {
  906. this.x = q.x / s;
  907. this.y = q.y / s;
  908. this.z = q.z / s;
  909. }
  910. return this;
  911. },
  912. setAxisAngleFromRotationMatrix: function ( m ) {
  913. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  914. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  915. var angle, x, y, z, // variables for result
  916. epsilon = 0.01, // margin to allow for rounding errors
  917. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  918. te = m.elements,
  919. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  920. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  921. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  922. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  923. ( Math.abs( m13 - m31 ) < epsilon ) &&
  924. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  925. // singularity found
  926. // first check for identity matrix which must have +1 for all terms
  927. // in leading diagonal and zero in other terms
  928. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  929. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  930. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  931. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  932. // this singularity is identity matrix so angle = 0
  933. this.set( 1, 0, 0, 0 );
  934. return this; // zero angle, arbitrary axis
  935. }
  936. // otherwise this singularity is angle = 180
  937. angle = Math.PI;
  938. var xx = ( m11 + 1 ) / 2;
  939. var yy = ( m22 + 1 ) / 2;
  940. var zz = ( m33 + 1 ) / 2;
  941. var xy = ( m12 + m21 ) / 4;
  942. var xz = ( m13 + m31 ) / 4;
  943. var yz = ( m23 + m32 ) / 4;
  944. if ( ( xx > yy ) && ( xx > zz ) ) {
  945. // m11 is the largest diagonal term
  946. if ( xx < epsilon ) {
  947. x = 0;
  948. y = 0.707106781;
  949. z = 0.707106781;
  950. } else {
  951. x = Math.sqrt( xx );
  952. y = xy / x;
  953. z = xz / x;
  954. }
  955. } else if ( yy > zz ) {
  956. // m22 is the largest diagonal term
  957. if ( yy < epsilon ) {
  958. x = 0.707106781;
  959. y = 0;
  960. z = 0.707106781;
  961. } else {
  962. y = Math.sqrt( yy );
  963. x = xy / y;
  964. z = yz / y;
  965. }
  966. } else {
  967. // m33 is the largest diagonal term so base result on this
  968. if ( zz < epsilon ) {
  969. x = 0.707106781;
  970. y = 0.707106781;
  971. z = 0;
  972. } else {
  973. z = Math.sqrt( zz );
  974. x = xz / z;
  975. y = yz / z;
  976. }
  977. }
  978. this.set( x, y, z, angle );
  979. return this; // return 180 deg rotation
  980. }
  981. // as we have reached here there are no singularities so we can handle normally
  982. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  983. ( m13 - m31 ) * ( m13 - m31 ) +
  984. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  985. if ( Math.abs( s ) < 0.001 ) s = 1;
  986. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  987. // caught by singularity test above, but I've left it in just in case
  988. this.x = ( m32 - m23 ) / s;
  989. this.y = ( m13 - m31 ) / s;
  990. this.z = ( m21 - m12 ) / s;
  991. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  992. return this;
  993. },
  994. min: function ( v ) {
  995. this.x = Math.min( this.x, v.x );
  996. this.y = Math.min( this.y, v.y );
  997. this.z = Math.min( this.z, v.z );
  998. this.w = Math.min( this.w, v.w );
  999. return this;
  1000. },
  1001. max: function ( v ) {
  1002. this.x = Math.max( this.x, v.x );
  1003. this.y = Math.max( this.y, v.y );
  1004. this.z = Math.max( this.z, v.z );
  1005. this.w = Math.max( this.w, v.w );
  1006. return this;
  1007. },
  1008. clamp: function ( min, max ) {
  1009. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1010. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1011. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1012. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1013. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1014. return this;
  1015. },
  1016. clampScalar: function () {
  1017. var min = new Vector4();
  1018. var max = new Vector4();
  1019. return function clampScalar( minVal, maxVal ) {
  1020. min.set( minVal, minVal, minVal, minVal );
  1021. max.set( maxVal, maxVal, maxVal, maxVal );
  1022. return this.clamp( min, max );
  1023. };
  1024. }(),
  1025. floor: function () {
  1026. this.x = Math.floor( this.x );
  1027. this.y = Math.floor( this.y );
  1028. this.z = Math.floor( this.z );
  1029. this.w = Math.floor( this.w );
  1030. return this;
  1031. },
  1032. ceil: function () {
  1033. this.x = Math.ceil( this.x );
  1034. this.y = Math.ceil( this.y );
  1035. this.z = Math.ceil( this.z );
  1036. this.w = Math.ceil( this.w );
  1037. return this;
  1038. },
  1039. round: function () {
  1040. this.x = Math.round( this.x );
  1041. this.y = Math.round( this.y );
  1042. this.z = Math.round( this.z );
  1043. this.w = Math.round( this.w );
  1044. return this;
  1045. },
  1046. roundToZero: function () {
  1047. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1048. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1049. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1050. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1051. return this;
  1052. },
  1053. negate: function () {
  1054. this.x = - this.x;
  1055. this.y = - this.y;
  1056. this.z = - this.z;
  1057. this.w = - this.w;
  1058. return this;
  1059. },
  1060. dot: function ( v ) {
  1061. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1062. },
  1063. lengthSq: function () {
  1064. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1065. },
  1066. length: function () {
  1067. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1068. },
  1069. lengthManhattan: function () {
  1070. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1071. },
  1072. normalize: function () {
  1073. return this.divideScalar( this.length() );
  1074. },
  1075. setLength: function ( length ) {
  1076. return this.multiplyScalar( length / this.length() );
  1077. },
  1078. lerp: function ( v, alpha ) {
  1079. this.x += ( v.x - this.x ) * alpha;
  1080. this.y += ( v.y - this.y ) * alpha;
  1081. this.z += ( v.z - this.z ) * alpha;
  1082. this.w += ( v.w - this.w ) * alpha;
  1083. return this;
  1084. },
  1085. lerpVectors: function ( v1, v2, alpha ) {
  1086. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1087. },
  1088. equals: function ( v ) {
  1089. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1090. },
  1091. fromArray: function ( array, offset ) {
  1092. if ( offset === undefined ) offset = 0;
  1093. this.x = array[ offset ];
  1094. this.y = array[ offset + 1 ];
  1095. this.z = array[ offset + 2 ];
  1096. this.w = array[ offset + 3 ];
  1097. return this;
  1098. },
  1099. toArray: function ( array, offset ) {
  1100. if ( array === undefined ) array = [];
  1101. if ( offset === undefined ) offset = 0;
  1102. array[ offset ] = this.x;
  1103. array[ offset + 1 ] = this.y;
  1104. array[ offset + 2 ] = this.z;
  1105. array[ offset + 3 ] = this.w;
  1106. return array;
  1107. },
  1108. fromBufferAttribute: function ( attribute, index, offset ) {
  1109. if ( offset !== undefined ) {
  1110. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1111. }
  1112. this.x = attribute.getX( index );
  1113. this.y = attribute.getY( index );
  1114. this.z = attribute.getZ( index );
  1115. this.w = attribute.getW( index );
  1116. return this;
  1117. }
  1118. } );
  1119. /**
  1120. * @author szimek / https://github.com/szimek/
  1121. * @author alteredq / http://alteredqualia.com/
  1122. * @author Marius Kintel / https://github.com/kintel
  1123. */
  1124. /*
  1125. In options, we can specify:
  1126. * Texture parameters for an auto-generated target texture
  1127. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1128. */
  1129. function WebGLRenderTarget( width, height, options ) {
  1130. this.uuid = _Math.generateUUID();
  1131. this.width = width;
  1132. this.height = height;
  1133. this.scissor = new Vector4( 0, 0, width, height );
  1134. this.scissorTest = false;
  1135. this.viewport = new Vector4( 0, 0, width, height );
  1136. options = options || {};
  1137. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  1138. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1139. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1140. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  1141. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1142. }
  1143. Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, {
  1144. isWebGLRenderTarget: true,
  1145. setSize: function ( width, height ) {
  1146. if ( this.width !== width || this.height !== height ) {
  1147. this.width = width;
  1148. this.height = height;
  1149. this.dispose();
  1150. }
  1151. this.viewport.set( 0, 0, width, height );
  1152. this.scissor.set( 0, 0, width, height );
  1153. },
  1154. clone: function () {
  1155. return new this.constructor().copy( this );
  1156. },
  1157. copy: function ( source ) {
  1158. this.width = source.width;
  1159. this.height = source.height;
  1160. this.viewport.copy( source.viewport );
  1161. this.texture = source.texture.clone();
  1162. this.depthBuffer = source.depthBuffer;
  1163. this.stencilBuffer = source.stencilBuffer;
  1164. this.depthTexture = source.depthTexture;
  1165. return this;
  1166. },
  1167. dispose: function () {
  1168. this.dispatchEvent( { type: 'dispose' } );
  1169. }
  1170. } );
  1171. /**
  1172. * @author alteredq / http://alteredqualia.com
  1173. */
  1174. function WebGLRenderTargetCube( width, height, options ) {
  1175. WebGLRenderTarget.call( this, width, height, options );
  1176. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  1177. this.activeMipMapLevel = 0;
  1178. }
  1179. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  1180. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  1181. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  1182. /**
  1183. * @author mikael emtinger / http://gomo.se/
  1184. * @author alteredq / http://alteredqualia.com/
  1185. * @author WestLangley / http://github.com/WestLangley
  1186. * @author bhouston / http://clara.io
  1187. */
  1188. function Quaternion( x, y, z, w ) {
  1189. this._x = x || 0;
  1190. this._y = y || 0;
  1191. this._z = z || 0;
  1192. this._w = ( w !== undefined ) ? w : 1;
  1193. }
  1194. Object.assign( Quaternion, {
  1195. slerp: function ( qa, qb, qm, t ) {
  1196. return qm.copy( qa ).slerp( qb, t );
  1197. },
  1198. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1199. // fuzz-free, array-based Quaternion SLERP operation
  1200. var x0 = src0[ srcOffset0 + 0 ],
  1201. y0 = src0[ srcOffset0 + 1 ],
  1202. z0 = src0[ srcOffset0 + 2 ],
  1203. w0 = src0[ srcOffset0 + 3 ],
  1204. x1 = src1[ srcOffset1 + 0 ],
  1205. y1 = src1[ srcOffset1 + 1 ],
  1206. z1 = src1[ srcOffset1 + 2 ],
  1207. w1 = src1[ srcOffset1 + 3 ];
  1208. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1209. var s = 1 - t,
  1210. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1211. dir = ( cos >= 0 ? 1 : - 1 ),
  1212. sqrSin = 1 - cos * cos;
  1213. // Skip the Slerp for tiny steps to avoid numeric problems:
  1214. if ( sqrSin > Number.EPSILON ) {
  1215. var sin = Math.sqrt( sqrSin ),
  1216. len = Math.atan2( sin, cos * dir );
  1217. s = Math.sin( s * len ) / sin;
  1218. t = Math.sin( t * len ) / sin;
  1219. }
  1220. var tDir = t * dir;
  1221. x0 = x0 * s + x1 * tDir;
  1222. y0 = y0 * s + y1 * tDir;
  1223. z0 = z0 * s + z1 * tDir;
  1224. w0 = w0 * s + w1 * tDir;
  1225. // Normalize in case we just did a lerp:
  1226. if ( s === 1 - t ) {
  1227. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1228. x0 *= f;
  1229. y0 *= f;
  1230. z0 *= f;
  1231. w0 *= f;
  1232. }
  1233. }
  1234. dst[ dstOffset ] = x0;
  1235. dst[ dstOffset + 1 ] = y0;
  1236. dst[ dstOffset + 2 ] = z0;
  1237. dst[ dstOffset + 3 ] = w0;
  1238. }
  1239. } );
  1240. Object.defineProperties( Quaternion.prototype, {
  1241. x: {
  1242. get: function () {
  1243. return this._x;
  1244. },
  1245. set: function ( value ) {
  1246. this._x = value;
  1247. this.onChangeCallback();
  1248. }
  1249. },
  1250. y: {
  1251. get: function () {
  1252. return this._y;
  1253. },
  1254. set: function ( value ) {
  1255. this._y = value;
  1256. this.onChangeCallback();
  1257. }
  1258. },
  1259. z: {
  1260. get: function () {
  1261. return this._z;
  1262. },
  1263. set: function ( value ) {
  1264. this._z = value;
  1265. this.onChangeCallback();
  1266. }
  1267. },
  1268. w: {
  1269. get: function () {
  1270. return this._w;
  1271. },
  1272. set: function ( value ) {
  1273. this._w = value;
  1274. this.onChangeCallback();
  1275. }
  1276. }
  1277. } );
  1278. Object.assign( Quaternion.prototype, {
  1279. set: function ( x, y, z, w ) {
  1280. this._x = x;
  1281. this._y = y;
  1282. this._z = z;
  1283. this._w = w;
  1284. this.onChangeCallback();
  1285. return this;
  1286. },
  1287. clone: function () {
  1288. return new this.constructor( this._x, this._y, this._z, this._w );
  1289. },
  1290. copy: function ( quaternion ) {
  1291. this._x = quaternion.x;
  1292. this._y = quaternion.y;
  1293. this._z = quaternion.z;
  1294. this._w = quaternion.w;
  1295. this.onChangeCallback();
  1296. return this;
  1297. },
  1298. setFromEuler: function ( euler, update ) {
  1299. if ( ! ( euler && euler.isEuler ) ) {
  1300. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1301. }
  1302. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1303. // http://www.mathworks.com/matlabcentral/fileexchange/
  1304. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1305. // content/SpinCalc.m
  1306. var cos = Math.cos;
  1307. var sin = Math.sin;
  1308. var c1 = cos( x / 2 );
  1309. var c2 = cos( y / 2 );
  1310. var c3 = cos( z / 2 );
  1311. var s1 = sin( x / 2 );
  1312. var s2 = sin( y / 2 );
  1313. var s3 = sin( z / 2 );
  1314. if ( order === 'XYZ' ) {
  1315. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1316. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1317. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1318. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1319. } else if ( order === 'YXZ' ) {
  1320. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1321. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1322. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1323. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1324. } else if ( order === 'ZXY' ) {
  1325. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1326. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1327. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1328. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1329. } else if ( order === 'ZYX' ) {
  1330. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1331. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1332. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1333. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1334. } else if ( order === 'YZX' ) {
  1335. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1336. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1337. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1338. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1339. } else if ( order === 'XZY' ) {
  1340. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1341. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1342. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1343. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1344. }
  1345. if ( update !== false ) this.onChangeCallback();
  1346. return this;
  1347. },
  1348. setFromAxisAngle: function ( axis, angle ) {
  1349. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1350. // assumes axis is normalized
  1351. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1352. this._x = axis.x * s;
  1353. this._y = axis.y * s;
  1354. this._z = axis.z * s;
  1355. this._w = Math.cos( halfAngle );
  1356. this.onChangeCallback();
  1357. return this;
  1358. },
  1359. setFromRotationMatrix: function ( m ) {
  1360. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1361. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1362. var te = m.elements,
  1363. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1364. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1365. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1366. trace = m11 + m22 + m33,
  1367. s;
  1368. if ( trace > 0 ) {
  1369. s = 0.5 / Math.sqrt( trace + 1.0 );
  1370. this._w = 0.25 / s;
  1371. this._x = ( m32 - m23 ) * s;
  1372. this._y = ( m13 - m31 ) * s;
  1373. this._z = ( m21 - m12 ) * s;
  1374. } else if ( m11 > m22 && m11 > m33 ) {
  1375. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1376. this._w = ( m32 - m23 ) / s;
  1377. this._x = 0.25 * s;
  1378. this._y = ( m12 + m21 ) / s;
  1379. this._z = ( m13 + m31 ) / s;
  1380. } else if ( m22 > m33 ) {
  1381. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1382. this._w = ( m13 - m31 ) / s;
  1383. this._x = ( m12 + m21 ) / s;
  1384. this._y = 0.25 * s;
  1385. this._z = ( m23 + m32 ) / s;
  1386. } else {
  1387. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1388. this._w = ( m21 - m12 ) / s;
  1389. this._x = ( m13 + m31 ) / s;
  1390. this._y = ( m23 + m32 ) / s;
  1391. this._z = 0.25 * s;
  1392. }
  1393. this.onChangeCallback();
  1394. return this;
  1395. },
  1396. setFromUnitVectors: function () {
  1397. // assumes direction vectors vFrom and vTo are normalized
  1398. var v1 = new Vector3();
  1399. var r;
  1400. var EPS = 0.000001;
  1401. return function setFromUnitVectors( vFrom, vTo ) {
  1402. if ( v1 === undefined ) v1 = new Vector3();
  1403. r = vFrom.dot( vTo ) + 1;
  1404. if ( r < EPS ) {
  1405. r = 0;
  1406. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1407. v1.set( - vFrom.y, vFrom.x, 0 );
  1408. } else {
  1409. v1.set( 0, - vFrom.z, vFrom.y );
  1410. }
  1411. } else {
  1412. v1.crossVectors( vFrom, vTo );
  1413. }
  1414. this._x = v1.x;
  1415. this._y = v1.y;
  1416. this._z = v1.z;
  1417. this._w = r;
  1418. return this.normalize();
  1419. };
  1420. }(),
  1421. inverse: function () {
  1422. return this.conjugate().normalize();
  1423. },
  1424. conjugate: function () {
  1425. this._x *= - 1;
  1426. this._y *= - 1;
  1427. this._z *= - 1;
  1428. this.onChangeCallback();
  1429. return this;
  1430. },
  1431. dot: function ( v ) {
  1432. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1433. },
  1434. lengthSq: function () {
  1435. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1436. },
  1437. length: function () {
  1438. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1439. },
  1440. normalize: function () {
  1441. var l = this.length();
  1442. if ( l === 0 ) {
  1443. this._x = 0;
  1444. this._y = 0;
  1445. this._z = 0;
  1446. this._w = 1;
  1447. } else {
  1448. l = 1 / l;
  1449. this._x = this._x * l;
  1450. this._y = this._y * l;
  1451. this._z = this._z * l;
  1452. this._w = this._w * l;
  1453. }
  1454. this.onChangeCallback();
  1455. return this;
  1456. },
  1457. multiply: function ( q, p ) {
  1458. if ( p !== undefined ) {
  1459. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1460. return this.multiplyQuaternions( q, p );
  1461. }
  1462. return this.multiplyQuaternions( this, q );
  1463. },
  1464. premultiply: function ( q ) {
  1465. return this.multiplyQuaternions( q, this );
  1466. },
  1467. multiplyQuaternions: function ( a, b ) {
  1468. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1469. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1470. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1471. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1472. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1473. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1474. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1475. this.onChangeCallback();
  1476. return this;
  1477. },
  1478. slerp: function ( qb, t ) {
  1479. if ( t === 0 ) return this;
  1480. if ( t === 1 ) return this.copy( qb );
  1481. var x = this._x, y = this._y, z = this._z, w = this._w;
  1482. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1483. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1484. if ( cosHalfTheta < 0 ) {
  1485. this._w = - qb._w;
  1486. this._x = - qb._x;
  1487. this._y = - qb._y;
  1488. this._z = - qb._z;
  1489. cosHalfTheta = - cosHalfTheta;
  1490. } else {
  1491. this.copy( qb );
  1492. }
  1493. if ( cosHalfTheta >= 1.0 ) {
  1494. this._w = w;
  1495. this._x = x;
  1496. this._y = y;
  1497. this._z = z;
  1498. return this;
  1499. }
  1500. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1501. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1502. this._w = 0.5 * ( w + this._w );
  1503. this._x = 0.5 * ( x + this._x );
  1504. this._y = 0.5 * ( y + this._y );
  1505. this._z = 0.5 * ( z + this._z );
  1506. return this;
  1507. }
  1508. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1509. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1510. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1511. this._w = ( w * ratioA + this._w * ratioB );
  1512. this._x = ( x * ratioA + this._x * ratioB );
  1513. this._y = ( y * ratioA + this._y * ratioB );
  1514. this._z = ( z * ratioA + this._z * ratioB );
  1515. this.onChangeCallback();
  1516. return this;
  1517. },
  1518. equals: function ( quaternion ) {
  1519. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1520. },
  1521. fromArray: function ( array, offset ) {
  1522. if ( offset === undefined ) offset = 0;
  1523. this._x = array[ offset ];
  1524. this._y = array[ offset + 1 ];
  1525. this._z = array[ offset + 2 ];
  1526. this._w = array[ offset + 3 ];
  1527. this.onChangeCallback();
  1528. return this;
  1529. },
  1530. toArray: function ( array, offset ) {
  1531. if ( array === undefined ) array = [];
  1532. if ( offset === undefined ) offset = 0;
  1533. array[ offset ] = this._x;
  1534. array[ offset + 1 ] = this._y;
  1535. array[ offset + 2 ] = this._z;
  1536. array[ offset + 3 ] = this._w;
  1537. return array;
  1538. },
  1539. onChange: function ( callback ) {
  1540. this.onChangeCallback = callback;
  1541. return this;
  1542. },
  1543. onChangeCallback: function () {}
  1544. } );
  1545. /**
  1546. * @author mrdoob / http://mrdoob.com/
  1547. * @author *kile / http://kile.stravaganza.org/
  1548. * @author philogb / http://blog.thejit.org/
  1549. * @author mikael emtinger / http://gomo.se/
  1550. * @author egraether / http://egraether.com/
  1551. * @author WestLangley / http://github.com/WestLangley
  1552. */
  1553. function Vector3( x, y, z ) {
  1554. this.x = x || 0;
  1555. this.y = y || 0;
  1556. this.z = z || 0;
  1557. }
  1558. Object.assign( Vector3.prototype, {
  1559. isVector3: true,
  1560. set: function ( x, y, z ) {
  1561. this.x = x;
  1562. this.y = y;
  1563. this.z = z;
  1564. return this;
  1565. },
  1566. setScalar: function ( scalar ) {
  1567. this.x = scalar;
  1568. this.y = scalar;
  1569. this.z = scalar;
  1570. return this;
  1571. },
  1572. setX: function ( x ) {
  1573. this.x = x;
  1574. return this;
  1575. },
  1576. setY: function ( y ) {
  1577. this.y = y;
  1578. return this;
  1579. },
  1580. setZ: function ( z ) {
  1581. this.z = z;
  1582. return this;
  1583. },
  1584. setComponent: function ( index, value ) {
  1585. switch ( index ) {
  1586. case 0: this.x = value; break;
  1587. case 1: this.y = value; break;
  1588. case 2: this.z = value; break;
  1589. default: throw new Error( 'index is out of range: ' + index );
  1590. }
  1591. return this;
  1592. },
  1593. getComponent: function ( index ) {
  1594. switch ( index ) {
  1595. case 0: return this.x;
  1596. case 1: return this.y;
  1597. case 2: return this.z;
  1598. default: throw new Error( 'index is out of range: ' + index );
  1599. }
  1600. },
  1601. clone: function () {
  1602. return new this.constructor( this.x, this.y, this.z );
  1603. },
  1604. copy: function ( v ) {
  1605. this.x = v.x;
  1606. this.y = v.y;
  1607. this.z = v.z;
  1608. return this;
  1609. },
  1610. add: function ( v, w ) {
  1611. if ( w !== undefined ) {
  1612. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1613. return this.addVectors( v, w );
  1614. }
  1615. this.x += v.x;
  1616. this.y += v.y;
  1617. this.z += v.z;
  1618. return this;
  1619. },
  1620. addScalar: function ( s ) {
  1621. this.x += s;
  1622. this.y += s;
  1623. this.z += s;
  1624. return this;
  1625. },
  1626. addVectors: function ( a, b ) {
  1627. this.x = a.x + b.x;
  1628. this.y = a.y + b.y;
  1629. this.z = a.z + b.z;
  1630. return this;
  1631. },
  1632. addScaledVector: function ( v, s ) {
  1633. this.x += v.x * s;
  1634. this.y += v.y * s;
  1635. this.z += v.z * s;
  1636. return this;
  1637. },
  1638. sub: function ( v, w ) {
  1639. if ( w !== undefined ) {
  1640. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1641. return this.subVectors( v, w );
  1642. }
  1643. this.x -= v.x;
  1644. this.y -= v.y;
  1645. this.z -= v.z;
  1646. return this;
  1647. },
  1648. subScalar: function ( s ) {
  1649. this.x -= s;
  1650. this.y -= s;
  1651. this.z -= s;
  1652. return this;
  1653. },
  1654. subVectors: function ( a, b ) {
  1655. this.x = a.x - b.x;
  1656. this.y = a.y - b.y;
  1657. this.z = a.z - b.z;
  1658. return this;
  1659. },
  1660. multiply: function ( v, w ) {
  1661. if ( w !== undefined ) {
  1662. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1663. return this.multiplyVectors( v, w );
  1664. }
  1665. this.x *= v.x;
  1666. this.y *= v.y;
  1667. this.z *= v.z;
  1668. return this;
  1669. },
  1670. multiplyScalar: function ( scalar ) {
  1671. this.x *= scalar;
  1672. this.y *= scalar;
  1673. this.z *= scalar;
  1674. return this;
  1675. },
  1676. multiplyVectors: function ( a, b ) {
  1677. this.x = a.x * b.x;
  1678. this.y = a.y * b.y;
  1679. this.z = a.z * b.z;
  1680. return this;
  1681. },
  1682. applyEuler: function () {
  1683. var quaternion = new Quaternion();
  1684. return function applyEuler( euler ) {
  1685. if ( ! ( euler && euler.isEuler ) ) {
  1686. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1687. }
  1688. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1689. };
  1690. }(),
  1691. applyAxisAngle: function () {
  1692. var quaternion = new Quaternion();
  1693. return function applyAxisAngle( axis, angle ) {
  1694. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1695. };
  1696. }(),
  1697. applyMatrix3: function ( m ) {
  1698. var x = this.x, y = this.y, z = this.z;
  1699. var e = m.elements;
  1700. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1701. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1702. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1703. return this;
  1704. },
  1705. applyMatrix4: function ( m ) {
  1706. var x = this.x, y = this.y, z = this.z;
  1707. var e = m.elements;
  1708. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1709. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1710. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1711. var w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ];
  1712. return this.divideScalar( w );
  1713. },
  1714. applyQuaternion: function ( q ) {
  1715. var x = this.x, y = this.y, z = this.z;
  1716. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1717. // calculate quat * vector
  1718. var ix = qw * x + qy * z - qz * y;
  1719. var iy = qw * y + qz * x - qx * z;
  1720. var iz = qw * z + qx * y - qy * x;
  1721. var iw = - qx * x - qy * y - qz * z;
  1722. // calculate result * inverse quat
  1723. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1724. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1725. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1726. return this;
  1727. },
  1728. project: function () {
  1729. var matrix = new Matrix4();
  1730. return function project( camera ) {
  1731. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1732. return this.applyMatrix4( matrix );
  1733. };
  1734. }(),
  1735. unproject: function () {
  1736. var matrix = new Matrix4();
  1737. return function unproject( camera ) {
  1738. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1739. return this.applyMatrix4( matrix );
  1740. };
  1741. }(),
  1742. transformDirection: function ( m ) {
  1743. // input: THREE.Matrix4 affine matrix
  1744. // vector interpreted as a direction
  1745. var x = this.x, y = this.y, z = this.z;
  1746. var e = m.elements;
  1747. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1748. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1749. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1750. return this.normalize();
  1751. },
  1752. divide: function ( v ) {
  1753. this.x /= v.x;
  1754. this.y /= v.y;
  1755. this.z /= v.z;
  1756. return this;
  1757. },
  1758. divideScalar: function ( scalar ) {
  1759. return this.multiplyScalar( 1 / scalar );
  1760. },
  1761. min: function ( v ) {
  1762. this.x = Math.min( this.x, v.x );
  1763. this.y = Math.min( this.y, v.y );
  1764. this.z = Math.min( this.z, v.z );
  1765. return this;
  1766. },
  1767. max: function ( v ) {
  1768. this.x = Math.max( this.x, v.x );
  1769. this.y = Math.max( this.y, v.y );
  1770. this.z = Math.max( this.z, v.z );
  1771. return this;
  1772. },
  1773. clamp: function ( min, max ) {
  1774. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1775. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1776. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1777. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1778. return this;
  1779. },
  1780. clampScalar: function () {
  1781. var min = new Vector3();
  1782. var max = new Vector3();
  1783. return function clampScalar( minVal, maxVal ) {
  1784. min.set( minVal, minVal, minVal );
  1785. max.set( maxVal, maxVal, maxVal );
  1786. return this.clamp( min, max );
  1787. };
  1788. }(),
  1789. clampLength: function ( min, max ) {
  1790. var length = this.length();
  1791. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1792. },
  1793. floor: function () {
  1794. this.x = Math.floor( this.x );
  1795. this.y = Math.floor( this.y );
  1796. this.z = Math.floor( this.z );
  1797. return this;
  1798. },
  1799. ceil: function () {
  1800. this.x = Math.ceil( this.x );
  1801. this.y = Math.ceil( this.y );
  1802. this.z = Math.ceil( this.z );
  1803. return this;
  1804. },
  1805. round: function () {
  1806. this.x = Math.round( this.x );
  1807. this.y = Math.round( this.y );
  1808. this.z = Math.round( this.z );
  1809. return this;
  1810. },
  1811. roundToZero: function () {
  1812. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1813. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1814. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1815. return this;
  1816. },
  1817. negate: function () {
  1818. this.x = - this.x;
  1819. this.y = - this.y;
  1820. this.z = - this.z;
  1821. return this;
  1822. },
  1823. dot: function ( v ) {
  1824. return this.x * v.x + this.y * v.y + this.z * v.z;
  1825. },
  1826. // TODO lengthSquared?
  1827. lengthSq: function () {
  1828. return this.x * this.x + this.y * this.y + this.z * this.z;
  1829. },
  1830. length: function () {
  1831. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1832. },
  1833. lengthManhattan: function () {
  1834. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1835. },
  1836. normalize: function () {
  1837. return this.divideScalar( this.length() );
  1838. },
  1839. setLength: function ( length ) {
  1840. return this.multiplyScalar( length / this.length() );
  1841. },
  1842. lerp: function ( v, alpha ) {
  1843. this.x += ( v.x - this.x ) * alpha;
  1844. this.y += ( v.y - this.y ) * alpha;
  1845. this.z += ( v.z - this.z ) * alpha;
  1846. return this;
  1847. },
  1848. lerpVectors: function ( v1, v2, alpha ) {
  1849. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1850. },
  1851. cross: function ( v, w ) {
  1852. if ( w !== undefined ) {
  1853. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1854. return this.crossVectors( v, w );
  1855. }
  1856. var x = this.x, y = this.y, z = this.z;
  1857. this.x = y * v.z - z * v.y;
  1858. this.y = z * v.x - x * v.z;
  1859. this.z = x * v.y - y * v.x;
  1860. return this;
  1861. },
  1862. crossVectors: function ( a, b ) {
  1863. var ax = a.x, ay = a.y, az = a.z;
  1864. var bx = b.x, by = b.y, bz = b.z;
  1865. this.x = ay * bz - az * by;
  1866. this.y = az * bx - ax * bz;
  1867. this.z = ax * by - ay * bx;
  1868. return this;
  1869. },
  1870. projectOnVector: function ( vector ) {
  1871. var scalar = vector.dot( this ) / vector.lengthSq();
  1872. return this.copy( vector ).multiplyScalar( scalar );
  1873. },
  1874. projectOnPlane: function () {
  1875. var v1 = new Vector3();
  1876. return function projectOnPlane( planeNormal ) {
  1877. v1.copy( this ).projectOnVector( planeNormal );
  1878. return this.sub( v1 );
  1879. };
  1880. }(),
  1881. reflect: function () {
  1882. // reflect incident vector off plane orthogonal to normal
  1883. // normal is assumed to have unit length
  1884. var v1 = new Vector3();
  1885. return function reflect( normal ) {
  1886. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1887. };
  1888. }(),
  1889. angleTo: function ( v ) {
  1890. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1891. // clamp, to handle numerical problems
  1892. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1893. },
  1894. distanceTo: function ( v ) {
  1895. return Math.sqrt( this.distanceToSquared( v ) );
  1896. },
  1897. distanceToSquared: function ( v ) {
  1898. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1899. return dx * dx + dy * dy + dz * dz;
  1900. },
  1901. distanceToManhattan: function ( v ) {
  1902. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1903. },
  1904. setFromSpherical: function ( s ) {
  1905. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1906. this.x = sinPhiRadius * Math.sin( s.theta );
  1907. this.y = Math.cos( s.phi ) * s.radius;
  1908. this.z = sinPhiRadius * Math.cos( s.theta );
  1909. return this;
  1910. },
  1911. setFromCylindrical: function ( c ) {
  1912. this.x = c.radius * Math.sin( c.theta );
  1913. this.y = c.y;
  1914. this.z = c.radius * Math.cos( c.theta );
  1915. return this;
  1916. },
  1917. setFromMatrixPosition: function ( m ) {
  1918. return this.setFromMatrixColumn( m, 3 );
  1919. },
  1920. setFromMatrixScale: function ( m ) {
  1921. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1922. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1923. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1924. this.x = sx;
  1925. this.y = sy;
  1926. this.z = sz;
  1927. return this;
  1928. },
  1929. setFromMatrixColumn: function ( m, index ) {
  1930. return this.fromArray( m.elements, index * 4 );
  1931. },
  1932. equals: function ( v ) {
  1933. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1934. },
  1935. fromArray: function ( array, offset ) {
  1936. if ( offset === undefined ) offset = 0;
  1937. this.x = array[ offset ];
  1938. this.y = array[ offset + 1 ];
  1939. this.z = array[ offset + 2 ];
  1940. return this;
  1941. },
  1942. toArray: function ( array, offset ) {
  1943. if ( array === undefined ) array = [];
  1944. if ( offset === undefined ) offset = 0;
  1945. array[ offset ] = this.x;
  1946. array[ offset + 1 ] = this.y;
  1947. array[ offset + 2 ] = this.z;
  1948. return array;
  1949. },
  1950. fromBufferAttribute: function ( attribute, index, offset ) {
  1951. if ( offset !== undefined ) {
  1952. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1953. }
  1954. this.x = attribute.getX( index );
  1955. this.y = attribute.getY( index );
  1956. this.z = attribute.getZ( index );
  1957. return this;
  1958. }
  1959. } );
  1960. /**
  1961. * @author mrdoob / http://mrdoob.com/
  1962. * @author supereggbert / http://www.paulbrunt.co.uk/
  1963. * @author philogb / http://blog.thejit.org/
  1964. * @author jordi_ros / http://plattsoft.com
  1965. * @author D1plo1d / http://github.com/D1plo1d
  1966. * @author alteredq / http://alteredqualia.com/
  1967. * @author mikael emtinger / http://gomo.se/
  1968. * @author timknip / http://www.floorplanner.com/
  1969. * @author bhouston / http://clara.io
  1970. * @author WestLangley / http://github.com/WestLangley
  1971. */
  1972. function Matrix4() {
  1973. this.elements = [
  1974. 1, 0, 0, 0,
  1975. 0, 1, 0, 0,
  1976. 0, 0, 1, 0,
  1977. 0, 0, 0, 1
  1978. ];
  1979. if ( arguments.length > 0 ) {
  1980. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  1981. }
  1982. }
  1983. Object.assign( Matrix4.prototype, {
  1984. isMatrix4: true,
  1985. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  1986. var te = this.elements;
  1987. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  1988. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  1989. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  1990. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  1991. return this;
  1992. },
  1993. identity: function () {
  1994. this.set(
  1995. 1, 0, 0, 0,
  1996. 0, 1, 0, 0,
  1997. 0, 0, 1, 0,
  1998. 0, 0, 0, 1
  1999. );
  2000. return this;
  2001. },
  2002. clone: function () {
  2003. return new Matrix4().fromArray( this.elements );
  2004. },
  2005. copy: function ( m ) {
  2006. var te = this.elements;
  2007. var me = m.elements;
  2008. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2009. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2010. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2011. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2012. return this;
  2013. },
  2014. copyPosition: function ( m ) {
  2015. var te = this.elements, me = m.elements;
  2016. te[ 12 ] = me[ 12 ];
  2017. te[ 13 ] = me[ 13 ];
  2018. te[ 14 ] = me[ 14 ];
  2019. return this;
  2020. },
  2021. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2022. xAxis.setFromMatrixColumn( this, 0 );
  2023. yAxis.setFromMatrixColumn( this, 1 );
  2024. zAxis.setFromMatrixColumn( this, 2 );
  2025. return this;
  2026. },
  2027. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2028. this.set(
  2029. xAxis.x, yAxis.x, zAxis.x, 0,
  2030. xAxis.y, yAxis.y, zAxis.y, 0,
  2031. xAxis.z, yAxis.z, zAxis.z, 0,
  2032. 0, 0, 0, 1
  2033. );
  2034. return this;
  2035. },
  2036. extractRotation: function () {
  2037. var v1 = new Vector3();
  2038. return function extractRotation( m ) {
  2039. var te = this.elements;
  2040. var me = m.elements;
  2041. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2042. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2043. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2044. te[ 0 ] = me[ 0 ] * scaleX;
  2045. te[ 1 ] = me[ 1 ] * scaleX;
  2046. te[ 2 ] = me[ 2 ] * scaleX;
  2047. te[ 4 ] = me[ 4 ] * scaleY;
  2048. te[ 5 ] = me[ 5 ] * scaleY;
  2049. te[ 6 ] = me[ 6 ] * scaleY;
  2050. te[ 8 ] = me[ 8 ] * scaleZ;
  2051. te[ 9 ] = me[ 9 ] * scaleZ;
  2052. te[ 10 ] = me[ 10 ] * scaleZ;
  2053. return this;
  2054. };
  2055. }(),
  2056. makeRotationFromEuler: function ( euler ) {
  2057. if ( ! ( euler && euler.isEuler ) ) {
  2058. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2059. }
  2060. var te = this.elements;
  2061. var x = euler.x, y = euler.y, z = euler.z;
  2062. var a = Math.cos( x ), b = Math.sin( x );
  2063. var c = Math.cos( y ), d = Math.sin( y );
  2064. var e = Math.cos( z ), f = Math.sin( z );
  2065. if ( euler.order === 'XYZ' ) {
  2066. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2067. te[ 0 ] = c * e;
  2068. te[ 4 ] = - c * f;
  2069. te[ 8 ] = d;
  2070. te[ 1 ] = af + be * d;
  2071. te[ 5 ] = ae - bf * d;
  2072. te[ 9 ] = - b * c;
  2073. te[ 2 ] = bf - ae * d;
  2074. te[ 6 ] = be + af * d;
  2075. te[ 10 ] = a * c;
  2076. } else if ( euler.order === 'YXZ' ) {
  2077. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2078. te[ 0 ] = ce + df * b;
  2079. te[ 4 ] = de * b - cf;
  2080. te[ 8 ] = a * d;
  2081. te[ 1 ] = a * f;
  2082. te[ 5 ] = a * e;
  2083. te[ 9 ] = - b;
  2084. te[ 2 ] = cf * b - de;
  2085. te[ 6 ] = df + ce * b;
  2086. te[ 10 ] = a * c;
  2087. } else if ( euler.order === 'ZXY' ) {
  2088. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2089. te[ 0 ] = ce - df * b;
  2090. te[ 4 ] = - a * f;
  2091. te[ 8 ] = de + cf * b;
  2092. te[ 1 ] = cf + de * b;
  2093. te[ 5 ] = a * e;
  2094. te[ 9 ] = df - ce * b;
  2095. te[ 2 ] = - a * d;
  2096. te[ 6 ] = b;
  2097. te[ 10 ] = a * c;
  2098. } else if ( euler.order === 'ZYX' ) {
  2099. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2100. te[ 0 ] = c * e;
  2101. te[ 4 ] = be * d - af;
  2102. te[ 8 ] = ae * d + bf;
  2103. te[ 1 ] = c * f;
  2104. te[ 5 ] = bf * d + ae;
  2105. te[ 9 ] = af * d - be;
  2106. te[ 2 ] = - d;
  2107. te[ 6 ] = b * c;
  2108. te[ 10 ] = a * c;
  2109. } else if ( euler.order === 'YZX' ) {
  2110. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2111. te[ 0 ] = c * e;
  2112. te[ 4 ] = bd - ac * f;
  2113. te[ 8 ] = bc * f + ad;
  2114. te[ 1 ] = f;
  2115. te[ 5 ] = a * e;
  2116. te[ 9 ] = - b * e;
  2117. te[ 2 ] = - d * e;
  2118. te[ 6 ] = ad * f + bc;
  2119. te[ 10 ] = ac - bd * f;
  2120. } else if ( euler.order === 'XZY' ) {
  2121. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2122. te[ 0 ] = c * e;
  2123. te[ 4 ] = - f;
  2124. te[ 8 ] = d * e;
  2125. te[ 1 ] = ac * f + bd;
  2126. te[ 5 ] = a * e;
  2127. te[ 9 ] = ad * f - bc;
  2128. te[ 2 ] = bc * f - ad;
  2129. te[ 6 ] = b * e;
  2130. te[ 10 ] = bd * f + ac;
  2131. }
  2132. // last column
  2133. te[ 3 ] = 0;
  2134. te[ 7 ] = 0;
  2135. te[ 11 ] = 0;
  2136. // bottom row
  2137. te[ 12 ] = 0;
  2138. te[ 13 ] = 0;
  2139. te[ 14 ] = 0;
  2140. te[ 15 ] = 1;
  2141. return this;
  2142. },
  2143. makeRotationFromQuaternion: function ( q ) {
  2144. var te = this.elements;
  2145. var x = q._x, y = q._y, z = q._z, w = q._w;
  2146. var x2 = x + x, y2 = y + y, z2 = z + z;
  2147. var xx = x * x2, xy = x * y2, xz = x * z2;
  2148. var yy = y * y2, yz = y * z2, zz = z * z2;
  2149. var wx = w * x2, wy = w * y2, wz = w * z2;
  2150. te[ 0 ] = 1 - ( yy + zz );
  2151. te[ 4 ] = xy - wz;
  2152. te[ 8 ] = xz + wy;
  2153. te[ 1 ] = xy + wz;
  2154. te[ 5 ] = 1 - ( xx + zz );
  2155. te[ 9 ] = yz - wx;
  2156. te[ 2 ] = xz - wy;
  2157. te[ 6 ] = yz + wx;
  2158. te[ 10 ] = 1 - ( xx + yy );
  2159. // last column
  2160. te[ 3 ] = 0;
  2161. te[ 7 ] = 0;
  2162. te[ 11 ] = 0;
  2163. // bottom row
  2164. te[ 12 ] = 0;
  2165. te[ 13 ] = 0;
  2166. te[ 14 ] = 0;
  2167. te[ 15 ] = 1;
  2168. return this;
  2169. },
  2170. lookAt: function () {
  2171. var x = new Vector3();
  2172. var y = new Vector3();
  2173. var z = new Vector3();
  2174. return function lookAt( eye, target, up ) {
  2175. var te = this.elements;
  2176. z.subVectors( eye, target );
  2177. if ( z.lengthSq() === 0 ) {
  2178. // eye and target are in the same position
  2179. z.z = 1;
  2180. }
  2181. z.normalize();
  2182. x.crossVectors( up, z );
  2183. if ( x.lengthSq() === 0 ) {
  2184. // eye and target are in the same vertical
  2185. z.z += 0.0001;
  2186. x.crossVectors( up, z );
  2187. }
  2188. x.normalize();
  2189. y.crossVectors( z, x );
  2190. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2191. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2192. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2193. return this;
  2194. };
  2195. }(),
  2196. multiply: function ( m, n ) {
  2197. if ( n !== undefined ) {
  2198. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2199. return this.multiplyMatrices( m, n );
  2200. }
  2201. return this.multiplyMatrices( this, m );
  2202. },
  2203. premultiply: function ( m ) {
  2204. return this.multiplyMatrices( m, this );
  2205. },
  2206. multiplyMatrices: function ( a, b ) {
  2207. var ae = a.elements;
  2208. var be = b.elements;
  2209. var te = this.elements;
  2210. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2211. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2212. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2213. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2214. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2215. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2216. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2217. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2218. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2219. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2220. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2221. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2222. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2223. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2224. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2225. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2226. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2227. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2228. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2229. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2230. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2231. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2232. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2233. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2234. return this;
  2235. },
  2236. multiplyScalar: function ( s ) {
  2237. var te = this.elements;
  2238. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2239. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2240. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2241. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2242. return this;
  2243. },
  2244. applyToBufferAttribute: function () {
  2245. var v1 = new Vector3();
  2246. return function applyToBufferAttribute( attribute ) {
  2247. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2248. v1.x = attribute.getX( i );
  2249. v1.y = attribute.getY( i );
  2250. v1.z = attribute.getZ( i );
  2251. v1.applyMatrix4( this );
  2252. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2253. }
  2254. return attribute;
  2255. };
  2256. }(),
  2257. determinant: function () {
  2258. var te = this.elements;
  2259. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2260. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2261. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2262. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2263. //TODO: make this more efficient
  2264. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2265. return (
  2266. n41 * (
  2267. + n14 * n23 * n32
  2268. - n13 * n24 * n32
  2269. - n14 * n22 * n33
  2270. + n12 * n24 * n33
  2271. + n13 * n22 * n34
  2272. - n12 * n23 * n34
  2273. ) +
  2274. n42 * (
  2275. + n11 * n23 * n34
  2276. - n11 * n24 * n33
  2277. + n14 * n21 * n33
  2278. - n13 * n21 * n34
  2279. + n13 * n24 * n31
  2280. - n14 * n23 * n31
  2281. ) +
  2282. n43 * (
  2283. + n11 * n24 * n32
  2284. - n11 * n22 * n34
  2285. - n14 * n21 * n32
  2286. + n12 * n21 * n34
  2287. + n14 * n22 * n31
  2288. - n12 * n24 * n31
  2289. ) +
  2290. n44 * (
  2291. - n13 * n22 * n31
  2292. - n11 * n23 * n32
  2293. + n11 * n22 * n33
  2294. + n13 * n21 * n32
  2295. - n12 * n21 * n33
  2296. + n12 * n23 * n31
  2297. )
  2298. );
  2299. },
  2300. transpose: function () {
  2301. var te = this.elements;
  2302. var tmp;
  2303. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2304. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2305. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2306. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2307. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2308. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2309. return this;
  2310. },
  2311. setPosition: function ( v ) {
  2312. var te = this.elements;
  2313. te[ 12 ] = v.x;
  2314. te[ 13 ] = v.y;
  2315. te[ 14 ] = v.z;
  2316. return this;
  2317. },
  2318. getInverse: function ( m, throwOnDegenerate ) {
  2319. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2320. var te = this.elements,
  2321. me = m.elements,
  2322. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2323. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2324. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2325. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2326. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2327. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2328. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2329. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2330. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2331. if ( det === 0 ) {
  2332. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  2333. if ( throwOnDegenerate === true ) {
  2334. throw new Error( msg );
  2335. } else {
  2336. console.warn( msg );
  2337. }
  2338. return this.identity();
  2339. }
  2340. var detInv = 1 / det;
  2341. te[ 0 ] = t11 * detInv;
  2342. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2343. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2344. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2345. te[ 4 ] = t12 * detInv;
  2346. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2347. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2348. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2349. te[ 8 ] = t13 * detInv;
  2350. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2351. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2352. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2353. te[ 12 ] = t14 * detInv;
  2354. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2355. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2356. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2357. return this;
  2358. },
  2359. scale: function ( v ) {
  2360. var te = this.elements;
  2361. var x = v.x, y = v.y, z = v.z;
  2362. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2363. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2364. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2365. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2366. return this;
  2367. },
  2368. getMaxScaleOnAxis: function () {
  2369. var te = this.elements;
  2370. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2371. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2372. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2373. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2374. },
  2375. makeTranslation: function ( x, y, z ) {
  2376. this.set(
  2377. 1, 0, 0, x,
  2378. 0, 1, 0, y,
  2379. 0, 0, 1, z,
  2380. 0, 0, 0, 1
  2381. );
  2382. return this;
  2383. },
  2384. makeRotationX: function ( theta ) {
  2385. var c = Math.cos( theta ), s = Math.sin( theta );
  2386. this.set(
  2387. 1, 0, 0, 0,
  2388. 0, c, - s, 0,
  2389. 0, s, c, 0,
  2390. 0, 0, 0, 1
  2391. );
  2392. return this;
  2393. },
  2394. makeRotationY: function ( theta ) {
  2395. var c = Math.cos( theta ), s = Math.sin( theta );
  2396. this.set(
  2397. c, 0, s, 0,
  2398. 0, 1, 0, 0,
  2399. - s, 0, c, 0,
  2400. 0, 0, 0, 1
  2401. );
  2402. return this;
  2403. },
  2404. makeRotationZ: function ( theta ) {
  2405. var c = Math.cos( theta ), s = Math.sin( theta );
  2406. this.set(
  2407. c, - s, 0, 0,
  2408. s, c, 0, 0,
  2409. 0, 0, 1, 0,
  2410. 0, 0, 0, 1
  2411. );
  2412. return this;
  2413. },
  2414. makeRotationAxis: function ( axis, angle ) {
  2415. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2416. var c = Math.cos( angle );
  2417. var s = Math.sin( angle );
  2418. var t = 1 - c;
  2419. var x = axis.x, y = axis.y, z = axis.z;
  2420. var tx = t * x, ty = t * y;
  2421. this.set(
  2422. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2423. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2424. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2425. 0, 0, 0, 1
  2426. );
  2427. return this;
  2428. },
  2429. makeScale: function ( x, y, z ) {
  2430. this.set(
  2431. x, 0, 0, 0,
  2432. 0, y, 0, 0,
  2433. 0, 0, z, 0,
  2434. 0, 0, 0, 1
  2435. );
  2436. return this;
  2437. },
  2438. makeShear: function ( x, y, z ) {
  2439. this.set(
  2440. 1, y, z, 0,
  2441. x, 1, z, 0,
  2442. x, y, 1, 0,
  2443. 0, 0, 0, 1
  2444. );
  2445. return this;
  2446. },
  2447. compose: function ( position, quaternion, scale ) {
  2448. this.makeRotationFromQuaternion( quaternion );
  2449. this.scale( scale );
  2450. this.setPosition( position );
  2451. return this;
  2452. },
  2453. decompose: function () {
  2454. var vector = new Vector3();
  2455. var matrix = new Matrix4();
  2456. return function decompose( position, quaternion, scale ) {
  2457. var te = this.elements;
  2458. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2459. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2460. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2461. // if determine is negative, we need to invert one scale
  2462. var det = this.determinant();
  2463. if ( det < 0 ) sx = - sx;
  2464. position.x = te[ 12 ];
  2465. position.y = te[ 13 ];
  2466. position.z = te[ 14 ];
  2467. // scale the rotation part
  2468. matrix.copy( this );
  2469. var invSX = 1 / sx;
  2470. var invSY = 1 / sy;
  2471. var invSZ = 1 / sz;
  2472. matrix.elements[ 0 ] *= invSX;
  2473. matrix.elements[ 1 ] *= invSX;
  2474. matrix.elements[ 2 ] *= invSX;
  2475. matrix.elements[ 4 ] *= invSY;
  2476. matrix.elements[ 5 ] *= invSY;
  2477. matrix.elements[ 6 ] *= invSY;
  2478. matrix.elements[ 8 ] *= invSZ;
  2479. matrix.elements[ 9 ] *= invSZ;
  2480. matrix.elements[ 10 ] *= invSZ;
  2481. quaternion.setFromRotationMatrix( matrix );
  2482. scale.x = sx;
  2483. scale.y = sy;
  2484. scale.z = sz;
  2485. return this;
  2486. };
  2487. }(),
  2488. makePerspective: function ( left, right, top, bottom, near, far ) {
  2489. if ( far === undefined ) {
  2490. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2491. }
  2492. var te = this.elements;
  2493. var x = 2 * near / ( right - left );
  2494. var y = 2 * near / ( top - bottom );
  2495. var a = ( right + left ) / ( right - left );
  2496. var b = ( top + bottom ) / ( top - bottom );
  2497. var c = - ( far + near ) / ( far - near );
  2498. var d = - 2 * far * near / ( far - near );
  2499. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2500. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2501. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2502. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2503. return this;
  2504. },
  2505. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2506. var te = this.elements;
  2507. var w = 1.0 / ( right - left );
  2508. var h = 1.0 / ( top - bottom );
  2509. var p = 1.0 / ( far - near );
  2510. var x = ( right + left ) * w;
  2511. var y = ( top + bottom ) * h;
  2512. var z = ( far + near ) * p;
  2513. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2514. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2515. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2516. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2517. return this;
  2518. },
  2519. equals: function ( matrix ) {
  2520. var te = this.elements;
  2521. var me = matrix.elements;
  2522. for ( var i = 0; i < 16; i ++ ) {
  2523. if ( te[ i ] !== me[ i ] ) return false;
  2524. }
  2525. return true;
  2526. },
  2527. fromArray: function ( array, offset ) {
  2528. if ( offset === undefined ) offset = 0;
  2529. for ( var i = 0; i < 16; i ++ ) {
  2530. this.elements[ i ] = array[ i + offset ];
  2531. }
  2532. return this;
  2533. },
  2534. toArray: function ( array, offset ) {
  2535. if ( array === undefined ) array = [];
  2536. if ( offset === undefined ) offset = 0;
  2537. var te = this.elements;
  2538. array[ offset ] = te[ 0 ];
  2539. array[ offset + 1 ] = te[ 1 ];
  2540. array[ offset + 2 ] = te[ 2 ];
  2541. array[ offset + 3 ] = te[ 3 ];
  2542. array[ offset + 4 ] = te[ 4 ];
  2543. array[ offset + 5 ] = te[ 5 ];
  2544. array[ offset + 6 ] = te[ 6 ];
  2545. array[ offset + 7 ] = te[ 7 ];
  2546. array[ offset + 8 ] = te[ 8 ];
  2547. array[ offset + 9 ] = te[ 9 ];
  2548. array[ offset + 10 ] = te[ 10 ];
  2549. array[ offset + 11 ] = te[ 11 ];
  2550. array[ offset + 12 ] = te[ 12 ];
  2551. array[ offset + 13 ] = te[ 13 ];
  2552. array[ offset + 14 ] = te[ 14 ];
  2553. array[ offset + 15 ] = te[ 15 ];
  2554. return array;
  2555. }
  2556. } );
  2557. /**
  2558. * @author alteredq / http://alteredqualia.com/
  2559. */
  2560. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2561. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2562. this.image = { data: data, width: width, height: height };
  2563. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2564. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2565. this.generateMipmaps = false;
  2566. this.flipY = false;
  2567. this.unpackAlignment = 1;
  2568. }
  2569. DataTexture.prototype = Object.create( Texture.prototype );
  2570. DataTexture.prototype.constructor = DataTexture;
  2571. DataTexture.prototype.isDataTexture = true;
  2572. /**
  2573. * @author mrdoob / http://mrdoob.com/
  2574. */
  2575. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2576. images = images !== undefined ? images : [];
  2577. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  2578. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2579. this.flipY = false;
  2580. }
  2581. CubeTexture.prototype = Object.create( Texture.prototype );
  2582. CubeTexture.prototype.constructor = CubeTexture;
  2583. CubeTexture.prototype.isCubeTexture = true;
  2584. Object.defineProperty( CubeTexture.prototype, 'images', {
  2585. get: function () {
  2586. return this.image;
  2587. },
  2588. set: function ( value ) {
  2589. this.image = value;
  2590. }
  2591. } );
  2592. /**
  2593. * @author tschw
  2594. *
  2595. * Uniforms of a program.
  2596. * Those form a tree structure with a special top-level container for the root,
  2597. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  2598. *
  2599. *
  2600. * Properties of inner nodes including the top-level container:
  2601. *
  2602. * .seq - array of nested uniforms
  2603. * .map - nested uniforms by name
  2604. *
  2605. *
  2606. * Methods of all nodes except the top-level container:
  2607. *
  2608. * .setValue( gl, value, [renderer] )
  2609. *
  2610. * uploads a uniform value(s)
  2611. * the 'renderer' parameter is needed for sampler uniforms
  2612. *
  2613. *
  2614. * Static methods of the top-level container (renderer factorizations):
  2615. *
  2616. * .upload( gl, seq, values, renderer )
  2617. *
  2618. * sets uniforms in 'seq' to 'values[id].value'
  2619. *
  2620. * .seqWithValue( seq, values ) : filteredSeq
  2621. *
  2622. * filters 'seq' entries with corresponding entry in values
  2623. *
  2624. *
  2625. * Methods of the top-level container (renderer factorizations):
  2626. *
  2627. * .setValue( gl, name, value )
  2628. *
  2629. * sets uniform with name 'name' to 'value'
  2630. *
  2631. * .set( gl, obj, prop )
  2632. *
  2633. * sets uniform from object and property with same name than uniform
  2634. *
  2635. * .setOptional( gl, obj, prop )
  2636. *
  2637. * like .set for an optional property of the object
  2638. *
  2639. */
  2640. var emptyTexture = new Texture();
  2641. var emptyCubeTexture = new CubeTexture();
  2642. // --- Base for inner nodes (including the root) ---
  2643. function UniformContainer() {
  2644. this.seq = [];
  2645. this.map = {};
  2646. }
  2647. // --- Utilities ---
  2648. // Array Caches (provide typed arrays for temporary by size)
  2649. var arrayCacheF32 = [];
  2650. var arrayCacheI32 = [];
  2651. // Float32Array caches used for uploading Matrix uniforms
  2652. var mat4array = new Float32Array( 16 );
  2653. var mat3array = new Float32Array( 9 );
  2654. // Flattening for arrays of vectors and matrices
  2655. function flatten( array, nBlocks, blockSize ) {
  2656. var firstElem = array[ 0 ];
  2657. if ( firstElem <= 0 || firstElem > 0 ) return array;
  2658. // unoptimized: ! isNaN( firstElem )
  2659. // see http://jacksondunstan.com/articles/983
  2660. var n = nBlocks * blockSize,
  2661. r = arrayCacheF32[ n ];
  2662. if ( r === undefined ) {
  2663. r = new Float32Array( n );
  2664. arrayCacheF32[ n ] = r;
  2665. }
  2666. if ( nBlocks !== 0 ) {
  2667. firstElem.toArray( r, 0 );
  2668. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  2669. offset += blockSize;
  2670. array[ i ].toArray( r, offset );
  2671. }
  2672. }
  2673. return r;
  2674. }
  2675. // Texture unit allocation
  2676. function allocTexUnits( renderer, n ) {
  2677. var r = arrayCacheI32[ n ];
  2678. if ( r === undefined ) {
  2679. r = new Int32Array( n );
  2680. arrayCacheI32[ n ] = r;
  2681. }
  2682. for ( var i = 0; i !== n; ++ i )
  2683. r[ i ] = renderer.allocTextureUnit();
  2684. return r;
  2685. }
  2686. // --- Setters ---
  2687. // Note: Defining these methods externally, because they come in a bunch
  2688. // and this way their names minify.
  2689. // Single scalar
  2690. function setValue1f( gl, v ) { gl.uniform1f( this.addr, v ); }
  2691. function setValue1i( gl, v ) { gl.uniform1i( this.addr, v ); }
  2692. // Single float vector (from flat array or THREE.VectorN)
  2693. function setValue2fv( gl, v ) {
  2694. if ( v.x === undefined ) gl.uniform2fv( this.addr, v );
  2695. else gl.uniform2f( this.addr, v.x, v.y );
  2696. }
  2697. function setValue3fv( gl, v ) {
  2698. if ( v.x !== undefined )
  2699. gl.uniform3f( this.addr, v.x, v.y, v.z );
  2700. else if ( v.r !== undefined )
  2701. gl.uniform3f( this.addr, v.r, v.g, v.b );
  2702. else
  2703. gl.uniform3fv( this.addr, v );
  2704. }
  2705. function setValue4fv( gl, v ) {
  2706. if ( v.x === undefined ) gl.uniform4fv( this.addr, v );
  2707. else gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  2708. }
  2709. // Single matrix (from flat array or MatrixN)
  2710. function setValue2fm( gl, v ) {
  2711. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  2712. }
  2713. function setValue3fm( gl, v ) {
  2714. if ( v.elements === undefined ) {
  2715. gl.uniformMatrix3fv( this.addr, false, v );
  2716. } else {
  2717. mat3array.set( v.elements );
  2718. gl.uniformMatrix3fv( this.addr, false, mat3array );
  2719. }
  2720. }
  2721. function setValue4fm( gl, v ) {
  2722. if ( v.elements === undefined ) {
  2723. gl.uniformMatrix4fv( this.addr, false, v );
  2724. } else {
  2725. mat4array.set( v.elements );
  2726. gl.uniformMatrix4fv( this.addr, false, mat4array );
  2727. }
  2728. }
  2729. // Single texture (2D / Cube)
  2730. function setValueT1( gl, v, renderer ) {
  2731. var unit = renderer.allocTextureUnit();
  2732. gl.uniform1i( this.addr, unit );
  2733. renderer.setTexture2D( v || emptyTexture, unit );
  2734. }
  2735. function setValueT6( gl, v, renderer ) {
  2736. var unit = renderer.allocTextureUnit();
  2737. gl.uniform1i( this.addr, unit );
  2738. renderer.setTextureCube( v || emptyCubeTexture, unit );
  2739. }
  2740. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  2741. function setValue2iv( gl, v ) { gl.uniform2iv( this.addr, v ); }
  2742. function setValue3iv( gl, v ) { gl.uniform3iv( this.addr, v ); }
  2743. function setValue4iv( gl, v ) { gl.uniform4iv( this.addr, v ); }
  2744. // Helper to pick the right setter for the singular case
  2745. function getSingularSetter( type ) {
  2746. switch ( type ) {
  2747. case 0x1406: return setValue1f; // FLOAT
  2748. case 0x8b50: return setValue2fv; // _VEC2
  2749. case 0x8b51: return setValue3fv; // _VEC3
  2750. case 0x8b52: return setValue4fv; // _VEC4
  2751. case 0x8b5a: return setValue2fm; // _MAT2
  2752. case 0x8b5b: return setValue3fm; // _MAT3
  2753. case 0x8b5c: return setValue4fm; // _MAT4
  2754. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  2755. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  2756. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  2757. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  2758. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  2759. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  2760. }
  2761. }
  2762. // Array of scalars
  2763. function setValue1fv( gl, v ) { gl.uniform1fv( this.addr, v ); }
  2764. function setValue1iv( gl, v ) { gl.uniform1iv( this.addr, v ); }
  2765. // Array of vectors (flat or from THREE classes)
  2766. function setValueV2a( gl, v ) {
  2767. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  2768. }
  2769. function setValueV3a( gl, v ) {
  2770. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  2771. }
  2772. function setValueV4a( gl, v ) {
  2773. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  2774. }
  2775. // Array of matrices (flat or from THREE clases)
  2776. function setValueM2a( gl, v ) {
  2777. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  2778. }
  2779. function setValueM3a( gl, v ) {
  2780. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  2781. }
  2782. function setValueM4a( gl, v ) {
  2783. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  2784. }
  2785. // Array of textures (2D / Cube)
  2786. function setValueT1a( gl, v, renderer ) {
  2787. var n = v.length,
  2788. units = allocTexUnits( renderer, n );
  2789. gl.uniform1iv( this.addr, units );
  2790. for ( var i = 0; i !== n; ++ i ) {
  2791. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  2792. }
  2793. }
  2794. function setValueT6a( gl, v, renderer ) {
  2795. var n = v.length,
  2796. units = allocTexUnits( renderer, n );
  2797. gl.uniform1iv( this.addr, units );
  2798. for ( var i = 0; i !== n; ++ i ) {
  2799. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  2800. }
  2801. }
  2802. // Helper to pick the right setter for a pure (bottom-level) array
  2803. function getPureArraySetter( type ) {
  2804. switch ( type ) {
  2805. case 0x1406: return setValue1fv; // FLOAT
  2806. case 0x8b50: return setValueV2a; // _VEC2
  2807. case 0x8b51: return setValueV3a; // _VEC3
  2808. case 0x8b52: return setValueV4a; // _VEC4
  2809. case 0x8b5a: return setValueM2a; // _MAT2
  2810. case 0x8b5b: return setValueM3a; // _MAT3
  2811. case 0x8b5c: return setValueM4a; // _MAT4
  2812. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  2813. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  2814. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  2815. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  2816. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  2817. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  2818. }
  2819. }
  2820. // --- Uniform Classes ---
  2821. function SingleUniform( id, activeInfo, addr ) {
  2822. this.id = id;
  2823. this.addr = addr;
  2824. this.setValue = getSingularSetter( activeInfo.type );
  2825. // this.path = activeInfo.name; // DEBUG
  2826. }
  2827. function PureArrayUniform( id, activeInfo, addr ) {
  2828. this.id = id;
  2829. this.addr = addr;
  2830. this.size = activeInfo.size;
  2831. this.setValue = getPureArraySetter( activeInfo.type );
  2832. // this.path = activeInfo.name; // DEBUG
  2833. }
  2834. function StructuredUniform( id ) {
  2835. this.id = id;
  2836. UniformContainer.call( this ); // mix-in
  2837. }
  2838. StructuredUniform.prototype.setValue = function ( gl, value ) {
  2839. // Note: Don't need an extra 'renderer' parameter, since samplers
  2840. // are not allowed in structured uniforms.
  2841. var seq = this.seq;
  2842. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  2843. var u = seq[ i ];
  2844. u.setValue( gl, value[ u.id ] );
  2845. }
  2846. };
  2847. // --- Top-level ---
  2848. // Parser - builds up the property tree from the path strings
  2849. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  2850. // extracts
  2851. // - the identifier (member name or array index)
  2852. // - followed by an optional right bracket (found when array index)
  2853. // - followed by an optional left bracket or dot (type of subscript)
  2854. //
  2855. // Note: These portions can be read in a non-overlapping fashion and
  2856. // allow straightforward parsing of the hierarchy that WebGL encodes
  2857. // in the uniform names.
  2858. function addUniform( container, uniformObject ) {
  2859. container.seq.push( uniformObject );
  2860. container.map[ uniformObject.id ] = uniformObject;
  2861. }
  2862. function parseUniform( activeInfo, addr, container ) {
  2863. var path = activeInfo.name,
  2864. pathLength = path.length;
  2865. // reset RegExp object, because of the early exit of a previous run
  2866. RePathPart.lastIndex = 0;
  2867. for ( ; ; ) {
  2868. var match = RePathPart.exec( path ),
  2869. matchEnd = RePathPart.lastIndex,
  2870. id = match[ 1 ],
  2871. idIsIndex = match[ 2 ] === ']',
  2872. subscript = match[ 3 ];
  2873. if ( idIsIndex ) id = id | 0; // convert to integer
  2874. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  2875. // bare name or "pure" bottom-level array "[0]" suffix
  2876. addUniform( container, subscript === undefined ?
  2877. new SingleUniform( id, activeInfo, addr ) :
  2878. new PureArrayUniform( id, activeInfo, addr ) );
  2879. break;
  2880. } else {
  2881. // step into inner node / create it in case it doesn't exist
  2882. var map = container.map, next = map[ id ];
  2883. if ( next === undefined ) {
  2884. next = new StructuredUniform( id );
  2885. addUniform( container, next );
  2886. }
  2887. container = next;
  2888. }
  2889. }
  2890. }
  2891. // Root Container
  2892. function WebGLUniforms( gl, program, renderer ) {
  2893. UniformContainer.call( this );
  2894. this.renderer = renderer;
  2895. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  2896. for ( var i = 0; i < n; ++ i ) {
  2897. var info = gl.getActiveUniform( program, i ),
  2898. path = info.name,
  2899. addr = gl.getUniformLocation( program, path );
  2900. parseUniform( info, addr, this );
  2901. }
  2902. }
  2903. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  2904. var u = this.map[ name ];
  2905. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  2906. };
  2907. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  2908. var v = object[ name ];
  2909. if ( v !== undefined ) this.setValue( gl, name, v );
  2910. };
  2911. // Static interface
  2912. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  2913. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  2914. var u = seq[ i ],
  2915. v = values[ u.id ];
  2916. if ( v.needsUpdate !== false ) {
  2917. // note: always updating when .needsUpdate is undefined
  2918. u.setValue( gl, v.value, renderer );
  2919. }
  2920. }
  2921. };
  2922. WebGLUniforms.seqWithValue = function ( seq, values ) {
  2923. var r = [];
  2924. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  2925. var u = seq[ i ];
  2926. if ( u.id in values ) r.push( u );
  2927. }
  2928. return r;
  2929. };
  2930. /**
  2931. * @author mrdoob / http://mrdoob.com/
  2932. */
  2933. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  2934. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  2935. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  2936. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  2937. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  2938. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  2939. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  2940. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  2941. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  2942. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  2943. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  2944. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  2945. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  2946. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  2947. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  2948. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  2949. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  2950. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  2951. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  2952. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  2953. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  2954. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  2955. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  2956. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  2957. function Color( r, g, b ) {
  2958. if ( g === undefined && b === undefined ) {
  2959. // r is THREE.Color, hex or string
  2960. return this.set( r );
  2961. }
  2962. return this.setRGB( r, g, b );
  2963. }
  2964. Object.assign( Color.prototype, {
  2965. isColor: true,
  2966. r: 1, g: 1, b: 1,
  2967. set: function ( value ) {
  2968. if ( value && value.isColor ) {
  2969. this.copy( value );
  2970. } else if ( typeof value === 'number' ) {
  2971. this.setHex( value );
  2972. } else if ( typeof value === 'string' ) {
  2973. this.setStyle( value );
  2974. }
  2975. return this;
  2976. },
  2977. setScalar: function ( scalar ) {
  2978. this.r = scalar;
  2979. this.g = scalar;
  2980. this.b = scalar;
  2981. return this;
  2982. },
  2983. setHex: function ( hex ) {
  2984. hex = Math.floor( hex );
  2985. this.r = ( hex >> 16 & 255 ) / 255;
  2986. this.g = ( hex >> 8 & 255 ) / 255;
  2987. this.b = ( hex & 255 ) / 255;
  2988. return this;
  2989. },
  2990. setRGB: function ( r, g, b ) {
  2991. this.r = r;
  2992. this.g = g;
  2993. this.b = b;
  2994. return this;
  2995. },
  2996. setHSL: function () {
  2997. function hue2rgb( p, q, t ) {
  2998. if ( t < 0 ) t += 1;
  2999. if ( t > 1 ) t -= 1;
  3000. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3001. if ( t < 1 / 2 ) return q;
  3002. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3003. return p;
  3004. }
  3005. return function setHSL( h, s, l ) {
  3006. // h,s,l ranges are in 0.0 - 1.0
  3007. h = _Math.euclideanModulo( h, 1 );
  3008. s = _Math.clamp( s, 0, 1 );
  3009. l = _Math.clamp( l, 0, 1 );
  3010. if ( s === 0 ) {
  3011. this.r = this.g = this.b = l;
  3012. } else {
  3013. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3014. var q = ( 2 * l ) - p;
  3015. this.r = hue2rgb( q, p, h + 1 / 3 );
  3016. this.g = hue2rgb( q, p, h );
  3017. this.b = hue2rgb( q, p, h - 1 / 3 );
  3018. }
  3019. return this;
  3020. };
  3021. }(),
  3022. setStyle: function ( style ) {
  3023. function handleAlpha( string ) {
  3024. if ( string === undefined ) return;
  3025. if ( parseFloat( string ) < 1 ) {
  3026. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3027. }
  3028. }
  3029. var m;
  3030. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3031. // rgb / hsl
  3032. var color;
  3033. var name = m[ 1 ];
  3034. var components = m[ 2 ];
  3035. switch ( name ) {
  3036. case 'rgb':
  3037. case 'rgba':
  3038. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3039. // rgb(255,0,0) rgba(255,0,0,0.5)
  3040. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3041. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3042. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3043. handleAlpha( color[ 5 ] );
  3044. return this;
  3045. }
  3046. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3047. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  3048. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  3049. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  3050. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  3051. handleAlpha( color[ 5 ] );
  3052. return this;
  3053. }
  3054. break;
  3055. case 'hsl':
  3056. case 'hsla':
  3057. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3058. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  3059. var h = parseFloat( color[ 1 ] ) / 360;
  3060. var s = parseInt( color[ 2 ], 10 ) / 100;
  3061. var l = parseInt( color[ 3 ], 10 ) / 100;
  3062. handleAlpha( color[ 5 ] );
  3063. return this.setHSL( h, s, l );
  3064. }
  3065. break;
  3066. }
  3067. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  3068. // hex color
  3069. var hex = m[ 1 ];
  3070. var size = hex.length;
  3071. if ( size === 3 ) {
  3072. // #ff0
  3073. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  3074. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  3075. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  3076. return this;
  3077. } else if ( size === 6 ) {
  3078. // #ff0000
  3079. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  3080. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  3081. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  3082. return this;
  3083. }
  3084. }
  3085. if ( style && style.length > 0 ) {
  3086. // color keywords
  3087. var hex = ColorKeywords[ style ];
  3088. if ( hex !== undefined ) {
  3089. // red
  3090. this.setHex( hex );
  3091. } else {
  3092. // unknown color
  3093. console.warn( 'THREE.Color: Unknown color ' + style );
  3094. }
  3095. }
  3096. return this;
  3097. },
  3098. clone: function () {
  3099. return new this.constructor( this.r, this.g, this.b );
  3100. },
  3101. copy: function ( color ) {
  3102. this.r = color.r;
  3103. this.g = color.g;
  3104. this.b = color.b;
  3105. return this;
  3106. },
  3107. copyGammaToLinear: function ( color, gammaFactor ) {
  3108. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3109. this.r = Math.pow( color.r, gammaFactor );
  3110. this.g = Math.pow( color.g, gammaFactor );
  3111. this.b = Math.pow( color.b, gammaFactor );
  3112. return this;
  3113. },
  3114. copyLinearToGamma: function ( color, gammaFactor ) {
  3115. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3116. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  3117. this.r = Math.pow( color.r, safeInverse );
  3118. this.g = Math.pow( color.g, safeInverse );
  3119. this.b = Math.pow( color.b, safeInverse );
  3120. return this;
  3121. },
  3122. convertGammaToLinear: function () {
  3123. var r = this.r, g = this.g, b = this.b;
  3124. this.r = r * r;
  3125. this.g = g * g;
  3126. this.b = b * b;
  3127. return this;
  3128. },
  3129. convertLinearToGamma: function () {
  3130. this.r = Math.sqrt( this.r );
  3131. this.g = Math.sqrt( this.g );
  3132. this.b = Math.sqrt( this.b );
  3133. return this;
  3134. },
  3135. getHex: function () {
  3136. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  3137. },
  3138. getHexString: function () {
  3139. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  3140. },
  3141. getHSL: function ( optionalTarget ) {
  3142. // h,s,l ranges are in 0.0 - 1.0
  3143. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  3144. var r = this.r, g = this.g, b = this.b;
  3145. var max = Math.max( r, g, b );
  3146. var min = Math.min( r, g, b );
  3147. var hue, saturation;
  3148. var lightness = ( min + max ) / 2.0;
  3149. if ( min === max ) {
  3150. hue = 0;
  3151. saturation = 0;
  3152. } else {
  3153. var delta = max - min;
  3154. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  3155. switch ( max ) {
  3156. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  3157. case g: hue = ( b - r ) / delta + 2; break;
  3158. case b: hue = ( r - g ) / delta + 4; break;
  3159. }
  3160. hue /= 6;
  3161. }
  3162. hsl.h = hue;
  3163. hsl.s = saturation;
  3164. hsl.l = lightness;
  3165. return hsl;
  3166. },
  3167. getStyle: function () {
  3168. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  3169. },
  3170. offsetHSL: function ( h, s, l ) {
  3171. var hsl = this.getHSL();
  3172. hsl.h += h; hsl.s += s; hsl.l += l;
  3173. this.setHSL( hsl.h, hsl.s, hsl.l );
  3174. return this;
  3175. },
  3176. add: function ( color ) {
  3177. this.r += color.r;
  3178. this.g += color.g;
  3179. this.b += color.b;
  3180. return this;
  3181. },
  3182. addColors: function ( color1, color2 ) {
  3183. this.r = color1.r + color2.r;
  3184. this.g = color1.g + color2.g;
  3185. this.b = color1.b + color2.b;
  3186. return this;
  3187. },
  3188. addScalar: function ( s ) {
  3189. this.r += s;
  3190. this.g += s;
  3191. this.b += s;
  3192. return this;
  3193. },
  3194. sub: function( color ) {
  3195. this.r = Math.max( 0, this.r - color.r );
  3196. this.g = Math.max( 0, this.g - color.g );
  3197. this.b = Math.max( 0, this.b - color.b );
  3198. return this;
  3199. },
  3200. multiply: function ( color ) {
  3201. this.r *= color.r;
  3202. this.g *= color.g;
  3203. this.b *= color.b;
  3204. return this;
  3205. },
  3206. multiplyScalar: function ( s ) {
  3207. this.r *= s;
  3208. this.g *= s;
  3209. this.b *= s;
  3210. return this;
  3211. },
  3212. lerp: function ( color, alpha ) {
  3213. this.r += ( color.r - this.r ) * alpha;
  3214. this.g += ( color.g - this.g ) * alpha;
  3215. this.b += ( color.b - this.b ) * alpha;
  3216. return this;
  3217. },
  3218. equals: function ( c ) {
  3219. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  3220. },
  3221. fromArray: function ( array, offset ) {
  3222. if ( offset === undefined ) offset = 0;
  3223. this.r = array[ offset ];
  3224. this.g = array[ offset + 1 ];
  3225. this.b = array[ offset + 2 ];
  3226. return this;
  3227. },
  3228. toArray: function ( array, offset ) {
  3229. if ( array === undefined ) array = [];
  3230. if ( offset === undefined ) offset = 0;
  3231. array[ offset ] = this.r;
  3232. array[ offset + 1 ] = this.g;
  3233. array[ offset + 2 ] = this.b;
  3234. return array;
  3235. },
  3236. toJSON: function () {
  3237. return this.getHex();
  3238. }
  3239. } );
  3240. /**
  3241. * Uniforms library for shared webgl shaders
  3242. */
  3243. var UniformsLib = {
  3244. common: {
  3245. diffuse: { value: new Color( 0xeeeeee ) },
  3246. opacity: { value: 1.0 },
  3247. map: { value: null },
  3248. offsetRepeat: { value: new Vector4( 0, 0, 1, 1 ) },
  3249. specularMap: { value: null },
  3250. alphaMap: { value: null },
  3251. envMap: { value: null },
  3252. flipEnvMap: { value: - 1 },
  3253. reflectivity: { value: 1.0 },
  3254. refractionRatio: { value: 0.98 }
  3255. },
  3256. aomap: {
  3257. aoMap: { value: null },
  3258. aoMapIntensity: { value: 1 }
  3259. },
  3260. lightmap: {
  3261. lightMap: { value: null },
  3262. lightMapIntensity: { value: 1 }
  3263. },
  3264. emissivemap: {
  3265. emissiveMap: { value: null }
  3266. },
  3267. bumpmap: {
  3268. bumpMap: { value: null },
  3269. bumpScale: { value: 1 }
  3270. },
  3271. normalmap: {
  3272. normalMap: { value: null },
  3273. normalScale: { value: new Vector2( 1, 1 ) }
  3274. },
  3275. displacementmap: {
  3276. displacementMap: { value: null },
  3277. displacementScale: { value: 1 },
  3278. displacementBias: { value: 0 }
  3279. },
  3280. roughnessmap: {
  3281. roughnessMap: { value: null }
  3282. },
  3283. metalnessmap: {
  3284. metalnessMap: { value: null }
  3285. },
  3286. gradientmap: {
  3287. gradientMap: { value: null }
  3288. },
  3289. fog: {
  3290. fogDensity: { value: 0.00025 },
  3291. fogNear: { value: 1 },
  3292. fogFar: { value: 2000 },
  3293. fogColor: { value: new Color( 0xffffff ) }
  3294. },
  3295. lights: {
  3296. ambientLightColor: { value: [] },
  3297. directionalLights: { value: [], properties: {
  3298. direction: {},
  3299. color: {},
  3300. shadow: {},
  3301. shadowBias: {},
  3302. shadowRadius: {},
  3303. shadowMapSize: {}
  3304. } },
  3305. directionalShadowMap: { value: [] },
  3306. directionalShadowMatrix: { value: [] },
  3307. spotLights: { value: [], properties: {
  3308. color: {},
  3309. position: {},
  3310. direction: {},
  3311. distance: {},
  3312. coneCos: {},
  3313. penumbraCos: {},
  3314. decay: {},
  3315. shadow: {},
  3316. shadowBias: {},
  3317. shadowRadius: {},
  3318. shadowMapSize: {}
  3319. } },
  3320. spotShadowMap: { value: [] },
  3321. spotShadowMatrix: { value: [] },
  3322. pointLights: { value: [], properties: {
  3323. color: {},
  3324. position: {},
  3325. decay: {},
  3326. distance: {},
  3327. shadow: {},
  3328. shadowBias: {},
  3329. shadowRadius: {},
  3330. shadowMapSize: {}
  3331. } },
  3332. pointShadowMap: { value: [] },
  3333. pointShadowMatrix: { value: [] },
  3334. hemisphereLights: { value: [], properties: {
  3335. direction: {},
  3336. skyColor: {},
  3337. groundColor: {}
  3338. } },
  3339. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  3340. rectAreaLights: { value: [], properties: {
  3341. color: {},
  3342. position: {},
  3343. width: {},
  3344. height: {}
  3345. } }
  3346. },
  3347. points: {
  3348. diffuse: { value: new Color( 0xeeeeee ) },
  3349. opacity: { value: 1.0 },
  3350. size: { value: 1.0 },
  3351. scale: { value: 1.0 },
  3352. map: { value: null },
  3353. offsetRepeat: { value: new Vector4( 0, 0, 1, 1 ) }
  3354. }
  3355. };
  3356. /**
  3357. * Uniform Utilities
  3358. */
  3359. var UniformsUtils = {
  3360. merge: function ( uniforms ) {
  3361. var merged = {};
  3362. for ( var u = 0; u < uniforms.length; u ++ ) {
  3363. var tmp = this.clone( uniforms[ u ] );
  3364. for ( var p in tmp ) {
  3365. merged[ p ] = tmp[ p ];
  3366. }
  3367. }
  3368. return merged;
  3369. },
  3370. clone: function ( uniforms_src ) {
  3371. var uniforms_dst = {};
  3372. for ( var u in uniforms_src ) {
  3373. uniforms_dst[ u ] = {};
  3374. for ( var p in uniforms_src[ u ] ) {
  3375. var parameter_src = uniforms_src[ u ][ p ];
  3376. if ( parameter_src && ( parameter_src.isColor ||
  3377. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  3378. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  3379. parameter_src.isTexture ) ) {
  3380. uniforms_dst[ u ][ p ] = parameter_src.clone();
  3381. } else if ( Array.isArray( parameter_src ) ) {
  3382. uniforms_dst[ u ][ p ] = parameter_src.slice();
  3383. } else {
  3384. uniforms_dst[ u ][ p ] = parameter_src;
  3385. }
  3386. }
  3387. }
  3388. return uniforms_dst;
  3389. }
  3390. };
  3391. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  3392. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif\n";
  3393. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  3394. 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\n";
  3395. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3396. var begin_vertex = "\nvec3 transformed = vec3( position );\n";
  3397. var beginnormal_vertex = "\nvec3 objectNormal = vec3( normal );\n";
  3398. var bsdfs = "float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tif( decayExponent > 0.0 ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tfloat maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\treturn distanceFalloff * maxDistanceCutoffFactor;\n#else\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n#endif\n\t}\n\treturn 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat theta = acos( dot( N, V ) );\n\tvec2 uv = vec2(\n\t\tsqrt( saturate( roughness ) ),\n\t\tsaturate( theta / ( 0.5 * PI ) ) );\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.86267 + (0.49788 + 0.01436 * y ) * y;\n\tfloat b = 3.45068 + (4.18814 + y) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = (x > 0.0) ? v : 0.5 * inversesqrt( 1.0 - x * x ) - 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 * transpose( 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\tvec3 result = vec3( LTC_ClippedSphereFormFactor( vectorFormFactor ) );\n\treturn result;\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\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\tvec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n\treturn specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n";
  3399. 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\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif\n";
  3400. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; ++ i ) {\n\t\tvec4 plane = clippingPlanes[ i ];\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t\t\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; ++ i ) {\n\t\t\tvec4 plane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\tif ( clipped ) discard;\n\t\n\t#endif\n#endif\n";
  3401. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif\n";
  3402. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvarying vec3 vViewPosition;\n#endif\n";
  3403. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n";
  3404. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3405. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif\n";
  3406. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3407. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3408. var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transpose( const in mat3 v ) {\n\tmat3 tmp;\n\ttmp[0] = vec3(v[0].x, v[1].x, v[2].x);\n\ttmp[1] = vec3(v[0].y, v[1].y, v[2].y);\n\ttmp[2] = vec3(v[0].z, v[1].z, v[2].z);\n\treturn tmp;\n}\n";
  3409. 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(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\n";
  3410. var defaultnormal_vertex = "#ifdef FLIP_SIDED\n\tobjectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  3411. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif\n";
  3412. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  3413. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n";
  3414. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif\n";
  3415. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  3416. 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.xyz, vec3( gammaFactor ) ), value.w );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\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.w );\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.w );\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.xyz * value.w * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.x, 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.x, 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 = value.rgb * cLogLuvM;\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 = Xp_Y_XYZp.rgb * cLogLuvInverseM;\n\treturn vec4( max(vRGB, 0.0), 1.0 );\n}\n";
  3417. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\tvec2 sampleUV;\n\t\tsampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n\t\tsampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\n\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\tvec3 reflectView = flipNormal * 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\n";
  3418. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n\tuniform float reflectivity;\n\tuniform float envMapIntensity;\n#endif\n#ifdef USE_ENVMAP\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n\t\tvarying vec3 vWorldPosition;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\tuniform float flipEnvMap;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif\n";
  3419. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif\n";
  3420. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif\n";
  3421. var fog_vertex = "\n#ifdef USE_FOG\nfogDepth = -mvPosition.z;\n#endif";
  3422. var fog_pars_vertex = "#ifdef USE_FOG\n varying float fogDepth;\n#endif\n";
  3423. 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\n";
  3424. 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\n";
  3425. 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\n";
  3426. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  3427. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3428. 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 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\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\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\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\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n#endif\n";
  3429. var lights_pars = "uniform vec3 ambientLightColor;\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};\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 ltcMat;\tuniform sampler2D ltcMag;\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\n#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( queryVec, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\tvec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = saturate( reflectVec.y * 0.5 + 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\n";
  3430. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  3431. 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)\n";
  3432. 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\n";
  3433. 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\tfloat norm = texture2D( ltcMag, uv ).a;\n\t\tvec4 t = texture2D( ltcMat, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( 1, 0, t.y ),\n\t\t\tvec3( 0, t.z, 0 ),\n\t\t\tvec3( t.w, 0, t.x )\n\t\t);\n\t\treflectedLight.directSpecular += lightColor * material.specularColor * norm * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  3434. var lights_template = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 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\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\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\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 ( NUM_HEMI_LIGHTS > 0 )\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\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n\t#endif\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tvec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n\t#ifndef STANDARD\n\t\tvec3 clearCoatRadiance = getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 );\n\t#else\n\t\tvec3 clearCoatRadiance = vec3( 0.0 );\n\t#endif\n\tRE_IndirectSpecular( radiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif\n";
  3435. var logdepthbuf_fragment = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\tgl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  3436. var logdepthbuf_pars_fragment = "#ifdef USE_LOGDEPTHBUF\n\tuniform float logDepthBufFC;\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n#endif\n";
  3437. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n\tuniform float logDepthBufFC;\n#endif";
  3438. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\tgl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t#else\n\t\tgl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n\t#endif\n#endif\n";
  3439. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif\n";
  3440. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n";
  3441. var map_particle_fragment = "#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n";
  3442. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform vec4 offsetRepeat;\n\tuniform sampler2D map;\n#endif\n";
  3443. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif\n";
  3444. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3445. 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\n";
  3446. 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";
  3447. 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\n";
  3448. var normal_flip = "#ifdef DOUBLE_SIDED\n\tfloat flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n#else\n\tfloat flipNormal = 1.0;\n#endif\n";
  3449. var normal_fragment = "#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 ) * flipNormal;\n#endif\n#ifdef USE_NORMALMAP\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  3450. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\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\tvec3 S = normalize( q0 * st1.t - q1 * st0.t );\n\t\tvec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n\t\tvec3 N = normalize( surf_norm );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy = normalScale * mapN.xy;\n\t\tmat3 tsn = mat3( S, T, N );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif\n";
  3451. 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 1.0 - 2.0 * rgb.xyz;\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}\n";
  3452. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  3453. var project_vertex = "#ifdef USE_SKINNING\n\tvec4 mvPosition = modelViewMatrix * skinned;\n#else\n\tvec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n#endif\ngl_Position = projectionMatrix * mvPosition;\n";
  3454. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif\n";
  3455. var dithering_pars_fragment = "#if defined( DITHERING )\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif\n";
  3456. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif\n";
  3457. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3458. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\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\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\treturn (\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\treturn texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn 1.0;\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 ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\tfloat dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\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\n";
  3459. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n#endif\n";
  3460. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif\n";
  3461. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tDirectionalLight directionalLight;\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tSpotLight spotLight;\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tPointLight pointLight;\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#endif\n\treturn shadow;\n}\n";
  3462. 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";
  3463. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif\n";
  3464. 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\tskinned = bindMatrixInverse * skinned;\n#endif\n";
  3465. 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#endif\n";
  3466. 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";
  3467. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3468. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  3469. var tonemapping_pars_fragment = "#define saturate(a) clamp( a, 0.0, 1.0 )\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}\n";
  3470. var uv_pars_fragment = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n#endif";
  3471. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n\tuniform vec4 offsetRepeat;\n#endif\n";
  3472. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  3473. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3474. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3475. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3476. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\t#ifdef USE_SKINNING\n\t\tvec4 worldPosition = modelMatrix * skinned;\n\t#else\n\t\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n\t#endif\n#endif\n";
  3477. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n\tgl_FragColor.a *= opacity;\n}\n";
  3478. var cube_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}\n";
  3479. 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( gl_FragCoord.z ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n\t#endif\n}\n";
  3480. 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#include <begin_vertex>\n\t#include <displacementmap_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}\n";
  3481. var distanceRGBA_frag = "uniform vec3 lightPos;\nvarying vec4 vWorldPosition;\n#include <common>\n#include <packing>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tgl_FragColor = packDepthToRGBA( length( vWorldPosition.xyz - lightPos.xyz ) / 1000.0 );\n}\n";
  3482. var distanceRGBA_vert = "varying vec4 vWorldPosition;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <skinbase_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition;\n}\n";
  3483. var equirect_frag = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldPosition );\n\tvec2 sampleUV;\n\tsampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n}\n";
  3484. var equirect_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}\n";
  3485. 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}\n";
  3486. 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}\n";
  3487. 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 <normal_flip>\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}\n";
  3488. 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}\n";
  3489. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\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>\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#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 <normal_flip>\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}\n";
  3490. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\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>\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}\n";
  3491. 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>\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_flip>\n\t#include <normal_fragment>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_template>\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}\n";
  3492. 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 <displacementmap_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\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3493. 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#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 <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_flip>\n\t#include <normal_fragment>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_template>\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}\n";
  3494. var meshphysical_vert = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <displacementmap_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\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3495. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\t#include <normal_flip>\n\t#include <normal_fragment>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}\n";
  3496. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <displacementmap_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}\n";
  3497. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_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}\n";
  3498. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <shadowmap_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 <project_vertex>\n\t#ifdef USE_SIZEATTENUATION\n\t\tgl_PointSize = size * ( scale / - mvPosition.z );\n\t#else\n\t\tgl_PointSize = size;\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3499. var shadow_frag = "uniform float opacity;\n#include <common>\n#include <packing>\n#include <bsdfs>\n#include <lights_pars>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( 0.0, 0.0, 0.0, opacity * ( 1.0 - getShadowMask() ) );\n}\n";
  3500. var shadow_vert = "#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}\n";
  3501. var ShaderChunk = {
  3502. alphamap_fragment: alphamap_fragment,
  3503. alphamap_pars_fragment: alphamap_pars_fragment,
  3504. alphatest_fragment: alphatest_fragment,
  3505. aomap_fragment: aomap_fragment,
  3506. aomap_pars_fragment: aomap_pars_fragment,
  3507. begin_vertex: begin_vertex,
  3508. beginnormal_vertex: beginnormal_vertex,
  3509. bsdfs: bsdfs,
  3510. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3511. clipping_planes_fragment: clipping_planes_fragment,
  3512. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3513. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3514. clipping_planes_vertex: clipping_planes_vertex,
  3515. color_fragment: color_fragment,
  3516. color_pars_fragment: color_pars_fragment,
  3517. color_pars_vertex: color_pars_vertex,
  3518. color_vertex: color_vertex,
  3519. common: common,
  3520. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3521. defaultnormal_vertex: defaultnormal_vertex,
  3522. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3523. displacementmap_vertex: displacementmap_vertex,
  3524. emissivemap_fragment: emissivemap_fragment,
  3525. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3526. encodings_fragment: encodings_fragment,
  3527. encodings_pars_fragment: encodings_pars_fragment,
  3528. envmap_fragment: envmap_fragment,
  3529. envmap_pars_fragment: envmap_pars_fragment,
  3530. envmap_pars_vertex: envmap_pars_vertex,
  3531. envmap_vertex: envmap_vertex,
  3532. fog_vertex: fog_vertex,
  3533. fog_pars_vertex: fog_pars_vertex,
  3534. fog_fragment: fog_fragment,
  3535. fog_pars_fragment: fog_pars_fragment,
  3536. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3537. lightmap_fragment: lightmap_fragment,
  3538. lightmap_pars_fragment: lightmap_pars_fragment,
  3539. lights_lambert_vertex: lights_lambert_vertex,
  3540. lights_pars: lights_pars,
  3541. lights_phong_fragment: lights_phong_fragment,
  3542. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3543. lights_physical_fragment: lights_physical_fragment,
  3544. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3545. lights_template: lights_template,
  3546. logdepthbuf_fragment: logdepthbuf_fragment,
  3547. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3548. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3549. logdepthbuf_vertex: logdepthbuf_vertex,
  3550. map_fragment: map_fragment,
  3551. map_pars_fragment: map_pars_fragment,
  3552. map_particle_fragment: map_particle_fragment,
  3553. map_particle_pars_fragment: map_particle_pars_fragment,
  3554. metalnessmap_fragment: metalnessmap_fragment,
  3555. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3556. morphnormal_vertex: morphnormal_vertex,
  3557. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3558. morphtarget_vertex: morphtarget_vertex,
  3559. normal_flip: normal_flip,
  3560. normal_fragment: normal_fragment,
  3561. normalmap_pars_fragment: normalmap_pars_fragment,
  3562. packing: packing,
  3563. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3564. project_vertex: project_vertex,
  3565. dithering_fragment: dithering_fragment,
  3566. dithering_pars_fragment: dithering_pars_fragment,
  3567. roughnessmap_fragment: roughnessmap_fragment,
  3568. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3569. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3570. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3571. shadowmap_vertex: shadowmap_vertex,
  3572. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3573. skinbase_vertex: skinbase_vertex,
  3574. skinning_pars_vertex: skinning_pars_vertex,
  3575. skinning_vertex: skinning_vertex,
  3576. skinnormal_vertex: skinnormal_vertex,
  3577. specularmap_fragment: specularmap_fragment,
  3578. specularmap_pars_fragment: specularmap_pars_fragment,
  3579. tonemapping_fragment: tonemapping_fragment,
  3580. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3581. uv_pars_fragment: uv_pars_fragment,
  3582. uv_pars_vertex: uv_pars_vertex,
  3583. uv_vertex: uv_vertex,
  3584. uv2_pars_fragment: uv2_pars_fragment,
  3585. uv2_pars_vertex: uv2_pars_vertex,
  3586. uv2_vertex: uv2_vertex,
  3587. worldpos_vertex: worldpos_vertex,
  3588. cube_frag: cube_frag,
  3589. cube_vert: cube_vert,
  3590. depth_frag: depth_frag,
  3591. depth_vert: depth_vert,
  3592. distanceRGBA_frag: distanceRGBA_frag,
  3593. distanceRGBA_vert: distanceRGBA_vert,
  3594. equirect_frag: equirect_frag,
  3595. equirect_vert: equirect_vert,
  3596. linedashed_frag: linedashed_frag,
  3597. linedashed_vert: linedashed_vert,
  3598. meshbasic_frag: meshbasic_frag,
  3599. meshbasic_vert: meshbasic_vert,
  3600. meshlambert_frag: meshlambert_frag,
  3601. meshlambert_vert: meshlambert_vert,
  3602. meshphong_frag: meshphong_frag,
  3603. meshphong_vert: meshphong_vert,
  3604. meshphysical_frag: meshphysical_frag,
  3605. meshphysical_vert: meshphysical_vert,
  3606. normal_frag: normal_frag,
  3607. normal_vert: normal_vert,
  3608. points_frag: points_frag,
  3609. points_vert: points_vert,
  3610. shadow_frag: shadow_frag,
  3611. shadow_vert: shadow_vert
  3612. };
  3613. /**
  3614. * @author alteredq / http://alteredqualia.com/
  3615. * @author mrdoob / http://mrdoob.com/
  3616. * @author mikael emtinger / http://gomo.se/
  3617. */
  3618. var ShaderLib = {
  3619. basic: {
  3620. uniforms: UniformsUtils.merge( [
  3621. UniformsLib.common,
  3622. UniformsLib.aomap,
  3623. UniformsLib.lightmap,
  3624. UniformsLib.fog
  3625. ] ),
  3626. vertexShader: ShaderChunk.meshbasic_vert,
  3627. fragmentShader: ShaderChunk.meshbasic_frag
  3628. },
  3629. lambert: {
  3630. uniforms: UniformsUtils.merge( [
  3631. UniformsLib.common,
  3632. UniformsLib.aomap,
  3633. UniformsLib.lightmap,
  3634. UniformsLib.emissivemap,
  3635. UniformsLib.fog,
  3636. UniformsLib.lights,
  3637. {
  3638. emissive: { value: new Color( 0x000000 ) }
  3639. }
  3640. ] ),
  3641. vertexShader: ShaderChunk.meshlambert_vert,
  3642. fragmentShader: ShaderChunk.meshlambert_frag
  3643. },
  3644. phong: {
  3645. uniforms: UniformsUtils.merge( [
  3646. UniformsLib.common,
  3647. UniformsLib.aomap,
  3648. UniformsLib.lightmap,
  3649. UniformsLib.emissivemap,
  3650. UniformsLib.bumpmap,
  3651. UniformsLib.normalmap,
  3652. UniformsLib.displacementmap,
  3653. UniformsLib.gradientmap,
  3654. UniformsLib.fog,
  3655. UniformsLib.lights,
  3656. {
  3657. emissive: { value: new Color( 0x000000 ) },
  3658. specular: { value: new Color( 0x111111 ) },
  3659. shininess: { value: 30 }
  3660. }
  3661. ] ),
  3662. vertexShader: ShaderChunk.meshphong_vert,
  3663. fragmentShader: ShaderChunk.meshphong_frag
  3664. },
  3665. standard: {
  3666. uniforms: UniformsUtils.merge( [
  3667. UniformsLib.common,
  3668. UniformsLib.aomap,
  3669. UniformsLib.lightmap,
  3670. UniformsLib.emissivemap,
  3671. UniformsLib.bumpmap,
  3672. UniformsLib.normalmap,
  3673. UniformsLib.displacementmap,
  3674. UniformsLib.roughnessmap,
  3675. UniformsLib.metalnessmap,
  3676. UniformsLib.fog,
  3677. UniformsLib.lights,
  3678. {
  3679. emissive: { value: new Color( 0x000000 ) },
  3680. roughness: { value: 0.5 },
  3681. metalness: { value: 0.5 },
  3682. envMapIntensity: { value: 1 } // temporary
  3683. }
  3684. ] ),
  3685. vertexShader: ShaderChunk.meshphysical_vert,
  3686. fragmentShader: ShaderChunk.meshphysical_frag
  3687. },
  3688. points: {
  3689. uniforms: UniformsUtils.merge( [
  3690. UniformsLib.points,
  3691. UniformsLib.fog
  3692. ] ),
  3693. vertexShader: ShaderChunk.points_vert,
  3694. fragmentShader: ShaderChunk.points_frag
  3695. },
  3696. dashed: {
  3697. uniforms: UniformsUtils.merge( [
  3698. UniformsLib.common,
  3699. UniformsLib.fog,
  3700. {
  3701. scale: { value: 1 },
  3702. dashSize: { value: 1 },
  3703. totalSize: { value: 2 }
  3704. }
  3705. ] ),
  3706. vertexShader: ShaderChunk.linedashed_vert,
  3707. fragmentShader: ShaderChunk.linedashed_frag
  3708. },
  3709. depth: {
  3710. uniforms: UniformsUtils.merge( [
  3711. UniformsLib.common,
  3712. UniformsLib.displacementmap
  3713. ] ),
  3714. vertexShader: ShaderChunk.depth_vert,
  3715. fragmentShader: ShaderChunk.depth_frag
  3716. },
  3717. normal: {
  3718. uniforms: UniformsUtils.merge( [
  3719. UniformsLib.common,
  3720. UniformsLib.bumpmap,
  3721. UniformsLib.normalmap,
  3722. UniformsLib.displacementmap,
  3723. {
  3724. opacity: { value: 1.0 }
  3725. }
  3726. ] ),
  3727. vertexShader: ShaderChunk.normal_vert,
  3728. fragmentShader: ShaderChunk.normal_frag
  3729. },
  3730. /* -------------------------------------------------------------------------
  3731. // Cube map shader
  3732. ------------------------------------------------------------------------- */
  3733. cube: {
  3734. uniforms: {
  3735. tCube: { value: null },
  3736. tFlip: { value: - 1 },
  3737. opacity: { value: 1.0 }
  3738. },
  3739. vertexShader: ShaderChunk.cube_vert,
  3740. fragmentShader: ShaderChunk.cube_frag
  3741. },
  3742. /* -------------------------------------------------------------------------
  3743. // Cube map shader
  3744. ------------------------------------------------------------------------- */
  3745. equirect: {
  3746. uniforms: {
  3747. tEquirect: { value: null },
  3748. tFlip: { value: - 1 }
  3749. },
  3750. vertexShader: ShaderChunk.equirect_vert,
  3751. fragmentShader: ShaderChunk.equirect_frag
  3752. },
  3753. distanceRGBA: {
  3754. uniforms: {
  3755. lightPos: { value: new Vector3() }
  3756. },
  3757. vertexShader: ShaderChunk.distanceRGBA_vert,
  3758. fragmentShader: ShaderChunk.distanceRGBA_frag
  3759. }
  3760. };
  3761. ShaderLib.physical = {
  3762. uniforms: UniformsUtils.merge( [
  3763. ShaderLib.standard.uniforms,
  3764. {
  3765. clearCoat: { value: 0 },
  3766. clearCoatRoughness: { value: 0 }
  3767. }
  3768. ] ),
  3769. vertexShader: ShaderChunk.meshphysical_vert,
  3770. fragmentShader: ShaderChunk.meshphysical_frag
  3771. };
  3772. /**
  3773. * @author bhouston / http://clara.io
  3774. */
  3775. function Box2( min, max ) {
  3776. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  3777. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  3778. }
  3779. Object.assign( Box2.prototype, {
  3780. set: function ( min, max ) {
  3781. this.min.copy( min );
  3782. this.max.copy( max );
  3783. return this;
  3784. },
  3785. setFromPoints: function ( points ) {
  3786. this.makeEmpty();
  3787. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3788. this.expandByPoint( points[ i ] );
  3789. }
  3790. return this;
  3791. },
  3792. setFromCenterAndSize: function () {
  3793. var v1 = new Vector2();
  3794. return function setFromCenterAndSize( center, size ) {
  3795. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  3796. this.min.copy( center ).sub( halfSize );
  3797. this.max.copy( center ).add( halfSize );
  3798. return this;
  3799. };
  3800. }(),
  3801. clone: function () {
  3802. return new this.constructor().copy( this );
  3803. },
  3804. copy: function ( box ) {
  3805. this.min.copy( box.min );
  3806. this.max.copy( box.max );
  3807. return this;
  3808. },
  3809. makeEmpty: function () {
  3810. this.min.x = this.min.y = + Infinity;
  3811. this.max.x = this.max.y = - Infinity;
  3812. return this;
  3813. },
  3814. isEmpty: function () {
  3815. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3816. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  3817. },
  3818. getCenter: function ( optionalTarget ) {
  3819. var result = optionalTarget || new Vector2();
  3820. return this.isEmpty() ? result.set( 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3821. },
  3822. getSize: function ( optionalTarget ) {
  3823. var result = optionalTarget || new Vector2();
  3824. return this.isEmpty() ? result.set( 0, 0 ) : result.subVectors( this.max, this.min );
  3825. },
  3826. expandByPoint: function ( point ) {
  3827. this.min.min( point );
  3828. this.max.max( point );
  3829. return this;
  3830. },
  3831. expandByVector: function ( vector ) {
  3832. this.min.sub( vector );
  3833. this.max.add( vector );
  3834. return this;
  3835. },
  3836. expandByScalar: function ( scalar ) {
  3837. this.min.addScalar( - scalar );
  3838. this.max.addScalar( scalar );
  3839. return this;
  3840. },
  3841. containsPoint: function ( point ) {
  3842. return point.x < this.min.x || point.x > this.max.x ||
  3843. point.y < this.min.y || point.y > this.max.y ? false : true;
  3844. },
  3845. containsBox: function ( box ) {
  3846. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3847. this.min.y <= box.min.y && box.max.y <= this.max.y;
  3848. },
  3849. getParameter: function ( point, optionalTarget ) {
  3850. // This can potentially have a divide by zero if the box
  3851. // has a size dimension of 0.
  3852. var result = optionalTarget || new Vector2();
  3853. return result.set(
  3854. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3855. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  3856. );
  3857. },
  3858. intersectsBox: function ( box ) {
  3859. // using 4 splitting planes to rule out intersections
  3860. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3861. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  3862. },
  3863. clampPoint: function ( point, optionalTarget ) {
  3864. var result = optionalTarget || new Vector2();
  3865. return result.copy( point ).clamp( this.min, this.max );
  3866. },
  3867. distanceToPoint: function () {
  3868. var v1 = new Vector2();
  3869. return function distanceToPoint( point ) {
  3870. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3871. return clampedPoint.sub( point ).length();
  3872. };
  3873. }(),
  3874. intersect: function ( box ) {
  3875. this.min.max( box.min );
  3876. this.max.min( box.max );
  3877. return this;
  3878. },
  3879. union: function ( box ) {
  3880. this.min.min( box.min );
  3881. this.max.max( box.max );
  3882. return this;
  3883. },
  3884. translate: function ( offset ) {
  3885. this.min.add( offset );
  3886. this.max.add( offset );
  3887. return this;
  3888. },
  3889. equals: function ( box ) {
  3890. return box.min.equals( this.min ) && box.max.equals( this.max );
  3891. }
  3892. } );
  3893. /**
  3894. * @author mikael emtinger / http://gomo.se/
  3895. * @author alteredq / http://alteredqualia.com/
  3896. */
  3897. function LensFlarePlugin( renderer, flares ) {
  3898. var gl = renderer.context;
  3899. var state = renderer.state;
  3900. var vertexBuffer, elementBuffer;
  3901. var shader, program, attributes, uniforms;
  3902. var tempTexture, occlusionTexture;
  3903. function init() {
  3904. var vertices = new Float32Array( [
  3905. - 1, - 1, 0, 0,
  3906. 1, - 1, 1, 0,
  3907. 1, 1, 1, 1,
  3908. - 1, 1, 0, 1
  3909. ] );
  3910. var faces = new Uint16Array( [
  3911. 0, 1, 2,
  3912. 0, 2, 3
  3913. ] );
  3914. // buffers
  3915. vertexBuffer = gl.createBuffer();
  3916. elementBuffer = gl.createBuffer();
  3917. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  3918. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  3919. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  3920. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  3921. // textures
  3922. tempTexture = gl.createTexture();
  3923. occlusionTexture = gl.createTexture();
  3924. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  3925. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  3926. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  3927. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  3928. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  3929. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  3930. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  3931. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  3932. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  3933. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  3934. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  3935. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  3936. shader = {
  3937. vertexShader: [
  3938. "uniform lowp int renderType;",
  3939. "uniform vec3 screenPosition;",
  3940. "uniform vec2 scale;",
  3941. "uniform float rotation;",
  3942. "uniform sampler2D occlusionMap;",
  3943. "attribute vec2 position;",
  3944. "attribute vec2 uv;",
  3945. "varying vec2 vUV;",
  3946. "varying float vVisibility;",
  3947. "void main() {",
  3948. "vUV = uv;",
  3949. "vec2 pos = position;",
  3950. "if ( renderType == 2 ) {",
  3951. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  3952. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  3953. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  3954. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  3955. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  3956. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  3957. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  3958. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  3959. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  3960. "vVisibility = visibility.r / 9.0;",
  3961. "vVisibility *= 1.0 - visibility.g / 9.0;",
  3962. "vVisibility *= visibility.b / 9.0;",
  3963. "vVisibility *= 1.0 - visibility.a / 9.0;",
  3964. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  3965. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  3966. "}",
  3967. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  3968. "}"
  3969. ].join( "\n" ),
  3970. fragmentShader: [
  3971. "uniform lowp int renderType;",
  3972. "uniform sampler2D map;",
  3973. "uniform float opacity;",
  3974. "uniform vec3 color;",
  3975. "varying vec2 vUV;",
  3976. "varying float vVisibility;",
  3977. "void main() {",
  3978. // pink square
  3979. "if ( renderType == 0 ) {",
  3980. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  3981. // restore
  3982. "} else if ( renderType == 1 ) {",
  3983. "gl_FragColor = texture2D( map, vUV );",
  3984. // flare
  3985. "} else {",
  3986. "vec4 texture = texture2D( map, vUV );",
  3987. "texture.a *= opacity * vVisibility;",
  3988. "gl_FragColor = texture;",
  3989. "gl_FragColor.rgb *= color;",
  3990. "}",
  3991. "}"
  3992. ].join( "\n" )
  3993. };
  3994. program = createProgram( shader );
  3995. attributes = {
  3996. vertex: gl.getAttribLocation ( program, "position" ),
  3997. uv: gl.getAttribLocation ( program, "uv" )
  3998. };
  3999. uniforms = {
  4000. renderType: gl.getUniformLocation( program, "renderType" ),
  4001. map: gl.getUniformLocation( program, "map" ),
  4002. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  4003. opacity: gl.getUniformLocation( program, "opacity" ),
  4004. color: gl.getUniformLocation( program, "color" ),
  4005. scale: gl.getUniformLocation( program, "scale" ),
  4006. rotation: gl.getUniformLocation( program, "rotation" ),
  4007. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  4008. };
  4009. }
  4010. /*
  4011. * Render lens flares
  4012. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  4013. * reads these back and calculates occlusion.
  4014. */
  4015. this.render = function ( scene, camera, viewport ) {
  4016. if ( flares.length === 0 ) return;
  4017. var tempPosition = new Vector3();
  4018. var invAspect = viewport.w / viewport.z,
  4019. halfViewportWidth = viewport.z * 0.5,
  4020. halfViewportHeight = viewport.w * 0.5;
  4021. var size = 16 / viewport.w,
  4022. scale = new Vector2( size * invAspect, size );
  4023. var screenPosition = new Vector3( 1, 1, 0 ),
  4024. screenPositionPixels = new Vector2( 1, 1 );
  4025. var validArea = new Box2();
  4026. validArea.min.set( viewport.x, viewport.y );
  4027. validArea.max.set( viewport.x + ( viewport.z - 16 ), viewport.y + ( viewport.w - 16 ) );
  4028. if ( program === undefined ) {
  4029. init();
  4030. }
  4031. gl.useProgram( program );
  4032. state.initAttributes();
  4033. state.enableAttribute( attributes.vertex );
  4034. state.enableAttribute( attributes.uv );
  4035. state.disableUnusedAttributes();
  4036. // loop through all lens flares to update their occlusion and positions
  4037. // setup gl and common used attribs/uniforms
  4038. gl.uniform1i( uniforms.occlusionMap, 0 );
  4039. gl.uniform1i( uniforms.map, 1 );
  4040. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4041. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  4042. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  4043. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4044. state.disable( gl.CULL_FACE );
  4045. state.buffers.depth.setMask( false );
  4046. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  4047. size = 16 / viewport.w;
  4048. scale.set( size * invAspect, size );
  4049. // calc object screen position
  4050. var flare = flares[ i ];
  4051. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  4052. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  4053. tempPosition.applyMatrix4( camera.projectionMatrix );
  4054. // setup arrays for gl programs
  4055. screenPosition.copy( tempPosition );
  4056. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  4057. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  4058. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  4059. // screen cull
  4060. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  4061. // save current RGB to temp texture
  4062. state.activeTexture( gl.TEXTURE0 );
  4063. state.bindTexture( gl.TEXTURE_2D, null );
  4064. state.activeTexture( gl.TEXTURE1 );
  4065. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  4066. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  4067. // render pink quad
  4068. gl.uniform1i( uniforms.renderType, 0 );
  4069. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  4070. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  4071. state.disable( gl.BLEND );
  4072. state.enable( gl.DEPTH_TEST );
  4073. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4074. // copy result to occlusionMap
  4075. state.activeTexture( gl.TEXTURE0 );
  4076. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  4077. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  4078. // restore graphics
  4079. gl.uniform1i( uniforms.renderType, 1 );
  4080. state.disable( gl.DEPTH_TEST );
  4081. state.activeTexture( gl.TEXTURE1 );
  4082. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  4083. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4084. // update object positions
  4085. flare.positionScreen.copy( screenPosition );
  4086. if ( flare.customUpdateCallback ) {
  4087. flare.customUpdateCallback( flare );
  4088. } else {
  4089. flare.updateLensFlares();
  4090. }
  4091. // render flares
  4092. gl.uniform1i( uniforms.renderType, 2 );
  4093. state.enable( gl.BLEND );
  4094. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  4095. var sprite = flare.lensFlares[ j ];
  4096. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  4097. screenPosition.x = sprite.x;
  4098. screenPosition.y = sprite.y;
  4099. screenPosition.z = sprite.z;
  4100. size = sprite.size * sprite.scale / viewport.w;
  4101. scale.x = size * invAspect;
  4102. scale.y = size;
  4103. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  4104. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  4105. gl.uniform1f( uniforms.rotation, sprite.rotation );
  4106. gl.uniform1f( uniforms.opacity, sprite.opacity );
  4107. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  4108. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  4109. renderer.setTexture2D( sprite.texture, 1 );
  4110. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4111. }
  4112. }
  4113. }
  4114. }
  4115. // restore gl
  4116. state.enable( gl.CULL_FACE );
  4117. state.enable( gl.DEPTH_TEST );
  4118. state.buffers.depth.setMask( true );
  4119. renderer.resetGLState();
  4120. };
  4121. function createProgram( shader ) {
  4122. var program = gl.createProgram();
  4123. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  4124. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  4125. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  4126. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  4127. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  4128. gl.compileShader( fragmentShader );
  4129. gl.compileShader( vertexShader );
  4130. gl.attachShader( program, fragmentShader );
  4131. gl.attachShader( program, vertexShader );
  4132. gl.linkProgram( program );
  4133. return program;
  4134. }
  4135. }
  4136. /**
  4137. * @author mikael emtinger / http://gomo.se/
  4138. * @author alteredq / http://alteredqualia.com/
  4139. */
  4140. function SpritePlugin( renderer, sprites ) {
  4141. var gl = renderer.context;
  4142. var state = renderer.state;
  4143. var vertexBuffer, elementBuffer;
  4144. var program, attributes, uniforms;
  4145. var texture;
  4146. // decompose matrixWorld
  4147. var spritePosition = new Vector3();
  4148. var spriteRotation = new Quaternion();
  4149. var spriteScale = new Vector3();
  4150. function init() {
  4151. var vertices = new Float32Array( [
  4152. - 0.5, - 0.5, 0, 0,
  4153. 0.5, - 0.5, 1, 0,
  4154. 0.5, 0.5, 1, 1,
  4155. - 0.5, 0.5, 0, 1
  4156. ] );
  4157. var faces = new Uint16Array( [
  4158. 0, 1, 2,
  4159. 0, 2, 3
  4160. ] );
  4161. vertexBuffer = gl.createBuffer();
  4162. elementBuffer = gl.createBuffer();
  4163. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4164. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  4165. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4166. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  4167. program = createProgram();
  4168. attributes = {
  4169. position: gl.getAttribLocation ( program, 'position' ),
  4170. uv: gl.getAttribLocation ( program, 'uv' )
  4171. };
  4172. uniforms = {
  4173. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  4174. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  4175. rotation: gl.getUniformLocation( program, 'rotation' ),
  4176. scale: gl.getUniformLocation( program, 'scale' ),
  4177. color: gl.getUniformLocation( program, 'color' ),
  4178. map: gl.getUniformLocation( program, 'map' ),
  4179. opacity: gl.getUniformLocation( program, 'opacity' ),
  4180. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  4181. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  4182. fogType: gl.getUniformLocation( program, 'fogType' ),
  4183. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  4184. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  4185. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  4186. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  4187. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  4188. };
  4189. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  4190. canvas.width = 8;
  4191. canvas.height = 8;
  4192. var context = canvas.getContext( '2d' );
  4193. context.fillStyle = 'white';
  4194. context.fillRect( 0, 0, 8, 8 );
  4195. texture = new Texture( canvas );
  4196. texture.needsUpdate = true;
  4197. }
  4198. this.render = function ( scene, camera ) {
  4199. if ( sprites.length === 0 ) return;
  4200. // setup gl
  4201. if ( program === undefined ) {
  4202. init();
  4203. }
  4204. gl.useProgram( program );
  4205. state.initAttributes();
  4206. state.enableAttribute( attributes.position );
  4207. state.enableAttribute( attributes.uv );
  4208. state.disableUnusedAttributes();
  4209. state.disable( gl.CULL_FACE );
  4210. state.enable( gl.BLEND );
  4211. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4212. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  4213. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  4214. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4215. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  4216. state.activeTexture( gl.TEXTURE0 );
  4217. gl.uniform1i( uniforms.map, 0 );
  4218. var oldFogType = 0;
  4219. var sceneFogType = 0;
  4220. var fog = scene.fog;
  4221. if ( fog ) {
  4222. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  4223. if ( fog.isFog ) {
  4224. gl.uniform1f( uniforms.fogNear, fog.near );
  4225. gl.uniform1f( uniforms.fogFar, fog.far );
  4226. gl.uniform1i( uniforms.fogType, 1 );
  4227. oldFogType = 1;
  4228. sceneFogType = 1;
  4229. } else if ( fog.isFogExp2 ) {
  4230. gl.uniform1f( uniforms.fogDensity, fog.density );
  4231. gl.uniform1i( uniforms.fogType, 2 );
  4232. oldFogType = 2;
  4233. sceneFogType = 2;
  4234. }
  4235. } else {
  4236. gl.uniform1i( uniforms.fogType, 0 );
  4237. oldFogType = 0;
  4238. sceneFogType = 0;
  4239. }
  4240. // update positions and sort
  4241. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  4242. var sprite = sprites[ i ];
  4243. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  4244. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  4245. }
  4246. sprites.sort( painterSortStable );
  4247. // render all sprites
  4248. var scale = [];
  4249. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  4250. var sprite = sprites[ i ];
  4251. var material = sprite.material;
  4252. if ( material.visible === false ) continue;
  4253. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  4254. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  4255. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  4256. scale[ 0 ] = spriteScale.x;
  4257. scale[ 1 ] = spriteScale.y;
  4258. var fogType = 0;
  4259. if ( scene.fog && material.fog ) {
  4260. fogType = sceneFogType;
  4261. }
  4262. if ( oldFogType !== fogType ) {
  4263. gl.uniform1i( uniforms.fogType, fogType );
  4264. oldFogType = fogType;
  4265. }
  4266. if ( material.map !== null ) {
  4267. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  4268. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  4269. } else {
  4270. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  4271. gl.uniform2f( uniforms.uvScale, 1, 1 );
  4272. }
  4273. gl.uniform1f( uniforms.opacity, material.opacity );
  4274. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  4275. gl.uniform1f( uniforms.rotation, material.rotation );
  4276. gl.uniform2fv( uniforms.scale, scale );
  4277. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  4278. state.buffers.depth.setTest( material.depthTest );
  4279. state.buffers.depth.setMask( material.depthWrite );
  4280. if ( material.map ) {
  4281. renderer.setTexture2D( material.map, 0 );
  4282. } else {
  4283. renderer.setTexture2D( texture, 0 );
  4284. }
  4285. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4286. }
  4287. // restore gl
  4288. state.enable( gl.CULL_FACE );
  4289. renderer.resetGLState();
  4290. };
  4291. function createProgram() {
  4292. var program = gl.createProgram();
  4293. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  4294. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  4295. gl.shaderSource( vertexShader, [
  4296. 'precision ' + renderer.getPrecision() + ' float;',
  4297. 'uniform mat4 modelViewMatrix;',
  4298. 'uniform mat4 projectionMatrix;',
  4299. 'uniform float rotation;',
  4300. 'uniform vec2 scale;',
  4301. 'uniform vec2 uvOffset;',
  4302. 'uniform vec2 uvScale;',
  4303. 'attribute vec2 position;',
  4304. 'attribute vec2 uv;',
  4305. 'varying vec2 vUV;',
  4306. 'void main() {',
  4307. 'vUV = uvOffset + uv * uvScale;',
  4308. 'vec2 alignedPosition = position * scale;',
  4309. 'vec2 rotatedPosition;',
  4310. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  4311. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  4312. 'vec4 finalPosition;',
  4313. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  4314. 'finalPosition.xy += rotatedPosition;',
  4315. 'finalPosition = projectionMatrix * finalPosition;',
  4316. 'gl_Position = finalPosition;',
  4317. '}'
  4318. ].join( '\n' ) );
  4319. gl.shaderSource( fragmentShader, [
  4320. 'precision ' + renderer.getPrecision() + ' float;',
  4321. 'uniform vec3 color;',
  4322. 'uniform sampler2D map;',
  4323. 'uniform float opacity;',
  4324. 'uniform int fogType;',
  4325. 'uniform vec3 fogColor;',
  4326. 'uniform float fogDensity;',
  4327. 'uniform float fogNear;',
  4328. 'uniform float fogFar;',
  4329. 'uniform float alphaTest;',
  4330. 'varying vec2 vUV;',
  4331. 'void main() {',
  4332. 'vec4 texture = texture2D( map, vUV );',
  4333. 'if ( texture.a < alphaTest ) discard;',
  4334. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  4335. 'if ( fogType > 0 ) {',
  4336. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  4337. 'float fogFactor = 0.0;',
  4338. 'if ( fogType == 1 ) {',
  4339. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  4340. '} else {',
  4341. 'const float LOG2 = 1.442695;',
  4342. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  4343. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  4344. '}',
  4345. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  4346. '}',
  4347. '}'
  4348. ].join( '\n' ) );
  4349. gl.compileShader( vertexShader );
  4350. gl.compileShader( fragmentShader );
  4351. gl.attachShader( program, vertexShader );
  4352. gl.attachShader( program, fragmentShader );
  4353. gl.linkProgram( program );
  4354. return program;
  4355. }
  4356. function painterSortStable( a, b ) {
  4357. if ( a.renderOrder !== b.renderOrder ) {
  4358. return a.renderOrder - b.renderOrder;
  4359. } else if ( a.z !== b.z ) {
  4360. return b.z - a.z;
  4361. } else {
  4362. return b.id - a.id;
  4363. }
  4364. }
  4365. }
  4366. /**
  4367. * @author mrdoob / http://mrdoob.com/
  4368. * @author alteredq / http://alteredqualia.com/
  4369. */
  4370. var materialId = 0;
  4371. function Material() {
  4372. Object.defineProperty( this, 'id', { value: materialId ++ } );
  4373. this.uuid = _Math.generateUUID();
  4374. this.name = '';
  4375. this.type = 'Material';
  4376. this.fog = true;
  4377. this.lights = true;
  4378. this.blending = NormalBlending;
  4379. this.side = FrontSide;
  4380. this.shading = SmoothShading; // THREE.FlatShading, THREE.SmoothShading
  4381. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  4382. this.opacity = 1;
  4383. this.transparent = false;
  4384. this.blendSrc = SrcAlphaFactor;
  4385. this.blendDst = OneMinusSrcAlphaFactor;
  4386. this.blendEquation = AddEquation;
  4387. this.blendSrcAlpha = null;
  4388. this.blendDstAlpha = null;
  4389. this.blendEquationAlpha = null;
  4390. this.depthFunc = LessEqualDepth;
  4391. this.depthTest = true;
  4392. this.depthWrite = true;
  4393. this.clippingPlanes = null;
  4394. this.clipIntersection = false;
  4395. this.clipShadows = false;
  4396. this.colorWrite = true;
  4397. this.precision = null; // override the renderer's default precision for this material
  4398. this.polygonOffset = false;
  4399. this.polygonOffsetFactor = 0;
  4400. this.polygonOffsetUnits = 0;
  4401. this.dithering = false;
  4402. this.alphaTest = 0;
  4403. this.premultipliedAlpha = false;
  4404. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  4405. this.visible = true;
  4406. this.needsUpdate = true;
  4407. }
  4408. Object.assign( Material.prototype, EventDispatcher.prototype, {
  4409. isMaterial: true,
  4410. onBeforeCompile: function () {},
  4411. setValues: function ( values ) {
  4412. if ( values === undefined ) return;
  4413. for ( var key in values ) {
  4414. var newValue = values[ key ];
  4415. if ( newValue === undefined ) {
  4416. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  4417. continue;
  4418. }
  4419. var currentValue = this[ key ];
  4420. if ( currentValue === undefined ) {
  4421. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  4422. continue;
  4423. }
  4424. if ( currentValue && currentValue.isColor ) {
  4425. currentValue.set( newValue );
  4426. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  4427. currentValue.copy( newValue );
  4428. } else if ( key === 'overdraw' ) {
  4429. // ensure overdraw is backwards-compatible with legacy boolean type
  4430. this[ key ] = Number( newValue );
  4431. } else {
  4432. this[ key ] = newValue;
  4433. }
  4434. }
  4435. },
  4436. toJSON: function ( meta ) {
  4437. var isRoot = meta === undefined;
  4438. if ( isRoot ) {
  4439. meta = {
  4440. textures: {},
  4441. images: {}
  4442. };
  4443. }
  4444. var data = {
  4445. metadata: {
  4446. version: 4.5,
  4447. type: 'Material',
  4448. generator: 'Material.toJSON'
  4449. }
  4450. };
  4451. // standard Material serialization
  4452. data.uuid = this.uuid;
  4453. data.type = this.type;
  4454. if ( this.name !== '' ) data.name = this.name;
  4455. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  4456. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  4457. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  4458. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  4459. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  4460. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  4461. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  4462. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  4463. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  4464. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  4465. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  4466. if ( this.bumpMap && this.bumpMap.isTexture ) {
  4467. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  4468. data.bumpScale = this.bumpScale;
  4469. }
  4470. if ( this.normalMap && this.normalMap.isTexture ) {
  4471. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  4472. data.normalScale = this.normalScale.toArray();
  4473. }
  4474. if ( this.displacementMap && this.displacementMap.isTexture ) {
  4475. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  4476. data.displacementScale = this.displacementScale;
  4477. data.displacementBias = this.displacementBias;
  4478. }
  4479. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  4480. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  4481. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  4482. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  4483. if ( this.envMap && this.envMap.isTexture ) {
  4484. data.envMap = this.envMap.toJSON( meta ).uuid;
  4485. data.reflectivity = this.reflectivity; // Scale behind envMap
  4486. }
  4487. if ( this.gradientMap && this.gradientMap.isTexture ) {
  4488. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  4489. }
  4490. if ( this.size !== undefined ) data.size = this.size;
  4491. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  4492. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  4493. if ( this.shading !== SmoothShading ) data.shading = this.shading;
  4494. if ( this.side !== FrontSide ) data.side = this.side;
  4495. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  4496. if ( this.opacity < 1 ) data.opacity = this.opacity;
  4497. if ( this.transparent === true ) data.transparent = this.transparent;
  4498. data.depthFunc = this.depthFunc;
  4499. data.depthTest = this.depthTest;
  4500. data.depthWrite = this.depthWrite;
  4501. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  4502. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  4503. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  4504. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  4505. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  4506. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  4507. data.skinning = this.skinning;
  4508. data.morphTargets = this.morphTargets;
  4509. data.dithering = this.dithering;
  4510. // TODO: Copied from Object3D.toJSON
  4511. function extractFromCache( cache ) {
  4512. var values = [];
  4513. for ( var key in cache ) {
  4514. var data = cache[ key ];
  4515. delete data.metadata;
  4516. values.push( data );
  4517. }
  4518. return values;
  4519. }
  4520. if ( isRoot ) {
  4521. var textures = extractFromCache( meta.textures );
  4522. var images = extractFromCache( meta.images );
  4523. if ( textures.length > 0 ) data.textures = textures;
  4524. if ( images.length > 0 ) data.images = images;
  4525. }
  4526. return data;
  4527. },
  4528. clone: function () {
  4529. return new this.constructor().copy( this );
  4530. },
  4531. copy: function ( source ) {
  4532. this.name = source.name;
  4533. this.fog = source.fog;
  4534. this.lights = source.lights;
  4535. this.blending = source.blending;
  4536. this.side = source.side;
  4537. this.shading = source.shading;
  4538. this.vertexColors = source.vertexColors;
  4539. this.opacity = source.opacity;
  4540. this.transparent = source.transparent;
  4541. this.blendSrc = source.blendSrc;
  4542. this.blendDst = source.blendDst;
  4543. this.blendEquation = source.blendEquation;
  4544. this.blendSrcAlpha = source.blendSrcAlpha;
  4545. this.blendDstAlpha = source.blendDstAlpha;
  4546. this.blendEquationAlpha = source.blendEquationAlpha;
  4547. this.depthFunc = source.depthFunc;
  4548. this.depthTest = source.depthTest;
  4549. this.depthWrite = source.depthWrite;
  4550. this.colorWrite = source.colorWrite;
  4551. this.precision = source.precision;
  4552. this.polygonOffset = source.polygonOffset;
  4553. this.polygonOffsetFactor = source.polygonOffsetFactor;
  4554. this.polygonOffsetUnits = source.polygonOffsetUnits;
  4555. this.dithering = source.dithering;
  4556. this.alphaTest = source.alphaTest;
  4557. this.premultipliedAlpha = source.premultipliedAlpha;
  4558. this.overdraw = source.overdraw;
  4559. this.visible = source.visible;
  4560. this.clipShadows = source.clipShadows;
  4561. this.clipIntersection = source.clipIntersection;
  4562. var srcPlanes = source.clippingPlanes,
  4563. dstPlanes = null;
  4564. if ( srcPlanes !== null ) {
  4565. var n = srcPlanes.length;
  4566. dstPlanes = new Array( n );
  4567. for ( var i = 0; i !== n; ++ i )
  4568. dstPlanes[ i ] = srcPlanes[ i ].clone();
  4569. }
  4570. this.clippingPlanes = dstPlanes;
  4571. return this;
  4572. },
  4573. dispose: function () {
  4574. this.dispatchEvent( { type: 'dispose' } );
  4575. }
  4576. } );
  4577. /**
  4578. * @author alteredq / http://alteredqualia.com/
  4579. *
  4580. * parameters = {
  4581. * defines: { "label" : "value" },
  4582. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  4583. *
  4584. * fragmentShader: <string>,
  4585. * vertexShader: <string>,
  4586. *
  4587. * wireframe: <boolean>,
  4588. * wireframeLinewidth: <float>,
  4589. *
  4590. * lights: <bool>,
  4591. *
  4592. * skinning: <bool>,
  4593. * morphTargets: <bool>,
  4594. * morphNormals: <bool>
  4595. * }
  4596. */
  4597. function ShaderMaterial( parameters ) {
  4598. Material.call( this );
  4599. this.type = 'ShaderMaterial';
  4600. this.defines = {};
  4601. this.uniforms = {};
  4602. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  4603. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  4604. this.linewidth = 1;
  4605. this.wireframe = false;
  4606. this.wireframeLinewidth = 1;
  4607. this.fog = false; // set to use scene fog
  4608. this.lights = false; // set to use scene lights
  4609. this.clipping = false; // set to use user-defined clipping planes
  4610. this.skinning = false; // set to use skinning attribute streams
  4611. this.morphTargets = false; // set to use morph targets
  4612. this.morphNormals = false; // set to use morph normals
  4613. this.extensions = {
  4614. derivatives: false, // set to use derivatives
  4615. fragDepth: false, // set to use fragment depth values
  4616. drawBuffers: false, // set to use draw buffers
  4617. shaderTextureLOD: false // set to use shader texture LOD
  4618. };
  4619. // When rendered geometry doesn't include these attributes but the material does,
  4620. // use these default values in WebGL. This avoids errors when buffer data is missing.
  4621. this.defaultAttributeValues = {
  4622. 'color': [ 1, 1, 1 ],
  4623. 'uv': [ 0, 0 ],
  4624. 'uv2': [ 0, 0 ]
  4625. };
  4626. this.index0AttributeName = undefined;
  4627. if ( parameters !== undefined ) {
  4628. if ( parameters.attributes !== undefined ) {
  4629. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  4630. }
  4631. this.setValues( parameters );
  4632. }
  4633. }
  4634. ShaderMaterial.prototype = Object.create( Material.prototype );
  4635. ShaderMaterial.prototype.constructor = ShaderMaterial;
  4636. ShaderMaterial.prototype.isShaderMaterial = true;
  4637. ShaderMaterial.prototype.copy = function ( source ) {
  4638. Material.prototype.copy.call( this, source );
  4639. this.fragmentShader = source.fragmentShader;
  4640. this.vertexShader = source.vertexShader;
  4641. this.uniforms = UniformsUtils.clone( source.uniforms );
  4642. this.defines = source.defines;
  4643. this.wireframe = source.wireframe;
  4644. this.wireframeLinewidth = source.wireframeLinewidth;
  4645. this.lights = source.lights;
  4646. this.clipping = source.clipping;
  4647. this.skinning = source.skinning;
  4648. this.morphTargets = source.morphTargets;
  4649. this.morphNormals = source.morphNormals;
  4650. this.extensions = source.extensions;
  4651. return this;
  4652. };
  4653. ShaderMaterial.prototype.toJSON = function ( meta ) {
  4654. var data = Material.prototype.toJSON.call( this, meta );
  4655. data.uniforms = this.uniforms;
  4656. data.vertexShader = this.vertexShader;
  4657. data.fragmentShader = this.fragmentShader;
  4658. return data;
  4659. };
  4660. /**
  4661. * @author mrdoob / http://mrdoob.com/
  4662. * @author alteredq / http://alteredqualia.com/
  4663. * @author bhouston / https://clara.io
  4664. * @author WestLangley / http://github.com/WestLangley
  4665. *
  4666. * parameters = {
  4667. *
  4668. * opacity: <float>,
  4669. *
  4670. * map: new THREE.Texture( <Image> ),
  4671. *
  4672. * alphaMap: new THREE.Texture( <Image> ),
  4673. *
  4674. * displacementMap: new THREE.Texture( <Image> ),
  4675. * displacementScale: <float>,
  4676. * displacementBias: <float>,
  4677. *
  4678. * wireframe: <boolean>,
  4679. * wireframeLinewidth: <float>
  4680. * }
  4681. */
  4682. function MeshDepthMaterial( parameters ) {
  4683. Material.call( this );
  4684. this.type = 'MeshDepthMaterial';
  4685. this.depthPacking = BasicDepthPacking;
  4686. this.skinning = false;
  4687. this.morphTargets = false;
  4688. this.map = null;
  4689. this.alphaMap = null;
  4690. this.displacementMap = null;
  4691. this.displacementScale = 1;
  4692. this.displacementBias = 0;
  4693. this.wireframe = false;
  4694. this.wireframeLinewidth = 1;
  4695. this.fog = false;
  4696. this.lights = false;
  4697. this.setValues( parameters );
  4698. }
  4699. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  4700. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  4701. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  4702. MeshDepthMaterial.prototype.copy = function ( source ) {
  4703. Material.prototype.copy.call( this, source );
  4704. this.depthPacking = source.depthPacking;
  4705. this.skinning = source.skinning;
  4706. this.morphTargets = source.morphTargets;
  4707. this.map = source.map;
  4708. this.alphaMap = source.alphaMap;
  4709. this.displacementMap = source.displacementMap;
  4710. this.displacementScale = source.displacementScale;
  4711. this.displacementBias = source.displacementBias;
  4712. this.wireframe = source.wireframe;
  4713. this.wireframeLinewidth = source.wireframeLinewidth;
  4714. return this;
  4715. };
  4716. /**
  4717. * @author bhouston / http://clara.io
  4718. * @author WestLangley / http://github.com/WestLangley
  4719. */
  4720. function Box3( min, max ) {
  4721. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  4722. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  4723. }
  4724. Object.assign( Box3.prototype, {
  4725. isBox3: true,
  4726. set: function ( min, max ) {
  4727. this.min.copy( min );
  4728. this.max.copy( max );
  4729. return this;
  4730. },
  4731. setFromArray: function ( array ) {
  4732. var minX = + Infinity;
  4733. var minY = + Infinity;
  4734. var minZ = + Infinity;
  4735. var maxX = - Infinity;
  4736. var maxY = - Infinity;
  4737. var maxZ = - Infinity;
  4738. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  4739. var x = array[ i ];
  4740. var y = array[ i + 1 ];
  4741. var z = array[ i + 2 ];
  4742. if ( x < minX ) minX = x;
  4743. if ( y < minY ) minY = y;
  4744. if ( z < minZ ) minZ = z;
  4745. if ( x > maxX ) maxX = x;
  4746. if ( y > maxY ) maxY = y;
  4747. if ( z > maxZ ) maxZ = z;
  4748. }
  4749. this.min.set( minX, minY, minZ );
  4750. this.max.set( maxX, maxY, maxZ );
  4751. return this;
  4752. },
  4753. setFromBufferAttribute: function ( attribute ) {
  4754. var minX = + Infinity;
  4755. var minY = + Infinity;
  4756. var minZ = + Infinity;
  4757. var maxX = - Infinity;
  4758. var maxY = - Infinity;
  4759. var maxZ = - Infinity;
  4760. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  4761. var x = attribute.getX( i );
  4762. var y = attribute.getY( i );
  4763. var z = attribute.getZ( i );
  4764. if ( x < minX ) minX = x;
  4765. if ( y < minY ) minY = y;
  4766. if ( z < minZ ) minZ = z;
  4767. if ( x > maxX ) maxX = x;
  4768. if ( y > maxY ) maxY = y;
  4769. if ( z > maxZ ) maxZ = z;
  4770. }
  4771. this.min.set( minX, minY, minZ );
  4772. this.max.set( maxX, maxY, maxZ );
  4773. return this;
  4774. },
  4775. setFromPoints: function ( points ) {
  4776. this.makeEmpty();
  4777. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4778. this.expandByPoint( points[ i ] );
  4779. }
  4780. return this;
  4781. },
  4782. setFromCenterAndSize: function () {
  4783. var v1 = new Vector3();
  4784. return function setFromCenterAndSize( center, size ) {
  4785. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  4786. this.min.copy( center ).sub( halfSize );
  4787. this.max.copy( center ).add( halfSize );
  4788. return this;
  4789. };
  4790. }(),
  4791. setFromObject: function ( object ) {
  4792. this.makeEmpty();
  4793. return this.expandByObject( object );
  4794. },
  4795. clone: function () {
  4796. return new this.constructor().copy( this );
  4797. },
  4798. copy: function ( box ) {
  4799. this.min.copy( box.min );
  4800. this.max.copy( box.max );
  4801. return this;
  4802. },
  4803. makeEmpty: function () {
  4804. this.min.x = this.min.y = this.min.z = + Infinity;
  4805. this.max.x = this.max.y = this.max.z = - Infinity;
  4806. return this;
  4807. },
  4808. isEmpty: function () {
  4809. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  4810. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  4811. },
  4812. getCenter: function ( optionalTarget ) {
  4813. var result = optionalTarget || new Vector3();
  4814. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  4815. },
  4816. getSize: function ( optionalTarget ) {
  4817. var result = optionalTarget || new Vector3();
  4818. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.subVectors( this.max, this.min );
  4819. },
  4820. expandByPoint: function ( point ) {
  4821. this.min.min( point );
  4822. this.max.max( point );
  4823. return this;
  4824. },
  4825. expandByVector: function ( vector ) {
  4826. this.min.sub( vector );
  4827. this.max.add( vector );
  4828. return this;
  4829. },
  4830. expandByScalar: function ( scalar ) {
  4831. this.min.addScalar( - scalar );
  4832. this.max.addScalar( scalar );
  4833. return this;
  4834. },
  4835. expandByObject: function () {
  4836. // Computes the world-axis-aligned bounding box of an object (including its children),
  4837. // accounting for both the object's, and children's, world transforms
  4838. var v1 = new Vector3();
  4839. return function expandByObject( object ) {
  4840. var scope = this;
  4841. object.updateMatrixWorld( true );
  4842. object.traverse( function ( node ) {
  4843. var i, l;
  4844. var geometry = node.geometry;
  4845. if ( geometry !== undefined ) {
  4846. if ( geometry.isGeometry ) {
  4847. var vertices = geometry.vertices;
  4848. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  4849. v1.copy( vertices[ i ] );
  4850. v1.applyMatrix4( node.matrixWorld );
  4851. scope.expandByPoint( v1 );
  4852. }
  4853. } else if ( geometry.isBufferGeometry ) {
  4854. var attribute = geometry.attributes.position;
  4855. if ( attribute !== undefined ) {
  4856. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  4857. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  4858. scope.expandByPoint( v1 );
  4859. }
  4860. }
  4861. }
  4862. }
  4863. } );
  4864. return this;
  4865. };
  4866. }(),
  4867. containsPoint: function ( point ) {
  4868. return point.x < this.min.x || point.x > this.max.x ||
  4869. point.y < this.min.y || point.y > this.max.y ||
  4870. point.z < this.min.z || point.z > this.max.z ? false : true;
  4871. },
  4872. containsBox: function ( box ) {
  4873. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  4874. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  4875. this.min.z <= box.min.z && box.max.z <= this.max.z;
  4876. },
  4877. getParameter: function ( point, optionalTarget ) {
  4878. // This can potentially have a divide by zero if the box
  4879. // has a size dimension of 0.
  4880. var result = optionalTarget || new Vector3();
  4881. return result.set(
  4882. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  4883. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  4884. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  4885. );
  4886. },
  4887. intersectsBox: function ( box ) {
  4888. // using 6 splitting planes to rule out intersections.
  4889. return box.max.x < this.min.x || box.min.x > this.max.x ||
  4890. box.max.y < this.min.y || box.min.y > this.max.y ||
  4891. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  4892. },
  4893. intersectsSphere: ( function () {
  4894. var closestPoint = new Vector3();
  4895. return function intersectsSphere( sphere ) {
  4896. // Find the point on the AABB closest to the sphere center.
  4897. this.clampPoint( sphere.center, closestPoint );
  4898. // If that point is inside the sphere, the AABB and sphere intersect.
  4899. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  4900. };
  4901. } )(),
  4902. intersectsPlane: function ( plane ) {
  4903. // We compute the minimum and maximum dot product values. If those values
  4904. // are on the same side (back or front) of the plane, then there is no intersection.
  4905. var min, max;
  4906. if ( plane.normal.x > 0 ) {
  4907. min = plane.normal.x * this.min.x;
  4908. max = plane.normal.x * this.max.x;
  4909. } else {
  4910. min = plane.normal.x * this.max.x;
  4911. max = plane.normal.x * this.min.x;
  4912. }
  4913. if ( plane.normal.y > 0 ) {
  4914. min += plane.normal.y * this.min.y;
  4915. max += plane.normal.y * this.max.y;
  4916. } else {
  4917. min += plane.normal.y * this.max.y;
  4918. max += plane.normal.y * this.min.y;
  4919. }
  4920. if ( plane.normal.z > 0 ) {
  4921. min += plane.normal.z * this.min.z;
  4922. max += plane.normal.z * this.max.z;
  4923. } else {
  4924. min += plane.normal.z * this.max.z;
  4925. max += plane.normal.z * this.min.z;
  4926. }
  4927. return ( min <= plane.constant && max >= plane.constant );
  4928. },
  4929. clampPoint: function ( point, optionalTarget ) {
  4930. var result = optionalTarget || new Vector3();
  4931. return result.copy( point ).clamp( this.min, this.max );
  4932. },
  4933. distanceToPoint: function () {
  4934. var v1 = new Vector3();
  4935. return function distanceToPoint( point ) {
  4936. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  4937. return clampedPoint.sub( point ).length();
  4938. };
  4939. }(),
  4940. getBoundingSphere: function () {
  4941. var v1 = new Vector3();
  4942. return function getBoundingSphere( optionalTarget ) {
  4943. var result = optionalTarget || new Sphere();
  4944. this.getCenter( result.center );
  4945. result.radius = this.getSize( v1 ).length() * 0.5;
  4946. return result;
  4947. };
  4948. }(),
  4949. intersect: function ( box ) {
  4950. this.min.max( box.min );
  4951. this.max.min( box.max );
  4952. // 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.
  4953. if( this.isEmpty() ) this.makeEmpty();
  4954. return this;
  4955. },
  4956. union: function ( box ) {
  4957. this.min.min( box.min );
  4958. this.max.max( box.max );
  4959. return this;
  4960. },
  4961. applyMatrix4: function () {
  4962. var points = [
  4963. new Vector3(),
  4964. new Vector3(),
  4965. new Vector3(),
  4966. new Vector3(),
  4967. new Vector3(),
  4968. new Vector3(),
  4969. new Vector3(),
  4970. new Vector3()
  4971. ];
  4972. return function applyMatrix4( matrix ) {
  4973. // transform of empty box is an empty box.
  4974. if( this.isEmpty() ) return this;
  4975. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4976. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4977. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4978. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4979. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4980. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4981. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4982. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4983. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4984. this.setFromPoints( points );
  4985. return this;
  4986. };
  4987. }(),
  4988. translate: function ( offset ) {
  4989. this.min.add( offset );
  4990. this.max.add( offset );
  4991. return this;
  4992. },
  4993. equals: function ( box ) {
  4994. return box.min.equals( this.min ) && box.max.equals( this.max );
  4995. }
  4996. } );
  4997. /**
  4998. * @author bhouston / http://clara.io
  4999. * @author mrdoob / http://mrdoob.com/
  5000. */
  5001. function Sphere( center, radius ) {
  5002. this.center = ( center !== undefined ) ? center : new Vector3();
  5003. this.radius = ( radius !== undefined ) ? radius : 0;
  5004. }
  5005. Object.assign( Sphere.prototype, {
  5006. set: function ( center, radius ) {
  5007. this.center.copy( center );
  5008. this.radius = radius;
  5009. return this;
  5010. },
  5011. setFromPoints: function () {
  5012. var box = new Box3();
  5013. return function setFromPoints( points, optionalCenter ) {
  5014. var center = this.center;
  5015. if ( optionalCenter !== undefined ) {
  5016. center.copy( optionalCenter );
  5017. } else {
  5018. box.setFromPoints( points ).getCenter( center );
  5019. }
  5020. var maxRadiusSq = 0;
  5021. for ( var i = 0, il = points.length; i < il; i ++ ) {
  5022. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  5023. }
  5024. this.radius = Math.sqrt( maxRadiusSq );
  5025. return this;
  5026. };
  5027. }(),
  5028. clone: function () {
  5029. return new this.constructor().copy( this );
  5030. },
  5031. copy: function ( sphere ) {
  5032. this.center.copy( sphere.center );
  5033. this.radius = sphere.radius;
  5034. return this;
  5035. },
  5036. empty: function () {
  5037. return ( this.radius <= 0 );
  5038. },
  5039. containsPoint: function ( point ) {
  5040. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  5041. },
  5042. distanceToPoint: function ( point ) {
  5043. return ( point.distanceTo( this.center ) - this.radius );
  5044. },
  5045. intersectsSphere: function ( sphere ) {
  5046. var radiusSum = this.radius + sphere.radius;
  5047. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  5048. },
  5049. intersectsBox: function ( box ) {
  5050. return box.intersectsSphere( this );
  5051. },
  5052. intersectsPlane: function ( plane ) {
  5053. // We use the following equation to compute the signed distance from
  5054. // the center of the sphere to the plane.
  5055. //
  5056. // distance = q * n - d
  5057. //
  5058. // If this distance is greater than the radius of the sphere,
  5059. // then there is no intersection.
  5060. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  5061. },
  5062. clampPoint: function ( point, optionalTarget ) {
  5063. var deltaLengthSq = this.center.distanceToSquared( point );
  5064. var result = optionalTarget || new Vector3();
  5065. result.copy( point );
  5066. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  5067. result.sub( this.center ).normalize();
  5068. result.multiplyScalar( this.radius ).add( this.center );
  5069. }
  5070. return result;
  5071. },
  5072. getBoundingBox: function ( optionalTarget ) {
  5073. var box = optionalTarget || new Box3();
  5074. box.set( this.center, this.center );
  5075. box.expandByScalar( this.radius );
  5076. return box;
  5077. },
  5078. applyMatrix4: function ( matrix ) {
  5079. this.center.applyMatrix4( matrix );
  5080. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  5081. return this;
  5082. },
  5083. translate: function ( offset ) {
  5084. this.center.add( offset );
  5085. return this;
  5086. },
  5087. equals: function ( sphere ) {
  5088. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  5089. }
  5090. } );
  5091. /**
  5092. * @author alteredq / http://alteredqualia.com/
  5093. * @author WestLangley / http://github.com/WestLangley
  5094. * @author bhouston / http://clara.io
  5095. * @author tschw
  5096. */
  5097. function Matrix3() {
  5098. this.elements = [
  5099. 1, 0, 0,
  5100. 0, 1, 0,
  5101. 0, 0, 1
  5102. ];
  5103. if ( arguments.length > 0 ) {
  5104. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  5105. }
  5106. }
  5107. Object.assign( Matrix3.prototype, {
  5108. isMatrix3: true,
  5109. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  5110. var te = this.elements;
  5111. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  5112. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  5113. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  5114. return this;
  5115. },
  5116. identity: function () {
  5117. this.set(
  5118. 1, 0, 0,
  5119. 0, 1, 0,
  5120. 0, 0, 1
  5121. );
  5122. return this;
  5123. },
  5124. clone: function () {
  5125. return new this.constructor().fromArray( this.elements );
  5126. },
  5127. copy: function ( m ) {
  5128. var te = this.elements;
  5129. var me = m.elements;
  5130. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  5131. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  5132. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  5133. return this;
  5134. },
  5135. setFromMatrix4: function ( m ) {
  5136. var me = m.elements;
  5137. this.set(
  5138. me[ 0 ], me[ 4 ], me[ 8 ],
  5139. me[ 1 ], me[ 5 ], me[ 9 ],
  5140. me[ 2 ], me[ 6 ], me[ 10 ]
  5141. );
  5142. return this;
  5143. },
  5144. applyToBufferAttribute: function () {
  5145. var v1 = new Vector3();
  5146. return function applyToBufferAttribute( attribute ) {
  5147. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  5148. v1.x = attribute.getX( i );
  5149. v1.y = attribute.getY( i );
  5150. v1.z = attribute.getZ( i );
  5151. v1.applyMatrix3( this );
  5152. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  5153. }
  5154. return attribute;
  5155. };
  5156. }(),
  5157. multiply: function ( m ) {
  5158. return this.multiplyMatrices( this, m );
  5159. },
  5160. premultiply: function ( m ) {
  5161. return this.multiplyMatrices( m, this );
  5162. },
  5163. multiplyMatrices: function ( a, b ) {
  5164. var ae = a.elements;
  5165. var be = b.elements;
  5166. var te = this.elements;
  5167. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  5168. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  5169. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  5170. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  5171. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  5172. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  5173. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  5174. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  5175. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  5176. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  5177. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  5178. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  5179. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  5180. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  5181. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  5182. return this;
  5183. },
  5184. multiplyScalar: function ( s ) {
  5185. var te = this.elements;
  5186. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  5187. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  5188. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  5189. return this;
  5190. },
  5191. determinant: function () {
  5192. var te = this.elements;
  5193. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  5194. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  5195. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  5196. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  5197. },
  5198. getInverse: function ( matrix, throwOnDegenerate ) {
  5199. if ( matrix && matrix.isMatrix4 ) {
  5200. console.error( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  5201. }
  5202. var me = matrix.elements,
  5203. te = this.elements,
  5204. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  5205. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  5206. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  5207. t11 = n33 * n22 - n32 * n23,
  5208. t12 = n32 * n13 - n33 * n12,
  5209. t13 = n23 * n12 - n22 * n13,
  5210. det = n11 * t11 + n21 * t12 + n31 * t13;
  5211. if ( det === 0 ) {
  5212. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  5213. if ( throwOnDegenerate === true ) {
  5214. throw new Error( msg );
  5215. } else {
  5216. console.warn( msg );
  5217. }
  5218. return this.identity();
  5219. }
  5220. var detInv = 1 / det;
  5221. te[ 0 ] = t11 * detInv;
  5222. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  5223. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  5224. te[ 3 ] = t12 * detInv;
  5225. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  5226. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  5227. te[ 6 ] = t13 * detInv;
  5228. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  5229. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  5230. return this;
  5231. },
  5232. transpose: function () {
  5233. var tmp, m = this.elements;
  5234. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  5235. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  5236. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  5237. return this;
  5238. },
  5239. getNormalMatrix: function ( matrix4 ) {
  5240. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  5241. },
  5242. transposeIntoArray: function ( r ) {
  5243. var m = this.elements;
  5244. r[ 0 ] = m[ 0 ];
  5245. r[ 1 ] = m[ 3 ];
  5246. r[ 2 ] = m[ 6 ];
  5247. r[ 3 ] = m[ 1 ];
  5248. r[ 4 ] = m[ 4 ];
  5249. r[ 5 ] = m[ 7 ];
  5250. r[ 6 ] = m[ 2 ];
  5251. r[ 7 ] = m[ 5 ];
  5252. r[ 8 ] = m[ 8 ];
  5253. return this;
  5254. },
  5255. equals: function ( matrix ) {
  5256. var te = this.elements;
  5257. var me = matrix.elements;
  5258. for ( var i = 0; i < 9; i ++ ) {
  5259. if ( te[ i ] !== me[ i ] ) return false;
  5260. }
  5261. return true;
  5262. },
  5263. fromArray: function ( array, offset ) {
  5264. if ( offset === undefined ) offset = 0;
  5265. for ( var i = 0; i < 9; i ++ ) {
  5266. this.elements[ i ] = array[ i + offset ];
  5267. }
  5268. return this;
  5269. },
  5270. toArray: function ( array, offset ) {
  5271. if ( array === undefined ) array = [];
  5272. if ( offset === undefined ) offset = 0;
  5273. var te = this.elements;
  5274. array[ offset ] = te[ 0 ];
  5275. array[ offset + 1 ] = te[ 1 ];
  5276. array[ offset + 2 ] = te[ 2 ];
  5277. array[ offset + 3 ] = te[ 3 ];
  5278. array[ offset + 4 ] = te[ 4 ];
  5279. array[ offset + 5 ] = te[ 5 ];
  5280. array[ offset + 6 ] = te[ 6 ];
  5281. array[ offset + 7 ] = te[ 7 ];
  5282. array[ offset + 8 ] = te[ 8 ];
  5283. return array;
  5284. }
  5285. } );
  5286. /**
  5287. * @author bhouston / http://clara.io
  5288. */
  5289. function Plane( normal, constant ) {
  5290. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  5291. this.constant = ( constant !== undefined ) ? constant : 0;
  5292. }
  5293. Object.assign( Plane.prototype, {
  5294. set: function ( normal, constant ) {
  5295. this.normal.copy( normal );
  5296. this.constant = constant;
  5297. return this;
  5298. },
  5299. setComponents: function ( x, y, z, w ) {
  5300. this.normal.set( x, y, z );
  5301. this.constant = w;
  5302. return this;
  5303. },
  5304. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  5305. this.normal.copy( normal );
  5306. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  5307. return this;
  5308. },
  5309. setFromCoplanarPoints: function () {
  5310. var v1 = new Vector3();
  5311. var v2 = new Vector3();
  5312. return function setFromCoplanarPoints( a, b, c ) {
  5313. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  5314. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  5315. this.setFromNormalAndCoplanarPoint( normal, a );
  5316. return this;
  5317. };
  5318. }(),
  5319. clone: function () {
  5320. return new this.constructor().copy( this );
  5321. },
  5322. copy: function ( plane ) {
  5323. this.normal.copy( plane.normal );
  5324. this.constant = plane.constant;
  5325. return this;
  5326. },
  5327. normalize: function () {
  5328. // Note: will lead to a divide by zero if the plane is invalid.
  5329. var inverseNormalLength = 1.0 / this.normal.length();
  5330. this.normal.multiplyScalar( inverseNormalLength );
  5331. this.constant *= inverseNormalLength;
  5332. return this;
  5333. },
  5334. negate: function () {
  5335. this.constant *= - 1;
  5336. this.normal.negate();
  5337. return this;
  5338. },
  5339. distanceToPoint: function ( point ) {
  5340. return this.normal.dot( point ) + this.constant;
  5341. },
  5342. distanceToSphere: function ( sphere ) {
  5343. return this.distanceToPoint( sphere.center ) - sphere.radius;
  5344. },
  5345. projectPoint: function ( point, optionalTarget ) {
  5346. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  5347. },
  5348. orthoPoint: function ( point, optionalTarget ) {
  5349. var perpendicularMagnitude = this.distanceToPoint( point );
  5350. var result = optionalTarget || new Vector3();
  5351. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  5352. },
  5353. intersectLine: function () {
  5354. var v1 = new Vector3();
  5355. return function intersectLine( line, optionalTarget ) {
  5356. var result = optionalTarget || new Vector3();
  5357. var direction = line.delta( v1 );
  5358. var denominator = this.normal.dot( direction );
  5359. if ( denominator === 0 ) {
  5360. // line is coplanar, return origin
  5361. if ( this.distanceToPoint( line.start ) === 0 ) {
  5362. return result.copy( line.start );
  5363. }
  5364. // Unsure if this is the correct method to handle this case.
  5365. return undefined;
  5366. }
  5367. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  5368. if ( t < 0 || t > 1 ) {
  5369. return undefined;
  5370. }
  5371. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  5372. };
  5373. }(),
  5374. intersectsLine: function ( line ) {
  5375. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5376. var startSign = this.distanceToPoint( line.start );
  5377. var endSign = this.distanceToPoint( line.end );
  5378. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  5379. },
  5380. intersectsBox: function ( box ) {
  5381. return box.intersectsPlane( this );
  5382. },
  5383. intersectsSphere: function ( sphere ) {
  5384. return sphere.intersectsPlane( this );
  5385. },
  5386. coplanarPoint: function ( optionalTarget ) {
  5387. var result = optionalTarget || new Vector3();
  5388. return result.copy( this.normal ).multiplyScalar( - this.constant );
  5389. },
  5390. applyMatrix4: function () {
  5391. var v1 = new Vector3();
  5392. var m1 = new Matrix3();
  5393. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  5394. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  5395. // transform normal based on theory here:
  5396. // http://www.songho.ca/opengl/gl_normaltransform.html
  5397. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  5398. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  5399. // recalculate constant (like in setFromNormalAndCoplanarPoint)
  5400. this.constant = - referencePoint.dot( normal );
  5401. return this;
  5402. };
  5403. }(),
  5404. translate: function ( offset ) {
  5405. this.constant = this.constant - offset.dot( this.normal );
  5406. return this;
  5407. },
  5408. equals: function ( plane ) {
  5409. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  5410. }
  5411. } );
  5412. /**
  5413. * @author mrdoob / http://mrdoob.com/
  5414. * @author alteredq / http://alteredqualia.com/
  5415. * @author bhouston / http://clara.io
  5416. */
  5417. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  5418. this.planes = [
  5419. ( p0 !== undefined ) ? p0 : new Plane(),
  5420. ( p1 !== undefined ) ? p1 : new Plane(),
  5421. ( p2 !== undefined ) ? p2 : new Plane(),
  5422. ( p3 !== undefined ) ? p3 : new Plane(),
  5423. ( p4 !== undefined ) ? p4 : new Plane(),
  5424. ( p5 !== undefined ) ? p5 : new Plane()
  5425. ];
  5426. }
  5427. Object.assign( Frustum.prototype, {
  5428. set: function ( p0, p1, p2, p3, p4, p5 ) {
  5429. var planes = this.planes;
  5430. planes[ 0 ].copy( p0 );
  5431. planes[ 1 ].copy( p1 );
  5432. planes[ 2 ].copy( p2 );
  5433. planes[ 3 ].copy( p3 );
  5434. planes[ 4 ].copy( p4 );
  5435. planes[ 5 ].copy( p5 );
  5436. return this;
  5437. },
  5438. clone: function () {
  5439. return new this.constructor().copy( this );
  5440. },
  5441. copy: function ( frustum ) {
  5442. var planes = this.planes;
  5443. for ( var i = 0; i < 6; i ++ ) {
  5444. planes[ i ].copy( frustum.planes[ i ] );
  5445. }
  5446. return this;
  5447. },
  5448. setFromMatrix: function ( m ) {
  5449. var planes = this.planes;
  5450. var me = m.elements;
  5451. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  5452. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  5453. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  5454. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  5455. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  5456. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  5457. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  5458. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  5459. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  5460. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  5461. return this;
  5462. },
  5463. intersectsObject: function () {
  5464. var sphere = new Sphere();
  5465. return function intersectsObject( object ) {
  5466. var geometry = object.geometry;
  5467. if ( geometry.boundingSphere === null )
  5468. geometry.computeBoundingSphere();
  5469. sphere.copy( geometry.boundingSphere )
  5470. .applyMatrix4( object.matrixWorld );
  5471. return this.intersectsSphere( sphere );
  5472. };
  5473. }(),
  5474. intersectsSprite: function () {
  5475. var sphere = new Sphere();
  5476. return function intersectsSprite( sprite ) {
  5477. sphere.center.set( 0, 0, 0 );
  5478. sphere.radius = 0.7071067811865476;
  5479. sphere.applyMatrix4( sprite.matrixWorld );
  5480. return this.intersectsSphere( sphere );
  5481. };
  5482. }(),
  5483. intersectsSphere: function ( sphere ) {
  5484. var planes = this.planes;
  5485. var center = sphere.center;
  5486. var negRadius = - sphere.radius;
  5487. for ( var i = 0; i < 6; i ++ ) {
  5488. var distance = planes[ i ].distanceToPoint( center );
  5489. if ( distance < negRadius ) {
  5490. return false;
  5491. }
  5492. }
  5493. return true;
  5494. },
  5495. intersectsBox: function () {
  5496. var p1 = new Vector3(),
  5497. p2 = new Vector3();
  5498. return function intersectsBox( box ) {
  5499. var planes = this.planes;
  5500. for ( var i = 0; i < 6; i ++ ) {
  5501. var plane = planes[ i ];
  5502. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  5503. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  5504. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  5505. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  5506. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  5507. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  5508. var d1 = plane.distanceToPoint( p1 );
  5509. var d2 = plane.distanceToPoint( p2 );
  5510. // if both outside plane, no intersection
  5511. if ( d1 < 0 && d2 < 0 ) {
  5512. return false;
  5513. }
  5514. }
  5515. return true;
  5516. };
  5517. }(),
  5518. containsPoint: function ( point ) {
  5519. var planes = this.planes;
  5520. for ( var i = 0; i < 6; i ++ ) {
  5521. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  5522. return false;
  5523. }
  5524. }
  5525. return true;
  5526. }
  5527. } );
  5528. /**
  5529. * @author alteredq / http://alteredqualia.com/
  5530. * @author mrdoob / http://mrdoob.com/
  5531. */
  5532. function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
  5533. var _gl = _renderer.context,
  5534. _state = _renderer.state,
  5535. _frustum = new Frustum(),
  5536. _projScreenMatrix = new Matrix4(),
  5537. _lightShadows = _lights.shadows,
  5538. _shadowMapSize = new Vector2(),
  5539. _maxShadowMapSize = new Vector2( capabilities.maxTextureSize, capabilities.maxTextureSize ),
  5540. _lookTarget = new Vector3(),
  5541. _lightPositionWorld = new Vector3(),
  5542. _MorphingFlag = 1,
  5543. _SkinningFlag = 2,
  5544. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  5545. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  5546. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  5547. _materialCache = {};
  5548. var cubeDirections = [
  5549. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  5550. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  5551. ];
  5552. var cubeUps = [
  5553. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  5554. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  5555. ];
  5556. var cube2DViewPorts = [
  5557. new Vector4(), new Vector4(), new Vector4(),
  5558. new Vector4(), new Vector4(), new Vector4()
  5559. ];
  5560. // init
  5561. var depthMaterialTemplate = new MeshDepthMaterial();
  5562. depthMaterialTemplate.depthPacking = RGBADepthPacking;
  5563. depthMaterialTemplate.clipping = true;
  5564. var distanceShader = ShaderLib[ "distanceRGBA" ];
  5565. var distanceUniforms = UniformsUtils.clone( distanceShader.uniforms );
  5566. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  5567. var useMorphing = ( i & _MorphingFlag ) !== 0;
  5568. var useSkinning = ( i & _SkinningFlag ) !== 0;
  5569. var depthMaterial = depthMaterialTemplate.clone();
  5570. depthMaterial.morphTargets = useMorphing;
  5571. depthMaterial.skinning = useSkinning;
  5572. _depthMaterials[ i ] = depthMaterial;
  5573. var distanceMaterial = new ShaderMaterial( {
  5574. defines: {
  5575. 'USE_SHADOWMAP': ''
  5576. },
  5577. uniforms: distanceUniforms,
  5578. vertexShader: distanceShader.vertexShader,
  5579. fragmentShader: distanceShader.fragmentShader,
  5580. morphTargets: useMorphing,
  5581. skinning: useSkinning,
  5582. clipping: true
  5583. } );
  5584. _distanceMaterials[ i ] = distanceMaterial;
  5585. }
  5586. //
  5587. var scope = this;
  5588. this.enabled = false;
  5589. this.autoUpdate = true;
  5590. this.needsUpdate = false;
  5591. this.type = PCFShadowMap;
  5592. this.renderReverseSided = true;
  5593. this.renderSingleSided = true;
  5594. this.render = function ( scene, camera ) {
  5595. if ( scope.enabled === false ) return;
  5596. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  5597. if ( _lightShadows.length === 0 ) return;
  5598. // Set GL state for depth map.
  5599. _state.disable( _gl.BLEND );
  5600. _state.buffers.color.setClear( 1, 1, 1, 1 );
  5601. _state.buffers.depth.setTest( true );
  5602. _state.setScissorTest( false );
  5603. // render depth map
  5604. var faceCount;
  5605. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  5606. var light = _lightShadows[ i ];
  5607. var shadow = light.shadow;
  5608. var isPointLight = light && light.isPointLight;
  5609. if ( shadow === undefined ) {
  5610. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  5611. continue;
  5612. }
  5613. var shadowCamera = shadow.camera;
  5614. _shadowMapSize.copy( shadow.mapSize );
  5615. _shadowMapSize.min( _maxShadowMapSize );
  5616. if ( isPointLight ) {
  5617. var vpWidth = _shadowMapSize.x;
  5618. var vpHeight = _shadowMapSize.y;
  5619. // These viewports map a cube-map onto a 2D texture with the
  5620. // following orientation:
  5621. //
  5622. // xzXZ
  5623. // y Y
  5624. //
  5625. // X - Positive x direction
  5626. // x - Negative x direction
  5627. // Y - Positive y direction
  5628. // y - Negative y direction
  5629. // Z - Positive z direction
  5630. // z - Negative z direction
  5631. // positive X
  5632. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  5633. // negative X
  5634. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  5635. // positive Z
  5636. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  5637. // negative Z
  5638. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  5639. // positive Y
  5640. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  5641. // negative Y
  5642. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  5643. _shadowMapSize.x *= 4.0;
  5644. _shadowMapSize.y *= 2.0;
  5645. }
  5646. if ( shadow.map === null ) {
  5647. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  5648. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  5649. shadow.map.texture.name = light.name + ".shadowMap";
  5650. shadowCamera.updateProjectionMatrix();
  5651. }
  5652. if ( shadow.isSpotLightShadow ) {
  5653. shadow.update( light );
  5654. }
  5655. var shadowMap = shadow.map;
  5656. var shadowMatrix = shadow.matrix;
  5657. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  5658. shadowCamera.position.copy( _lightPositionWorld );
  5659. if ( isPointLight ) {
  5660. faceCount = 6;
  5661. // for point lights we set the shadow matrix to be a translation-only matrix
  5662. // equal to inverse of the light's position
  5663. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  5664. } else {
  5665. faceCount = 1;
  5666. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  5667. shadowCamera.lookAt( _lookTarget );
  5668. shadowCamera.updateMatrixWorld();
  5669. // compute shadow matrix
  5670. shadowMatrix.set(
  5671. 0.5, 0.0, 0.0, 0.5,
  5672. 0.0, 0.5, 0.0, 0.5,
  5673. 0.0, 0.0, 0.5, 0.5,
  5674. 0.0, 0.0, 0.0, 1.0
  5675. );
  5676. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  5677. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  5678. }
  5679. _renderer.setRenderTarget( shadowMap );
  5680. _renderer.clear();
  5681. // render shadow map for each cube face (if omni-directional) or
  5682. // run a single pass if not
  5683. for ( var face = 0; face < faceCount; face ++ ) {
  5684. if ( isPointLight ) {
  5685. _lookTarget.copy( shadowCamera.position );
  5686. _lookTarget.add( cubeDirections[ face ] );
  5687. shadowCamera.up.copy( cubeUps[ face ] );
  5688. shadowCamera.lookAt( _lookTarget );
  5689. shadowCamera.updateMatrixWorld();
  5690. var vpDimensions = cube2DViewPorts[ face ];
  5691. _state.viewport( vpDimensions );
  5692. }
  5693. // update camera matrices and frustum
  5694. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  5695. _frustum.setFromMatrix( _projScreenMatrix );
  5696. // set object matrices & frustum culling
  5697. renderObject( scene, camera, shadowCamera, isPointLight );
  5698. }
  5699. }
  5700. // Restore GL state.
  5701. var clearColor = _renderer.getClearColor();
  5702. var clearAlpha = _renderer.getClearAlpha();
  5703. _renderer.setClearColor( clearColor, clearAlpha );
  5704. scope.needsUpdate = false;
  5705. };
  5706. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  5707. var geometry = object.geometry;
  5708. var result = null;
  5709. var materialVariants = _depthMaterials;
  5710. var customMaterial = object.customDepthMaterial;
  5711. if ( isPointLight ) {
  5712. materialVariants = _distanceMaterials;
  5713. customMaterial = object.customDistanceMaterial;
  5714. }
  5715. if ( ! customMaterial ) {
  5716. var useMorphing = false;
  5717. if ( material.morphTargets ) {
  5718. if ( geometry && geometry.isBufferGeometry ) {
  5719. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  5720. } else if ( geometry && geometry.isGeometry ) {
  5721. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  5722. }
  5723. }
  5724. if ( object.isSkinnedMesh && material.skinning === false ) {
  5725. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  5726. }
  5727. var useSkinning = object.isSkinnedMesh && material.skinning;
  5728. var variantIndex = 0;
  5729. if ( useMorphing ) variantIndex |= _MorphingFlag;
  5730. if ( useSkinning ) variantIndex |= _SkinningFlag;
  5731. result = materialVariants[ variantIndex ];
  5732. } else {
  5733. result = customMaterial;
  5734. }
  5735. if ( _renderer.localClippingEnabled &&
  5736. material.clipShadows === true &&
  5737. material.clippingPlanes.length !== 0 ) {
  5738. // in this case we need a unique material instance reflecting the
  5739. // appropriate state
  5740. var keyA = result.uuid, keyB = material.uuid;
  5741. var materialsForVariant = _materialCache[ keyA ];
  5742. if ( materialsForVariant === undefined ) {
  5743. materialsForVariant = {};
  5744. _materialCache[ keyA ] = materialsForVariant;
  5745. }
  5746. var cachedMaterial = materialsForVariant[ keyB ];
  5747. if ( cachedMaterial === undefined ) {
  5748. cachedMaterial = result.clone();
  5749. materialsForVariant[ keyB ] = cachedMaterial;
  5750. }
  5751. result = cachedMaterial;
  5752. }
  5753. result.visible = material.visible;
  5754. result.wireframe = material.wireframe;
  5755. var side = material.side;
  5756. if ( scope.renderSingleSided && side == DoubleSide ) {
  5757. side = FrontSide;
  5758. }
  5759. if ( scope.renderReverseSided ) {
  5760. if ( side === FrontSide ) side = BackSide;
  5761. else if ( side === BackSide ) side = FrontSide;
  5762. }
  5763. result.side = side;
  5764. result.clipShadows = material.clipShadows;
  5765. result.clippingPlanes = material.clippingPlanes;
  5766. result.wireframeLinewidth = material.wireframeLinewidth;
  5767. result.linewidth = material.linewidth;
  5768. if ( isPointLight && result.uniforms.lightPos !== undefined ) {
  5769. result.uniforms.lightPos.value.copy( lightPositionWorld );
  5770. }
  5771. return result;
  5772. }
  5773. function renderObject( object, camera, shadowCamera, isPointLight ) {
  5774. if ( object.visible === false ) return;
  5775. var visible = object.layers.test( camera.layers );
  5776. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  5777. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  5778. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  5779. var geometry = _objects.update( object );
  5780. var material = object.material;
  5781. if ( Array.isArray( material ) ) {
  5782. var groups = geometry.groups;
  5783. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  5784. var group = groups[ k ];
  5785. var groupMaterial = material[ group.materialIndex ];
  5786. if ( groupMaterial && groupMaterial.visible ) {
  5787. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  5788. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  5789. }
  5790. }
  5791. } else if ( material.visible ) {
  5792. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  5793. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  5794. }
  5795. }
  5796. }
  5797. var children = object.children;
  5798. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5799. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  5800. }
  5801. }
  5802. }
  5803. /**
  5804. * @author bhouston / http://clara.io
  5805. */
  5806. function Ray( origin, direction ) {
  5807. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  5808. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  5809. }
  5810. Object.assign( Ray.prototype, {
  5811. set: function ( origin, direction ) {
  5812. this.origin.copy( origin );
  5813. this.direction.copy( direction );
  5814. return this;
  5815. },
  5816. clone: function () {
  5817. return new this.constructor().copy( this );
  5818. },
  5819. copy: function ( ray ) {
  5820. this.origin.copy( ray.origin );
  5821. this.direction.copy( ray.direction );
  5822. return this;
  5823. },
  5824. at: function ( t, optionalTarget ) {
  5825. var result = optionalTarget || new Vector3();
  5826. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  5827. },
  5828. lookAt: function ( v ) {
  5829. this.direction.copy( v ).sub( this.origin ).normalize();
  5830. return this;
  5831. },
  5832. recast: function () {
  5833. var v1 = new Vector3();
  5834. return function recast( t ) {
  5835. this.origin.copy( this.at( t, v1 ) );
  5836. return this;
  5837. };
  5838. }(),
  5839. closestPointToPoint: function ( point, optionalTarget ) {
  5840. var result = optionalTarget || new Vector3();
  5841. result.subVectors( point, this.origin );
  5842. var directionDistance = result.dot( this.direction );
  5843. if ( directionDistance < 0 ) {
  5844. return result.copy( this.origin );
  5845. }
  5846. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  5847. },
  5848. distanceToPoint: function ( point ) {
  5849. return Math.sqrt( this.distanceSqToPoint( point ) );
  5850. },
  5851. distanceSqToPoint: function () {
  5852. var v1 = new Vector3();
  5853. return function distanceSqToPoint( point ) {
  5854. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  5855. // point behind the ray
  5856. if ( directionDistance < 0 ) {
  5857. return this.origin.distanceToSquared( point );
  5858. }
  5859. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  5860. return v1.distanceToSquared( point );
  5861. };
  5862. }(),
  5863. distanceSqToSegment: function () {
  5864. var segCenter = new Vector3();
  5865. var segDir = new Vector3();
  5866. var diff = new Vector3();
  5867. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  5868. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  5869. // It returns the min distance between the ray and the segment
  5870. // defined by v0 and v1
  5871. // It can also set two optional targets :
  5872. // - The closest point on the ray
  5873. // - The closest point on the segment
  5874. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  5875. segDir.copy( v1 ).sub( v0 ).normalize();
  5876. diff.copy( this.origin ).sub( segCenter );
  5877. var segExtent = v0.distanceTo( v1 ) * 0.5;
  5878. var a01 = - this.direction.dot( segDir );
  5879. var b0 = diff.dot( this.direction );
  5880. var b1 = - diff.dot( segDir );
  5881. var c = diff.lengthSq();
  5882. var det = Math.abs( 1 - a01 * a01 );
  5883. var s0, s1, sqrDist, extDet;
  5884. if ( det > 0 ) {
  5885. // The ray and segment are not parallel.
  5886. s0 = a01 * b1 - b0;
  5887. s1 = a01 * b0 - b1;
  5888. extDet = segExtent * det;
  5889. if ( s0 >= 0 ) {
  5890. if ( s1 >= - extDet ) {
  5891. if ( s1 <= extDet ) {
  5892. // region 0
  5893. // Minimum at interior points of ray and segment.
  5894. var invDet = 1 / det;
  5895. s0 *= invDet;
  5896. s1 *= invDet;
  5897. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  5898. } else {
  5899. // region 1
  5900. s1 = segExtent;
  5901. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  5902. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5903. }
  5904. } else {
  5905. // region 5
  5906. s1 = - segExtent;
  5907. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  5908. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5909. }
  5910. } else {
  5911. if ( s1 <= - extDet ) {
  5912. // region 4
  5913. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  5914. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  5915. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5916. } else if ( s1 <= extDet ) {
  5917. // region 3
  5918. s0 = 0;
  5919. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  5920. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  5921. } else {
  5922. // region 2
  5923. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  5924. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  5925. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5926. }
  5927. }
  5928. } else {
  5929. // Ray and segment are parallel.
  5930. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  5931. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  5932. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5933. }
  5934. if ( optionalPointOnRay ) {
  5935. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  5936. }
  5937. if ( optionalPointOnSegment ) {
  5938. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  5939. }
  5940. return sqrDist;
  5941. };
  5942. }(),
  5943. intersectSphere: function () {
  5944. var v1 = new Vector3();
  5945. return function intersectSphere( sphere, optionalTarget ) {
  5946. v1.subVectors( sphere.center, this.origin );
  5947. var tca = v1.dot( this.direction );
  5948. var d2 = v1.dot( v1 ) - tca * tca;
  5949. var radius2 = sphere.radius * sphere.radius;
  5950. if ( d2 > radius2 ) return null;
  5951. var thc = Math.sqrt( radius2 - d2 );
  5952. // t0 = first intersect point - entrance on front of sphere
  5953. var t0 = tca - thc;
  5954. // t1 = second intersect point - exit point on back of sphere
  5955. var t1 = tca + thc;
  5956. // test to see if both t0 and t1 are behind the ray - if so, return null
  5957. if ( t0 < 0 && t1 < 0 ) return null;
  5958. // test to see if t0 is behind the ray:
  5959. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  5960. // in order to always return an intersect point that is in front of the ray.
  5961. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  5962. // else t0 is in front of the ray, so return the first collision point scaled by t0
  5963. return this.at( t0, optionalTarget );
  5964. };
  5965. }(),
  5966. intersectsSphere: function ( sphere ) {
  5967. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  5968. },
  5969. distanceToPlane: function ( plane ) {
  5970. var denominator = plane.normal.dot( this.direction );
  5971. if ( denominator === 0 ) {
  5972. // line is coplanar, return origin
  5973. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  5974. return 0;
  5975. }
  5976. // Null is preferable to undefined since undefined means.... it is undefined
  5977. return null;
  5978. }
  5979. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  5980. // Return if the ray never intersects the plane
  5981. return t >= 0 ? t : null;
  5982. },
  5983. intersectPlane: function ( plane, optionalTarget ) {
  5984. var t = this.distanceToPlane( plane );
  5985. if ( t === null ) {
  5986. return null;
  5987. }
  5988. return this.at( t, optionalTarget );
  5989. },
  5990. intersectsPlane: function ( plane ) {
  5991. // check if the ray lies on the plane first
  5992. var distToPoint = plane.distanceToPoint( this.origin );
  5993. if ( distToPoint === 0 ) {
  5994. return true;
  5995. }
  5996. var denominator = plane.normal.dot( this.direction );
  5997. if ( denominator * distToPoint < 0 ) {
  5998. return true;
  5999. }
  6000. // ray origin is behind the plane (and is pointing behind it)
  6001. return false;
  6002. },
  6003. intersectBox: function ( box, optionalTarget ) {
  6004. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  6005. var invdirx = 1 / this.direction.x,
  6006. invdiry = 1 / this.direction.y,
  6007. invdirz = 1 / this.direction.z;
  6008. var origin = this.origin;
  6009. if ( invdirx >= 0 ) {
  6010. tmin = ( box.min.x - origin.x ) * invdirx;
  6011. tmax = ( box.max.x - origin.x ) * invdirx;
  6012. } else {
  6013. tmin = ( box.max.x - origin.x ) * invdirx;
  6014. tmax = ( box.min.x - origin.x ) * invdirx;
  6015. }
  6016. if ( invdiry >= 0 ) {
  6017. tymin = ( box.min.y - origin.y ) * invdiry;
  6018. tymax = ( box.max.y - origin.y ) * invdiry;
  6019. } else {
  6020. tymin = ( box.max.y - origin.y ) * invdiry;
  6021. tymax = ( box.min.y - origin.y ) * invdiry;
  6022. }
  6023. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  6024. // These lines also handle the case where tmin or tmax is NaN
  6025. // (result of 0 * Infinity). x !== x returns true if x is NaN
  6026. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  6027. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  6028. if ( invdirz >= 0 ) {
  6029. tzmin = ( box.min.z - origin.z ) * invdirz;
  6030. tzmax = ( box.max.z - origin.z ) * invdirz;
  6031. } else {
  6032. tzmin = ( box.max.z - origin.z ) * invdirz;
  6033. tzmax = ( box.min.z - origin.z ) * invdirz;
  6034. }
  6035. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  6036. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  6037. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  6038. //return point closest to the ray (positive side)
  6039. if ( tmax < 0 ) return null;
  6040. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  6041. },
  6042. intersectsBox: ( function () {
  6043. var v = new Vector3();
  6044. return function intersectsBox( box ) {
  6045. return this.intersectBox( box, v ) !== null;
  6046. };
  6047. } )(),
  6048. intersectTriangle: function () {
  6049. // Compute the offset origin, edges, and normal.
  6050. var diff = new Vector3();
  6051. var edge1 = new Vector3();
  6052. var edge2 = new Vector3();
  6053. var normal = new Vector3();
  6054. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  6055. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  6056. edge1.subVectors( b, a );
  6057. edge2.subVectors( c, a );
  6058. normal.crossVectors( edge1, edge2 );
  6059. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  6060. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  6061. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  6062. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  6063. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  6064. var DdN = this.direction.dot( normal );
  6065. var sign;
  6066. if ( DdN > 0 ) {
  6067. if ( backfaceCulling ) return null;
  6068. sign = 1;
  6069. } else if ( DdN < 0 ) {
  6070. sign = - 1;
  6071. DdN = - DdN;
  6072. } else {
  6073. return null;
  6074. }
  6075. diff.subVectors( this.origin, a );
  6076. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  6077. // b1 < 0, no intersection
  6078. if ( DdQxE2 < 0 ) {
  6079. return null;
  6080. }
  6081. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  6082. // b2 < 0, no intersection
  6083. if ( DdE1xQ < 0 ) {
  6084. return null;
  6085. }
  6086. // b1+b2 > 1, no intersection
  6087. if ( DdQxE2 + DdE1xQ > DdN ) {
  6088. return null;
  6089. }
  6090. // Line intersects triangle, check if ray does.
  6091. var QdN = - sign * diff.dot( normal );
  6092. // t < 0, no intersection
  6093. if ( QdN < 0 ) {
  6094. return null;
  6095. }
  6096. // Ray intersects triangle.
  6097. return this.at( QdN / DdN, optionalTarget );
  6098. };
  6099. }(),
  6100. applyMatrix4: function ( matrix4 ) {
  6101. this.origin.applyMatrix4( matrix4 );
  6102. this.direction.transformDirection( matrix4 );
  6103. return this;
  6104. },
  6105. equals: function ( ray ) {
  6106. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  6107. }
  6108. } );
  6109. /**
  6110. * @author mrdoob / http://mrdoob.com/
  6111. * @author WestLangley / http://github.com/WestLangley
  6112. * @author bhouston / http://clara.io
  6113. */
  6114. function Euler( x, y, z, order ) {
  6115. this._x = x || 0;
  6116. this._y = y || 0;
  6117. this._z = z || 0;
  6118. this._order = order || Euler.DefaultOrder;
  6119. }
  6120. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  6121. Euler.DefaultOrder = 'XYZ';
  6122. Object.defineProperties( Euler.prototype, {
  6123. x: {
  6124. get: function () {
  6125. return this._x;
  6126. },
  6127. set: function ( value ) {
  6128. this._x = value;
  6129. this.onChangeCallback();
  6130. }
  6131. },
  6132. y: {
  6133. get: function () {
  6134. return this._y;
  6135. },
  6136. set: function ( value ) {
  6137. this._y = value;
  6138. this.onChangeCallback();
  6139. }
  6140. },
  6141. z: {
  6142. get: function () {
  6143. return this._z;
  6144. },
  6145. set: function ( value ) {
  6146. this._z = value;
  6147. this.onChangeCallback();
  6148. }
  6149. },
  6150. order: {
  6151. get: function () {
  6152. return this._order;
  6153. },
  6154. set: function ( value ) {
  6155. this._order = value;
  6156. this.onChangeCallback();
  6157. }
  6158. }
  6159. } );
  6160. Object.assign( Euler.prototype, {
  6161. isEuler: true,
  6162. set: function ( x, y, z, order ) {
  6163. this._x = x;
  6164. this._y = y;
  6165. this._z = z;
  6166. this._order = order || this._order;
  6167. this.onChangeCallback();
  6168. return this;
  6169. },
  6170. clone: function () {
  6171. return new this.constructor( this._x, this._y, this._z, this._order );
  6172. },
  6173. copy: function ( euler ) {
  6174. this._x = euler._x;
  6175. this._y = euler._y;
  6176. this._z = euler._z;
  6177. this._order = euler._order;
  6178. this.onChangeCallback();
  6179. return this;
  6180. },
  6181. setFromRotationMatrix: function ( m, order, update ) {
  6182. var clamp = _Math.clamp;
  6183. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  6184. var te = m.elements;
  6185. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  6186. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  6187. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  6188. order = order || this._order;
  6189. if ( order === 'XYZ' ) {
  6190. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  6191. if ( Math.abs( m13 ) < 0.99999 ) {
  6192. this._x = Math.atan2( - m23, m33 );
  6193. this._z = Math.atan2( - m12, m11 );
  6194. } else {
  6195. this._x = Math.atan2( m32, m22 );
  6196. this._z = 0;
  6197. }
  6198. } else if ( order === 'YXZ' ) {
  6199. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  6200. if ( Math.abs( m23 ) < 0.99999 ) {
  6201. this._y = Math.atan2( m13, m33 );
  6202. this._z = Math.atan2( m21, m22 );
  6203. } else {
  6204. this._y = Math.atan2( - m31, m11 );
  6205. this._z = 0;
  6206. }
  6207. } else if ( order === 'ZXY' ) {
  6208. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  6209. if ( Math.abs( m32 ) < 0.99999 ) {
  6210. this._y = Math.atan2( - m31, m33 );
  6211. this._z = Math.atan2( - m12, m22 );
  6212. } else {
  6213. this._y = 0;
  6214. this._z = Math.atan2( m21, m11 );
  6215. }
  6216. } else if ( order === 'ZYX' ) {
  6217. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  6218. if ( Math.abs( m31 ) < 0.99999 ) {
  6219. this._x = Math.atan2( m32, m33 );
  6220. this._z = Math.atan2( m21, m11 );
  6221. } else {
  6222. this._x = 0;
  6223. this._z = Math.atan2( - m12, m22 );
  6224. }
  6225. } else if ( order === 'YZX' ) {
  6226. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  6227. if ( Math.abs( m21 ) < 0.99999 ) {
  6228. this._x = Math.atan2( - m23, m22 );
  6229. this._y = Math.atan2( - m31, m11 );
  6230. } else {
  6231. this._x = 0;
  6232. this._y = Math.atan2( m13, m33 );
  6233. }
  6234. } else if ( order === 'XZY' ) {
  6235. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  6236. if ( Math.abs( m12 ) < 0.99999 ) {
  6237. this._x = Math.atan2( m32, m22 );
  6238. this._y = Math.atan2( m13, m11 );
  6239. } else {
  6240. this._x = Math.atan2( - m23, m33 );
  6241. this._y = 0;
  6242. }
  6243. } else {
  6244. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  6245. }
  6246. this._order = order;
  6247. if ( update !== false ) this.onChangeCallback();
  6248. return this;
  6249. },
  6250. setFromQuaternion: function () {
  6251. var matrix = new Matrix4();
  6252. return function setFromQuaternion( q, order, update ) {
  6253. matrix.makeRotationFromQuaternion( q );
  6254. return this.setFromRotationMatrix( matrix, order, update );
  6255. };
  6256. }(),
  6257. setFromVector3: function ( v, order ) {
  6258. return this.set( v.x, v.y, v.z, order || this._order );
  6259. },
  6260. reorder: function () {
  6261. // WARNING: this discards revolution information -bhouston
  6262. var q = new Quaternion();
  6263. return function reorder( newOrder ) {
  6264. q.setFromEuler( this );
  6265. return this.setFromQuaternion( q, newOrder );
  6266. };
  6267. }(),
  6268. equals: function ( euler ) {
  6269. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  6270. },
  6271. fromArray: function ( array ) {
  6272. this._x = array[ 0 ];
  6273. this._y = array[ 1 ];
  6274. this._z = array[ 2 ];
  6275. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  6276. this.onChangeCallback();
  6277. return this;
  6278. },
  6279. toArray: function ( array, offset ) {
  6280. if ( array === undefined ) array = [];
  6281. if ( offset === undefined ) offset = 0;
  6282. array[ offset ] = this._x;
  6283. array[ offset + 1 ] = this._y;
  6284. array[ offset + 2 ] = this._z;
  6285. array[ offset + 3 ] = this._order;
  6286. return array;
  6287. },
  6288. toVector3: function ( optionalResult ) {
  6289. if ( optionalResult ) {
  6290. return optionalResult.set( this._x, this._y, this._z );
  6291. } else {
  6292. return new Vector3( this._x, this._y, this._z );
  6293. }
  6294. },
  6295. onChange: function ( callback ) {
  6296. this.onChangeCallback = callback;
  6297. return this;
  6298. },
  6299. onChangeCallback: function () {}
  6300. } );
  6301. /**
  6302. * @author mrdoob / http://mrdoob.com/
  6303. */
  6304. function Layers() {
  6305. this.mask = 1 | 0;
  6306. }
  6307. Object.assign( Layers.prototype, {
  6308. set: function ( channel ) {
  6309. this.mask = 1 << channel | 0;
  6310. },
  6311. enable: function ( channel ) {
  6312. this.mask |= 1 << channel | 0;
  6313. },
  6314. toggle: function ( channel ) {
  6315. this.mask ^= 1 << channel | 0;
  6316. },
  6317. disable: function ( channel ) {
  6318. this.mask &= ~ ( 1 << channel | 0 );
  6319. },
  6320. test: function ( layers ) {
  6321. return ( this.mask & layers.mask ) !== 0;
  6322. }
  6323. } );
  6324. /**
  6325. * @author mrdoob / http://mrdoob.com/
  6326. * @author mikael emtinger / http://gomo.se/
  6327. * @author alteredq / http://alteredqualia.com/
  6328. * @author WestLangley / http://github.com/WestLangley
  6329. * @author elephantatwork / www.elephantatwork.ch
  6330. */
  6331. var object3DId = 0;
  6332. function Object3D() {
  6333. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  6334. this.uuid = _Math.generateUUID();
  6335. this.name = '';
  6336. this.type = 'Object3D';
  6337. this.parent = null;
  6338. this.children = [];
  6339. this.up = Object3D.DefaultUp.clone();
  6340. var position = new Vector3();
  6341. var rotation = new Euler();
  6342. var quaternion = new Quaternion();
  6343. var scale = new Vector3( 1, 1, 1 );
  6344. function onRotationChange() {
  6345. quaternion.setFromEuler( rotation, false );
  6346. }
  6347. function onQuaternionChange() {
  6348. rotation.setFromQuaternion( quaternion, undefined, false );
  6349. }
  6350. rotation.onChange( onRotationChange );
  6351. quaternion.onChange( onQuaternionChange );
  6352. Object.defineProperties( this, {
  6353. position: {
  6354. enumerable: true,
  6355. value: position
  6356. },
  6357. rotation: {
  6358. enumerable: true,
  6359. value: rotation
  6360. },
  6361. quaternion: {
  6362. enumerable: true,
  6363. value: quaternion
  6364. },
  6365. scale: {
  6366. enumerable: true,
  6367. value: scale
  6368. },
  6369. modelViewMatrix: {
  6370. value: new Matrix4()
  6371. },
  6372. normalMatrix: {
  6373. value: new Matrix3()
  6374. }
  6375. } );
  6376. this.matrix = new Matrix4();
  6377. this.matrixWorld = new Matrix4();
  6378. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  6379. this.matrixWorldNeedsUpdate = false;
  6380. this.layers = new Layers();
  6381. this.visible = true;
  6382. this.castShadow = false;
  6383. this.receiveShadow = false;
  6384. this.frustumCulled = true;
  6385. this.renderOrder = 0;
  6386. this.userData = {};
  6387. }
  6388. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  6389. Object3D.DefaultMatrixAutoUpdate = true;
  6390. Object.assign( Object3D.prototype, EventDispatcher.prototype, {
  6391. isObject3D: true,
  6392. onBeforeRender: function () {},
  6393. onAfterRender: function () {},
  6394. applyMatrix: function ( matrix ) {
  6395. this.matrix.multiplyMatrices( matrix, this.matrix );
  6396. this.matrix.decompose( this.position, this.quaternion, this.scale );
  6397. },
  6398. applyQuaternion: function ( q ) {
  6399. this.quaternion.premultiply( q );
  6400. return this;
  6401. },
  6402. setRotationFromAxisAngle: function ( axis, angle ) {
  6403. // assumes axis is normalized
  6404. this.quaternion.setFromAxisAngle( axis, angle );
  6405. },
  6406. setRotationFromEuler: function ( euler ) {
  6407. this.quaternion.setFromEuler( euler, true );
  6408. },
  6409. setRotationFromMatrix: function ( m ) {
  6410. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  6411. this.quaternion.setFromRotationMatrix( m );
  6412. },
  6413. setRotationFromQuaternion: function ( q ) {
  6414. // assumes q is normalized
  6415. this.quaternion.copy( q );
  6416. },
  6417. rotateOnAxis: function () {
  6418. // rotate object on axis in object space
  6419. // axis is assumed to be normalized
  6420. var q1 = new Quaternion();
  6421. return function rotateOnAxis( axis, angle ) {
  6422. q1.setFromAxisAngle( axis, angle );
  6423. this.quaternion.multiply( q1 );
  6424. return this;
  6425. };
  6426. }(),
  6427. rotateX: function () {
  6428. var v1 = new Vector3( 1, 0, 0 );
  6429. return function rotateX( angle ) {
  6430. return this.rotateOnAxis( v1, angle );
  6431. };
  6432. }(),
  6433. rotateY: function () {
  6434. var v1 = new Vector3( 0, 1, 0 );
  6435. return function rotateY( angle ) {
  6436. return this.rotateOnAxis( v1, angle );
  6437. };
  6438. }(),
  6439. rotateZ: function () {
  6440. var v1 = new Vector3( 0, 0, 1 );
  6441. return function rotateZ( angle ) {
  6442. return this.rotateOnAxis( v1, angle );
  6443. };
  6444. }(),
  6445. translateOnAxis: function () {
  6446. // translate object by distance along axis in object space
  6447. // axis is assumed to be normalized
  6448. var v1 = new Vector3();
  6449. return function translateOnAxis( axis, distance ) {
  6450. v1.copy( axis ).applyQuaternion( this.quaternion );
  6451. this.position.add( v1.multiplyScalar( distance ) );
  6452. return this;
  6453. };
  6454. }(),
  6455. translateX: function () {
  6456. var v1 = new Vector3( 1, 0, 0 );
  6457. return function translateX( distance ) {
  6458. return this.translateOnAxis( v1, distance );
  6459. };
  6460. }(),
  6461. translateY: function () {
  6462. var v1 = new Vector3( 0, 1, 0 );
  6463. return function translateY( distance ) {
  6464. return this.translateOnAxis( v1, distance );
  6465. };
  6466. }(),
  6467. translateZ: function () {
  6468. var v1 = new Vector3( 0, 0, 1 );
  6469. return function translateZ( distance ) {
  6470. return this.translateOnAxis( v1, distance );
  6471. };
  6472. }(),
  6473. localToWorld: function ( vector ) {
  6474. return vector.applyMatrix4( this.matrixWorld );
  6475. },
  6476. worldToLocal: function () {
  6477. var m1 = new Matrix4();
  6478. return function worldToLocal( vector ) {
  6479. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  6480. };
  6481. }(),
  6482. lookAt: function () {
  6483. // This method does not support objects with rotated and/or translated parent(s)
  6484. var m1 = new Matrix4();
  6485. return function lookAt( vector ) {
  6486. if ( this.isCamera ) {
  6487. m1.lookAt( this.position, vector, this.up );
  6488. } else {
  6489. m1.lookAt( vector, this.position, this.up );
  6490. }
  6491. this.quaternion.setFromRotationMatrix( m1 );
  6492. };
  6493. }(),
  6494. add: function ( object ) {
  6495. if ( arguments.length > 1 ) {
  6496. for ( var i = 0; i < arguments.length; i ++ ) {
  6497. this.add( arguments[ i ] );
  6498. }
  6499. return this;
  6500. }
  6501. if ( object === this ) {
  6502. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  6503. return this;
  6504. }
  6505. if ( ( object && object.isObject3D ) ) {
  6506. if ( object.parent !== null ) {
  6507. object.parent.remove( object );
  6508. }
  6509. object.parent = this;
  6510. object.dispatchEvent( { type: 'added' } );
  6511. this.children.push( object );
  6512. } else {
  6513. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  6514. }
  6515. return this;
  6516. },
  6517. remove: function ( object ) {
  6518. if ( arguments.length > 1 ) {
  6519. for ( var i = 0; i < arguments.length; i ++ ) {
  6520. this.remove( arguments[ i ] );
  6521. }
  6522. }
  6523. var index = this.children.indexOf( object );
  6524. if ( index !== - 1 ) {
  6525. object.parent = null;
  6526. object.dispatchEvent( { type: 'removed' } );
  6527. this.children.splice( index, 1 );
  6528. }
  6529. },
  6530. getObjectById: function ( id ) {
  6531. return this.getObjectByProperty( 'id', id );
  6532. },
  6533. getObjectByName: function ( name ) {
  6534. return this.getObjectByProperty( 'name', name );
  6535. },
  6536. getObjectByProperty: function ( name, value ) {
  6537. if ( this[ name ] === value ) return this;
  6538. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  6539. var child = this.children[ i ];
  6540. var object = child.getObjectByProperty( name, value );
  6541. if ( object !== undefined ) {
  6542. return object;
  6543. }
  6544. }
  6545. return undefined;
  6546. },
  6547. getWorldPosition: function ( optionalTarget ) {
  6548. var result = optionalTarget || new Vector3();
  6549. this.updateMatrixWorld( true );
  6550. return result.setFromMatrixPosition( this.matrixWorld );
  6551. },
  6552. getWorldQuaternion: function () {
  6553. var position = new Vector3();
  6554. var scale = new Vector3();
  6555. return function getWorldQuaternion( optionalTarget ) {
  6556. var result = optionalTarget || new Quaternion();
  6557. this.updateMatrixWorld( true );
  6558. this.matrixWorld.decompose( position, result, scale );
  6559. return result;
  6560. };
  6561. }(),
  6562. getWorldRotation: function () {
  6563. var quaternion = new Quaternion();
  6564. return function getWorldRotation( optionalTarget ) {
  6565. var result = optionalTarget || new Euler();
  6566. this.getWorldQuaternion( quaternion );
  6567. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  6568. };
  6569. }(),
  6570. getWorldScale: function () {
  6571. var position = new Vector3();
  6572. var quaternion = new Quaternion();
  6573. return function getWorldScale( optionalTarget ) {
  6574. var result = optionalTarget || new Vector3();
  6575. this.updateMatrixWorld( true );
  6576. this.matrixWorld.decompose( position, quaternion, result );
  6577. return result;
  6578. };
  6579. }(),
  6580. getWorldDirection: function () {
  6581. var quaternion = new Quaternion();
  6582. return function getWorldDirection( optionalTarget ) {
  6583. var result = optionalTarget || new Vector3();
  6584. this.getWorldQuaternion( quaternion );
  6585. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  6586. };
  6587. }(),
  6588. raycast: function () {},
  6589. traverse: function ( callback ) {
  6590. callback( this );
  6591. var children = this.children;
  6592. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6593. children[ i ].traverse( callback );
  6594. }
  6595. },
  6596. traverseVisible: function ( callback ) {
  6597. if ( this.visible === false ) return;
  6598. callback( this );
  6599. var children = this.children;
  6600. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6601. children[ i ].traverseVisible( callback );
  6602. }
  6603. },
  6604. traverseAncestors: function ( callback ) {
  6605. var parent = this.parent;
  6606. if ( parent !== null ) {
  6607. callback( parent );
  6608. parent.traverseAncestors( callback );
  6609. }
  6610. },
  6611. updateMatrix: function () {
  6612. this.matrix.compose( this.position, this.quaternion, this.scale );
  6613. this.matrixWorldNeedsUpdate = true;
  6614. },
  6615. updateMatrixWorld: function ( force ) {
  6616. if ( this.matrixAutoUpdate ) this.updateMatrix();
  6617. if ( this.matrixWorldNeedsUpdate || force ) {
  6618. if ( this.parent === null ) {
  6619. this.matrixWorld.copy( this.matrix );
  6620. } else {
  6621. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  6622. }
  6623. this.matrixWorldNeedsUpdate = false;
  6624. force = true;
  6625. }
  6626. // update children
  6627. var children = this.children;
  6628. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6629. children[ i ].updateMatrixWorld( force );
  6630. }
  6631. },
  6632. toJSON: function ( meta ) {
  6633. // meta is '' when called from JSON.stringify
  6634. var isRootObject = ( meta === undefined || meta === '' );
  6635. var output = {};
  6636. // meta is a hash used to collect geometries, materials.
  6637. // not providing it implies that this is the root object
  6638. // being serialized.
  6639. if ( isRootObject ) {
  6640. // initialize meta obj
  6641. meta = {
  6642. geometries: {},
  6643. materials: {},
  6644. textures: {},
  6645. images: {}
  6646. };
  6647. output.metadata = {
  6648. version: 4.5,
  6649. type: 'Object',
  6650. generator: 'Object3D.toJSON'
  6651. };
  6652. }
  6653. // standard Object3D serialization
  6654. var object = {};
  6655. object.uuid = this.uuid;
  6656. object.type = this.type;
  6657. if ( this.name !== '' ) object.name = this.name;
  6658. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  6659. if ( this.castShadow === true ) object.castShadow = true;
  6660. if ( this.receiveShadow === true ) object.receiveShadow = true;
  6661. if ( this.visible === false ) object.visible = false;
  6662. object.matrix = this.matrix.toArray();
  6663. //
  6664. function serialize( library, element ) {
  6665. if ( library[ element.uuid ] === undefined ) {
  6666. library[ element.uuid ] = element.toJSON( meta );
  6667. }
  6668. return element.uuid;
  6669. }
  6670. if ( this.geometry !== undefined ) {
  6671. object.geometry = serialize( meta.geometries, this.geometry );
  6672. }
  6673. if ( this.material !== undefined ) {
  6674. if ( Array.isArray( this.material ) ) {
  6675. var uuids = [];
  6676. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  6677. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  6678. }
  6679. object.material = uuids;
  6680. } else {
  6681. object.material = serialize( meta.materials, this.material );
  6682. }
  6683. }
  6684. //
  6685. if ( this.children.length > 0 ) {
  6686. object.children = [];
  6687. for ( var i = 0; i < this.children.length; i ++ ) {
  6688. object.children.push( this.children[ i ].toJSON( meta ).object );
  6689. }
  6690. }
  6691. if ( isRootObject ) {
  6692. var geometries = extractFromCache( meta.geometries );
  6693. var materials = extractFromCache( meta.materials );
  6694. var textures = extractFromCache( meta.textures );
  6695. var images = extractFromCache( meta.images );
  6696. if ( geometries.length > 0 ) output.geometries = geometries;
  6697. if ( materials.length > 0 ) output.materials = materials;
  6698. if ( textures.length > 0 ) output.textures = textures;
  6699. if ( images.length > 0 ) output.images = images;
  6700. }
  6701. output.object = object;
  6702. return output;
  6703. // extract data from the cache hash
  6704. // remove metadata on each item
  6705. // and return as array
  6706. function extractFromCache( cache ) {
  6707. var values = [];
  6708. for ( var key in cache ) {
  6709. var data = cache[ key ];
  6710. delete data.metadata;
  6711. values.push( data );
  6712. }
  6713. return values;
  6714. }
  6715. },
  6716. clone: function ( recursive ) {
  6717. return new this.constructor().copy( this, recursive );
  6718. },
  6719. copy: function ( source, recursive ) {
  6720. if ( recursive === undefined ) recursive = true;
  6721. this.name = source.name;
  6722. this.up.copy( source.up );
  6723. this.position.copy( source.position );
  6724. this.quaternion.copy( source.quaternion );
  6725. this.scale.copy( source.scale );
  6726. this.matrix.copy( source.matrix );
  6727. this.matrixWorld.copy( source.matrixWorld );
  6728. this.matrixAutoUpdate = source.matrixAutoUpdate;
  6729. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  6730. this.layers.mask = source.layers.mask;
  6731. this.visible = source.visible;
  6732. this.castShadow = source.castShadow;
  6733. this.receiveShadow = source.receiveShadow;
  6734. this.frustumCulled = source.frustumCulled;
  6735. this.renderOrder = source.renderOrder;
  6736. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  6737. if ( recursive === true ) {
  6738. for ( var i = 0; i < source.children.length; i ++ ) {
  6739. var child = source.children[ i ];
  6740. this.add( child.clone() );
  6741. }
  6742. }
  6743. return this;
  6744. }
  6745. } );
  6746. /**
  6747. * @author bhouston / http://clara.io
  6748. */
  6749. function Line3( start, end ) {
  6750. this.start = ( start !== undefined ) ? start : new Vector3();
  6751. this.end = ( end !== undefined ) ? end : new Vector3();
  6752. }
  6753. Object.assign( Line3.prototype, {
  6754. set: function ( start, end ) {
  6755. this.start.copy( start );
  6756. this.end.copy( end );
  6757. return this;
  6758. },
  6759. clone: function () {
  6760. return new this.constructor().copy( this );
  6761. },
  6762. copy: function ( line ) {
  6763. this.start.copy( line.start );
  6764. this.end.copy( line.end );
  6765. return this;
  6766. },
  6767. getCenter: function ( optionalTarget ) {
  6768. var result = optionalTarget || new Vector3();
  6769. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  6770. },
  6771. delta: function ( optionalTarget ) {
  6772. var result = optionalTarget || new Vector3();
  6773. return result.subVectors( this.end, this.start );
  6774. },
  6775. distanceSq: function () {
  6776. return this.start.distanceToSquared( this.end );
  6777. },
  6778. distance: function () {
  6779. return this.start.distanceTo( this.end );
  6780. },
  6781. at: function ( t, optionalTarget ) {
  6782. var result = optionalTarget || new Vector3();
  6783. return this.delta( result ).multiplyScalar( t ).add( this.start );
  6784. },
  6785. closestPointToPointParameter: function () {
  6786. var startP = new Vector3();
  6787. var startEnd = new Vector3();
  6788. return function closestPointToPointParameter( point, clampToLine ) {
  6789. startP.subVectors( point, this.start );
  6790. startEnd.subVectors( this.end, this.start );
  6791. var startEnd2 = startEnd.dot( startEnd );
  6792. var startEnd_startP = startEnd.dot( startP );
  6793. var t = startEnd_startP / startEnd2;
  6794. if ( clampToLine ) {
  6795. t = _Math.clamp( t, 0, 1 );
  6796. }
  6797. return t;
  6798. };
  6799. }(),
  6800. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  6801. var t = this.closestPointToPointParameter( point, clampToLine );
  6802. var result = optionalTarget || new Vector3();
  6803. return this.delta( result ).multiplyScalar( t ).add( this.start );
  6804. },
  6805. applyMatrix4: function ( matrix ) {
  6806. this.start.applyMatrix4( matrix );
  6807. this.end.applyMatrix4( matrix );
  6808. return this;
  6809. },
  6810. equals: function ( line ) {
  6811. return line.start.equals( this.start ) && line.end.equals( this.end );
  6812. }
  6813. } );
  6814. /**
  6815. * @author bhouston / http://clara.io
  6816. * @author mrdoob / http://mrdoob.com/
  6817. */
  6818. function Triangle( a, b, c ) {
  6819. this.a = ( a !== undefined ) ? a : new Vector3();
  6820. this.b = ( b !== undefined ) ? b : new Vector3();
  6821. this.c = ( c !== undefined ) ? c : new Vector3();
  6822. }
  6823. Object.assign( Triangle, {
  6824. normal: function () {
  6825. var v0 = new Vector3();
  6826. return function normal( a, b, c, optionalTarget ) {
  6827. var result = optionalTarget || new Vector3();
  6828. result.subVectors( c, b );
  6829. v0.subVectors( a, b );
  6830. result.cross( v0 );
  6831. var resultLengthSq = result.lengthSq();
  6832. if ( resultLengthSq > 0 ) {
  6833. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  6834. }
  6835. return result.set( 0, 0, 0 );
  6836. };
  6837. }(),
  6838. // static/instance method to calculate barycentric coordinates
  6839. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  6840. barycoordFromPoint: function () {
  6841. var v0 = new Vector3();
  6842. var v1 = new Vector3();
  6843. var v2 = new Vector3();
  6844. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  6845. v0.subVectors( c, a );
  6846. v1.subVectors( b, a );
  6847. v2.subVectors( point, a );
  6848. var dot00 = v0.dot( v0 );
  6849. var dot01 = v0.dot( v1 );
  6850. var dot02 = v0.dot( v2 );
  6851. var dot11 = v1.dot( v1 );
  6852. var dot12 = v1.dot( v2 );
  6853. var denom = ( dot00 * dot11 - dot01 * dot01 );
  6854. var result = optionalTarget || new Vector3();
  6855. // collinear or singular triangle
  6856. if ( denom === 0 ) {
  6857. // arbitrary location outside of triangle?
  6858. // not sure if this is the best idea, maybe should be returning undefined
  6859. return result.set( - 2, - 1, - 1 );
  6860. }
  6861. var invDenom = 1 / denom;
  6862. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  6863. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  6864. // barycentric coordinates must always sum to 1
  6865. return result.set( 1 - u - v, v, u );
  6866. };
  6867. }(),
  6868. containsPoint: function () {
  6869. var v1 = new Vector3();
  6870. return function containsPoint( point, a, b, c ) {
  6871. var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
  6872. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  6873. };
  6874. }()
  6875. } );
  6876. Object.assign( Triangle.prototype, {
  6877. set: function ( a, b, c ) {
  6878. this.a.copy( a );
  6879. this.b.copy( b );
  6880. this.c.copy( c );
  6881. return this;
  6882. },
  6883. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  6884. this.a.copy( points[ i0 ] );
  6885. this.b.copy( points[ i1 ] );
  6886. this.c.copy( points[ i2 ] );
  6887. return this;
  6888. },
  6889. clone: function () {
  6890. return new this.constructor().copy( this );
  6891. },
  6892. copy: function ( triangle ) {
  6893. this.a.copy( triangle.a );
  6894. this.b.copy( triangle.b );
  6895. this.c.copy( triangle.c );
  6896. return this;
  6897. },
  6898. area: function () {
  6899. var v0 = new Vector3();
  6900. var v1 = new Vector3();
  6901. return function area() {
  6902. v0.subVectors( this.c, this.b );
  6903. v1.subVectors( this.a, this.b );
  6904. return v0.cross( v1 ).length() * 0.5;
  6905. };
  6906. }(),
  6907. midpoint: function ( optionalTarget ) {
  6908. var result = optionalTarget || new Vector3();
  6909. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  6910. },
  6911. normal: function ( optionalTarget ) {
  6912. return Triangle.normal( this.a, this.b, this.c, optionalTarget );
  6913. },
  6914. plane: function ( optionalTarget ) {
  6915. var result = optionalTarget || new Plane();
  6916. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  6917. },
  6918. barycoordFromPoint: function ( point, optionalTarget ) {
  6919. return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  6920. },
  6921. containsPoint: function ( point ) {
  6922. return Triangle.containsPoint( point, this.a, this.b, this.c );
  6923. },
  6924. closestPointToPoint: function () {
  6925. var plane = new Plane();
  6926. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  6927. var projectedPoint = new Vector3();
  6928. var closestPoint = new Vector3();
  6929. return function closestPointToPoint( point, optionalTarget ) {
  6930. var result = optionalTarget || new Vector3();
  6931. var minDistance = Infinity;
  6932. // project the point onto the plane of the triangle
  6933. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  6934. plane.projectPoint( point, projectedPoint );
  6935. // check if the projection lies within the triangle
  6936. if( this.containsPoint( projectedPoint ) === true ) {
  6937. // if so, this is the closest point
  6938. result.copy( projectedPoint );
  6939. } else {
  6940. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  6941. edgeList[ 0 ].set( this.a, this.b );
  6942. edgeList[ 1 ].set( this.b, this.c );
  6943. edgeList[ 2 ].set( this.c, this.a );
  6944. for( var i = 0; i < edgeList.length; i ++ ) {
  6945. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  6946. var distance = projectedPoint.distanceToSquared( closestPoint );
  6947. if( distance < minDistance ) {
  6948. minDistance = distance;
  6949. result.copy( closestPoint );
  6950. }
  6951. }
  6952. }
  6953. return result;
  6954. };
  6955. }(),
  6956. equals: function ( triangle ) {
  6957. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  6958. }
  6959. } );
  6960. /**
  6961. * @author mrdoob / http://mrdoob.com/
  6962. * @author alteredq / http://alteredqualia.com/
  6963. */
  6964. function Face3( a, b, c, normal, color, materialIndex ) {
  6965. this.a = a;
  6966. this.b = b;
  6967. this.c = c;
  6968. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  6969. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  6970. this.color = ( color && color.isColor ) ? color : new Color();
  6971. this.vertexColors = Array.isArray( color ) ? color : [];
  6972. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  6973. }
  6974. Object.assign( Face3.prototype, {
  6975. clone: function () {
  6976. return new this.constructor().copy( this );
  6977. },
  6978. copy: function ( source ) {
  6979. this.a = source.a;
  6980. this.b = source.b;
  6981. this.c = source.c;
  6982. this.normal.copy( source.normal );
  6983. this.color.copy( source.color );
  6984. this.materialIndex = source.materialIndex;
  6985. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  6986. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  6987. }
  6988. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  6989. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  6990. }
  6991. return this;
  6992. }
  6993. } );
  6994. /**
  6995. * @author mrdoob / http://mrdoob.com/
  6996. * @author alteredq / http://alteredqualia.com/
  6997. *
  6998. * parameters = {
  6999. * color: <hex>,
  7000. * opacity: <float>,
  7001. * map: new THREE.Texture( <Image> ),
  7002. *
  7003. * lightMap: new THREE.Texture( <Image> ),
  7004. * lightMapIntensity: <float>
  7005. *
  7006. * aoMap: new THREE.Texture( <Image> ),
  7007. * aoMapIntensity: <float>
  7008. *
  7009. * specularMap: new THREE.Texture( <Image> ),
  7010. *
  7011. * alphaMap: new THREE.Texture( <Image> ),
  7012. *
  7013. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  7014. * combine: THREE.Multiply,
  7015. * reflectivity: <float>,
  7016. * refractionRatio: <float>,
  7017. *
  7018. * shading: THREE.SmoothShading,
  7019. * depthTest: <bool>,
  7020. * depthWrite: <bool>,
  7021. *
  7022. * wireframe: <boolean>,
  7023. * wireframeLinewidth: <float>,
  7024. *
  7025. * skinning: <bool>,
  7026. * morphTargets: <bool>
  7027. * }
  7028. */
  7029. function MeshBasicMaterial( parameters ) {
  7030. Material.call( this );
  7031. this.type = 'MeshBasicMaterial';
  7032. this.color = new Color( 0xffffff ); // emissive
  7033. this.map = null;
  7034. this.lightMap = null;
  7035. this.lightMapIntensity = 1.0;
  7036. this.aoMap = null;
  7037. this.aoMapIntensity = 1.0;
  7038. this.specularMap = null;
  7039. this.alphaMap = null;
  7040. this.envMap = null;
  7041. this.combine = MultiplyOperation;
  7042. this.reflectivity = 1;
  7043. this.refractionRatio = 0.98;
  7044. this.wireframe = false;
  7045. this.wireframeLinewidth = 1;
  7046. this.wireframeLinecap = 'round';
  7047. this.wireframeLinejoin = 'round';
  7048. this.skinning = false;
  7049. this.morphTargets = false;
  7050. this.lights = false;
  7051. this.setValues( parameters );
  7052. }
  7053. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  7054. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  7055. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  7056. MeshBasicMaterial.prototype.copy = function ( source ) {
  7057. Material.prototype.copy.call( this, source );
  7058. this.color.copy( source.color );
  7059. this.map = source.map;
  7060. this.lightMap = source.lightMap;
  7061. this.lightMapIntensity = source.lightMapIntensity;
  7062. this.aoMap = source.aoMap;
  7063. this.aoMapIntensity = source.aoMapIntensity;
  7064. this.specularMap = source.specularMap;
  7065. this.alphaMap = source.alphaMap;
  7066. this.envMap = source.envMap;
  7067. this.combine = source.combine;
  7068. this.reflectivity = source.reflectivity;
  7069. this.refractionRatio = source.refractionRatio;
  7070. this.wireframe = source.wireframe;
  7071. this.wireframeLinewidth = source.wireframeLinewidth;
  7072. this.wireframeLinecap = source.wireframeLinecap;
  7073. this.wireframeLinejoin = source.wireframeLinejoin;
  7074. this.skinning = source.skinning;
  7075. this.morphTargets = source.morphTargets;
  7076. return this;
  7077. };
  7078. /**
  7079. * @author mrdoob / http://mrdoob.com/
  7080. */
  7081. function BufferAttribute( array, itemSize, normalized ) {
  7082. if ( Array.isArray( array ) ) {
  7083. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7084. }
  7085. this.uuid = _Math.generateUUID();
  7086. this.name = '';
  7087. this.array = array;
  7088. this.itemSize = itemSize;
  7089. this.count = array !== undefined ? array.length / itemSize : 0;
  7090. this.normalized = normalized === true;
  7091. this.dynamic = false;
  7092. this.updateRange = { offset: 0, count: - 1 };
  7093. this.onUploadCallback = function () {};
  7094. this.version = 0;
  7095. }
  7096. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  7097. set: function ( value ) {
  7098. if ( value === true ) this.version ++;
  7099. }
  7100. } );
  7101. Object.assign( BufferAttribute.prototype, {
  7102. isBufferAttribute: true,
  7103. setArray: function ( array ) {
  7104. if ( Array.isArray( array ) ) {
  7105. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7106. }
  7107. this.count = array !== undefined ? array.length / this.itemSize : 0;
  7108. this.array = array;
  7109. },
  7110. setDynamic: function ( value ) {
  7111. this.dynamic = value;
  7112. return this;
  7113. },
  7114. copy: function ( source ) {
  7115. this.array = new source.array.constructor( source.array );
  7116. this.itemSize = source.itemSize;
  7117. this.count = source.count;
  7118. this.normalized = source.normalized;
  7119. this.dynamic = source.dynamic;
  7120. return this;
  7121. },
  7122. copyAt: function ( index1, attribute, index2 ) {
  7123. index1 *= this.itemSize;
  7124. index2 *= attribute.itemSize;
  7125. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  7126. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  7127. }
  7128. return this;
  7129. },
  7130. copyArray: function ( array ) {
  7131. this.array.set( array );
  7132. return this;
  7133. },
  7134. copyColorsArray: function ( colors ) {
  7135. var array = this.array, offset = 0;
  7136. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  7137. var color = colors[ i ];
  7138. if ( color === undefined ) {
  7139. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  7140. color = new Color();
  7141. }
  7142. array[ offset ++ ] = color.r;
  7143. array[ offset ++ ] = color.g;
  7144. array[ offset ++ ] = color.b;
  7145. }
  7146. return this;
  7147. },
  7148. copyIndicesArray: function ( indices ) {
  7149. var array = this.array, offset = 0;
  7150. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7151. var index = indices[ i ];
  7152. array[ offset ++ ] = index.a;
  7153. array[ offset ++ ] = index.b;
  7154. array[ offset ++ ] = index.c;
  7155. }
  7156. return this;
  7157. },
  7158. copyVector2sArray: function ( vectors ) {
  7159. var array = this.array, offset = 0;
  7160. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7161. var vector = vectors[ i ];
  7162. if ( vector === undefined ) {
  7163. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  7164. vector = new Vector2();
  7165. }
  7166. array[ offset ++ ] = vector.x;
  7167. array[ offset ++ ] = vector.y;
  7168. }
  7169. return this;
  7170. },
  7171. copyVector3sArray: function ( vectors ) {
  7172. var array = this.array, offset = 0;
  7173. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7174. var vector = vectors[ i ];
  7175. if ( vector === undefined ) {
  7176. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  7177. vector = new Vector3();
  7178. }
  7179. array[ offset ++ ] = vector.x;
  7180. array[ offset ++ ] = vector.y;
  7181. array[ offset ++ ] = vector.z;
  7182. }
  7183. return this;
  7184. },
  7185. copyVector4sArray: function ( vectors ) {
  7186. var array = this.array, offset = 0;
  7187. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7188. var vector = vectors[ i ];
  7189. if ( vector === undefined ) {
  7190. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  7191. vector = new Vector4();
  7192. }
  7193. array[ offset ++ ] = vector.x;
  7194. array[ offset ++ ] = vector.y;
  7195. array[ offset ++ ] = vector.z;
  7196. array[ offset ++ ] = vector.w;
  7197. }
  7198. return this;
  7199. },
  7200. set: function ( value, offset ) {
  7201. if ( offset === undefined ) offset = 0;
  7202. this.array.set( value, offset );
  7203. return this;
  7204. },
  7205. getX: function ( index ) {
  7206. return this.array[ index * this.itemSize ];
  7207. },
  7208. setX: function ( index, x ) {
  7209. this.array[ index * this.itemSize ] = x;
  7210. return this;
  7211. },
  7212. getY: function ( index ) {
  7213. return this.array[ index * this.itemSize + 1 ];
  7214. },
  7215. setY: function ( index, y ) {
  7216. this.array[ index * this.itemSize + 1 ] = y;
  7217. return this;
  7218. },
  7219. getZ: function ( index ) {
  7220. return this.array[ index * this.itemSize + 2 ];
  7221. },
  7222. setZ: function ( index, z ) {
  7223. this.array[ index * this.itemSize + 2 ] = z;
  7224. return this;
  7225. },
  7226. getW: function ( index ) {
  7227. return this.array[ index * this.itemSize + 3 ];
  7228. },
  7229. setW: function ( index, w ) {
  7230. this.array[ index * this.itemSize + 3 ] = w;
  7231. return this;
  7232. },
  7233. setXY: function ( index, x, y ) {
  7234. index *= this.itemSize;
  7235. this.array[ index + 0 ] = x;
  7236. this.array[ index + 1 ] = y;
  7237. return this;
  7238. },
  7239. setXYZ: function ( index, x, y, z ) {
  7240. index *= this.itemSize;
  7241. this.array[ index + 0 ] = x;
  7242. this.array[ index + 1 ] = y;
  7243. this.array[ index + 2 ] = z;
  7244. return this;
  7245. },
  7246. setXYZW: function ( index, x, y, z, w ) {
  7247. index *= this.itemSize;
  7248. this.array[ index + 0 ] = x;
  7249. this.array[ index + 1 ] = y;
  7250. this.array[ index + 2 ] = z;
  7251. this.array[ index + 3 ] = w;
  7252. return this;
  7253. },
  7254. onUpload: function ( callback ) {
  7255. this.onUploadCallback = callback;
  7256. return this;
  7257. },
  7258. clone: function () {
  7259. return new this.constructor( this.array, this.itemSize ).copy( this );
  7260. }
  7261. } );
  7262. //
  7263. function Int8BufferAttribute( array, itemSize ) {
  7264. BufferAttribute.call( this, new Int8Array( array ), itemSize );
  7265. }
  7266. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7267. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  7268. function Uint8BufferAttribute( array, itemSize ) {
  7269. BufferAttribute.call( this, new Uint8Array( array ), itemSize );
  7270. }
  7271. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7272. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  7273. function Uint8ClampedBufferAttribute( array, itemSize ) {
  7274. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize );
  7275. }
  7276. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7277. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  7278. function Int16BufferAttribute( array, itemSize ) {
  7279. BufferAttribute.call( this, new Int16Array( array ), itemSize );
  7280. }
  7281. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7282. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  7283. function Uint16BufferAttribute( array, itemSize ) {
  7284. BufferAttribute.call( this, new Uint16Array( array ), itemSize );
  7285. }
  7286. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7287. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  7288. function Int32BufferAttribute( array, itemSize ) {
  7289. BufferAttribute.call( this, new Int32Array( array ), itemSize );
  7290. }
  7291. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7292. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  7293. function Uint32BufferAttribute( array, itemSize ) {
  7294. BufferAttribute.call( this, new Uint32Array( array ), itemSize );
  7295. }
  7296. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7297. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  7298. function Float32BufferAttribute( array, itemSize ) {
  7299. BufferAttribute.call( this, new Float32Array( array ), itemSize );
  7300. }
  7301. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7302. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  7303. function Float64BufferAttribute( array, itemSize ) {
  7304. BufferAttribute.call( this, new Float64Array( array ), itemSize );
  7305. }
  7306. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7307. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  7308. /**
  7309. * @author mrdoob / http://mrdoob.com/
  7310. */
  7311. function DirectGeometry() {
  7312. this.indices = [];
  7313. this.vertices = [];
  7314. this.normals = [];
  7315. this.colors = [];
  7316. this.uvs = [];
  7317. this.uvs2 = [];
  7318. this.groups = [];
  7319. this.morphTargets = {};
  7320. this.skinWeights = [];
  7321. this.skinIndices = [];
  7322. // this.lineDistances = [];
  7323. this.boundingBox = null;
  7324. this.boundingSphere = null;
  7325. // update flags
  7326. this.verticesNeedUpdate = false;
  7327. this.normalsNeedUpdate = false;
  7328. this.colorsNeedUpdate = false;
  7329. this.uvsNeedUpdate = false;
  7330. this.groupsNeedUpdate = false;
  7331. }
  7332. Object.assign( DirectGeometry.prototype, {
  7333. computeGroups: function ( geometry ) {
  7334. var group;
  7335. var groups = [];
  7336. var materialIndex = undefined;
  7337. var faces = geometry.faces;
  7338. for ( var i = 0; i < faces.length; i ++ ) {
  7339. var face = faces[ i ];
  7340. // materials
  7341. if ( face.materialIndex !== materialIndex ) {
  7342. materialIndex = face.materialIndex;
  7343. if ( group !== undefined ) {
  7344. group.count = ( i * 3 ) - group.start;
  7345. groups.push( group );
  7346. }
  7347. group = {
  7348. start: i * 3,
  7349. materialIndex: materialIndex
  7350. };
  7351. }
  7352. }
  7353. if ( group !== undefined ) {
  7354. group.count = ( i * 3 ) - group.start;
  7355. groups.push( group );
  7356. }
  7357. this.groups = groups;
  7358. },
  7359. fromGeometry: function ( geometry ) {
  7360. var faces = geometry.faces;
  7361. var vertices = geometry.vertices;
  7362. var faceVertexUvs = geometry.faceVertexUvs;
  7363. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  7364. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  7365. // morphs
  7366. var morphTargets = geometry.morphTargets;
  7367. var morphTargetsLength = morphTargets.length;
  7368. var morphTargetsPosition;
  7369. if ( morphTargetsLength > 0 ) {
  7370. morphTargetsPosition = [];
  7371. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  7372. morphTargetsPosition[ i ] = [];
  7373. }
  7374. this.morphTargets.position = morphTargetsPosition;
  7375. }
  7376. var morphNormals = geometry.morphNormals;
  7377. var morphNormalsLength = morphNormals.length;
  7378. var morphTargetsNormal;
  7379. if ( morphNormalsLength > 0 ) {
  7380. morphTargetsNormal = [];
  7381. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  7382. morphTargetsNormal[ i ] = [];
  7383. }
  7384. this.morphTargets.normal = morphTargetsNormal;
  7385. }
  7386. // skins
  7387. var skinIndices = geometry.skinIndices;
  7388. var skinWeights = geometry.skinWeights;
  7389. var hasSkinIndices = skinIndices.length === vertices.length;
  7390. var hasSkinWeights = skinWeights.length === vertices.length;
  7391. //
  7392. for ( var i = 0; i < faces.length; i ++ ) {
  7393. var face = faces[ i ];
  7394. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  7395. var vertexNormals = face.vertexNormals;
  7396. if ( vertexNormals.length === 3 ) {
  7397. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  7398. } else {
  7399. var normal = face.normal;
  7400. this.normals.push( normal, normal, normal );
  7401. }
  7402. var vertexColors = face.vertexColors;
  7403. if ( vertexColors.length === 3 ) {
  7404. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  7405. } else {
  7406. var color = face.color;
  7407. this.colors.push( color, color, color );
  7408. }
  7409. if ( hasFaceVertexUv === true ) {
  7410. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  7411. if ( vertexUvs !== undefined ) {
  7412. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  7413. } else {
  7414. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  7415. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  7416. }
  7417. }
  7418. if ( hasFaceVertexUv2 === true ) {
  7419. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  7420. if ( vertexUvs !== undefined ) {
  7421. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  7422. } else {
  7423. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  7424. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  7425. }
  7426. }
  7427. // morphs
  7428. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  7429. var morphTarget = morphTargets[ j ].vertices;
  7430. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  7431. }
  7432. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  7433. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  7434. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  7435. }
  7436. // skins
  7437. if ( hasSkinIndices ) {
  7438. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  7439. }
  7440. if ( hasSkinWeights ) {
  7441. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  7442. }
  7443. }
  7444. this.computeGroups( geometry );
  7445. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  7446. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  7447. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  7448. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  7449. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  7450. return this;
  7451. }
  7452. } );
  7453. function arrayMax( array ) {
  7454. if ( array.length === 0 ) return - Infinity;
  7455. var max = array[ 0 ];
  7456. for ( var i = 1, l = array.length; i < l; ++ i ) {
  7457. if ( array[ i ] > max ) max = array[ i ];
  7458. }
  7459. return max;
  7460. }
  7461. /**
  7462. * @author mrdoob / http://mrdoob.com/
  7463. * @author kile / http://kile.stravaganza.org/
  7464. * @author alteredq / http://alteredqualia.com/
  7465. * @author mikael emtinger / http://gomo.se/
  7466. * @author zz85 / http://www.lab4games.net/zz85/blog
  7467. * @author bhouston / http://clara.io
  7468. */
  7469. var count = 0;
  7470. function GeometryIdCount() { return count++; }
  7471. function Geometry() {
  7472. Object.defineProperty( this, 'id', { value: GeometryIdCount() } );
  7473. this.uuid = _Math.generateUUID();
  7474. this.name = '';
  7475. this.type = 'Geometry';
  7476. this.vertices = [];
  7477. this.colors = [];
  7478. this.faces = [];
  7479. this.faceVertexUvs = [[]];
  7480. this.morphTargets = [];
  7481. this.morphNormals = [];
  7482. this.skinWeights = [];
  7483. this.skinIndices = [];
  7484. this.lineDistances = [];
  7485. this.boundingBox = null;
  7486. this.boundingSphere = null;
  7487. // update flags
  7488. this.elementsNeedUpdate = false;
  7489. this.verticesNeedUpdate = false;
  7490. this.uvsNeedUpdate = false;
  7491. this.normalsNeedUpdate = false;
  7492. this.colorsNeedUpdate = false;
  7493. this.lineDistancesNeedUpdate = false;
  7494. this.groupsNeedUpdate = false;
  7495. }
  7496. Object.assign( Geometry.prototype, EventDispatcher.prototype, {
  7497. isGeometry: true,
  7498. applyMatrix: function ( matrix ) {
  7499. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7500. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  7501. var vertex = this.vertices[ i ];
  7502. vertex.applyMatrix4( matrix );
  7503. }
  7504. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  7505. var face = this.faces[ i ];
  7506. face.normal.applyMatrix3( normalMatrix ).normalize();
  7507. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  7508. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  7509. }
  7510. }
  7511. if ( this.boundingBox !== null ) {
  7512. this.computeBoundingBox();
  7513. }
  7514. if ( this.boundingSphere !== null ) {
  7515. this.computeBoundingSphere();
  7516. }
  7517. this.verticesNeedUpdate = true;
  7518. this.normalsNeedUpdate = true;
  7519. return this;
  7520. },
  7521. rotateX: function () {
  7522. // rotate geometry around world x-axis
  7523. var m1 = new Matrix4();
  7524. return function rotateX( angle ) {
  7525. m1.makeRotationX( angle );
  7526. this.applyMatrix( m1 );
  7527. return this;
  7528. };
  7529. }(),
  7530. rotateY: function () {
  7531. // rotate geometry around world y-axis
  7532. var m1 = new Matrix4();
  7533. return function rotateY( angle ) {
  7534. m1.makeRotationY( angle );
  7535. this.applyMatrix( m1 );
  7536. return this;
  7537. };
  7538. }(),
  7539. rotateZ: function () {
  7540. // rotate geometry around world z-axis
  7541. var m1 = new Matrix4();
  7542. return function rotateZ( angle ) {
  7543. m1.makeRotationZ( angle );
  7544. this.applyMatrix( m1 );
  7545. return this;
  7546. };
  7547. }(),
  7548. translate: function () {
  7549. // translate geometry
  7550. var m1 = new Matrix4();
  7551. return function translate( x, y, z ) {
  7552. m1.makeTranslation( x, y, z );
  7553. this.applyMatrix( m1 );
  7554. return this;
  7555. };
  7556. }(),
  7557. scale: function () {
  7558. // scale geometry
  7559. var m1 = new Matrix4();
  7560. return function scale( x, y, z ) {
  7561. m1.makeScale( x, y, z );
  7562. this.applyMatrix( m1 );
  7563. return this;
  7564. };
  7565. }(),
  7566. lookAt: function () {
  7567. var obj = new Object3D();
  7568. return function lookAt( vector ) {
  7569. obj.lookAt( vector );
  7570. obj.updateMatrix();
  7571. this.applyMatrix( obj.matrix );
  7572. };
  7573. }(),
  7574. fromBufferGeometry: function ( geometry ) {
  7575. var scope = this;
  7576. var indices = geometry.index !== null ? geometry.index.array : undefined;
  7577. var attributes = geometry.attributes;
  7578. var positions = attributes.position.array;
  7579. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  7580. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  7581. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  7582. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  7583. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  7584. var tempNormals = [];
  7585. var tempUVs = [];
  7586. var tempUVs2 = [];
  7587. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  7588. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  7589. if ( normals !== undefined ) {
  7590. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  7591. }
  7592. if ( colors !== undefined ) {
  7593. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  7594. }
  7595. if ( uvs !== undefined ) {
  7596. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  7597. }
  7598. if ( uvs2 !== undefined ) {
  7599. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  7600. }
  7601. }
  7602. function addFace( a, b, c, materialIndex ) {
  7603. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  7604. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  7605. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  7606. scope.faces.push( face );
  7607. if ( uvs !== undefined ) {
  7608. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  7609. }
  7610. if ( uvs2 !== undefined ) {
  7611. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  7612. }
  7613. }
  7614. var groups = geometry.groups;
  7615. if ( groups.length > 0 ) {
  7616. for ( var i = 0; i < groups.length; i ++ ) {
  7617. var group = groups[ i ];
  7618. var start = group.start;
  7619. var count = group.count;
  7620. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  7621. if ( indices !== undefined ) {
  7622. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  7623. } else {
  7624. addFace( j, j + 1, j + 2, group.materialIndex );
  7625. }
  7626. }
  7627. }
  7628. } else {
  7629. if ( indices !== undefined ) {
  7630. for ( var i = 0; i < indices.length; i += 3 ) {
  7631. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  7632. }
  7633. } else {
  7634. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  7635. addFace( i, i + 1, i + 2 );
  7636. }
  7637. }
  7638. }
  7639. this.computeFaceNormals();
  7640. if ( geometry.boundingBox !== null ) {
  7641. this.boundingBox = geometry.boundingBox.clone();
  7642. }
  7643. if ( geometry.boundingSphere !== null ) {
  7644. this.boundingSphere = geometry.boundingSphere.clone();
  7645. }
  7646. return this;
  7647. },
  7648. center: function () {
  7649. this.computeBoundingBox();
  7650. var offset = this.boundingBox.getCenter().negate();
  7651. this.translate( offset.x, offset.y, offset.z );
  7652. return offset;
  7653. },
  7654. normalize: function () {
  7655. this.computeBoundingSphere();
  7656. var center = this.boundingSphere.center;
  7657. var radius = this.boundingSphere.radius;
  7658. var s = radius === 0 ? 1 : 1.0 / radius;
  7659. var matrix = new Matrix4();
  7660. matrix.set(
  7661. s, 0, 0, - s * center.x,
  7662. 0, s, 0, - s * center.y,
  7663. 0, 0, s, - s * center.z,
  7664. 0, 0, 0, 1
  7665. );
  7666. this.applyMatrix( matrix );
  7667. return this;
  7668. },
  7669. computeFaceNormals: function () {
  7670. var cb = new Vector3(), ab = new Vector3();
  7671. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7672. var face = this.faces[ f ];
  7673. var vA = this.vertices[ face.a ];
  7674. var vB = this.vertices[ face.b ];
  7675. var vC = this.vertices[ face.c ];
  7676. cb.subVectors( vC, vB );
  7677. ab.subVectors( vA, vB );
  7678. cb.cross( ab );
  7679. cb.normalize();
  7680. face.normal.copy( cb );
  7681. }
  7682. },
  7683. computeVertexNormals: function ( areaWeighted ) {
  7684. if ( areaWeighted === undefined ) areaWeighted = true;
  7685. var v, vl, f, fl, face, vertices;
  7686. vertices = new Array( this.vertices.length );
  7687. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7688. vertices[ v ] = new Vector3();
  7689. }
  7690. if ( areaWeighted ) {
  7691. // vertex normals weighted by triangle areas
  7692. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7693. var vA, vB, vC;
  7694. var cb = new Vector3(), ab = new Vector3();
  7695. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7696. face = this.faces[ f ];
  7697. vA = this.vertices[ face.a ];
  7698. vB = this.vertices[ face.b ];
  7699. vC = this.vertices[ face.c ];
  7700. cb.subVectors( vC, vB );
  7701. ab.subVectors( vA, vB );
  7702. cb.cross( ab );
  7703. vertices[ face.a ].add( cb );
  7704. vertices[ face.b ].add( cb );
  7705. vertices[ face.c ].add( cb );
  7706. }
  7707. } else {
  7708. this.computeFaceNormals();
  7709. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7710. face = this.faces[ f ];
  7711. vertices[ face.a ].add( face.normal );
  7712. vertices[ face.b ].add( face.normal );
  7713. vertices[ face.c ].add( face.normal );
  7714. }
  7715. }
  7716. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7717. vertices[ v ].normalize();
  7718. }
  7719. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7720. face = this.faces[ f ];
  7721. var vertexNormals = face.vertexNormals;
  7722. if ( vertexNormals.length === 3 ) {
  7723. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7724. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7725. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7726. } else {
  7727. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7728. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7729. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7730. }
  7731. }
  7732. if ( this.faces.length > 0 ) {
  7733. this.normalsNeedUpdate = true;
  7734. }
  7735. },
  7736. computeFlatVertexNormals: function () {
  7737. var f, fl, face;
  7738. this.computeFaceNormals();
  7739. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7740. face = this.faces[ f ];
  7741. var vertexNormals = face.vertexNormals;
  7742. if ( vertexNormals.length === 3 ) {
  7743. vertexNormals[ 0 ].copy( face.normal );
  7744. vertexNormals[ 1 ].copy( face.normal );
  7745. vertexNormals[ 2 ].copy( face.normal );
  7746. } else {
  7747. vertexNormals[ 0 ] = face.normal.clone();
  7748. vertexNormals[ 1 ] = face.normal.clone();
  7749. vertexNormals[ 2 ] = face.normal.clone();
  7750. }
  7751. }
  7752. if ( this.faces.length > 0 ) {
  7753. this.normalsNeedUpdate = true;
  7754. }
  7755. },
  7756. computeMorphNormals: function () {
  7757. var i, il, f, fl, face;
  7758. // save original normals
  7759. // - create temp variables on first access
  7760. // otherwise just copy (for faster repeated calls)
  7761. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7762. face = this.faces[ f ];
  7763. if ( ! face.__originalFaceNormal ) {
  7764. face.__originalFaceNormal = face.normal.clone();
  7765. } else {
  7766. face.__originalFaceNormal.copy( face.normal );
  7767. }
  7768. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7769. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7770. if ( ! face.__originalVertexNormals[ i ] ) {
  7771. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7772. } else {
  7773. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7774. }
  7775. }
  7776. }
  7777. // use temp geometry to compute face and vertex normals for each morph
  7778. var tmpGeo = new Geometry();
  7779. tmpGeo.faces = this.faces;
  7780. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7781. // create on first access
  7782. if ( ! this.morphNormals[ i ] ) {
  7783. this.morphNormals[ i ] = {};
  7784. this.morphNormals[ i ].faceNormals = [];
  7785. this.morphNormals[ i ].vertexNormals = [];
  7786. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7787. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7788. var faceNormal, vertexNormals;
  7789. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7790. faceNormal = new Vector3();
  7791. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7792. dstNormalsFace.push( faceNormal );
  7793. dstNormalsVertex.push( vertexNormals );
  7794. }
  7795. }
  7796. var morphNormals = this.morphNormals[ i ];
  7797. // set vertices to morph target
  7798. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7799. // compute morph normals
  7800. tmpGeo.computeFaceNormals();
  7801. tmpGeo.computeVertexNormals();
  7802. // store morph normals
  7803. var faceNormal, vertexNormals;
  7804. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7805. face = this.faces[ f ];
  7806. faceNormal = morphNormals.faceNormals[ f ];
  7807. vertexNormals = morphNormals.vertexNormals[ f ];
  7808. faceNormal.copy( face.normal );
  7809. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7810. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7811. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7812. }
  7813. }
  7814. // restore original normals
  7815. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7816. face = this.faces[ f ];
  7817. face.normal = face.__originalFaceNormal;
  7818. face.vertexNormals = face.__originalVertexNormals;
  7819. }
  7820. },
  7821. computeLineDistances: function () {
  7822. var d = 0;
  7823. var vertices = this.vertices;
  7824. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  7825. if ( i > 0 ) {
  7826. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  7827. }
  7828. this.lineDistances[ i ] = d;
  7829. }
  7830. },
  7831. computeBoundingBox: function () {
  7832. if ( this.boundingBox === null ) {
  7833. this.boundingBox = new Box3();
  7834. }
  7835. this.boundingBox.setFromPoints( this.vertices );
  7836. },
  7837. computeBoundingSphere: function () {
  7838. if ( this.boundingSphere === null ) {
  7839. this.boundingSphere = new Sphere();
  7840. }
  7841. this.boundingSphere.setFromPoints( this.vertices );
  7842. },
  7843. merge: function ( geometry, matrix, materialIndexOffset ) {
  7844. if ( ! ( geometry && geometry.isGeometry ) ) {
  7845. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7846. return;
  7847. }
  7848. var normalMatrix,
  7849. vertexOffset = this.vertices.length,
  7850. vertices1 = this.vertices,
  7851. vertices2 = geometry.vertices,
  7852. faces1 = this.faces,
  7853. faces2 = geometry.faces,
  7854. uvs1 = this.faceVertexUvs[ 0 ],
  7855. uvs2 = geometry.faceVertexUvs[ 0 ],
  7856. colors1 = this.colors,
  7857. colors2 = geometry.colors;
  7858. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7859. if ( matrix !== undefined ) {
  7860. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7861. }
  7862. // vertices
  7863. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7864. var vertex = vertices2[ i ];
  7865. var vertexCopy = vertex.clone();
  7866. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7867. vertices1.push( vertexCopy );
  7868. }
  7869. // colors
  7870. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7871. colors1.push( colors2[ i ].clone() );
  7872. }
  7873. // faces
  7874. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7875. var face = faces2[ i ], faceCopy, normal, color,
  7876. faceVertexNormals = face.vertexNormals,
  7877. faceVertexColors = face.vertexColors;
  7878. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7879. faceCopy.normal.copy( face.normal );
  7880. if ( normalMatrix !== undefined ) {
  7881. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7882. }
  7883. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7884. normal = faceVertexNormals[ j ].clone();
  7885. if ( normalMatrix !== undefined ) {
  7886. normal.applyMatrix3( normalMatrix ).normalize();
  7887. }
  7888. faceCopy.vertexNormals.push( normal );
  7889. }
  7890. faceCopy.color.copy( face.color );
  7891. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7892. color = faceVertexColors[ j ];
  7893. faceCopy.vertexColors.push( color.clone() );
  7894. }
  7895. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7896. faces1.push( faceCopy );
  7897. }
  7898. // uvs
  7899. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  7900. var uv = uvs2[ i ], uvCopy = [];
  7901. if ( uv === undefined ) {
  7902. continue;
  7903. }
  7904. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  7905. uvCopy.push( uv[ j ].clone() );
  7906. }
  7907. uvs1.push( uvCopy );
  7908. }
  7909. },
  7910. mergeMesh: function ( mesh ) {
  7911. if ( ! ( mesh && mesh.isMesh ) ) {
  7912. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7913. return;
  7914. }
  7915. mesh.matrixAutoUpdate && mesh.updateMatrix();
  7916. this.merge( mesh.geometry, mesh.matrix );
  7917. },
  7918. /*
  7919. * Checks for duplicate vertices with hashmap.
  7920. * Duplicated vertices are removed
  7921. * and faces' vertices are updated.
  7922. */
  7923. mergeVertices: function () {
  7924. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7925. var unique = [], changes = [];
  7926. var v, key;
  7927. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7928. var precision = Math.pow( 10, precisionPoints );
  7929. var i, il, face;
  7930. var indices, j, jl;
  7931. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7932. v = this.vertices[ i ];
  7933. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7934. if ( verticesMap[ key ] === undefined ) {
  7935. verticesMap[ key ] = i;
  7936. unique.push( this.vertices[ i ] );
  7937. changes[ i ] = unique.length - 1;
  7938. } else {
  7939. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7940. changes[ i ] = changes[ verticesMap[ key ] ];
  7941. }
  7942. }
  7943. // if faces are completely degenerate after merging vertices, we
  7944. // have to remove them from the geometry.
  7945. var faceIndicesToRemove = [];
  7946. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7947. face = this.faces[ i ];
  7948. face.a = changes[ face.a ];
  7949. face.b = changes[ face.b ];
  7950. face.c = changes[ face.c ];
  7951. indices = [ face.a, face.b, face.c ];
  7952. // if any duplicate vertices are found in a Face3
  7953. // we have to remove the face as nothing can be saved
  7954. for ( var n = 0; n < 3; n ++ ) {
  7955. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7956. faceIndicesToRemove.push( i );
  7957. break;
  7958. }
  7959. }
  7960. }
  7961. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7962. var idx = faceIndicesToRemove[ i ];
  7963. this.faces.splice( idx, 1 );
  7964. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7965. this.faceVertexUvs[ j ].splice( idx, 1 );
  7966. }
  7967. }
  7968. // Use unique set of vertices
  7969. var diff = this.vertices.length - unique.length;
  7970. this.vertices = unique;
  7971. return diff;
  7972. },
  7973. sortFacesByMaterialIndex: function () {
  7974. var faces = this.faces;
  7975. var length = faces.length;
  7976. // tag faces
  7977. for ( var i = 0; i < length; i ++ ) {
  7978. faces[ i ]._id = i;
  7979. }
  7980. // sort faces
  7981. function materialIndexSort( a, b ) {
  7982. return a.materialIndex - b.materialIndex;
  7983. }
  7984. faces.sort( materialIndexSort );
  7985. // sort uvs
  7986. var uvs1 = this.faceVertexUvs[ 0 ];
  7987. var uvs2 = this.faceVertexUvs[ 1 ];
  7988. var newUvs1, newUvs2;
  7989. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7990. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7991. for ( var i = 0; i < length; i ++ ) {
  7992. var id = faces[ i ]._id;
  7993. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7994. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7995. }
  7996. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7997. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7998. },
  7999. toJSON: function () {
  8000. var data = {
  8001. metadata: {
  8002. version: 4.5,
  8003. type: 'Geometry',
  8004. generator: 'Geometry.toJSON'
  8005. }
  8006. };
  8007. // standard Geometry serialization
  8008. data.uuid = this.uuid;
  8009. data.type = this.type;
  8010. if ( this.name !== '' ) data.name = this.name;
  8011. if ( this.parameters !== undefined ) {
  8012. var parameters = this.parameters;
  8013. for ( var key in parameters ) {
  8014. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8015. }
  8016. return data;
  8017. }
  8018. var vertices = [];
  8019. for ( var i = 0; i < this.vertices.length; i ++ ) {
  8020. var vertex = this.vertices[ i ];
  8021. vertices.push( vertex.x, vertex.y, vertex.z );
  8022. }
  8023. var faces = [];
  8024. var normals = [];
  8025. var normalsHash = {};
  8026. var colors = [];
  8027. var colorsHash = {};
  8028. var uvs = [];
  8029. var uvsHash = {};
  8030. for ( var i = 0; i < this.faces.length; i ++ ) {
  8031. var face = this.faces[ i ];
  8032. var hasMaterial = true;
  8033. var hasFaceUv = false; // deprecated
  8034. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  8035. var hasFaceNormal = face.normal.length() > 0;
  8036. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  8037. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  8038. var hasFaceVertexColor = face.vertexColors.length > 0;
  8039. var faceType = 0;
  8040. faceType = setBit( faceType, 0, 0 ); // isQuad
  8041. faceType = setBit( faceType, 1, hasMaterial );
  8042. faceType = setBit( faceType, 2, hasFaceUv );
  8043. faceType = setBit( faceType, 3, hasFaceVertexUv );
  8044. faceType = setBit( faceType, 4, hasFaceNormal );
  8045. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  8046. faceType = setBit( faceType, 6, hasFaceColor );
  8047. faceType = setBit( faceType, 7, hasFaceVertexColor );
  8048. faces.push( faceType );
  8049. faces.push( face.a, face.b, face.c );
  8050. faces.push( face.materialIndex );
  8051. if ( hasFaceVertexUv ) {
  8052. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  8053. faces.push(
  8054. getUvIndex( faceVertexUvs[ 0 ] ),
  8055. getUvIndex( faceVertexUvs[ 1 ] ),
  8056. getUvIndex( faceVertexUvs[ 2 ] )
  8057. );
  8058. }
  8059. if ( hasFaceNormal ) {
  8060. faces.push( getNormalIndex( face.normal ) );
  8061. }
  8062. if ( hasFaceVertexNormal ) {
  8063. var vertexNormals = face.vertexNormals;
  8064. faces.push(
  8065. getNormalIndex( vertexNormals[ 0 ] ),
  8066. getNormalIndex( vertexNormals[ 1 ] ),
  8067. getNormalIndex( vertexNormals[ 2 ] )
  8068. );
  8069. }
  8070. if ( hasFaceColor ) {
  8071. faces.push( getColorIndex( face.color ) );
  8072. }
  8073. if ( hasFaceVertexColor ) {
  8074. var vertexColors = face.vertexColors;
  8075. faces.push(
  8076. getColorIndex( vertexColors[ 0 ] ),
  8077. getColorIndex( vertexColors[ 1 ] ),
  8078. getColorIndex( vertexColors[ 2 ] )
  8079. );
  8080. }
  8081. }
  8082. function setBit( value, position, enabled ) {
  8083. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  8084. }
  8085. function getNormalIndex( normal ) {
  8086. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  8087. if ( normalsHash[ hash ] !== undefined ) {
  8088. return normalsHash[ hash ];
  8089. }
  8090. normalsHash[ hash ] = normals.length / 3;
  8091. normals.push( normal.x, normal.y, normal.z );
  8092. return normalsHash[ hash ];
  8093. }
  8094. function getColorIndex( color ) {
  8095. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  8096. if ( colorsHash[ hash ] !== undefined ) {
  8097. return colorsHash[ hash ];
  8098. }
  8099. colorsHash[ hash ] = colors.length;
  8100. colors.push( color.getHex() );
  8101. return colorsHash[ hash ];
  8102. }
  8103. function getUvIndex( uv ) {
  8104. var hash = uv.x.toString() + uv.y.toString();
  8105. if ( uvsHash[ hash ] !== undefined ) {
  8106. return uvsHash[ hash ];
  8107. }
  8108. uvsHash[ hash ] = uvs.length / 2;
  8109. uvs.push( uv.x, uv.y );
  8110. return uvsHash[ hash ];
  8111. }
  8112. data.data = {};
  8113. data.data.vertices = vertices;
  8114. data.data.normals = normals;
  8115. if ( colors.length > 0 ) data.data.colors = colors;
  8116. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  8117. data.data.faces = faces;
  8118. return data;
  8119. },
  8120. clone: function () {
  8121. /*
  8122. // Handle primitives
  8123. var parameters = this.parameters;
  8124. if ( parameters !== undefined ) {
  8125. var values = [];
  8126. for ( var key in parameters ) {
  8127. values.push( parameters[ key ] );
  8128. }
  8129. var geometry = Object.create( this.constructor.prototype );
  8130. this.constructor.apply( geometry, values );
  8131. return geometry;
  8132. }
  8133. return new this.constructor().copy( this );
  8134. */
  8135. return new Geometry().copy( this );
  8136. },
  8137. copy: function ( source ) {
  8138. var i, il, j, jl, k, kl;
  8139. // reset
  8140. this.vertices = [];
  8141. this.colors = [];
  8142. this.faces = [];
  8143. this.faceVertexUvs = [[]];
  8144. this.morphTargets = [];
  8145. this.morphNormals = [];
  8146. this.skinWeights = [];
  8147. this.skinIndices = [];
  8148. this.lineDistances = [];
  8149. this.boundingBox = null;
  8150. this.boundingSphere = null;
  8151. // name
  8152. this.name = source.name;
  8153. // vertices
  8154. var vertices = source.vertices;
  8155. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  8156. this.vertices.push( vertices[ i ].clone() );
  8157. }
  8158. // colors
  8159. var colors = source.colors;
  8160. for ( i = 0, il = colors.length; i < il; i ++ ) {
  8161. this.colors.push( colors[ i ].clone() );
  8162. }
  8163. // faces
  8164. var faces = source.faces;
  8165. for ( i = 0, il = faces.length; i < il; i ++ ) {
  8166. this.faces.push( faces[ i ].clone() );
  8167. }
  8168. // face vertex uvs
  8169. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  8170. var faceVertexUvs = source.faceVertexUvs[ i ];
  8171. if ( this.faceVertexUvs[ i ] === undefined ) {
  8172. this.faceVertexUvs[ i ] = [];
  8173. }
  8174. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  8175. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  8176. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  8177. var uv = uvs[ k ];
  8178. uvsCopy.push( uv.clone() );
  8179. }
  8180. this.faceVertexUvs[ i ].push( uvsCopy );
  8181. }
  8182. }
  8183. // morph targets
  8184. var morphTargets = source.morphTargets;
  8185. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  8186. var morphTarget = {};
  8187. morphTarget.name = morphTargets[ i ].name;
  8188. // vertices
  8189. if ( morphTargets[ i ].vertices !== undefined ) {
  8190. morphTarget.vertices = [];
  8191. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  8192. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  8193. }
  8194. }
  8195. // normals
  8196. if ( morphTargets[ i ].normals !== undefined ) {
  8197. morphTarget.normals = [];
  8198. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  8199. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  8200. }
  8201. }
  8202. this.morphTargets.push( morphTarget );
  8203. }
  8204. // morph normals
  8205. var morphNormals = source.morphNormals;
  8206. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  8207. var morphNormal = {};
  8208. // vertex normals
  8209. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  8210. morphNormal.vertexNormals = [];
  8211. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  8212. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  8213. var destVertexNormal = {};
  8214. destVertexNormal.a = srcVertexNormal.a.clone();
  8215. destVertexNormal.b = srcVertexNormal.b.clone();
  8216. destVertexNormal.c = srcVertexNormal.c.clone();
  8217. morphNormal.vertexNormals.push( destVertexNormal );
  8218. }
  8219. }
  8220. // face normals
  8221. if ( morphNormals[ i ].faceNormals !== undefined ) {
  8222. morphNormal.faceNormals = [];
  8223. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  8224. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  8225. }
  8226. }
  8227. this.morphNormals.push( morphNormal );
  8228. }
  8229. // skin weights
  8230. var skinWeights = source.skinWeights;
  8231. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  8232. this.skinWeights.push( skinWeights[ i ].clone() );
  8233. }
  8234. // skin indices
  8235. var skinIndices = source.skinIndices;
  8236. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  8237. this.skinIndices.push( skinIndices[ i ].clone() );
  8238. }
  8239. // line distances
  8240. var lineDistances = source.lineDistances;
  8241. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  8242. this.lineDistances.push( lineDistances[ i ] );
  8243. }
  8244. // bounding box
  8245. var boundingBox = source.boundingBox;
  8246. if ( boundingBox !== null ) {
  8247. this.boundingBox = boundingBox.clone();
  8248. }
  8249. // bounding sphere
  8250. var boundingSphere = source.boundingSphere;
  8251. if ( boundingSphere !== null ) {
  8252. this.boundingSphere = boundingSphere.clone();
  8253. }
  8254. // update flags
  8255. this.elementsNeedUpdate = source.elementsNeedUpdate;
  8256. this.verticesNeedUpdate = source.verticesNeedUpdate;
  8257. this.uvsNeedUpdate = source.uvsNeedUpdate;
  8258. this.normalsNeedUpdate = source.normalsNeedUpdate;
  8259. this.colorsNeedUpdate = source.colorsNeedUpdate;
  8260. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  8261. this.groupsNeedUpdate = source.groupsNeedUpdate;
  8262. return this;
  8263. },
  8264. dispose: function () {
  8265. this.dispatchEvent( { type: 'dispose' } );
  8266. }
  8267. } );
  8268. /**
  8269. * @author alteredq / http://alteredqualia.com/
  8270. * @author mrdoob / http://mrdoob.com/
  8271. */
  8272. function BufferGeometry() {
  8273. Object.defineProperty( this, 'id', { value: GeometryIdCount() } );
  8274. this.uuid = _Math.generateUUID();
  8275. this.name = '';
  8276. this.type = 'BufferGeometry';
  8277. this.index = null;
  8278. this.attributes = {};
  8279. this.morphAttributes = {};
  8280. this.groups = [];
  8281. this.boundingBox = null;
  8282. this.boundingSphere = null;
  8283. this.drawRange = { start: 0, count: Infinity };
  8284. }
  8285. BufferGeometry.MaxIndex = 65535;
  8286. Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
  8287. isBufferGeometry: true,
  8288. getIndex: function () {
  8289. return this.index;
  8290. },
  8291. setIndex: function ( index ) {
  8292. if ( Array.isArray( index ) ) {
  8293. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  8294. } else {
  8295. this.index = index;
  8296. }
  8297. },
  8298. addAttribute: function ( name, attribute ) {
  8299. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  8300. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  8301. this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  8302. return;
  8303. }
  8304. if ( name === 'index' ) {
  8305. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  8306. this.setIndex( attribute );
  8307. return;
  8308. }
  8309. this.attributes[ name ] = attribute;
  8310. return this;
  8311. },
  8312. getAttribute: function ( name ) {
  8313. return this.attributes[ name ];
  8314. },
  8315. removeAttribute: function ( name ) {
  8316. delete this.attributes[ name ];
  8317. return this;
  8318. },
  8319. addGroup: function ( start, count, materialIndex ) {
  8320. this.groups.push( {
  8321. start: start,
  8322. count: count,
  8323. materialIndex: materialIndex !== undefined ? materialIndex : 0
  8324. } );
  8325. },
  8326. clearGroups: function () {
  8327. this.groups = [];
  8328. },
  8329. setDrawRange: function ( start, count ) {
  8330. this.drawRange.start = start;
  8331. this.drawRange.count = count;
  8332. },
  8333. applyMatrix: function ( matrix ) {
  8334. var position = this.attributes.position;
  8335. if ( position !== undefined ) {
  8336. matrix.applyToBufferAttribute( position );
  8337. position.needsUpdate = true;
  8338. }
  8339. var normal = this.attributes.normal;
  8340. if ( normal !== undefined ) {
  8341. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  8342. normalMatrix.applyToBufferAttribute( normal );
  8343. normal.needsUpdate = true;
  8344. }
  8345. if ( this.boundingBox !== null ) {
  8346. this.computeBoundingBox();
  8347. }
  8348. if ( this.boundingSphere !== null ) {
  8349. this.computeBoundingSphere();
  8350. }
  8351. return this;
  8352. },
  8353. rotateX: function () {
  8354. // rotate geometry around world x-axis
  8355. var m1 = new Matrix4();
  8356. return function rotateX( angle ) {
  8357. m1.makeRotationX( angle );
  8358. this.applyMatrix( m1 );
  8359. return this;
  8360. };
  8361. }(),
  8362. rotateY: function () {
  8363. // rotate geometry around world y-axis
  8364. var m1 = new Matrix4();
  8365. return function rotateY( angle ) {
  8366. m1.makeRotationY( angle );
  8367. this.applyMatrix( m1 );
  8368. return this;
  8369. };
  8370. }(),
  8371. rotateZ: function () {
  8372. // rotate geometry around world z-axis
  8373. var m1 = new Matrix4();
  8374. return function rotateZ( angle ) {
  8375. m1.makeRotationZ( angle );
  8376. this.applyMatrix( m1 );
  8377. return this;
  8378. };
  8379. }(),
  8380. translate: function () {
  8381. // translate geometry
  8382. var m1 = new Matrix4();
  8383. return function translate( x, y, z ) {
  8384. m1.makeTranslation( x, y, z );
  8385. this.applyMatrix( m1 );
  8386. return this;
  8387. };
  8388. }(),
  8389. scale: function () {
  8390. // scale geometry
  8391. var m1 = new Matrix4();
  8392. return function scale( x, y, z ) {
  8393. m1.makeScale( x, y, z );
  8394. this.applyMatrix( m1 );
  8395. return this;
  8396. };
  8397. }(),
  8398. lookAt: function () {
  8399. var obj = new Object3D();
  8400. return function lookAt( vector ) {
  8401. obj.lookAt( vector );
  8402. obj.updateMatrix();
  8403. this.applyMatrix( obj.matrix );
  8404. };
  8405. }(),
  8406. center: function () {
  8407. this.computeBoundingBox();
  8408. var offset = this.boundingBox.getCenter().negate();
  8409. this.translate( offset.x, offset.y, offset.z );
  8410. return offset;
  8411. },
  8412. setFromObject: function ( object ) {
  8413. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  8414. var geometry = object.geometry;
  8415. if ( object.isPoints || object.isLine ) {
  8416. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  8417. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  8418. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  8419. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  8420. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  8421. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  8422. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  8423. }
  8424. if ( geometry.boundingSphere !== null ) {
  8425. this.boundingSphere = geometry.boundingSphere.clone();
  8426. }
  8427. if ( geometry.boundingBox !== null ) {
  8428. this.boundingBox = geometry.boundingBox.clone();
  8429. }
  8430. } else if ( object.isMesh ) {
  8431. if ( geometry && geometry.isGeometry ) {
  8432. this.fromGeometry( geometry );
  8433. }
  8434. }
  8435. return this;
  8436. },
  8437. updateFromObject: function ( object ) {
  8438. var geometry = object.geometry;
  8439. if ( object.isMesh ) {
  8440. var direct = geometry.__directGeometry;
  8441. if ( geometry.elementsNeedUpdate === true ) {
  8442. direct = undefined;
  8443. geometry.elementsNeedUpdate = false;
  8444. }
  8445. if ( direct === undefined ) {
  8446. return this.fromGeometry( geometry );
  8447. }
  8448. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8449. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8450. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8451. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8452. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8453. geometry.verticesNeedUpdate = false;
  8454. geometry.normalsNeedUpdate = false;
  8455. geometry.colorsNeedUpdate = false;
  8456. geometry.uvsNeedUpdate = false;
  8457. geometry.groupsNeedUpdate = false;
  8458. geometry = direct;
  8459. }
  8460. var attribute;
  8461. if ( geometry.verticesNeedUpdate === true ) {
  8462. attribute = this.attributes.position;
  8463. if ( attribute !== undefined ) {
  8464. attribute.copyVector3sArray( geometry.vertices );
  8465. attribute.needsUpdate = true;
  8466. }
  8467. geometry.verticesNeedUpdate = false;
  8468. }
  8469. if ( geometry.normalsNeedUpdate === true ) {
  8470. attribute = this.attributes.normal;
  8471. if ( attribute !== undefined ) {
  8472. attribute.copyVector3sArray( geometry.normals );
  8473. attribute.needsUpdate = true;
  8474. }
  8475. geometry.normalsNeedUpdate = false;
  8476. }
  8477. if ( geometry.colorsNeedUpdate === true ) {
  8478. attribute = this.attributes.color;
  8479. if ( attribute !== undefined ) {
  8480. attribute.copyColorsArray( geometry.colors );
  8481. attribute.needsUpdate = true;
  8482. }
  8483. geometry.colorsNeedUpdate = false;
  8484. }
  8485. if ( geometry.uvsNeedUpdate ) {
  8486. attribute = this.attributes.uv;
  8487. if ( attribute !== undefined ) {
  8488. attribute.copyVector2sArray( geometry.uvs );
  8489. attribute.needsUpdate = true;
  8490. }
  8491. geometry.uvsNeedUpdate = false;
  8492. }
  8493. if ( geometry.lineDistancesNeedUpdate ) {
  8494. attribute = this.attributes.lineDistance;
  8495. if ( attribute !== undefined ) {
  8496. attribute.copyArray( geometry.lineDistances );
  8497. attribute.needsUpdate = true;
  8498. }
  8499. geometry.lineDistancesNeedUpdate = false;
  8500. }
  8501. if ( geometry.groupsNeedUpdate ) {
  8502. geometry.computeGroups( object.geometry );
  8503. this.groups = geometry.groups;
  8504. geometry.groupsNeedUpdate = false;
  8505. }
  8506. return this;
  8507. },
  8508. fromGeometry: function ( geometry ) {
  8509. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  8510. return this.fromDirectGeometry( geometry.__directGeometry );
  8511. },
  8512. fromDirectGeometry: function ( geometry ) {
  8513. var positions = new Float32Array( geometry.vertices.length * 3 );
  8514. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  8515. if ( geometry.normals.length > 0 ) {
  8516. var normals = new Float32Array( geometry.normals.length * 3 );
  8517. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  8518. }
  8519. if ( geometry.colors.length > 0 ) {
  8520. var colors = new Float32Array( geometry.colors.length * 3 );
  8521. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  8522. }
  8523. if ( geometry.uvs.length > 0 ) {
  8524. var uvs = new Float32Array( geometry.uvs.length * 2 );
  8525. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  8526. }
  8527. if ( geometry.uvs2.length > 0 ) {
  8528. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  8529. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  8530. }
  8531. if ( geometry.indices.length > 0 ) {
  8532. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  8533. var indices = new TypeArray( geometry.indices.length * 3 );
  8534. this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  8535. }
  8536. // groups
  8537. this.groups = geometry.groups;
  8538. // morphs
  8539. for ( var name in geometry.morphTargets ) {
  8540. var array = [];
  8541. var morphTargets = geometry.morphTargets[ name ];
  8542. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  8543. var morphTarget = morphTargets[ i ];
  8544. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  8545. array.push( attribute.copyVector3sArray( morphTarget ) );
  8546. }
  8547. this.morphAttributes[ name ] = array;
  8548. }
  8549. // skinning
  8550. if ( geometry.skinIndices.length > 0 ) {
  8551. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  8552. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  8553. }
  8554. if ( geometry.skinWeights.length > 0 ) {
  8555. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  8556. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  8557. }
  8558. //
  8559. if ( geometry.boundingSphere !== null ) {
  8560. this.boundingSphere = geometry.boundingSphere.clone();
  8561. }
  8562. if ( geometry.boundingBox !== null ) {
  8563. this.boundingBox = geometry.boundingBox.clone();
  8564. }
  8565. return this;
  8566. },
  8567. computeBoundingBox: function () {
  8568. if ( this.boundingBox === null ) {
  8569. this.boundingBox = new Box3();
  8570. }
  8571. var position = this.attributes.position;
  8572. if ( position !== undefined ) {
  8573. this.boundingBox.setFromBufferAttribute( position );
  8574. } else {
  8575. this.boundingBox.makeEmpty();
  8576. }
  8577. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  8578. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  8579. }
  8580. },
  8581. computeBoundingSphere: function () {
  8582. var box = new Box3();
  8583. var vector = new Vector3();
  8584. return function computeBoundingSphere() {
  8585. if ( this.boundingSphere === null ) {
  8586. this.boundingSphere = new Sphere();
  8587. }
  8588. var position = this.attributes.position;
  8589. if ( position ) {
  8590. var center = this.boundingSphere.center;
  8591. box.setFromBufferAttribute( position );
  8592. box.getCenter( center );
  8593. // hoping to find a boundingSphere with a radius smaller than the
  8594. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  8595. var maxRadiusSq = 0;
  8596. for ( var i = 0, il = position.count; i < il; i ++ ) {
  8597. vector.x = position.getX( i );
  8598. vector.y = position.getY( i );
  8599. vector.z = position.getZ( i );
  8600. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  8601. }
  8602. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  8603. if ( isNaN( this.boundingSphere.radius ) ) {
  8604. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  8605. }
  8606. }
  8607. };
  8608. }(),
  8609. computeFaceNormals: function () {
  8610. // backwards compatibility
  8611. },
  8612. computeVertexNormals: function () {
  8613. var index = this.index;
  8614. var attributes = this.attributes;
  8615. var groups = this.groups;
  8616. if ( attributes.position ) {
  8617. var positions = attributes.position.array;
  8618. if ( attributes.normal === undefined ) {
  8619. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  8620. } else {
  8621. // reset existing normals to zero
  8622. var array = attributes.normal.array;
  8623. for ( var i = 0, il = array.length; i < il; i ++ ) {
  8624. array[ i ] = 0;
  8625. }
  8626. }
  8627. var normals = attributes.normal.array;
  8628. var vA, vB, vC;
  8629. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  8630. var cb = new Vector3(), ab = new Vector3();
  8631. // indexed elements
  8632. if ( index ) {
  8633. var indices = index.array;
  8634. if ( groups.length === 0 ) {
  8635. this.addGroup( 0, indices.length );
  8636. }
  8637. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  8638. var group = groups[ j ];
  8639. var start = group.start;
  8640. var count = group.count;
  8641. for ( var i = start, il = start + count; i < il; i += 3 ) {
  8642. vA = indices[ i + 0 ] * 3;
  8643. vB = indices[ i + 1 ] * 3;
  8644. vC = indices[ i + 2 ] * 3;
  8645. pA.fromArray( positions, vA );
  8646. pB.fromArray( positions, vB );
  8647. pC.fromArray( positions, vC );
  8648. cb.subVectors( pC, pB );
  8649. ab.subVectors( pA, pB );
  8650. cb.cross( ab );
  8651. normals[ vA ] += cb.x;
  8652. normals[ vA + 1 ] += cb.y;
  8653. normals[ vA + 2 ] += cb.z;
  8654. normals[ vB ] += cb.x;
  8655. normals[ vB + 1 ] += cb.y;
  8656. normals[ vB + 2 ] += cb.z;
  8657. normals[ vC ] += cb.x;
  8658. normals[ vC + 1 ] += cb.y;
  8659. normals[ vC + 2 ] += cb.z;
  8660. }
  8661. }
  8662. } else {
  8663. // non-indexed elements (unconnected triangle soup)
  8664. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  8665. pA.fromArray( positions, i );
  8666. pB.fromArray( positions, i + 3 );
  8667. pC.fromArray( positions, i + 6 );
  8668. cb.subVectors( pC, pB );
  8669. ab.subVectors( pA, pB );
  8670. cb.cross( ab );
  8671. normals[ i ] = cb.x;
  8672. normals[ i + 1 ] = cb.y;
  8673. normals[ i + 2 ] = cb.z;
  8674. normals[ i + 3 ] = cb.x;
  8675. normals[ i + 4 ] = cb.y;
  8676. normals[ i + 5 ] = cb.z;
  8677. normals[ i + 6 ] = cb.x;
  8678. normals[ i + 7 ] = cb.y;
  8679. normals[ i + 8 ] = cb.z;
  8680. }
  8681. }
  8682. this.normalizeNormals();
  8683. attributes.normal.needsUpdate = true;
  8684. }
  8685. },
  8686. merge: function ( geometry, offset ) {
  8687. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  8688. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  8689. return;
  8690. }
  8691. if ( offset === undefined ) offset = 0;
  8692. var attributes = this.attributes;
  8693. for ( var key in attributes ) {
  8694. if ( geometry.attributes[ key ] === undefined ) continue;
  8695. var attribute1 = attributes[ key ];
  8696. var attributeArray1 = attribute1.array;
  8697. var attribute2 = geometry.attributes[ key ];
  8698. var attributeArray2 = attribute2.array;
  8699. var attributeSize = attribute2.itemSize;
  8700. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  8701. attributeArray1[ j ] = attributeArray2[ i ];
  8702. }
  8703. }
  8704. return this;
  8705. },
  8706. normalizeNormals: function () {
  8707. var normals = this.attributes.normal;
  8708. var x, y, z, n;
  8709. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  8710. x = normals.getX( i );
  8711. y = normals.getY( i );
  8712. z = normals.getZ( i );
  8713. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  8714. normals.setXYZ( i, x * n, y * n, z * n );
  8715. }
  8716. },
  8717. toNonIndexed: function () {
  8718. if ( this.index === null ) {
  8719. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  8720. return this;
  8721. }
  8722. var geometry2 = new BufferGeometry();
  8723. var indices = this.index.array;
  8724. var attributes = this.attributes;
  8725. for ( var name in attributes ) {
  8726. var attribute = attributes[ name ];
  8727. var array = attribute.array;
  8728. var itemSize = attribute.itemSize;
  8729. var array2 = new array.constructor( indices.length * itemSize );
  8730. var index = 0, index2 = 0;
  8731. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8732. index = indices[ i ] * itemSize;
  8733. for ( var j = 0; j < itemSize; j ++ ) {
  8734. array2[ index2 ++ ] = array[ index ++ ];
  8735. }
  8736. }
  8737. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  8738. }
  8739. return geometry2;
  8740. },
  8741. toJSON: function () {
  8742. var data = {
  8743. metadata: {
  8744. version: 4.5,
  8745. type: 'BufferGeometry',
  8746. generator: 'BufferGeometry.toJSON'
  8747. }
  8748. };
  8749. // standard BufferGeometry serialization
  8750. data.uuid = this.uuid;
  8751. data.type = this.type;
  8752. if ( this.name !== '' ) data.name = this.name;
  8753. if ( this.parameters !== undefined ) {
  8754. var parameters = this.parameters;
  8755. for ( var key in parameters ) {
  8756. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8757. }
  8758. return data;
  8759. }
  8760. data.data = { attributes: {} };
  8761. var index = this.index;
  8762. if ( index !== null ) {
  8763. var array = Array.prototype.slice.call( index.array );
  8764. data.data.index = {
  8765. type: index.array.constructor.name,
  8766. array: array
  8767. };
  8768. }
  8769. var attributes = this.attributes;
  8770. for ( var key in attributes ) {
  8771. var attribute = attributes[ key ];
  8772. var array = Array.prototype.slice.call( attribute.array );
  8773. data.data.attributes[ key ] = {
  8774. itemSize: attribute.itemSize,
  8775. type: attribute.array.constructor.name,
  8776. array: array,
  8777. normalized: attribute.normalized
  8778. };
  8779. }
  8780. var groups = this.groups;
  8781. if ( groups.length > 0 ) {
  8782. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  8783. }
  8784. var boundingSphere = this.boundingSphere;
  8785. if ( boundingSphere !== null ) {
  8786. data.data.boundingSphere = {
  8787. center: boundingSphere.center.toArray(),
  8788. radius: boundingSphere.radius
  8789. };
  8790. }
  8791. return data;
  8792. },
  8793. clone: function () {
  8794. /*
  8795. // Handle primitives
  8796. var parameters = this.parameters;
  8797. if ( parameters !== undefined ) {
  8798. var values = [];
  8799. for ( var key in parameters ) {
  8800. values.push( parameters[ key ] );
  8801. }
  8802. var geometry = Object.create( this.constructor.prototype );
  8803. this.constructor.apply( geometry, values );
  8804. return geometry;
  8805. }
  8806. return new this.constructor().copy( this );
  8807. */
  8808. return new BufferGeometry().copy( this );
  8809. },
  8810. copy: function ( source ) {
  8811. var name, i, l;
  8812. // reset
  8813. this.index = null;
  8814. this.attributes = {};
  8815. this.morphAttributes = {};
  8816. this.groups = [];
  8817. this.boundingBox = null;
  8818. this.boundingSphere = null;
  8819. // name
  8820. this.name = source.name;
  8821. // index
  8822. var index = source.index;
  8823. if ( index !== null ) {
  8824. this.setIndex( index.clone() );
  8825. }
  8826. // attributes
  8827. var attributes = source.attributes;
  8828. for ( name in attributes ) {
  8829. var attribute = attributes[ name ];
  8830. this.addAttribute( name, attribute.clone() );
  8831. }
  8832. // morph attributes
  8833. var morphAttributes = source.morphAttributes;
  8834. for ( name in morphAttributes ) {
  8835. var array = [];
  8836. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  8837. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  8838. array.push( morphAttribute[ i ].clone() );
  8839. }
  8840. this.morphAttributes[ name ] = array;
  8841. }
  8842. // groups
  8843. var groups = source.groups;
  8844. for ( i = 0, l = groups.length; i < l; i ++ ) {
  8845. var group = groups[ i ];
  8846. this.addGroup( group.start, group.count, group.materialIndex );
  8847. }
  8848. // bounding box
  8849. var boundingBox = source.boundingBox;
  8850. if ( boundingBox !== null ) {
  8851. this.boundingBox = boundingBox.clone();
  8852. }
  8853. // bounding sphere
  8854. var boundingSphere = source.boundingSphere;
  8855. if ( boundingSphere !== null ) {
  8856. this.boundingSphere = boundingSphere.clone();
  8857. }
  8858. // draw range
  8859. this.drawRange.start = source.drawRange.start;
  8860. this.drawRange.count = source.drawRange.count;
  8861. return this;
  8862. },
  8863. dispose: function () {
  8864. this.dispatchEvent( { type: 'dispose' } );
  8865. }
  8866. } );
  8867. /**
  8868. * @author mrdoob / http://mrdoob.com/
  8869. * @author alteredq / http://alteredqualia.com/
  8870. * @author mikael emtinger / http://gomo.se/
  8871. * @author jonobr1 / http://jonobr1.com/
  8872. */
  8873. function Mesh( geometry, material ) {
  8874. Object3D.call( this );
  8875. this.type = 'Mesh';
  8876. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8877. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8878. this.drawMode = TrianglesDrawMode;
  8879. this.updateMorphTargets();
  8880. }
  8881. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8882. constructor: Mesh,
  8883. isMesh: true,
  8884. setDrawMode: function ( value ) {
  8885. this.drawMode = value;
  8886. },
  8887. copy: function ( source ) {
  8888. Object3D.prototype.copy.call( this, source );
  8889. this.drawMode = source.drawMode;
  8890. return this;
  8891. },
  8892. updateMorphTargets: function () {
  8893. var geometry = this.geometry;
  8894. var m, ml, name;
  8895. if ( geometry.isBufferGeometry ) {
  8896. var morphAttributes = geometry.morphAttributes;
  8897. var keys = Object.keys( morphAttributes );
  8898. if ( keys.length > 0 ) {
  8899. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8900. if ( morphAttribute !== undefined ) {
  8901. this.morphTargetInfluences = [];
  8902. this.morphTargetDictionary = {};
  8903. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8904. name = morphAttribute[ m ].name || String( m );
  8905. this.morphTargetInfluences.push( 0 );
  8906. this.morphTargetDictionary[ name ] = m;
  8907. }
  8908. }
  8909. }
  8910. } else {
  8911. var morphTargets = geometry.morphTargets;
  8912. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8913. this.morphTargetInfluences = [];
  8914. this.morphTargetDictionary = {};
  8915. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  8916. name = morphTargets[ m ].name || String( m );
  8917. this.morphTargetInfluences.push( 0 );
  8918. this.morphTargetDictionary[ name ] = m;
  8919. }
  8920. }
  8921. }
  8922. },
  8923. raycast: ( function () {
  8924. var inverseMatrix = new Matrix4();
  8925. var ray = new Ray();
  8926. var sphere = new Sphere();
  8927. var vA = new Vector3();
  8928. var vB = new Vector3();
  8929. var vC = new Vector3();
  8930. var tempA = new Vector3();
  8931. var tempB = new Vector3();
  8932. var tempC = new Vector3();
  8933. var uvA = new Vector2();
  8934. var uvB = new Vector2();
  8935. var uvC = new Vector2();
  8936. var barycoord = new Vector3();
  8937. var intersectionPoint = new Vector3();
  8938. var intersectionPointWorld = new Vector3();
  8939. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  8940. Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  8941. uv1.multiplyScalar( barycoord.x );
  8942. uv2.multiplyScalar( barycoord.y );
  8943. uv3.multiplyScalar( barycoord.z );
  8944. uv1.add( uv2 ).add( uv3 );
  8945. return uv1.clone();
  8946. }
  8947. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  8948. var intersect;
  8949. var material = object.material;
  8950. if ( material.side === BackSide ) {
  8951. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8952. } else {
  8953. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8954. }
  8955. if ( intersect === null ) return null;
  8956. intersectionPointWorld.copy( point );
  8957. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8958. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8959. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8960. return {
  8961. distance: distance,
  8962. point: intersectionPointWorld.clone(),
  8963. object: object
  8964. };
  8965. }
  8966. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  8967. vA.fromBufferAttribute( position, a );
  8968. vB.fromBufferAttribute( position, b );
  8969. vC.fromBufferAttribute( position, c );
  8970. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  8971. if ( intersection ) {
  8972. if ( uv ) {
  8973. uvA.fromBufferAttribute( uv, a );
  8974. uvB.fromBufferAttribute( uv, b );
  8975. uvC.fromBufferAttribute( uv, c );
  8976. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  8977. }
  8978. intersection.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) );
  8979. intersection.faceIndex = a;
  8980. }
  8981. return intersection;
  8982. }
  8983. return function raycast( raycaster, intersects ) {
  8984. var geometry = this.geometry;
  8985. var material = this.material;
  8986. var matrixWorld = this.matrixWorld;
  8987. if ( material === undefined ) return;
  8988. // Checking boundingSphere distance to ray
  8989. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8990. sphere.copy( geometry.boundingSphere );
  8991. sphere.applyMatrix4( matrixWorld );
  8992. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8993. //
  8994. inverseMatrix.getInverse( matrixWorld );
  8995. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8996. // Check boundingBox before continuing
  8997. if ( geometry.boundingBox !== null ) {
  8998. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8999. }
  9000. var intersection;
  9001. if ( geometry.isBufferGeometry ) {
  9002. var a, b, c;
  9003. var index = geometry.index;
  9004. var position = geometry.attributes.position;
  9005. var uv = geometry.attributes.uv;
  9006. var i, l;
  9007. if ( index !== null ) {
  9008. // indexed buffer geometry
  9009. for ( i = 0, l = index.count; i < l; i += 3 ) {
  9010. a = index.getX( i );
  9011. b = index.getX( i + 1 );
  9012. c = index.getX( i + 2 );
  9013. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9014. if ( intersection ) {
  9015. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  9016. intersects.push( intersection );
  9017. }
  9018. }
  9019. } else {
  9020. // non-indexed buffer geometry
  9021. for ( i = 0, l = position.count; i < l; i += 3 ) {
  9022. a = i;
  9023. b = i + 1;
  9024. c = i + 2;
  9025. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9026. if ( intersection ) {
  9027. intersection.index = a; // triangle number in positions buffer semantics
  9028. intersects.push( intersection );
  9029. }
  9030. }
  9031. }
  9032. } else if ( geometry.isGeometry ) {
  9033. var fvA, fvB, fvC;
  9034. var isMultiMaterial = Array.isArray( material );
  9035. var vertices = geometry.vertices;
  9036. var faces = geometry.faces;
  9037. var uvs;
  9038. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  9039. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  9040. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  9041. var face = faces[ f ];
  9042. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  9043. if ( faceMaterial === undefined ) continue;
  9044. fvA = vertices[ face.a ];
  9045. fvB = vertices[ face.b ];
  9046. fvC = vertices[ face.c ];
  9047. if ( faceMaterial.morphTargets === true ) {
  9048. var morphTargets = geometry.morphTargets;
  9049. var morphInfluences = this.morphTargetInfluences;
  9050. vA.set( 0, 0, 0 );
  9051. vB.set( 0, 0, 0 );
  9052. vC.set( 0, 0, 0 );
  9053. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  9054. var influence = morphInfluences[ t ];
  9055. if ( influence === 0 ) continue;
  9056. var targets = morphTargets[ t ].vertices;
  9057. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  9058. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  9059. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  9060. }
  9061. vA.add( fvA );
  9062. vB.add( fvB );
  9063. vC.add( fvC );
  9064. fvA = vA;
  9065. fvB = vB;
  9066. fvC = vC;
  9067. }
  9068. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  9069. if ( intersection ) {
  9070. if ( uvs && uvs[ f ] ) {
  9071. var uvs_f = uvs[ f ];
  9072. uvA.copy( uvs_f[ 0 ] );
  9073. uvB.copy( uvs_f[ 1 ] );
  9074. uvC.copy( uvs_f[ 2 ] );
  9075. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  9076. }
  9077. intersection.face = face;
  9078. intersection.faceIndex = f;
  9079. intersects.push( intersection );
  9080. }
  9081. }
  9082. }
  9083. };
  9084. }() ),
  9085. clone: function () {
  9086. return new this.constructor( this.geometry, this.material ).copy( this );
  9087. }
  9088. } );
  9089. /**
  9090. * @author mrdoob / http://mrdoob.com/
  9091. * @author Mugen87 / https://github.com/Mugen87
  9092. */
  9093. // BoxGeometry
  9094. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9095. Geometry.call( this );
  9096. this.type = 'BoxGeometry';
  9097. this.parameters = {
  9098. width: width,
  9099. height: height,
  9100. depth: depth,
  9101. widthSegments: widthSegments,
  9102. heightSegments: heightSegments,
  9103. depthSegments: depthSegments
  9104. };
  9105. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  9106. this.mergeVertices();
  9107. }
  9108. BoxGeometry.prototype = Object.create( Geometry.prototype );
  9109. BoxGeometry.prototype.constructor = BoxGeometry;
  9110. // BoxBufferGeometry
  9111. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9112. BufferGeometry.call( this );
  9113. this.type = 'BoxBufferGeometry';
  9114. this.parameters = {
  9115. width: width,
  9116. height: height,
  9117. depth: depth,
  9118. widthSegments: widthSegments,
  9119. heightSegments: heightSegments,
  9120. depthSegments: depthSegments
  9121. };
  9122. var scope = this;
  9123. // segments
  9124. widthSegments = Math.floor( widthSegments ) || 1;
  9125. heightSegments = Math.floor( heightSegments ) || 1;
  9126. depthSegments = Math.floor( depthSegments ) || 1;
  9127. // buffers
  9128. var indices = [];
  9129. var vertices = [];
  9130. var normals = [];
  9131. var uvs = [];
  9132. // helper variables
  9133. var numberOfVertices = 0;
  9134. var groupStart = 0;
  9135. // build each side of the box geometry
  9136. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  9137. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  9138. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  9139. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  9140. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  9141. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  9142. // build geometry
  9143. this.setIndex( indices );
  9144. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9145. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9146. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9147. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  9148. var segmentWidth = width / gridX;
  9149. var segmentHeight = height / gridY;
  9150. var widthHalf = width / 2;
  9151. var heightHalf = height / 2;
  9152. var depthHalf = depth / 2;
  9153. var gridX1 = gridX + 1;
  9154. var gridY1 = gridY + 1;
  9155. var vertexCounter = 0;
  9156. var groupCount = 0;
  9157. var ix, iy;
  9158. var vector = new Vector3();
  9159. // generate vertices, normals and uvs
  9160. for ( iy = 0; iy < gridY1; iy ++ ) {
  9161. var y = iy * segmentHeight - heightHalf;
  9162. for ( ix = 0; ix < gridX1; ix ++ ) {
  9163. var x = ix * segmentWidth - widthHalf;
  9164. // set values to correct vector component
  9165. vector[ u ] = x * udir;
  9166. vector[ v ] = y * vdir;
  9167. vector[ w ] = depthHalf;
  9168. // now apply vector to vertex buffer
  9169. vertices.push( vector.x, vector.y, vector.z );
  9170. // set values to correct vector component
  9171. vector[ u ] = 0;
  9172. vector[ v ] = 0;
  9173. vector[ w ] = depth > 0 ? 1 : - 1;
  9174. // now apply vector to normal buffer
  9175. normals.push( vector.x, vector.y, vector.z );
  9176. // uvs
  9177. uvs.push( ix / gridX );
  9178. uvs.push( 1 - ( iy / gridY ) );
  9179. // counters
  9180. vertexCounter += 1;
  9181. }
  9182. }
  9183. // indices
  9184. // 1. you need three indices to draw a single face
  9185. // 2. a single segment consists of two faces
  9186. // 3. so we need to generate six (2*3) indices per segment
  9187. for ( iy = 0; iy < gridY; iy ++ ) {
  9188. for ( ix = 0; ix < gridX; ix ++ ) {
  9189. var a = numberOfVertices + ix + gridX1 * iy;
  9190. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  9191. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  9192. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  9193. // faces
  9194. indices.push( a, b, d );
  9195. indices.push( b, c, d );
  9196. // increase counter
  9197. groupCount += 6;
  9198. }
  9199. }
  9200. // add a group to the geometry. this will ensure multi material support
  9201. scope.addGroup( groupStart, groupCount, materialIndex );
  9202. // calculate new start value for groups
  9203. groupStart += groupCount;
  9204. // update total number of vertices
  9205. numberOfVertices += vertexCounter;
  9206. }
  9207. }
  9208. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9209. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  9210. /**
  9211. * @author mrdoob / http://mrdoob.com/
  9212. * @author Mugen87 / https://github.com/Mugen87
  9213. */
  9214. // PlaneGeometry
  9215. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  9216. Geometry.call( this );
  9217. this.type = 'PlaneGeometry';
  9218. this.parameters = {
  9219. width: width,
  9220. height: height,
  9221. widthSegments: widthSegments,
  9222. heightSegments: heightSegments
  9223. };
  9224. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  9225. this.mergeVertices();
  9226. }
  9227. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  9228. PlaneGeometry.prototype.constructor = PlaneGeometry;
  9229. // PlaneBufferGeometry
  9230. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  9231. BufferGeometry.call( this );
  9232. this.type = 'PlaneBufferGeometry';
  9233. this.parameters = {
  9234. width: width,
  9235. height: height,
  9236. widthSegments: widthSegments,
  9237. heightSegments: heightSegments
  9238. };
  9239. var width_half = width / 2;
  9240. var height_half = height / 2;
  9241. var gridX = Math.floor( widthSegments ) || 1;
  9242. var gridY = Math.floor( heightSegments ) || 1;
  9243. var gridX1 = gridX + 1;
  9244. var gridY1 = gridY + 1;
  9245. var segment_width = width / gridX;
  9246. var segment_height = height / gridY;
  9247. var ix, iy;
  9248. // buffers
  9249. var indices = [];
  9250. var vertices = [];
  9251. var normals = [];
  9252. var uvs = [];
  9253. // generate vertices, normals and uvs
  9254. for ( iy = 0; iy < gridY1; iy ++ ) {
  9255. var y = iy * segment_height - height_half;
  9256. for ( ix = 0; ix < gridX1; ix ++ ) {
  9257. var x = ix * segment_width - width_half;
  9258. vertices.push( x, - y, 0 );
  9259. normals.push( 0, 0, 1 );
  9260. uvs.push( ix / gridX );
  9261. uvs.push( 1 - ( iy / gridY ) );
  9262. }
  9263. }
  9264. // indices
  9265. for ( iy = 0; iy < gridY; iy ++ ) {
  9266. for ( ix = 0; ix < gridX; ix ++ ) {
  9267. var a = ix + gridX1 * iy;
  9268. var b = ix + gridX1 * ( iy + 1 );
  9269. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  9270. var d = ( ix + 1 ) + gridX1 * iy;
  9271. // faces
  9272. indices.push( a, b, d );
  9273. indices.push( b, c, d );
  9274. }
  9275. }
  9276. // build geometry
  9277. this.setIndex( indices );
  9278. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9279. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9280. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9281. }
  9282. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9283. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  9284. /**
  9285. * @author mrdoob / http://mrdoob.com/
  9286. * @author mikael emtinger / http://gomo.se/
  9287. * @author WestLangley / http://github.com/WestLangley
  9288. */
  9289. function Camera() {
  9290. Object3D.call( this );
  9291. this.type = 'Camera';
  9292. this.matrixWorldInverse = new Matrix4();
  9293. this.projectionMatrix = new Matrix4();
  9294. }
  9295. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  9296. constructor: Camera,
  9297. isCamera: true,
  9298. copy: function ( source, recursive ) {
  9299. Object3D.prototype.copy.call( this, source, recursive );
  9300. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9301. this.projectionMatrix.copy( source.projectionMatrix );
  9302. return this;
  9303. },
  9304. getWorldDirection: function () {
  9305. var quaternion = new Quaternion();
  9306. return function getWorldDirection( optionalTarget ) {
  9307. var result = optionalTarget || new Vector3();
  9308. this.getWorldQuaternion( quaternion );
  9309. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9310. };
  9311. }(),
  9312. updateMatrixWorld: function ( force ) {
  9313. Object3D.prototype.updateMatrixWorld.call( this, force );
  9314. this.matrixWorldInverse.getInverse( this.matrixWorld );
  9315. },
  9316. clone: function () {
  9317. return new this.constructor().copy( this );
  9318. }
  9319. } );
  9320. /**
  9321. * @author mrdoob / http://mrdoob.com/
  9322. * @author greggman / http://games.greggman.com/
  9323. * @author zz85 / http://www.lab4games.net/zz85/blog
  9324. * @author tschw
  9325. */
  9326. function PerspectiveCamera( fov, aspect, near, far ) {
  9327. Camera.call( this );
  9328. this.type = 'PerspectiveCamera';
  9329. this.fov = fov !== undefined ? fov : 50;
  9330. this.zoom = 1;
  9331. this.near = near !== undefined ? near : 0.1;
  9332. this.far = far !== undefined ? far : 2000;
  9333. this.focus = 10;
  9334. this.aspect = aspect !== undefined ? aspect : 1;
  9335. this.view = null;
  9336. this.filmGauge = 35; // width of the film (default in millimeters)
  9337. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  9338. this.updateProjectionMatrix();
  9339. }
  9340. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  9341. constructor: PerspectiveCamera,
  9342. isPerspectiveCamera: true,
  9343. copy: function ( source, recursive ) {
  9344. Camera.prototype.copy.call( this, source, recursive );
  9345. this.fov = source.fov;
  9346. this.zoom = source.zoom;
  9347. this.near = source.near;
  9348. this.far = source.far;
  9349. this.focus = source.focus;
  9350. this.aspect = source.aspect;
  9351. this.view = source.view === null ? null : Object.assign( {}, source.view );
  9352. this.filmGauge = source.filmGauge;
  9353. this.filmOffset = source.filmOffset;
  9354. return this;
  9355. },
  9356. /**
  9357. * Sets the FOV by focal length in respect to the current .filmGauge.
  9358. *
  9359. * The default film gauge is 35, so that the focal length can be specified for
  9360. * a 35mm (full frame) camera.
  9361. *
  9362. * Values for focal length and film gauge must have the same unit.
  9363. */
  9364. setFocalLength: function ( focalLength ) {
  9365. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  9366. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  9367. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  9368. this.updateProjectionMatrix();
  9369. },
  9370. /**
  9371. * Calculates the focal length from the current .fov and .filmGauge.
  9372. */
  9373. getFocalLength: function () {
  9374. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  9375. return 0.5 * this.getFilmHeight() / vExtentSlope;
  9376. },
  9377. getEffectiveFOV: function () {
  9378. return _Math.RAD2DEG * 2 * Math.atan(
  9379. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  9380. },
  9381. getFilmWidth: function () {
  9382. // film not completely covered in portrait format (aspect < 1)
  9383. return this.filmGauge * Math.min( this.aspect, 1 );
  9384. },
  9385. getFilmHeight: function () {
  9386. // film not completely covered in landscape format (aspect > 1)
  9387. return this.filmGauge / Math.max( this.aspect, 1 );
  9388. },
  9389. /**
  9390. * Sets an offset in a larger frustum. This is useful for multi-window or
  9391. * multi-monitor/multi-machine setups.
  9392. *
  9393. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9394. * the monitors are in grid like this
  9395. *
  9396. * +---+---+---+
  9397. * | A | B | C |
  9398. * +---+---+---+
  9399. * | D | E | F |
  9400. * +---+---+---+
  9401. *
  9402. * then for each monitor you would call it like this
  9403. *
  9404. * var w = 1920;
  9405. * var h = 1080;
  9406. * var fullWidth = w * 3;
  9407. * var fullHeight = h * 2;
  9408. *
  9409. * --A--
  9410. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9411. * --B--
  9412. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  9413. * --C--
  9414. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  9415. * --D--
  9416. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  9417. * --E--
  9418. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  9419. * --F--
  9420. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  9421. *
  9422. * Note there is no reason monitors have to be the same size or in a grid.
  9423. */
  9424. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  9425. this.aspect = fullWidth / fullHeight;
  9426. this.view = {
  9427. fullWidth: fullWidth,
  9428. fullHeight: fullHeight,
  9429. offsetX: x,
  9430. offsetY: y,
  9431. width: width,
  9432. height: height
  9433. };
  9434. this.updateProjectionMatrix();
  9435. },
  9436. clearViewOffset: function () {
  9437. this.view = null;
  9438. this.updateProjectionMatrix();
  9439. },
  9440. updateProjectionMatrix: function () {
  9441. var near = this.near,
  9442. top = near * Math.tan(
  9443. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  9444. height = 2 * top,
  9445. width = this.aspect * height,
  9446. left = - 0.5 * width,
  9447. view = this.view;
  9448. if ( view !== null ) {
  9449. var fullWidth = view.fullWidth,
  9450. fullHeight = view.fullHeight;
  9451. left += view.offsetX * width / fullWidth;
  9452. top -= view.offsetY * height / fullHeight;
  9453. width *= view.width / fullWidth;
  9454. height *= view.height / fullHeight;
  9455. }
  9456. var skew = this.filmOffset;
  9457. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  9458. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  9459. },
  9460. toJSON: function ( meta ) {
  9461. var data = Object3D.prototype.toJSON.call( this, meta );
  9462. data.object.fov = this.fov;
  9463. data.object.zoom = this.zoom;
  9464. data.object.near = this.near;
  9465. data.object.far = this.far;
  9466. data.object.focus = this.focus;
  9467. data.object.aspect = this.aspect;
  9468. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  9469. data.object.filmGauge = this.filmGauge;
  9470. data.object.filmOffset = this.filmOffset;
  9471. return data;
  9472. }
  9473. } );
  9474. /**
  9475. * @author alteredq / http://alteredqualia.com/
  9476. * @author arose / http://github.com/arose
  9477. */
  9478. function OrthographicCamera( left, right, top, bottom, near, far ) {
  9479. Camera.call( this );
  9480. this.type = 'OrthographicCamera';
  9481. this.zoom = 1;
  9482. this.view = null;
  9483. this.left = left;
  9484. this.right = right;
  9485. this.top = top;
  9486. this.bottom = bottom;
  9487. this.near = ( near !== undefined ) ? near : 0.1;
  9488. this.far = ( far !== undefined ) ? far : 2000;
  9489. this.updateProjectionMatrix();
  9490. }
  9491. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  9492. constructor: OrthographicCamera,
  9493. isOrthographicCamera: true,
  9494. copy: function ( source, recursive ) {
  9495. Camera.prototype.copy.call( this, source, recursive );
  9496. this.left = source.left;
  9497. this.right = source.right;
  9498. this.top = source.top;
  9499. this.bottom = source.bottom;
  9500. this.near = source.near;
  9501. this.far = source.far;
  9502. this.zoom = source.zoom;
  9503. this.view = source.view === null ? null : Object.assign( {}, source.view );
  9504. return this;
  9505. },
  9506. setViewOffset: function( fullWidth, fullHeight, x, y, width, height ) {
  9507. this.view = {
  9508. fullWidth: fullWidth,
  9509. fullHeight: fullHeight,
  9510. offsetX: x,
  9511. offsetY: y,
  9512. width: width,
  9513. height: height
  9514. };
  9515. this.updateProjectionMatrix();
  9516. },
  9517. clearViewOffset: function() {
  9518. this.view = null;
  9519. this.updateProjectionMatrix();
  9520. },
  9521. updateProjectionMatrix: function () {
  9522. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9523. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9524. var cx = ( this.right + this.left ) / 2;
  9525. var cy = ( this.top + this.bottom ) / 2;
  9526. var left = cx - dx;
  9527. var right = cx + dx;
  9528. var top = cy + dy;
  9529. var bottom = cy - dy;
  9530. if ( this.view !== null ) {
  9531. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  9532. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  9533. var scaleW = ( this.right - this.left ) / this.view.width;
  9534. var scaleH = ( this.top - this.bottom ) / this.view.height;
  9535. left += scaleW * ( this.view.offsetX / zoomW );
  9536. right = left + scaleW * ( this.view.width / zoomW );
  9537. top -= scaleH * ( this.view.offsetY / zoomH );
  9538. bottom = top - scaleH * ( this.view.height / zoomH );
  9539. }
  9540. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  9541. },
  9542. toJSON: function ( meta ) {
  9543. var data = Object3D.prototype.toJSON.call( this, meta );
  9544. data.object.zoom = this.zoom;
  9545. data.object.left = this.left;
  9546. data.object.right = this.right;
  9547. data.object.top = this.top;
  9548. data.object.bottom = this.bottom;
  9549. data.object.near = this.near;
  9550. data.object.far = this.far;
  9551. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  9552. return data;
  9553. }
  9554. } );
  9555. /**
  9556. * @author mrdoob / http://mrdoob.com/
  9557. */
  9558. function WebGLAttributes( gl ) {
  9559. var buffers = {};
  9560. function createBuffer( attribute, bufferType ) {
  9561. var array = attribute.array;
  9562. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  9563. var buffer = gl.createBuffer();
  9564. gl.bindBuffer( bufferType, buffer );
  9565. gl.bufferData( bufferType, array, usage );
  9566. attribute.onUploadCallback();
  9567. var type = gl.FLOAT;
  9568. if ( array instanceof Float32Array ) {
  9569. type = gl.FLOAT;
  9570. } else if ( array instanceof Float64Array ) {
  9571. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  9572. } else if ( array instanceof Uint16Array ) {
  9573. type = gl.UNSIGNED_SHORT;
  9574. } else if ( array instanceof Int16Array ) {
  9575. type = gl.SHORT;
  9576. } else if ( array instanceof Uint32Array ) {
  9577. type = gl.UNSIGNED_INT;
  9578. } else if ( array instanceof Int32Array ) {
  9579. type = gl.INT;
  9580. } else if ( array instanceof Int8Array ) {
  9581. type = gl.BYTE;
  9582. } else if ( array instanceof Uint8Array ) {
  9583. type = gl.UNSIGNED_BYTE;
  9584. }
  9585. return {
  9586. buffer: buffer,
  9587. type: type,
  9588. bytesPerElement: array.BYTES_PER_ELEMENT,
  9589. version: attribute.version
  9590. };
  9591. }
  9592. function updateBuffer( buffer, attribute, bufferType ) {
  9593. var array = attribute.array;
  9594. var updateRange = attribute.updateRange;
  9595. gl.bindBuffer( bufferType, buffer );
  9596. if ( attribute.dynamic === false ) {
  9597. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  9598. } else if ( updateRange.count === - 1 ) {
  9599. // Not using update ranges
  9600. gl.bufferSubData( bufferType, 0, array );
  9601. } else if ( updateRange.count === 0 ) {
  9602. 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.' );
  9603. } else {
  9604. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9605. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9606. updateRange.count = 0; // reset range
  9607. }
  9608. }
  9609. //
  9610. function get( attribute ) {
  9611. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9612. return buffers[ attribute.uuid ];
  9613. }
  9614. function remove( attribute ) {
  9615. var data = buffers[ attribute.uuid ];
  9616. if ( data ) {
  9617. gl.deleteBuffer( data.buffer );
  9618. delete buffers[ attribute.uuid ];
  9619. }
  9620. }
  9621. function update( attribute, bufferType ) {
  9622. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9623. var data = buffers[ attribute.uuid ];
  9624. if ( data === undefined ) {
  9625. buffers[ attribute.uuid ] = createBuffer( attribute, bufferType );
  9626. } else if ( data.version < attribute.version ) {
  9627. updateBuffer( data.buffer, attribute, bufferType );
  9628. data.version = attribute.version;
  9629. }
  9630. }
  9631. return {
  9632. get: get,
  9633. remove: remove,
  9634. update: update
  9635. };
  9636. }
  9637. /**
  9638. * @author mrdoob / http://mrdoob.com/
  9639. */
  9640. function painterSortStable( a, b ) {
  9641. if ( a.renderOrder !== b.renderOrder ) {
  9642. return a.renderOrder - b.renderOrder;
  9643. } else if ( a.program && b.program && a.program !== b.program ) {
  9644. return a.program.id - b.program.id;
  9645. } else if ( a.material.id !== b.material.id ) {
  9646. return a.material.id - b.material.id;
  9647. } else if ( a.z !== b.z ) {
  9648. return a.z - b.z;
  9649. } else {
  9650. return a.id - b.id;
  9651. }
  9652. }
  9653. function reversePainterSortStable( a, b ) {
  9654. if ( a.renderOrder !== b.renderOrder ) {
  9655. return a.renderOrder - b.renderOrder;
  9656. } if ( a.z !== b.z ) {
  9657. return b.z - a.z;
  9658. } else {
  9659. return a.id - b.id;
  9660. }
  9661. }
  9662. function WebGLRenderList() {
  9663. var opaque = [];
  9664. var opaqueLastIndex = - 1;
  9665. var transparent = [];
  9666. var transparentLastIndex = - 1;
  9667. function init() {
  9668. opaqueLastIndex = - 1;
  9669. transparentLastIndex = - 1;
  9670. }
  9671. function push( object, geometry, material, z, group ) {
  9672. var array, index;
  9673. // allocate the next position in the appropriate array
  9674. if ( material.transparent ) {
  9675. array = transparent;
  9676. index = ++ transparentLastIndex;
  9677. } else {
  9678. array = opaque;
  9679. index = ++ opaqueLastIndex;
  9680. }
  9681. // recycle existing render item or grow the array
  9682. var renderItem = array[ index ];
  9683. if ( renderItem ) {
  9684. renderItem.id = object.id;
  9685. renderItem.object = object;
  9686. renderItem.geometry = geometry;
  9687. renderItem.material = material;
  9688. renderItem.program = material.program;
  9689. renderItem.renderOrder = object.renderOrder;
  9690. renderItem.z = z;
  9691. renderItem.group = group;
  9692. } else {
  9693. renderItem = {
  9694. id: object.id,
  9695. object: object,
  9696. geometry: geometry,
  9697. material: material,
  9698. program: material.program,
  9699. renderOrder: object.renderOrder,
  9700. z: z,
  9701. group: group
  9702. };
  9703. // assert( index === array.length );
  9704. array.push( renderItem );
  9705. }
  9706. }
  9707. function finish() {
  9708. opaque.length = opaqueLastIndex + 1;
  9709. transparent.length = transparentLastIndex + 1;
  9710. }
  9711. function sort() {
  9712. opaque.sort( painterSortStable );
  9713. transparent.sort( reversePainterSortStable );
  9714. }
  9715. return {
  9716. opaque: opaque,
  9717. transparent: transparent,
  9718. init: init,
  9719. push: push,
  9720. finish: finish,
  9721. sort: sort
  9722. };
  9723. }
  9724. function WebGLRenderLists() {
  9725. var lists = {};
  9726. function get( scene, camera ) {
  9727. var hash = scene.id + ',' + camera.id;
  9728. var list = lists[ hash ];
  9729. if ( list === undefined ) {
  9730. // console.log( 'THREE.WebGLRenderLists:', hash );
  9731. list = new WebGLRenderList();
  9732. lists[ hash ] = list;
  9733. }
  9734. return list;
  9735. }
  9736. function dispose() {
  9737. lists = {};
  9738. }
  9739. return {
  9740. get: get,
  9741. dispose: dispose
  9742. };
  9743. }
  9744. /**
  9745. * @author mrdoob / http://mrdoob.com/
  9746. */
  9747. function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
  9748. var mode;
  9749. function setMode( value ) {
  9750. mode = value;
  9751. }
  9752. var type, bytesPerElement;
  9753. function setIndex( value ) {
  9754. type = value.type;
  9755. bytesPerElement = value.bytesPerElement;
  9756. }
  9757. function render( start, count ) {
  9758. gl.drawElements( mode, count, type, start * bytesPerElement );
  9759. infoRender.calls ++;
  9760. infoRender.vertices += count;
  9761. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  9762. }
  9763. function renderInstances( geometry, start, count ) {
  9764. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9765. if ( extension === null ) {
  9766. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9767. return;
  9768. }
  9769. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9770. infoRender.calls ++;
  9771. infoRender.vertices += count * geometry.maxInstancedCount;
  9772. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  9773. }
  9774. //
  9775. this.setMode = setMode;
  9776. this.setIndex = setIndex;
  9777. this.render = render;
  9778. this.renderInstances = renderInstances;
  9779. }
  9780. /**
  9781. * @author mrdoob / http://mrdoob.com/
  9782. */
  9783. function WebGLBufferRenderer( gl, extensions, infoRender ) {
  9784. var mode;
  9785. function setMode( value ) {
  9786. mode = value;
  9787. }
  9788. function render( start, count ) {
  9789. gl.drawArrays( mode, start, count );
  9790. infoRender.calls ++;
  9791. infoRender.vertices += count;
  9792. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  9793. }
  9794. function renderInstances( geometry, start, count ) {
  9795. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9796. if ( extension === null ) {
  9797. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9798. return;
  9799. }
  9800. var position = geometry.attributes.position;
  9801. if ( position.isInterleavedBufferAttribute ) {
  9802. count = position.data.count;
  9803. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  9804. } else {
  9805. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  9806. }
  9807. infoRender.calls ++;
  9808. infoRender.vertices += count * geometry.maxInstancedCount;
  9809. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  9810. }
  9811. //
  9812. this.setMode = setMode;
  9813. this.render = render;
  9814. this.renderInstances = renderInstances;
  9815. }
  9816. /**
  9817. * @author mrdoob / http://mrdoob.com/
  9818. */
  9819. function WebGLGeometries( gl, attributes, infoMemory ) {
  9820. var geometries = {};
  9821. var wireframeAttributes = {};
  9822. function onGeometryDispose( event ) {
  9823. var geometry = event.target;
  9824. var buffergeometry = geometries[ geometry.id ];
  9825. if ( buffergeometry.index !== null ) {
  9826. attributes.remove( buffergeometry.index );
  9827. }
  9828. for ( var name in buffergeometry.attributes ) {
  9829. attributes.remove( buffergeometry.attributes[ name ] );
  9830. }
  9831. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9832. delete geometries[ geometry.id ];
  9833. // TODO Remove duplicate code
  9834. var attribute = wireframeAttributes[ geometry.id ];
  9835. if ( attribute ) {
  9836. attributes.remove( attribute );
  9837. delete wireframeAttributes[ geometry.id ];
  9838. }
  9839. attribute = wireframeAttributes[ buffergeometry.id ];
  9840. if ( attribute ) {
  9841. attributes.remove( attribute );
  9842. delete wireframeAttributes[ buffergeometry.id ];
  9843. }
  9844. //
  9845. infoMemory.geometries --;
  9846. }
  9847. function get( object, geometry ) {
  9848. var buffergeometry = geometries[ geometry.id ];
  9849. if ( buffergeometry ) return buffergeometry;
  9850. geometry.addEventListener( 'dispose', onGeometryDispose );
  9851. if ( geometry.isBufferGeometry ) {
  9852. buffergeometry = geometry;
  9853. } else if ( geometry.isGeometry ) {
  9854. if ( geometry._bufferGeometry === undefined ) {
  9855. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9856. }
  9857. buffergeometry = geometry._bufferGeometry;
  9858. }
  9859. geometries[ geometry.id ] = buffergeometry;
  9860. infoMemory.geometries ++;
  9861. return buffergeometry;
  9862. }
  9863. function update( geometry ) {
  9864. var index = geometry.index;
  9865. var geometryAttributes = geometry.attributes;
  9866. if ( index !== null ) {
  9867. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  9868. }
  9869. for ( var name in geometryAttributes ) {
  9870. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  9871. }
  9872. // morph targets
  9873. var morphAttributes = geometry.morphAttributes;
  9874. for ( var name in morphAttributes ) {
  9875. var array = morphAttributes[ name ];
  9876. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9877. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  9878. }
  9879. }
  9880. }
  9881. function getWireframeAttribute( geometry ) {
  9882. var attribute = wireframeAttributes[ geometry.id ];
  9883. if ( attribute ) return attribute;
  9884. var indices = [];
  9885. var geometryIndex = geometry.index;
  9886. var geometryAttributes = geometry.attributes;
  9887. // console.time( 'wireframe' );
  9888. if ( geometryIndex !== null ) {
  9889. var array = geometryIndex.array;
  9890. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9891. var a = array[ i + 0 ];
  9892. var b = array[ i + 1 ];
  9893. var c = array[ i + 2 ];
  9894. indices.push( a, b, b, c, c, a );
  9895. }
  9896. } else {
  9897. var array = geometryAttributes.position.array;
  9898. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9899. var a = i + 0;
  9900. var b = i + 1;
  9901. var c = i + 2;
  9902. indices.push( a, b, b, c, c, a );
  9903. }
  9904. }
  9905. // console.timeEnd( 'wireframe' );
  9906. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9907. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  9908. wireframeAttributes[ geometry.id ] = attribute;
  9909. return attribute;
  9910. }
  9911. return {
  9912. get: get,
  9913. update: update,
  9914. getWireframeAttribute: getWireframeAttribute
  9915. };
  9916. }
  9917. /**
  9918. * @author mrdoob / http://mrdoob.com/
  9919. */
  9920. function WebGLLights() {
  9921. var lights = {};
  9922. return {
  9923. get: function ( light ) {
  9924. if ( lights[ light.id ] !== undefined ) {
  9925. return lights[ light.id ];
  9926. }
  9927. var uniforms;
  9928. switch ( light.type ) {
  9929. case 'DirectionalLight':
  9930. uniforms = {
  9931. direction: new Vector3(),
  9932. color: new Color(),
  9933. shadow: false,
  9934. shadowBias: 0,
  9935. shadowRadius: 1,
  9936. shadowMapSize: new Vector2()
  9937. };
  9938. break;
  9939. case 'SpotLight':
  9940. uniforms = {
  9941. position: new Vector3(),
  9942. direction: new Vector3(),
  9943. color: new Color(),
  9944. distance: 0,
  9945. coneCos: 0,
  9946. penumbraCos: 0,
  9947. decay: 0,
  9948. shadow: false,
  9949. shadowBias: 0,
  9950. shadowRadius: 1,
  9951. shadowMapSize: new Vector2()
  9952. };
  9953. break;
  9954. case 'PointLight':
  9955. uniforms = {
  9956. position: new Vector3(),
  9957. color: new Color(),
  9958. distance: 0,
  9959. decay: 0,
  9960. shadow: false,
  9961. shadowBias: 0,
  9962. shadowRadius: 1,
  9963. shadowMapSize: new Vector2()
  9964. };
  9965. break;
  9966. case 'HemisphereLight':
  9967. uniforms = {
  9968. direction: new Vector3(),
  9969. skyColor: new Color(),
  9970. groundColor: new Color()
  9971. };
  9972. break;
  9973. case 'RectAreaLight':
  9974. uniforms = {
  9975. color: new Color(),
  9976. position: new Vector3(),
  9977. halfWidth: new Vector3(),
  9978. halfHeight: new Vector3()
  9979. // TODO (abelnation): set RectAreaLight shadow uniforms
  9980. };
  9981. break;
  9982. }
  9983. lights[ light.id ] = uniforms;
  9984. return uniforms;
  9985. }
  9986. };
  9987. }
  9988. /**
  9989. * @author mrdoob / http://mrdoob.com/
  9990. */
  9991. function WebGLObjects( gl, geometries, infoRender ) {
  9992. var updateList = {};
  9993. function update( object ) {
  9994. var frame = infoRender.frame;
  9995. var geometry = object.geometry;
  9996. var buffergeometry = geometries.get( object, geometry );
  9997. // Update once per frame
  9998. if ( updateList[ buffergeometry.id ] !== frame ) {
  9999. if ( geometry.isGeometry ) {
  10000. buffergeometry.updateFromObject( object );
  10001. }
  10002. geometries.update( buffergeometry );
  10003. updateList[ buffergeometry.id ] = frame;
  10004. }
  10005. return buffergeometry;
  10006. }
  10007. function clear() {
  10008. updateList = {};
  10009. }
  10010. return {
  10011. update: update,
  10012. clear: clear
  10013. };
  10014. }
  10015. /**
  10016. * @author mrdoob / http://mrdoob.com/
  10017. */
  10018. function addLineNumbers( string ) {
  10019. var lines = string.split( '\n' );
  10020. for ( var i = 0; i < lines.length; i ++ ) {
  10021. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10022. }
  10023. return lines.join( '\n' );
  10024. }
  10025. function WebGLShader( gl, type, string ) {
  10026. var shader = gl.createShader( type );
  10027. gl.shaderSource( shader, string );
  10028. gl.compileShader( shader );
  10029. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  10030. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  10031. }
  10032. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  10033. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  10034. }
  10035. // --enable-privileged-webgl-extension
  10036. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10037. return shader;
  10038. }
  10039. /**
  10040. * @author mrdoob / http://mrdoob.com/
  10041. */
  10042. var programIdCount = 0;
  10043. function getEncodingComponents( encoding ) {
  10044. switch ( encoding ) {
  10045. case LinearEncoding:
  10046. return [ 'Linear','( value )' ];
  10047. case sRGBEncoding:
  10048. return [ 'sRGB','( value )' ];
  10049. case RGBEEncoding:
  10050. return [ 'RGBE','( value )' ];
  10051. case RGBM7Encoding:
  10052. return [ 'RGBM','( value, 7.0 )' ];
  10053. case RGBM16Encoding:
  10054. return [ 'RGBM','( value, 16.0 )' ];
  10055. case RGBDEncoding:
  10056. return [ 'RGBD','( value, 256.0 )' ];
  10057. case GammaEncoding:
  10058. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  10059. default:
  10060. throw new Error( 'unsupported encoding: ' + encoding );
  10061. }
  10062. }
  10063. function getTexelDecodingFunction( functionName, encoding ) {
  10064. var components = getEncodingComponents( encoding );
  10065. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  10066. }
  10067. function getTexelEncodingFunction( functionName, encoding ) {
  10068. var components = getEncodingComponents( encoding );
  10069. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  10070. }
  10071. function getToneMappingFunction( functionName, toneMapping ) {
  10072. var toneMappingName;
  10073. switch ( toneMapping ) {
  10074. case LinearToneMapping:
  10075. toneMappingName = "Linear";
  10076. break;
  10077. case ReinhardToneMapping:
  10078. toneMappingName = "Reinhard";
  10079. break;
  10080. case Uncharted2ToneMapping:
  10081. toneMappingName = "Uncharted2";
  10082. break;
  10083. case CineonToneMapping:
  10084. toneMappingName = "OptimizedCineon";
  10085. break;
  10086. default:
  10087. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10088. }
  10089. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  10090. }
  10091. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10092. extensions = extensions || {};
  10093. var chunks = [
  10094. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10095. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10096. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10097. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10098. ];
  10099. return chunks.filter( filterEmptyLine ).join( '\n' );
  10100. }
  10101. function generateDefines( defines ) {
  10102. var chunks = [];
  10103. for ( var name in defines ) {
  10104. var value = defines[ name ];
  10105. if ( value === false ) continue;
  10106. chunks.push( '#define ' + name + ' ' + value );
  10107. }
  10108. return chunks.join( '\n' );
  10109. }
  10110. function fetchAttributeLocations( gl, program, identifiers ) {
  10111. var attributes = {};
  10112. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  10113. for ( var i = 0; i < n; i ++ ) {
  10114. var info = gl.getActiveAttrib( program, i );
  10115. var name = info.name;
  10116. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  10117. attributes[ name ] = gl.getAttribLocation( program, name );
  10118. }
  10119. return attributes;
  10120. }
  10121. function filterEmptyLine( string ) {
  10122. return string !== '';
  10123. }
  10124. function replaceLightNums( string, parameters ) {
  10125. return string
  10126. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10127. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10128. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10129. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10130. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10131. }
  10132. function parseIncludes( string ) {
  10133. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  10134. function replace( match, include ) {
  10135. var replace = ShaderChunk[ include ];
  10136. if ( replace === undefined ) {
  10137. throw new Error( 'Can not resolve #include <' + include + '>' );
  10138. }
  10139. return parseIncludes( replace );
  10140. }
  10141. return string.replace( pattern, replace );
  10142. }
  10143. function unrollLoops( string ) {
  10144. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10145. function replace( match, start, end, snippet ) {
  10146. var unroll = '';
  10147. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10148. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10149. }
  10150. return unroll;
  10151. }
  10152. return string.replace( pattern, replace );
  10153. }
  10154. function WebGLProgram( renderer, code, material, parameters ) {
  10155. var gl = renderer.context;
  10156. var extensions = material.extensions;
  10157. var defines = material.defines;
  10158. var vertexShader = material.__webglShader.vertexShader;
  10159. var fragmentShader = material.__webglShader.fragmentShader;
  10160. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10161. if ( parameters.shadowMapType === PCFShadowMap ) {
  10162. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10163. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10164. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10165. }
  10166. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10167. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10168. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10169. if ( parameters.envMap ) {
  10170. switch ( material.envMap.mapping ) {
  10171. case CubeReflectionMapping:
  10172. case CubeRefractionMapping:
  10173. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10174. break;
  10175. case CubeUVReflectionMapping:
  10176. case CubeUVRefractionMapping:
  10177. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10178. break;
  10179. case EquirectangularReflectionMapping:
  10180. case EquirectangularRefractionMapping:
  10181. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10182. break;
  10183. case SphericalReflectionMapping:
  10184. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10185. break;
  10186. }
  10187. switch ( material.envMap.mapping ) {
  10188. case CubeRefractionMapping:
  10189. case EquirectangularRefractionMapping:
  10190. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10191. break;
  10192. }
  10193. switch ( material.combine ) {
  10194. case MultiplyOperation:
  10195. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10196. break;
  10197. case MixOperation:
  10198. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10199. break;
  10200. case AddOperation:
  10201. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10202. break;
  10203. }
  10204. }
  10205. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10206. // console.log( 'building new program ' );
  10207. //
  10208. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  10209. var customDefines = generateDefines( defines );
  10210. //
  10211. var program = gl.createProgram();
  10212. var prefixVertex, prefixFragment;
  10213. if ( material.isRawShaderMaterial ) {
  10214. prefixVertex = [
  10215. customDefines,
  10216. '\n'
  10217. ].filter( filterEmptyLine ).join( '\n' );
  10218. prefixFragment = [
  10219. customExtensions,
  10220. customDefines,
  10221. '\n'
  10222. ].filter( filterEmptyLine ).join( '\n' );
  10223. } else {
  10224. prefixVertex = [
  10225. 'precision ' + parameters.precision + ' float;',
  10226. 'precision ' + parameters.precision + ' int;',
  10227. '#define SHADER_NAME ' + material.__webglShader.name,
  10228. customDefines,
  10229. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10230. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10231. '#define MAX_BONES ' + parameters.maxBones,
  10232. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10233. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10234. parameters.map ? '#define USE_MAP' : '',
  10235. parameters.envMap ? '#define USE_ENVMAP' : '',
  10236. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10237. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10238. parameters.aoMap ? '#define USE_AOMAP' : '',
  10239. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10240. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10241. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10242. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10243. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10244. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10245. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10246. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10247. parameters.vertexColors ? '#define USE_COLOR' : '',
  10248. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10249. parameters.skinning ? '#define USE_SKINNING' : '',
  10250. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10251. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10252. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10253. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10254. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10255. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  10256. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10257. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10258. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10259. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10260. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10261. 'uniform mat4 modelMatrix;',
  10262. 'uniform mat4 modelViewMatrix;',
  10263. 'uniform mat4 projectionMatrix;',
  10264. 'uniform mat4 viewMatrix;',
  10265. 'uniform mat3 normalMatrix;',
  10266. 'uniform vec3 cameraPosition;',
  10267. 'attribute vec3 position;',
  10268. 'attribute vec3 normal;',
  10269. 'attribute vec2 uv;',
  10270. '#ifdef USE_COLOR',
  10271. ' attribute vec3 color;',
  10272. '#endif',
  10273. '#ifdef USE_MORPHTARGETS',
  10274. ' attribute vec3 morphTarget0;',
  10275. ' attribute vec3 morphTarget1;',
  10276. ' attribute vec3 morphTarget2;',
  10277. ' attribute vec3 morphTarget3;',
  10278. ' #ifdef USE_MORPHNORMALS',
  10279. ' attribute vec3 morphNormal0;',
  10280. ' attribute vec3 morphNormal1;',
  10281. ' attribute vec3 morphNormal2;',
  10282. ' attribute vec3 morphNormal3;',
  10283. ' #else',
  10284. ' attribute vec3 morphTarget4;',
  10285. ' attribute vec3 morphTarget5;',
  10286. ' attribute vec3 morphTarget6;',
  10287. ' attribute vec3 morphTarget7;',
  10288. ' #endif',
  10289. '#endif',
  10290. '#ifdef USE_SKINNING',
  10291. ' attribute vec4 skinIndex;',
  10292. ' attribute vec4 skinWeight;',
  10293. '#endif',
  10294. '\n'
  10295. ].filter( filterEmptyLine ).join( '\n' );
  10296. prefixFragment = [
  10297. customExtensions,
  10298. 'precision ' + parameters.precision + ' float;',
  10299. 'precision ' + parameters.precision + ' int;',
  10300. '#define SHADER_NAME ' + material.__webglShader.name,
  10301. customDefines,
  10302. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  10303. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10304. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10305. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10306. parameters.map ? '#define USE_MAP' : '',
  10307. parameters.envMap ? '#define USE_ENVMAP' : '',
  10308. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10309. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10310. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10311. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10312. parameters.aoMap ? '#define USE_AOMAP' : '',
  10313. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10314. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10315. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10316. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10317. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10318. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10319. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10320. parameters.vertexColors ? '#define USE_COLOR' : '',
  10321. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10322. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10323. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10324. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10325. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  10326. '#define UNION_CLIPPING_PLANES ' + (parameters.numClippingPlanes - parameters.numClipIntersection),
  10327. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10328. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10329. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  10330. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  10331. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10332. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10333. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  10334. 'uniform mat4 viewMatrix;',
  10335. 'uniform vec3 cameraPosition;',
  10336. ( parameters.toneMapping !== NoToneMapping ) ? "#define TONE_MAPPING" : '',
  10337. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10338. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  10339. parameters.dithering ? '#define DITHERING' : '',
  10340. ( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10341. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10342. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10343. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10344. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  10345. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  10346. '\n'
  10347. ].filter( filterEmptyLine ).join( '\n' );
  10348. }
  10349. vertexShader = parseIncludes( vertexShader );
  10350. vertexShader = replaceLightNums( vertexShader, parameters );
  10351. fragmentShader = parseIncludes( fragmentShader );
  10352. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10353. if ( ! material.isShaderMaterial ) {
  10354. vertexShader = unrollLoops( vertexShader );
  10355. fragmentShader = unrollLoops( fragmentShader );
  10356. }
  10357. var vertexGlsl = prefixVertex + vertexShader;
  10358. var fragmentGlsl = prefixFragment + fragmentShader;
  10359. // console.log( '*VERTEX*', vertexGlsl );
  10360. // console.log( '*FRAGMENT*', fragmentGlsl );
  10361. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  10362. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  10363. gl.attachShader( program, glVertexShader );
  10364. gl.attachShader( program, glFragmentShader );
  10365. // Force a particular attribute to index 0.
  10366. if ( material.index0AttributeName !== undefined ) {
  10367. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10368. } else if ( parameters.morphTargets === true ) {
  10369. // programs with morphTargets displace position out of attribute 0
  10370. gl.bindAttribLocation( program, 0, 'position' );
  10371. }
  10372. gl.linkProgram( program );
  10373. var programLog = gl.getProgramInfoLog( program );
  10374. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  10375. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  10376. var runnable = true;
  10377. var haveDiagnostics = true;
  10378. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10379. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10380. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  10381. runnable = false;
  10382. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10383. } else if ( programLog !== '' ) {
  10384. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10385. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10386. haveDiagnostics = false;
  10387. }
  10388. if ( haveDiagnostics ) {
  10389. this.diagnostics = {
  10390. runnable: runnable,
  10391. material: material,
  10392. programLog: programLog,
  10393. vertexShader: {
  10394. log: vertexLog,
  10395. prefix: prefixVertex
  10396. },
  10397. fragmentShader: {
  10398. log: fragmentLog,
  10399. prefix: prefixFragment
  10400. }
  10401. };
  10402. }
  10403. // clean up
  10404. gl.deleteShader( glVertexShader );
  10405. gl.deleteShader( glFragmentShader );
  10406. // set up caching for uniform locations
  10407. var cachedUniforms;
  10408. this.getUniforms = function() {
  10409. if ( cachedUniforms === undefined ) {
  10410. cachedUniforms =
  10411. new WebGLUniforms( gl, program, renderer );
  10412. }
  10413. return cachedUniforms;
  10414. };
  10415. // set up caching for attribute locations
  10416. var cachedAttributes;
  10417. this.getAttributes = function() {
  10418. if ( cachedAttributes === undefined ) {
  10419. cachedAttributes = fetchAttributeLocations( gl, program );
  10420. }
  10421. return cachedAttributes;
  10422. };
  10423. // free resource
  10424. this.destroy = function() {
  10425. gl.deleteProgram( program );
  10426. this.program = undefined;
  10427. };
  10428. // DEPRECATED
  10429. Object.defineProperties( this, {
  10430. uniforms: {
  10431. get: function() {
  10432. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10433. return this.getUniforms();
  10434. }
  10435. },
  10436. attributes: {
  10437. get: function() {
  10438. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10439. return this.getAttributes();
  10440. }
  10441. }
  10442. } );
  10443. //
  10444. this.id = programIdCount ++;
  10445. this.code = code;
  10446. this.usedTimes = 1;
  10447. this.program = program;
  10448. this.vertexShader = glVertexShader;
  10449. this.fragmentShader = glFragmentShader;
  10450. return this;
  10451. }
  10452. /**
  10453. * @author mrdoob / http://mrdoob.com/
  10454. */
  10455. function WebGLPrograms( renderer, capabilities ) {
  10456. var programs = [];
  10457. var shaderIDs = {
  10458. MeshDepthMaterial: 'depth',
  10459. MeshNormalMaterial: 'normal',
  10460. MeshBasicMaterial: 'basic',
  10461. MeshLambertMaterial: 'lambert',
  10462. MeshPhongMaterial: 'phong',
  10463. MeshToonMaterial: 'phong',
  10464. MeshStandardMaterial: 'physical',
  10465. MeshPhysicalMaterial: 'physical',
  10466. LineBasicMaterial: 'basic',
  10467. LineDashedMaterial: 'dashed',
  10468. PointsMaterial: 'points'
  10469. };
  10470. var parameterNames = [
  10471. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10472. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  10473. "roughnessMap", "metalnessMap", "gradientMap",
  10474. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  10475. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10476. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10477. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10478. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10479. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10480. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10481. ];
  10482. function allocateBones( object ) {
  10483. var skeleton = object.skeleton;
  10484. var bones = skeleton.bones;
  10485. if ( capabilities.floatVertexTextures ) {
  10486. return 1024;
  10487. } else {
  10488. // default for when object is not specified
  10489. // ( for example when prebuilding shader to be used with multiple objects )
  10490. //
  10491. // - leave some extra space for other uniforms
  10492. // - limit here is ANGLE's 254 max uniform vectors
  10493. // (up to 54 should be safe)
  10494. var nVertexUniforms = capabilities.maxVertexUniforms;
  10495. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10496. var maxBones = Math.min( nVertexMatrices, bones.length );
  10497. if ( maxBones < bones.length ) {
  10498. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10499. return 0;
  10500. }
  10501. return maxBones;
  10502. }
  10503. }
  10504. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10505. var encoding;
  10506. if ( ! map ) {
  10507. encoding = LinearEncoding;
  10508. } else if ( map.isTexture ) {
  10509. encoding = map.encoding;
  10510. } else if ( map.isWebGLRenderTarget ) {
  10511. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10512. encoding = map.texture.encoding;
  10513. }
  10514. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10515. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10516. encoding = GammaEncoding;
  10517. }
  10518. return encoding;
  10519. }
  10520. this.getParameters = function ( material, lights, fog, nClipPlanes, nClipIntersection, object ) {
  10521. var shaderID = shaderIDs[ material.type ];
  10522. // heuristics to create shader parameters according to lights in the scene
  10523. // (not to blow over maxLights budget)
  10524. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10525. var precision = renderer.getPrecision();
  10526. if ( material.precision !== null ) {
  10527. precision = capabilities.getMaxPrecision( material.precision );
  10528. if ( precision !== material.precision ) {
  10529. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10530. }
  10531. }
  10532. var currentRenderTarget = renderer.getRenderTarget();
  10533. var parameters = {
  10534. shaderID: shaderID,
  10535. precision: precision,
  10536. supportsVertexTextures: capabilities.vertexTextures,
  10537. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10538. map: !! material.map,
  10539. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10540. envMap: !! material.envMap,
  10541. envMapMode: material.envMap && material.envMap.mapping,
  10542. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10543. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10544. lightMap: !! material.lightMap,
  10545. aoMap: !! material.aoMap,
  10546. emissiveMap: !! material.emissiveMap,
  10547. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10548. bumpMap: !! material.bumpMap,
  10549. normalMap: !! material.normalMap,
  10550. displacementMap: !! material.displacementMap,
  10551. roughnessMap: !! material.roughnessMap,
  10552. metalnessMap: !! material.metalnessMap,
  10553. specularMap: !! material.specularMap,
  10554. alphaMap: !! material.alphaMap,
  10555. gradientMap: !! material.gradientMap,
  10556. combine: material.combine,
  10557. vertexColors: material.vertexColors,
  10558. fog: !! fog,
  10559. useFog: material.fog,
  10560. fogExp: ( fog && fog.isFogExp2 ),
  10561. flatShading: material.shading === FlatShading,
  10562. sizeAttenuation: material.sizeAttenuation,
  10563. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10564. skinning: material.skinning && maxBones > 0,
  10565. maxBones: maxBones,
  10566. useVertexTexture: capabilities.floatVertexTextures,
  10567. morphTargets: material.morphTargets,
  10568. morphNormals: material.morphNormals,
  10569. maxMorphTargets: renderer.maxMorphTargets,
  10570. maxMorphNormals: renderer.maxMorphNormals,
  10571. numDirLights: lights.directional.length,
  10572. numPointLights: lights.point.length,
  10573. numSpotLights: lights.spot.length,
  10574. numRectAreaLights: lights.rectArea.length,
  10575. numHemiLights: lights.hemi.length,
  10576. numClippingPlanes: nClipPlanes,
  10577. numClipIntersection: nClipIntersection,
  10578. dithering: material.dithering,
  10579. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  10580. shadowMapType: renderer.shadowMap.type,
  10581. toneMapping: renderer.toneMapping,
  10582. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10583. premultipliedAlpha: material.premultipliedAlpha,
  10584. alphaTest: material.alphaTest,
  10585. doubleSided: material.side === DoubleSide,
  10586. flipSided: material.side === BackSide,
  10587. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10588. };
  10589. return parameters;
  10590. };
  10591. this.getProgramCode = function ( material, parameters ) {
  10592. var array = [];
  10593. if ( parameters.shaderID ) {
  10594. array.push( parameters.shaderID );
  10595. } else {
  10596. array.push( material.fragmentShader );
  10597. array.push( material.vertexShader );
  10598. }
  10599. if ( material.defines !== undefined ) {
  10600. for ( var name in material.defines ) {
  10601. array.push( name );
  10602. array.push( material.defines[ name ] );
  10603. }
  10604. }
  10605. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10606. array.push( parameters[ parameterNames[ i ] ] );
  10607. }
  10608. array.push( material.onBeforeCompile.toString() );
  10609. array.push( renderer.gammaOutput );
  10610. return array.join();
  10611. };
  10612. this.acquireProgram = function ( material, parameters, code ) {
  10613. var program;
  10614. // Check if code has been already compiled
  10615. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10616. var programInfo = programs[ p ];
  10617. if ( programInfo.code === code ) {
  10618. program = programInfo;
  10619. ++ program.usedTimes;
  10620. break;
  10621. }
  10622. }
  10623. if ( program === undefined ) {
  10624. program = new WebGLProgram( renderer, code, material, parameters );
  10625. programs.push( program );
  10626. }
  10627. return program;
  10628. };
  10629. this.releaseProgram = function ( program ) {
  10630. if ( -- program.usedTimes === 0 ) {
  10631. // Remove from unordered set
  10632. var i = programs.indexOf( program );
  10633. programs[ i ] = programs[ programs.length - 1 ];
  10634. programs.pop();
  10635. // Free WebGL resources
  10636. program.destroy();
  10637. }
  10638. };
  10639. // Exposed for resource monitoring & error feedback via renderer.info:
  10640. this.programs = programs;
  10641. }
  10642. /**
  10643. * @author mrdoob / http://mrdoob.com/
  10644. */
  10645. function WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, infoMemory ) {
  10646. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
  10647. //
  10648. function clampToMaxSize( image, maxSize ) {
  10649. if ( image.width > maxSize || image.height > maxSize ) {
  10650. // Warning: Scaling through the canvas will only work with images that use
  10651. // premultiplied alpha.
  10652. var scale = maxSize / Math.max( image.width, image.height );
  10653. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  10654. canvas.width = Math.floor( image.width * scale );
  10655. canvas.height = Math.floor( image.height * scale );
  10656. var context = canvas.getContext( '2d' );
  10657. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  10658. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  10659. return canvas;
  10660. }
  10661. return image;
  10662. }
  10663. function isPowerOfTwo( image ) {
  10664. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  10665. }
  10666. function makePowerOfTwo( image ) {
  10667. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  10668. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  10669. canvas.width = _Math.nearestPowerOfTwo( image.width );
  10670. canvas.height = _Math.nearestPowerOfTwo( image.height );
  10671. var context = canvas.getContext( '2d' );
  10672. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  10673. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  10674. return canvas;
  10675. }
  10676. return image;
  10677. }
  10678. function textureNeedsPowerOfTwo( texture ) {
  10679. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  10680. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  10681. }
  10682. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  10683. return texture.generateMipmaps && isPowerOfTwo &&
  10684. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  10685. }
  10686. // Fallback filters for non-power-of-2 textures
  10687. function filterFallback( f ) {
  10688. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  10689. return _gl.NEAREST;
  10690. }
  10691. return _gl.LINEAR;
  10692. }
  10693. //
  10694. function onTextureDispose( event ) {
  10695. var texture = event.target;
  10696. texture.removeEventListener( 'dispose', onTextureDispose );
  10697. deallocateTexture( texture );
  10698. infoMemory.textures --;
  10699. }
  10700. function onRenderTargetDispose( event ) {
  10701. var renderTarget = event.target;
  10702. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  10703. deallocateRenderTarget( renderTarget );
  10704. infoMemory.textures --;
  10705. }
  10706. //
  10707. function deallocateTexture( texture ) {
  10708. var textureProperties = properties.get( texture );
  10709. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  10710. // cube texture
  10711. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  10712. } else {
  10713. // 2D texture
  10714. if ( textureProperties.__webglInit === undefined ) return;
  10715. _gl.deleteTexture( textureProperties.__webglTexture );
  10716. }
  10717. // remove all webgl properties
  10718. properties.remove( texture );
  10719. }
  10720. function deallocateRenderTarget( renderTarget ) {
  10721. var renderTargetProperties = properties.get( renderTarget );
  10722. var textureProperties = properties.get( renderTarget.texture );
  10723. if ( ! renderTarget ) return;
  10724. if ( textureProperties.__webglTexture !== undefined ) {
  10725. _gl.deleteTexture( textureProperties.__webglTexture );
  10726. }
  10727. if ( renderTarget.depthTexture ) {
  10728. renderTarget.depthTexture.dispose();
  10729. }
  10730. if ( renderTarget.isWebGLRenderTargetCube ) {
  10731. for ( var i = 0; i < 6; i ++ ) {
  10732. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  10733. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  10734. }
  10735. } else {
  10736. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  10737. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  10738. }
  10739. properties.remove( renderTarget.texture );
  10740. properties.remove( renderTarget );
  10741. }
  10742. //
  10743. function setTexture2D( texture, slot ) {
  10744. var textureProperties = properties.get( texture );
  10745. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  10746. var image = texture.image;
  10747. if ( image === undefined ) {
  10748. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  10749. } else if ( image.complete === false ) {
  10750. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  10751. } else {
  10752. uploadTexture( textureProperties, texture, slot );
  10753. return;
  10754. }
  10755. }
  10756. state.activeTexture( _gl.TEXTURE0 + slot );
  10757. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  10758. }
  10759. function setTextureCube( texture, slot ) {
  10760. var textureProperties = properties.get( texture );
  10761. if ( texture.image.length === 6 ) {
  10762. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  10763. if ( ! textureProperties.__image__webglTextureCube ) {
  10764. texture.addEventListener( 'dispose', onTextureDispose );
  10765. textureProperties.__image__webglTextureCube = _gl.createTexture();
  10766. infoMemory.textures ++;
  10767. }
  10768. state.activeTexture( _gl.TEXTURE0 + slot );
  10769. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  10770. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  10771. var isCompressed = ( texture && texture.isCompressedTexture );
  10772. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  10773. var cubeImage = [];
  10774. for ( var i = 0; i < 6; i ++ ) {
  10775. if ( ! isCompressed && ! isDataTexture ) {
  10776. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  10777. } else {
  10778. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  10779. }
  10780. }
  10781. var image = cubeImage[ 0 ],
  10782. isPowerOfTwoImage = isPowerOfTwo( image ),
  10783. glFormat = paramThreeToGL( texture.format ),
  10784. glType = paramThreeToGL( texture.type );
  10785. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  10786. for ( var i = 0; i < 6; i ++ ) {
  10787. if ( ! isCompressed ) {
  10788. if ( isDataTexture ) {
  10789. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  10790. } else {
  10791. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  10792. }
  10793. } else {
  10794. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  10795. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  10796. mipmap = mipmaps[ j ];
  10797. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  10798. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  10799. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  10800. } else {
  10801. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()" );
  10802. }
  10803. } else {
  10804. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10805. }
  10806. }
  10807. }
  10808. }
  10809. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  10810. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  10811. }
  10812. textureProperties.__version = texture.version;
  10813. if ( texture.onUpdate ) texture.onUpdate( texture );
  10814. } else {
  10815. state.activeTexture( _gl.TEXTURE0 + slot );
  10816. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  10817. }
  10818. }
  10819. }
  10820. function setTextureCubeDynamic( texture, slot ) {
  10821. state.activeTexture( _gl.TEXTURE0 + slot );
  10822. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  10823. }
  10824. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  10825. var extension;
  10826. if ( isPowerOfTwoImage ) {
  10827. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  10828. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  10829. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  10830. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  10831. } else {
  10832. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  10833. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  10834. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  10835. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  10836. }
  10837. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  10838. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  10839. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  10840. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  10841. }
  10842. }
  10843. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  10844. if ( extension ) {
  10845. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  10846. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  10847. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  10848. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  10849. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  10850. }
  10851. }
  10852. }
  10853. function uploadTexture( textureProperties, texture, slot ) {
  10854. if ( textureProperties.__webglInit === undefined ) {
  10855. textureProperties.__webglInit = true;
  10856. texture.addEventListener( 'dispose', onTextureDispose );
  10857. textureProperties.__webglTexture = _gl.createTexture();
  10858. infoMemory.textures ++;
  10859. }
  10860. state.activeTexture( _gl.TEXTURE0 + slot );
  10861. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  10862. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  10863. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  10864. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  10865. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  10866. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  10867. image = makePowerOfTwo( image );
  10868. }
  10869. var isPowerOfTwoImage = isPowerOfTwo( image ),
  10870. glFormat = paramThreeToGL( texture.format ),
  10871. glType = paramThreeToGL( texture.type );
  10872. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  10873. var mipmap, mipmaps = texture.mipmaps;
  10874. if ( texture.isDepthTexture ) {
  10875. // populate depth texture with dummy data
  10876. var internalFormat = _gl.DEPTH_COMPONENT;
  10877. if ( texture.type === FloatType ) {
  10878. if ( !_isWebGL2 ) throw new Error('Float Depth Texture only supported in WebGL2.0');
  10879. internalFormat = _gl.DEPTH_COMPONENT32F;
  10880. } else if ( _isWebGL2 ) {
  10881. // WebGL 2.0 requires signed internalformat for glTexImage2D
  10882. internalFormat = _gl.DEPTH_COMPONENT16;
  10883. }
  10884. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  10885. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  10886. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  10887. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10888. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  10889. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  10890. texture.type = UnsignedShortType;
  10891. glType = paramThreeToGL( texture.type );
  10892. }
  10893. }
  10894. // Depth stencil textures need the DEPTH_STENCIL internal format
  10895. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10896. if ( texture.format === DepthStencilFormat ) {
  10897. internalFormat = _gl.DEPTH_STENCIL;
  10898. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  10899. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  10900. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10901. if ( texture.type !== UnsignedInt248Type ) {
  10902. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  10903. texture.type = UnsignedInt248Type;
  10904. glType = paramThreeToGL( texture.type );
  10905. }
  10906. }
  10907. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  10908. } else if ( texture.isDataTexture ) {
  10909. // use manually created mipmaps if available
  10910. // if there are no manual mipmaps
  10911. // set 0 level mipmap and then use GL to generate other mipmap levels
  10912. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  10913. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10914. mipmap = mipmaps[ i ];
  10915. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10916. }
  10917. texture.generateMipmaps = false;
  10918. } else {
  10919. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  10920. }
  10921. } else if ( texture.isCompressedTexture ) {
  10922. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10923. mipmap = mipmaps[ i ];
  10924. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  10925. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  10926. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  10927. } else {
  10928. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  10929. }
  10930. } else {
  10931. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10932. }
  10933. }
  10934. } else {
  10935. // regular Texture (image, video, canvas)
  10936. // use manually created mipmaps if available
  10937. // if there are no manual mipmaps
  10938. // set 0 level mipmap and then use GL to generate other mipmap levels
  10939. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  10940. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10941. mipmap = mipmaps[ i ];
  10942. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  10943. }
  10944. texture.generateMipmaps = false;
  10945. } else {
  10946. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  10947. }
  10948. }
  10949. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  10950. textureProperties.__version = texture.version;
  10951. if ( texture.onUpdate ) texture.onUpdate( texture );
  10952. }
  10953. // Render targets
  10954. // Setup storage for target texture and bind it to correct framebuffer
  10955. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  10956. var glFormat = paramThreeToGL( renderTarget.texture.format );
  10957. var glType = paramThreeToGL( renderTarget.texture.type );
  10958. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  10959. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  10960. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  10961. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  10962. }
  10963. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  10964. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  10965. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  10966. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  10967. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  10968. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  10969. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  10970. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  10971. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  10972. } else {
  10973. // FIXME: We don't support !depth !stencil
  10974. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  10975. }
  10976. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  10977. }
  10978. // Setup resources for a Depth Texture for a FBO (needs an extension)
  10979. function setupDepthTexture( framebuffer, renderTarget ) {
  10980. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  10981. if ( isCube ) throw new Error('Depth Texture with cube render targets is not supported!');
  10982. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  10983. if ( !( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  10984. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  10985. }
  10986. // upload an empty depth texture with framebuffer size
  10987. if ( !properties.get( renderTarget.depthTexture ).__webglTexture ||
  10988. renderTarget.depthTexture.image.width !== renderTarget.width ||
  10989. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  10990. renderTarget.depthTexture.image.width = renderTarget.width;
  10991. renderTarget.depthTexture.image.height = renderTarget.height;
  10992. renderTarget.depthTexture.needsUpdate = true;
  10993. }
  10994. setTexture2D( renderTarget.depthTexture, 0 );
  10995. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  10996. if ( renderTarget.depthTexture.format === DepthFormat ) {
  10997. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  10998. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  10999. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  11000. } else {
  11001. throw new Error('Unknown depthTexture format')
  11002. }
  11003. }
  11004. // Setup GL resources for a non-texture depth buffer
  11005. function setupDepthRenderbuffer( renderTarget ) {
  11006. var renderTargetProperties = properties.get( renderTarget );
  11007. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  11008. if ( renderTarget.depthTexture ) {
  11009. if ( isCube ) throw new Error('target.depthTexture not supported in Cube render targets');
  11010. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  11011. } else {
  11012. if ( isCube ) {
  11013. renderTargetProperties.__webglDepthbuffer = [];
  11014. for ( var i = 0; i < 6; i ++ ) {
  11015. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  11016. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  11017. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  11018. }
  11019. } else {
  11020. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  11021. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  11022. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  11023. }
  11024. }
  11025. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  11026. }
  11027. // Set up GL resources for the render target
  11028. function setupRenderTarget( renderTarget ) {
  11029. var renderTargetProperties = properties.get( renderTarget );
  11030. var textureProperties = properties.get( renderTarget.texture );
  11031. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  11032. textureProperties.__webglTexture = _gl.createTexture();
  11033. infoMemory.textures ++;
  11034. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  11035. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  11036. // Setup framebuffer
  11037. if ( isCube ) {
  11038. renderTargetProperties.__webglFramebuffer = [];
  11039. for ( var i = 0; i < 6; i ++ ) {
  11040. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  11041. }
  11042. } else {
  11043. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  11044. }
  11045. // Setup color buffer
  11046. if ( isCube ) {
  11047. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  11048. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  11049. for ( var i = 0; i < 6; i ++ ) {
  11050. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  11051. }
  11052. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  11053. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  11054. } else {
  11055. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  11056. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  11057. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  11058. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  11059. state.bindTexture( _gl.TEXTURE_2D, null );
  11060. }
  11061. // Setup depth and stencil buffers
  11062. if ( renderTarget.depthBuffer ) {
  11063. setupDepthRenderbuffer( renderTarget );
  11064. }
  11065. }
  11066. function updateRenderTargetMipmap( renderTarget ) {
  11067. var texture = renderTarget.texture;
  11068. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  11069. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  11070. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  11071. var webglTexture = properties.get( texture ).__webglTexture;
  11072. state.bindTexture( target, webglTexture );
  11073. _gl.generateMipmap( target );
  11074. state.bindTexture( target, null );
  11075. }
  11076. }
  11077. this.setTexture2D = setTexture2D;
  11078. this.setTextureCube = setTextureCube;
  11079. this.setTextureCubeDynamic = setTextureCubeDynamic;
  11080. this.setupRenderTarget = setupRenderTarget;
  11081. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  11082. }
  11083. /**
  11084. * @author fordacious / fordacious.github.io
  11085. */
  11086. function WebGLProperties() {
  11087. var properties = {};
  11088. function get( object ) {
  11089. var uuid = object.uuid;
  11090. var map = properties[ uuid ];
  11091. if ( map === undefined ) {
  11092. map = {};
  11093. properties[ uuid ] = map;
  11094. }
  11095. return map;
  11096. }
  11097. function remove( object ) {
  11098. delete properties[ object.uuid ];
  11099. }
  11100. function clear() {
  11101. properties = {};
  11102. }
  11103. return {
  11104. get: get,
  11105. remove: remove,
  11106. clear: clear
  11107. };
  11108. }
  11109. /**
  11110. * @author mrdoob / http://mrdoob.com/
  11111. */
  11112. function WebGLState( gl, extensions, paramThreeToGL ) {
  11113. function ColorBuffer() {
  11114. var locked = false;
  11115. var color = new Vector4();
  11116. var currentColorMask = null;
  11117. var currentColorClear = new Vector4();
  11118. return {
  11119. setMask: function ( colorMask ) {
  11120. if ( currentColorMask !== colorMask && ! locked ) {
  11121. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11122. currentColorMask = colorMask;
  11123. }
  11124. },
  11125. setLocked: function ( lock ) {
  11126. locked = lock;
  11127. },
  11128. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11129. if ( premultipliedAlpha === true ) {
  11130. r *= a; g *= a; b *= a;
  11131. }
  11132. color.set( r, g, b, a );
  11133. if ( currentColorClear.equals( color ) === false ) {
  11134. gl.clearColor( r, g, b, a );
  11135. currentColorClear.copy( color );
  11136. }
  11137. },
  11138. reset: function () {
  11139. locked = false;
  11140. currentColorMask = null;
  11141. currentColorClear.set( 0, 0, 0, 1 );
  11142. }
  11143. };
  11144. }
  11145. function DepthBuffer() {
  11146. var locked = false;
  11147. var currentDepthMask = null;
  11148. var currentDepthFunc = null;
  11149. var currentDepthClear = null;
  11150. return {
  11151. setTest: function ( depthTest ) {
  11152. if ( depthTest ) {
  11153. enable( gl.DEPTH_TEST );
  11154. } else {
  11155. disable( gl.DEPTH_TEST );
  11156. }
  11157. },
  11158. setMask: function ( depthMask ) {
  11159. if ( currentDepthMask !== depthMask && ! locked ) {
  11160. gl.depthMask( depthMask );
  11161. currentDepthMask = depthMask;
  11162. }
  11163. },
  11164. setFunc: function ( depthFunc ) {
  11165. if ( currentDepthFunc !== depthFunc ) {
  11166. if ( depthFunc ) {
  11167. switch ( depthFunc ) {
  11168. case NeverDepth:
  11169. gl.depthFunc( gl.NEVER );
  11170. break;
  11171. case AlwaysDepth:
  11172. gl.depthFunc( gl.ALWAYS );
  11173. break;
  11174. case LessDepth:
  11175. gl.depthFunc( gl.LESS );
  11176. break;
  11177. case LessEqualDepth:
  11178. gl.depthFunc( gl.LEQUAL );
  11179. break;
  11180. case EqualDepth:
  11181. gl.depthFunc( gl.EQUAL );
  11182. break;
  11183. case GreaterEqualDepth:
  11184. gl.depthFunc( gl.GEQUAL );
  11185. break;
  11186. case GreaterDepth:
  11187. gl.depthFunc( gl.GREATER );
  11188. break;
  11189. case NotEqualDepth:
  11190. gl.depthFunc( gl.NOTEQUAL );
  11191. break;
  11192. default:
  11193. gl.depthFunc( gl.LEQUAL );
  11194. }
  11195. } else {
  11196. gl.depthFunc( gl.LEQUAL );
  11197. }
  11198. currentDepthFunc = depthFunc;
  11199. }
  11200. },
  11201. setLocked: function ( lock ) {
  11202. locked = lock;
  11203. },
  11204. setClear: function ( depth ) {
  11205. if ( currentDepthClear !== depth ) {
  11206. gl.clearDepth( depth );
  11207. currentDepthClear = depth;
  11208. }
  11209. },
  11210. reset: function () {
  11211. locked = false;
  11212. currentDepthMask = null;
  11213. currentDepthFunc = null;
  11214. currentDepthClear = null;
  11215. }
  11216. };
  11217. }
  11218. function StencilBuffer() {
  11219. var locked = false;
  11220. var currentStencilMask = null;
  11221. var currentStencilFunc = null;
  11222. var currentStencilRef = null;
  11223. var currentStencilFuncMask = null;
  11224. var currentStencilFail = null;
  11225. var currentStencilZFail = null;
  11226. var currentStencilZPass = null;
  11227. var currentStencilClear = null;
  11228. return {
  11229. setTest: function ( stencilTest ) {
  11230. if ( stencilTest ) {
  11231. enable( gl.STENCIL_TEST );
  11232. } else {
  11233. disable( gl.STENCIL_TEST );
  11234. }
  11235. },
  11236. setMask: function ( stencilMask ) {
  11237. if ( currentStencilMask !== stencilMask && ! locked ) {
  11238. gl.stencilMask( stencilMask );
  11239. currentStencilMask = stencilMask;
  11240. }
  11241. },
  11242. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11243. if ( currentStencilFunc !== stencilFunc ||
  11244. currentStencilRef !== stencilRef ||
  11245. currentStencilFuncMask !== stencilMask ) {
  11246. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11247. currentStencilFunc = stencilFunc;
  11248. currentStencilRef = stencilRef;
  11249. currentStencilFuncMask = stencilMask;
  11250. }
  11251. },
  11252. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11253. if ( currentStencilFail !== stencilFail ||
  11254. currentStencilZFail !== stencilZFail ||
  11255. currentStencilZPass !== stencilZPass ) {
  11256. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11257. currentStencilFail = stencilFail;
  11258. currentStencilZFail = stencilZFail;
  11259. currentStencilZPass = stencilZPass;
  11260. }
  11261. },
  11262. setLocked: function ( lock ) {
  11263. locked = lock;
  11264. },
  11265. setClear: function ( stencil ) {
  11266. if ( currentStencilClear !== stencil ) {
  11267. gl.clearStencil( stencil );
  11268. currentStencilClear = stencil;
  11269. }
  11270. },
  11271. reset: function () {
  11272. locked = false;
  11273. currentStencilMask = null;
  11274. currentStencilFunc = null;
  11275. currentStencilRef = null;
  11276. currentStencilFuncMask = null;
  11277. currentStencilFail = null;
  11278. currentStencilZFail = null;
  11279. currentStencilZPass = null;
  11280. currentStencilClear = null;
  11281. }
  11282. };
  11283. }
  11284. //
  11285. var colorBuffer = new ColorBuffer();
  11286. var depthBuffer = new DepthBuffer();
  11287. var stencilBuffer = new StencilBuffer();
  11288. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11289. var newAttributes = new Uint8Array( maxVertexAttributes );
  11290. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11291. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11292. var capabilities = {};
  11293. var compressedTextureFormats = null;
  11294. var currentBlending = null;
  11295. var currentBlendEquation = null;
  11296. var currentBlendSrc = null;
  11297. var currentBlendDst = null;
  11298. var currentBlendEquationAlpha = null;
  11299. var currentBlendSrcAlpha = null;
  11300. var currentBlendDstAlpha = null;
  11301. var currentPremultipledAlpha = false;
  11302. var currentFlipSided = null;
  11303. var currentCullFace = null;
  11304. var currentLineWidth = null;
  11305. var currentPolygonOffsetFactor = null;
  11306. var currentPolygonOffsetUnits = null;
  11307. var currentScissorTest = null;
  11308. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  11309. var version = parseFloat( /^WebGL\ ([0-9])/.exec( gl.getParameter( gl.VERSION ) )[ 1 ] );
  11310. var lineWidthAvailable = parseFloat( version ) >= 1.0;
  11311. var currentTextureSlot = null;
  11312. var currentBoundTextures = {};
  11313. var currentScissor = new Vector4();
  11314. var currentViewport = new Vector4();
  11315. function createTexture( type, target, count ) {
  11316. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11317. var texture = gl.createTexture();
  11318. gl.bindTexture( type, texture );
  11319. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  11320. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  11321. for ( var i = 0; i < count; i ++ ) {
  11322. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  11323. }
  11324. return texture;
  11325. }
  11326. var emptyTextures = {};
  11327. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  11328. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  11329. //
  11330. function init() {
  11331. colorBuffer.setClear( 0, 0, 0, 1 );
  11332. depthBuffer.setClear( 1 );
  11333. stencilBuffer.setClear( 0 );
  11334. enable( gl.DEPTH_TEST );
  11335. depthBuffer.setFunc( LessEqualDepth );
  11336. setFlipSided( false );
  11337. setCullFace( CullFaceBack );
  11338. enable( gl.CULL_FACE );
  11339. enable( gl.BLEND );
  11340. setBlending( NormalBlending );
  11341. }
  11342. function initAttributes() {
  11343. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11344. newAttributes[ i ] = 0;
  11345. }
  11346. }
  11347. function enableAttribute( attribute ) {
  11348. newAttributes[ attribute ] = 1;
  11349. if ( enabledAttributes[ attribute ] === 0 ) {
  11350. gl.enableVertexAttribArray( attribute );
  11351. enabledAttributes[ attribute ] = 1;
  11352. }
  11353. if ( attributeDivisors[ attribute ] !== 0 ) {
  11354. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11355. extension.vertexAttribDivisorANGLE( attribute, 0 );
  11356. attributeDivisors[ attribute ] = 0;
  11357. }
  11358. }
  11359. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11360. newAttributes[ attribute ] = 1;
  11361. if ( enabledAttributes[ attribute ] === 0 ) {
  11362. gl.enableVertexAttribArray( attribute );
  11363. enabledAttributes[ attribute ] = 1;
  11364. }
  11365. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11366. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11367. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  11368. attributeDivisors[ attribute ] = meshPerAttribute;
  11369. }
  11370. }
  11371. function disableUnusedAttributes() {
  11372. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11373. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11374. gl.disableVertexAttribArray( i );
  11375. enabledAttributes[ i ] = 0;
  11376. }
  11377. }
  11378. }
  11379. function enable( id ) {
  11380. if ( capabilities[ id ] !== true ) {
  11381. gl.enable( id );
  11382. capabilities[ id ] = true;
  11383. }
  11384. }
  11385. function disable( id ) {
  11386. if ( capabilities[ id ] !== false ) {
  11387. gl.disable( id );
  11388. capabilities[ id ] = false;
  11389. }
  11390. }
  11391. function getCompressedTextureFormats() {
  11392. if ( compressedTextureFormats === null ) {
  11393. compressedTextureFormats = [];
  11394. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11395. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11396. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  11397. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  11398. for ( var i = 0; i < formats.length; i ++ ) {
  11399. compressedTextureFormats.push( formats[ i ] );
  11400. }
  11401. }
  11402. }
  11403. return compressedTextureFormats;
  11404. }
  11405. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11406. if ( blending !== NoBlending ) {
  11407. enable( gl.BLEND );
  11408. } else {
  11409. disable( gl.BLEND );
  11410. }
  11411. if ( ( blending !== CustomBlending ) && ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) ) {
  11412. if ( blending === AdditiveBlending ) {
  11413. if ( premultipliedAlpha ) {
  11414. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11415. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  11416. } else {
  11417. gl.blendEquation( gl.FUNC_ADD );
  11418. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  11419. }
  11420. } else if ( blending === SubtractiveBlending ) {
  11421. if ( premultipliedAlpha ) {
  11422. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11423. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  11424. } else {
  11425. gl.blendEquation( gl.FUNC_ADD );
  11426. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  11427. }
  11428. } else if ( blending === MultiplyBlending ) {
  11429. if ( premultipliedAlpha ) {
  11430. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11431. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  11432. } else {
  11433. gl.blendEquation( gl.FUNC_ADD );
  11434. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  11435. }
  11436. } else {
  11437. if ( premultipliedAlpha ) {
  11438. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11439. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11440. } else {
  11441. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11442. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11443. }
  11444. }
  11445. currentBlending = blending;
  11446. currentPremultipledAlpha = premultipliedAlpha;
  11447. }
  11448. if ( blending === CustomBlending ) {
  11449. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11450. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11451. blendDstAlpha = blendDstAlpha || blendDst;
  11452. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11453. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  11454. currentBlendEquation = blendEquation;
  11455. currentBlendEquationAlpha = blendEquationAlpha;
  11456. }
  11457. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11458. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  11459. currentBlendSrc = blendSrc;
  11460. currentBlendDst = blendDst;
  11461. currentBlendSrcAlpha = blendSrcAlpha;
  11462. currentBlendDstAlpha = blendDstAlpha;
  11463. }
  11464. } else {
  11465. currentBlendEquation = null;
  11466. currentBlendSrc = null;
  11467. currentBlendDst = null;
  11468. currentBlendEquationAlpha = null;
  11469. currentBlendSrcAlpha = null;
  11470. currentBlendDstAlpha = null;
  11471. }
  11472. }
  11473. function setMaterial( material ) {
  11474. material.side === DoubleSide
  11475. ? disable( gl.CULL_FACE )
  11476. : enable( gl.CULL_FACE );
  11477. setFlipSided( material.side === BackSide );
  11478. material.transparent === true
  11479. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  11480. : setBlending( NoBlending );
  11481. depthBuffer.setFunc( material.depthFunc );
  11482. depthBuffer.setTest( material.depthTest );
  11483. depthBuffer.setMask( material.depthWrite );
  11484. colorBuffer.setMask( material.colorWrite );
  11485. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11486. }
  11487. //
  11488. function setFlipSided( flipSided ) {
  11489. if ( currentFlipSided !== flipSided ) {
  11490. if ( flipSided ) {
  11491. gl.frontFace( gl.CW );
  11492. } else {
  11493. gl.frontFace( gl.CCW );
  11494. }
  11495. currentFlipSided = flipSided;
  11496. }
  11497. }
  11498. function setCullFace( cullFace ) {
  11499. if ( cullFace !== CullFaceNone ) {
  11500. enable( gl.CULL_FACE );
  11501. if ( cullFace !== currentCullFace ) {
  11502. if ( cullFace === CullFaceBack ) {
  11503. gl.cullFace( gl.BACK );
  11504. } else if ( cullFace === CullFaceFront ) {
  11505. gl.cullFace( gl.FRONT );
  11506. } else {
  11507. gl.cullFace( gl.FRONT_AND_BACK );
  11508. }
  11509. }
  11510. } else {
  11511. disable( gl.CULL_FACE );
  11512. }
  11513. currentCullFace = cullFace;
  11514. }
  11515. function setLineWidth( width ) {
  11516. if ( width !== currentLineWidth ) {
  11517. if ( lineWidthAvailable ) gl.lineWidth( width );
  11518. currentLineWidth = width;
  11519. }
  11520. }
  11521. function setPolygonOffset( polygonOffset, factor, units ) {
  11522. if ( polygonOffset ) {
  11523. enable( gl.POLYGON_OFFSET_FILL );
  11524. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11525. gl.polygonOffset( factor, units );
  11526. currentPolygonOffsetFactor = factor;
  11527. currentPolygonOffsetUnits = units;
  11528. }
  11529. } else {
  11530. disable( gl.POLYGON_OFFSET_FILL );
  11531. }
  11532. }
  11533. function getScissorTest() {
  11534. return currentScissorTest;
  11535. }
  11536. function setScissorTest( scissorTest ) {
  11537. currentScissorTest = scissorTest;
  11538. if ( scissorTest ) {
  11539. enable( gl.SCISSOR_TEST );
  11540. } else {
  11541. disable( gl.SCISSOR_TEST );
  11542. }
  11543. }
  11544. // texture
  11545. function activeTexture( webglSlot ) {
  11546. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  11547. if ( currentTextureSlot !== webglSlot ) {
  11548. gl.activeTexture( webglSlot );
  11549. currentTextureSlot = webglSlot;
  11550. }
  11551. }
  11552. function bindTexture( webglType, webglTexture ) {
  11553. if ( currentTextureSlot === null ) {
  11554. activeTexture();
  11555. }
  11556. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11557. if ( boundTexture === undefined ) {
  11558. boundTexture = { type: undefined, texture: undefined };
  11559. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11560. }
  11561. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11562. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11563. boundTexture.type = webglType;
  11564. boundTexture.texture = webglTexture;
  11565. }
  11566. }
  11567. function compressedTexImage2D() {
  11568. try {
  11569. gl.compressedTexImage2D.apply( gl, arguments );
  11570. } catch ( error ) {
  11571. console.error( 'THREE.WebGLState:', error );
  11572. }
  11573. }
  11574. function texImage2D() {
  11575. try {
  11576. gl.texImage2D.apply( gl, arguments );
  11577. } catch ( error ) {
  11578. console.error( 'THREE.WebGLState:', error );
  11579. }
  11580. }
  11581. //
  11582. function scissor( scissor ) {
  11583. if ( currentScissor.equals( scissor ) === false ) {
  11584. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11585. currentScissor.copy( scissor );
  11586. }
  11587. }
  11588. function viewport( viewport ) {
  11589. if ( currentViewport.equals( viewport ) === false ) {
  11590. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11591. currentViewport.copy( viewport );
  11592. }
  11593. }
  11594. //
  11595. function reset() {
  11596. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11597. if ( enabledAttributes[ i ] === 1 ) {
  11598. gl.disableVertexAttribArray( i );
  11599. enabledAttributes[ i ] = 0;
  11600. }
  11601. }
  11602. capabilities = {};
  11603. compressedTextureFormats = null;
  11604. currentTextureSlot = null;
  11605. currentBoundTextures = {};
  11606. currentBlending = null;
  11607. currentFlipSided = null;
  11608. currentCullFace = null;
  11609. colorBuffer.reset();
  11610. depthBuffer.reset();
  11611. stencilBuffer.reset();
  11612. }
  11613. return {
  11614. buffers: {
  11615. color: colorBuffer,
  11616. depth: depthBuffer,
  11617. stencil: stencilBuffer
  11618. },
  11619. init: init,
  11620. initAttributes: initAttributes,
  11621. enableAttribute: enableAttribute,
  11622. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11623. disableUnusedAttributes: disableUnusedAttributes,
  11624. enable: enable,
  11625. disable: disable,
  11626. getCompressedTextureFormats: getCompressedTextureFormats,
  11627. setBlending: setBlending,
  11628. setMaterial: setMaterial,
  11629. setFlipSided: setFlipSided,
  11630. setCullFace: setCullFace,
  11631. setLineWidth: setLineWidth,
  11632. setPolygonOffset: setPolygonOffset,
  11633. getScissorTest: getScissorTest,
  11634. setScissorTest: setScissorTest,
  11635. activeTexture: activeTexture,
  11636. bindTexture: bindTexture,
  11637. compressedTexImage2D: compressedTexImage2D,
  11638. texImage2D: texImage2D,
  11639. scissor: scissor,
  11640. viewport: viewport,
  11641. reset: reset
  11642. };
  11643. }
  11644. /**
  11645. * @author mrdoob / http://mrdoob.com/
  11646. */
  11647. function WebGLCapabilities( gl, extensions, parameters ) {
  11648. var maxAnisotropy;
  11649. function getMaxAnisotropy() {
  11650. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  11651. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11652. if ( extension !== null ) {
  11653. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11654. } else {
  11655. maxAnisotropy = 0;
  11656. }
  11657. return maxAnisotropy;
  11658. }
  11659. function getMaxPrecision( precision ) {
  11660. if ( precision === 'highp' ) {
  11661. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  11662. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  11663. return 'highp';
  11664. }
  11665. precision = 'mediump';
  11666. }
  11667. if ( precision === 'mediump' ) {
  11668. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  11669. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  11670. return 'mediump';
  11671. }
  11672. }
  11673. return 'lowp';
  11674. }
  11675. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  11676. var maxPrecision = getMaxPrecision( precision );
  11677. if ( maxPrecision !== precision ) {
  11678. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  11679. precision = maxPrecision;
  11680. }
  11681. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true && !! extensions.get( 'EXT_frag_depth' );
  11682. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  11683. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11684. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  11685. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11686. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11687. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  11688. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  11689. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  11690. var vertexTextures = maxVertexTextures > 0;
  11691. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  11692. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  11693. return {
  11694. getMaxAnisotropy: getMaxAnisotropy,
  11695. getMaxPrecision: getMaxPrecision,
  11696. precision: precision,
  11697. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11698. maxTextures: maxTextures,
  11699. maxVertexTextures: maxVertexTextures,
  11700. maxTextureSize: maxTextureSize,
  11701. maxCubemapSize: maxCubemapSize,
  11702. maxAttributes: maxAttributes,
  11703. maxVertexUniforms: maxVertexUniforms,
  11704. maxVaryings: maxVaryings,
  11705. maxFragmentUniforms: maxFragmentUniforms,
  11706. vertexTextures: vertexTextures,
  11707. floatFragmentTextures: floatFragmentTextures,
  11708. floatVertexTextures: floatVertexTextures
  11709. };
  11710. }
  11711. /**
  11712. * @author mrdoob / http://mrdoob.com/
  11713. */
  11714. function WebGLExtensions( gl ) {
  11715. var extensions = {};
  11716. return {
  11717. get: function ( name ) {
  11718. if ( extensions[ name ] !== undefined ) {
  11719. return extensions[ name ];
  11720. }
  11721. var extension;
  11722. switch ( name ) {
  11723. case 'WEBGL_depth_texture':
  11724. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  11725. break;
  11726. case 'EXT_texture_filter_anisotropic':
  11727. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  11728. break;
  11729. case 'WEBGL_compressed_texture_s3tc':
  11730. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  11731. break;
  11732. case 'WEBGL_compressed_texture_pvrtc':
  11733. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  11734. break;
  11735. case 'WEBGL_compressed_texture_etc1':
  11736. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  11737. break;
  11738. default:
  11739. extension = gl.getExtension( name );
  11740. }
  11741. if ( extension === null ) {
  11742. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  11743. }
  11744. extensions[ name ] = extension;
  11745. return extension;
  11746. }
  11747. };
  11748. }
  11749. /**
  11750. * @author tschw
  11751. */
  11752. function WebGLClipping() {
  11753. var scope = this,
  11754. globalState = null,
  11755. numGlobalPlanes = 0,
  11756. localClippingEnabled = false,
  11757. renderingShadows = false,
  11758. plane = new Plane(),
  11759. viewNormalMatrix = new Matrix3(),
  11760. uniform = { value: null, needsUpdate: false };
  11761. this.uniform = uniform;
  11762. this.numPlanes = 0;
  11763. this.numIntersection = 0;
  11764. this.init = function( planes, enableLocalClipping, camera ) {
  11765. var enabled =
  11766. planes.length !== 0 ||
  11767. enableLocalClipping ||
  11768. // enable state of previous frame - the clipping code has to
  11769. // run another frame in order to reset the state:
  11770. numGlobalPlanes !== 0 ||
  11771. localClippingEnabled;
  11772. localClippingEnabled = enableLocalClipping;
  11773. globalState = projectPlanes( planes, camera, 0 );
  11774. numGlobalPlanes = planes.length;
  11775. return enabled;
  11776. };
  11777. this.beginShadows = function() {
  11778. renderingShadows = true;
  11779. projectPlanes( null );
  11780. };
  11781. this.endShadows = function() {
  11782. renderingShadows = false;
  11783. resetGlobalState();
  11784. };
  11785. this.setState = function( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  11786. if ( ! localClippingEnabled ||
  11787. planes === null || planes.length === 0 ||
  11788. renderingShadows && ! clipShadows ) {
  11789. // there's no local clipping
  11790. if ( renderingShadows ) {
  11791. // there's no global clipping
  11792. projectPlanes( null );
  11793. } else {
  11794. resetGlobalState();
  11795. }
  11796. } else {
  11797. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  11798. lGlobal = nGlobal * 4,
  11799. dstArray = cache.clippingState || null;
  11800. uniform.value = dstArray; // ensure unique state
  11801. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  11802. for ( var i = 0; i !== lGlobal; ++ i ) {
  11803. dstArray[ i ] = globalState[ i ];
  11804. }
  11805. cache.clippingState = dstArray;
  11806. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  11807. this.numPlanes += nGlobal;
  11808. }
  11809. };
  11810. function resetGlobalState() {
  11811. if ( uniform.value !== globalState ) {
  11812. uniform.value = globalState;
  11813. uniform.needsUpdate = numGlobalPlanes > 0;
  11814. }
  11815. scope.numPlanes = numGlobalPlanes;
  11816. scope.numIntersection = 0;
  11817. }
  11818. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  11819. var nPlanes = planes !== null ? planes.length : 0,
  11820. dstArray = null;
  11821. if ( nPlanes !== 0 ) {
  11822. dstArray = uniform.value;
  11823. if ( skipTransform !== true || dstArray === null ) {
  11824. var flatSize = dstOffset + nPlanes * 4,
  11825. viewMatrix = camera.matrixWorldInverse;
  11826. viewNormalMatrix.getNormalMatrix( viewMatrix );
  11827. if ( dstArray === null || dstArray.length < flatSize ) {
  11828. dstArray = new Float32Array( flatSize );
  11829. }
  11830. for ( var i = 0, i4 = dstOffset;
  11831. i !== nPlanes; ++ i, i4 += 4 ) {
  11832. plane.copy( planes[ i ] ).
  11833. applyMatrix4( viewMatrix, viewNormalMatrix );
  11834. plane.normal.toArray( dstArray, i4 );
  11835. dstArray[ i4 + 3 ] = plane.constant;
  11836. }
  11837. }
  11838. uniform.value = dstArray;
  11839. uniform.needsUpdate = true;
  11840. }
  11841. scope.numPlanes = nPlanes;
  11842. return dstArray;
  11843. }
  11844. }
  11845. // import { Sphere } from '../math/Sphere';
  11846. /**
  11847. * @author supereggbert / http://www.paulbrunt.co.uk/
  11848. * @author mrdoob / http://mrdoob.com/
  11849. * @author alteredq / http://alteredqualia.com/
  11850. * @author szimek / https://github.com/szimek/
  11851. * @author tschw
  11852. */
  11853. function WebGLRenderer( parameters ) {
  11854. console.log( 'THREE.WebGLRenderer', REVISION );
  11855. parameters = parameters || {};
  11856. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  11857. _context = parameters.context !== undefined ? parameters.context : null,
  11858. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11859. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11860. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11861. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11862. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11863. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  11864. var lights = [];
  11865. var currentRenderList = null;
  11866. var morphInfluences = new Float32Array( 8 );
  11867. var sprites = [];
  11868. var lensFlares = [];
  11869. // public properties
  11870. this.domElement = _canvas;
  11871. this.context = null;
  11872. // clearing
  11873. this.autoClear = true;
  11874. this.autoClearColor = true;
  11875. this.autoClearDepth = true;
  11876. this.autoClearStencil = true;
  11877. // scene graph
  11878. this.sortObjects = true;
  11879. // user-defined clipping
  11880. this.clippingPlanes = [];
  11881. this.localClippingEnabled = false;
  11882. // physically based shading
  11883. this.gammaFactor = 2.0; // for backwards compatibility
  11884. this.gammaInput = false;
  11885. this.gammaOutput = false;
  11886. // physical lights
  11887. this.physicallyCorrectLights = false;
  11888. // tone mapping
  11889. this.toneMapping = LinearToneMapping;
  11890. this.toneMappingExposure = 1.0;
  11891. this.toneMappingWhitePoint = 1.0;
  11892. // morphs
  11893. this.maxMorphTargets = 8;
  11894. this.maxMorphNormals = 4;
  11895. // internal properties
  11896. var _this = this,
  11897. // internal state cache
  11898. _currentProgram = null,
  11899. _currentRenderTarget = null,
  11900. _currentFramebuffer = null,
  11901. _currentMaterialId = - 1,
  11902. _currentGeometryProgram = '',
  11903. _currentCamera = null,
  11904. _currentScissor = new Vector4(),
  11905. _currentScissorTest = null,
  11906. _currentViewport = new Vector4(),
  11907. //
  11908. _usedTextureUnits = 0,
  11909. //
  11910. _clearColor = new Color( 0x000000 ),
  11911. _clearAlpha = 0,
  11912. _width = _canvas.width,
  11913. _height = _canvas.height,
  11914. _pixelRatio = 1,
  11915. _scissor = new Vector4( 0, 0, _width, _height ),
  11916. _scissorTest = false,
  11917. _viewport = new Vector4( 0, 0, _width, _height ),
  11918. // frustum
  11919. _frustum = new Frustum(),
  11920. // clipping
  11921. _clipping = new WebGLClipping(),
  11922. _clippingEnabled = false,
  11923. _localClippingEnabled = false,
  11924. // camera matrices cache
  11925. _projScreenMatrix = new Matrix4(),
  11926. _vector3 = new Vector3(),
  11927. _matrix4 = new Matrix4(),
  11928. _matrix42 = new Matrix4(),
  11929. // light arrays cache
  11930. _lights = {
  11931. hash: '',
  11932. ambient: [ 0, 0, 0 ],
  11933. directional: [],
  11934. directionalShadowMap: [],
  11935. directionalShadowMatrix: [],
  11936. spot: [],
  11937. spotShadowMap: [],
  11938. spotShadowMatrix: [],
  11939. rectArea: [],
  11940. point: [],
  11941. pointShadowMap: [],
  11942. pointShadowMatrix: [],
  11943. hemi: [],
  11944. shadows: []
  11945. },
  11946. // info
  11947. _infoMemory = {
  11948. geometries: 0,
  11949. textures: 0
  11950. },
  11951. _infoRender = {
  11952. frame: 0,
  11953. calls: 0,
  11954. vertices: 0,
  11955. faces: 0,
  11956. points: 0
  11957. };
  11958. this.info = {
  11959. render: _infoRender,
  11960. memory: _infoMemory,
  11961. programs: null
  11962. };
  11963. // initialize
  11964. var _gl;
  11965. try {
  11966. var contextAttributes = {
  11967. alpha: _alpha,
  11968. depth: _depth,
  11969. stencil: _stencil,
  11970. antialias: _antialias,
  11971. premultipliedAlpha: _premultipliedAlpha,
  11972. preserveDrawingBuffer: _preserveDrawingBuffer
  11973. };
  11974. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  11975. if ( _gl === null ) {
  11976. if ( _canvas.getContext( 'webgl' ) !== null ) {
  11977. throw 'Error creating WebGL context with your selected attributes.';
  11978. } else {
  11979. throw 'Error creating WebGL context.';
  11980. }
  11981. }
  11982. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  11983. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11984. _gl.getShaderPrecisionFormat = function () {
  11985. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  11986. };
  11987. }
  11988. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  11989. } catch ( error ) {
  11990. console.error( 'THREE.WebGLRenderer: ' + error );
  11991. }
  11992. var extensions = new WebGLExtensions( _gl );
  11993. extensions.get( 'WEBGL_depth_texture' );
  11994. extensions.get( 'OES_texture_float' );
  11995. extensions.get( 'OES_texture_float_linear' );
  11996. extensions.get( 'OES_texture_half_float' );
  11997. extensions.get( 'OES_texture_half_float_linear' );
  11998. extensions.get( 'OES_standard_derivatives' );
  11999. extensions.get( 'ANGLE_instanced_arrays' );
  12000. if ( extensions.get( 'OES_element_index_uint' ) ) {
  12001. BufferGeometry.MaxIndex = 4294967296;
  12002. }
  12003. var capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  12004. var state = new WebGLState( _gl, extensions, paramThreeToGL );
  12005. var properties = new WebGLProperties();
  12006. var textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, _infoMemory );
  12007. var attributes = new WebGLAttributes( _gl );
  12008. var geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
  12009. var objects = new WebGLObjects( _gl, geometries, _infoRender );
  12010. var programCache = new WebGLPrograms( this, capabilities );
  12011. var lightCache = new WebGLLights();
  12012. var renderLists = new WebGLRenderLists();
  12013. this.info.programs = programCache.programs;
  12014. var bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
  12015. var indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12016. //
  12017. var backgroundPlaneCamera, backgroundPlaneMesh;
  12018. var backgroundBoxCamera, backgroundBoxMesh;
  12019. //
  12020. function getTargetPixelRatio() {
  12021. return _currentRenderTarget === null ? _pixelRatio : 1;
  12022. }
  12023. function setDefaultGLState() {
  12024. state.init();
  12025. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  12026. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  12027. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12028. }
  12029. function resetGLState() {
  12030. _currentProgram = null;
  12031. _currentCamera = null;
  12032. _currentGeometryProgram = '';
  12033. _currentMaterialId = - 1;
  12034. state.reset();
  12035. }
  12036. setDefaultGLState();
  12037. this.context = _gl;
  12038. this.capabilities = capabilities;
  12039. this.extensions = extensions;
  12040. this.properties = properties;
  12041. this.state = state;
  12042. // shadow map
  12043. var shadowMap = new WebGLShadowMap( this, _lights, objects, capabilities );
  12044. this.shadowMap = shadowMap;
  12045. // Plugins
  12046. var spritePlugin = new SpritePlugin( this, sprites );
  12047. var lensFlarePlugin = new LensFlarePlugin( this, lensFlares );
  12048. // API
  12049. this.getContext = function () {
  12050. return _gl;
  12051. };
  12052. this.getContextAttributes = function () {
  12053. return _gl.getContextAttributes();
  12054. };
  12055. this.forceContextLoss = function () {
  12056. var extension = extensions.get( 'WEBGL_lose_context' );
  12057. if ( extension ) extension.loseContext();
  12058. };
  12059. this.getMaxAnisotropy = function () {
  12060. return capabilities.getMaxAnisotropy();
  12061. };
  12062. this.getPrecision = function () {
  12063. return capabilities.precision;
  12064. };
  12065. this.getPixelRatio = function () {
  12066. return _pixelRatio;
  12067. };
  12068. this.setPixelRatio = function ( value ) {
  12069. if ( value === undefined ) return;
  12070. _pixelRatio = value;
  12071. this.setSize( _width, _height, false );
  12072. };
  12073. this.getSize = function () {
  12074. return {
  12075. width: _width,
  12076. height: _height
  12077. };
  12078. };
  12079. this.setSize = function ( width, height, updateStyle ) {
  12080. _width = width;
  12081. _height = height;
  12082. _canvas.width = width * _pixelRatio;
  12083. _canvas.height = height * _pixelRatio;
  12084. if ( updateStyle !== false ) {
  12085. _canvas.style.width = width + 'px';
  12086. _canvas.style.height = height + 'px';
  12087. }
  12088. this.setViewport( 0, 0, width, height );
  12089. };
  12090. this.setViewport = function ( x, y, width, height ) {
  12091. _viewport.set( x, _height - y - height, width, height );
  12092. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  12093. };
  12094. this.setScissor = function ( x, y, width, height ) {
  12095. _scissor.set( x, _height - y - height, width, height );
  12096. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  12097. };
  12098. this.setScissorTest = function ( boolean ) {
  12099. state.setScissorTest( _scissorTest = boolean );
  12100. };
  12101. // Clearing
  12102. this.getClearColor = function () {
  12103. return _clearColor;
  12104. };
  12105. this.setClearColor = function ( color, alpha ) {
  12106. _clearColor.set( color );
  12107. _clearAlpha = alpha !== undefined ? alpha : 1;
  12108. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12109. };
  12110. this.getClearAlpha = function () {
  12111. return _clearAlpha;
  12112. };
  12113. this.setClearAlpha = function ( alpha ) {
  12114. _clearAlpha = alpha;
  12115. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12116. };
  12117. this.clear = function ( color, depth, stencil ) {
  12118. var bits = 0;
  12119. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12120. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12121. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12122. _gl.clear( bits );
  12123. };
  12124. this.clearColor = function () {
  12125. this.clear( true, false, false );
  12126. };
  12127. this.clearDepth = function () {
  12128. this.clear( false, true, false );
  12129. };
  12130. this.clearStencil = function () {
  12131. this.clear( false, false, true );
  12132. };
  12133. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12134. this.setRenderTarget( renderTarget );
  12135. this.clear( color, depth, stencil );
  12136. };
  12137. // Reset
  12138. this.resetGLState = resetGLState;
  12139. this.dispose = function () {
  12140. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12141. renderLists.dispose();
  12142. };
  12143. // Events
  12144. function onContextLost( event ) {
  12145. event.preventDefault();
  12146. resetGLState();
  12147. setDefaultGLState();
  12148. properties.clear();
  12149. objects.clear();
  12150. }
  12151. function onMaterialDispose( event ) {
  12152. var material = event.target;
  12153. material.removeEventListener( 'dispose', onMaterialDispose );
  12154. deallocateMaterial( material );
  12155. }
  12156. // Buffer deallocation
  12157. function deallocateMaterial( material ) {
  12158. releaseMaterialProgramReference( material );
  12159. properties.remove( material );
  12160. }
  12161. function releaseMaterialProgramReference( material ) {
  12162. var programInfo = properties.get( material ).program;
  12163. material.program = undefined;
  12164. if ( programInfo !== undefined ) {
  12165. programCache.releaseProgram( programInfo );
  12166. }
  12167. }
  12168. // Buffer rendering
  12169. function renderObjectImmediate( object, program, material ) {
  12170. object.render( function ( object ) {
  12171. _this.renderBufferImmediate( object, program, material );
  12172. } );
  12173. }
  12174. this.renderBufferImmediate = function ( object, program, material ) {
  12175. state.initAttributes();
  12176. var buffers = properties.get( object );
  12177. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  12178. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  12179. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  12180. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  12181. var programAttributes = program.getAttributes();
  12182. if ( object.hasPositions ) {
  12183. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  12184. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12185. state.enableAttribute( programAttributes.position );
  12186. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12187. }
  12188. if ( object.hasNormals ) {
  12189. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  12190. if ( ! material.isMeshPhongMaterial &&
  12191. ! material.isMeshStandardMaterial &&
  12192. ! material.isMeshNormalMaterial &&
  12193. material.shading === FlatShading ) {
  12194. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  12195. var array = object.normalArray;
  12196. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  12197. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  12198. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  12199. array[ i + 0 ] = nx;
  12200. array[ i + 1 ] = ny;
  12201. array[ i + 2 ] = nz;
  12202. array[ i + 3 ] = nx;
  12203. array[ i + 4 ] = ny;
  12204. array[ i + 5 ] = nz;
  12205. array[ i + 6 ] = nx;
  12206. array[ i + 7 ] = ny;
  12207. array[ i + 8 ] = nz;
  12208. }
  12209. }
  12210. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12211. state.enableAttribute( programAttributes.normal );
  12212. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12213. }
  12214. if ( object.hasUvs && material.map ) {
  12215. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  12216. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12217. state.enableAttribute( programAttributes.uv );
  12218. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12219. }
  12220. if ( object.hasColors && material.vertexColors !== NoColors ) {
  12221. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  12222. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12223. state.enableAttribute( programAttributes.color );
  12224. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12225. }
  12226. state.disableUnusedAttributes();
  12227. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12228. object.count = 0;
  12229. };
  12230. function absNumericalSort( a, b ) {
  12231. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  12232. }
  12233. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  12234. state.setMaterial( material );
  12235. var program = setProgram( camera, fog, material, object );
  12236. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  12237. var updateBuffers = false;
  12238. if ( geometryProgram !== _currentGeometryProgram ) {
  12239. _currentGeometryProgram = geometryProgram;
  12240. updateBuffers = true;
  12241. }
  12242. // morph targets
  12243. var morphTargetInfluences = object.morphTargetInfluences;
  12244. if ( morphTargetInfluences !== undefined ) {
  12245. // TODO Remove allocations
  12246. var activeInfluences = [];
  12247. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  12248. var influence = morphTargetInfluences[ i ];
  12249. activeInfluences.push( [ influence, i ] );
  12250. }
  12251. activeInfluences.sort( absNumericalSort );
  12252. if ( activeInfluences.length > 8 ) {
  12253. activeInfluences.length = 8;
  12254. }
  12255. var morphAttributes = geometry.morphAttributes;
  12256. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  12257. var influence = activeInfluences[ i ];
  12258. morphInfluences[ i ] = influence[ 0 ];
  12259. if ( influence[ 0 ] !== 0 ) {
  12260. var index = influence[ 1 ];
  12261. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  12262. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  12263. } else {
  12264. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  12265. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  12266. }
  12267. }
  12268. for ( var i = activeInfluences.length, il = morphInfluences.length; i < il; i ++ ) {
  12269. morphInfluences[ i ] = 0.0;
  12270. }
  12271. program.getUniforms().setValue( _gl, 'morphTargetInfluences', morphInfluences );
  12272. updateBuffers = true;
  12273. }
  12274. //
  12275. var index = geometry.index;
  12276. var position = geometry.attributes.position;
  12277. var rangeFactor = 1;
  12278. if ( material.wireframe === true ) {
  12279. index = geometries.getWireframeAttribute( geometry );
  12280. rangeFactor = 2;
  12281. }
  12282. var attribute;
  12283. var renderer = bufferRenderer;
  12284. if ( index !== null ) {
  12285. attribute = attributes.get( index );
  12286. renderer = indexedBufferRenderer;
  12287. renderer.setIndex( attribute );
  12288. }
  12289. if ( updateBuffers ) {
  12290. setupVertexAttributes( material, program, geometry );
  12291. if ( index !== null ) {
  12292. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  12293. }
  12294. }
  12295. //
  12296. var dataCount = 0;
  12297. if ( index !== null ) {
  12298. dataCount = index.count;
  12299. } else if ( position !== undefined ) {
  12300. dataCount = position.count;
  12301. }
  12302. var rangeStart = geometry.drawRange.start * rangeFactor;
  12303. var rangeCount = geometry.drawRange.count * rangeFactor;
  12304. var groupStart = group !== null ? group.start * rangeFactor : 0;
  12305. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  12306. var drawStart = Math.max( rangeStart, groupStart );
  12307. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  12308. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  12309. if ( drawCount === 0 ) return;
  12310. //
  12311. if ( object.isMesh ) {
  12312. if ( material.wireframe === true ) {
  12313. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  12314. renderer.setMode( _gl.LINES );
  12315. } else {
  12316. switch ( object.drawMode ) {
  12317. case TrianglesDrawMode:
  12318. renderer.setMode( _gl.TRIANGLES );
  12319. break;
  12320. case TriangleStripDrawMode:
  12321. renderer.setMode( _gl.TRIANGLE_STRIP );
  12322. break;
  12323. case TriangleFanDrawMode:
  12324. renderer.setMode( _gl.TRIANGLE_FAN );
  12325. break;
  12326. }
  12327. }
  12328. } else if ( object.isLine ) {
  12329. var lineWidth = material.linewidth;
  12330. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  12331. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  12332. if ( object.isLineSegments ) {
  12333. renderer.setMode( _gl.LINES );
  12334. } else if ( object.isLineLoop ) {
  12335. renderer.setMode( _gl.LINE_LOOP );
  12336. } else {
  12337. renderer.setMode( _gl.LINE_STRIP );
  12338. }
  12339. } else if ( object.isPoints ) {
  12340. renderer.setMode( _gl.POINTS );
  12341. }
  12342. if ( geometry && geometry.isInstancedBufferGeometry ) {
  12343. if ( geometry.maxInstancedCount > 0 ) {
  12344. renderer.renderInstances( geometry, drawStart, drawCount );
  12345. }
  12346. } else {
  12347. renderer.render( drawStart, drawCount );
  12348. }
  12349. };
  12350. function setupVertexAttributes( material, program, geometry, startIndex ) {
  12351. if ( geometry && geometry.isInstancedBufferGeometry ) {
  12352. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  12353. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12354. return;
  12355. }
  12356. }
  12357. if ( startIndex === undefined ) startIndex = 0;
  12358. state.initAttributes();
  12359. var geometryAttributes = geometry.attributes;
  12360. var programAttributes = program.getAttributes();
  12361. var materialDefaultAttributeValues = material.defaultAttributeValues;
  12362. for ( var name in programAttributes ) {
  12363. var programAttribute = programAttributes[ name ];
  12364. if ( programAttribute >= 0 ) {
  12365. var geometryAttribute = geometryAttributes[ name ];
  12366. if ( geometryAttribute !== undefined ) {
  12367. var normalized = geometryAttribute.normalized;
  12368. var size = geometryAttribute.itemSize;
  12369. var attribute = attributes.get( geometryAttribute );
  12370. var buffer = attribute.buffer;
  12371. var type = attribute.type;
  12372. var bytesPerElement = attribute.bytesPerElement;
  12373. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  12374. var data = geometryAttribute.data;
  12375. var stride = data.stride;
  12376. var offset = geometryAttribute.offset;
  12377. if ( data && data.isInstancedInterleavedBuffer ) {
  12378. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  12379. if ( geometry.maxInstancedCount === undefined ) {
  12380. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  12381. }
  12382. } else {
  12383. state.enableAttribute( programAttribute );
  12384. }
  12385. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12386. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement );
  12387. } else {
  12388. if ( geometryAttribute.isInstancedBufferAttribute ) {
  12389. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  12390. if ( geometry.maxInstancedCount === undefined ) {
  12391. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  12392. }
  12393. } else {
  12394. state.enableAttribute( programAttribute );
  12395. }
  12396. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12397. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement );
  12398. }
  12399. } else if ( materialDefaultAttributeValues !== undefined ) {
  12400. var value = materialDefaultAttributeValues[ name ];
  12401. if ( value !== undefined ) {
  12402. switch ( value.length ) {
  12403. case 2:
  12404. _gl.vertexAttrib2fv( programAttribute, value );
  12405. break;
  12406. case 3:
  12407. _gl.vertexAttrib3fv( programAttribute, value );
  12408. break;
  12409. case 4:
  12410. _gl.vertexAttrib4fv( programAttribute, value );
  12411. break;
  12412. default:
  12413. _gl.vertexAttrib1fv( programAttribute, value );
  12414. }
  12415. }
  12416. }
  12417. }
  12418. }
  12419. state.disableUnusedAttributes();
  12420. }
  12421. // Compile
  12422. this.compile = function ( scene, camera ) {
  12423. lights = [];
  12424. scene.traverse( function ( object ) {
  12425. if ( object.isLight ) {
  12426. lights.push( object );
  12427. }
  12428. } );
  12429. setupLights( lights, camera );
  12430. scene.traverse( function ( object ) {
  12431. if ( object.material ) {
  12432. if ( Array.isArray( object.material ) ) {
  12433. for ( var i = 0; i < object.material.length; i ++ ) {
  12434. initMaterial( object.material[ i ], scene.fog, object );
  12435. }
  12436. } else {
  12437. initMaterial( object.material, scene.fog, object );
  12438. }
  12439. }
  12440. } );
  12441. };
  12442. // Rendering
  12443. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12444. if ( ! ( camera && camera.isCamera ) ) {
  12445. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12446. return;
  12447. }
  12448. // reset caching for this frame
  12449. _currentGeometryProgram = '';
  12450. _currentMaterialId = - 1;
  12451. _currentCamera = null;
  12452. // update scene graph
  12453. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12454. // update camera matrices and frustum
  12455. camera.onBeforeRender( _this );
  12456. if ( camera.parent === null ) camera.updateMatrixWorld();
  12457. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12458. _frustum.setFromMatrix( _projScreenMatrix );
  12459. lights.length = 0;
  12460. sprites.length = 0;
  12461. lensFlares.length = 0;
  12462. _localClippingEnabled = this.localClippingEnabled;
  12463. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  12464. currentRenderList = renderLists.get( scene, camera );
  12465. currentRenderList.init();
  12466. projectObject( scene, camera, _this.sortObjects );
  12467. currentRenderList.finish();
  12468. if ( _this.sortObjects === true ) {
  12469. currentRenderList.sort();
  12470. }
  12471. //
  12472. if ( _clippingEnabled ) _clipping.beginShadows();
  12473. setupShadows( lights );
  12474. shadowMap.render( scene, camera );
  12475. setupLights( lights, camera );
  12476. if ( _clippingEnabled ) _clipping.endShadows();
  12477. //
  12478. _infoRender.frame ++;
  12479. _infoRender.calls = 0;
  12480. _infoRender.vertices = 0;
  12481. _infoRender.faces = 0;
  12482. _infoRender.points = 0;
  12483. if ( renderTarget === undefined ) {
  12484. renderTarget = null;
  12485. }
  12486. this.setRenderTarget( renderTarget );
  12487. //
  12488. var background = scene.background;
  12489. if ( background === null ) {
  12490. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12491. } else if ( background && background.isColor ) {
  12492. state.buffers.color.setClear( background.r, background.g, background.b, 1, _premultipliedAlpha );
  12493. forceClear = true;
  12494. }
  12495. if ( this.autoClear || forceClear ) {
  12496. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12497. }
  12498. if ( background && background.isCubeTexture ) {
  12499. if ( backgroundBoxCamera === undefined ) {
  12500. backgroundBoxCamera = new PerspectiveCamera();
  12501. backgroundBoxMesh = new Mesh(
  12502. new BoxBufferGeometry( 5, 5, 5 ),
  12503. new ShaderMaterial( {
  12504. uniforms: ShaderLib.cube.uniforms,
  12505. vertexShader: ShaderLib.cube.vertexShader,
  12506. fragmentShader: ShaderLib.cube.fragmentShader,
  12507. side: BackSide,
  12508. depthTest: false,
  12509. depthWrite: false,
  12510. fog: false
  12511. } )
  12512. );
  12513. }
  12514. backgroundBoxCamera.projectionMatrix.copy( camera.projectionMatrix );
  12515. backgroundBoxCamera.matrixWorld.extractRotation( camera.matrixWorld );
  12516. backgroundBoxCamera.matrixWorldInverse.getInverse( backgroundBoxCamera.matrixWorld );
  12517. backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
  12518. backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundBoxCamera.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
  12519. objects.update( backgroundBoxMesh );
  12520. _this.renderBufferDirect( backgroundBoxCamera, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
  12521. } else if ( background && background.isTexture ) {
  12522. if ( backgroundPlaneCamera === undefined ) {
  12523. backgroundPlaneCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  12524. backgroundPlaneMesh = new Mesh(
  12525. new PlaneBufferGeometry( 2, 2 ),
  12526. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  12527. );
  12528. }
  12529. backgroundPlaneMesh.material.map = background;
  12530. objects.update( backgroundPlaneMesh );
  12531. _this.renderBufferDirect( backgroundPlaneCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
  12532. }
  12533. //
  12534. var opaqueObjects = currentRenderList.opaque;
  12535. var transparentObjects = currentRenderList.transparent;
  12536. if ( scene.overrideMaterial ) {
  12537. var overrideMaterial = scene.overrideMaterial;
  12538. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  12539. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  12540. } else {
  12541. // opaque pass (front-to-back order)
  12542. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  12543. // transparent pass (back-to-front order)
  12544. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  12545. }
  12546. // custom render plugins (post pass)
  12547. spritePlugin.render( scene, camera );
  12548. lensFlarePlugin.render( scene, camera, _currentViewport );
  12549. // Generate mipmap if we're using any kind of mipmap filtering
  12550. if ( renderTarget ) {
  12551. textures.updateRenderTargetMipmap( renderTarget );
  12552. }
  12553. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12554. state.buffers.depth.setTest( true );
  12555. state.buffers.depth.setMask( true );
  12556. state.buffers.color.setMask( true );
  12557. if ( camera.isArrayCamera ) {
  12558. _this.setScissorTest( false );
  12559. }
  12560. camera.onAfterRender( _this );
  12561. // _gl.finish();
  12562. };
  12563. /*
  12564. // TODO Duplicated code (Frustum)
  12565. var _sphere = new Sphere();
  12566. function isObjectViewable( object ) {
  12567. var geometry = object.geometry;
  12568. if ( geometry.boundingSphere === null )
  12569. geometry.computeBoundingSphere();
  12570. _sphere.copy( geometry.boundingSphere ).
  12571. applyMatrix4( object.matrixWorld );
  12572. return isSphereViewable( _sphere );
  12573. }
  12574. function isSpriteViewable( sprite ) {
  12575. _sphere.center.set( 0, 0, 0 );
  12576. _sphere.radius = 0.7071067811865476;
  12577. _sphere.applyMatrix4( sprite.matrixWorld );
  12578. return isSphereViewable( _sphere );
  12579. }
  12580. function isSphereViewable( sphere ) {
  12581. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  12582. var numPlanes = _clipping.numPlanes;
  12583. if ( numPlanes === 0 ) return true;
  12584. var planes = _this.clippingPlanes,
  12585. center = sphere.center,
  12586. negRad = - sphere.radius,
  12587. i = 0;
  12588. do {
  12589. // out when deeper than radius in the negative halfspace
  12590. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  12591. } while ( ++ i !== numPlanes );
  12592. return true;
  12593. }
  12594. */
  12595. function projectObject( object, camera, sortObjects ) {
  12596. if ( ! object.visible ) return;
  12597. var visible = object.layers.test( camera.layers );
  12598. if ( visible ) {
  12599. if ( object.isLight ) {
  12600. lights.push( object );
  12601. } else if ( object.isSprite ) {
  12602. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  12603. sprites.push( object );
  12604. }
  12605. } else if ( object.isLensFlare ) {
  12606. lensFlares.push( object );
  12607. } else if ( object.isImmediateRenderObject ) {
  12608. if ( sortObjects ) {
  12609. _vector3.setFromMatrixPosition( object.matrixWorld )
  12610. .applyMatrix4( _projScreenMatrix );
  12611. }
  12612. currentRenderList.push( object, null, object.material, _vector3.z, null );
  12613. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  12614. if ( object.isSkinnedMesh ) {
  12615. object.skeleton.update();
  12616. }
  12617. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  12618. if ( sortObjects ) {
  12619. _vector3.setFromMatrixPosition( object.matrixWorld )
  12620. .applyMatrix4( _projScreenMatrix );
  12621. }
  12622. var geometry = objects.update( object );
  12623. var material = object.material;
  12624. if ( Array.isArray( material ) ) {
  12625. var groups = geometry.groups;
  12626. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  12627. var group = groups[ i ];
  12628. var groupMaterial = material[ group.materialIndex ];
  12629. if ( groupMaterial && groupMaterial.visible ) {
  12630. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  12631. }
  12632. }
  12633. } else if ( material.visible ) {
  12634. currentRenderList.push( object, geometry, material, _vector3.z, null );
  12635. }
  12636. }
  12637. }
  12638. }
  12639. var children = object.children;
  12640. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12641. projectObject( children[ i ], camera, sortObjects );
  12642. }
  12643. }
  12644. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  12645. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12646. var renderItem = renderList[ i ];
  12647. var object = renderItem.object;
  12648. var geometry = renderItem.geometry;
  12649. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  12650. var group = renderItem.group;
  12651. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  12652. if ( camera.isArrayCamera ) {
  12653. var cameras = camera.cameras;
  12654. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  12655. var camera2 = cameras[ j ];
  12656. var bounds = camera2.bounds;
  12657. var x = bounds.x * _width;
  12658. var y = bounds.y * _height;
  12659. var width = bounds.z * _width;
  12660. var height = bounds.w * _height;
  12661. _this.setViewport( x, y, width, height );
  12662. _this.setScissor( x, y, width, height );
  12663. _this.setScissorTest( true );
  12664. renderObject( object, scene, camera2, geometry, material, group );
  12665. }
  12666. } else {
  12667. renderObject( object, scene, camera, geometry, material, group );
  12668. }
  12669. object.onAfterRender( _this, scene, camera, geometry, material, group );
  12670. }
  12671. }
  12672. function renderObject( object, scene, camera, geometry, material, group ) {
  12673. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  12674. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  12675. if ( object.isImmediateRenderObject ) {
  12676. state.setMaterial( material );
  12677. var program = setProgram( camera, scene.fog, material, object );
  12678. _currentGeometryProgram = '';
  12679. renderObjectImmediate( object, program, material );
  12680. } else {
  12681. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  12682. }
  12683. }
  12684. function initMaterial( material, fog, object ) {
  12685. var materialProperties = properties.get( material );
  12686. var parameters = programCache.getParameters(
  12687. material, _lights, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  12688. var code = programCache.getProgramCode( material, parameters );
  12689. var program = materialProperties.program;
  12690. var programChange = true;
  12691. if ( program === undefined ) {
  12692. // new material
  12693. material.addEventListener( 'dispose', onMaterialDispose );
  12694. } else if ( program.code !== code ) {
  12695. // changed glsl or parameters
  12696. releaseMaterialProgramReference( material );
  12697. } else if ( parameters.shaderID !== undefined ) {
  12698. // same glsl and uniform list
  12699. return;
  12700. } else {
  12701. // only rebuild uniform list
  12702. programChange = false;
  12703. }
  12704. if ( programChange ) {
  12705. if ( parameters.shaderID ) {
  12706. var shader = ShaderLib[ parameters.shaderID ];
  12707. materialProperties.__webglShader = {
  12708. name: material.type,
  12709. uniforms: UniformsUtils.clone( shader.uniforms ),
  12710. vertexShader: shader.vertexShader,
  12711. fragmentShader: shader.fragmentShader
  12712. };
  12713. } else {
  12714. materialProperties.__webglShader = {
  12715. name: material.type,
  12716. uniforms: material.uniforms,
  12717. vertexShader: material.vertexShader,
  12718. fragmentShader: material.fragmentShader
  12719. };
  12720. }
  12721. material.__webglShader = materialProperties.__webglShader;
  12722. material.onBeforeCompile();
  12723. program = programCache.acquireProgram( material, parameters, code );
  12724. materialProperties.program = program;
  12725. material.program = program;
  12726. }
  12727. var programAttributes = program.getAttributes();
  12728. if ( material.morphTargets ) {
  12729. material.numSupportedMorphTargets = 0;
  12730. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12731. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  12732. material.numSupportedMorphTargets ++;
  12733. }
  12734. }
  12735. }
  12736. if ( material.morphNormals ) {
  12737. material.numSupportedMorphNormals = 0;
  12738. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  12739. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  12740. material.numSupportedMorphNormals ++;
  12741. }
  12742. }
  12743. }
  12744. var uniforms = materialProperties.__webglShader.uniforms;
  12745. if ( ! material.isShaderMaterial &&
  12746. ! material.isRawShaderMaterial ||
  12747. material.clipping === true ) {
  12748. materialProperties.numClippingPlanes = _clipping.numPlanes;
  12749. materialProperties.numIntersection = _clipping.numIntersection;
  12750. uniforms.clippingPlanes = _clipping.uniform;
  12751. }
  12752. materialProperties.fog = fog;
  12753. // store the light setup it was created for
  12754. materialProperties.lightsHash = _lights.hash;
  12755. if ( material.lights ) {
  12756. // wire up the material to this renderer's lighting state
  12757. uniforms.ambientLightColor.value = _lights.ambient;
  12758. uniforms.directionalLights.value = _lights.directional;
  12759. uniforms.spotLights.value = _lights.spot;
  12760. uniforms.rectAreaLights.value = _lights.rectArea;
  12761. uniforms.pointLights.value = _lights.point;
  12762. uniforms.hemisphereLights.value = _lights.hemi;
  12763. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  12764. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  12765. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  12766. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  12767. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  12768. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  12769. // TODO (abelnation): add area lights shadow info to uniforms
  12770. }
  12771. var progUniforms = materialProperties.program.getUniforms(),
  12772. uniformsList =
  12773. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  12774. materialProperties.uniformsList = uniformsList;
  12775. }
  12776. function setProgram( camera, fog, material, object ) {
  12777. _usedTextureUnits = 0;
  12778. var materialProperties = properties.get( material );
  12779. if ( _clippingEnabled ) {
  12780. if ( _localClippingEnabled || camera !== _currentCamera ) {
  12781. var useCache =
  12782. camera === _currentCamera &&
  12783. material.id === _currentMaterialId;
  12784. // we might want to call this function with some ClippingGroup
  12785. // object instead of the material, once it becomes feasible
  12786. // (#8465, #8379)
  12787. _clipping.setState(
  12788. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  12789. camera, materialProperties, useCache );
  12790. }
  12791. }
  12792. if ( material.needsUpdate === false ) {
  12793. if ( materialProperties.program === undefined ) {
  12794. material.needsUpdate = true;
  12795. } else if ( material.fog && materialProperties.fog !== fog ) {
  12796. material.needsUpdate = true;
  12797. } else if ( material.lights && materialProperties.lightsHash !== _lights.hash ) {
  12798. material.needsUpdate = true;
  12799. } else if ( materialProperties.numClippingPlanes !== undefined &&
  12800. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  12801. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  12802. material.needsUpdate = true;
  12803. }
  12804. }
  12805. if ( material.needsUpdate ) {
  12806. initMaterial( material, fog, object );
  12807. material.needsUpdate = false;
  12808. }
  12809. var refreshProgram = false;
  12810. var refreshMaterial = false;
  12811. var refreshLights = false;
  12812. var program = materialProperties.program,
  12813. p_uniforms = program.getUniforms(),
  12814. m_uniforms = materialProperties.__webglShader.uniforms;
  12815. if ( program.id !== _currentProgram ) {
  12816. _gl.useProgram( program.program );
  12817. _currentProgram = program.id;
  12818. refreshProgram = true;
  12819. refreshMaterial = true;
  12820. refreshLights = true;
  12821. }
  12822. if ( material.id !== _currentMaterialId ) {
  12823. _currentMaterialId = material.id;
  12824. refreshMaterial = true;
  12825. }
  12826. if ( refreshProgram || camera !== _currentCamera ) {
  12827. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  12828. if ( capabilities.logarithmicDepthBuffer ) {
  12829. p_uniforms.setValue( _gl, 'logDepthBufFC',
  12830. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12831. }
  12832. if ( camera !== _currentCamera ) {
  12833. _currentCamera = camera;
  12834. // lighting uniforms depend on the camera so enforce an update
  12835. // now, in case this material supports lights - or later, when
  12836. // the next material that does gets activated:
  12837. refreshMaterial = true; // set to true on material change
  12838. refreshLights = true; // remains set until update done
  12839. }
  12840. // load material specific uniforms
  12841. // (shader material also gets them for the sake of genericity)
  12842. if ( material.isShaderMaterial ||
  12843. material.isMeshPhongMaterial ||
  12844. material.isMeshStandardMaterial ||
  12845. material.envMap ) {
  12846. var uCamPos = p_uniforms.map.cameraPosition;
  12847. if ( uCamPos !== undefined ) {
  12848. uCamPos.setValue( _gl,
  12849. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  12850. }
  12851. }
  12852. if ( material.isMeshPhongMaterial ||
  12853. material.isMeshLambertMaterial ||
  12854. material.isMeshBasicMaterial ||
  12855. material.isMeshStandardMaterial ||
  12856. material.isShaderMaterial ||
  12857. material.skinning ) {
  12858. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  12859. }
  12860. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  12861. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  12862. }
  12863. // skinning uniforms must be set even if material didn't change
  12864. // auto-setting of texture unit for bone texture must go before other textures
  12865. // not sure why, but otherwise weird things happen
  12866. if ( material.skinning ) {
  12867. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  12868. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  12869. var skeleton = object.skeleton;
  12870. if ( skeleton ) {
  12871. var bones = skeleton.bones;
  12872. if ( capabilities.floatVertexTextures ) {
  12873. if ( skeleton.boneTexture === undefined ) {
  12874. // layout (1 matrix = 4 pixels)
  12875. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  12876. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  12877. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  12878. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  12879. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  12880. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  12881. size = _Math.nextPowerOfTwo( Math.ceil( size ) );
  12882. size = Math.max( size, 4 );
  12883. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  12884. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  12885. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  12886. skeleton.boneMatrices = boneMatrices;
  12887. skeleton.boneTexture = boneTexture;
  12888. skeleton.boneTextureSize = size;
  12889. }
  12890. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  12891. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  12892. } else {
  12893. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  12894. }
  12895. }
  12896. }
  12897. if ( refreshMaterial ) {
  12898. if ( material.lights ) {
  12899. // the current material requires lighting info
  12900. // note: all lighting uniforms are always set correctly
  12901. // they simply reference the renderer's state for their
  12902. // values
  12903. //
  12904. // use the current material's .needsUpdate flags to set
  12905. // the GL state when required
  12906. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  12907. }
  12908. // refresh uniforms common to several materials
  12909. if ( fog && material.fog ) {
  12910. refreshUniformsFog( m_uniforms, fog );
  12911. }
  12912. if ( material.isMeshBasicMaterial ||
  12913. material.isMeshLambertMaterial ||
  12914. material.isMeshPhongMaterial ||
  12915. material.isMeshStandardMaterial ||
  12916. material.isMeshNormalMaterial ||
  12917. material.isMeshDepthMaterial ) {
  12918. refreshUniformsCommon( m_uniforms, material );
  12919. }
  12920. // refresh single material specific uniforms
  12921. if ( material.isLineBasicMaterial ) {
  12922. refreshUniformsLine( m_uniforms, material );
  12923. } else if ( material.isLineDashedMaterial ) {
  12924. refreshUniformsLine( m_uniforms, material );
  12925. refreshUniformsDash( m_uniforms, material );
  12926. } else if ( material.isPointsMaterial ) {
  12927. refreshUniformsPoints( m_uniforms, material );
  12928. } else if ( material.isMeshLambertMaterial ) {
  12929. refreshUniformsLambert( m_uniforms, material );
  12930. } else if ( material.isMeshToonMaterial ) {
  12931. refreshUniformsToon( m_uniforms, material );
  12932. } else if ( material.isMeshPhongMaterial ) {
  12933. refreshUniformsPhong( m_uniforms, material );
  12934. } else if ( material.isMeshPhysicalMaterial ) {
  12935. refreshUniformsPhysical( m_uniforms, material );
  12936. } else if ( material.isMeshStandardMaterial ) {
  12937. refreshUniformsStandard( m_uniforms, material );
  12938. } else if ( material.isMeshDepthMaterial ) {
  12939. if ( material.displacementMap ) {
  12940. m_uniforms.displacementMap.value = material.displacementMap;
  12941. m_uniforms.displacementScale.value = material.displacementScale;
  12942. m_uniforms.displacementBias.value = material.displacementBias;
  12943. }
  12944. } else if ( material.isMeshNormalMaterial ) {
  12945. refreshUniformsNormal( m_uniforms, material );
  12946. }
  12947. // RectAreaLight Texture
  12948. // TODO (mrdoob): Find a nicer implementation
  12949. if ( m_uniforms.ltcMat !== undefined ) m_uniforms.ltcMat.value = UniformsLib.LTC_MAT_TEXTURE;
  12950. if ( m_uniforms.ltcMag !== undefined ) m_uniforms.ltcMag.value = UniformsLib.LTC_MAG_TEXTURE;
  12951. WebGLUniforms.upload(
  12952. _gl, materialProperties.uniformsList, m_uniforms, _this );
  12953. }
  12954. // common matrices
  12955. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  12956. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  12957. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  12958. return program;
  12959. }
  12960. // Uniforms (refresh uniforms objects)
  12961. function refreshUniformsCommon( uniforms, material ) {
  12962. uniforms.opacity.value = material.opacity;
  12963. uniforms.diffuse.value = material.color;
  12964. if ( material.emissive ) {
  12965. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  12966. }
  12967. uniforms.map.value = material.map;
  12968. uniforms.specularMap.value = material.specularMap;
  12969. uniforms.alphaMap.value = material.alphaMap;
  12970. if ( material.lightMap ) {
  12971. uniforms.lightMap.value = material.lightMap;
  12972. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  12973. }
  12974. if ( material.aoMap ) {
  12975. uniforms.aoMap.value = material.aoMap;
  12976. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12977. }
  12978. // uv repeat and offset setting priorities
  12979. // 1. color map
  12980. // 2. specular map
  12981. // 3. normal map
  12982. // 4. bump map
  12983. // 5. alpha map
  12984. // 6. emissive map
  12985. var uvScaleMap;
  12986. if ( material.map ) {
  12987. uvScaleMap = material.map;
  12988. } else if ( material.specularMap ) {
  12989. uvScaleMap = material.specularMap;
  12990. } else if ( material.displacementMap ) {
  12991. uvScaleMap = material.displacementMap;
  12992. } else if ( material.normalMap ) {
  12993. uvScaleMap = material.normalMap;
  12994. } else if ( material.bumpMap ) {
  12995. uvScaleMap = material.bumpMap;
  12996. } else if ( material.roughnessMap ) {
  12997. uvScaleMap = material.roughnessMap;
  12998. } else if ( material.metalnessMap ) {
  12999. uvScaleMap = material.metalnessMap;
  13000. } else if ( material.alphaMap ) {
  13001. uvScaleMap = material.alphaMap;
  13002. } else if ( material.emissiveMap ) {
  13003. uvScaleMap = material.emissiveMap;
  13004. }
  13005. if ( uvScaleMap !== undefined ) {
  13006. // backwards compatibility
  13007. if ( uvScaleMap.isWebGLRenderTarget ) {
  13008. uvScaleMap = uvScaleMap.texture;
  13009. }
  13010. var offset = uvScaleMap.offset;
  13011. var repeat = uvScaleMap.repeat;
  13012. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13013. }
  13014. uniforms.envMap.value = material.envMap;
  13015. // don't flip CubeTexture envMaps, flip everything else:
  13016. // WebGLRenderTargetCube will be flipped for backwards compatibility
  13017. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  13018. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  13019. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  13020. uniforms.reflectivity.value = material.reflectivity;
  13021. uniforms.refractionRatio.value = material.refractionRatio;
  13022. }
  13023. function refreshUniformsLine( uniforms, material ) {
  13024. uniforms.diffuse.value = material.color;
  13025. uniforms.opacity.value = material.opacity;
  13026. }
  13027. function refreshUniformsDash( uniforms, material ) {
  13028. uniforms.dashSize.value = material.dashSize;
  13029. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13030. uniforms.scale.value = material.scale;
  13031. }
  13032. function refreshUniformsPoints( uniforms, material ) {
  13033. uniforms.diffuse.value = material.color;
  13034. uniforms.opacity.value = material.opacity;
  13035. uniforms.size.value = material.size * _pixelRatio;
  13036. uniforms.scale.value = _height * 0.5;
  13037. uniforms.map.value = material.map;
  13038. if ( material.map !== null ) {
  13039. var offset = material.map.offset;
  13040. var repeat = material.map.repeat;
  13041. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13042. }
  13043. }
  13044. function refreshUniformsFog( uniforms, fog ) {
  13045. uniforms.fogColor.value = fog.color;
  13046. if ( fog.isFog ) {
  13047. uniforms.fogNear.value = fog.near;
  13048. uniforms.fogFar.value = fog.far;
  13049. } else if ( fog.isFogExp2 ) {
  13050. uniforms.fogDensity.value = fog.density;
  13051. }
  13052. }
  13053. function refreshUniformsLambert( uniforms, material ) {
  13054. if ( material.emissiveMap ) {
  13055. uniforms.emissiveMap.value = material.emissiveMap;
  13056. }
  13057. }
  13058. function refreshUniformsPhong( uniforms, material ) {
  13059. uniforms.specular.value = material.specular;
  13060. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13061. if ( material.emissiveMap ) {
  13062. uniforms.emissiveMap.value = material.emissiveMap;
  13063. }
  13064. if ( material.bumpMap ) {
  13065. uniforms.bumpMap.value = material.bumpMap;
  13066. uniforms.bumpScale.value = material.bumpScale;
  13067. }
  13068. if ( material.normalMap ) {
  13069. uniforms.normalMap.value = material.normalMap;
  13070. uniforms.normalScale.value.copy( material.normalScale );
  13071. }
  13072. if ( material.displacementMap ) {
  13073. uniforms.displacementMap.value = material.displacementMap;
  13074. uniforms.displacementScale.value = material.displacementScale;
  13075. uniforms.displacementBias.value = material.displacementBias;
  13076. }
  13077. }
  13078. function refreshUniformsToon( uniforms, material ) {
  13079. refreshUniformsPhong( uniforms, material );
  13080. if ( material.gradientMap ) {
  13081. uniforms.gradientMap.value = material.gradientMap;
  13082. }
  13083. }
  13084. function refreshUniformsStandard( uniforms, material ) {
  13085. uniforms.roughness.value = material.roughness;
  13086. uniforms.metalness.value = material.metalness;
  13087. if ( material.roughnessMap ) {
  13088. uniforms.roughnessMap.value = material.roughnessMap;
  13089. }
  13090. if ( material.metalnessMap ) {
  13091. uniforms.metalnessMap.value = material.metalnessMap;
  13092. }
  13093. if ( material.emissiveMap ) {
  13094. uniforms.emissiveMap.value = material.emissiveMap;
  13095. }
  13096. if ( material.bumpMap ) {
  13097. uniforms.bumpMap.value = material.bumpMap;
  13098. uniforms.bumpScale.value = material.bumpScale;
  13099. }
  13100. if ( material.normalMap ) {
  13101. uniforms.normalMap.value = material.normalMap;
  13102. uniforms.normalScale.value.copy( material.normalScale );
  13103. }
  13104. if ( material.displacementMap ) {
  13105. uniforms.displacementMap.value = material.displacementMap;
  13106. uniforms.displacementScale.value = material.displacementScale;
  13107. uniforms.displacementBias.value = material.displacementBias;
  13108. }
  13109. if ( material.envMap ) {
  13110. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13111. uniforms.envMapIntensity.value = material.envMapIntensity;
  13112. }
  13113. }
  13114. function refreshUniformsPhysical( uniforms, material ) {
  13115. uniforms.clearCoat.value = material.clearCoat;
  13116. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  13117. refreshUniformsStandard( uniforms, material );
  13118. }
  13119. function refreshUniformsNormal( uniforms, material ) {
  13120. if ( material.bumpMap ) {
  13121. uniforms.bumpMap.value = material.bumpMap;
  13122. uniforms.bumpScale.value = material.bumpScale;
  13123. }
  13124. if ( material.normalMap ) {
  13125. uniforms.normalMap.value = material.normalMap;
  13126. uniforms.normalScale.value.copy( material.normalScale );
  13127. }
  13128. if ( material.displacementMap ) {
  13129. uniforms.displacementMap.value = material.displacementMap;
  13130. uniforms.displacementScale.value = material.displacementScale;
  13131. uniforms.displacementBias.value = material.displacementBias;
  13132. }
  13133. }
  13134. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13135. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  13136. uniforms.ambientLightColor.needsUpdate = value;
  13137. uniforms.directionalLights.needsUpdate = value;
  13138. uniforms.pointLights.needsUpdate = value;
  13139. uniforms.spotLights.needsUpdate = value;
  13140. uniforms.rectAreaLights.needsUpdate = value;
  13141. uniforms.hemisphereLights.needsUpdate = value;
  13142. }
  13143. // Lighting
  13144. function setupShadows( lights ) {
  13145. var lightShadowsLength = 0;
  13146. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  13147. var light = lights[ i ];
  13148. if ( light.castShadow ) {
  13149. _lights.shadows[ lightShadowsLength ] = light;
  13150. lightShadowsLength ++;
  13151. }
  13152. }
  13153. _lights.shadows.length = lightShadowsLength;
  13154. }
  13155. function setupLights( lights, camera ) {
  13156. var l, ll, light, shadow,
  13157. r = 0, g = 0, b = 0,
  13158. color,
  13159. intensity,
  13160. distance,
  13161. shadowMap,
  13162. viewMatrix = camera.matrixWorldInverse,
  13163. directionalLength = 0,
  13164. pointLength = 0,
  13165. spotLength = 0,
  13166. rectAreaLength = 0,
  13167. hemiLength = 0;
  13168. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13169. light = lights[ l ];
  13170. color = light.color;
  13171. intensity = light.intensity;
  13172. distance = light.distance;
  13173. shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  13174. if ( light.isAmbientLight ) {
  13175. r += color.r * intensity;
  13176. g += color.g * intensity;
  13177. b += color.b * intensity;
  13178. } else if ( light.isDirectionalLight ) {
  13179. var uniforms = lightCache.get( light );
  13180. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  13181. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  13182. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13183. uniforms.direction.sub( _vector3 );
  13184. uniforms.direction.transformDirection( viewMatrix );
  13185. uniforms.shadow = light.castShadow;
  13186. if ( light.castShadow ) {
  13187. shadow = light.shadow;
  13188. uniforms.shadowBias = shadow.bias;
  13189. uniforms.shadowRadius = shadow.radius;
  13190. uniforms.shadowMapSize = shadow.mapSize;
  13191. }
  13192. _lights.directionalShadowMap[ directionalLength ] = shadowMap;
  13193. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  13194. _lights.directional[ directionalLength ] = uniforms;
  13195. directionalLength ++;
  13196. } else if ( light.isSpotLight ) {
  13197. var uniforms = lightCache.get( light );
  13198. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  13199. uniforms.position.applyMatrix4( viewMatrix );
  13200. uniforms.color.copy( color ).multiplyScalar( intensity );
  13201. uniforms.distance = distance;
  13202. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  13203. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13204. uniforms.direction.sub( _vector3 );
  13205. uniforms.direction.transformDirection( viewMatrix );
  13206. uniforms.coneCos = Math.cos( light.angle );
  13207. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  13208. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  13209. uniforms.shadow = light.castShadow;
  13210. if ( light.castShadow ) {
  13211. shadow = light.shadow;
  13212. uniforms.shadowBias = shadow.bias;
  13213. uniforms.shadowRadius = shadow.radius;
  13214. uniforms.shadowMapSize = shadow.mapSize;
  13215. }
  13216. _lights.spotShadowMap[ spotLength ] = shadowMap;
  13217. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  13218. _lights.spot[ spotLength ] = uniforms;
  13219. spotLength ++;
  13220. } else if ( light.isRectAreaLight ) {
  13221. var uniforms = lightCache.get( light );
  13222. // (a) intensity controls irradiance of entire light
  13223. uniforms.color
  13224. .copy( color )
  13225. .multiplyScalar( intensity / ( light.width * light.height ) );
  13226. // (b) intensity controls the radiance per light area
  13227. // uniforms.color.copy( color ).multiplyScalar( intensity );
  13228. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  13229. uniforms.position.applyMatrix4( viewMatrix );
  13230. // extract local rotation of light to derive width/height half vectors
  13231. _matrix42.identity();
  13232. _matrix4.copy( light.matrixWorld );
  13233. _matrix4.premultiply( viewMatrix );
  13234. _matrix42.extractRotation( _matrix4 );
  13235. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  13236. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  13237. uniforms.halfWidth.applyMatrix4( _matrix42 );
  13238. uniforms.halfHeight.applyMatrix4( _matrix42 );
  13239. // TODO (abelnation): RectAreaLight distance?
  13240. // uniforms.distance = distance;
  13241. _lights.rectArea[ rectAreaLength ] = uniforms;
  13242. rectAreaLength ++;
  13243. } else if ( light.isPointLight ) {
  13244. var uniforms = lightCache.get( light );
  13245. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  13246. uniforms.position.applyMatrix4( viewMatrix );
  13247. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  13248. uniforms.distance = light.distance;
  13249. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  13250. uniforms.shadow = light.castShadow;
  13251. if ( light.castShadow ) {
  13252. shadow = light.shadow;
  13253. uniforms.shadowBias = shadow.bias;
  13254. uniforms.shadowRadius = shadow.radius;
  13255. uniforms.shadowMapSize = shadow.mapSize;
  13256. }
  13257. _lights.pointShadowMap[ pointLength ] = shadowMap;
  13258. _lights.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  13259. _lights.point[ pointLength ] = uniforms;
  13260. pointLength ++;
  13261. } else if ( light.isHemisphereLight ) {
  13262. var uniforms = lightCache.get( light );
  13263. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  13264. uniforms.direction.transformDirection( viewMatrix );
  13265. uniforms.direction.normalize();
  13266. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  13267. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  13268. _lights.hemi[ hemiLength ] = uniforms;
  13269. hemiLength ++;
  13270. }
  13271. }
  13272. _lights.ambient[ 0 ] = r;
  13273. _lights.ambient[ 1 ] = g;
  13274. _lights.ambient[ 2 ] = b;
  13275. _lights.directional.length = directionalLength;
  13276. _lights.spot.length = spotLength;
  13277. _lights.rectArea.length = rectAreaLength;
  13278. _lights.point.length = pointLength;
  13279. _lights.hemi.length = hemiLength;
  13280. // TODO (sam-g-steel) why aren't we using join
  13281. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + _lights.shadows.length;
  13282. }
  13283. // GL state setting
  13284. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13285. state.setCullFace( cullFace );
  13286. state.setFlipSided( frontFaceDirection === FrontFaceDirectionCW );
  13287. };
  13288. // Textures
  13289. function allocTextureUnit() {
  13290. var textureUnit = _usedTextureUnits;
  13291. if ( textureUnit >= capabilities.maxTextures ) {
  13292. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13293. }
  13294. _usedTextureUnits += 1;
  13295. return textureUnit;
  13296. }
  13297. this.allocTextureUnit = allocTextureUnit;
  13298. // this.setTexture2D = setTexture2D;
  13299. this.setTexture2D = ( function () {
  13300. var warned = false;
  13301. // backwards compatibility: peel texture.texture
  13302. return function setTexture2D( texture, slot ) {
  13303. if ( texture && texture.isWebGLRenderTarget ) {
  13304. if ( ! warned ) {
  13305. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13306. warned = true;
  13307. }
  13308. texture = texture.texture;
  13309. }
  13310. textures.setTexture2D( texture, slot );
  13311. };
  13312. }() );
  13313. this.setTexture = ( function () {
  13314. var warned = false;
  13315. return function setTexture( texture, slot ) {
  13316. if ( ! warned ) {
  13317. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  13318. warned = true;
  13319. }
  13320. textures.setTexture2D( texture, slot );
  13321. };
  13322. }() );
  13323. this.setTextureCube = ( function () {
  13324. var warned = false;
  13325. return function setTextureCube( texture, slot ) {
  13326. // backwards compatibility: peel texture.texture
  13327. if ( texture && texture.isWebGLRenderTargetCube ) {
  13328. if ( ! warned ) {
  13329. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13330. warned = true;
  13331. }
  13332. texture = texture.texture;
  13333. }
  13334. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13335. // TODO: unify these code paths
  13336. if ( ( texture && texture.isCubeTexture ) ||
  13337. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13338. // CompressedTexture can have Array in image :/
  13339. // this function alone should take care of cube textures
  13340. textures.setTextureCube( texture, slot );
  13341. } else {
  13342. // assumed: texture property of THREE.WebGLRenderTargetCube
  13343. textures.setTextureCubeDynamic( texture, slot );
  13344. }
  13345. };
  13346. }() );
  13347. this.getRenderTarget = function () {
  13348. return _currentRenderTarget;
  13349. };
  13350. this.setRenderTarget = function ( renderTarget ) {
  13351. _currentRenderTarget = renderTarget;
  13352. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13353. textures.setupRenderTarget( renderTarget );
  13354. }
  13355. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  13356. var framebuffer;
  13357. if ( renderTarget ) {
  13358. var renderTargetProperties = properties.get( renderTarget );
  13359. if ( isCube ) {
  13360. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13361. } else {
  13362. framebuffer = renderTargetProperties.__webglFramebuffer;
  13363. }
  13364. _currentScissor.copy( renderTarget.scissor );
  13365. _currentScissorTest = renderTarget.scissorTest;
  13366. _currentViewport.copy( renderTarget.viewport );
  13367. } else {
  13368. framebuffer = null;
  13369. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  13370. _currentScissorTest = _scissorTest;
  13371. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  13372. }
  13373. if ( _currentFramebuffer !== framebuffer ) {
  13374. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13375. _currentFramebuffer = framebuffer;
  13376. }
  13377. state.scissor( _currentScissor );
  13378. state.setScissorTest( _currentScissorTest );
  13379. state.viewport( _currentViewport );
  13380. if ( isCube ) {
  13381. var textureProperties = properties.get( renderTarget.texture );
  13382. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  13383. }
  13384. };
  13385. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  13386. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  13387. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13388. return;
  13389. }
  13390. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  13391. if ( framebuffer ) {
  13392. var restore = false;
  13393. if ( framebuffer !== _currentFramebuffer ) {
  13394. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13395. restore = true;
  13396. }
  13397. try {
  13398. var texture = renderTarget.texture;
  13399. var textureFormat = texture.format;
  13400. var textureType = texture.type;
  13401. if ( textureFormat !== RGBAFormat && paramThreeToGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  13402. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  13403. return;
  13404. }
  13405. if ( textureType !== UnsignedByteType && paramThreeToGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  13406. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  13407. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  13408. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  13409. return;
  13410. }
  13411. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13412. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  13413. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  13414. _gl.readPixels( x, y, width, height, paramThreeToGL( textureFormat ), paramThreeToGL( textureType ), buffer );
  13415. }
  13416. } else {
  13417. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13418. }
  13419. } finally {
  13420. if ( restore ) {
  13421. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13422. }
  13423. }
  13424. }
  13425. };
  13426. // Map three.js constants to WebGL constants
  13427. function paramThreeToGL( p ) {
  13428. var extension;
  13429. if ( p === RepeatWrapping ) return _gl.REPEAT;
  13430. if ( p === ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13431. if ( p === MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13432. if ( p === NearestFilter ) return _gl.NEAREST;
  13433. if ( p === NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13434. if ( p === NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13435. if ( p === LinearFilter ) return _gl.LINEAR;
  13436. if ( p === LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13437. if ( p === LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13438. if ( p === UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13439. if ( p === UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13440. if ( p === UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13441. if ( p === UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13442. if ( p === ByteType ) return _gl.BYTE;
  13443. if ( p === ShortType ) return _gl.SHORT;
  13444. if ( p === UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13445. if ( p === IntType ) return _gl.INT;
  13446. if ( p === UnsignedIntType ) return _gl.UNSIGNED_INT;
  13447. if ( p === FloatType ) return _gl.FLOAT;
  13448. if ( p === HalfFloatType ) {
  13449. extension = extensions.get( 'OES_texture_half_float' );
  13450. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  13451. }
  13452. if ( p === AlphaFormat ) return _gl.ALPHA;
  13453. if ( p === RGBFormat ) return _gl.RGB;
  13454. if ( p === RGBAFormat ) return _gl.RGBA;
  13455. if ( p === LuminanceFormat ) return _gl.LUMINANCE;
  13456. if ( p === LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13457. if ( p === DepthFormat ) return _gl.DEPTH_COMPONENT;
  13458. if ( p === DepthStencilFormat ) return _gl.DEPTH_STENCIL;
  13459. if ( p === AddEquation ) return _gl.FUNC_ADD;
  13460. if ( p === SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13461. if ( p === ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13462. if ( p === ZeroFactor ) return _gl.ZERO;
  13463. if ( p === OneFactor ) return _gl.ONE;
  13464. if ( p === SrcColorFactor ) return _gl.SRC_COLOR;
  13465. if ( p === OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13466. if ( p === SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13467. if ( p === OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13468. if ( p === DstAlphaFactor ) return _gl.DST_ALPHA;
  13469. if ( p === OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13470. if ( p === DstColorFactor ) return _gl.DST_COLOR;
  13471. if ( p === OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13472. if ( p === SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13473. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13474. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13475. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13476. if ( extension !== null ) {
  13477. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13478. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13479. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13480. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13481. }
  13482. }
  13483. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13484. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13485. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13486. if ( extension !== null ) {
  13487. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13488. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13489. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13490. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13491. }
  13492. }
  13493. if ( p === RGB_ETC1_Format ) {
  13494. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13495. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13496. }
  13497. if ( p === MinEquation || p === MaxEquation ) {
  13498. extension = extensions.get( 'EXT_blend_minmax' );
  13499. if ( extension !== null ) {
  13500. if ( p === MinEquation ) return extension.MIN_EXT;
  13501. if ( p === MaxEquation ) return extension.MAX_EXT;
  13502. }
  13503. }
  13504. if ( p === UnsignedInt248Type ) {
  13505. extension = extensions.get( 'WEBGL_depth_texture' );
  13506. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  13507. }
  13508. return 0;
  13509. }
  13510. }
  13511. /**
  13512. * @author mrdoob / http://mrdoob.com/
  13513. * @author alteredq / http://alteredqualia.com/
  13514. */
  13515. function FogExp2 ( color, density ) {
  13516. this.name = '';
  13517. this.color = new Color( color );
  13518. this.density = ( density !== undefined ) ? density : 0.00025;
  13519. }
  13520. FogExp2.prototype.isFogExp2 = true;
  13521. FogExp2.prototype.clone = function () {
  13522. return new FogExp2( this.color.getHex(), this.density );
  13523. };
  13524. FogExp2.prototype.toJSON = function ( meta ) {
  13525. return {
  13526. type: 'FogExp2',
  13527. color: this.color.getHex(),
  13528. density: this.density
  13529. };
  13530. };
  13531. /**
  13532. * @author mrdoob / http://mrdoob.com/
  13533. * @author alteredq / http://alteredqualia.com/
  13534. */
  13535. function Fog ( color, near, far ) {
  13536. this.name = '';
  13537. this.color = new Color( color );
  13538. this.near = ( near !== undefined ) ? near : 1;
  13539. this.far = ( far !== undefined ) ? far : 1000;
  13540. }
  13541. Fog.prototype.isFog = true;
  13542. Fog.prototype.clone = function () {
  13543. return new Fog( this.color.getHex(), this.near, this.far );
  13544. };
  13545. Fog.prototype.toJSON = function ( meta ) {
  13546. return {
  13547. type: 'Fog',
  13548. color: this.color.getHex(),
  13549. near: this.near,
  13550. far: this.far
  13551. };
  13552. };
  13553. /**
  13554. * @author mrdoob / http://mrdoob.com/
  13555. */
  13556. function Scene () {
  13557. Object3D.call( this );
  13558. this.type = 'Scene';
  13559. this.background = null;
  13560. this.fog = null;
  13561. this.overrideMaterial = null;
  13562. this.autoUpdate = true; // checked by the renderer
  13563. }
  13564. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13565. constructor: Scene,
  13566. copy: function ( source, recursive ) {
  13567. Object3D.prototype.copy.call( this, source, recursive );
  13568. if ( source.background !== null ) this.background = source.background.clone();
  13569. if ( source.fog !== null ) this.fog = source.fog.clone();
  13570. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13571. this.autoUpdate = source.autoUpdate;
  13572. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13573. return this;
  13574. },
  13575. toJSON: function ( meta ) {
  13576. var data = Object3D.prototype.toJSON.call( this, meta );
  13577. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  13578. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  13579. return data;
  13580. }
  13581. } );
  13582. /**
  13583. * @author mikael emtinger / http://gomo.se/
  13584. * @author alteredq / http://alteredqualia.com/
  13585. */
  13586. function LensFlare( texture, size, distance, blending, color ) {
  13587. Object3D.call( this );
  13588. this.lensFlares = [];
  13589. this.positionScreen = new Vector3();
  13590. this.customUpdateCallback = undefined;
  13591. if ( texture !== undefined ) {
  13592. this.add( texture, size, distance, blending, color );
  13593. }
  13594. }
  13595. LensFlare.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13596. constructor: LensFlare,
  13597. isLensFlare: true,
  13598. copy: function ( source ) {
  13599. Object3D.prototype.copy.call( this, source );
  13600. this.positionScreen.copy( source.positionScreen );
  13601. this.customUpdateCallback = source.customUpdateCallback;
  13602. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13603. this.lensFlares.push( source.lensFlares[ i ] );
  13604. }
  13605. return this;
  13606. },
  13607. add: function ( texture, size, distance, blending, color, opacity ) {
  13608. if ( size === undefined ) size = - 1;
  13609. if ( distance === undefined ) distance = 0;
  13610. if ( opacity === undefined ) opacity = 1;
  13611. if ( color === undefined ) color = new Color( 0xffffff );
  13612. if ( blending === undefined ) blending = NormalBlending;
  13613. distance = Math.min( distance, Math.max( 0, distance ) );
  13614. this.lensFlares.push( {
  13615. texture: texture, // THREE.Texture
  13616. size: size, // size in pixels (-1 = use texture.width)
  13617. distance: distance, // distance (0-1) from light source (0=at light source)
  13618. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13619. scale: 1, // scale
  13620. rotation: 0, // rotation
  13621. opacity: opacity, // opacity
  13622. color: color, // color
  13623. blending: blending // blending
  13624. } );
  13625. },
  13626. /*
  13627. * Update lens flares update positions on all flares based on the screen position
  13628. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13629. */
  13630. updateLensFlares: function () {
  13631. var f, fl = this.lensFlares.length;
  13632. var flare;
  13633. var vecX = - this.positionScreen.x * 2;
  13634. var vecY = - this.positionScreen.y * 2;
  13635. for ( f = 0; f < fl; f ++ ) {
  13636. flare = this.lensFlares[ f ];
  13637. flare.x = this.positionScreen.x + vecX * flare.distance;
  13638. flare.y = this.positionScreen.y + vecY * flare.distance;
  13639. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13640. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13641. }
  13642. }
  13643. } );
  13644. /**
  13645. * @author alteredq / http://alteredqualia.com/
  13646. *
  13647. * parameters = {
  13648. * color: <hex>,
  13649. * opacity: <float>,
  13650. * map: new THREE.Texture( <Image> ),
  13651. *
  13652. * uvOffset: new THREE.Vector2(),
  13653. * uvScale: new THREE.Vector2()
  13654. * }
  13655. */
  13656. function SpriteMaterial( parameters ) {
  13657. Material.call( this );
  13658. this.type = 'SpriteMaterial';
  13659. this.color = new Color( 0xffffff );
  13660. this.map = null;
  13661. this.rotation = 0;
  13662. this.fog = false;
  13663. this.lights = false;
  13664. this.setValues( parameters );
  13665. }
  13666. SpriteMaterial.prototype = Object.create( Material.prototype );
  13667. SpriteMaterial.prototype.constructor = SpriteMaterial;
  13668. SpriteMaterial.prototype.isSpriteMaterial = true;
  13669. SpriteMaterial.prototype.copy = function ( source ) {
  13670. Material.prototype.copy.call( this, source );
  13671. this.color.copy( source.color );
  13672. this.map = source.map;
  13673. this.rotation = source.rotation;
  13674. return this;
  13675. };
  13676. /**
  13677. * @author mikael emtinger / http://gomo.se/
  13678. * @author alteredq / http://alteredqualia.com/
  13679. */
  13680. function Sprite( material ) {
  13681. Object3D.call( this );
  13682. this.type = 'Sprite';
  13683. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  13684. }
  13685. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13686. constructor: Sprite,
  13687. isSprite: true,
  13688. raycast: ( function () {
  13689. var intersectPoint = new Vector3();
  13690. var worldPosition = new Vector3();
  13691. var worldScale = new Vector3();
  13692. return function raycast( raycaster, intersects ) {
  13693. worldPosition.setFromMatrixPosition( this.matrixWorld );
  13694. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  13695. worldScale.setFromMatrixScale( this.matrixWorld );
  13696. var guessSizeSq = worldScale.x * worldScale.y / 4;
  13697. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  13698. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13699. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13700. intersects.push( {
  13701. distance: distance,
  13702. point: intersectPoint.clone(),
  13703. face: null,
  13704. object: this
  13705. } );
  13706. };
  13707. }() ),
  13708. clone: function () {
  13709. return new this.constructor( this.material ).copy( this );
  13710. }
  13711. } );
  13712. /**
  13713. * @author mikael emtinger / http://gomo.se/
  13714. * @author alteredq / http://alteredqualia.com/
  13715. * @author mrdoob / http://mrdoob.com/
  13716. */
  13717. function LOD() {
  13718. Object3D.call( this );
  13719. this.type = 'LOD';
  13720. Object.defineProperties( this, {
  13721. levels: {
  13722. enumerable: true,
  13723. value: []
  13724. }
  13725. } );
  13726. }
  13727. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13728. constructor: LOD,
  13729. copy: function ( source ) {
  13730. Object3D.prototype.copy.call( this, source, false );
  13731. var levels = source.levels;
  13732. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13733. var level = levels[ i ];
  13734. this.addLevel( level.object.clone(), level.distance );
  13735. }
  13736. return this;
  13737. },
  13738. addLevel: function ( object, distance ) {
  13739. if ( distance === undefined ) distance = 0;
  13740. distance = Math.abs( distance );
  13741. var levels = this.levels;
  13742. for ( var l = 0; l < levels.length; l ++ ) {
  13743. if ( distance < levels[ l ].distance ) {
  13744. break;
  13745. }
  13746. }
  13747. levels.splice( l, 0, { distance: distance, object: object } );
  13748. this.add( object );
  13749. },
  13750. getObjectForDistance: function ( distance ) {
  13751. var levels = this.levels;
  13752. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13753. if ( distance < levels[ i ].distance ) {
  13754. break;
  13755. }
  13756. }
  13757. return levels[ i - 1 ].object;
  13758. },
  13759. raycast: ( function () {
  13760. var matrixPosition = new Vector3();
  13761. return function raycast( raycaster, intersects ) {
  13762. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13763. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13764. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13765. };
  13766. }() ),
  13767. update: function () {
  13768. var v1 = new Vector3();
  13769. var v2 = new Vector3();
  13770. return function update( camera ) {
  13771. var levels = this.levels;
  13772. if ( levels.length > 1 ) {
  13773. v1.setFromMatrixPosition( camera.matrixWorld );
  13774. v2.setFromMatrixPosition( this.matrixWorld );
  13775. var distance = v1.distanceTo( v2 );
  13776. levels[ 0 ].object.visible = true;
  13777. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13778. if ( distance >= levels[ i ].distance ) {
  13779. levels[ i - 1 ].object.visible = false;
  13780. levels[ i ].object.visible = true;
  13781. } else {
  13782. break;
  13783. }
  13784. }
  13785. for ( ; i < l; i ++ ) {
  13786. levels[ i ].object.visible = false;
  13787. }
  13788. }
  13789. };
  13790. }(),
  13791. toJSON: function ( meta ) {
  13792. var data = Object3D.prototype.toJSON.call( this, meta );
  13793. data.object.levels = [];
  13794. var levels = this.levels;
  13795. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13796. var level = levels[ i ];
  13797. data.object.levels.push( {
  13798. object: level.object.uuid,
  13799. distance: level.distance
  13800. } );
  13801. }
  13802. return data;
  13803. }
  13804. } );
  13805. /**
  13806. * @author mikael emtinger / http://gomo.se/
  13807. * @author alteredq / http://alteredqualia.com/
  13808. * @author michael guerrero / http://realitymeltdown.com
  13809. * @author ikerr / http://verold.com
  13810. */
  13811. function Skeleton( bones, boneInverses ) {
  13812. // copy the bone array
  13813. bones = bones || [];
  13814. this.bones = bones.slice( 0 );
  13815. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  13816. // use the supplied bone inverses or calculate the inverses
  13817. if ( boneInverses === undefined ) {
  13818. this.calculateInverses();
  13819. } else {
  13820. if ( this.bones.length === boneInverses.length ) {
  13821. this.boneInverses = boneInverses.slice( 0 );
  13822. } else {
  13823. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  13824. this.boneInverses = [];
  13825. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  13826. this.boneInverses.push( new Matrix4() );
  13827. }
  13828. }
  13829. }
  13830. }
  13831. Object.assign( Skeleton.prototype, {
  13832. calculateInverses: function () {
  13833. this.boneInverses = [];
  13834. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  13835. var inverse = new Matrix4();
  13836. if ( this.bones[ i ] ) {
  13837. inverse.getInverse( this.bones[ i ].matrixWorld );
  13838. }
  13839. this.boneInverses.push( inverse );
  13840. }
  13841. },
  13842. pose: function () {
  13843. var bone, i, il;
  13844. // recover the bind-time world matrices
  13845. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  13846. bone = this.bones[ i ];
  13847. if ( bone ) {
  13848. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  13849. }
  13850. }
  13851. // compute the local matrices, positions, rotations and scales
  13852. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  13853. bone = this.bones[ i ];
  13854. if ( bone ) {
  13855. if ( bone.parent && bone.parent.isBone ) {
  13856. bone.matrix.getInverse( bone.parent.matrixWorld );
  13857. bone.matrix.multiply( bone.matrixWorld );
  13858. } else {
  13859. bone.matrix.copy( bone.matrixWorld );
  13860. }
  13861. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13862. }
  13863. }
  13864. },
  13865. update: ( function () {
  13866. var offsetMatrix = new Matrix4();
  13867. var identityMatrix = new Matrix4();
  13868. return function update() {
  13869. var bones = this.bones;
  13870. var boneInverses = this.boneInverses;
  13871. var boneMatrices = this.boneMatrices;
  13872. var boneTexture = this.boneTexture;
  13873. // flatten bone matrices to array
  13874. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  13875. // compute the offset between the current and the original transform
  13876. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  13877. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  13878. offsetMatrix.toArray( boneMatrices, i * 16 );
  13879. }
  13880. if ( boneTexture !== undefined ) {
  13881. boneTexture.needsUpdate = true;
  13882. }
  13883. };
  13884. } )(),
  13885. clone: function () {
  13886. return new Skeleton( this.bones, this.boneInverses );
  13887. }
  13888. } );
  13889. /**
  13890. * @author mikael emtinger / http://gomo.se/
  13891. * @author alteredq / http://alteredqualia.com/
  13892. * @author ikerr / http://verold.com
  13893. */
  13894. function Bone() {
  13895. Object3D.call( this );
  13896. this.type = 'Bone';
  13897. }
  13898. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13899. constructor: Bone,
  13900. isBone: true
  13901. } );
  13902. /**
  13903. * @author mikael emtinger / http://gomo.se/
  13904. * @author alteredq / http://alteredqualia.com/
  13905. * @author ikerr / http://verold.com
  13906. */
  13907. function SkinnedMesh( geometry, material ) {
  13908. Mesh.call( this, geometry, material );
  13909. this.type = 'SkinnedMesh';
  13910. this.bindMode = 'attached';
  13911. this.bindMatrix = new Matrix4();
  13912. this.bindMatrixInverse = new Matrix4();
  13913. var bones = this.initBones();
  13914. var skeleton = new Skeleton( bones );
  13915. this.bind( skeleton, this.matrixWorld );
  13916. this.normalizeSkinWeights();
  13917. }
  13918. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  13919. constructor: SkinnedMesh,
  13920. isSkinnedMesh: true,
  13921. initBones: function () {
  13922. var bones = [], bone, gbone;
  13923. var i, il;
  13924. if ( this.geometry && this.geometry.bones !== undefined ) {
  13925. // first, create array of 'Bone' objects from geometry data
  13926. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  13927. gbone = this.geometry.bones[ i ];
  13928. // create new 'Bone' object
  13929. bone = new Bone();
  13930. bones.push( bone );
  13931. // apply values
  13932. bone.name = gbone.name;
  13933. bone.position.fromArray( gbone.pos );
  13934. bone.quaternion.fromArray( gbone.rotq );
  13935. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13936. }
  13937. // second, create bone hierarchy
  13938. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  13939. gbone = this.geometry.bones[ i ];
  13940. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  13941. // subsequent bones in the hierarchy
  13942. bones[ gbone.parent ].add( bones[ i ] );
  13943. } else {
  13944. // topmost bone, immediate child of the skinned mesh
  13945. this.add( bones[ i ] );
  13946. }
  13947. }
  13948. }
  13949. // now the bones are part of the scene graph and children of the skinned mesh.
  13950. // let's update the corresponding matrices
  13951. this.updateMatrixWorld( true );
  13952. return bones;
  13953. },
  13954. bind: function ( skeleton, bindMatrix ) {
  13955. this.skeleton = skeleton;
  13956. if ( bindMatrix === undefined ) {
  13957. this.updateMatrixWorld( true );
  13958. this.skeleton.calculateInverses();
  13959. bindMatrix = this.matrixWorld;
  13960. }
  13961. this.bindMatrix.copy( bindMatrix );
  13962. this.bindMatrixInverse.getInverse( bindMatrix );
  13963. },
  13964. pose: function () {
  13965. this.skeleton.pose();
  13966. },
  13967. normalizeSkinWeights: function () {
  13968. var scale, i;
  13969. if ( this.geometry && this.geometry.isGeometry ) {
  13970. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13971. var sw = this.geometry.skinWeights[ i ];
  13972. scale = 1.0 / sw.lengthManhattan();
  13973. if ( scale !== Infinity ) {
  13974. sw.multiplyScalar( scale );
  13975. } else {
  13976. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13977. }
  13978. }
  13979. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  13980. var vec = new Vector4();
  13981. var skinWeight = this.geometry.attributes.skinWeight;
  13982. for ( i = 0; i < skinWeight.count; i ++ ) {
  13983. vec.x = skinWeight.getX( i );
  13984. vec.y = skinWeight.getY( i );
  13985. vec.z = skinWeight.getZ( i );
  13986. vec.w = skinWeight.getW( i );
  13987. scale = 1.0 / vec.lengthManhattan();
  13988. if ( scale !== Infinity ) {
  13989. vec.multiplyScalar( scale );
  13990. } else {
  13991. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13992. }
  13993. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13994. }
  13995. }
  13996. },
  13997. updateMatrixWorld: function ( force ) {
  13998. Mesh.prototype.updateMatrixWorld.call( this, force );
  13999. if ( this.bindMode === 'attached' ) {
  14000. this.bindMatrixInverse.getInverse( this.matrixWorld );
  14001. } else if ( this.bindMode === 'detached' ) {
  14002. this.bindMatrixInverse.getInverse( this.bindMatrix );
  14003. } else {
  14004. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  14005. }
  14006. },
  14007. clone: function () {
  14008. return new this.constructor( this.geometry, this.material ).copy( this );
  14009. }
  14010. } );
  14011. /**
  14012. * @author mrdoob / http://mrdoob.com/
  14013. * @author alteredq / http://alteredqualia.com/
  14014. *
  14015. * parameters = {
  14016. * color: <hex>,
  14017. * opacity: <float>,
  14018. *
  14019. * linewidth: <float>,
  14020. * linecap: "round",
  14021. * linejoin: "round"
  14022. * }
  14023. */
  14024. function LineBasicMaterial( parameters ) {
  14025. Material.call( this );
  14026. this.type = 'LineBasicMaterial';
  14027. this.color = new Color( 0xffffff );
  14028. this.linewidth = 1;
  14029. this.linecap = 'round';
  14030. this.linejoin = 'round';
  14031. this.lights = false;
  14032. this.setValues( parameters );
  14033. }
  14034. LineBasicMaterial.prototype = Object.create( Material.prototype );
  14035. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  14036. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  14037. LineBasicMaterial.prototype.copy = function ( source ) {
  14038. Material.prototype.copy.call( this, source );
  14039. this.color.copy( source.color );
  14040. this.linewidth = source.linewidth;
  14041. this.linecap = source.linecap;
  14042. this.linejoin = source.linejoin;
  14043. return this;
  14044. };
  14045. /**
  14046. * @author mrdoob / http://mrdoob.com/
  14047. */
  14048. function Line( geometry, material, mode ) {
  14049. if ( mode === 1 ) {
  14050. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14051. return new LineSegments( geometry, material );
  14052. }
  14053. Object3D.call( this );
  14054. this.type = 'Line';
  14055. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14056. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14057. }
  14058. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14059. constructor: Line,
  14060. isLine: true,
  14061. raycast: ( function () {
  14062. var inverseMatrix = new Matrix4();
  14063. var ray = new Ray();
  14064. var sphere = new Sphere();
  14065. return function raycast( raycaster, intersects ) {
  14066. var precision = raycaster.linePrecision;
  14067. var precisionSq = precision * precision;
  14068. var geometry = this.geometry;
  14069. var matrixWorld = this.matrixWorld;
  14070. // Checking boundingSphere distance to ray
  14071. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14072. sphere.copy( geometry.boundingSphere );
  14073. sphere.applyMatrix4( matrixWorld );
  14074. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14075. //
  14076. inverseMatrix.getInverse( matrixWorld );
  14077. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14078. var vStart = new Vector3();
  14079. var vEnd = new Vector3();
  14080. var interSegment = new Vector3();
  14081. var interRay = new Vector3();
  14082. var step = (this && this.isLineSegments) ? 2 : 1;
  14083. if ( geometry.isBufferGeometry ) {
  14084. var index = geometry.index;
  14085. var attributes = geometry.attributes;
  14086. var positions = attributes.position.array;
  14087. if ( index !== null ) {
  14088. var indices = index.array;
  14089. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14090. var a = indices[ i ];
  14091. var b = indices[ i + 1 ];
  14092. vStart.fromArray( positions, a * 3 );
  14093. vEnd.fromArray( positions, b * 3 );
  14094. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14095. if ( distSq > precisionSq ) continue;
  14096. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14097. var distance = raycaster.ray.origin.distanceTo( interRay );
  14098. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14099. intersects.push( {
  14100. distance: distance,
  14101. // What do we want? intersection point on the ray or on the segment??
  14102. // point: raycaster.ray.at( distance ),
  14103. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14104. index: i,
  14105. face: null,
  14106. faceIndex: null,
  14107. object: this
  14108. } );
  14109. }
  14110. } else {
  14111. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14112. vStart.fromArray( positions, 3 * i );
  14113. vEnd.fromArray( positions, 3 * i + 3 );
  14114. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14115. if ( distSq > precisionSq ) continue;
  14116. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14117. var distance = raycaster.ray.origin.distanceTo( interRay );
  14118. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14119. intersects.push( {
  14120. distance: distance,
  14121. // What do we want? intersection point on the ray or on the segment??
  14122. // point: raycaster.ray.at( distance ),
  14123. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14124. index: i,
  14125. face: null,
  14126. faceIndex: null,
  14127. object: this
  14128. } );
  14129. }
  14130. }
  14131. } else if ( geometry.isGeometry ) {
  14132. var vertices = geometry.vertices;
  14133. var nbVertices = vertices.length;
  14134. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14135. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14136. if ( distSq > precisionSq ) continue;
  14137. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14138. var distance = raycaster.ray.origin.distanceTo( interRay );
  14139. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14140. intersects.push( {
  14141. distance: distance,
  14142. // What do we want? intersection point on the ray or on the segment??
  14143. // point: raycaster.ray.at( distance ),
  14144. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14145. index: i,
  14146. face: null,
  14147. faceIndex: null,
  14148. object: this
  14149. } );
  14150. }
  14151. }
  14152. };
  14153. }() ),
  14154. clone: function () {
  14155. return new this.constructor( this.geometry, this.material ).copy( this );
  14156. }
  14157. } );
  14158. /**
  14159. * @author mrdoob / http://mrdoob.com/
  14160. */
  14161. function LineSegments( geometry, material ) {
  14162. Line.call( this, geometry, material );
  14163. this.type = 'LineSegments';
  14164. }
  14165. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14166. constructor: LineSegments,
  14167. isLineSegments: true
  14168. } );
  14169. /**
  14170. * @author mgreter / http://github.com/mgreter
  14171. */
  14172. function LineLoop( geometry, material ) {
  14173. Line.call( this, geometry, material );
  14174. this.type = 'LineLoop';
  14175. }
  14176. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  14177. constructor: LineLoop,
  14178. isLineLoop: true,
  14179. } );
  14180. /**
  14181. * @author mrdoob / http://mrdoob.com/
  14182. * @author alteredq / http://alteredqualia.com/
  14183. *
  14184. * parameters = {
  14185. * color: <hex>,
  14186. * opacity: <float>,
  14187. * map: new THREE.Texture( <Image> ),
  14188. *
  14189. * size: <float>,
  14190. * sizeAttenuation: <bool>
  14191. * }
  14192. */
  14193. function PointsMaterial( parameters ) {
  14194. Material.call( this );
  14195. this.type = 'PointsMaterial';
  14196. this.color = new Color( 0xffffff );
  14197. this.map = null;
  14198. this.size = 1;
  14199. this.sizeAttenuation = true;
  14200. this.lights = false;
  14201. this.setValues( parameters );
  14202. }
  14203. PointsMaterial.prototype = Object.create( Material.prototype );
  14204. PointsMaterial.prototype.constructor = PointsMaterial;
  14205. PointsMaterial.prototype.isPointsMaterial = true;
  14206. PointsMaterial.prototype.copy = function ( source ) {
  14207. Material.prototype.copy.call( this, source );
  14208. this.color.copy( source.color );
  14209. this.map = source.map;
  14210. this.size = source.size;
  14211. this.sizeAttenuation = source.sizeAttenuation;
  14212. return this;
  14213. };
  14214. /**
  14215. * @author alteredq / http://alteredqualia.com/
  14216. */
  14217. function Points( geometry, material ) {
  14218. Object3D.call( this );
  14219. this.type = 'Points';
  14220. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14221. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  14222. }
  14223. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14224. constructor: Points,
  14225. isPoints: true,
  14226. raycast: ( function () {
  14227. var inverseMatrix = new Matrix4();
  14228. var ray = new Ray();
  14229. var sphere = new Sphere();
  14230. return function raycast( raycaster, intersects ) {
  14231. var object = this;
  14232. var geometry = this.geometry;
  14233. var matrixWorld = this.matrixWorld;
  14234. var threshold = raycaster.params.Points.threshold;
  14235. // Checking boundingSphere distance to ray
  14236. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14237. sphere.copy( geometry.boundingSphere );
  14238. sphere.applyMatrix4( matrixWorld );
  14239. sphere.radius += threshold;
  14240. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14241. //
  14242. inverseMatrix.getInverse( matrixWorld );
  14243. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14244. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  14245. var localThresholdSq = localThreshold * localThreshold;
  14246. var position = new Vector3();
  14247. function testPoint( point, index ) {
  14248. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  14249. if ( rayPointDistanceSq < localThresholdSq ) {
  14250. var intersectPoint = ray.closestPointToPoint( point );
  14251. intersectPoint.applyMatrix4( matrixWorld );
  14252. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14253. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14254. intersects.push( {
  14255. distance: distance,
  14256. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  14257. point: intersectPoint.clone(),
  14258. index: index,
  14259. face: null,
  14260. object: object
  14261. } );
  14262. }
  14263. }
  14264. if ( geometry.isBufferGeometry ) {
  14265. var index = geometry.index;
  14266. var attributes = geometry.attributes;
  14267. var positions = attributes.position.array;
  14268. if ( index !== null ) {
  14269. var indices = index.array;
  14270. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  14271. var a = indices[ i ];
  14272. position.fromArray( positions, a * 3 );
  14273. testPoint( position, a );
  14274. }
  14275. } else {
  14276. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  14277. position.fromArray( positions, i * 3 );
  14278. testPoint( position, i );
  14279. }
  14280. }
  14281. } else {
  14282. var vertices = geometry.vertices;
  14283. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  14284. testPoint( vertices[ i ], i );
  14285. }
  14286. }
  14287. };
  14288. }() ),
  14289. clone: function () {
  14290. return new this.constructor( this.geometry, this.material ).copy( this );
  14291. }
  14292. } );
  14293. /**
  14294. * @author mrdoob / http://mrdoob.com/
  14295. */
  14296. function Group() {
  14297. Object3D.call( this );
  14298. this.type = 'Group';
  14299. }
  14300. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14301. constructor: Group
  14302. } );
  14303. /**
  14304. * @author mrdoob / http://mrdoob.com/
  14305. */
  14306. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  14307. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14308. this.generateMipmaps = false;
  14309. var scope = this;
  14310. function update() {
  14311. requestAnimationFrame( update );
  14312. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  14313. scope.needsUpdate = true;
  14314. }
  14315. }
  14316. update();
  14317. }
  14318. VideoTexture.prototype = Object.create( Texture.prototype );
  14319. VideoTexture.prototype.constructor = VideoTexture;
  14320. /**
  14321. * @author alteredq / http://alteredqualia.com/
  14322. */
  14323. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  14324. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  14325. this.image = { width: width, height: height };
  14326. this.mipmaps = mipmaps;
  14327. // no flipping for cube textures
  14328. // (also flipping doesn't work for compressed textures )
  14329. this.flipY = false;
  14330. // can't generate mipmaps for compressed textures
  14331. // mips must be embedded in DDS files
  14332. this.generateMipmaps = false;
  14333. }
  14334. CompressedTexture.prototype = Object.create( Texture.prototype );
  14335. CompressedTexture.prototype.constructor = CompressedTexture;
  14336. CompressedTexture.prototype.isCompressedTexture = true;
  14337. /**
  14338. * @author mrdoob / http://mrdoob.com/
  14339. */
  14340. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  14341. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14342. this.needsUpdate = true;
  14343. }
  14344. CanvasTexture.prototype = Object.create( Texture.prototype );
  14345. CanvasTexture.prototype.constructor = CanvasTexture;
  14346. /**
  14347. * @author Matt DesLauriers / @mattdesl
  14348. * @author atix / arthursilber.de
  14349. */
  14350. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  14351. format = format !== undefined ? format : DepthFormat;
  14352. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  14353. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' )
  14354. }
  14355. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  14356. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  14357. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14358. this.image = { width: width, height: height };
  14359. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  14360. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  14361. this.flipY = false;
  14362. this.generateMipmaps = false;
  14363. }
  14364. DepthTexture.prototype = Object.create( Texture.prototype );
  14365. DepthTexture.prototype.constructor = DepthTexture;
  14366. DepthTexture.prototype.isDepthTexture = true;
  14367. /**
  14368. * @author mrdoob / http://mrdoob.com/
  14369. * @author Mugen87 / https://github.com/Mugen87
  14370. */
  14371. function WireframeGeometry( geometry ) {
  14372. BufferGeometry.call( this );
  14373. this.type = 'WireframeGeometry';
  14374. // buffer
  14375. var vertices = [];
  14376. // helper variables
  14377. var i, j, l, o, ol;
  14378. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  14379. var key, keys = [ 'a', 'b', 'c' ];
  14380. var vertex;
  14381. // different logic for Geometry and BufferGeometry
  14382. if ( geometry && geometry.isGeometry ) {
  14383. // create a data structure that contains all edges without duplicates
  14384. var faces = geometry.faces;
  14385. for ( i = 0, l = faces.length; i < l; i ++ ) {
  14386. var face = faces[ i ];
  14387. for ( j = 0; j < 3; j ++ ) {
  14388. edge1 = face[ keys[ j ] ];
  14389. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  14390. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14391. edge[ 1 ] = Math.max( edge1, edge2 );
  14392. key = edge[ 0 ] + ',' + edge[ 1 ];
  14393. if ( edges[ key ] === undefined ) {
  14394. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14395. }
  14396. }
  14397. }
  14398. // generate vertices
  14399. for ( key in edges ) {
  14400. e = edges[ key ];
  14401. vertex = geometry.vertices[ e.index1 ];
  14402. vertices.push( vertex.x, vertex.y, vertex.z );
  14403. vertex = geometry.vertices[ e.index2 ];
  14404. vertices.push( vertex.x, vertex.y, vertex.z );
  14405. }
  14406. } else if ( geometry && geometry.isBufferGeometry ) {
  14407. var position, indices, groups;
  14408. var group, start, count;
  14409. var index1, index2;
  14410. vertex = new Vector3();
  14411. if ( geometry.index !== null ) {
  14412. // indexed BufferGeometry
  14413. position = geometry.attributes.position;
  14414. indices = geometry.index;
  14415. groups = geometry.groups;
  14416. if ( groups.length === 0 ) {
  14417. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  14418. }
  14419. // create a data structure that contains all eges without duplicates
  14420. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  14421. group = groups[ o ];
  14422. start = group.start;
  14423. count = group.count;
  14424. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  14425. for ( j = 0; j < 3; j ++ ) {
  14426. edge1 = indices.getX( i + j );
  14427. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  14428. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14429. edge[ 1 ] = Math.max( edge1, edge2 );
  14430. key = edge[ 0 ] + ',' + edge[ 1 ];
  14431. if ( edges[ key ] === undefined ) {
  14432. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14433. }
  14434. }
  14435. }
  14436. }
  14437. // generate vertices
  14438. for ( key in edges ) {
  14439. e = edges[ key ];
  14440. vertex.fromBufferAttribute( position, e.index1 );
  14441. vertices.push( vertex.x, vertex.y, vertex.z );
  14442. vertex.fromBufferAttribute( position, e.index2 );
  14443. vertices.push( vertex.x, vertex.y, vertex.z );
  14444. }
  14445. } else {
  14446. // non-indexed BufferGeometry
  14447. position = geometry.attributes.position;
  14448. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  14449. for ( j = 0; j < 3; j ++ ) {
  14450. // three edges per triangle, an edge is represented as (index1, index2)
  14451. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  14452. index1 = 3 * i + j;
  14453. vertex.fromBufferAttribute( position, index1 );
  14454. vertices.push( vertex.x, vertex.y, vertex.z );
  14455. index2 = 3 * i + ( ( j + 1 ) % 3 );
  14456. vertex.fromBufferAttribute( position, index2 );
  14457. vertices.push( vertex.x, vertex.y, vertex.z );
  14458. }
  14459. }
  14460. }
  14461. }
  14462. // build geometry
  14463. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14464. }
  14465. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  14466. WireframeGeometry.prototype.constructor = WireframeGeometry;
  14467. /**
  14468. * @author zz85 / https://github.com/zz85
  14469. * @author Mugen87 / https://github.com/Mugen87
  14470. *
  14471. * Parametric Surfaces Geometry
  14472. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  14473. */
  14474. // ParametricGeometry
  14475. function ParametricGeometry( func, slices, stacks ) {
  14476. Geometry.call( this );
  14477. this.type = 'ParametricGeometry';
  14478. this.parameters = {
  14479. func: func,
  14480. slices: slices,
  14481. stacks: stacks
  14482. };
  14483. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  14484. this.mergeVertices();
  14485. }
  14486. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  14487. ParametricGeometry.prototype.constructor = ParametricGeometry;
  14488. // ParametricBufferGeometry
  14489. function ParametricBufferGeometry( func, slices, stacks ) {
  14490. BufferGeometry.call( this );
  14491. this.type = 'ParametricBufferGeometry';
  14492. this.parameters = {
  14493. func: func,
  14494. slices: slices,
  14495. stacks: stacks
  14496. };
  14497. // buffers
  14498. var indices = [];
  14499. var vertices = [];
  14500. var normals = [];
  14501. var uvs = [];
  14502. var EPS = 0.00001;
  14503. var normal = new Vector3();
  14504. var p0 = new Vector3(), p1 = new Vector3();
  14505. var pu = new Vector3(), pv = new Vector3();
  14506. var i, j;
  14507. // generate vertices, normals and uvs
  14508. var sliceCount = slices + 1;
  14509. for ( i = 0; i <= stacks; i ++ ) {
  14510. var v = i / stacks;
  14511. for ( j = 0; j <= slices; j ++ ) {
  14512. var u = j / slices;
  14513. // vertex
  14514. p0 = func( u, v, p0 );
  14515. vertices.push( p0.x, p0.y, p0.z );
  14516. // normal
  14517. // approximate tangent vectors via finite differences
  14518. if ( u - EPS >= 0 ) {
  14519. p1 = func( u - EPS, v, p1 );
  14520. pu.subVectors( p0, p1 );
  14521. } else {
  14522. p1 = func( u + EPS, v, p1 );
  14523. pu.subVectors( p1, p0 );
  14524. }
  14525. if ( v - EPS >= 0 ) {
  14526. p1 = func( u, v - EPS, p1 );
  14527. pv.subVectors( p0, p1 );
  14528. } else {
  14529. p1 = func( u, v + EPS, p1 );
  14530. pv.subVectors( p1, p0 );
  14531. }
  14532. // cross product of tangent vectors returns surface normal
  14533. normal.crossVectors( pu, pv ).normalize();
  14534. normals.push( normal.x, normal.y, normal.z );
  14535. // uv
  14536. uvs.push( u, v );
  14537. }
  14538. }
  14539. // generate indices
  14540. for ( i = 0; i < stacks; i ++ ) {
  14541. for ( j = 0; j < slices; j ++ ) {
  14542. var a = i * sliceCount + j;
  14543. var b = i * sliceCount + j + 1;
  14544. var c = ( i + 1 ) * sliceCount + j + 1;
  14545. var d = ( i + 1 ) * sliceCount + j;
  14546. // faces one and two
  14547. indices.push( a, b, d );
  14548. indices.push( b, c, d );
  14549. }
  14550. }
  14551. // build geometry
  14552. this.setIndex( indices );
  14553. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14554. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  14555. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  14556. }
  14557. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  14558. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  14559. /**
  14560. * @author clockworkgeek / https://github.com/clockworkgeek
  14561. * @author timothypratley / https://github.com/timothypratley
  14562. * @author WestLangley / http://github.com/WestLangley
  14563. * @author Mugen87 / https://github.com/Mugen87
  14564. */
  14565. // PolyhedronGeometry
  14566. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  14567. Geometry.call( this );
  14568. this.type = 'PolyhedronGeometry';
  14569. this.parameters = {
  14570. vertices: vertices,
  14571. indices: indices,
  14572. radius: radius,
  14573. detail: detail
  14574. };
  14575. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  14576. this.mergeVertices();
  14577. }
  14578. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  14579. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  14580. // PolyhedronBufferGeometry
  14581. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  14582. BufferGeometry.call( this );
  14583. this.type = 'PolyhedronBufferGeometry';
  14584. this.parameters = {
  14585. vertices: vertices,
  14586. indices: indices,
  14587. radius: radius,
  14588. detail: detail
  14589. };
  14590. radius = radius || 1;
  14591. detail = detail || 0;
  14592. // default buffer data
  14593. var vertexBuffer = [];
  14594. var uvBuffer = [];
  14595. // the subdivision creates the vertex buffer data
  14596. subdivide( detail );
  14597. // all vertices should lie on a conceptual sphere with a given radius
  14598. appplyRadius( radius );
  14599. // finally, create the uv data
  14600. generateUVs();
  14601. // build non-indexed geometry
  14602. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  14603. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  14604. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  14605. if ( detail === 0 ) {
  14606. this.computeVertexNormals(); // flat normals
  14607. } else {
  14608. this.normalizeNormals(); // smooth normals
  14609. }
  14610. // helper functions
  14611. function subdivide( detail ) {
  14612. var a = new Vector3();
  14613. var b = new Vector3();
  14614. var c = new Vector3();
  14615. // iterate over all faces and apply a subdivison with the given detail value
  14616. for ( var i = 0; i < indices.length; i += 3 ) {
  14617. // get the vertices of the face
  14618. getVertexByIndex( indices[ i + 0 ], a );
  14619. getVertexByIndex( indices[ i + 1 ], b );
  14620. getVertexByIndex( indices[ i + 2 ], c );
  14621. // perform subdivision
  14622. subdivideFace( a, b, c, detail );
  14623. }
  14624. }
  14625. function subdivideFace( a, b, c, detail ) {
  14626. var cols = Math.pow( 2, detail );
  14627. // we use this multidimensional array as a data structure for creating the subdivision
  14628. var v = [];
  14629. var i, j;
  14630. // construct all of the vertices for this subdivision
  14631. for ( i = 0; i <= cols; i ++ ) {
  14632. v[ i ] = [];
  14633. var aj = a.clone().lerp( c, i / cols );
  14634. var bj = b.clone().lerp( c, i / cols );
  14635. var rows = cols - i;
  14636. for ( j = 0; j <= rows; j ++ ) {
  14637. if ( j === 0 && i === cols ) {
  14638. v[ i ][ j ] = aj;
  14639. } else {
  14640. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  14641. }
  14642. }
  14643. }
  14644. // construct all of the faces
  14645. for ( i = 0; i < cols; i ++ ) {
  14646. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  14647. var k = Math.floor( j / 2 );
  14648. if ( j % 2 === 0 ) {
  14649. pushVertex( v[ i ][ k + 1 ] );
  14650. pushVertex( v[ i + 1 ][ k ] );
  14651. pushVertex( v[ i ][ k ] );
  14652. } else {
  14653. pushVertex( v[ i ][ k + 1 ] );
  14654. pushVertex( v[ i + 1 ][ k + 1 ] );
  14655. pushVertex( v[ i + 1 ][ k ] );
  14656. }
  14657. }
  14658. }
  14659. }
  14660. function appplyRadius( radius ) {
  14661. var vertex = new Vector3();
  14662. // iterate over the entire buffer and apply the radius to each vertex
  14663. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  14664. vertex.x = vertexBuffer[ i + 0 ];
  14665. vertex.y = vertexBuffer[ i + 1 ];
  14666. vertex.z = vertexBuffer[ i + 2 ];
  14667. vertex.normalize().multiplyScalar( radius );
  14668. vertexBuffer[ i + 0 ] = vertex.x;
  14669. vertexBuffer[ i + 1 ] = vertex.y;
  14670. vertexBuffer[ i + 2 ] = vertex.z;
  14671. }
  14672. }
  14673. function generateUVs() {
  14674. var vertex = new Vector3();
  14675. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  14676. vertex.x = vertexBuffer[ i + 0 ];
  14677. vertex.y = vertexBuffer[ i + 1 ];
  14678. vertex.z = vertexBuffer[ i + 2 ];
  14679. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  14680. var v = inclination( vertex ) / Math.PI + 0.5;
  14681. uvBuffer.push( u, 1 - v );
  14682. }
  14683. correctUVs();
  14684. correctSeam();
  14685. }
  14686. function correctSeam() {
  14687. // handle case when face straddles the seam, see #3269
  14688. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  14689. // uv data of a single face
  14690. var x0 = uvBuffer[ i + 0 ];
  14691. var x1 = uvBuffer[ i + 2 ];
  14692. var x2 = uvBuffer[ i + 4 ];
  14693. var max = Math.max( x0, x1, x2 );
  14694. var min = Math.min( x0, x1, x2 );
  14695. // 0.9 is somewhat arbitrary
  14696. if ( max > 0.9 && min < 0.1 ) {
  14697. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  14698. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  14699. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  14700. }
  14701. }
  14702. }
  14703. function pushVertex( vertex ) {
  14704. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  14705. }
  14706. function getVertexByIndex( index, vertex ) {
  14707. var stride = index * 3;
  14708. vertex.x = vertices[ stride + 0 ];
  14709. vertex.y = vertices[ stride + 1 ];
  14710. vertex.z = vertices[ stride + 2 ];
  14711. }
  14712. function correctUVs() {
  14713. var a = new Vector3();
  14714. var b = new Vector3();
  14715. var c = new Vector3();
  14716. var centroid = new Vector3();
  14717. var uvA = new Vector2();
  14718. var uvB = new Vector2();
  14719. var uvC = new Vector2();
  14720. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  14721. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  14722. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  14723. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  14724. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  14725. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  14726. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  14727. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  14728. var azi = azimuth( centroid );
  14729. correctUV( uvA, j + 0, a, azi );
  14730. correctUV( uvB, j + 2, b, azi );
  14731. correctUV( uvC, j + 4, c, azi );
  14732. }
  14733. }
  14734. function correctUV( uv, stride, vector, azimuth ) {
  14735. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  14736. uvBuffer[ stride ] = uv.x - 1;
  14737. }
  14738. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  14739. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  14740. }
  14741. }
  14742. // Angle around the Y axis, counter-clockwise when looking from above.
  14743. function azimuth( vector ) {
  14744. return Math.atan2( vector.z, - vector.x );
  14745. }
  14746. // Angle above the XZ plane.
  14747. function inclination( vector ) {
  14748. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  14749. }
  14750. }
  14751. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  14752. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  14753. /**
  14754. * @author timothypratley / https://github.com/timothypratley
  14755. * @author Mugen87 / https://github.com/Mugen87
  14756. */
  14757. // TetrahedronGeometry
  14758. function TetrahedronGeometry( radius, detail ) {
  14759. Geometry.call( this );
  14760. this.type = 'TetrahedronGeometry';
  14761. this.parameters = {
  14762. radius: radius,
  14763. detail: detail
  14764. };
  14765. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  14766. this.mergeVertices();
  14767. }
  14768. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  14769. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  14770. // TetrahedronBufferGeometry
  14771. function TetrahedronBufferGeometry( radius, detail ) {
  14772. var vertices = [
  14773. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  14774. ];
  14775. var indices = [
  14776. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  14777. ];
  14778. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14779. this.type = 'TetrahedronBufferGeometry';
  14780. this.parameters = {
  14781. radius: radius,
  14782. detail: detail
  14783. };
  14784. }
  14785. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14786. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  14787. /**
  14788. * @author timothypratley / https://github.com/timothypratley
  14789. * @author Mugen87 / https://github.com/Mugen87
  14790. */
  14791. // OctahedronGeometry
  14792. function OctahedronGeometry( radius, detail ) {
  14793. Geometry.call( this );
  14794. this.type = 'OctahedronGeometry';
  14795. this.parameters = {
  14796. radius: radius,
  14797. detail: detail
  14798. };
  14799. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  14800. this.mergeVertices();
  14801. }
  14802. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  14803. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  14804. // OctahedronBufferGeometry
  14805. function OctahedronBufferGeometry( radius, detail ) {
  14806. var vertices = [
  14807. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  14808. ];
  14809. var indices = [
  14810. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  14811. ];
  14812. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14813. this.type = 'OctahedronBufferGeometry';
  14814. this.parameters = {
  14815. radius: radius,
  14816. detail: detail
  14817. };
  14818. }
  14819. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14820. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  14821. /**
  14822. * @author timothypratley / https://github.com/timothypratley
  14823. * @author Mugen87 / https://github.com/Mugen87
  14824. */
  14825. // IcosahedronGeometry
  14826. function IcosahedronGeometry( radius, detail ) {
  14827. Geometry.call( this );
  14828. this.type = 'IcosahedronGeometry';
  14829. this.parameters = {
  14830. radius: radius,
  14831. detail: detail
  14832. };
  14833. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  14834. this.mergeVertices();
  14835. }
  14836. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  14837. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  14838. // IcosahedronBufferGeometry
  14839. function IcosahedronBufferGeometry( radius, detail ) {
  14840. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  14841. var vertices = [
  14842. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  14843. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  14844. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  14845. ];
  14846. var indices = [
  14847. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  14848. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  14849. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  14850. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  14851. ];
  14852. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14853. this.type = 'IcosahedronBufferGeometry';
  14854. this.parameters = {
  14855. radius: radius,
  14856. detail: detail
  14857. };
  14858. }
  14859. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14860. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  14861. /**
  14862. * @author Abe Pazos / https://hamoid.com
  14863. * @author Mugen87 / https://github.com/Mugen87
  14864. */
  14865. // DodecahedronGeometry
  14866. function DodecahedronGeometry( radius, detail ) {
  14867. Geometry.call( this );
  14868. this.type = 'DodecahedronGeometry';
  14869. this.parameters = {
  14870. radius: radius,
  14871. detail: detail
  14872. };
  14873. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  14874. this.mergeVertices();
  14875. }
  14876. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  14877. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  14878. // DodecahedronBufferGeometry
  14879. function DodecahedronBufferGeometry( radius, detail ) {
  14880. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  14881. var r = 1 / t;
  14882. var vertices = [
  14883. // (±1, ±1, ±1)
  14884. - 1, - 1, - 1, - 1, - 1, 1,
  14885. - 1, 1, - 1, - 1, 1, 1,
  14886. 1, - 1, - 1, 1, - 1, 1,
  14887. 1, 1, - 1, 1, 1, 1,
  14888. // (0, ±1/φ, ±φ)
  14889. 0, - r, - t, 0, - r, t,
  14890. 0, r, - t, 0, r, t,
  14891. // (±1/φ, ±φ, 0)
  14892. - r, - t, 0, - r, t, 0,
  14893. r, - t, 0, r, t, 0,
  14894. // (±φ, 0, ±1/φ)
  14895. - t, 0, - r, t, 0, - r,
  14896. - t, 0, r, t, 0, r
  14897. ];
  14898. var indices = [
  14899. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  14900. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  14901. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  14902. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  14903. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  14904. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  14905. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  14906. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  14907. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  14908. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  14909. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  14910. 1, 12, 14, 1, 14, 5, 1, 5, 9
  14911. ];
  14912. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14913. this.type = 'DodecahedronBufferGeometry';
  14914. this.parameters = {
  14915. radius: radius,
  14916. detail: detail
  14917. };
  14918. }
  14919. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14920. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  14921. /**
  14922. * @author oosmoxiecode / https://github.com/oosmoxiecode
  14923. * @author WestLangley / https://github.com/WestLangley
  14924. * @author zz85 / https://github.com/zz85
  14925. * @author miningold / https://github.com/miningold
  14926. * @author jonobr1 / https://github.com/jonobr1
  14927. * @author Mugen87 / https://github.com/Mugen87
  14928. *
  14929. */
  14930. // TubeGeometry
  14931. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  14932. Geometry.call( this );
  14933. this.type = 'TubeGeometry';
  14934. this.parameters = {
  14935. path: path,
  14936. tubularSegments: tubularSegments,
  14937. radius: radius,
  14938. radialSegments: radialSegments,
  14939. closed: closed
  14940. };
  14941. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  14942. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  14943. // expose internals
  14944. this.tangents = bufferGeometry.tangents;
  14945. this.normals = bufferGeometry.normals;
  14946. this.binormals = bufferGeometry.binormals;
  14947. // create geometry
  14948. this.fromBufferGeometry( bufferGeometry );
  14949. this.mergeVertices();
  14950. }
  14951. TubeGeometry.prototype = Object.create( Geometry.prototype );
  14952. TubeGeometry.prototype.constructor = TubeGeometry;
  14953. // TubeBufferGeometry
  14954. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  14955. BufferGeometry.call( this );
  14956. this.type = 'TubeBufferGeometry';
  14957. this.parameters = {
  14958. path: path,
  14959. tubularSegments: tubularSegments,
  14960. radius: radius,
  14961. radialSegments: radialSegments,
  14962. closed: closed
  14963. };
  14964. tubularSegments = tubularSegments || 64;
  14965. radius = radius || 1;
  14966. radialSegments = radialSegments || 8;
  14967. closed = closed || false;
  14968. var frames = path.computeFrenetFrames( tubularSegments, closed );
  14969. // expose internals
  14970. this.tangents = frames.tangents;
  14971. this.normals = frames.normals;
  14972. this.binormals = frames.binormals;
  14973. // helper variables
  14974. var vertex = new Vector3();
  14975. var normal = new Vector3();
  14976. var uv = new Vector2();
  14977. var i, j;
  14978. // buffer
  14979. var vertices = [];
  14980. var normals = [];
  14981. var uvs = [];
  14982. var indices = [];
  14983. // create buffer data
  14984. generateBufferData();
  14985. // build geometry
  14986. this.setIndex( indices );
  14987. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14988. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  14989. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  14990. // functions
  14991. function generateBufferData() {
  14992. for ( i = 0; i < tubularSegments; i ++ ) {
  14993. generateSegment( i );
  14994. }
  14995. // if the geometry is not closed, generate the last row of vertices and normals
  14996. // at the regular position on the given path
  14997. //
  14998. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  14999. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  15000. // uvs are generated in a separate function.
  15001. // this makes it easy compute correct values for closed geometries
  15002. generateUVs();
  15003. // finally create faces
  15004. generateIndices();
  15005. }
  15006. function generateSegment( i ) {
  15007. // we use getPointAt to sample evenly distributed points from the given path
  15008. var P = path.getPointAt( i / tubularSegments );
  15009. // retrieve corresponding normal and binormal
  15010. var N = frames.normals[ i ];
  15011. var B = frames.binormals[ i ];
  15012. // generate normals and vertices for the current segment
  15013. for ( j = 0; j <= radialSegments; j ++ ) {
  15014. var v = j / radialSegments * Math.PI * 2;
  15015. var sin = Math.sin( v );
  15016. var cos = - Math.cos( v );
  15017. // normal
  15018. normal.x = ( cos * N.x + sin * B.x );
  15019. normal.y = ( cos * N.y + sin * B.y );
  15020. normal.z = ( cos * N.z + sin * B.z );
  15021. normal.normalize();
  15022. normals.push( normal.x, normal.y, normal.z );
  15023. // vertex
  15024. vertex.x = P.x + radius * normal.x;
  15025. vertex.y = P.y + radius * normal.y;
  15026. vertex.z = P.z + radius * normal.z;
  15027. vertices.push( vertex.x, vertex.y, vertex.z );
  15028. }
  15029. }
  15030. function generateIndices() {
  15031. for ( j = 1; j <= tubularSegments; j ++ ) {
  15032. for ( i = 1; i <= radialSegments; i ++ ) {
  15033. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15034. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15035. var c = ( radialSegments + 1 ) * j + i;
  15036. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15037. // faces
  15038. indices.push( a, b, d );
  15039. indices.push( b, c, d );
  15040. }
  15041. }
  15042. }
  15043. function generateUVs() {
  15044. for ( i = 0; i <= tubularSegments; i ++ ) {
  15045. for ( j = 0; j <= radialSegments; j ++ ) {
  15046. uv.x = i / tubularSegments;
  15047. uv.y = j / radialSegments;
  15048. uvs.push( uv.x, uv.y );
  15049. }
  15050. }
  15051. }
  15052. }
  15053. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15054. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  15055. /**
  15056. * @author oosmoxiecode
  15057. * @author Mugen87 / https://github.com/Mugen87
  15058. *
  15059. * based on http://www.blackpawn.com/texts/pqtorus/
  15060. */
  15061. // TorusKnotGeometry
  15062. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  15063. Geometry.call( this );
  15064. this.type = 'TorusKnotGeometry';
  15065. this.parameters = {
  15066. radius: radius,
  15067. tube: tube,
  15068. tubularSegments: tubularSegments,
  15069. radialSegments: radialSegments,
  15070. p: p,
  15071. q: q
  15072. };
  15073. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  15074. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  15075. this.mergeVertices();
  15076. }
  15077. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  15078. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  15079. // TorusKnotBufferGeometry
  15080. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  15081. BufferGeometry.call( this );
  15082. this.type = 'TorusKnotBufferGeometry';
  15083. this.parameters = {
  15084. radius: radius,
  15085. tube: tube,
  15086. tubularSegments: tubularSegments,
  15087. radialSegments: radialSegments,
  15088. p: p,
  15089. q: q
  15090. };
  15091. radius = radius || 100;
  15092. tube = tube || 40;
  15093. tubularSegments = Math.floor( tubularSegments ) || 64;
  15094. radialSegments = Math.floor( radialSegments ) || 8;
  15095. p = p || 2;
  15096. q = q || 3;
  15097. // buffers
  15098. var indices = [];
  15099. var vertices = [];
  15100. var normals = [];
  15101. var uvs = [];
  15102. // helper variables
  15103. var i, j;
  15104. var vertex = new Vector3();
  15105. var normal = new Vector3();
  15106. var P1 = new Vector3();
  15107. var P2 = new Vector3();
  15108. var B = new Vector3();
  15109. var T = new Vector3();
  15110. var N = new Vector3();
  15111. // generate vertices, normals and uvs
  15112. for ( i = 0; i <= tubularSegments; ++ i ) {
  15113. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  15114. var u = i / tubularSegments * p * Math.PI * 2;
  15115. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  15116. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  15117. calculatePositionOnCurve( u, p, q, radius, P1 );
  15118. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  15119. // calculate orthonormal basis
  15120. T.subVectors( P2, P1 );
  15121. N.addVectors( P2, P1 );
  15122. B.crossVectors( T, N );
  15123. N.crossVectors( B, T );
  15124. // normalize B, N. T can be ignored, we don't use it
  15125. B.normalize();
  15126. N.normalize();
  15127. for ( j = 0; j <= radialSegments; ++ j ) {
  15128. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  15129. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  15130. var v = j / radialSegments * Math.PI * 2;
  15131. var cx = - tube * Math.cos( v );
  15132. var cy = tube * Math.sin( v );
  15133. // now calculate the final vertex position.
  15134. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  15135. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  15136. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  15137. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  15138. vertices.push( vertex.x, vertex.y, vertex.z );
  15139. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  15140. normal.subVectors( vertex, P1 ).normalize();
  15141. normals.push( normal.x, normal.y, normal.z );
  15142. // uv
  15143. uvs.push( i / tubularSegments );
  15144. uvs.push( j / radialSegments );
  15145. }
  15146. }
  15147. // generate indices
  15148. for ( j = 1; j <= tubularSegments; j ++ ) {
  15149. for ( i = 1; i <= radialSegments; i ++ ) {
  15150. // indices
  15151. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15152. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15153. var c = ( radialSegments + 1 ) * j + i;
  15154. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15155. // faces
  15156. indices.push( a, b, d );
  15157. indices.push( b, c, d );
  15158. }
  15159. }
  15160. // build geometry
  15161. this.setIndex( indices );
  15162. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15163. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15164. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15165. // this function calculates the current position on the torus curve
  15166. function calculatePositionOnCurve( u, p, q, radius, position ) {
  15167. var cu = Math.cos( u );
  15168. var su = Math.sin( u );
  15169. var quOverP = q / p * u;
  15170. var cs = Math.cos( quOverP );
  15171. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  15172. position.y = radius * ( 2 + cs ) * su * 0.5;
  15173. position.z = radius * Math.sin( quOverP ) * 0.5;
  15174. }
  15175. }
  15176. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15177. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  15178. /**
  15179. * @author oosmoxiecode
  15180. * @author mrdoob / http://mrdoob.com/
  15181. * @author Mugen87 / https://github.com/Mugen87
  15182. */
  15183. // TorusGeometry
  15184. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15185. Geometry.call( this );
  15186. this.type = 'TorusGeometry';
  15187. this.parameters = {
  15188. radius: radius,
  15189. tube: tube,
  15190. radialSegments: radialSegments,
  15191. tubularSegments: tubularSegments,
  15192. arc: arc
  15193. };
  15194. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  15195. this.mergeVertices();
  15196. }
  15197. TorusGeometry.prototype = Object.create( Geometry.prototype );
  15198. TorusGeometry.prototype.constructor = TorusGeometry;
  15199. // TorusBufferGeometry
  15200. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15201. BufferGeometry.call( this );
  15202. this.type = 'TorusBufferGeometry';
  15203. this.parameters = {
  15204. radius: radius,
  15205. tube: tube,
  15206. radialSegments: radialSegments,
  15207. tubularSegments: tubularSegments,
  15208. arc: arc
  15209. };
  15210. radius = radius || 100;
  15211. tube = tube || 40;
  15212. radialSegments = Math.floor( radialSegments ) || 8;
  15213. tubularSegments = Math.floor( tubularSegments ) || 6;
  15214. arc = arc || Math.PI * 2;
  15215. // buffers
  15216. var indices = [];
  15217. var vertices = [];
  15218. var normals = [];
  15219. var uvs = [];
  15220. // helper variables
  15221. var center = new Vector3();
  15222. var vertex = new Vector3();
  15223. var normal = new Vector3();
  15224. var j, i;
  15225. // generate vertices, normals and uvs
  15226. for ( j = 0; j <= radialSegments; j ++ ) {
  15227. for ( i = 0; i <= tubularSegments; i ++ ) {
  15228. var u = i / tubularSegments * arc;
  15229. var v = j / radialSegments * Math.PI * 2;
  15230. // vertex
  15231. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  15232. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  15233. vertex.z = tube * Math.sin( v );
  15234. vertices.push( vertex.x, vertex.y, vertex.z );
  15235. // normal
  15236. center.x = radius * Math.cos( u );
  15237. center.y = radius * Math.sin( u );
  15238. normal.subVectors( vertex, center ).normalize();
  15239. normals.push( normal.x, normal.y, normal.z );
  15240. // uv
  15241. uvs.push( i / tubularSegments );
  15242. uvs.push( j / radialSegments );
  15243. }
  15244. }
  15245. // generate indices
  15246. for ( j = 1; j <= radialSegments; j ++ ) {
  15247. for ( i = 1; i <= tubularSegments; i ++ ) {
  15248. // indices
  15249. var a = ( tubularSegments + 1 ) * j + i - 1;
  15250. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  15251. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  15252. var d = ( tubularSegments + 1 ) * j + i;
  15253. // faces
  15254. indices.push( a, b, d );
  15255. indices.push( b, c, d );
  15256. }
  15257. }
  15258. // build geometry
  15259. this.setIndex( indices );
  15260. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15261. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15262. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15263. }
  15264. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15265. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  15266. /**
  15267. * @author zz85 / http://www.lab4games.net/zz85/blog
  15268. */
  15269. var ShapeUtils = {
  15270. // calculate area of the contour polygon
  15271. area: function ( contour ) {
  15272. var n = contour.length;
  15273. var a = 0.0;
  15274. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  15275. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15276. }
  15277. return a * 0.5;
  15278. },
  15279. triangulate: ( function () {
  15280. /**
  15281. * This code is a quick port of code written in C++ which was submitted to
  15282. * flipcode.com by John W. Ratcliff // July 22, 2000
  15283. * See original code and more information here:
  15284. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15285. *
  15286. * ported to actionscript by Zevan Rosser
  15287. * www.actionsnippet.com
  15288. *
  15289. * ported to javascript by Joshua Koo
  15290. * http://www.lab4games.net/zz85/blog
  15291. *
  15292. */
  15293. function snip( contour, u, v, w, n, verts ) {
  15294. var p;
  15295. var ax, ay, bx, by;
  15296. var cx, cy, px, py;
  15297. ax = contour[ verts[ u ] ].x;
  15298. ay = contour[ verts[ u ] ].y;
  15299. bx = contour[ verts[ v ] ].x;
  15300. by = contour[ verts[ v ] ].y;
  15301. cx = contour[ verts[ w ] ].x;
  15302. cy = contour[ verts[ w ] ].y;
  15303. if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
  15304. var aX, aY, bX, bY, cX, cY;
  15305. var apx, apy, bpx, bpy, cpx, cpy;
  15306. var cCROSSap, bCROSScp, aCROSSbp;
  15307. aX = cx - bx; aY = cy - by;
  15308. bX = ax - cx; bY = ay - cy;
  15309. cX = bx - ax; cY = by - ay;
  15310. for ( p = 0; p < n; p ++ ) {
  15311. px = contour[ verts[ p ] ].x;
  15312. py = contour[ verts[ p ] ].y;
  15313. if ( ( ( px === ax ) && ( py === ay ) ) ||
  15314. ( ( px === bx ) && ( py === by ) ) ||
  15315. ( ( px === cx ) && ( py === cy ) ) ) continue;
  15316. apx = px - ax; apy = py - ay;
  15317. bpx = px - bx; bpy = py - by;
  15318. cpx = px - cx; cpy = py - cy;
  15319. // see if p is inside triangle abc
  15320. aCROSSbp = aX * bpy - aY * bpx;
  15321. cCROSSap = cX * apy - cY * apx;
  15322. bCROSScp = bX * cpy - bY * cpx;
  15323. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  15324. }
  15325. return true;
  15326. }
  15327. // takes in an contour array and returns
  15328. return function triangulate( contour, indices ) {
  15329. var n = contour.length;
  15330. if ( n < 3 ) return null;
  15331. var result = [],
  15332. verts = [],
  15333. vertIndices = [];
  15334. /* we want a counter-clockwise polygon in verts */
  15335. var u, v, w;
  15336. if ( ShapeUtils.area( contour ) > 0.0 ) {
  15337. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  15338. } else {
  15339. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  15340. }
  15341. var nv = n;
  15342. /* remove nv - 2 vertices, creating 1 triangle every time */
  15343. var count = 2 * nv; /* error detection */
  15344. for ( v = nv - 1; nv > 2; ) {
  15345. /* if we loop, it is probably a non-simple polygon */
  15346. if ( ( count -- ) <= 0 ) {
  15347. //** Triangulate: ERROR - probable bad polygon!
  15348. //throw ( "Warning, unable to triangulate polygon!" );
  15349. //return null;
  15350. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15351. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  15352. if ( indices ) return vertIndices;
  15353. return result;
  15354. }
  15355. /* three consecutive vertices in current polygon, <u,v,w> */
  15356. u = v; if ( nv <= u ) u = 0; /* previous */
  15357. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15358. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15359. if ( snip( contour, u, v, w, nv, verts ) ) {
  15360. var a, b, c, s, t;
  15361. /* true names of the vertices */
  15362. a = verts[ u ];
  15363. b = verts[ v ];
  15364. c = verts[ w ];
  15365. /* output Triangle */
  15366. result.push( [ contour[ a ],
  15367. contour[ b ],
  15368. contour[ c ] ] );
  15369. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15370. /* remove v from the remaining polygon */
  15371. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  15372. verts[ s ] = verts[ t ];
  15373. }
  15374. nv --;
  15375. /* reset error detection counter */
  15376. count = 2 * nv;
  15377. }
  15378. }
  15379. if ( indices ) return vertIndices;
  15380. return result;
  15381. }
  15382. } )(),
  15383. triangulateShape: function ( contour, holes ) {
  15384. function removeDupEndPts(points) {
  15385. var l = points.length;
  15386. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  15387. points.pop();
  15388. }
  15389. }
  15390. removeDupEndPts( contour );
  15391. holes.forEach( removeDupEndPts );
  15392. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  15393. // inOtherPt needs to be collinear to the inSegment
  15394. if ( inSegPt1.x !== inSegPt2.x ) {
  15395. if ( inSegPt1.x < inSegPt2.x ) {
  15396. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  15397. } else {
  15398. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  15399. }
  15400. } else {
  15401. if ( inSegPt1.y < inSegPt2.y ) {
  15402. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  15403. } else {
  15404. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  15405. }
  15406. }
  15407. }
  15408. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  15409. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  15410. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  15411. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  15412. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  15413. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  15414. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  15415. if ( Math.abs( limit ) > Number.EPSILON ) {
  15416. // not parallel
  15417. var perpSeg2;
  15418. if ( limit > 0 ) {
  15419. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  15420. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  15421. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  15422. } else {
  15423. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  15424. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  15425. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  15426. }
  15427. // i.e. to reduce rounding errors
  15428. // intersection at endpoint of segment#1?
  15429. if ( perpSeg2 === 0 ) {
  15430. if ( ( inExcludeAdjacentSegs ) &&
  15431. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  15432. return [ inSeg1Pt1 ];
  15433. }
  15434. if ( perpSeg2 === limit ) {
  15435. if ( ( inExcludeAdjacentSegs ) &&
  15436. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  15437. return [ inSeg1Pt2 ];
  15438. }
  15439. // intersection at endpoint of segment#2?
  15440. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  15441. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  15442. // return real intersection point
  15443. var factorSeg1 = perpSeg2 / limit;
  15444. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  15445. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  15446. } else {
  15447. // parallel or collinear
  15448. if ( ( perpSeg1 !== 0 ) ||
  15449. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  15450. // they are collinear or degenerate
  15451. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  15452. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  15453. // both segments are points
  15454. if ( seg1Pt && seg2Pt ) {
  15455. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  15456. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  15457. return [ inSeg1Pt1 ]; // they are the same point
  15458. }
  15459. // segment#1 is a single point
  15460. if ( seg1Pt ) {
  15461. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  15462. return [ inSeg1Pt1 ];
  15463. }
  15464. // segment#2 is a single point
  15465. if ( seg2Pt ) {
  15466. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  15467. return [ inSeg2Pt1 ];
  15468. }
  15469. // they are collinear segments, which might overlap
  15470. var seg1min, seg1max, seg1minVal, seg1maxVal;
  15471. var seg2min, seg2max, seg2minVal, seg2maxVal;
  15472. if ( seg1dx !== 0 ) {
  15473. // the segments are NOT on a vertical line
  15474. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  15475. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  15476. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  15477. } else {
  15478. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  15479. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  15480. }
  15481. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  15482. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  15483. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  15484. } else {
  15485. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  15486. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  15487. }
  15488. } else {
  15489. // the segments are on a vertical line
  15490. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  15491. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  15492. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  15493. } else {
  15494. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  15495. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  15496. }
  15497. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  15498. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  15499. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  15500. } else {
  15501. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  15502. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  15503. }
  15504. }
  15505. if ( seg1minVal <= seg2minVal ) {
  15506. if ( seg1maxVal < seg2minVal ) return [];
  15507. if ( seg1maxVal === seg2minVal ) {
  15508. if ( inExcludeAdjacentSegs ) return [];
  15509. return [ seg2min ];
  15510. }
  15511. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  15512. return [ seg2min, seg2max ];
  15513. } else {
  15514. if ( seg1minVal > seg2maxVal ) return [];
  15515. if ( seg1minVal === seg2maxVal ) {
  15516. if ( inExcludeAdjacentSegs ) return [];
  15517. return [ seg1min ];
  15518. }
  15519. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  15520. return [ seg1min, seg2max ];
  15521. }
  15522. }
  15523. }
  15524. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  15525. // The order of legs is important
  15526. // translation of all points, so that Vertex is at (0,0)
  15527. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  15528. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  15529. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  15530. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  15531. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  15532. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  15533. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  15534. // angle != 180 deg.
  15535. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  15536. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  15537. if ( from2toAngle > 0 ) {
  15538. // main angle < 180 deg.
  15539. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  15540. } else {
  15541. // main angle > 180 deg.
  15542. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  15543. }
  15544. } else {
  15545. // angle == 180 deg.
  15546. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  15547. return ( from2otherAngle > 0 );
  15548. }
  15549. }
  15550. function removeHoles( contour, holes ) {
  15551. var shape = contour.concat(); // work on this shape
  15552. var hole;
  15553. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  15554. // Check if hole point lies within angle around shape point
  15555. var lastShapeIdx = shape.length - 1;
  15556. var prevShapeIdx = inShapeIdx - 1;
  15557. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  15558. var nextShapeIdx = inShapeIdx + 1;
  15559. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  15560. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  15561. if ( ! insideAngle ) {
  15562. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  15563. return false;
  15564. }
  15565. // Check if shape point lies within angle around hole point
  15566. var lastHoleIdx = hole.length - 1;
  15567. var prevHoleIdx = inHoleIdx - 1;
  15568. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  15569. var nextHoleIdx = inHoleIdx + 1;
  15570. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  15571. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  15572. if ( ! insideAngle ) {
  15573. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  15574. return false;
  15575. }
  15576. return true;
  15577. }
  15578. function intersectsShapeEdge( inShapePt, inHolePt ) {
  15579. // checks for intersections with shape edges
  15580. var sIdx, nextIdx, intersection;
  15581. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  15582. nextIdx = sIdx + 1; nextIdx %= shape.length;
  15583. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  15584. if ( intersection.length > 0 ) return true;
  15585. }
  15586. return false;
  15587. }
  15588. var indepHoles = [];
  15589. function intersectsHoleEdge( inShapePt, inHolePt ) {
  15590. // checks for intersections with hole edges
  15591. var ihIdx, chkHole,
  15592. hIdx, nextIdx, intersection;
  15593. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  15594. chkHole = holes[ indepHoles[ ihIdx ]];
  15595. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  15596. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  15597. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  15598. if ( intersection.length > 0 ) return true;
  15599. }
  15600. }
  15601. return false;
  15602. }
  15603. var holeIndex, shapeIndex,
  15604. shapePt, holePt,
  15605. holeIdx, cutKey, failedCuts = [],
  15606. tmpShape1, tmpShape2,
  15607. tmpHole1, tmpHole2;
  15608. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  15609. indepHoles.push( h );
  15610. }
  15611. var minShapeIndex = 0;
  15612. var counter = indepHoles.length * 2;
  15613. while ( indepHoles.length > 0 ) {
  15614. counter --;
  15615. if ( counter < 0 ) {
  15616. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  15617. break;
  15618. }
  15619. // search for shape-vertex and hole-vertex,
  15620. // which can be connected without intersections
  15621. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  15622. shapePt = shape[ shapeIndex ];
  15623. holeIndex = - 1;
  15624. // search for hole which can be reached without intersections
  15625. for ( var h = 0; h < indepHoles.length; h ++ ) {
  15626. holeIdx = indepHoles[ h ];
  15627. // prevent multiple checks
  15628. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  15629. if ( failedCuts[ cutKey ] !== undefined ) continue;
  15630. hole = holes[ holeIdx ];
  15631. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  15632. holePt = hole[ h2 ];
  15633. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  15634. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  15635. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  15636. holeIndex = h2;
  15637. indepHoles.splice( h, 1 );
  15638. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  15639. tmpShape2 = shape.slice( shapeIndex );
  15640. tmpHole1 = hole.slice( holeIndex );
  15641. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  15642. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  15643. minShapeIndex = shapeIndex;
  15644. // Debug only, to show the selected cuts
  15645. // glob_CutLines.push( [ shapePt, holePt ] );
  15646. break;
  15647. }
  15648. if ( holeIndex >= 0 ) break; // hole-vertex found
  15649. failedCuts[ cutKey ] = true; // remember failure
  15650. }
  15651. if ( holeIndex >= 0 ) break; // hole-vertex found
  15652. }
  15653. }
  15654. return shape; /* shape with no holes */
  15655. }
  15656. var i, il, f, face,
  15657. key, index,
  15658. allPointsMap = {};
  15659. // To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
  15660. var allpoints = contour.concat();
  15661. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  15662. Array.prototype.push.apply( allpoints, holes[ h ] );
  15663. }
  15664. //console.log( "allpoints",allpoints, allpoints.length );
  15665. // prepare all points map
  15666. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  15667. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  15668. if ( allPointsMap[ key ] !== undefined ) {
  15669. console.warn( "THREE.ShapeUtils: Duplicate point", key, i );
  15670. }
  15671. allPointsMap[ key ] = i;
  15672. }
  15673. // remove holes by cutting paths to holes and adding them to the shape
  15674. var shapeWithoutHoles = removeHoles( contour, holes );
  15675. var triangles = ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  15676. //console.log( "triangles",triangles, triangles.length );
  15677. // check all face vertices against all points map
  15678. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  15679. face = triangles[ i ];
  15680. for ( f = 0; f < 3; f ++ ) {
  15681. key = face[ f ].x + ":" + face[ f ].y;
  15682. index = allPointsMap[ key ];
  15683. if ( index !== undefined ) {
  15684. face[ f ] = index;
  15685. }
  15686. }
  15687. }
  15688. return triangles.concat();
  15689. },
  15690. isClockWise: function ( pts ) {
  15691. return ShapeUtils.area( pts ) < 0;
  15692. }
  15693. };
  15694. /**
  15695. * @author zz85 / http://www.lab4games.net/zz85/blog
  15696. *
  15697. * Creates extruded geometry from a path shape.
  15698. *
  15699. * parameters = {
  15700. *
  15701. * curveSegments: <int>, // number of points on the curves
  15702. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  15703. * amount: <int>, // Depth to extrude the shape
  15704. *
  15705. * bevelEnabled: <bool>, // turn on bevel
  15706. * bevelThickness: <float>, // how deep into the original shape bevel goes
  15707. * bevelSize: <float>, // how far from shape outline is bevel
  15708. * bevelSegments: <int>, // number of bevel layers
  15709. *
  15710. * extrudePath: <THREE.Curve> // curve to extrude shape along
  15711. * frames: <Object> // containing arrays of tangents, normals, binormals
  15712. *
  15713. * UVGenerator: <Object> // object that provides UV generator functions
  15714. *
  15715. * }
  15716. */
  15717. // ExtrudeGeometry
  15718. function ExtrudeGeometry( shapes, options ) {
  15719. Geometry.call( this );
  15720. this.type = 'ExtrudeGeometry';
  15721. this.parameters = {
  15722. shapes: shapes,
  15723. options: options
  15724. };
  15725. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  15726. this.mergeVertices();
  15727. }
  15728. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  15729. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  15730. // ExtrudeBufferGeometry
  15731. function ExtrudeBufferGeometry( shapes, options ) {
  15732. if ( typeof ( shapes ) === "undefined" ) {
  15733. return;
  15734. }
  15735. BufferGeometry.call( this );
  15736. this.type = 'ExtrudeBufferGeometry';
  15737. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  15738. this.addShapeList( shapes, options );
  15739. this.computeVertexNormals();
  15740. // can't really use automatic vertex normals
  15741. // as then front and back sides get smoothed too
  15742. // should do separate smoothing just for sides
  15743. //this.computeVertexNormals();
  15744. //console.log( "took", ( Date.now() - startTime ) );
  15745. }
  15746. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15747. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  15748. ExtrudeBufferGeometry.prototype.getArrays = function () {
  15749. var positionAttribute = this.getAttribute( "position" );
  15750. var verticesArray = positionAttribute ? Array.prototype.slice.call( positionAttribute.array ) : [];
  15751. var uvAttribute = this.getAttribute( "uv" );
  15752. var uvArray = uvAttribute ? Array.prototype.slice.call( uvAttribute.array ) : [];
  15753. var IndexAttribute = this.index;
  15754. var indicesArray = IndexAttribute ? Array.prototype.slice.call( IndexAttribute.array ) : [];
  15755. return {
  15756. position: verticesArray,
  15757. uv: uvArray,
  15758. index: indicesArray
  15759. };
  15760. };
  15761. ExtrudeBufferGeometry.prototype.addShapeList = function ( shapes, options ) {
  15762. var sl = shapes.length;
  15763. options.arrays = this.getArrays();
  15764. for ( var s = 0; s < sl; s ++ ) {
  15765. var shape = shapes[ s ];
  15766. this.addShape( shape, options );
  15767. }
  15768. this.setIndex( options.arrays.index );
  15769. this.addAttribute( 'position', new Float32BufferAttribute( options.arrays.position, 3 ) );
  15770. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  15771. };
  15772. ExtrudeBufferGeometry.prototype.addShape = function ( shape, options ) {
  15773. var arrays = options.arrays ? options.arrays : this.getArrays();
  15774. var verticesArray = arrays.position;
  15775. var indicesArray = arrays.index;
  15776. var uvArray = arrays.uv;
  15777. var placeholder = [];
  15778. var amount = options.amount !== undefined ? options.amount : 100;
  15779. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  15780. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  15781. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  15782. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  15783. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  15784. var steps = options.steps !== undefined ? options.steps : 1;
  15785. var extrudePath = options.extrudePath;
  15786. var extrudePts, extrudeByPath = false;
  15787. // Use default WorldUVGenerator if no UV generators are specified.
  15788. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
  15789. var splineTube, binormal, normal, position2;
  15790. if ( extrudePath ) {
  15791. extrudePts = extrudePath.getSpacedPoints( steps );
  15792. extrudeByPath = true;
  15793. bevelEnabled = false; // bevels not supported for path extrusion
  15794. // SETUP TNB variables
  15795. // TODO1 - have a .isClosed in spline?
  15796. splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
  15797. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  15798. binormal = new Vector3();
  15799. normal = new Vector3();
  15800. position2 = new Vector3();
  15801. }
  15802. // Safeguards if bevels are not enabled
  15803. if ( ! bevelEnabled ) {
  15804. bevelSegments = 0;
  15805. bevelThickness = 0;
  15806. bevelSize = 0;
  15807. }
  15808. // Variables initialization
  15809. var ahole, h, hl; // looping of holes
  15810. var scope = this;
  15811. var shapePoints = shape.extractPoints( curveSegments );
  15812. var vertices = shapePoints.shape;
  15813. var holes = shapePoints.holes;
  15814. var reverse = ! ShapeUtils.isClockWise( vertices );
  15815. if ( reverse ) {
  15816. vertices = vertices.reverse();
  15817. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  15818. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15819. ahole = holes[ h ];
  15820. if ( ShapeUtils.isClockWise( ahole ) ) {
  15821. holes[ h ] = ahole.reverse();
  15822. }
  15823. }
  15824. }
  15825. var faces = ShapeUtils.triangulateShape( vertices, holes );
  15826. /* Vertices */
  15827. var contour = vertices; // vertices has all points but contour has only points of circumference
  15828. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15829. ahole = holes[ h ];
  15830. vertices = vertices.concat( ahole );
  15831. }
  15832. function scalePt2( pt, vec, size ) {
  15833. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  15834. return vec.clone().multiplyScalar( size ).add( pt );
  15835. }
  15836. var b, bs, t, z,
  15837. vert, vlen = vertices.length,
  15838. face, flen = faces.length;
  15839. // Find directions for point movement
  15840. function getBevelVec( inPt, inPrev, inNext ) {
  15841. // computes for inPt the corresponding point inPt' on a new contour
  15842. // shifted by 1 unit (length of normalized vector) to the left
  15843. // if we walk along contour clockwise, this new contour is outside the old one
  15844. //
  15845. // inPt' is the intersection of the two lines parallel to the two
  15846. // adjacent edges of inPt at a distance of 1 unit on the left side.
  15847. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  15848. // good reading for geometry algorithms (here: line-line intersection)
  15849. // http://geomalgorithms.com/a05-_intersect-1.html
  15850. var v_prev_x = inPt.x - inPrev.x,
  15851. v_prev_y = inPt.y - inPrev.y;
  15852. var v_next_x = inNext.x - inPt.x,
  15853. v_next_y = inNext.y - inPt.y;
  15854. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  15855. // check for collinear edges
  15856. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  15857. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  15858. // not collinear
  15859. // length of vectors for normalizing
  15860. var v_prev_len = Math.sqrt( v_prev_lensq );
  15861. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  15862. // shift adjacent points by unit vectors to the left
  15863. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  15864. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  15865. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  15866. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  15867. // scaling factor for v_prev to intersection point
  15868. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  15869. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  15870. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  15871. // vector from inPt to intersection point
  15872. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  15873. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  15874. // Don't normalize!, otherwise sharp corners become ugly
  15875. // but prevent crazy spikes
  15876. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  15877. if ( v_trans_lensq <= 2 ) {
  15878. return new Vector2( v_trans_x, v_trans_y );
  15879. } else {
  15880. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  15881. }
  15882. } else {
  15883. // handle special case of collinear edges
  15884. var direction_eq = false; // assumes: opposite
  15885. if ( v_prev_x > Number.EPSILON ) {
  15886. if ( v_next_x > Number.EPSILON ) {
  15887. direction_eq = true;
  15888. }
  15889. } else {
  15890. if ( v_prev_x < - Number.EPSILON ) {
  15891. if ( v_next_x < - Number.EPSILON ) {
  15892. direction_eq = true;
  15893. }
  15894. } else {
  15895. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  15896. direction_eq = true;
  15897. }
  15898. }
  15899. }
  15900. if ( direction_eq ) {
  15901. // console.log("Warning: lines are a straight sequence");
  15902. v_trans_x = - v_prev_y;
  15903. v_trans_y = v_prev_x;
  15904. shrink_by = Math.sqrt( v_prev_lensq );
  15905. } else {
  15906. // console.log("Warning: lines are a straight spike");
  15907. v_trans_x = v_prev_x;
  15908. v_trans_y = v_prev_y;
  15909. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  15910. }
  15911. }
  15912. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  15913. }
  15914. var contourMovements = [];
  15915. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  15916. if ( j === il ) j = 0;
  15917. if ( k === il ) k = 0;
  15918. // (j)---(i)---(k)
  15919. // console.log('i,j,k', i, j , k)
  15920. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  15921. }
  15922. var holesMovements = [],
  15923. oneHoleMovements, verticesMovements = contourMovements.concat();
  15924. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15925. ahole = holes[ h ];
  15926. oneHoleMovements = [];
  15927. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  15928. if ( j === il ) j = 0;
  15929. if ( k === il ) k = 0;
  15930. // (j)---(i)---(k)
  15931. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  15932. }
  15933. holesMovements.push( oneHoleMovements );
  15934. verticesMovements = verticesMovements.concat( oneHoleMovements );
  15935. }
  15936. // Loop bevelSegments, 1 for the front, 1 for the back
  15937. for ( b = 0; b < bevelSegments; b ++ ) {
  15938. //for ( b = bevelSegments; b > 0; b -- ) {
  15939. t = b / bevelSegments;
  15940. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  15941. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  15942. // contract shape
  15943. for ( i = 0, il = contour.length; i < il; i ++ ) {
  15944. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  15945. v( vert.x, vert.y, - z );
  15946. }
  15947. // expand holes
  15948. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15949. ahole = holes[ h ];
  15950. oneHoleMovements = holesMovements[ h ];
  15951. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  15952. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  15953. v( vert.x, vert.y, - z );
  15954. }
  15955. }
  15956. }
  15957. bs = bevelSize;
  15958. // Back facing vertices
  15959. for ( i = 0; i < vlen; i ++ ) {
  15960. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  15961. if ( ! extrudeByPath ) {
  15962. v( vert.x, vert.y, 0 );
  15963. } else {
  15964. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  15965. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  15966. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  15967. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  15968. v( position2.x, position2.y, position2.z );
  15969. }
  15970. }
  15971. // Add stepped vertices...
  15972. // Including front facing vertices
  15973. var s;
  15974. for ( s = 1; s <= steps; s ++ ) {
  15975. for ( i = 0; i < vlen; i ++ ) {
  15976. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  15977. if ( ! extrudeByPath ) {
  15978. v( vert.x, vert.y, amount / steps * s );
  15979. } else {
  15980. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  15981. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  15982. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  15983. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  15984. v( position2.x, position2.y, position2.z );
  15985. }
  15986. }
  15987. }
  15988. // Add bevel segments planes
  15989. //for ( b = 1; b <= bevelSegments; b ++ ) {
  15990. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  15991. t = b / bevelSegments;
  15992. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  15993. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  15994. // contract shape
  15995. for ( i = 0, il = contour.length; i < il; i ++ ) {
  15996. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  15997. v( vert.x, vert.y, amount + z );
  15998. }
  15999. // expand holes
  16000. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16001. ahole = holes[ h ];
  16002. oneHoleMovements = holesMovements[ h ];
  16003. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16004. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16005. if ( ! extrudeByPath ) {
  16006. v( vert.x, vert.y, amount + z );
  16007. } else {
  16008. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  16009. }
  16010. }
  16011. }
  16012. }
  16013. /* Faces */
  16014. // Top and bottom faces
  16015. buildLidFaces();
  16016. // Sides faces
  16017. buildSideFaces();
  16018. ///// Internal functions
  16019. function buildLidFaces() {
  16020. var start = verticesArray.length/3;
  16021. if ( bevelEnabled ) {
  16022. var layer = 0; // steps + 1
  16023. var offset = vlen * layer;
  16024. // Bottom faces
  16025. for ( i = 0; i < flen; i ++ ) {
  16026. face = faces[ i ];
  16027. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  16028. }
  16029. layer = steps + bevelSegments * 2;
  16030. offset = vlen * layer;
  16031. // Top faces
  16032. for ( i = 0; i < flen; i ++ ) {
  16033. face = faces[ i ];
  16034. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  16035. }
  16036. } else {
  16037. // Bottom faces
  16038. for ( i = 0; i < flen; i ++ ) {
  16039. face = faces[ i ];
  16040. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  16041. }
  16042. // Top faces
  16043. for ( i = 0; i < flen; i ++ ) {
  16044. face = faces[ i ];
  16045. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  16046. }
  16047. }
  16048. scope.addGroup( start, verticesArray.length/3 -start, options.material !== undefined ? options.material : 0);
  16049. }
  16050. // Create faces for the z-sides of the shape
  16051. function buildSideFaces() {
  16052. var start = verticesArray.length/3;
  16053. var layeroffset = 0;
  16054. sidewalls( contour, layeroffset );
  16055. layeroffset += contour.length;
  16056. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16057. ahole = holes[ h ];
  16058. sidewalls( ahole, layeroffset );
  16059. //, true
  16060. layeroffset += ahole.length;
  16061. }
  16062. scope.addGroup( start, verticesArray.length/3 -start, options.extrudeMaterial !== undefined ? options.extrudeMaterial : 1);
  16063. }
  16064. function sidewalls( contour, layeroffset ) {
  16065. var j, k;
  16066. i = contour.length;
  16067. while ( -- i >= 0 ) {
  16068. j = i;
  16069. k = i - 1;
  16070. if ( k < 0 ) k = contour.length - 1;
  16071. //console.log('b', i,j, i-1, k,vertices.length);
  16072. var s = 0,
  16073. sl = steps + bevelSegments * 2;
  16074. for ( s = 0; s < sl; s ++ ) {
  16075. var slen1 = vlen * s;
  16076. var slen2 = vlen * ( s + 1 );
  16077. var a = layeroffset + j + slen1,
  16078. b = layeroffset + k + slen1,
  16079. c = layeroffset + k + slen2,
  16080. d = layeroffset + j + slen2;
  16081. f4( a, b, c, d, contour, s, sl, j, k );
  16082. }
  16083. }
  16084. }
  16085. function v( x, y, z ) {
  16086. placeholder.push( x );
  16087. placeholder.push( y );
  16088. placeholder.push( z );
  16089. }
  16090. function f3( a, b, c ) {
  16091. addVertex( a );
  16092. addVertex( b );
  16093. addVertex( c );
  16094. var nextIndex = verticesArray.length / 3;
  16095. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16096. addUV( uvs[ 0 ] );
  16097. addUV( uvs[ 1 ] );
  16098. addUV( uvs[ 2 ] );
  16099. }
  16100. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  16101. addVertex( a );
  16102. addVertex( b );
  16103. addVertex( d );
  16104. addVertex( b );
  16105. addVertex( c );
  16106. addVertex( d );
  16107. var nextIndex = verticesArray.length / 3;
  16108. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16109. addUV( uvs[ 0 ] );
  16110. addUV( uvs[ 1 ] );
  16111. addUV( uvs[ 3 ] );
  16112. addUV( uvs[ 1 ] );
  16113. addUV( uvs[ 2 ] );
  16114. addUV( uvs[ 3 ] );
  16115. }
  16116. function addVertex( index ) {
  16117. indicesArray.push( verticesArray.length / 3 );
  16118. verticesArray.push( placeholder[ index * 3 + 0 ] );
  16119. verticesArray.push( placeholder[ index * 3 + 1 ] );
  16120. verticesArray.push( placeholder[ index * 3 + 2 ] );
  16121. }
  16122. function addUV( vector2 ) {
  16123. uvArray.push( vector2.x );
  16124. uvArray.push( vector2.y );
  16125. }
  16126. if ( ! options.arrays ) {
  16127. this.setIndex( indicesArray );
  16128. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  16129. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  16130. }
  16131. };
  16132. ExtrudeGeometry.WorldUVGenerator = {
  16133. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  16134. var a_x = vertices[ indexA * 3 ];
  16135. var a_y = vertices[ indexA * 3 + 1 ];
  16136. var b_x = vertices[ indexB * 3 ];
  16137. var b_y = vertices[ indexB * 3 + 1 ];
  16138. var c_x = vertices[ indexC * 3 ];
  16139. var c_y = vertices[ indexC * 3 + 1 ];
  16140. return [
  16141. new Vector2( a_x, a_y ),
  16142. new Vector2( b_x, b_y ),
  16143. new Vector2( c_x, c_y )
  16144. ];
  16145. },
  16146. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  16147. var a_x = vertices[ indexA * 3 ];
  16148. var a_y = vertices[ indexA * 3 + 1 ];
  16149. var a_z = vertices[ indexA * 3 + 2 ];
  16150. var b_x = vertices[ indexB * 3 ];
  16151. var b_y = vertices[ indexB * 3 + 1 ];
  16152. var b_z = vertices[ indexB * 3 + 2 ];
  16153. var c_x = vertices[ indexC * 3 ];
  16154. var c_y = vertices[ indexC * 3 + 1 ];
  16155. var c_z = vertices[ indexC * 3 + 2 ];
  16156. var d_x = vertices[ indexD * 3 ];
  16157. var d_y = vertices[ indexD * 3 + 1 ];
  16158. var d_z = vertices[ indexD * 3 + 2 ];
  16159. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  16160. return [
  16161. new Vector2( a_x, 1 - a_z ),
  16162. new Vector2( b_x, 1 - b_z ),
  16163. new Vector2( c_x, 1 - c_z ),
  16164. new Vector2( d_x, 1 - d_z )
  16165. ];
  16166. } else {
  16167. return [
  16168. new Vector2( a_y, 1 - a_z ),
  16169. new Vector2( b_y, 1 - b_z ),
  16170. new Vector2( c_y, 1 - c_z ),
  16171. new Vector2( d_y, 1 - d_z )
  16172. ];
  16173. }
  16174. }
  16175. };
  16176. /**
  16177. * @author zz85 / http://www.lab4games.net/zz85/blog
  16178. * @author alteredq / http://alteredqualia.com/
  16179. *
  16180. * Text = 3D Text
  16181. *
  16182. * parameters = {
  16183. * font: <THREE.Font>, // font
  16184. *
  16185. * size: <float>, // size of the text
  16186. * height: <float>, // thickness to extrude text
  16187. * curveSegments: <int>, // number of points on the curves
  16188. *
  16189. * bevelEnabled: <bool>, // turn on bevel
  16190. * bevelThickness: <float>, // how deep into text bevel goes
  16191. * bevelSize: <float> // how far from text outline is bevel
  16192. * }
  16193. */
  16194. // TextGeometry
  16195. function TextGeometry( text, parameters ) {
  16196. Geometry.call( this );
  16197. this.type = 'TextGeometry';
  16198. this.parameters = {
  16199. text: text,
  16200. parameters: parameters
  16201. };
  16202. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  16203. this.mergeVertices();
  16204. }
  16205. TextGeometry.prototype = Object.create( Geometry.prototype );
  16206. TextGeometry.prototype.constructor = TextGeometry;
  16207. // TextBufferGeometry
  16208. function TextBufferGeometry( text, parameters ) {
  16209. parameters = parameters || {};
  16210. var font = parameters.font;
  16211. if ( ! ( font && font.isFont ) ) {
  16212. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  16213. return new Geometry();
  16214. }
  16215. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  16216. // translate parameters to ExtrudeGeometry API
  16217. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  16218. // defaults
  16219. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  16220. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  16221. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  16222. ExtrudeBufferGeometry.call( this, shapes, parameters );
  16223. this.type = 'TextBufferGeometry';
  16224. }
  16225. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  16226. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  16227. /**
  16228. * @author mrdoob / http://mrdoob.com/
  16229. * @author benaadams / https://twitter.com/ben_a_adams
  16230. * @author Mugen87 / https://github.com/Mugen87
  16231. */
  16232. // SphereGeometry
  16233. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16234. Geometry.call( this );
  16235. this.type = 'SphereGeometry';
  16236. this.parameters = {
  16237. radius: radius,
  16238. widthSegments: widthSegments,
  16239. heightSegments: heightSegments,
  16240. phiStart: phiStart,
  16241. phiLength: phiLength,
  16242. thetaStart: thetaStart,
  16243. thetaLength: thetaLength
  16244. };
  16245. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  16246. this.mergeVertices();
  16247. }
  16248. SphereGeometry.prototype = Object.create( Geometry.prototype );
  16249. SphereGeometry.prototype.constructor = SphereGeometry;
  16250. // SphereBufferGeometry
  16251. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16252. BufferGeometry.call( this );
  16253. this.type = 'SphereBufferGeometry';
  16254. this.parameters = {
  16255. radius: radius,
  16256. widthSegments: widthSegments,
  16257. heightSegments: heightSegments,
  16258. phiStart: phiStart,
  16259. phiLength: phiLength,
  16260. thetaStart: thetaStart,
  16261. thetaLength: thetaLength
  16262. };
  16263. radius = radius || 50;
  16264. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  16265. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  16266. phiStart = phiStart !== undefined ? phiStart : 0;
  16267. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  16268. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16269. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  16270. var thetaEnd = thetaStart + thetaLength;
  16271. var ix, iy;
  16272. var index = 0;
  16273. var grid = [];
  16274. var vertex = new Vector3();
  16275. var normal = new Vector3();
  16276. // buffers
  16277. var indices = [];
  16278. var vertices = [];
  16279. var normals = [];
  16280. var uvs = [];
  16281. // generate vertices, normals and uvs
  16282. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  16283. var verticesRow = [];
  16284. var v = iy / heightSegments;
  16285. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  16286. var u = ix / widthSegments;
  16287. // vertex
  16288. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16289. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  16290. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16291. vertices.push( vertex.x, vertex.y, vertex.z );
  16292. // normal
  16293. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  16294. normals.push( normal.x, normal.y, normal.z );
  16295. // uv
  16296. uvs.push( u, 1 - v );
  16297. verticesRow.push( index ++ );
  16298. }
  16299. grid.push( verticesRow );
  16300. }
  16301. // indices
  16302. for ( iy = 0; iy < heightSegments; iy ++ ) {
  16303. for ( ix = 0; ix < widthSegments; ix ++ ) {
  16304. var a = grid[ iy ][ ix + 1 ];
  16305. var b = grid[ iy ][ ix ];
  16306. var c = grid[ iy + 1 ][ ix ];
  16307. var d = grid[ iy + 1 ][ ix + 1 ];
  16308. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  16309. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  16310. }
  16311. }
  16312. // build geometry
  16313. this.setIndex( indices );
  16314. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16315. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16316. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16317. }
  16318. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16319. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  16320. /**
  16321. * @author Kaleb Murphy
  16322. * @author Mugen87 / https://github.com/Mugen87
  16323. */
  16324. // RingGeometry
  16325. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16326. Geometry.call( this );
  16327. this.type = 'RingGeometry';
  16328. this.parameters = {
  16329. innerRadius: innerRadius,
  16330. outerRadius: outerRadius,
  16331. thetaSegments: thetaSegments,
  16332. phiSegments: phiSegments,
  16333. thetaStart: thetaStart,
  16334. thetaLength: thetaLength
  16335. };
  16336. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  16337. this.mergeVertices();
  16338. }
  16339. RingGeometry.prototype = Object.create( Geometry.prototype );
  16340. RingGeometry.prototype.constructor = RingGeometry;
  16341. // RingBufferGeometry
  16342. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16343. BufferGeometry.call( this );
  16344. this.type = 'RingBufferGeometry';
  16345. this.parameters = {
  16346. innerRadius: innerRadius,
  16347. outerRadius: outerRadius,
  16348. thetaSegments: thetaSegments,
  16349. phiSegments: phiSegments,
  16350. thetaStart: thetaStart,
  16351. thetaLength: thetaLength
  16352. };
  16353. innerRadius = innerRadius || 20;
  16354. outerRadius = outerRadius || 50;
  16355. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16356. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  16357. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  16358. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  16359. // buffers
  16360. var indices = [];
  16361. var vertices = [];
  16362. var normals = [];
  16363. var uvs = [];
  16364. // some helper variables
  16365. var segment;
  16366. var radius = innerRadius;
  16367. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  16368. var vertex = new Vector3();
  16369. var uv = new Vector2();
  16370. var j, i;
  16371. // generate vertices, normals and uvs
  16372. for ( j = 0; j <= phiSegments; j ++ ) {
  16373. for ( i = 0; i <= thetaSegments; i ++ ) {
  16374. // values are generate from the inside of the ring to the outside
  16375. segment = thetaStart + i / thetaSegments * thetaLength;
  16376. // vertex
  16377. vertex.x = radius * Math.cos( segment );
  16378. vertex.y = radius * Math.sin( segment );
  16379. vertices.push( vertex.x, vertex.y, vertex.z );
  16380. // normal
  16381. normals.push( 0, 0, 1 );
  16382. // uv
  16383. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  16384. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  16385. uvs.push( uv.x, uv.y );
  16386. }
  16387. // increase the radius for next row of vertices
  16388. radius += radiusStep;
  16389. }
  16390. // indices
  16391. for ( j = 0; j < phiSegments; j ++ ) {
  16392. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  16393. for ( i = 0; i < thetaSegments; i ++ ) {
  16394. segment = i + thetaSegmentLevel;
  16395. var a = segment;
  16396. var b = segment + thetaSegments + 1;
  16397. var c = segment + thetaSegments + 2;
  16398. var d = segment + 1;
  16399. // faces
  16400. indices.push( a, b, d );
  16401. indices.push( b, c, d );
  16402. }
  16403. }
  16404. // build geometry
  16405. this.setIndex( indices );
  16406. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16407. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16408. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16409. }
  16410. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16411. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  16412. /**
  16413. * @author astrodud / http://astrodud.isgreat.org/
  16414. * @author zz85 / https://github.com/zz85
  16415. * @author bhouston / http://clara.io
  16416. * @author Mugen87 / https://github.com/Mugen87
  16417. */
  16418. // LatheGeometry
  16419. function LatheGeometry( points, segments, phiStart, phiLength ) {
  16420. Geometry.call( this );
  16421. this.type = 'LatheGeometry';
  16422. this.parameters = {
  16423. points: points,
  16424. segments: segments,
  16425. phiStart: phiStart,
  16426. phiLength: phiLength
  16427. };
  16428. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  16429. this.mergeVertices();
  16430. }
  16431. LatheGeometry.prototype = Object.create( Geometry.prototype );
  16432. LatheGeometry.prototype.constructor = LatheGeometry;
  16433. // LatheBufferGeometry
  16434. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  16435. BufferGeometry.call( this );
  16436. this.type = 'LatheBufferGeometry';
  16437. this.parameters = {
  16438. points: points,
  16439. segments: segments,
  16440. phiStart: phiStart,
  16441. phiLength: phiLength
  16442. };
  16443. segments = Math.floor( segments ) || 12;
  16444. phiStart = phiStart || 0;
  16445. phiLength = phiLength || Math.PI * 2;
  16446. // clamp phiLength so it's in range of [ 0, 2PI ]
  16447. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  16448. // buffers
  16449. var indices = [];
  16450. var vertices = [];
  16451. var uvs = [];
  16452. // helper variables
  16453. var base;
  16454. var inverseSegments = 1.0 / segments;
  16455. var vertex = new Vector3();
  16456. var uv = new Vector2();
  16457. var i, j;
  16458. // generate vertices and uvs
  16459. for ( i = 0; i <= segments; i ++ ) {
  16460. var phi = phiStart + i * inverseSegments * phiLength;
  16461. var sin = Math.sin( phi );
  16462. var cos = Math.cos( phi );
  16463. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  16464. // vertex
  16465. vertex.x = points[ j ].x * sin;
  16466. vertex.y = points[ j ].y;
  16467. vertex.z = points[ j ].x * cos;
  16468. vertices.push( vertex.x, vertex.y, vertex.z );
  16469. // uv
  16470. uv.x = i / segments;
  16471. uv.y = j / ( points.length - 1 );
  16472. uvs.push( uv.x, uv.y );
  16473. }
  16474. }
  16475. // indices
  16476. for ( i = 0; i < segments; i ++ ) {
  16477. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  16478. base = j + i * points.length;
  16479. var a = base;
  16480. var b = base + points.length;
  16481. var c = base + points.length + 1;
  16482. var d = base + 1;
  16483. // faces
  16484. indices.push( a, b, d );
  16485. indices.push( b, c, d );
  16486. }
  16487. }
  16488. // build geometry
  16489. this.setIndex( indices );
  16490. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16491. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16492. // generate normals
  16493. this.computeVertexNormals();
  16494. // if the geometry is closed, we need to average the normals along the seam.
  16495. // because the corresponding vertices are identical (but still have different UVs).
  16496. if ( phiLength === Math.PI * 2 ) {
  16497. var normals = this.attributes.normal.array;
  16498. var n1 = new Vector3();
  16499. var n2 = new Vector3();
  16500. var n = new Vector3();
  16501. // this is the buffer offset for the last line of vertices
  16502. base = segments * points.length * 3;
  16503. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  16504. // select the normal of the vertex in the first line
  16505. n1.x = normals[ j + 0 ];
  16506. n1.y = normals[ j + 1 ];
  16507. n1.z = normals[ j + 2 ];
  16508. // select the normal of the vertex in the last line
  16509. n2.x = normals[ base + j + 0 ];
  16510. n2.y = normals[ base + j + 1 ];
  16511. n2.z = normals[ base + j + 2 ];
  16512. // average normals
  16513. n.addVectors( n1, n2 ).normalize();
  16514. // assign the new values to both normals
  16515. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  16516. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  16517. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  16518. }
  16519. }
  16520. }
  16521. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16522. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  16523. /**
  16524. * @author jonobr1 / http://jonobr1.com
  16525. * @author Mugen87 / https://github.com/Mugen87
  16526. */
  16527. // ShapeGeometry
  16528. function ShapeGeometry( shapes, curveSegments ) {
  16529. Geometry.call( this );
  16530. this.type = 'ShapeGeometry';
  16531. if ( typeof curveSegments === 'object' ) {
  16532. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  16533. curveSegments = curveSegments.curveSegments;
  16534. }
  16535. this.parameters = {
  16536. shapes: shapes,
  16537. curveSegments: curveSegments
  16538. };
  16539. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  16540. this.mergeVertices();
  16541. }
  16542. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  16543. ShapeGeometry.prototype.constructor = ShapeGeometry;
  16544. // ShapeBufferGeometry
  16545. function ShapeBufferGeometry( shapes, curveSegments ) {
  16546. BufferGeometry.call( this );
  16547. this.type = 'ShapeBufferGeometry';
  16548. this.parameters = {
  16549. shapes: shapes,
  16550. curveSegments: curveSegments
  16551. };
  16552. curveSegments = curveSegments || 12;
  16553. // buffers
  16554. var indices = [];
  16555. var vertices = [];
  16556. var normals = [];
  16557. var uvs = [];
  16558. // helper variables
  16559. var groupStart = 0;
  16560. var groupCount = 0;
  16561. // allow single and array values for "shapes" parameter
  16562. if ( Array.isArray( shapes ) === false ) {
  16563. addShape( shapes );
  16564. } else {
  16565. for ( var i = 0; i < shapes.length; i ++ ) {
  16566. addShape( shapes[ i ] );
  16567. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  16568. groupStart += groupCount;
  16569. groupCount = 0;
  16570. }
  16571. }
  16572. // build geometry
  16573. this.setIndex( indices );
  16574. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16575. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16576. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16577. // helper functions
  16578. function addShape( shape ) {
  16579. var i, l, shapeHole;
  16580. var indexOffset = vertices.length / 3;
  16581. var points = shape.extractPoints( curveSegments );
  16582. var shapeVertices = points.shape;
  16583. var shapeHoles = points.holes;
  16584. // check direction of vertices
  16585. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  16586. shapeVertices = shapeVertices.reverse();
  16587. // also check if holes are in the opposite direction
  16588. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  16589. shapeHole = shapeHoles[ i ];
  16590. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  16591. shapeHoles[ i ] = shapeHole.reverse();
  16592. }
  16593. }
  16594. }
  16595. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  16596. // join vertices of inner and outer paths to a single array
  16597. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  16598. shapeHole = shapeHoles[ i ];
  16599. shapeVertices = shapeVertices.concat( shapeHole );
  16600. }
  16601. // vertices, normals, uvs
  16602. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  16603. var vertex = shapeVertices[ i ];
  16604. vertices.push( vertex.x, vertex.y, 0 );
  16605. normals.push( 0, 0, 1 );
  16606. uvs.push( vertex.x, vertex.y ); // world uvs
  16607. }
  16608. // incides
  16609. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16610. var face = faces[ i ];
  16611. var a = face[ 0 ] + indexOffset;
  16612. var b = face[ 1 ] + indexOffset;
  16613. var c = face[ 2 ] + indexOffset;
  16614. indices.push( a, b, c );
  16615. groupCount += 3;
  16616. }
  16617. }
  16618. }
  16619. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16620. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  16621. /**
  16622. * @author WestLangley / http://github.com/WestLangley
  16623. * @author Mugen87 / https://github.com/Mugen87
  16624. */
  16625. function EdgesGeometry( geometry, thresholdAngle ) {
  16626. BufferGeometry.call( this );
  16627. this.type = 'EdgesGeometry';
  16628. this.parameters = {
  16629. thresholdAngle: thresholdAngle
  16630. };
  16631. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  16632. // buffer
  16633. var vertices = [];
  16634. // helper variables
  16635. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  16636. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  16637. var key, keys = [ 'a', 'b', 'c' ];
  16638. // prepare source geometry
  16639. var geometry2;
  16640. if ( geometry.isBufferGeometry ) {
  16641. geometry2 = new Geometry();
  16642. geometry2.fromBufferGeometry( geometry );
  16643. } else {
  16644. geometry2 = geometry.clone();
  16645. }
  16646. geometry2.mergeVertices();
  16647. geometry2.computeFaceNormals();
  16648. var sourceVertices = geometry2.vertices;
  16649. var faces = geometry2.faces;
  16650. // now create a data structure where each entry represents an edge with its adjoining faces
  16651. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  16652. var face = faces[ i ];
  16653. for ( var j = 0; j < 3; j ++ ) {
  16654. edge1 = face[ keys[ j ] ];
  16655. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16656. edge[ 0 ] = Math.min( edge1, edge2 );
  16657. edge[ 1 ] = Math.max( edge1, edge2 );
  16658. key = edge[ 0 ] + ',' + edge[ 1 ];
  16659. if ( edges[ key ] === undefined ) {
  16660. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  16661. } else {
  16662. edges[ key ].face2 = i;
  16663. }
  16664. }
  16665. }
  16666. // generate vertices
  16667. for ( key in edges ) {
  16668. var e = edges[ key ];
  16669. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  16670. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  16671. var vertex = sourceVertices[ e.index1 ];
  16672. vertices.push( vertex.x, vertex.y, vertex.z );
  16673. vertex = sourceVertices[ e.index2 ];
  16674. vertices.push( vertex.x, vertex.y, vertex.z );
  16675. }
  16676. }
  16677. // build geometry
  16678. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16679. }
  16680. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  16681. EdgesGeometry.prototype.constructor = EdgesGeometry;
  16682. /**
  16683. * @author mrdoob / http://mrdoob.com/
  16684. * @author Mugen87 / https://github.com/Mugen87
  16685. */
  16686. // CylinderGeometry
  16687. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16688. Geometry.call( this );
  16689. this.type = 'CylinderGeometry';
  16690. this.parameters = {
  16691. radiusTop: radiusTop,
  16692. radiusBottom: radiusBottom,
  16693. height: height,
  16694. radialSegments: radialSegments,
  16695. heightSegments: heightSegments,
  16696. openEnded: openEnded,
  16697. thetaStart: thetaStart,
  16698. thetaLength: thetaLength
  16699. };
  16700. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  16701. this.mergeVertices();
  16702. }
  16703. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  16704. CylinderGeometry.prototype.constructor = CylinderGeometry;
  16705. // CylinderBufferGeometry
  16706. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16707. BufferGeometry.call( this );
  16708. this.type = 'CylinderBufferGeometry';
  16709. this.parameters = {
  16710. radiusTop: radiusTop,
  16711. radiusBottom: radiusBottom,
  16712. height: height,
  16713. radialSegments: radialSegments,
  16714. heightSegments: heightSegments,
  16715. openEnded: openEnded,
  16716. thetaStart: thetaStart,
  16717. thetaLength: thetaLength
  16718. };
  16719. var scope = this;
  16720. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  16721. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  16722. height = height !== undefined ? height : 100;
  16723. radialSegments = Math.floor( radialSegments ) || 8;
  16724. heightSegments = Math.floor( heightSegments ) || 1;
  16725. openEnded = openEnded !== undefined ? openEnded : false;
  16726. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  16727. thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
  16728. // buffers
  16729. var indices = [];
  16730. var vertices = [];
  16731. var normals = [];
  16732. var uvs = [];
  16733. // helper variables
  16734. var index = 0;
  16735. var indexArray = [];
  16736. var halfHeight = height / 2;
  16737. var groupStart = 0;
  16738. // generate geometry
  16739. generateTorso();
  16740. if ( openEnded === false ) {
  16741. if ( radiusTop > 0 ) generateCap( true );
  16742. if ( radiusBottom > 0 ) generateCap( false );
  16743. }
  16744. // build geometry
  16745. this.setIndex( indices );
  16746. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16747. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16748. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16749. function generateTorso() {
  16750. var x, y;
  16751. var normal = new Vector3();
  16752. var vertex = new Vector3();
  16753. var groupCount = 0;
  16754. // this will be used to calculate the normal
  16755. var slope = ( radiusBottom - radiusTop ) / height;
  16756. // generate vertices, normals and uvs
  16757. for ( y = 0; y <= heightSegments; y ++ ) {
  16758. var indexRow = [];
  16759. var v = y / heightSegments;
  16760. // calculate the radius of the current row
  16761. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  16762. for ( x = 0; x <= radialSegments; x ++ ) {
  16763. var u = x / radialSegments;
  16764. var theta = u * thetaLength + thetaStart;
  16765. var sinTheta = Math.sin( theta );
  16766. var cosTheta = Math.cos( theta );
  16767. // vertex
  16768. vertex.x = radius * sinTheta;
  16769. vertex.y = - v * height + halfHeight;
  16770. vertex.z = radius * cosTheta;
  16771. vertices.push( vertex.x, vertex.y, vertex.z );
  16772. // normal
  16773. normal.set( sinTheta, slope, cosTheta ).normalize();
  16774. normals.push( normal.x, normal.y, normal.z );
  16775. // uv
  16776. uvs.push( u, 1 - v );
  16777. // save index of vertex in respective row
  16778. indexRow.push( index ++ );
  16779. }
  16780. // now save vertices of the row in our index array
  16781. indexArray.push( indexRow );
  16782. }
  16783. // generate indices
  16784. for ( x = 0; x < radialSegments; x ++ ) {
  16785. for ( y = 0; y < heightSegments; y ++ ) {
  16786. // we use the index array to access the correct indices
  16787. var a = indexArray[ y ][ x ];
  16788. var b = indexArray[ y + 1 ][ x ];
  16789. var c = indexArray[ y + 1 ][ x + 1 ];
  16790. var d = indexArray[ y ][ x + 1 ];
  16791. // faces
  16792. indices.push( a, b, d );
  16793. indices.push( b, c, d );
  16794. // update group counter
  16795. groupCount += 6;
  16796. }
  16797. }
  16798. // add a group to the geometry. this will ensure multi material support
  16799. scope.addGroup( groupStart, groupCount, 0 );
  16800. // calculate new start value for groups
  16801. groupStart += groupCount;
  16802. }
  16803. function generateCap( top ) {
  16804. var x, centerIndexStart, centerIndexEnd;
  16805. var uv = new Vector2();
  16806. var vertex = new Vector3();
  16807. var groupCount = 0;
  16808. var radius = ( top === true ) ? radiusTop : radiusBottom;
  16809. var sign = ( top === true ) ? 1 : - 1;
  16810. // save the index of the first center vertex
  16811. centerIndexStart = index;
  16812. // first we generate the center vertex data of the cap.
  16813. // because the geometry needs one set of uvs per face,
  16814. // we must generate a center vertex per face/segment
  16815. for ( x = 1; x <= radialSegments; x ++ ) {
  16816. // vertex
  16817. vertices.push( 0, halfHeight * sign, 0 );
  16818. // normal
  16819. normals.push( 0, sign, 0 );
  16820. // uv
  16821. uvs.push( 0.5, 0.5 );
  16822. // increase index
  16823. index ++;
  16824. }
  16825. // save the index of the last center vertex
  16826. centerIndexEnd = index;
  16827. // now we generate the surrounding vertices, normals and uvs
  16828. for ( x = 0; x <= radialSegments; x ++ ) {
  16829. var u = x / radialSegments;
  16830. var theta = u * thetaLength + thetaStart;
  16831. var cosTheta = Math.cos( theta );
  16832. var sinTheta = Math.sin( theta );
  16833. // vertex
  16834. vertex.x = radius * sinTheta;
  16835. vertex.y = halfHeight * sign;
  16836. vertex.z = radius * cosTheta;
  16837. vertices.push( vertex.x, vertex.y, vertex.z );
  16838. // normal
  16839. normals.push( 0, sign, 0 );
  16840. // uv
  16841. uv.x = ( cosTheta * 0.5 ) + 0.5;
  16842. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  16843. uvs.push( uv.x, uv.y );
  16844. // increase index
  16845. index ++;
  16846. }
  16847. // generate indices
  16848. for ( x = 0; x < radialSegments; x ++ ) {
  16849. var c = centerIndexStart + x;
  16850. var i = centerIndexEnd + x;
  16851. if ( top === true ) {
  16852. // face top
  16853. indices.push( i, i + 1, c );
  16854. } else {
  16855. // face bottom
  16856. indices.push( i + 1, i, c );
  16857. }
  16858. groupCount += 3;
  16859. }
  16860. // add a group to the geometry. this will ensure multi material support
  16861. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  16862. // calculate new start value for groups
  16863. groupStart += groupCount;
  16864. }
  16865. }
  16866. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16867. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  16868. /**
  16869. * @author abelnation / http://github.com/abelnation
  16870. */
  16871. // ConeGeometry
  16872. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16873. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  16874. this.type = 'ConeGeometry';
  16875. this.parameters = {
  16876. radius: radius,
  16877. height: height,
  16878. radialSegments: radialSegments,
  16879. heightSegments: heightSegments,
  16880. openEnded: openEnded,
  16881. thetaStart: thetaStart,
  16882. thetaLength: thetaLength
  16883. };
  16884. }
  16885. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  16886. ConeGeometry.prototype.constructor = ConeGeometry;
  16887. // ConeBufferGeometry
  16888. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16889. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  16890. this.type = 'ConeBufferGeometry';
  16891. this.parameters = {
  16892. radius: radius,
  16893. height: height,
  16894. radialSegments: radialSegments,
  16895. heightSegments: heightSegments,
  16896. openEnded: openEnded,
  16897. thetaStart: thetaStart,
  16898. thetaLength: thetaLength
  16899. };
  16900. }
  16901. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  16902. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  16903. /**
  16904. * @author benaadams / https://twitter.com/ben_a_adams
  16905. * @author Mugen87 / https://github.com/Mugen87
  16906. * @author hughes
  16907. */
  16908. // CircleGeometry
  16909. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  16910. Geometry.call( this );
  16911. this.type = 'CircleGeometry';
  16912. this.parameters = {
  16913. radius: radius,
  16914. segments: segments,
  16915. thetaStart: thetaStart,
  16916. thetaLength: thetaLength
  16917. };
  16918. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  16919. this.mergeVertices();
  16920. }
  16921. CircleGeometry.prototype = Object.create( Geometry.prototype );
  16922. CircleGeometry.prototype.constructor = CircleGeometry;
  16923. // CircleBufferGeometry
  16924. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  16925. BufferGeometry.call( this );
  16926. this.type = 'CircleBufferGeometry';
  16927. this.parameters = {
  16928. radius: radius,
  16929. segments: segments,
  16930. thetaStart: thetaStart,
  16931. thetaLength: thetaLength
  16932. };
  16933. radius = radius || 50;
  16934. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  16935. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16936. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  16937. // buffers
  16938. var indices = [];
  16939. var vertices = [];
  16940. var normals = [];
  16941. var uvs = [];
  16942. // helper variables
  16943. var i, s;
  16944. var vertex = new Vector3();
  16945. var uv = new Vector2();
  16946. // center point
  16947. vertices.push( 0, 0, 0 );
  16948. normals.push( 0, 0, 1 );
  16949. uvs.push( 0.5, 0.5 );
  16950. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  16951. var segment = thetaStart + s / segments * thetaLength;
  16952. // vertex
  16953. vertex.x = radius * Math.cos( segment );
  16954. vertex.y = radius * Math.sin( segment );
  16955. vertices.push( vertex.x, vertex.y, vertex.z );
  16956. // normal
  16957. normals.push( 0, 0, 1 );
  16958. // uvs
  16959. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  16960. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  16961. uvs.push( uv.x, uv.y );
  16962. }
  16963. // indices
  16964. for ( i = 1; i <= segments; i ++ ) {
  16965. indices.push( i, i + 1, 0 );
  16966. }
  16967. // build geometry
  16968. this.setIndex( indices );
  16969. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16970. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16971. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16972. }
  16973. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16974. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  16975. var Geometries = Object.freeze({
  16976. WireframeGeometry: WireframeGeometry,
  16977. ParametricGeometry: ParametricGeometry,
  16978. ParametricBufferGeometry: ParametricBufferGeometry,
  16979. TetrahedronGeometry: TetrahedronGeometry,
  16980. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  16981. OctahedronGeometry: OctahedronGeometry,
  16982. OctahedronBufferGeometry: OctahedronBufferGeometry,
  16983. IcosahedronGeometry: IcosahedronGeometry,
  16984. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  16985. DodecahedronGeometry: DodecahedronGeometry,
  16986. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  16987. PolyhedronGeometry: PolyhedronGeometry,
  16988. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  16989. TubeGeometry: TubeGeometry,
  16990. TubeBufferGeometry: TubeBufferGeometry,
  16991. TorusKnotGeometry: TorusKnotGeometry,
  16992. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  16993. TorusGeometry: TorusGeometry,
  16994. TorusBufferGeometry: TorusBufferGeometry,
  16995. TextGeometry: TextGeometry,
  16996. TextBufferGeometry: TextBufferGeometry,
  16997. SphereGeometry: SphereGeometry,
  16998. SphereBufferGeometry: SphereBufferGeometry,
  16999. RingGeometry: RingGeometry,
  17000. RingBufferGeometry: RingBufferGeometry,
  17001. PlaneGeometry: PlaneGeometry,
  17002. PlaneBufferGeometry: PlaneBufferGeometry,
  17003. LatheGeometry: LatheGeometry,
  17004. LatheBufferGeometry: LatheBufferGeometry,
  17005. ShapeGeometry: ShapeGeometry,
  17006. ShapeBufferGeometry: ShapeBufferGeometry,
  17007. ExtrudeGeometry: ExtrudeGeometry,
  17008. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  17009. EdgesGeometry: EdgesGeometry,
  17010. ConeGeometry: ConeGeometry,
  17011. ConeBufferGeometry: ConeBufferGeometry,
  17012. CylinderGeometry: CylinderGeometry,
  17013. CylinderBufferGeometry: CylinderBufferGeometry,
  17014. CircleGeometry: CircleGeometry,
  17015. CircleBufferGeometry: CircleBufferGeometry,
  17016. BoxGeometry: BoxGeometry,
  17017. BoxBufferGeometry: BoxBufferGeometry
  17018. });
  17019. /**
  17020. * @author mrdoob / http://mrdoob.com/
  17021. *
  17022. * parameters = {
  17023. * opacity: <float>
  17024. * }
  17025. */
  17026. function ShadowMaterial( parameters ) {
  17027. ShaderMaterial.call( this, {
  17028. uniforms: UniformsUtils.merge( [
  17029. UniformsLib.lights,
  17030. {
  17031. opacity: { value: 1.0 }
  17032. }
  17033. ] ),
  17034. vertexShader: ShaderChunk[ 'shadow_vert' ],
  17035. fragmentShader: ShaderChunk[ 'shadow_frag' ]
  17036. } );
  17037. this.lights = true;
  17038. this.transparent = true;
  17039. Object.defineProperties( this, {
  17040. opacity: {
  17041. enumerable: true,
  17042. get: function () {
  17043. return this.uniforms.opacity.value;
  17044. },
  17045. set: function ( value ) {
  17046. this.uniforms.opacity.value = value;
  17047. }
  17048. }
  17049. } );
  17050. this.setValues( parameters );
  17051. }
  17052. ShadowMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17053. ShadowMaterial.prototype.constructor = ShadowMaterial;
  17054. ShadowMaterial.prototype.isShadowMaterial = true;
  17055. /**
  17056. * @author mrdoob / http://mrdoob.com/
  17057. */
  17058. function RawShaderMaterial( parameters ) {
  17059. ShaderMaterial.call( this, parameters );
  17060. this.type = 'RawShaderMaterial';
  17061. }
  17062. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17063. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  17064. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  17065. /**
  17066. * @author WestLangley / http://github.com/WestLangley
  17067. *
  17068. * parameters = {
  17069. * color: <hex>,
  17070. * roughness: <float>,
  17071. * metalness: <float>,
  17072. * opacity: <float>,
  17073. *
  17074. * map: new THREE.Texture( <Image> ),
  17075. *
  17076. * lightMap: new THREE.Texture( <Image> ),
  17077. * lightMapIntensity: <float>
  17078. *
  17079. * aoMap: new THREE.Texture( <Image> ),
  17080. * aoMapIntensity: <float>
  17081. *
  17082. * emissive: <hex>,
  17083. * emissiveIntensity: <float>
  17084. * emissiveMap: new THREE.Texture( <Image> ),
  17085. *
  17086. * bumpMap: new THREE.Texture( <Image> ),
  17087. * bumpScale: <float>,
  17088. *
  17089. * normalMap: new THREE.Texture( <Image> ),
  17090. * normalScale: <Vector2>,
  17091. *
  17092. * displacementMap: new THREE.Texture( <Image> ),
  17093. * displacementScale: <float>,
  17094. * displacementBias: <float>,
  17095. *
  17096. * roughnessMap: new THREE.Texture( <Image> ),
  17097. *
  17098. * metalnessMap: new THREE.Texture( <Image> ),
  17099. *
  17100. * alphaMap: new THREE.Texture( <Image> ),
  17101. *
  17102. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  17103. * envMapIntensity: <float>
  17104. *
  17105. * refractionRatio: <float>,
  17106. *
  17107. * wireframe: <boolean>,
  17108. * wireframeLinewidth: <float>,
  17109. *
  17110. * skinning: <bool>,
  17111. * morphTargets: <bool>,
  17112. * morphNormals: <bool>
  17113. * }
  17114. */
  17115. function MeshStandardMaterial( parameters ) {
  17116. Material.call( this );
  17117. this.defines = { 'STANDARD': '' };
  17118. this.type = 'MeshStandardMaterial';
  17119. this.color = new Color( 0xffffff ); // diffuse
  17120. this.roughness = 0.5;
  17121. this.metalness = 0.5;
  17122. this.map = null;
  17123. this.lightMap = null;
  17124. this.lightMapIntensity = 1.0;
  17125. this.aoMap = null;
  17126. this.aoMapIntensity = 1.0;
  17127. this.emissive = new Color( 0x000000 );
  17128. this.emissiveIntensity = 1.0;
  17129. this.emissiveMap = null;
  17130. this.bumpMap = null;
  17131. this.bumpScale = 1;
  17132. this.normalMap = null;
  17133. this.normalScale = new Vector2( 1, 1 );
  17134. this.displacementMap = null;
  17135. this.displacementScale = 1;
  17136. this.displacementBias = 0;
  17137. this.roughnessMap = null;
  17138. this.metalnessMap = null;
  17139. this.alphaMap = null;
  17140. this.envMap = null;
  17141. this.envMapIntensity = 1.0;
  17142. this.refractionRatio = 0.98;
  17143. this.wireframe = false;
  17144. this.wireframeLinewidth = 1;
  17145. this.wireframeLinecap = 'round';
  17146. this.wireframeLinejoin = 'round';
  17147. this.skinning = false;
  17148. this.morphTargets = false;
  17149. this.morphNormals = false;
  17150. this.setValues( parameters );
  17151. }
  17152. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  17153. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  17154. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  17155. MeshStandardMaterial.prototype.copy = function ( source ) {
  17156. Material.prototype.copy.call( this, source );
  17157. this.defines = { 'STANDARD': '' };
  17158. this.color.copy( source.color );
  17159. this.roughness = source.roughness;
  17160. this.metalness = source.metalness;
  17161. this.map = source.map;
  17162. this.lightMap = source.lightMap;
  17163. this.lightMapIntensity = source.lightMapIntensity;
  17164. this.aoMap = source.aoMap;
  17165. this.aoMapIntensity = source.aoMapIntensity;
  17166. this.emissive.copy( source.emissive );
  17167. this.emissiveMap = source.emissiveMap;
  17168. this.emissiveIntensity = source.emissiveIntensity;
  17169. this.bumpMap = source.bumpMap;
  17170. this.bumpScale = source.bumpScale;
  17171. this.normalMap = source.normalMap;
  17172. this.normalScale.copy( source.normalScale );
  17173. this.displacementMap = source.displacementMap;
  17174. this.displacementScale = source.displacementScale;
  17175. this.displacementBias = source.displacementBias;
  17176. this.roughnessMap = source.roughnessMap;
  17177. this.metalnessMap = source.metalnessMap;
  17178. this.alphaMap = source.alphaMap;
  17179. this.envMap = source.envMap;
  17180. this.envMapIntensity = source.envMapIntensity;
  17181. this.refractionRatio = source.refractionRatio;
  17182. this.wireframe = source.wireframe;
  17183. this.wireframeLinewidth = source.wireframeLinewidth;
  17184. this.wireframeLinecap = source.wireframeLinecap;
  17185. this.wireframeLinejoin = source.wireframeLinejoin;
  17186. this.skinning = source.skinning;
  17187. this.morphTargets = source.morphTargets;
  17188. this.morphNormals = source.morphNormals;
  17189. return this;
  17190. };
  17191. /**
  17192. * @author WestLangley / http://github.com/WestLangley
  17193. *
  17194. * parameters = {
  17195. * reflectivity: <float>
  17196. * }
  17197. */
  17198. function MeshPhysicalMaterial( parameters ) {
  17199. MeshStandardMaterial.call( this );
  17200. this.defines = { 'PHYSICAL': '' };
  17201. this.type = 'MeshPhysicalMaterial';
  17202. this.reflectivity = 0.5; // maps to F0 = 0.04
  17203. this.clearCoat = 0.0;
  17204. this.clearCoatRoughness = 0.0;
  17205. this.setValues( parameters );
  17206. }
  17207. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  17208. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  17209. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  17210. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  17211. MeshStandardMaterial.prototype.copy.call( this, source );
  17212. this.defines = { 'PHYSICAL': '' };
  17213. this.reflectivity = source.reflectivity;
  17214. this.clearCoat = source.clearCoat;
  17215. this.clearCoatRoughness = source.clearCoatRoughness;
  17216. return this;
  17217. };
  17218. /**
  17219. * @author mrdoob / http://mrdoob.com/
  17220. * @author alteredq / http://alteredqualia.com/
  17221. *
  17222. * parameters = {
  17223. * color: <hex>,
  17224. * specular: <hex>,
  17225. * shininess: <float>,
  17226. * opacity: <float>,
  17227. *
  17228. * map: new THREE.Texture( <Image> ),
  17229. *
  17230. * lightMap: new THREE.Texture( <Image> ),
  17231. * lightMapIntensity: <float>
  17232. *
  17233. * aoMap: new THREE.Texture( <Image> ),
  17234. * aoMapIntensity: <float>
  17235. *
  17236. * emissive: <hex>,
  17237. * emissiveIntensity: <float>
  17238. * emissiveMap: new THREE.Texture( <Image> ),
  17239. *
  17240. * bumpMap: new THREE.Texture( <Image> ),
  17241. * bumpScale: <float>,
  17242. *
  17243. * normalMap: new THREE.Texture( <Image> ),
  17244. * normalScale: <Vector2>,
  17245. *
  17246. * displacementMap: new THREE.Texture( <Image> ),
  17247. * displacementScale: <float>,
  17248. * displacementBias: <float>,
  17249. *
  17250. * specularMap: new THREE.Texture( <Image> ),
  17251. *
  17252. * alphaMap: new THREE.Texture( <Image> ),
  17253. *
  17254. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  17255. * combine: THREE.Multiply,
  17256. * reflectivity: <float>,
  17257. * refractionRatio: <float>,
  17258. *
  17259. * wireframe: <boolean>,
  17260. * wireframeLinewidth: <float>,
  17261. *
  17262. * skinning: <bool>,
  17263. * morphTargets: <bool>,
  17264. * morphNormals: <bool>
  17265. * }
  17266. */
  17267. function MeshPhongMaterial( parameters ) {
  17268. Material.call( this );
  17269. this.type = 'MeshPhongMaterial';
  17270. this.color = new Color( 0xffffff ); // diffuse
  17271. this.specular = new Color( 0x111111 );
  17272. this.shininess = 30;
  17273. this.map = null;
  17274. this.lightMap = null;
  17275. this.lightMapIntensity = 1.0;
  17276. this.aoMap = null;
  17277. this.aoMapIntensity = 1.0;
  17278. this.emissive = new Color( 0x000000 );
  17279. this.emissiveIntensity = 1.0;
  17280. this.emissiveMap = null;
  17281. this.bumpMap = null;
  17282. this.bumpScale = 1;
  17283. this.normalMap = null;
  17284. this.normalScale = new Vector2( 1, 1 );
  17285. this.displacementMap = null;
  17286. this.displacementScale = 1;
  17287. this.displacementBias = 0;
  17288. this.specularMap = null;
  17289. this.alphaMap = null;
  17290. this.envMap = null;
  17291. this.combine = MultiplyOperation;
  17292. this.reflectivity = 1;
  17293. this.refractionRatio = 0.98;
  17294. this.wireframe = false;
  17295. this.wireframeLinewidth = 1;
  17296. this.wireframeLinecap = 'round';
  17297. this.wireframeLinejoin = 'round';
  17298. this.skinning = false;
  17299. this.morphTargets = false;
  17300. this.morphNormals = false;
  17301. this.setValues( parameters );
  17302. }
  17303. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  17304. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  17305. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  17306. MeshPhongMaterial.prototype.copy = function ( source ) {
  17307. Material.prototype.copy.call( this, source );
  17308. this.color.copy( source.color );
  17309. this.specular.copy( source.specular );
  17310. this.shininess = source.shininess;
  17311. this.map = source.map;
  17312. this.lightMap = source.lightMap;
  17313. this.lightMapIntensity = source.lightMapIntensity;
  17314. this.aoMap = source.aoMap;
  17315. this.aoMapIntensity = source.aoMapIntensity;
  17316. this.emissive.copy( source.emissive );
  17317. this.emissiveMap = source.emissiveMap;
  17318. this.emissiveIntensity = source.emissiveIntensity;
  17319. this.bumpMap = source.bumpMap;
  17320. this.bumpScale = source.bumpScale;
  17321. this.normalMap = source.normalMap;
  17322. this.normalScale.copy( source.normalScale );
  17323. this.displacementMap = source.displacementMap;
  17324. this.displacementScale = source.displacementScale;
  17325. this.displacementBias = source.displacementBias;
  17326. this.specularMap = source.specularMap;
  17327. this.alphaMap = source.alphaMap;
  17328. this.envMap = source.envMap;
  17329. this.combine = source.combine;
  17330. this.reflectivity = source.reflectivity;
  17331. this.refractionRatio = source.refractionRatio;
  17332. this.wireframe = source.wireframe;
  17333. this.wireframeLinewidth = source.wireframeLinewidth;
  17334. this.wireframeLinecap = source.wireframeLinecap;
  17335. this.wireframeLinejoin = source.wireframeLinejoin;
  17336. this.skinning = source.skinning;
  17337. this.morphTargets = source.morphTargets;
  17338. this.morphNormals = source.morphNormals;
  17339. return this;
  17340. };
  17341. /**
  17342. * @author takahirox / http://github.com/takahirox
  17343. *
  17344. * parameters = {
  17345. * gradientMap: new THREE.Texture( <Image> )
  17346. * }
  17347. */
  17348. function MeshToonMaterial( parameters ) {
  17349. MeshPhongMaterial.call( this );
  17350. this.defines = { 'TOON': '' };
  17351. this.type = 'MeshToonMaterial';
  17352. this.gradientMap = null;
  17353. this.setValues( parameters );
  17354. }
  17355. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  17356. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  17357. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  17358. MeshToonMaterial.prototype.copy = function ( source ) {
  17359. MeshPhongMaterial.prototype.copy.call( this, source );
  17360. this.gradientMap = source.gradientMap;
  17361. return this;
  17362. };
  17363. /**
  17364. * @author mrdoob / http://mrdoob.com/
  17365. * @author WestLangley / http://github.com/WestLangley
  17366. *
  17367. * parameters = {
  17368. * opacity: <float>,
  17369. *
  17370. * bumpMap: new THREE.Texture( <Image> ),
  17371. * bumpScale: <float>,
  17372. *
  17373. * normalMap: new THREE.Texture( <Image> ),
  17374. * normalScale: <Vector2>,
  17375. *
  17376. * displacementMap: new THREE.Texture( <Image> ),
  17377. * displacementScale: <float>,
  17378. * displacementBias: <float>,
  17379. *
  17380. * wireframe: <boolean>,
  17381. * wireframeLinewidth: <float>
  17382. *
  17383. * skinning: <bool>,
  17384. * morphTargets: <bool>,
  17385. * morphNormals: <bool>
  17386. * }
  17387. */
  17388. function MeshNormalMaterial( parameters ) {
  17389. Material.call( this, parameters );
  17390. this.type = 'MeshNormalMaterial';
  17391. this.bumpMap = null;
  17392. this.bumpScale = 1;
  17393. this.normalMap = null;
  17394. this.normalScale = new Vector2( 1, 1 );
  17395. this.displacementMap = null;
  17396. this.displacementScale = 1;
  17397. this.displacementBias = 0;
  17398. this.wireframe = false;
  17399. this.wireframeLinewidth = 1;
  17400. this.fog = false;
  17401. this.lights = false;
  17402. this.skinning = false;
  17403. this.morphTargets = false;
  17404. this.morphNormals = false;
  17405. this.setValues( parameters );
  17406. }
  17407. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  17408. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  17409. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  17410. MeshNormalMaterial.prototype.copy = function ( source ) {
  17411. Material.prototype.copy.call( this, source );
  17412. this.bumpMap = source.bumpMap;
  17413. this.bumpScale = source.bumpScale;
  17414. this.normalMap = source.normalMap;
  17415. this.normalScale.copy( source.normalScale );
  17416. this.displacementMap = source.displacementMap;
  17417. this.displacementScale = source.displacementScale;
  17418. this.displacementBias = source.displacementBias;
  17419. this.wireframe = source.wireframe;
  17420. this.wireframeLinewidth = source.wireframeLinewidth;
  17421. this.skinning = source.skinning;
  17422. this.morphTargets = source.morphTargets;
  17423. this.morphNormals = source.morphNormals;
  17424. return this;
  17425. };
  17426. /**
  17427. * @author mrdoob / http://mrdoob.com/
  17428. * @author alteredq / http://alteredqualia.com/
  17429. *
  17430. * parameters = {
  17431. * color: <hex>,
  17432. * opacity: <float>,
  17433. *
  17434. * map: new THREE.Texture( <Image> ),
  17435. *
  17436. * lightMap: new THREE.Texture( <Image> ),
  17437. * lightMapIntensity: <float>
  17438. *
  17439. * aoMap: new THREE.Texture( <Image> ),
  17440. * aoMapIntensity: <float>
  17441. *
  17442. * emissive: <hex>,
  17443. * emissiveIntensity: <float>
  17444. * emissiveMap: new THREE.Texture( <Image> ),
  17445. *
  17446. * specularMap: new THREE.Texture( <Image> ),
  17447. *
  17448. * alphaMap: new THREE.Texture( <Image> ),
  17449. *
  17450. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  17451. * combine: THREE.Multiply,
  17452. * reflectivity: <float>,
  17453. * refractionRatio: <float>,
  17454. *
  17455. * wireframe: <boolean>,
  17456. * wireframeLinewidth: <float>,
  17457. *
  17458. * skinning: <bool>,
  17459. * morphTargets: <bool>,
  17460. * morphNormals: <bool>
  17461. * }
  17462. */
  17463. function MeshLambertMaterial( parameters ) {
  17464. Material.call( this );
  17465. this.type = 'MeshLambertMaterial';
  17466. this.color = new Color( 0xffffff ); // diffuse
  17467. this.map = null;
  17468. this.lightMap = null;
  17469. this.lightMapIntensity = 1.0;
  17470. this.aoMap = null;
  17471. this.aoMapIntensity = 1.0;
  17472. this.emissive = new Color( 0x000000 );
  17473. this.emissiveIntensity = 1.0;
  17474. this.emissiveMap = null;
  17475. this.specularMap = null;
  17476. this.alphaMap = null;
  17477. this.envMap = null;
  17478. this.combine = MultiplyOperation;
  17479. this.reflectivity = 1;
  17480. this.refractionRatio = 0.98;
  17481. this.wireframe = false;
  17482. this.wireframeLinewidth = 1;
  17483. this.wireframeLinecap = 'round';
  17484. this.wireframeLinejoin = 'round';
  17485. this.skinning = false;
  17486. this.morphTargets = false;
  17487. this.morphNormals = false;
  17488. this.setValues( parameters );
  17489. }
  17490. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  17491. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  17492. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  17493. MeshLambertMaterial.prototype.copy = function ( source ) {
  17494. Material.prototype.copy.call( this, source );
  17495. this.color.copy( source.color );
  17496. this.map = source.map;
  17497. this.lightMap = source.lightMap;
  17498. this.lightMapIntensity = source.lightMapIntensity;
  17499. this.aoMap = source.aoMap;
  17500. this.aoMapIntensity = source.aoMapIntensity;
  17501. this.emissive.copy( source.emissive );
  17502. this.emissiveMap = source.emissiveMap;
  17503. this.emissiveIntensity = source.emissiveIntensity;
  17504. this.specularMap = source.specularMap;
  17505. this.alphaMap = source.alphaMap;
  17506. this.envMap = source.envMap;
  17507. this.combine = source.combine;
  17508. this.reflectivity = source.reflectivity;
  17509. this.refractionRatio = source.refractionRatio;
  17510. this.wireframe = source.wireframe;
  17511. this.wireframeLinewidth = source.wireframeLinewidth;
  17512. this.wireframeLinecap = source.wireframeLinecap;
  17513. this.wireframeLinejoin = source.wireframeLinejoin;
  17514. this.skinning = source.skinning;
  17515. this.morphTargets = source.morphTargets;
  17516. this.morphNormals = source.morphNormals;
  17517. return this;
  17518. };
  17519. /**
  17520. * @author alteredq / http://alteredqualia.com/
  17521. *
  17522. * parameters = {
  17523. * color: <hex>,
  17524. * opacity: <float>,
  17525. *
  17526. * linewidth: <float>,
  17527. *
  17528. * scale: <float>,
  17529. * dashSize: <float>,
  17530. * gapSize: <float>
  17531. * }
  17532. */
  17533. function LineDashedMaterial( parameters ) {
  17534. Material.call( this );
  17535. this.type = 'LineDashedMaterial';
  17536. this.color = new Color( 0xffffff );
  17537. this.linewidth = 1;
  17538. this.scale = 1;
  17539. this.dashSize = 3;
  17540. this.gapSize = 1;
  17541. this.lights = false;
  17542. this.setValues( parameters );
  17543. }
  17544. LineDashedMaterial.prototype = Object.create( Material.prototype );
  17545. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  17546. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  17547. LineDashedMaterial.prototype.copy = function ( source ) {
  17548. Material.prototype.copy.call( this, source );
  17549. this.color.copy( source.color );
  17550. this.linewidth = source.linewidth;
  17551. this.scale = source.scale;
  17552. this.dashSize = source.dashSize;
  17553. this.gapSize = source.gapSize;
  17554. return this;
  17555. };
  17556. var Materials = Object.freeze({
  17557. ShadowMaterial: ShadowMaterial,
  17558. SpriteMaterial: SpriteMaterial,
  17559. RawShaderMaterial: RawShaderMaterial,
  17560. ShaderMaterial: ShaderMaterial,
  17561. PointsMaterial: PointsMaterial,
  17562. MeshPhysicalMaterial: MeshPhysicalMaterial,
  17563. MeshStandardMaterial: MeshStandardMaterial,
  17564. MeshPhongMaterial: MeshPhongMaterial,
  17565. MeshToonMaterial: MeshToonMaterial,
  17566. MeshNormalMaterial: MeshNormalMaterial,
  17567. MeshLambertMaterial: MeshLambertMaterial,
  17568. MeshDepthMaterial: MeshDepthMaterial,
  17569. MeshBasicMaterial: MeshBasicMaterial,
  17570. LineDashedMaterial: LineDashedMaterial,
  17571. LineBasicMaterial: LineBasicMaterial,
  17572. Material: Material
  17573. });
  17574. /**
  17575. * @author mrdoob / http://mrdoob.com/
  17576. */
  17577. var Cache = {
  17578. enabled: false,
  17579. files: {},
  17580. add: function ( key, file ) {
  17581. if ( this.enabled === false ) return;
  17582. // console.log( 'THREE.Cache', 'Adding key:', key );
  17583. this.files[ key ] = file;
  17584. },
  17585. get: function ( key ) {
  17586. if ( this.enabled === false ) return;
  17587. // console.log( 'THREE.Cache', 'Checking key:', key );
  17588. return this.files[ key ];
  17589. },
  17590. remove: function ( key ) {
  17591. delete this.files[ key ];
  17592. },
  17593. clear: function () {
  17594. this.files = {};
  17595. }
  17596. };
  17597. /**
  17598. * @author mrdoob / http://mrdoob.com/
  17599. */
  17600. function LoadingManager( onLoad, onProgress, onError ) {
  17601. var scope = this;
  17602. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  17603. this.onStart = undefined;
  17604. this.onLoad = onLoad;
  17605. this.onProgress = onProgress;
  17606. this.onError = onError;
  17607. this.itemStart = function ( url ) {
  17608. itemsTotal ++;
  17609. if ( isLoading === false ) {
  17610. if ( scope.onStart !== undefined ) {
  17611. scope.onStart( url, itemsLoaded, itemsTotal );
  17612. }
  17613. }
  17614. isLoading = true;
  17615. };
  17616. this.itemEnd = function ( url ) {
  17617. itemsLoaded ++;
  17618. if ( scope.onProgress !== undefined ) {
  17619. scope.onProgress( url, itemsLoaded, itemsTotal );
  17620. }
  17621. if ( itemsLoaded === itemsTotal ) {
  17622. isLoading = false;
  17623. if ( scope.onLoad !== undefined ) {
  17624. scope.onLoad();
  17625. }
  17626. }
  17627. };
  17628. this.itemError = function ( url ) {
  17629. if ( scope.onError !== undefined ) {
  17630. scope.onError( url );
  17631. }
  17632. };
  17633. }
  17634. var DefaultLoadingManager = new LoadingManager();
  17635. /**
  17636. * @author mrdoob / http://mrdoob.com/
  17637. */
  17638. function FileLoader( manager ) {
  17639. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17640. }
  17641. Object.assign( FileLoader.prototype, {
  17642. load: function ( url, onLoad, onProgress, onError ) {
  17643. if ( url === undefined ) url = '';
  17644. if ( this.path !== undefined ) url = this.path + url;
  17645. var scope = this;
  17646. var cached = Cache.get( url );
  17647. if ( cached !== undefined ) {
  17648. scope.manager.itemStart( url );
  17649. setTimeout( function () {
  17650. if ( onLoad ) onLoad( cached );
  17651. scope.manager.itemEnd( url );
  17652. }, 0 );
  17653. return cached;
  17654. }
  17655. // Check for data: URI
  17656. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  17657. var dataUriRegexResult = url.match( dataUriRegex );
  17658. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  17659. if ( dataUriRegexResult ) {
  17660. var mimeType = dataUriRegexResult[ 1 ];
  17661. var isBase64 = !! dataUriRegexResult[ 2 ];
  17662. var data = dataUriRegexResult[ 3 ];
  17663. data = window.decodeURIComponent( data );
  17664. if ( isBase64 ) data = window.atob( data );
  17665. try {
  17666. var response;
  17667. var responseType = ( this.responseType || '' ).toLowerCase();
  17668. switch ( responseType ) {
  17669. case 'arraybuffer':
  17670. case 'blob':
  17671. response = new ArrayBuffer( data.length );
  17672. var view = new Uint8Array( response );
  17673. for ( var i = 0; i < data.length; i ++ ) {
  17674. view[ i ] = data.charCodeAt( i );
  17675. }
  17676. if ( responseType === 'blob' ) {
  17677. response = new Blob( [ response ], { type: mimeType } );
  17678. }
  17679. break;
  17680. case 'document':
  17681. var parser = new DOMParser();
  17682. response = parser.parseFromString( data, mimeType );
  17683. break;
  17684. case 'json':
  17685. response = JSON.parse( data );
  17686. break;
  17687. default: // 'text' or other
  17688. response = data;
  17689. break;
  17690. }
  17691. // Wait for next browser tick
  17692. window.setTimeout( function () {
  17693. if ( onLoad ) onLoad( response );
  17694. scope.manager.itemEnd( url );
  17695. }, 0 );
  17696. } catch ( error ) {
  17697. // Wait for next browser tick
  17698. window.setTimeout( function () {
  17699. if ( onError ) onError( error );
  17700. scope.manager.itemEnd( url );
  17701. scope.manager.itemError( url );
  17702. }, 0 );
  17703. }
  17704. } else {
  17705. var request = new XMLHttpRequest();
  17706. request.open( 'GET', url, true );
  17707. request.addEventListener( 'load', function ( event ) {
  17708. var response = event.target.response;
  17709. Cache.add( url, response );
  17710. if ( this.status === 200 ) {
  17711. if ( onLoad ) onLoad( response );
  17712. scope.manager.itemEnd( url );
  17713. } else if ( this.status === 0 ) {
  17714. // Some browsers return HTTP Status 0 when using non-http protocol
  17715. // e.g. 'file://' or 'data://'. Handle as success.
  17716. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  17717. if ( onLoad ) onLoad( response );
  17718. scope.manager.itemEnd( url );
  17719. } else {
  17720. if ( onError ) onError( event );
  17721. scope.manager.itemEnd( url );
  17722. scope.manager.itemError( url );
  17723. }
  17724. }, false );
  17725. if ( onProgress !== undefined ) {
  17726. request.addEventListener( 'progress', function ( event ) {
  17727. onProgress( event );
  17728. }, false );
  17729. }
  17730. request.addEventListener( 'error', function ( event ) {
  17731. if ( onError ) onError( event );
  17732. scope.manager.itemEnd( url );
  17733. scope.manager.itemError( url );
  17734. }, false );
  17735. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  17736. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  17737. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  17738. for ( var header in this.requestHeader ) {
  17739. request.setRequestHeader( header, this.requestHeader[ header ] );
  17740. }
  17741. request.send( null );
  17742. }
  17743. scope.manager.itemStart( url );
  17744. return request;
  17745. },
  17746. setPath: function ( value ) {
  17747. this.path = value;
  17748. return this;
  17749. },
  17750. setResponseType: function ( value ) {
  17751. this.responseType = value;
  17752. return this;
  17753. },
  17754. setWithCredentials: function ( value ) {
  17755. this.withCredentials = value;
  17756. return this;
  17757. },
  17758. setMimeType: function ( value ) {
  17759. this.mimeType = value;
  17760. return this;
  17761. },
  17762. setRequestHeader: function ( value ) {
  17763. this.requestHeader = value;
  17764. return this;
  17765. }
  17766. } );
  17767. /**
  17768. * @author mrdoob / http://mrdoob.com/
  17769. *
  17770. * Abstract Base class to block based textures loader (dds, pvr, ...)
  17771. */
  17772. function CompressedTextureLoader( manager ) {
  17773. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17774. // override in sub classes
  17775. this._parser = null;
  17776. }
  17777. Object.assign( CompressedTextureLoader.prototype, {
  17778. load: function ( url, onLoad, onProgress, onError ) {
  17779. var scope = this;
  17780. var images = [];
  17781. var texture = new CompressedTexture();
  17782. texture.image = images;
  17783. var loader = new FileLoader( this.manager );
  17784. loader.setPath( this.path );
  17785. loader.setResponseType( 'arraybuffer' );
  17786. function loadTexture( i ) {
  17787. loader.load( url[ i ], function ( buffer ) {
  17788. var texDatas = scope._parser( buffer, true );
  17789. images[ i ] = {
  17790. width: texDatas.width,
  17791. height: texDatas.height,
  17792. format: texDatas.format,
  17793. mipmaps: texDatas.mipmaps
  17794. };
  17795. loaded += 1;
  17796. if ( loaded === 6 ) {
  17797. if ( texDatas.mipmapCount === 1 )
  17798. texture.minFilter = LinearFilter;
  17799. texture.format = texDatas.format;
  17800. texture.needsUpdate = true;
  17801. if ( onLoad ) onLoad( texture );
  17802. }
  17803. }, onProgress, onError );
  17804. }
  17805. if ( Array.isArray( url ) ) {
  17806. var loaded = 0;
  17807. for ( var i = 0, il = url.length; i < il; ++ i ) {
  17808. loadTexture( i );
  17809. }
  17810. } else {
  17811. // compressed cubemap texture stored in a single DDS file
  17812. loader.load( url, function ( buffer ) {
  17813. var texDatas = scope._parser( buffer, true );
  17814. if ( texDatas.isCubemap ) {
  17815. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  17816. for ( var f = 0; f < faces; f ++ ) {
  17817. images[ f ] = { mipmaps : [] };
  17818. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  17819. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  17820. images[ f ].format = texDatas.format;
  17821. images[ f ].width = texDatas.width;
  17822. images[ f ].height = texDatas.height;
  17823. }
  17824. }
  17825. } else {
  17826. texture.image.width = texDatas.width;
  17827. texture.image.height = texDatas.height;
  17828. texture.mipmaps = texDatas.mipmaps;
  17829. }
  17830. if ( texDatas.mipmapCount === 1 ) {
  17831. texture.minFilter = LinearFilter;
  17832. }
  17833. texture.format = texDatas.format;
  17834. texture.needsUpdate = true;
  17835. if ( onLoad ) onLoad( texture );
  17836. }, onProgress, onError );
  17837. }
  17838. return texture;
  17839. },
  17840. setPath: function ( value ) {
  17841. this.path = value;
  17842. return this;
  17843. }
  17844. } );
  17845. /**
  17846. * @author Nikos M. / https://github.com/foo123/
  17847. *
  17848. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  17849. */
  17850. function DataTextureLoader( manager ) {
  17851. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17852. // override in sub classes
  17853. this._parser = null;
  17854. }
  17855. Object.assign( DataTextureLoader.prototype, {
  17856. load: function ( url, onLoad, onProgress, onError ) {
  17857. var scope = this;
  17858. var texture = new DataTexture();
  17859. var loader = new FileLoader( this.manager );
  17860. loader.setResponseType( 'arraybuffer' );
  17861. loader.load( url, function ( buffer ) {
  17862. var texData = scope._parser( buffer );
  17863. if ( ! texData ) return;
  17864. if ( undefined !== texData.image ) {
  17865. texture.image = texData.image;
  17866. } else if ( undefined !== texData.data ) {
  17867. texture.image.width = texData.width;
  17868. texture.image.height = texData.height;
  17869. texture.image.data = texData.data;
  17870. }
  17871. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  17872. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  17873. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  17874. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  17875. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  17876. if ( undefined !== texData.format ) {
  17877. texture.format = texData.format;
  17878. }
  17879. if ( undefined !== texData.type ) {
  17880. texture.type = texData.type;
  17881. }
  17882. if ( undefined !== texData.mipmaps ) {
  17883. texture.mipmaps = texData.mipmaps;
  17884. }
  17885. if ( 1 === texData.mipmapCount ) {
  17886. texture.minFilter = LinearFilter;
  17887. }
  17888. texture.needsUpdate = true;
  17889. if ( onLoad ) onLoad( texture, texData );
  17890. }, onProgress, onError );
  17891. return texture;
  17892. }
  17893. } );
  17894. /**
  17895. * @author mrdoob / http://mrdoob.com/
  17896. */
  17897. function ImageLoader( manager ) {
  17898. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17899. }
  17900. Object.assign( ImageLoader.prototype, {
  17901. load: function ( url, onLoad, onProgress, onError ) {
  17902. if ( url === undefined ) url = '';
  17903. if ( this.path !== undefined ) url = this.path + url;
  17904. var scope = this;
  17905. var cached = Cache.get( url );
  17906. if ( cached !== undefined ) {
  17907. scope.manager.itemStart( url );
  17908. setTimeout( function () {
  17909. if ( onLoad ) onLoad( cached );
  17910. scope.manager.itemEnd( url );
  17911. }, 0 );
  17912. return cached;
  17913. }
  17914. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  17915. image.addEventListener( 'load', function () {
  17916. Cache.add( url, this );
  17917. if ( onLoad ) onLoad( this );
  17918. scope.manager.itemEnd( url );
  17919. }, false );
  17920. /*
  17921. image.addEventListener( 'progress', function ( event ) {
  17922. if ( onProgress ) onProgress( event );
  17923. }, false );
  17924. */
  17925. image.addEventListener( 'error', function ( event ) {
  17926. if ( onError ) onError( event );
  17927. scope.manager.itemEnd( url );
  17928. scope.manager.itemError( url );
  17929. }, false );
  17930. if ( url.substr( 0, 5 ) !== 'data:' ) {
  17931. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  17932. }
  17933. scope.manager.itemStart( url );
  17934. image.src = url;
  17935. return image;
  17936. },
  17937. setCrossOrigin: function ( value ) {
  17938. this.crossOrigin = value;
  17939. return this;
  17940. },
  17941. setPath: function ( value ) {
  17942. this.path = value;
  17943. return this;
  17944. }
  17945. } );
  17946. /**
  17947. * @author mrdoob / http://mrdoob.com/
  17948. */
  17949. function CubeTextureLoader( manager ) {
  17950. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17951. }
  17952. Object.assign( CubeTextureLoader.prototype, {
  17953. load: function ( urls, onLoad, onProgress, onError ) {
  17954. var texture = new CubeTexture();
  17955. var loader = new ImageLoader( this.manager );
  17956. loader.setCrossOrigin( this.crossOrigin );
  17957. loader.setPath( this.path );
  17958. var loaded = 0;
  17959. function loadTexture( i ) {
  17960. loader.load( urls[ i ], function ( image ) {
  17961. texture.images[ i ] = image;
  17962. loaded ++;
  17963. if ( loaded === 6 ) {
  17964. texture.needsUpdate = true;
  17965. if ( onLoad ) onLoad( texture );
  17966. }
  17967. }, undefined, onError );
  17968. }
  17969. for ( var i = 0; i < urls.length; ++ i ) {
  17970. loadTexture( i );
  17971. }
  17972. return texture;
  17973. },
  17974. setCrossOrigin: function ( value ) {
  17975. this.crossOrigin = value;
  17976. return this;
  17977. },
  17978. setPath: function ( value ) {
  17979. this.path = value;
  17980. return this;
  17981. }
  17982. } );
  17983. /**
  17984. * @author mrdoob / http://mrdoob.com/
  17985. */
  17986. function TextureLoader( manager ) {
  17987. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17988. }
  17989. Object.assign( TextureLoader.prototype, {
  17990. load: function ( url, onLoad, onProgress, onError ) {
  17991. var loader = new ImageLoader( this.manager );
  17992. loader.setCrossOrigin( this.crossOrigin );
  17993. loader.setPath( this.path );
  17994. var texture = new Texture();
  17995. texture.image = loader.load( url, function () {
  17996. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  17997. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  17998. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  17999. texture.needsUpdate = true;
  18000. if ( onLoad !== undefined ) {
  18001. onLoad( texture );
  18002. }
  18003. }, onProgress, onError );
  18004. return texture;
  18005. },
  18006. setCrossOrigin: function ( value ) {
  18007. this.crossOrigin = value;
  18008. return this;
  18009. },
  18010. setPath: function ( value ) {
  18011. this.path = value;
  18012. return this;
  18013. }
  18014. } );
  18015. /**
  18016. * @author mrdoob / http://mrdoob.com/
  18017. * @author alteredq / http://alteredqualia.com/
  18018. */
  18019. function Light( color, intensity ) {
  18020. Object3D.call( this );
  18021. this.type = 'Light';
  18022. this.color = new Color( color );
  18023. this.intensity = intensity !== undefined ? intensity : 1;
  18024. this.receiveShadow = undefined;
  18025. }
  18026. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  18027. constructor: Light,
  18028. isLight: true,
  18029. copy: function ( source ) {
  18030. Object3D.prototype.copy.call( this, source );
  18031. this.color.copy( source.color );
  18032. this.intensity = source.intensity;
  18033. return this;
  18034. },
  18035. toJSON: function ( meta ) {
  18036. var data = Object3D.prototype.toJSON.call( this, meta );
  18037. data.object.color = this.color.getHex();
  18038. data.object.intensity = this.intensity;
  18039. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  18040. if ( this.distance !== undefined ) data.object.distance = this.distance;
  18041. if ( this.angle !== undefined ) data.object.angle = this.angle;
  18042. if ( this.decay !== undefined ) data.object.decay = this.decay;
  18043. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  18044. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  18045. return data;
  18046. }
  18047. } );
  18048. /**
  18049. * @author alteredq / http://alteredqualia.com/
  18050. */
  18051. function HemisphereLight( skyColor, groundColor, intensity ) {
  18052. Light.call( this, skyColor, intensity );
  18053. this.type = 'HemisphereLight';
  18054. this.castShadow = undefined;
  18055. this.position.copy( Object3D.DefaultUp );
  18056. this.updateMatrix();
  18057. this.groundColor = new Color( groundColor );
  18058. }
  18059. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18060. constructor: HemisphereLight,
  18061. isHemisphereLight: true,
  18062. copy: function ( source ) {
  18063. Light.prototype.copy.call( this, source );
  18064. this.groundColor.copy( source.groundColor );
  18065. return this;
  18066. }
  18067. } );
  18068. /**
  18069. * @author mrdoob / http://mrdoob.com/
  18070. */
  18071. function LightShadow( camera ) {
  18072. this.camera = camera;
  18073. this.bias = 0;
  18074. this.radius = 1;
  18075. this.mapSize = new Vector2( 512, 512 );
  18076. this.map = null;
  18077. this.matrix = new Matrix4();
  18078. }
  18079. Object.assign( LightShadow.prototype, {
  18080. copy: function ( source ) {
  18081. this.camera = source.camera.clone();
  18082. this.bias = source.bias;
  18083. this.radius = source.radius;
  18084. this.mapSize.copy( source.mapSize );
  18085. return this;
  18086. },
  18087. clone: function () {
  18088. return new this.constructor().copy( this );
  18089. },
  18090. toJSON: function () {
  18091. var object = {};
  18092. if ( this.bias !== 0 ) object.bias = this.bias;
  18093. if ( this.radius !== 1 ) object.radius = this.radius;
  18094. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  18095. object.camera = this.camera.toJSON( false ).object;
  18096. delete object.camera.matrix;
  18097. return object;
  18098. }
  18099. } );
  18100. /**
  18101. * @author mrdoob / http://mrdoob.com/
  18102. */
  18103. function SpotLightShadow() {
  18104. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  18105. }
  18106. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  18107. constructor: SpotLightShadow,
  18108. isSpotLightShadow: true,
  18109. update: function ( light ) {
  18110. var camera = this.camera;
  18111. var fov = _Math.RAD2DEG * 2 * light.angle;
  18112. var aspect = this.mapSize.width / this.mapSize.height;
  18113. var far = light.distance || camera.far;
  18114. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  18115. camera.fov = fov;
  18116. camera.aspect = aspect;
  18117. camera.far = far;
  18118. camera.updateProjectionMatrix();
  18119. }
  18120. }
  18121. } );
  18122. /**
  18123. * @author alteredq / http://alteredqualia.com/
  18124. */
  18125. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  18126. Light.call( this, color, intensity );
  18127. this.type = 'SpotLight';
  18128. this.position.copy( Object3D.DefaultUp );
  18129. this.updateMatrix();
  18130. this.target = new Object3D();
  18131. Object.defineProperty( this, 'power', {
  18132. get: function () {
  18133. // intensity = power per solid angle.
  18134. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18135. return this.intensity * Math.PI;
  18136. },
  18137. set: function ( power ) {
  18138. // intensity = power per solid angle.
  18139. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18140. this.intensity = power / Math.PI;
  18141. }
  18142. } );
  18143. this.distance = ( distance !== undefined ) ? distance : 0;
  18144. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  18145. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  18146. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  18147. this.shadow = new SpotLightShadow();
  18148. }
  18149. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18150. constructor: SpotLight,
  18151. isSpotLight: true,
  18152. copy: function ( source ) {
  18153. Light.prototype.copy.call( this, source );
  18154. this.distance = source.distance;
  18155. this.angle = source.angle;
  18156. this.penumbra = source.penumbra;
  18157. this.decay = source.decay;
  18158. this.target = source.target.clone();
  18159. this.shadow = source.shadow.clone();
  18160. return this;
  18161. }
  18162. } );
  18163. /**
  18164. * @author mrdoob / http://mrdoob.com/
  18165. */
  18166. function PointLight( color, intensity, distance, decay ) {
  18167. Light.call( this, color, intensity );
  18168. this.type = 'PointLight';
  18169. Object.defineProperty( this, 'power', {
  18170. get: function () {
  18171. // intensity = power per solid angle.
  18172. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18173. return this.intensity * 4 * Math.PI;
  18174. },
  18175. set: function ( power ) {
  18176. // intensity = power per solid angle.
  18177. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18178. this.intensity = power / ( 4 * Math.PI );
  18179. }
  18180. } );
  18181. this.distance = ( distance !== undefined ) ? distance : 0;
  18182. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  18183. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  18184. }
  18185. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18186. constructor: PointLight,
  18187. isPointLight: true,
  18188. copy: function ( source ) {
  18189. Light.prototype.copy.call( this, source );
  18190. this.distance = source.distance;
  18191. this.decay = source.decay;
  18192. this.shadow = source.shadow.clone();
  18193. return this;
  18194. }
  18195. } );
  18196. /**
  18197. * @author mrdoob / http://mrdoob.com/
  18198. */
  18199. function DirectionalLightShadow( ) {
  18200. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  18201. }
  18202. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  18203. constructor: DirectionalLightShadow
  18204. } );
  18205. /**
  18206. * @author mrdoob / http://mrdoob.com/
  18207. * @author alteredq / http://alteredqualia.com/
  18208. */
  18209. function DirectionalLight( color, intensity ) {
  18210. Light.call( this, color, intensity );
  18211. this.type = 'DirectionalLight';
  18212. this.position.copy( Object3D.DefaultUp );
  18213. this.updateMatrix();
  18214. this.target = new Object3D();
  18215. this.shadow = new DirectionalLightShadow();
  18216. }
  18217. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18218. constructor: DirectionalLight,
  18219. isDirectionalLight: true,
  18220. copy: function ( source ) {
  18221. Light.prototype.copy.call( this, source );
  18222. this.target = source.target.clone();
  18223. this.shadow = source.shadow.clone();
  18224. return this;
  18225. }
  18226. } );
  18227. /**
  18228. * @author mrdoob / http://mrdoob.com/
  18229. */
  18230. function AmbientLight( color, intensity ) {
  18231. Light.call( this, color, intensity );
  18232. this.type = 'AmbientLight';
  18233. this.castShadow = undefined;
  18234. }
  18235. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18236. constructor: AmbientLight,
  18237. isAmbientLight: true
  18238. } );
  18239. /**
  18240. * @author abelnation / http://github.com/abelnation
  18241. */
  18242. function RectAreaLight( color, intensity, width, height ) {
  18243. Light.call( this, color, intensity );
  18244. this.type = 'RectAreaLight';
  18245. this.position.set( 0, 1, 0 );
  18246. this.updateMatrix();
  18247. this.width = ( width !== undefined ) ? width : 10;
  18248. this.height = ( height !== undefined ) ? height : 10;
  18249. // TODO (abelnation): distance/decay
  18250. // TODO (abelnation): update method for RectAreaLight to update transform to lookat target
  18251. // TODO (abelnation): shadows
  18252. }
  18253. // TODO (abelnation): RectAreaLight update when light shape is changed
  18254. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18255. constructor: RectAreaLight,
  18256. isRectAreaLight: true,
  18257. copy: function ( source ) {
  18258. Light.prototype.copy.call( this, source );
  18259. this.width = source.width;
  18260. this.height = source.height;
  18261. return this;
  18262. },
  18263. toJSON: function ( meta ) {
  18264. var data = Light.prototype.toJSON.call( this, meta );
  18265. data.object.width = this.width;
  18266. data.object.height = this.height;
  18267. return data;
  18268. }
  18269. } );
  18270. /**
  18271. * @author tschw
  18272. * @author Ben Houston / http://clara.io/
  18273. * @author David Sarno / http://lighthaus.us/
  18274. */
  18275. var AnimationUtils = {
  18276. // same as Array.prototype.slice, but also works on typed arrays
  18277. arraySlice: function ( array, from, to ) {
  18278. if ( AnimationUtils.isTypedArray( array ) ) {
  18279. // in ios9 array.subarray(from, undefined) will return empty array
  18280. // but array.subarray(from) or array.subarray(from, len) is correct
  18281. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  18282. }
  18283. return array.slice( from, to );
  18284. },
  18285. // converts an array to a specific type
  18286. convertArray: function ( array, type, forceClone ) {
  18287. if ( ! array || // let 'undefined' and 'null' pass
  18288. ! forceClone && array.constructor === type ) return array;
  18289. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  18290. return new type( array ); // create typed array
  18291. }
  18292. return Array.prototype.slice.call( array ); // create Array
  18293. },
  18294. isTypedArray: function ( object ) {
  18295. return ArrayBuffer.isView( object ) &&
  18296. ! ( object instanceof DataView );
  18297. },
  18298. // returns an array by which times and values can be sorted
  18299. getKeyframeOrder: function ( times ) {
  18300. function compareTime( i, j ) {
  18301. return times[ i ] - times[ j ];
  18302. }
  18303. var n = times.length;
  18304. var result = new Array( n );
  18305. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  18306. result.sort( compareTime );
  18307. return result;
  18308. },
  18309. // uses the array previously returned by 'getKeyframeOrder' to sort data
  18310. sortedArray: function ( values, stride, order ) {
  18311. var nValues = values.length;
  18312. var result = new values.constructor( nValues );
  18313. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  18314. var srcOffset = order[ i ] * stride;
  18315. for ( var j = 0; j !== stride; ++ j ) {
  18316. result[ dstOffset ++ ] = values[ srcOffset + j ];
  18317. }
  18318. }
  18319. return result;
  18320. },
  18321. // function for parsing AOS keyframe formats
  18322. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  18323. var i = 1, key = jsonKeys[ 0 ];
  18324. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  18325. key = jsonKeys[ i ++ ];
  18326. }
  18327. if ( key === undefined ) return; // no data
  18328. var value = key[ valuePropertyName ];
  18329. if ( value === undefined ) return; // no data
  18330. if ( Array.isArray( value ) ) {
  18331. do {
  18332. value = key[ valuePropertyName ];
  18333. if ( value !== undefined ) {
  18334. times.push( key.time );
  18335. values.push.apply( values, value ); // push all elements
  18336. }
  18337. key = jsonKeys[ i ++ ];
  18338. } while ( key !== undefined );
  18339. } else if ( value.toArray !== undefined ) {
  18340. // ...assume THREE.Math-ish
  18341. do {
  18342. value = key[ valuePropertyName ];
  18343. if ( value !== undefined ) {
  18344. times.push( key.time );
  18345. value.toArray( values, values.length );
  18346. }
  18347. key = jsonKeys[ i ++ ];
  18348. } while ( key !== undefined );
  18349. } else {
  18350. // otherwise push as-is
  18351. do {
  18352. value = key[ valuePropertyName ];
  18353. if ( value !== undefined ) {
  18354. times.push( key.time );
  18355. values.push( value );
  18356. }
  18357. key = jsonKeys[ i ++ ];
  18358. } while ( key !== undefined );
  18359. }
  18360. }
  18361. };
  18362. /**
  18363. * Abstract base class of interpolants over parametric samples.
  18364. *
  18365. * The parameter domain is one dimensional, typically the time or a path
  18366. * along a curve defined by the data.
  18367. *
  18368. * The sample values can have any dimensionality and derived classes may
  18369. * apply special interpretations to the data.
  18370. *
  18371. * This class provides the interval seek in a Template Method, deferring
  18372. * the actual interpolation to derived classes.
  18373. *
  18374. * Time complexity is O(1) for linear access crossing at most two points
  18375. * and O(log N) for random access, where N is the number of positions.
  18376. *
  18377. * References:
  18378. *
  18379. * http://www.oodesign.com/template-method-pattern.html
  18380. *
  18381. * @author tschw
  18382. */
  18383. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18384. this.parameterPositions = parameterPositions;
  18385. this._cachedIndex = 0;
  18386. this.resultBuffer = resultBuffer !== undefined ?
  18387. resultBuffer : new sampleValues.constructor( sampleSize );
  18388. this.sampleValues = sampleValues;
  18389. this.valueSize = sampleSize;
  18390. }
  18391. Object.assign( Interpolant.prototype, {
  18392. evaluate: function( t ) {
  18393. var pp = this.parameterPositions,
  18394. i1 = this._cachedIndex,
  18395. t1 = pp[ i1 ],
  18396. t0 = pp[ i1 - 1 ];
  18397. validate_interval: {
  18398. seek: {
  18399. var right;
  18400. linear_scan: {
  18401. //- See http://jsperf.com/comparison-to-undefined/3
  18402. //- slower code:
  18403. //-
  18404. //- if ( t >= t1 || t1 === undefined ) {
  18405. forward_scan: if ( ! ( t < t1 ) ) {
  18406. for ( var giveUpAt = i1 + 2; ;) {
  18407. if ( t1 === undefined ) {
  18408. if ( t < t0 ) break forward_scan;
  18409. // after end
  18410. i1 = pp.length;
  18411. this._cachedIndex = i1;
  18412. return this.afterEnd_( i1 - 1, t, t0 );
  18413. }
  18414. if ( i1 === giveUpAt ) break; // this loop
  18415. t0 = t1;
  18416. t1 = pp[ ++ i1 ];
  18417. if ( t < t1 ) {
  18418. // we have arrived at the sought interval
  18419. break seek;
  18420. }
  18421. }
  18422. // prepare binary search on the right side of the index
  18423. right = pp.length;
  18424. break linear_scan;
  18425. }
  18426. //- slower code:
  18427. //- if ( t < t0 || t0 === undefined ) {
  18428. if ( ! ( t >= t0 ) ) {
  18429. // looping?
  18430. var t1global = pp[ 1 ];
  18431. if ( t < t1global ) {
  18432. i1 = 2; // + 1, using the scan for the details
  18433. t0 = t1global;
  18434. }
  18435. // linear reverse scan
  18436. for ( var giveUpAt = i1 - 2; ;) {
  18437. if ( t0 === undefined ) {
  18438. // before start
  18439. this._cachedIndex = 0;
  18440. return this.beforeStart_( 0, t, t1 );
  18441. }
  18442. if ( i1 === giveUpAt ) break; // this loop
  18443. t1 = t0;
  18444. t0 = pp[ -- i1 - 1 ];
  18445. if ( t >= t0 ) {
  18446. // we have arrived at the sought interval
  18447. break seek;
  18448. }
  18449. }
  18450. // prepare binary search on the left side of the index
  18451. right = i1;
  18452. i1 = 0;
  18453. break linear_scan;
  18454. }
  18455. // the interval is valid
  18456. break validate_interval;
  18457. } // linear scan
  18458. // binary search
  18459. while ( i1 < right ) {
  18460. var mid = ( i1 + right ) >>> 1;
  18461. if ( t < pp[ mid ] ) {
  18462. right = mid;
  18463. } else {
  18464. i1 = mid + 1;
  18465. }
  18466. }
  18467. t1 = pp[ i1 ];
  18468. t0 = pp[ i1 - 1 ];
  18469. // check boundary cases, again
  18470. if ( t0 === undefined ) {
  18471. this._cachedIndex = 0;
  18472. return this.beforeStart_( 0, t, t1 );
  18473. }
  18474. if ( t1 === undefined ) {
  18475. i1 = pp.length;
  18476. this._cachedIndex = i1;
  18477. return this.afterEnd_( i1 - 1, t0, t );
  18478. }
  18479. } // seek
  18480. this._cachedIndex = i1;
  18481. this.intervalChanged_( i1, t0, t1 );
  18482. } // validate_interval
  18483. return this.interpolate_( i1, t0, t, t1 );
  18484. },
  18485. settings: null, // optional, subclass-specific settings structure
  18486. // Note: The indirection allows central control of many interpolants.
  18487. // --- Protected interface
  18488. DefaultSettings_: {},
  18489. getSettings_: function() {
  18490. return this.settings || this.DefaultSettings_;
  18491. },
  18492. copySampleValue_: function( index ) {
  18493. // copies a sample value to the result buffer
  18494. var result = this.resultBuffer,
  18495. values = this.sampleValues,
  18496. stride = this.valueSize,
  18497. offset = index * stride;
  18498. for ( var i = 0; i !== stride; ++ i ) {
  18499. result[ i ] = values[ offset + i ];
  18500. }
  18501. return result;
  18502. },
  18503. // Template methods for derived classes:
  18504. interpolate_: function( i1, t0, t, t1 ) {
  18505. throw new Error( "call to abstract method" );
  18506. // implementations shall return this.resultBuffer
  18507. },
  18508. intervalChanged_: function( i1, t0, t1 ) {
  18509. // empty
  18510. }
  18511. } );
  18512. //!\ DECLARE ALIAS AFTER assign prototype !
  18513. Object.assign( Interpolant.prototype, {
  18514. //( 0, t, t0 ), returns this.resultBuffer
  18515. beforeStart_: Interpolant.prototype.copySampleValue_,
  18516. //( N-1, tN-1, t ), returns this.resultBuffer
  18517. afterEnd_: Interpolant.prototype.copySampleValue_,
  18518. } );
  18519. /**
  18520. * Fast and simple cubic spline interpolant.
  18521. *
  18522. * It was derived from a Hermitian construction setting the first derivative
  18523. * at each sample position to the linear slope between neighboring positions
  18524. * over their parameter interval.
  18525. *
  18526. * @author tschw
  18527. */
  18528. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18529. Interpolant.call(
  18530. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18531. this._weightPrev = -0;
  18532. this._offsetPrev = -0;
  18533. this._weightNext = -0;
  18534. this._offsetNext = -0;
  18535. }
  18536. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18537. constructor: CubicInterpolant,
  18538. DefaultSettings_: {
  18539. endingStart: ZeroCurvatureEnding,
  18540. endingEnd: ZeroCurvatureEnding
  18541. },
  18542. intervalChanged_: function( i1, t0, t1 ) {
  18543. var pp = this.parameterPositions,
  18544. iPrev = i1 - 2,
  18545. iNext = i1 + 1,
  18546. tPrev = pp[ iPrev ],
  18547. tNext = pp[ iNext ];
  18548. if ( tPrev === undefined ) {
  18549. switch ( this.getSettings_().endingStart ) {
  18550. case ZeroSlopeEnding:
  18551. // f'(t0) = 0
  18552. iPrev = i1;
  18553. tPrev = 2 * t0 - t1;
  18554. break;
  18555. case WrapAroundEnding:
  18556. // use the other end of the curve
  18557. iPrev = pp.length - 2;
  18558. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  18559. break;
  18560. default: // ZeroCurvatureEnding
  18561. // f''(t0) = 0 a.k.a. Natural Spline
  18562. iPrev = i1;
  18563. tPrev = t1;
  18564. }
  18565. }
  18566. if ( tNext === undefined ) {
  18567. switch ( this.getSettings_().endingEnd ) {
  18568. case ZeroSlopeEnding:
  18569. // f'(tN) = 0
  18570. iNext = i1;
  18571. tNext = 2 * t1 - t0;
  18572. break;
  18573. case WrapAroundEnding:
  18574. // use the other end of the curve
  18575. iNext = 1;
  18576. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  18577. break;
  18578. default: // ZeroCurvatureEnding
  18579. // f''(tN) = 0, a.k.a. Natural Spline
  18580. iNext = i1 - 1;
  18581. tNext = t0;
  18582. }
  18583. }
  18584. var halfDt = ( t1 - t0 ) * 0.5,
  18585. stride = this.valueSize;
  18586. this._weightPrev = halfDt / ( t0 - tPrev );
  18587. this._weightNext = halfDt / ( tNext - t1 );
  18588. this._offsetPrev = iPrev * stride;
  18589. this._offsetNext = iNext * stride;
  18590. },
  18591. interpolate_: function( i1, t0, t, t1 ) {
  18592. var result = this.resultBuffer,
  18593. values = this.sampleValues,
  18594. stride = this.valueSize,
  18595. o1 = i1 * stride, o0 = o1 - stride,
  18596. oP = this._offsetPrev, oN = this._offsetNext,
  18597. wP = this._weightPrev, wN = this._weightNext,
  18598. p = ( t - t0 ) / ( t1 - t0 ),
  18599. pp = p * p,
  18600. ppp = pp * p;
  18601. // evaluate polynomials
  18602. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  18603. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  18604. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  18605. var sN = wN * ppp - wN * pp;
  18606. // combine data linearly
  18607. for ( var i = 0; i !== stride; ++ i ) {
  18608. result[ i ] =
  18609. sP * values[ oP + i ] +
  18610. s0 * values[ o0 + i ] +
  18611. s1 * values[ o1 + i ] +
  18612. sN * values[ oN + i ];
  18613. }
  18614. return result;
  18615. }
  18616. } );
  18617. /**
  18618. * @author tschw
  18619. */
  18620. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18621. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18622. }
  18623. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18624. constructor: LinearInterpolant,
  18625. interpolate_: function( i1, t0, t, t1 ) {
  18626. var result = this.resultBuffer,
  18627. values = this.sampleValues,
  18628. stride = this.valueSize,
  18629. offset1 = i1 * stride,
  18630. offset0 = offset1 - stride,
  18631. weight1 = ( t - t0 ) / ( t1 - t0 ),
  18632. weight0 = 1 - weight1;
  18633. for ( var i = 0; i !== stride; ++ i ) {
  18634. result[ i ] =
  18635. values[ offset0 + i ] * weight0 +
  18636. values[ offset1 + i ] * weight1;
  18637. }
  18638. return result;
  18639. }
  18640. } );
  18641. /**
  18642. *
  18643. * Interpolant that evaluates to the sample value at the position preceeding
  18644. * the parameter.
  18645. *
  18646. * @author tschw
  18647. */
  18648. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18649. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18650. }
  18651. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18652. constructor: DiscreteInterpolant,
  18653. interpolate_: function( i1, t0, t, t1 ) {
  18654. return this.copySampleValue_( i1 - 1 );
  18655. }
  18656. } );
  18657. var KeyframeTrackPrototype;
  18658. KeyframeTrackPrototype = {
  18659. TimeBufferType: Float32Array,
  18660. ValueBufferType: Float32Array,
  18661. DefaultInterpolation: InterpolateLinear,
  18662. InterpolantFactoryMethodDiscrete: function ( result ) {
  18663. return new DiscreteInterpolant(
  18664. this.times, this.values, this.getValueSize(), result );
  18665. },
  18666. InterpolantFactoryMethodLinear: function ( result ) {
  18667. return new LinearInterpolant(
  18668. this.times, this.values, this.getValueSize(), result );
  18669. },
  18670. InterpolantFactoryMethodSmooth: function ( result ) {
  18671. return new CubicInterpolant(
  18672. this.times, this.values, this.getValueSize(), result );
  18673. },
  18674. setInterpolation: function ( interpolation ) {
  18675. var factoryMethod;
  18676. switch ( interpolation ) {
  18677. case InterpolateDiscrete:
  18678. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  18679. break;
  18680. case InterpolateLinear:
  18681. factoryMethod = this.InterpolantFactoryMethodLinear;
  18682. break;
  18683. case InterpolateSmooth:
  18684. factoryMethod = this.InterpolantFactoryMethodSmooth;
  18685. break;
  18686. }
  18687. if ( factoryMethod === undefined ) {
  18688. var message = "unsupported interpolation for " +
  18689. this.ValueTypeName + " keyframe track named " + this.name;
  18690. if ( this.createInterpolant === undefined ) {
  18691. // fall back to default, unless the default itself is messed up
  18692. if ( interpolation !== this.DefaultInterpolation ) {
  18693. this.setInterpolation( this.DefaultInterpolation );
  18694. } else {
  18695. throw new Error( message ); // fatal, in this case
  18696. }
  18697. }
  18698. console.warn( 'THREE.KeyframeTrackPrototype:', message );
  18699. return;
  18700. }
  18701. this.createInterpolant = factoryMethod;
  18702. },
  18703. getInterpolation: function () {
  18704. switch ( this.createInterpolant ) {
  18705. case this.InterpolantFactoryMethodDiscrete:
  18706. return InterpolateDiscrete;
  18707. case this.InterpolantFactoryMethodLinear:
  18708. return InterpolateLinear;
  18709. case this.InterpolantFactoryMethodSmooth:
  18710. return InterpolateSmooth;
  18711. }
  18712. },
  18713. getValueSize: function () {
  18714. return this.values.length / this.times.length;
  18715. },
  18716. // move all keyframes either forwards or backwards in time
  18717. shift: function ( timeOffset ) {
  18718. if ( timeOffset !== 0.0 ) {
  18719. var times = this.times;
  18720. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  18721. times[ i ] += timeOffset;
  18722. }
  18723. }
  18724. return this;
  18725. },
  18726. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  18727. scale: function ( timeScale ) {
  18728. if ( timeScale !== 1.0 ) {
  18729. var times = this.times;
  18730. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  18731. times[ i ] *= timeScale;
  18732. }
  18733. }
  18734. return this;
  18735. },
  18736. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  18737. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  18738. trim: function ( startTime, endTime ) {
  18739. var times = this.times,
  18740. nKeys = times.length,
  18741. from = 0,
  18742. to = nKeys - 1;
  18743. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  18744. while ( to !== - 1 && times[ to ] > endTime ) -- to;
  18745. ++ to; // inclusive -> exclusive bound
  18746. if ( from !== 0 || to !== nKeys ) {
  18747. // empty tracks are forbidden, so keep at least one keyframe
  18748. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  18749. var stride = this.getValueSize();
  18750. this.times = AnimationUtils.arraySlice( times, from, to );
  18751. this.values = AnimationUtils.
  18752. arraySlice( this.values, from * stride, to * stride );
  18753. }
  18754. return this;
  18755. },
  18756. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  18757. validate: function () {
  18758. var valid = true;
  18759. var valueSize = this.getValueSize();
  18760. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  18761. console.error( 'THREE.KeyframeTrackPrototype: Invalid value size in track.', this );
  18762. valid = false;
  18763. }
  18764. var times = this.times,
  18765. values = this.values,
  18766. nKeys = times.length;
  18767. if ( nKeys === 0 ) {
  18768. console.error( 'THREE.KeyframeTrackPrototype: Track is empty.', this );
  18769. valid = false;
  18770. }
  18771. var prevTime = null;
  18772. for ( var i = 0; i !== nKeys; i ++ ) {
  18773. var currTime = times[ i ];
  18774. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  18775. console.error( 'THREE.KeyframeTrackPrototype: Time is not a valid number.', this, i, currTime );
  18776. valid = false;
  18777. break;
  18778. }
  18779. if ( prevTime !== null && prevTime > currTime ) {
  18780. console.error( 'THREE.KeyframeTrackPrototype: Out of order keys.', this, i, currTime, prevTime );
  18781. valid = false;
  18782. break;
  18783. }
  18784. prevTime = currTime;
  18785. }
  18786. if ( values !== undefined ) {
  18787. if ( AnimationUtils.isTypedArray( values ) ) {
  18788. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  18789. var value = values[ i ];
  18790. if ( isNaN( value ) ) {
  18791. console.error( 'THREE.KeyframeTrackPrototype: Value is not a valid number.', this, i, value );
  18792. valid = false;
  18793. break;
  18794. }
  18795. }
  18796. }
  18797. }
  18798. return valid;
  18799. },
  18800. // removes equivalent sequential keys as common in morph target sequences
  18801. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  18802. optimize: function () {
  18803. var times = this.times,
  18804. values = this.values,
  18805. stride = this.getValueSize(),
  18806. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  18807. writeIndex = 1,
  18808. lastIndex = times.length - 1;
  18809. for ( var i = 1; i < lastIndex; ++ i ) {
  18810. var keep = false;
  18811. var time = times[ i ];
  18812. var timeNext = times[ i + 1 ];
  18813. // remove adjacent keyframes scheduled at the same time
  18814. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  18815. if ( ! smoothInterpolation ) {
  18816. // remove unnecessary keyframes same as their neighbors
  18817. var offset = i * stride,
  18818. offsetP = offset - stride,
  18819. offsetN = offset + stride;
  18820. for ( var j = 0; j !== stride; ++ j ) {
  18821. var value = values[ offset + j ];
  18822. if ( value !== values[ offsetP + j ] ||
  18823. value !== values[ offsetN + j ] ) {
  18824. keep = true;
  18825. break;
  18826. }
  18827. }
  18828. } else keep = true;
  18829. }
  18830. // in-place compaction
  18831. if ( keep ) {
  18832. if ( i !== writeIndex ) {
  18833. times[ writeIndex ] = times[ i ];
  18834. var readOffset = i * stride,
  18835. writeOffset = writeIndex * stride;
  18836. for ( var j = 0; j !== stride; ++ j )
  18837. values[ writeOffset + j ] = values[ readOffset + j ];
  18838. }
  18839. ++ writeIndex;
  18840. }
  18841. }
  18842. // flush last keyframe (compaction looks ahead)
  18843. if ( lastIndex > 0 ) {
  18844. times[ writeIndex ] = times[ lastIndex ];
  18845. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j )
  18846. values[ writeOffset + j ] = values[ readOffset + j ];
  18847. ++ writeIndex;
  18848. }
  18849. if ( writeIndex !== times.length ) {
  18850. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  18851. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  18852. }
  18853. return this;
  18854. }
  18855. };
  18856. function KeyframeTrackConstructor( name, times, values, interpolation ) {
  18857. if ( name === undefined ) throw new Error( "track name is undefined" );
  18858. if ( times === undefined || times.length === 0 ) {
  18859. throw new Error( "no keyframes in track named " + name );
  18860. }
  18861. this.name = name;
  18862. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  18863. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  18864. this.setInterpolation( interpolation || this.DefaultInterpolation );
  18865. this.validate();
  18866. this.optimize();
  18867. }
  18868. /**
  18869. *
  18870. * A Track of vectored keyframe values.
  18871. *
  18872. *
  18873. * @author Ben Houston / http://clara.io/
  18874. * @author David Sarno / http://lighthaus.us/
  18875. * @author tschw
  18876. */
  18877. function VectorKeyframeTrack( name, times, values, interpolation ) {
  18878. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18879. }
  18880. VectorKeyframeTrack.prototype =
  18881. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18882. constructor: VectorKeyframeTrack,
  18883. ValueTypeName: 'vector'
  18884. // ValueBufferType is inherited
  18885. // DefaultInterpolation is inherited
  18886. } );
  18887. /**
  18888. * Spherical linear unit quaternion interpolant.
  18889. *
  18890. * @author tschw
  18891. */
  18892. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18893. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18894. }
  18895. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18896. constructor: QuaternionLinearInterpolant,
  18897. interpolate_: function( i1, t0, t, t1 ) {
  18898. var result = this.resultBuffer,
  18899. values = this.sampleValues,
  18900. stride = this.valueSize,
  18901. offset = i1 * stride,
  18902. alpha = ( t - t0 ) / ( t1 - t0 );
  18903. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  18904. Quaternion.slerpFlat( result, 0,
  18905. values, offset - stride, values, offset, alpha );
  18906. }
  18907. return result;
  18908. }
  18909. } );
  18910. /**
  18911. *
  18912. * A Track of quaternion keyframe values.
  18913. *
  18914. * @author Ben Houston / http://clara.io/
  18915. * @author David Sarno / http://lighthaus.us/
  18916. * @author tschw
  18917. */
  18918. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  18919. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18920. }
  18921. QuaternionKeyframeTrack.prototype =
  18922. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18923. constructor: QuaternionKeyframeTrack,
  18924. ValueTypeName: 'quaternion',
  18925. // ValueBufferType is inherited
  18926. DefaultInterpolation: InterpolateLinear,
  18927. InterpolantFactoryMethodLinear: function( result ) {
  18928. return new QuaternionLinearInterpolant(
  18929. this.times, this.values, this.getValueSize(), result );
  18930. },
  18931. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  18932. } );
  18933. /**
  18934. *
  18935. * A Track of numeric keyframe values.
  18936. *
  18937. * @author Ben Houston / http://clara.io/
  18938. * @author David Sarno / http://lighthaus.us/
  18939. * @author tschw
  18940. */
  18941. function NumberKeyframeTrack( name, times, values, interpolation ) {
  18942. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18943. }
  18944. NumberKeyframeTrack.prototype =
  18945. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18946. constructor: NumberKeyframeTrack,
  18947. ValueTypeName: 'number'
  18948. // ValueBufferType is inherited
  18949. // DefaultInterpolation is inherited
  18950. } );
  18951. /**
  18952. *
  18953. * A Track that interpolates Strings
  18954. *
  18955. *
  18956. * @author Ben Houston / http://clara.io/
  18957. * @author David Sarno / http://lighthaus.us/
  18958. * @author tschw
  18959. */
  18960. function StringKeyframeTrack( name, times, values, interpolation ) {
  18961. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18962. }
  18963. StringKeyframeTrack.prototype =
  18964. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18965. constructor: StringKeyframeTrack,
  18966. ValueTypeName: 'string',
  18967. ValueBufferType: Array,
  18968. DefaultInterpolation: InterpolateDiscrete,
  18969. InterpolantFactoryMethodLinear: undefined,
  18970. InterpolantFactoryMethodSmooth: undefined
  18971. } );
  18972. /**
  18973. *
  18974. * A Track of Boolean keyframe values.
  18975. *
  18976. *
  18977. * @author Ben Houston / http://clara.io/
  18978. * @author David Sarno / http://lighthaus.us/
  18979. * @author tschw
  18980. */
  18981. function BooleanKeyframeTrack( name, times, values ) {
  18982. KeyframeTrackConstructor.call( this, name, times, values );
  18983. }
  18984. BooleanKeyframeTrack.prototype =
  18985. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18986. constructor: BooleanKeyframeTrack,
  18987. ValueTypeName: 'bool',
  18988. ValueBufferType: Array,
  18989. DefaultInterpolation: InterpolateDiscrete,
  18990. InterpolantFactoryMethodLinear: undefined,
  18991. InterpolantFactoryMethodSmooth: undefined
  18992. // Note: Actually this track could have a optimized / compressed
  18993. // representation of a single value and a custom interpolant that
  18994. // computes "firstValue ^ isOdd( index )".
  18995. } );
  18996. /**
  18997. *
  18998. * A Track of keyframe values that represent color.
  18999. *
  19000. *
  19001. * @author Ben Houston / http://clara.io/
  19002. * @author David Sarno / http://lighthaus.us/
  19003. * @author tschw
  19004. */
  19005. function ColorKeyframeTrack( name, times, values, interpolation ) {
  19006. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  19007. }
  19008. ColorKeyframeTrack.prototype =
  19009. Object.assign( Object.create( KeyframeTrackPrototype ), {
  19010. constructor: ColorKeyframeTrack,
  19011. ValueTypeName: 'color'
  19012. // ValueBufferType is inherited
  19013. // DefaultInterpolation is inherited
  19014. // Note: Very basic implementation and nothing special yet.
  19015. // However, this is the place for color space parameterization.
  19016. } );
  19017. /**
  19018. *
  19019. * A timed sequence of keyframes for a specific property.
  19020. *
  19021. *
  19022. * @author Ben Houston / http://clara.io/
  19023. * @author David Sarno / http://lighthaus.us/
  19024. * @author tschw
  19025. */
  19026. function KeyframeTrack( name, times, values, interpolation ) {
  19027. KeyframeTrackConstructor.apply( this, arguments );
  19028. }
  19029. KeyframeTrack.prototype = KeyframeTrackPrototype;
  19030. KeyframeTrackPrototype.constructor = KeyframeTrack;
  19031. // Static methods:
  19032. Object.assign( KeyframeTrack, {
  19033. // Serialization (in static context, because of constructor invocation
  19034. // and automatic invocation of .toJSON):
  19035. parse: function( json ) {
  19036. if( json.type === undefined ) {
  19037. throw new Error( "track type undefined, can not parse" );
  19038. }
  19039. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  19040. if ( json.times === undefined ) {
  19041. var times = [], values = [];
  19042. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  19043. json.times = times;
  19044. json.values = values;
  19045. }
  19046. // derived classes can define a static parse method
  19047. if ( trackType.parse !== undefined ) {
  19048. return trackType.parse( json );
  19049. } else {
  19050. // by default, we asssume a constructor compatible with the base
  19051. return new trackType(
  19052. json.name, json.times, json.values, json.interpolation );
  19053. }
  19054. },
  19055. toJSON: function( track ) {
  19056. var trackType = track.constructor;
  19057. var json;
  19058. // derived classes can define a static toJSON method
  19059. if ( trackType.toJSON !== undefined ) {
  19060. json = trackType.toJSON( track );
  19061. } else {
  19062. // by default, we assume the data can be serialized as-is
  19063. json = {
  19064. 'name': track.name,
  19065. 'times': AnimationUtils.convertArray( track.times, Array ),
  19066. 'values': AnimationUtils.convertArray( track.values, Array )
  19067. };
  19068. var interpolation = track.getInterpolation();
  19069. if ( interpolation !== track.DefaultInterpolation ) {
  19070. json.interpolation = interpolation;
  19071. }
  19072. }
  19073. json.type = track.ValueTypeName; // mandatory
  19074. return json;
  19075. },
  19076. _getTrackTypeForValueTypeName: function( typeName ) {
  19077. switch( typeName.toLowerCase() ) {
  19078. case "scalar":
  19079. case "double":
  19080. case "float":
  19081. case "number":
  19082. case "integer":
  19083. return NumberKeyframeTrack;
  19084. case "vector":
  19085. case "vector2":
  19086. case "vector3":
  19087. case "vector4":
  19088. return VectorKeyframeTrack;
  19089. case "color":
  19090. return ColorKeyframeTrack;
  19091. case "quaternion":
  19092. return QuaternionKeyframeTrack;
  19093. case "bool":
  19094. case "boolean":
  19095. return BooleanKeyframeTrack;
  19096. case "string":
  19097. return StringKeyframeTrack;
  19098. }
  19099. throw new Error( "Unsupported typeName: " + typeName );
  19100. }
  19101. } );
  19102. /**
  19103. *
  19104. * Reusable set of Tracks that represent an animation.
  19105. *
  19106. * @author Ben Houston / http://clara.io/
  19107. * @author David Sarno / http://lighthaus.us/
  19108. */
  19109. function AnimationClip( name, duration, tracks ) {
  19110. this.name = name;
  19111. this.tracks = tracks;
  19112. this.duration = ( duration !== undefined ) ? duration : - 1;
  19113. this.uuid = _Math.generateUUID();
  19114. // this means it should figure out its duration by scanning the tracks
  19115. if ( this.duration < 0 ) {
  19116. this.resetDuration();
  19117. }
  19118. this.optimize();
  19119. }
  19120. Object.assign( AnimationClip, {
  19121. parse: function ( json ) {
  19122. var tracks = [],
  19123. jsonTracks = json.tracks,
  19124. frameTime = 1.0 / ( json.fps || 1.0 );
  19125. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  19126. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  19127. }
  19128. return new AnimationClip( json.name, json.duration, tracks );
  19129. },
  19130. toJSON: function ( clip ) {
  19131. var tracks = [],
  19132. clipTracks = clip.tracks;
  19133. var json = {
  19134. 'name': clip.name,
  19135. 'duration': clip.duration,
  19136. 'tracks': tracks
  19137. };
  19138. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  19139. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  19140. }
  19141. return json;
  19142. },
  19143. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  19144. var numMorphTargets = morphTargetSequence.length;
  19145. var tracks = [];
  19146. for ( var i = 0; i < numMorphTargets; i ++ ) {
  19147. var times = [];
  19148. var values = [];
  19149. times.push(
  19150. ( i + numMorphTargets - 1 ) % numMorphTargets,
  19151. i,
  19152. ( i + 1 ) % numMorphTargets );
  19153. values.push( 0, 1, 0 );
  19154. var order = AnimationUtils.getKeyframeOrder( times );
  19155. times = AnimationUtils.sortedArray( times, 1, order );
  19156. values = AnimationUtils.sortedArray( values, 1, order );
  19157. // if there is a key at the first frame, duplicate it as the
  19158. // last frame as well for perfect loop.
  19159. if ( ! noLoop && times[ 0 ] === 0 ) {
  19160. times.push( numMorphTargets );
  19161. values.push( values[ 0 ] );
  19162. }
  19163. tracks.push(
  19164. new NumberKeyframeTrack(
  19165. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  19166. times, values
  19167. ).scale( 1.0 / fps ) );
  19168. }
  19169. return new AnimationClip( name, - 1, tracks );
  19170. },
  19171. findByName: function ( objectOrClipArray, name ) {
  19172. var clipArray = objectOrClipArray;
  19173. if ( ! Array.isArray( objectOrClipArray ) ) {
  19174. var o = objectOrClipArray;
  19175. clipArray = o.geometry && o.geometry.animations || o.animations;
  19176. }
  19177. for ( var i = 0; i < clipArray.length; i ++ ) {
  19178. if ( clipArray[ i ].name === name ) {
  19179. return clipArray[ i ];
  19180. }
  19181. }
  19182. return null;
  19183. },
  19184. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  19185. var animationToMorphTargets = {};
  19186. // tested with https://regex101.com/ on trick sequences
  19187. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  19188. var pattern = /^([\w-]*?)([\d]+)$/;
  19189. // sort morph target names into animation groups based
  19190. // patterns like Walk_001, Walk_002, Run_001, Run_002
  19191. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  19192. var morphTarget = morphTargets[ i ];
  19193. var parts = morphTarget.name.match( pattern );
  19194. if ( parts && parts.length > 1 ) {
  19195. var name = parts[ 1 ];
  19196. var animationMorphTargets = animationToMorphTargets[ name ];
  19197. if ( ! animationMorphTargets ) {
  19198. animationToMorphTargets[ name ] = animationMorphTargets = [];
  19199. }
  19200. animationMorphTargets.push( morphTarget );
  19201. }
  19202. }
  19203. var clips = [];
  19204. for ( var name in animationToMorphTargets ) {
  19205. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  19206. }
  19207. return clips;
  19208. },
  19209. // parse the animation.hierarchy format
  19210. parseAnimation: function ( animation, bones ) {
  19211. if ( ! animation ) {
  19212. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  19213. return null;
  19214. }
  19215. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  19216. // only return track if there are actually keys.
  19217. if ( animationKeys.length !== 0 ) {
  19218. var times = [];
  19219. var values = [];
  19220. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  19221. // empty keys are filtered out, so check again
  19222. if ( times.length !== 0 ) {
  19223. destTracks.push( new trackType( trackName, times, values ) );
  19224. }
  19225. }
  19226. };
  19227. var tracks = [];
  19228. var clipName = animation.name || 'default';
  19229. // automatic length determination in AnimationClip.
  19230. var duration = animation.length || - 1;
  19231. var fps = animation.fps || 30;
  19232. var hierarchyTracks = animation.hierarchy || [];
  19233. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  19234. var animationKeys = hierarchyTracks[ h ].keys;
  19235. // skip empty tracks
  19236. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  19237. // process morph targets
  19238. if ( animationKeys[ 0 ].morphTargets ) {
  19239. // figure out all morph targets used in this track
  19240. var morphTargetNames = {};
  19241. for ( var k = 0; k < animationKeys.length; k ++ ) {
  19242. if ( animationKeys[ k ].morphTargets ) {
  19243. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  19244. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  19245. }
  19246. }
  19247. }
  19248. // create a track for each morph target with all zero
  19249. // morphTargetInfluences except for the keys in which
  19250. // the morphTarget is named.
  19251. for ( var morphTargetName in morphTargetNames ) {
  19252. var times = [];
  19253. var values = [];
  19254. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  19255. var animationKey = animationKeys[ k ];
  19256. times.push( animationKey.time );
  19257. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  19258. }
  19259. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  19260. }
  19261. duration = morphTargetNames.length * ( fps || 1.0 );
  19262. } else {
  19263. // ...assume skeletal animation
  19264. var boneName = '.bones[' + bones[ h ].name + ']';
  19265. addNonemptyTrack(
  19266. VectorKeyframeTrack, boneName + '.position',
  19267. animationKeys, 'pos', tracks );
  19268. addNonemptyTrack(
  19269. QuaternionKeyframeTrack, boneName + '.quaternion',
  19270. animationKeys, 'rot', tracks );
  19271. addNonemptyTrack(
  19272. VectorKeyframeTrack, boneName + '.scale',
  19273. animationKeys, 'scl', tracks );
  19274. }
  19275. }
  19276. if ( tracks.length === 0 ) {
  19277. return null;
  19278. }
  19279. var clip = new AnimationClip( clipName, duration, tracks );
  19280. return clip;
  19281. }
  19282. } );
  19283. Object.assign( AnimationClip.prototype, {
  19284. resetDuration: function () {
  19285. var tracks = this.tracks, duration = 0;
  19286. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  19287. var track = this.tracks[ i ];
  19288. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  19289. }
  19290. this.duration = duration;
  19291. },
  19292. trim: function () {
  19293. for ( var i = 0; i < this.tracks.length; i ++ ) {
  19294. this.tracks[ i ].trim( 0, this.duration );
  19295. }
  19296. return this;
  19297. },
  19298. optimize: function () {
  19299. for ( var i = 0; i < this.tracks.length; i ++ ) {
  19300. this.tracks[ i ].optimize();
  19301. }
  19302. return this;
  19303. }
  19304. } );
  19305. /**
  19306. * @author mrdoob / http://mrdoob.com/
  19307. */
  19308. function MaterialLoader( manager ) {
  19309. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  19310. this.textures = {};
  19311. }
  19312. Object.assign( MaterialLoader.prototype, {
  19313. load: function ( url, onLoad, onProgress, onError ) {
  19314. var scope = this;
  19315. var loader = new FileLoader( scope.manager );
  19316. loader.load( url, function ( text ) {
  19317. onLoad( scope.parse( JSON.parse( text ) ) );
  19318. }, onProgress, onError );
  19319. },
  19320. setTextures: function ( value ) {
  19321. this.textures = value;
  19322. },
  19323. parse: function ( json ) {
  19324. var textures = this.textures;
  19325. function getTexture( name ) {
  19326. if ( textures[ name ] === undefined ) {
  19327. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  19328. }
  19329. return textures[ name ];
  19330. }
  19331. var material = new Materials[ json.type ]();
  19332. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  19333. if ( json.name !== undefined ) material.name = json.name;
  19334. if ( json.color !== undefined ) material.color.setHex( json.color );
  19335. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  19336. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  19337. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  19338. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  19339. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  19340. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  19341. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  19342. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  19343. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  19344. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  19345. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  19346. if ( json.fog !== undefined ) material.fog = json.fog;
  19347. if ( json.shading !== undefined ) material.shading = json.shading;
  19348. if ( json.blending !== undefined ) material.blending = json.blending;
  19349. if ( json.side !== undefined ) material.side = json.side;
  19350. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  19351. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  19352. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  19353. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  19354. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  19355. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  19356. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  19357. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  19358. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  19359. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  19360. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  19361. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  19362. // for PointsMaterial
  19363. if ( json.size !== undefined ) material.size = json.size;
  19364. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  19365. // maps
  19366. if ( json.map !== undefined ) material.map = getTexture( json.map );
  19367. if ( json.alphaMap !== undefined ) {
  19368. material.alphaMap = getTexture( json.alphaMap );
  19369. material.transparent = true;
  19370. }
  19371. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  19372. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  19373. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  19374. if ( json.normalScale !== undefined ) {
  19375. var normalScale = json.normalScale;
  19376. if ( Array.isArray( normalScale ) === false ) {
  19377. // Blender exporter used to export a scalar. See #7459
  19378. normalScale = [ normalScale, normalScale ];
  19379. }
  19380. material.normalScale = new Vector2().fromArray( normalScale );
  19381. }
  19382. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  19383. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  19384. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  19385. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  19386. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  19387. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  19388. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  19389. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  19390. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  19391. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  19392. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  19393. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  19394. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  19395. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  19396. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  19397. return material;
  19398. }
  19399. } );
  19400. /**
  19401. * @author mrdoob / http://mrdoob.com/
  19402. */
  19403. function BufferGeometryLoader( manager ) {
  19404. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  19405. }
  19406. Object.assign( BufferGeometryLoader.prototype, {
  19407. load: function ( url, onLoad, onProgress, onError ) {
  19408. var scope = this;
  19409. var loader = new FileLoader( scope.manager );
  19410. loader.load( url, function ( text ) {
  19411. onLoad( scope.parse( JSON.parse( text ) ) );
  19412. }, onProgress, onError );
  19413. },
  19414. parse: function ( json ) {
  19415. var geometry = new BufferGeometry();
  19416. var index = json.data.index;
  19417. if ( index !== undefined ) {
  19418. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  19419. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  19420. }
  19421. var attributes = json.data.attributes;
  19422. for ( var key in attributes ) {
  19423. var attribute = attributes[ key ];
  19424. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  19425. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  19426. }
  19427. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  19428. if ( groups !== undefined ) {
  19429. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  19430. var group = groups[ i ];
  19431. geometry.addGroup( group.start, group.count, group.materialIndex );
  19432. }
  19433. }
  19434. var boundingSphere = json.data.boundingSphere;
  19435. if ( boundingSphere !== undefined ) {
  19436. var center = new Vector3();
  19437. if ( boundingSphere.center !== undefined ) {
  19438. center.fromArray( boundingSphere.center );
  19439. }
  19440. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  19441. }
  19442. return geometry;
  19443. }
  19444. } );
  19445. var TYPED_ARRAYS = {
  19446. Int8Array: Int8Array,
  19447. Uint8Array: Uint8Array,
  19448. // Workaround for IE11 pre KB2929437. See #11440
  19449. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  19450. Int16Array: Int16Array,
  19451. Uint16Array: Uint16Array,
  19452. Int32Array: Int32Array,
  19453. Uint32Array: Uint32Array,
  19454. Float32Array: Float32Array,
  19455. Float64Array: Float64Array
  19456. };
  19457. /**
  19458. * @author alteredq / http://alteredqualia.com/
  19459. */
  19460. function Loader() {
  19461. this.onLoadStart = function () {};
  19462. this.onLoadProgress = function () {};
  19463. this.onLoadComplete = function () {};
  19464. }
  19465. Loader.Handlers = {
  19466. handlers: [],
  19467. add: function ( regex, loader ) {
  19468. this.handlers.push( regex, loader );
  19469. },
  19470. get: function ( file ) {
  19471. var handlers = this.handlers;
  19472. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  19473. var regex = handlers[ i ];
  19474. var loader = handlers[ i + 1 ];
  19475. if ( regex.test( file ) ) {
  19476. return loader;
  19477. }
  19478. }
  19479. return null;
  19480. }
  19481. };
  19482. Object.assign( Loader.prototype, {
  19483. crossOrigin: undefined,
  19484. extractUrlBase: function ( url ) {
  19485. var parts = url.split( '/' );
  19486. if ( parts.length === 1 ) return './';
  19487. parts.pop();
  19488. return parts.join( '/' ) + '/';
  19489. },
  19490. initMaterials: function ( materials, texturePath, crossOrigin ) {
  19491. var array = [];
  19492. for ( var i = 0; i < materials.length; ++ i ) {
  19493. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  19494. }
  19495. return array;
  19496. },
  19497. createMaterial: ( function () {
  19498. var BlendingMode = {
  19499. NoBlending: NoBlending,
  19500. NormalBlending: NormalBlending,
  19501. AdditiveBlending: AdditiveBlending,
  19502. SubtractiveBlending: SubtractiveBlending,
  19503. MultiplyBlending: MultiplyBlending,
  19504. CustomBlending: CustomBlending
  19505. };
  19506. var color = new Color();
  19507. var textureLoader = new TextureLoader();
  19508. var materialLoader = new MaterialLoader();
  19509. return function createMaterial( m, texturePath, crossOrigin ) {
  19510. // convert from old material format
  19511. var textures = {};
  19512. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  19513. var fullPath = texturePath + path;
  19514. var loader = Loader.Handlers.get( fullPath );
  19515. var texture;
  19516. if ( loader !== null ) {
  19517. texture = loader.load( fullPath );
  19518. } else {
  19519. textureLoader.setCrossOrigin( crossOrigin );
  19520. texture = textureLoader.load( fullPath );
  19521. }
  19522. if ( repeat !== undefined ) {
  19523. texture.repeat.fromArray( repeat );
  19524. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  19525. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  19526. }
  19527. if ( offset !== undefined ) {
  19528. texture.offset.fromArray( offset );
  19529. }
  19530. if ( wrap !== undefined ) {
  19531. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  19532. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  19533. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  19534. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  19535. }
  19536. if ( anisotropy !== undefined ) {
  19537. texture.anisotropy = anisotropy;
  19538. }
  19539. var uuid = _Math.generateUUID();
  19540. textures[ uuid ] = texture;
  19541. return uuid;
  19542. }
  19543. //
  19544. var json = {
  19545. uuid: _Math.generateUUID(),
  19546. type: 'MeshLambertMaterial'
  19547. };
  19548. for ( var name in m ) {
  19549. var value = m[ name ];
  19550. switch ( name ) {
  19551. case 'DbgColor':
  19552. case 'DbgIndex':
  19553. case 'opticalDensity':
  19554. case 'illumination':
  19555. break;
  19556. case 'DbgName':
  19557. json.name = value;
  19558. break;
  19559. case 'blending':
  19560. json.blending = BlendingMode[ value ];
  19561. break;
  19562. case 'colorAmbient':
  19563. case 'mapAmbient':
  19564. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  19565. break;
  19566. case 'colorDiffuse':
  19567. json.color = color.fromArray( value ).getHex();
  19568. break;
  19569. case 'colorSpecular':
  19570. json.specular = color.fromArray( value ).getHex();
  19571. break;
  19572. case 'colorEmissive':
  19573. json.emissive = color.fromArray( value ).getHex();
  19574. break;
  19575. case 'specularCoef':
  19576. json.shininess = value;
  19577. break;
  19578. case 'shading':
  19579. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  19580. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  19581. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  19582. break;
  19583. case 'mapDiffuse':
  19584. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  19585. break;
  19586. case 'mapDiffuseRepeat':
  19587. case 'mapDiffuseOffset':
  19588. case 'mapDiffuseWrap':
  19589. case 'mapDiffuseAnisotropy':
  19590. break;
  19591. case 'mapEmissive':
  19592. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  19593. break;
  19594. case 'mapEmissiveRepeat':
  19595. case 'mapEmissiveOffset':
  19596. case 'mapEmissiveWrap':
  19597. case 'mapEmissiveAnisotropy':
  19598. break;
  19599. case 'mapLight':
  19600. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  19601. break;
  19602. case 'mapLightRepeat':
  19603. case 'mapLightOffset':
  19604. case 'mapLightWrap':
  19605. case 'mapLightAnisotropy':
  19606. break;
  19607. case 'mapAO':
  19608. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  19609. break;
  19610. case 'mapAORepeat':
  19611. case 'mapAOOffset':
  19612. case 'mapAOWrap':
  19613. case 'mapAOAnisotropy':
  19614. break;
  19615. case 'mapBump':
  19616. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  19617. break;
  19618. case 'mapBumpScale':
  19619. json.bumpScale = value;
  19620. break;
  19621. case 'mapBumpRepeat':
  19622. case 'mapBumpOffset':
  19623. case 'mapBumpWrap':
  19624. case 'mapBumpAnisotropy':
  19625. break;
  19626. case 'mapNormal':
  19627. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  19628. break;
  19629. case 'mapNormalFactor':
  19630. json.normalScale = [ value, value ];
  19631. break;
  19632. case 'mapNormalRepeat':
  19633. case 'mapNormalOffset':
  19634. case 'mapNormalWrap':
  19635. case 'mapNormalAnisotropy':
  19636. break;
  19637. case 'mapSpecular':
  19638. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  19639. break;
  19640. case 'mapSpecularRepeat':
  19641. case 'mapSpecularOffset':
  19642. case 'mapSpecularWrap':
  19643. case 'mapSpecularAnisotropy':
  19644. break;
  19645. case 'mapMetalness':
  19646. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  19647. break;
  19648. case 'mapMetalnessRepeat':
  19649. case 'mapMetalnessOffset':
  19650. case 'mapMetalnessWrap':
  19651. case 'mapMetalnessAnisotropy':
  19652. break;
  19653. case 'mapRoughness':
  19654. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  19655. break;
  19656. case 'mapRoughnessRepeat':
  19657. case 'mapRoughnessOffset':
  19658. case 'mapRoughnessWrap':
  19659. case 'mapRoughnessAnisotropy':
  19660. break;
  19661. case 'mapAlpha':
  19662. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  19663. break;
  19664. case 'mapAlphaRepeat':
  19665. case 'mapAlphaOffset':
  19666. case 'mapAlphaWrap':
  19667. case 'mapAlphaAnisotropy':
  19668. break;
  19669. case 'flipSided':
  19670. json.side = BackSide;
  19671. break;
  19672. case 'doubleSided':
  19673. json.side = DoubleSide;
  19674. break;
  19675. case 'transparency':
  19676. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  19677. json.opacity = value;
  19678. break;
  19679. case 'depthTest':
  19680. case 'depthWrite':
  19681. case 'colorWrite':
  19682. case 'opacity':
  19683. case 'reflectivity':
  19684. case 'transparent':
  19685. case 'visible':
  19686. case 'wireframe':
  19687. json[ name ] = value;
  19688. break;
  19689. case 'vertexColors':
  19690. if ( value === true ) json.vertexColors = VertexColors;
  19691. if ( value === 'face' ) json.vertexColors = FaceColors;
  19692. break;
  19693. default:
  19694. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  19695. break;
  19696. }
  19697. }
  19698. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  19699. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  19700. if ( json.opacity < 1 ) json.transparent = true;
  19701. materialLoader.setTextures( textures );
  19702. return materialLoader.parse( json );
  19703. };
  19704. } )()
  19705. } );
  19706. /**
  19707. * @author mrdoob / http://mrdoob.com/
  19708. * @author alteredq / http://alteredqualia.com/
  19709. */
  19710. function JSONLoader( manager ) {
  19711. if ( typeof manager === 'boolean' ) {
  19712. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  19713. manager = undefined;
  19714. }
  19715. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  19716. this.withCredentials = false;
  19717. }
  19718. Object.assign( JSONLoader.prototype, {
  19719. load: function ( url, onLoad, onProgress, onError ) {
  19720. var scope = this;
  19721. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : Loader.prototype.extractUrlBase( url );
  19722. var loader = new FileLoader( this.manager );
  19723. loader.setWithCredentials( this.withCredentials );
  19724. loader.load( url, function ( text ) {
  19725. var json = JSON.parse( text );
  19726. var metadata = json.metadata;
  19727. if ( metadata !== undefined ) {
  19728. var type = metadata.type;
  19729. if ( type !== undefined ) {
  19730. if ( type.toLowerCase() === 'object' ) {
  19731. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  19732. return;
  19733. }
  19734. if ( type.toLowerCase() === 'scene' ) {
  19735. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  19736. return;
  19737. }
  19738. }
  19739. }
  19740. var object = scope.parse( json, texturePath );
  19741. onLoad( object.geometry, object.materials );
  19742. }, onProgress, onError );
  19743. },
  19744. setTexturePath: function ( value ) {
  19745. this.texturePath = value;
  19746. },
  19747. parse: ( function () {
  19748. function parseModel( json, geometry ) {
  19749. function isBitSet( value, position ) {
  19750. return value & ( 1 << position );
  19751. }
  19752. var i, j, fi,
  19753. offset, zLength,
  19754. colorIndex, normalIndex, uvIndex, materialIndex,
  19755. type,
  19756. isQuad,
  19757. hasMaterial,
  19758. hasFaceVertexUv,
  19759. hasFaceNormal, hasFaceVertexNormal,
  19760. hasFaceColor, hasFaceVertexColor,
  19761. vertex, face, faceA, faceB, hex, normal,
  19762. uvLayer, uv, u, v,
  19763. faces = json.faces,
  19764. vertices = json.vertices,
  19765. normals = json.normals,
  19766. colors = json.colors,
  19767. scale = json.scale,
  19768. nUvLayers = 0;
  19769. if ( json.uvs !== undefined ) {
  19770. // disregard empty arrays
  19771. for ( i = 0; i < json.uvs.length; i ++ ) {
  19772. if ( json.uvs[ i ].length ) nUvLayers ++;
  19773. }
  19774. for ( i = 0; i < nUvLayers; i ++ ) {
  19775. geometry.faceVertexUvs[ i ] = [];
  19776. }
  19777. }
  19778. offset = 0;
  19779. zLength = vertices.length;
  19780. while ( offset < zLength ) {
  19781. vertex = new Vector3();
  19782. vertex.x = vertices[ offset ++ ] * scale;
  19783. vertex.y = vertices[ offset ++ ] * scale;
  19784. vertex.z = vertices[ offset ++ ] * scale;
  19785. geometry.vertices.push( vertex );
  19786. }
  19787. offset = 0;
  19788. zLength = faces.length;
  19789. while ( offset < zLength ) {
  19790. type = faces[ offset ++ ];
  19791. isQuad = isBitSet( type, 0 );
  19792. hasMaterial = isBitSet( type, 1 );
  19793. hasFaceVertexUv = isBitSet( type, 3 );
  19794. hasFaceNormal = isBitSet( type, 4 );
  19795. hasFaceVertexNormal = isBitSet( type, 5 );
  19796. hasFaceColor = isBitSet( type, 6 );
  19797. hasFaceVertexColor = isBitSet( type, 7 );
  19798. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  19799. if ( isQuad ) {
  19800. faceA = new Face3();
  19801. faceA.a = faces[ offset ];
  19802. faceA.b = faces[ offset + 1 ];
  19803. faceA.c = faces[ offset + 3 ];
  19804. faceB = new Face3();
  19805. faceB.a = faces[ offset + 1 ];
  19806. faceB.b = faces[ offset + 2 ];
  19807. faceB.c = faces[ offset + 3 ];
  19808. offset += 4;
  19809. if ( hasMaterial ) {
  19810. materialIndex = faces[ offset ++ ];
  19811. faceA.materialIndex = materialIndex;
  19812. faceB.materialIndex = materialIndex;
  19813. }
  19814. // to get face <=> uv index correspondence
  19815. fi = geometry.faces.length;
  19816. if ( hasFaceVertexUv ) {
  19817. for ( i = 0; i < nUvLayers; i ++ ) {
  19818. uvLayer = json.uvs[ i ];
  19819. geometry.faceVertexUvs[ i ][ fi ] = [];
  19820. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  19821. for ( j = 0; j < 4; j ++ ) {
  19822. uvIndex = faces[ offset ++ ];
  19823. u = uvLayer[ uvIndex * 2 ];
  19824. v = uvLayer[ uvIndex * 2 + 1 ];
  19825. uv = new Vector2( u, v );
  19826. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  19827. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  19828. }
  19829. }
  19830. }
  19831. if ( hasFaceNormal ) {
  19832. normalIndex = faces[ offset ++ ] * 3;
  19833. faceA.normal.set(
  19834. normals[ normalIndex ++ ],
  19835. normals[ normalIndex ++ ],
  19836. normals[ normalIndex ]
  19837. );
  19838. faceB.normal.copy( faceA.normal );
  19839. }
  19840. if ( hasFaceVertexNormal ) {
  19841. for ( i = 0; i < 4; i ++ ) {
  19842. normalIndex = faces[ offset ++ ] * 3;
  19843. normal = new Vector3(
  19844. normals[ normalIndex ++ ],
  19845. normals[ normalIndex ++ ],
  19846. normals[ normalIndex ]
  19847. );
  19848. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  19849. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  19850. }
  19851. }
  19852. if ( hasFaceColor ) {
  19853. colorIndex = faces[ offset ++ ];
  19854. hex = colors[ colorIndex ];
  19855. faceA.color.setHex( hex );
  19856. faceB.color.setHex( hex );
  19857. }
  19858. if ( hasFaceVertexColor ) {
  19859. for ( i = 0; i < 4; i ++ ) {
  19860. colorIndex = faces[ offset ++ ];
  19861. hex = colors[ colorIndex ];
  19862. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  19863. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  19864. }
  19865. }
  19866. geometry.faces.push( faceA );
  19867. geometry.faces.push( faceB );
  19868. } else {
  19869. face = new Face3();
  19870. face.a = faces[ offset ++ ];
  19871. face.b = faces[ offset ++ ];
  19872. face.c = faces[ offset ++ ];
  19873. if ( hasMaterial ) {
  19874. materialIndex = faces[ offset ++ ];
  19875. face.materialIndex = materialIndex;
  19876. }
  19877. // to get face <=> uv index correspondence
  19878. fi = geometry.faces.length;
  19879. if ( hasFaceVertexUv ) {
  19880. for ( i = 0; i < nUvLayers; i ++ ) {
  19881. uvLayer = json.uvs[ i ];
  19882. geometry.faceVertexUvs[ i ][ fi ] = [];
  19883. for ( j = 0; j < 3; j ++ ) {
  19884. uvIndex = faces[ offset ++ ];
  19885. u = uvLayer[ uvIndex * 2 ];
  19886. v = uvLayer[ uvIndex * 2 + 1 ];
  19887. uv = new Vector2( u, v );
  19888. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  19889. }
  19890. }
  19891. }
  19892. if ( hasFaceNormal ) {
  19893. normalIndex = faces[ offset ++ ] * 3;
  19894. face.normal.set(
  19895. normals[ normalIndex ++ ],
  19896. normals[ normalIndex ++ ],
  19897. normals[ normalIndex ]
  19898. );
  19899. }
  19900. if ( hasFaceVertexNormal ) {
  19901. for ( i = 0; i < 3; i ++ ) {
  19902. normalIndex = faces[ offset ++ ] * 3;
  19903. normal = new Vector3(
  19904. normals[ normalIndex ++ ],
  19905. normals[ normalIndex ++ ],
  19906. normals[ normalIndex ]
  19907. );
  19908. face.vertexNormals.push( normal );
  19909. }
  19910. }
  19911. if ( hasFaceColor ) {
  19912. colorIndex = faces[ offset ++ ];
  19913. face.color.setHex( colors[ colorIndex ] );
  19914. }
  19915. if ( hasFaceVertexColor ) {
  19916. for ( i = 0; i < 3; i ++ ) {
  19917. colorIndex = faces[ offset ++ ];
  19918. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  19919. }
  19920. }
  19921. geometry.faces.push( face );
  19922. }
  19923. }
  19924. }
  19925. function parseSkin( json, geometry ) {
  19926. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  19927. if ( json.skinWeights ) {
  19928. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  19929. var x = json.skinWeights[ i ];
  19930. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  19931. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  19932. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  19933. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  19934. }
  19935. }
  19936. if ( json.skinIndices ) {
  19937. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  19938. var a = json.skinIndices[ i ];
  19939. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  19940. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  19941. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  19942. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  19943. }
  19944. }
  19945. geometry.bones = json.bones;
  19946. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  19947. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  19948. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  19949. }
  19950. }
  19951. function parseMorphing( json, geometry ) {
  19952. var scale = json.scale;
  19953. if ( json.morphTargets !== undefined ) {
  19954. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  19955. geometry.morphTargets[ i ] = {};
  19956. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  19957. geometry.morphTargets[ i ].vertices = [];
  19958. var dstVertices = geometry.morphTargets[ i ].vertices;
  19959. var srcVertices = json.morphTargets[ i ].vertices;
  19960. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  19961. var vertex = new Vector3();
  19962. vertex.x = srcVertices[ v ] * scale;
  19963. vertex.y = srcVertices[ v + 1 ] * scale;
  19964. vertex.z = srcVertices[ v + 2 ] * scale;
  19965. dstVertices.push( vertex );
  19966. }
  19967. }
  19968. }
  19969. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  19970. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  19971. var faces = geometry.faces;
  19972. var morphColors = json.morphColors[ 0 ].colors;
  19973. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19974. faces[ i ].color.fromArray( morphColors, i * 3 );
  19975. }
  19976. }
  19977. }
  19978. function parseAnimations( json, geometry ) {
  19979. var outputAnimations = [];
  19980. // parse old style Bone/Hierarchy animations
  19981. var animations = [];
  19982. if ( json.animation !== undefined ) {
  19983. animations.push( json.animation );
  19984. }
  19985. if ( json.animations !== undefined ) {
  19986. if ( json.animations.length ) {
  19987. animations = animations.concat( json.animations );
  19988. } else {
  19989. animations.push( json.animations );
  19990. }
  19991. }
  19992. for ( var i = 0; i < animations.length; i ++ ) {
  19993. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  19994. if ( clip ) outputAnimations.push( clip );
  19995. }
  19996. // parse implicit morph animations
  19997. if ( geometry.morphTargets ) {
  19998. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  19999. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  20000. outputAnimations = outputAnimations.concat( morphAnimationClips );
  20001. }
  20002. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  20003. }
  20004. return function ( json, texturePath ) {
  20005. if ( json.data !== undefined ) {
  20006. // Geometry 4.0 spec
  20007. json = json.data;
  20008. }
  20009. if ( json.scale !== undefined ) {
  20010. json.scale = 1.0 / json.scale;
  20011. } else {
  20012. json.scale = 1.0;
  20013. }
  20014. var geometry = new Geometry();
  20015. parseModel( json, geometry );
  20016. parseSkin( json, geometry );
  20017. parseMorphing( json, geometry );
  20018. parseAnimations( json, geometry );
  20019. geometry.computeFaceNormals();
  20020. geometry.computeBoundingSphere();
  20021. if ( json.materials === undefined || json.materials.length === 0 ) {
  20022. return { geometry: geometry };
  20023. } else {
  20024. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  20025. return { geometry: geometry, materials: materials };
  20026. }
  20027. };
  20028. } )()
  20029. } );
  20030. /**
  20031. * @author mrdoob / http://mrdoob.com/
  20032. */
  20033. function ObjectLoader( manager ) {
  20034. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20035. this.texturePath = '';
  20036. }
  20037. Object.assign( ObjectLoader.prototype, {
  20038. load: function ( url, onLoad, onProgress, onError ) {
  20039. if ( this.texturePath === '' ) {
  20040. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  20041. }
  20042. var scope = this;
  20043. var loader = new FileLoader( scope.manager );
  20044. loader.load( url, function ( text ) {
  20045. var json = null;
  20046. try {
  20047. json = JSON.parse( text );
  20048. } catch ( error ) {
  20049. if ( onError !== undefined ) onError( error );
  20050. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  20051. return;
  20052. }
  20053. var metadata = json.metadata;
  20054. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  20055. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  20056. return;
  20057. }
  20058. scope.parse( json, onLoad );
  20059. }, onProgress, onError );
  20060. },
  20061. setTexturePath: function ( value ) {
  20062. this.texturePath = value;
  20063. },
  20064. setCrossOrigin: function ( value ) {
  20065. this.crossOrigin = value;
  20066. },
  20067. parse: function ( json, onLoad ) {
  20068. var geometries = this.parseGeometries( json.geometries );
  20069. var images = this.parseImages( json.images, function () {
  20070. if ( onLoad !== undefined ) onLoad( object );
  20071. } );
  20072. var textures = this.parseTextures( json.textures, images );
  20073. var materials = this.parseMaterials( json.materials, textures );
  20074. var object = this.parseObject( json.object, geometries, materials );
  20075. if ( json.animations ) {
  20076. object.animations = this.parseAnimations( json.animations );
  20077. }
  20078. if ( json.images === undefined || json.images.length === 0 ) {
  20079. if ( onLoad !== undefined ) onLoad( object );
  20080. }
  20081. return object;
  20082. },
  20083. parseGeometries: function ( json ) {
  20084. var geometries = {};
  20085. if ( json !== undefined ) {
  20086. var geometryLoader = new JSONLoader();
  20087. var bufferGeometryLoader = new BufferGeometryLoader();
  20088. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20089. var geometry;
  20090. var data = json[ i ];
  20091. switch ( data.type ) {
  20092. case 'PlaneGeometry':
  20093. case 'PlaneBufferGeometry':
  20094. geometry = new Geometries[ data.type ](
  20095. data.width,
  20096. data.height,
  20097. data.widthSegments,
  20098. data.heightSegments
  20099. );
  20100. break;
  20101. case 'BoxGeometry':
  20102. case 'BoxBufferGeometry':
  20103. case 'CubeGeometry': // backwards compatible
  20104. geometry = new Geometries[ data.type ](
  20105. data.width,
  20106. data.height,
  20107. data.depth,
  20108. data.widthSegments,
  20109. data.heightSegments,
  20110. data.depthSegments
  20111. );
  20112. break;
  20113. case 'CircleGeometry':
  20114. case 'CircleBufferGeometry':
  20115. geometry = new Geometries[ data.type ](
  20116. data.radius,
  20117. data.segments,
  20118. data.thetaStart,
  20119. data.thetaLength
  20120. );
  20121. break;
  20122. case 'CylinderGeometry':
  20123. case 'CylinderBufferGeometry':
  20124. geometry = new Geometries[ data.type ](
  20125. data.radiusTop,
  20126. data.radiusBottom,
  20127. data.height,
  20128. data.radialSegments,
  20129. data.heightSegments,
  20130. data.openEnded,
  20131. data.thetaStart,
  20132. data.thetaLength
  20133. );
  20134. break;
  20135. case 'ConeGeometry':
  20136. case 'ConeBufferGeometry':
  20137. geometry = new Geometries[ data.type ](
  20138. data.radius,
  20139. data.height,
  20140. data.radialSegments,
  20141. data.heightSegments,
  20142. data.openEnded,
  20143. data.thetaStart,
  20144. data.thetaLength
  20145. );
  20146. break;
  20147. case 'SphereGeometry':
  20148. case 'SphereBufferGeometry':
  20149. geometry = new Geometries[ data.type ](
  20150. data.radius,
  20151. data.widthSegments,
  20152. data.heightSegments,
  20153. data.phiStart,
  20154. data.phiLength,
  20155. data.thetaStart,
  20156. data.thetaLength
  20157. );
  20158. break;
  20159. case 'DodecahedronGeometry':
  20160. case 'IcosahedronGeometry':
  20161. case 'OctahedronGeometry':
  20162. case 'TetrahedronGeometry':
  20163. geometry = new Geometries[ data.type ](
  20164. data.radius,
  20165. data.detail
  20166. );
  20167. break;
  20168. case 'RingGeometry':
  20169. case 'RingBufferGeometry':
  20170. geometry = new Geometries[ data.type ](
  20171. data.innerRadius,
  20172. data.outerRadius,
  20173. data.thetaSegments,
  20174. data.phiSegments,
  20175. data.thetaStart,
  20176. data.thetaLength
  20177. );
  20178. break;
  20179. case 'TorusGeometry':
  20180. case 'TorusBufferGeometry':
  20181. geometry = new Geometries[ data.type ](
  20182. data.radius,
  20183. data.tube,
  20184. data.radialSegments,
  20185. data.tubularSegments,
  20186. data.arc
  20187. );
  20188. break;
  20189. case 'TorusKnotGeometry':
  20190. case 'TorusKnotBufferGeometry':
  20191. geometry = new Geometries[ data.type ](
  20192. data.radius,
  20193. data.tube,
  20194. data.tubularSegments,
  20195. data.radialSegments,
  20196. data.p,
  20197. data.q
  20198. );
  20199. break;
  20200. case 'LatheGeometry':
  20201. case 'LatheBufferGeometry':
  20202. geometry = new Geometries[ data.type ](
  20203. data.points,
  20204. data.segments,
  20205. data.phiStart,
  20206. data.phiLength
  20207. );
  20208. break;
  20209. case 'BufferGeometry':
  20210. geometry = bufferGeometryLoader.parse( data );
  20211. break;
  20212. case 'Geometry':
  20213. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  20214. break;
  20215. default:
  20216. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  20217. continue;
  20218. }
  20219. geometry.uuid = data.uuid;
  20220. if ( data.name !== undefined ) geometry.name = data.name;
  20221. geometries[ data.uuid ] = geometry;
  20222. }
  20223. }
  20224. return geometries;
  20225. },
  20226. parseMaterials: function ( json, textures ) {
  20227. var materials = {};
  20228. if ( json !== undefined ) {
  20229. var loader = new MaterialLoader();
  20230. loader.setTextures( textures );
  20231. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20232. var data = json[ i ];
  20233. if ( data.type === 'MultiMaterial' ) {
  20234. // Deprecated
  20235. var array = [];
  20236. for ( var j = 0; j < data.materials.length; j ++ ) {
  20237. array.push( loader.parse( data.materials[ j ] ) );
  20238. }
  20239. materials[ data.uuid ] = array;
  20240. } else {
  20241. materials[ data.uuid ] = loader.parse( data );
  20242. }
  20243. }
  20244. }
  20245. return materials;
  20246. },
  20247. parseAnimations: function ( json ) {
  20248. var animations = [];
  20249. for ( var i = 0; i < json.length; i ++ ) {
  20250. var clip = AnimationClip.parse( json[ i ] );
  20251. animations.push( clip );
  20252. }
  20253. return animations;
  20254. },
  20255. parseImages: function ( json, onLoad ) {
  20256. var scope = this;
  20257. var images = {};
  20258. function loadImage( url ) {
  20259. scope.manager.itemStart( url );
  20260. return loader.load( url, function () {
  20261. scope.manager.itemEnd( url );
  20262. }, undefined, function () {
  20263. scope.manager.itemEnd( url );
  20264. scope.manager.itemError( url );
  20265. } );
  20266. }
  20267. if ( json !== undefined && json.length > 0 ) {
  20268. var manager = new LoadingManager( onLoad );
  20269. var loader = new ImageLoader( manager );
  20270. loader.setCrossOrigin( this.crossOrigin );
  20271. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20272. var image = json[ i ];
  20273. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  20274. images[ image.uuid ] = loadImage( path );
  20275. }
  20276. }
  20277. return images;
  20278. },
  20279. parseTextures: function ( json, images ) {
  20280. function parseConstant( value, type ) {
  20281. if ( typeof( value ) === 'number' ) return value;
  20282. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  20283. return type[ value ];
  20284. }
  20285. var textures = {};
  20286. if ( json !== undefined ) {
  20287. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20288. var data = json[ i ];
  20289. if ( data.image === undefined ) {
  20290. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  20291. }
  20292. if ( images[ data.image ] === undefined ) {
  20293. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  20294. }
  20295. var texture = new Texture( images[ data.image ] );
  20296. texture.needsUpdate = true;
  20297. texture.uuid = data.uuid;
  20298. if ( data.name !== undefined ) texture.name = data.name;
  20299. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  20300. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  20301. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  20302. if ( data.wrap !== undefined ) {
  20303. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  20304. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  20305. }
  20306. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  20307. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  20308. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  20309. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  20310. textures[ data.uuid ] = texture;
  20311. }
  20312. }
  20313. return textures;
  20314. },
  20315. parseObject: function () {
  20316. var matrix = new Matrix4();
  20317. return function parseObject( data, geometries, materials ) {
  20318. var object;
  20319. function getGeometry( name ) {
  20320. if ( geometries[ name ] === undefined ) {
  20321. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  20322. }
  20323. return geometries[ name ];
  20324. }
  20325. function getMaterial( name ) {
  20326. if ( name === undefined ) return undefined;
  20327. if ( Array.isArray( name ) ) {
  20328. var array = [];
  20329. for ( var i = 0, l = name.length; i < l; i ++ ) {
  20330. var uuid = name[ i ];
  20331. if ( materials[ uuid ] === undefined ) {
  20332. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  20333. }
  20334. array.push( materials[ uuid ] );
  20335. }
  20336. return array;
  20337. }
  20338. if ( materials[ name ] === undefined ) {
  20339. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  20340. }
  20341. return materials[ name ];
  20342. }
  20343. switch ( data.type ) {
  20344. case 'Scene':
  20345. object = new Scene();
  20346. if ( data.background !== undefined ) {
  20347. if ( Number.isInteger( data.background ) ) {
  20348. object.background = new Color( data.background );
  20349. }
  20350. }
  20351. if ( data.fog !== undefined ) {
  20352. if ( data.fog.type === 'Fog' ) {
  20353. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  20354. } else if ( data.fog.type === 'FogExp2' ) {
  20355. object.fog = new FogExp2( data.fog.color, data.fog.density );
  20356. }
  20357. }
  20358. break;
  20359. case 'PerspectiveCamera':
  20360. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  20361. if ( data.focus !== undefined ) object.focus = data.focus;
  20362. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  20363. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  20364. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  20365. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  20366. break;
  20367. case 'OrthographicCamera':
  20368. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  20369. break;
  20370. case 'AmbientLight':
  20371. object = new AmbientLight( data.color, data.intensity );
  20372. break;
  20373. case 'DirectionalLight':
  20374. object = new DirectionalLight( data.color, data.intensity );
  20375. break;
  20376. case 'PointLight':
  20377. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  20378. break;
  20379. case 'RectAreaLight':
  20380. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  20381. break;
  20382. case 'SpotLight':
  20383. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  20384. break;
  20385. case 'HemisphereLight':
  20386. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  20387. break;
  20388. case 'SkinnedMesh':
  20389. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  20390. case 'Mesh':
  20391. var geometry = getGeometry( data.geometry );
  20392. var material = getMaterial( data.material );
  20393. if ( geometry.bones && geometry.bones.length > 0 ) {
  20394. object = new SkinnedMesh( geometry, material );
  20395. } else {
  20396. object = new Mesh( geometry, material );
  20397. }
  20398. break;
  20399. case 'LOD':
  20400. object = new LOD();
  20401. break;
  20402. case 'Line':
  20403. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  20404. break;
  20405. case 'LineLoop':
  20406. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  20407. break;
  20408. case 'LineSegments':
  20409. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  20410. break;
  20411. case 'PointCloud':
  20412. case 'Points':
  20413. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  20414. break;
  20415. case 'Sprite':
  20416. object = new Sprite( getMaterial( data.material ) );
  20417. break;
  20418. case 'Group':
  20419. object = new Group();
  20420. break;
  20421. default:
  20422. object = new Object3D();
  20423. }
  20424. object.uuid = data.uuid;
  20425. if ( data.name !== undefined ) object.name = data.name;
  20426. if ( data.matrix !== undefined ) {
  20427. matrix.fromArray( data.matrix );
  20428. matrix.decompose( object.position, object.quaternion, object.scale );
  20429. } else {
  20430. if ( data.position !== undefined ) object.position.fromArray( data.position );
  20431. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  20432. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  20433. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  20434. }
  20435. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  20436. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  20437. if ( data.shadow ) {
  20438. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  20439. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  20440. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  20441. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  20442. }
  20443. if ( data.visible !== undefined ) object.visible = data.visible;
  20444. if ( data.userData !== undefined ) object.userData = data.userData;
  20445. if ( data.children !== undefined ) {
  20446. for ( var child in data.children ) {
  20447. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  20448. }
  20449. }
  20450. if ( data.type === 'LOD' ) {
  20451. var levels = data.levels;
  20452. for ( var l = 0; l < levels.length; l ++ ) {
  20453. var level = levels[ l ];
  20454. var child = object.getObjectByProperty( 'uuid', level.object );
  20455. if ( child !== undefined ) {
  20456. object.addLevel( child, level.distance );
  20457. }
  20458. }
  20459. }
  20460. return object;
  20461. };
  20462. }()
  20463. } );
  20464. var TEXTURE_MAPPING = {
  20465. UVMapping: UVMapping,
  20466. CubeReflectionMapping: CubeReflectionMapping,
  20467. CubeRefractionMapping: CubeRefractionMapping,
  20468. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  20469. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  20470. SphericalReflectionMapping: SphericalReflectionMapping,
  20471. CubeUVReflectionMapping: CubeUVReflectionMapping,
  20472. CubeUVRefractionMapping: CubeUVRefractionMapping
  20473. };
  20474. var TEXTURE_WRAPPING = {
  20475. RepeatWrapping: RepeatWrapping,
  20476. ClampToEdgeWrapping: ClampToEdgeWrapping,
  20477. MirroredRepeatWrapping: MirroredRepeatWrapping
  20478. };
  20479. var TEXTURE_FILTER = {
  20480. NearestFilter: NearestFilter,
  20481. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  20482. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  20483. LinearFilter: LinearFilter,
  20484. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  20485. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  20486. };
  20487. /**
  20488. * @author zz85 / http://www.lab4games.net/zz85/blog
  20489. *
  20490. * Bezier Curves formulas obtained from
  20491. * http://en.wikipedia.org/wiki/Bézier_curve
  20492. */
  20493. function CatmullRom( t, p0, p1, p2, p3 ) {
  20494. var v0 = ( p2 - p0 ) * 0.5;
  20495. var v1 = ( p3 - p1 ) * 0.5;
  20496. var t2 = t * t;
  20497. var t3 = t * t2;
  20498. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  20499. }
  20500. //
  20501. function QuadraticBezierP0( t, p ) {
  20502. var k = 1 - t;
  20503. return k * k * p;
  20504. }
  20505. function QuadraticBezierP1( t, p ) {
  20506. return 2 * ( 1 - t ) * t * p;
  20507. }
  20508. function QuadraticBezierP2( t, p ) {
  20509. return t * t * p;
  20510. }
  20511. function QuadraticBezier( t, p0, p1, p2 ) {
  20512. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  20513. QuadraticBezierP2( t, p2 );
  20514. }
  20515. //
  20516. function CubicBezierP0( t, p ) {
  20517. var k = 1 - t;
  20518. return k * k * k * p;
  20519. }
  20520. function CubicBezierP1( t, p ) {
  20521. var k = 1 - t;
  20522. return 3 * k * k * t * p;
  20523. }
  20524. function CubicBezierP2( t, p ) {
  20525. return 3 * ( 1 - t ) * t * t * p;
  20526. }
  20527. function CubicBezierP3( t, p ) {
  20528. return t * t * t * p;
  20529. }
  20530. function CubicBezier( t, p0, p1, p2, p3 ) {
  20531. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  20532. CubicBezierP3( t, p3 );
  20533. }
  20534. /**
  20535. * @author zz85 / http://www.lab4games.net/zz85/blog
  20536. * Extensible curve object
  20537. *
  20538. * Some common of curve methods:
  20539. * .getPoint(t), getTangent(t)
  20540. * .getPointAt(u), getTangentAt(u)
  20541. * .getPoints(), .getSpacedPoints()
  20542. * .getLength()
  20543. * .updateArcLengths()
  20544. *
  20545. * This following curves inherit from THREE.Curve:
  20546. *
  20547. * -- 2D curves --
  20548. * THREE.ArcCurve
  20549. * THREE.CubicBezierCurve
  20550. * THREE.EllipseCurve
  20551. * THREE.LineCurve
  20552. * THREE.QuadraticBezierCurve
  20553. * THREE.SplineCurve
  20554. *
  20555. * -- 3D curves --
  20556. * THREE.CatmullRomCurve3
  20557. * THREE.CubicBezierCurve3
  20558. * THREE.LineCurve3
  20559. * THREE.QuadraticBezierCurve3
  20560. *
  20561. * A series of curves can be represented as a THREE.CurvePath.
  20562. *
  20563. **/
  20564. /**************************************************************
  20565. * Abstract Curve base class
  20566. **************************************************************/
  20567. function Curve() {
  20568. this.arcLengthDivisions = 200;
  20569. }
  20570. Object.assign( Curve.prototype, {
  20571. // Virtual base class method to overwrite and implement in subclasses
  20572. // - t [0 .. 1]
  20573. getPoint: function () {
  20574. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  20575. return null;
  20576. },
  20577. // Get point at relative position in curve according to arc length
  20578. // - u [0 .. 1]
  20579. getPointAt: function ( u ) {
  20580. var t = this.getUtoTmapping( u );
  20581. return this.getPoint( t );
  20582. },
  20583. // Get sequence of points using getPoint( t )
  20584. getPoints: function ( divisions ) {
  20585. if ( divisions === undefined ) divisions = 5;
  20586. var points = [];
  20587. for ( var d = 0; d <= divisions; d ++ ) {
  20588. points.push( this.getPoint( d / divisions ) );
  20589. }
  20590. return points;
  20591. },
  20592. // Get sequence of points using getPointAt( u )
  20593. getSpacedPoints: function ( divisions ) {
  20594. if ( divisions === undefined ) divisions = 5;
  20595. var points = [];
  20596. for ( var d = 0; d <= divisions; d ++ ) {
  20597. points.push( this.getPointAt( d / divisions ) );
  20598. }
  20599. return points;
  20600. },
  20601. // Get total curve arc length
  20602. getLength: function () {
  20603. var lengths = this.getLengths();
  20604. return lengths[ lengths.length - 1 ];
  20605. },
  20606. // Get list of cumulative segment lengths
  20607. getLengths: function ( divisions ) {
  20608. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  20609. if ( this.cacheArcLengths &&
  20610. ( this.cacheArcLengths.length === divisions + 1 ) &&
  20611. ! this.needsUpdate ) {
  20612. return this.cacheArcLengths;
  20613. }
  20614. this.needsUpdate = false;
  20615. var cache = [];
  20616. var current, last = this.getPoint( 0 );
  20617. var p, sum = 0;
  20618. cache.push( 0 );
  20619. for ( p = 1; p <= divisions; p ++ ) {
  20620. current = this.getPoint( p / divisions );
  20621. sum += current.distanceTo( last );
  20622. cache.push( sum );
  20623. last = current;
  20624. }
  20625. this.cacheArcLengths = cache;
  20626. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  20627. },
  20628. updateArcLengths: function () {
  20629. this.needsUpdate = true;
  20630. this.getLengths();
  20631. },
  20632. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20633. getUtoTmapping: function ( u, distance ) {
  20634. var arcLengths = this.getLengths();
  20635. var i = 0, il = arcLengths.length;
  20636. var targetArcLength; // The targeted u distance value to get
  20637. if ( distance ) {
  20638. targetArcLength = distance;
  20639. } else {
  20640. targetArcLength = u * arcLengths[ il - 1 ];
  20641. }
  20642. // binary search for the index with largest value smaller than target u distance
  20643. var low = 0, high = il - 1, comparison;
  20644. while ( low <= high ) {
  20645. 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
  20646. comparison = arcLengths[ i ] - targetArcLength;
  20647. if ( comparison < 0 ) {
  20648. low = i + 1;
  20649. } else if ( comparison > 0 ) {
  20650. high = i - 1;
  20651. } else {
  20652. high = i;
  20653. break;
  20654. // DONE
  20655. }
  20656. }
  20657. i = high;
  20658. if ( arcLengths[ i ] === targetArcLength ) {
  20659. return i / ( il - 1 );
  20660. }
  20661. // we could get finer grain at lengths, or use simple interpolation between two points
  20662. var lengthBefore = arcLengths[ i ];
  20663. var lengthAfter = arcLengths[ i + 1 ];
  20664. var segmentLength = lengthAfter - lengthBefore;
  20665. // determine where we are between the 'before' and 'after' points
  20666. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20667. // add that fractional amount to t
  20668. var t = ( i + segmentFraction ) / ( il - 1 );
  20669. return t;
  20670. },
  20671. // Returns a unit vector tangent at t
  20672. // In case any sub curve does not implement its tangent derivation,
  20673. // 2 points a small delta apart will be used to find its gradient
  20674. // which seems to give a reasonable approximation
  20675. getTangent: function ( t ) {
  20676. var delta = 0.0001;
  20677. var t1 = t - delta;
  20678. var t2 = t + delta;
  20679. // Capping in case of danger
  20680. if ( t1 < 0 ) t1 = 0;
  20681. if ( t2 > 1 ) t2 = 1;
  20682. var pt1 = this.getPoint( t1 );
  20683. var pt2 = this.getPoint( t2 );
  20684. var vec = pt2.clone().sub( pt1 );
  20685. return vec.normalize();
  20686. },
  20687. getTangentAt: function ( u ) {
  20688. var t = this.getUtoTmapping( u );
  20689. return this.getTangent( t );
  20690. },
  20691. computeFrenetFrames: function ( segments, closed ) {
  20692. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20693. var normal = new Vector3();
  20694. var tangents = [];
  20695. var normals = [];
  20696. var binormals = [];
  20697. var vec = new Vector3();
  20698. var mat = new Matrix4();
  20699. var i, u, theta;
  20700. // compute the tangent vectors for each segment on the curve
  20701. for ( i = 0; i <= segments; i ++ ) {
  20702. u = i / segments;
  20703. tangents[ i ] = this.getTangentAt( u );
  20704. tangents[ i ].normalize();
  20705. }
  20706. // select an initial normal vector perpendicular to the first tangent vector,
  20707. // and in the direction of the minimum tangent xyz component
  20708. normals[ 0 ] = new Vector3();
  20709. binormals[ 0 ] = new Vector3();
  20710. var min = Number.MAX_VALUE;
  20711. var tx = Math.abs( tangents[ 0 ].x );
  20712. var ty = Math.abs( tangents[ 0 ].y );
  20713. var tz = Math.abs( tangents[ 0 ].z );
  20714. if ( tx <= min ) {
  20715. min = tx;
  20716. normal.set( 1, 0, 0 );
  20717. }
  20718. if ( ty <= min ) {
  20719. min = ty;
  20720. normal.set( 0, 1, 0 );
  20721. }
  20722. if ( tz <= min ) {
  20723. normal.set( 0, 0, 1 );
  20724. }
  20725. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20726. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20727. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20728. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  20729. for ( i = 1; i <= segments; i ++ ) {
  20730. normals[ i ] = normals[ i - 1 ].clone();
  20731. binormals[ i ] = binormals[ i - 1 ].clone();
  20732. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20733. if ( vec.length() > Number.EPSILON ) {
  20734. vec.normalize();
  20735. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20736. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20737. }
  20738. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20739. }
  20740. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20741. if ( closed === true ) {
  20742. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  20743. theta /= segments;
  20744. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  20745. theta = - theta;
  20746. }
  20747. for ( i = 1; i <= segments; i ++ ) {
  20748. // twist a little...
  20749. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20750. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20751. }
  20752. }
  20753. return {
  20754. tangents: tangents,
  20755. normals: normals,
  20756. binormals: binormals
  20757. };
  20758. }
  20759. } );
  20760. function LineCurve( v1, v2 ) {
  20761. Curve.call( this );
  20762. this.v1 = v1;
  20763. this.v2 = v2;
  20764. }
  20765. LineCurve.prototype = Object.create( Curve.prototype );
  20766. LineCurve.prototype.constructor = LineCurve;
  20767. LineCurve.prototype.isLineCurve = true;
  20768. LineCurve.prototype.getPoint = function ( t ) {
  20769. if ( t === 1 ) {
  20770. return this.v2.clone();
  20771. }
  20772. var point = this.v2.clone().sub( this.v1 );
  20773. point.multiplyScalar( t ).add( this.v1 );
  20774. return point;
  20775. };
  20776. // Line curve is linear, so we can overwrite default getPointAt
  20777. LineCurve.prototype.getPointAt = function ( u ) {
  20778. return this.getPoint( u );
  20779. };
  20780. LineCurve.prototype.getTangent = function ( t ) {
  20781. var tangent = this.v2.clone().sub( this.v1 );
  20782. return tangent.normalize();
  20783. };
  20784. /**
  20785. * @author zz85 / http://www.lab4games.net/zz85/blog
  20786. *
  20787. **/
  20788. /**************************************************************
  20789. * Curved Path - a curve path is simply a array of connected
  20790. * curves, but retains the api of a curve
  20791. **************************************************************/
  20792. function CurvePath() {
  20793. Curve.call( this );
  20794. this.curves = [];
  20795. this.autoClose = false; // Automatically closes the path
  20796. }
  20797. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  20798. constructor: CurvePath,
  20799. add: function ( curve ) {
  20800. this.curves.push( curve );
  20801. },
  20802. closePath: function () {
  20803. // Add a line curve if start and end of lines are not connected
  20804. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20805. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20806. if ( ! startPoint.equals( endPoint ) ) {
  20807. this.curves.push( new LineCurve( endPoint, startPoint ) );
  20808. }
  20809. },
  20810. // To get accurate point with reference to
  20811. // entire path distance at time t,
  20812. // following has to be done:
  20813. // 1. Length of each sub path have to be known
  20814. // 2. Locate and identify type of curve
  20815. // 3. Get t for the curve
  20816. // 4. Return curve.getPointAt(t')
  20817. getPoint: function ( t ) {
  20818. var d = t * this.getLength();
  20819. var curveLengths = this.getCurveLengths();
  20820. var i = 0;
  20821. // To think about boundaries points.
  20822. while ( i < curveLengths.length ) {
  20823. if ( curveLengths[ i ] >= d ) {
  20824. var diff = curveLengths[ i ] - d;
  20825. var curve = this.curves[ i ];
  20826. var segmentLength = curve.getLength();
  20827. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  20828. return curve.getPointAt( u );
  20829. }
  20830. i ++;
  20831. }
  20832. return null;
  20833. // loop where sum != 0, sum > d , sum+1 <d
  20834. },
  20835. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20836. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20837. // getPoint() depends on getLength
  20838. getLength: function () {
  20839. var lens = this.getCurveLengths();
  20840. return lens[ lens.length - 1 ];
  20841. },
  20842. // cacheLengths must be recalculated.
  20843. updateArcLengths: function () {
  20844. this.needsUpdate = true;
  20845. this.cacheLengths = null;
  20846. this.getCurveLengths();
  20847. },
  20848. // Compute lengths and cache them
  20849. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20850. getCurveLengths: function () {
  20851. // We use cache values if curves and cache array are same length
  20852. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20853. return this.cacheLengths;
  20854. }
  20855. // Get length of sub-curve
  20856. // Push sums into cached array
  20857. var lengths = [], sums = 0;
  20858. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20859. sums += this.curves[ i ].getLength();
  20860. lengths.push( sums );
  20861. }
  20862. this.cacheLengths = lengths;
  20863. return lengths;
  20864. },
  20865. getSpacedPoints: function ( divisions ) {
  20866. if ( divisions === undefined ) divisions = 40;
  20867. var points = [];
  20868. for ( var i = 0; i <= divisions; i ++ ) {
  20869. points.push( this.getPoint( i / divisions ) );
  20870. }
  20871. if ( this.autoClose ) {
  20872. points.push( points[ 0 ] );
  20873. }
  20874. return points;
  20875. },
  20876. getPoints: function ( divisions ) {
  20877. divisions = divisions || 12;
  20878. var points = [], last;
  20879. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  20880. var curve = curves[ i ];
  20881. var resolution = (curve && curve.isEllipseCurve) ? divisions * 2
  20882. : (curve && curve.isLineCurve) ? 1
  20883. : (curve && curve.isSplineCurve) ? divisions * curve.points.length
  20884. : divisions;
  20885. var pts = curve.getPoints( resolution );
  20886. for ( var j = 0; j < pts.length; j++ ) {
  20887. var point = pts[ j ];
  20888. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  20889. points.push( point );
  20890. last = point;
  20891. }
  20892. }
  20893. if ( this.autoClose && points.length > 1 && !points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  20894. points.push( points[ 0 ] );
  20895. }
  20896. return points;
  20897. },
  20898. /**************************************************************
  20899. * Create Geometries Helpers
  20900. **************************************************************/
  20901. /// Generate geometry from path points (for Line or Points objects)
  20902. createPointsGeometry: function ( divisions ) {
  20903. var pts = this.getPoints( divisions );
  20904. return this.createGeometry( pts );
  20905. },
  20906. // Generate geometry from equidistant sampling along the path
  20907. createSpacedPointsGeometry: function ( divisions ) {
  20908. var pts = this.getSpacedPoints( divisions );
  20909. return this.createGeometry( pts );
  20910. },
  20911. createGeometry: function ( points ) {
  20912. var geometry = new Geometry();
  20913. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20914. var point = points[ i ];
  20915. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  20916. }
  20917. return geometry;
  20918. }
  20919. } );
  20920. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20921. Curve.call( this );
  20922. this.aX = aX;
  20923. this.aY = aY;
  20924. this.xRadius = xRadius;
  20925. this.yRadius = yRadius;
  20926. this.aStartAngle = aStartAngle;
  20927. this.aEndAngle = aEndAngle;
  20928. this.aClockwise = aClockwise;
  20929. this.aRotation = aRotation || 0;
  20930. }
  20931. EllipseCurve.prototype = Object.create( Curve.prototype );
  20932. EllipseCurve.prototype.constructor = EllipseCurve;
  20933. EllipseCurve.prototype.isEllipseCurve = true;
  20934. EllipseCurve.prototype.getPoint = function ( t ) {
  20935. var twoPi = Math.PI * 2;
  20936. var deltaAngle = this.aEndAngle - this.aStartAngle;
  20937. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  20938. // ensures that deltaAngle is 0 .. 2 PI
  20939. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  20940. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  20941. if ( deltaAngle < Number.EPSILON ) {
  20942. if ( samePoints ) {
  20943. deltaAngle = 0;
  20944. } else {
  20945. deltaAngle = twoPi;
  20946. }
  20947. }
  20948. if ( this.aClockwise === true && ! samePoints ) {
  20949. if ( deltaAngle === twoPi ) {
  20950. deltaAngle = - twoPi;
  20951. } else {
  20952. deltaAngle = deltaAngle - twoPi;
  20953. }
  20954. }
  20955. var angle = this.aStartAngle + t * deltaAngle;
  20956. var x = this.aX + this.xRadius * Math.cos( angle );
  20957. var y = this.aY + this.yRadius * Math.sin( angle );
  20958. if ( this.aRotation !== 0 ) {
  20959. var cos = Math.cos( this.aRotation );
  20960. var sin = Math.sin( this.aRotation );
  20961. var tx = x - this.aX;
  20962. var ty = y - this.aY;
  20963. // Rotate the point about the center of the ellipse.
  20964. x = tx * cos - ty * sin + this.aX;
  20965. y = tx * sin + ty * cos + this.aY;
  20966. }
  20967. return new Vector2( x, y );
  20968. };
  20969. function SplineCurve( points /* array of Vector2 */ ) {
  20970. Curve.call( this );
  20971. this.points = ( points === undefined ) ? [] : points;
  20972. }
  20973. SplineCurve.prototype = Object.create( Curve.prototype );
  20974. SplineCurve.prototype.constructor = SplineCurve;
  20975. SplineCurve.prototype.isSplineCurve = true;
  20976. SplineCurve.prototype.getPoint = function ( t ) {
  20977. var points = this.points;
  20978. var point = ( points.length - 1 ) * t;
  20979. var intPoint = Math.floor( point );
  20980. var weight = point - intPoint;
  20981. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20982. var point1 = points[ intPoint ];
  20983. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20984. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20985. return new Vector2(
  20986. CatmullRom( weight, point0.x, point1.x, point2.x, point3.x ),
  20987. CatmullRom( weight, point0.y, point1.y, point2.y, point3.y )
  20988. );
  20989. };
  20990. function CubicBezierCurve( v0, v1, v2, v3 ) {
  20991. Curve.call( this );
  20992. this.v0 = v0;
  20993. this.v1 = v1;
  20994. this.v2 = v2;
  20995. this.v3 = v3;
  20996. }
  20997. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  20998. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  20999. CubicBezierCurve.prototype.getPoint = function ( t ) {
  21000. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21001. return new Vector2(
  21002. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21003. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21004. );
  21005. };
  21006. function QuadraticBezierCurve( v0, v1, v2 ) {
  21007. Curve.call( this );
  21008. this.v0 = v0;
  21009. this.v1 = v1;
  21010. this.v2 = v2;
  21011. }
  21012. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21013. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21014. QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21015. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21016. return new Vector2(
  21017. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21018. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21019. );
  21020. };
  21021. var PathPrototype = Object.assign( Object.create( CurvePath.prototype ), {
  21022. fromPoints: function ( vectors ) {
  21023. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  21024. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  21025. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  21026. }
  21027. },
  21028. moveTo: function ( x, y ) {
  21029. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21030. },
  21031. lineTo: function ( x, y ) {
  21032. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  21033. this.curves.push( curve );
  21034. this.currentPoint.set( x, y );
  21035. },
  21036. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21037. var curve = new QuadraticBezierCurve(
  21038. this.currentPoint.clone(),
  21039. new Vector2( aCPx, aCPy ),
  21040. new Vector2( aX, aY )
  21041. );
  21042. this.curves.push( curve );
  21043. this.currentPoint.set( aX, aY );
  21044. },
  21045. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21046. var curve = new CubicBezierCurve(
  21047. this.currentPoint.clone(),
  21048. new Vector2( aCP1x, aCP1y ),
  21049. new Vector2( aCP2x, aCP2y ),
  21050. new Vector2( aX, aY )
  21051. );
  21052. this.curves.push( curve );
  21053. this.currentPoint.set( aX, aY );
  21054. },
  21055. splineThru: function ( pts /*Array of Vector*/ ) {
  21056. var npts = [ this.currentPoint.clone() ].concat( pts );
  21057. var curve = new SplineCurve( npts );
  21058. this.curves.push( curve );
  21059. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21060. },
  21061. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21062. var x0 = this.currentPoint.x;
  21063. var y0 = this.currentPoint.y;
  21064. this.absarc( aX + x0, aY + y0, aRadius,
  21065. aStartAngle, aEndAngle, aClockwise );
  21066. },
  21067. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21068. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21069. },
  21070. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21071. var x0 = this.currentPoint.x;
  21072. var y0 = this.currentPoint.y;
  21073. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21074. },
  21075. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21076. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21077. if ( this.curves.length > 0 ) {
  21078. // if a previous curve is present, attempt to join
  21079. var firstPoint = curve.getPoint( 0 );
  21080. if ( ! firstPoint.equals( this.currentPoint ) ) {
  21081. this.lineTo( firstPoint.x, firstPoint.y );
  21082. }
  21083. }
  21084. this.curves.push( curve );
  21085. var lastPoint = curve.getPoint( 1 );
  21086. this.currentPoint.copy( lastPoint );
  21087. }
  21088. } );
  21089. /**
  21090. * @author zz85 / http://www.lab4games.net/zz85/blog
  21091. * Creates free form 2d path using series of points, lines or curves.
  21092. **/
  21093. function Path( points ) {
  21094. CurvePath.call( this );
  21095. this.currentPoint = new Vector2();
  21096. if ( points ) {
  21097. this.fromPoints( points );
  21098. }
  21099. }
  21100. Path.prototype = PathPrototype;
  21101. PathPrototype.constructor = Path;
  21102. /**
  21103. * @author zz85 / http://www.lab4games.net/zz85/blog
  21104. * Defines a 2d shape plane using paths.
  21105. **/
  21106. // STEP 1 Create a path.
  21107. // STEP 2 Turn path into shape.
  21108. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21109. // STEP 3a - Extract points from each shape, turn to vertices
  21110. // STEP 3b - Triangulate each shape, add faces.
  21111. function Shape() {
  21112. Path.apply( this, arguments );
  21113. this.holes = [];
  21114. }
  21115. Shape.prototype = Object.assign( Object.create( PathPrototype ), {
  21116. constructor: Shape,
  21117. getPointsHoles: function ( divisions ) {
  21118. var holesPts = [];
  21119. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21120. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21121. }
  21122. return holesPts;
  21123. },
  21124. // Get points of shape and holes (keypoints based on segments parameter)
  21125. extractAllPoints: function ( divisions ) {
  21126. return {
  21127. shape: this.getPoints( divisions ),
  21128. holes: this.getPointsHoles( divisions )
  21129. };
  21130. },
  21131. extractPoints: function ( divisions ) {
  21132. return this.extractAllPoints( divisions );
  21133. }
  21134. } );
  21135. /**
  21136. * @author zz85 / http://www.lab4games.net/zz85/blog
  21137. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  21138. **/
  21139. function ShapePath() {
  21140. this.subPaths = [];
  21141. this.currentPath = null;
  21142. }
  21143. Object.assign( ShapePath.prototype, {
  21144. moveTo: function ( x, y ) {
  21145. this.currentPath = new Path();
  21146. this.subPaths.push( this.currentPath );
  21147. this.currentPath.moveTo( x, y );
  21148. },
  21149. lineTo: function ( x, y ) {
  21150. this.currentPath.lineTo( x, y );
  21151. },
  21152. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21153. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21154. },
  21155. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21156. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21157. },
  21158. splineThru: function ( pts ) {
  21159. this.currentPath.splineThru( pts );
  21160. },
  21161. toShapes: function ( isCCW, noHoles ) {
  21162. function toShapesNoHoles( inSubpaths ) {
  21163. var shapes = [];
  21164. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21165. var tmpPath = inSubpaths[ i ];
  21166. var tmpShape = new Shape();
  21167. tmpShape.curves = tmpPath.curves;
  21168. shapes.push( tmpShape );
  21169. }
  21170. return shapes;
  21171. }
  21172. function isPointInsidePolygon( inPt, inPolygon ) {
  21173. var polyLen = inPolygon.length;
  21174. // inPt on polygon contour => immediate success or
  21175. // toggling of inside/outside at every single! intersection point of an edge
  21176. // with the horizontal line through inPt, left of inPt
  21177. // not counting lowerY endpoints of edges and whole edges on that line
  21178. var inside = false;
  21179. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21180. var edgeLowPt = inPolygon[ p ];
  21181. var edgeHighPt = inPolygon[ q ];
  21182. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21183. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21184. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21185. // not parallel
  21186. if ( edgeDy < 0 ) {
  21187. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21188. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21189. }
  21190. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21191. if ( inPt.y === edgeLowPt.y ) {
  21192. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21193. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21194. } else {
  21195. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21196. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21197. if ( perpEdge < 0 ) continue;
  21198. inside = ! inside; // true intersection left of inPt
  21199. }
  21200. } else {
  21201. // parallel or collinear
  21202. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21203. // edge lies on the same horizontal line as inPt
  21204. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21205. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21206. // continue;
  21207. }
  21208. }
  21209. return inside;
  21210. }
  21211. var isClockWise = ShapeUtils.isClockWise;
  21212. var subPaths = this.subPaths;
  21213. if ( subPaths.length === 0 ) return [];
  21214. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21215. var solid, tmpPath, tmpShape, shapes = [];
  21216. if ( subPaths.length === 1 ) {
  21217. tmpPath = subPaths[ 0 ];
  21218. tmpShape = new Shape();
  21219. tmpShape.curves = tmpPath.curves;
  21220. shapes.push( tmpShape );
  21221. return shapes;
  21222. }
  21223. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21224. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21225. // console.log("Holes first", holesFirst);
  21226. var betterShapeHoles = [];
  21227. var newShapes = [];
  21228. var newShapeHoles = [];
  21229. var mainIdx = 0;
  21230. var tmpPoints;
  21231. newShapes[ mainIdx ] = undefined;
  21232. newShapeHoles[ mainIdx ] = [];
  21233. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21234. tmpPath = subPaths[ i ];
  21235. tmpPoints = tmpPath.getPoints();
  21236. solid = isClockWise( tmpPoints );
  21237. solid = isCCW ? ! solid : solid;
  21238. if ( solid ) {
  21239. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21240. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  21241. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21242. if ( holesFirst ) mainIdx ++;
  21243. newShapeHoles[ mainIdx ] = [];
  21244. //console.log('cw', i);
  21245. } else {
  21246. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21247. //console.log('ccw', i);
  21248. }
  21249. }
  21250. // only Holes? -> probably all Shapes with wrong orientation
  21251. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21252. if ( newShapes.length > 1 ) {
  21253. var ambiguous = false;
  21254. var toChange = [];
  21255. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21256. betterShapeHoles[ sIdx ] = [];
  21257. }
  21258. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21259. var sho = newShapeHoles[ sIdx ];
  21260. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21261. var ho = sho[ hIdx ];
  21262. var hole_unassigned = true;
  21263. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21264. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21265. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21266. if ( hole_unassigned ) {
  21267. hole_unassigned = false;
  21268. betterShapeHoles[ s2Idx ].push( ho );
  21269. } else {
  21270. ambiguous = true;
  21271. }
  21272. }
  21273. }
  21274. if ( hole_unassigned ) {
  21275. betterShapeHoles[ sIdx ].push( ho );
  21276. }
  21277. }
  21278. }
  21279. // console.log("ambiguous: ", ambiguous);
  21280. if ( toChange.length > 0 ) {
  21281. // console.log("to change: ", toChange);
  21282. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21283. }
  21284. }
  21285. var tmpHoles;
  21286. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21287. tmpShape = newShapes[ i ].s;
  21288. shapes.push( tmpShape );
  21289. tmpHoles = newShapeHoles[ i ];
  21290. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21291. tmpShape.holes.push( tmpHoles[ j ].h );
  21292. }
  21293. }
  21294. //console.log("shape", shapes);
  21295. return shapes;
  21296. }
  21297. } );
  21298. /**
  21299. * @author zz85 / http://www.lab4games.net/zz85/blog
  21300. * @author mrdoob / http://mrdoob.com/
  21301. */
  21302. function Font( data ) {
  21303. this.data = data;
  21304. }
  21305. Object.assign( Font.prototype, {
  21306. isFont: true,
  21307. generateShapes: function ( text, size, divisions ) {
  21308. function createPaths( text ) {
  21309. var chars = String( text ).split( '' );
  21310. var scale = size / data.resolution;
  21311. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  21312. var offsetX = 0, offsetY = 0;
  21313. var paths = [];
  21314. for ( var i = 0; i < chars.length; i ++ ) {
  21315. var char = chars[ i ];
  21316. if ( char === '\n' ) {
  21317. offsetX = 0;
  21318. offsetY -= line_height;
  21319. } else {
  21320. var ret = createPath( char, scale, offsetX, offsetY );
  21321. offsetX += ret.offsetX;
  21322. paths.push( ret.path );
  21323. }
  21324. }
  21325. return paths;
  21326. }
  21327. function createPath( c, scale, offsetX, offsetY ) {
  21328. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  21329. if ( ! glyph ) return;
  21330. var path = new ShapePath();
  21331. var pts = [];
  21332. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  21333. if ( glyph.o ) {
  21334. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  21335. for ( var i = 0, l = outline.length; i < l; ) {
  21336. var action = outline[ i ++ ];
  21337. switch ( action ) {
  21338. case 'm': // moveTo
  21339. x = outline[ i ++ ] * scale + offsetX;
  21340. y = outline[ i ++ ] * scale + offsetY;
  21341. path.moveTo( x, y );
  21342. break;
  21343. case 'l': // lineTo
  21344. x = outline[ i ++ ] * scale + offsetX;
  21345. y = outline[ i ++ ] * scale + offsetY;
  21346. path.lineTo( x, y );
  21347. break;
  21348. case 'q': // quadraticCurveTo
  21349. cpx = outline[ i ++ ] * scale + offsetX;
  21350. cpy = outline[ i ++ ] * scale + offsetY;
  21351. cpx1 = outline[ i ++ ] * scale + offsetX;
  21352. cpy1 = outline[ i ++ ] * scale + offsetY;
  21353. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  21354. laste = pts[ pts.length - 1 ];
  21355. if ( laste ) {
  21356. cpx0 = laste.x;
  21357. cpy0 = laste.y;
  21358. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21359. var t = i2 / divisions;
  21360. QuadraticBezier( t, cpx0, cpx1, cpx );
  21361. QuadraticBezier( t, cpy0, cpy1, cpy );
  21362. }
  21363. }
  21364. break;
  21365. case 'b': // bezierCurveTo
  21366. cpx = outline[ i ++ ] * scale + offsetX;
  21367. cpy = outline[ i ++ ] * scale + offsetY;
  21368. cpx1 = outline[ i ++ ] * scale + offsetX;
  21369. cpy1 = outline[ i ++ ] * scale + offsetY;
  21370. cpx2 = outline[ i ++ ] * scale + offsetX;
  21371. cpy2 = outline[ i ++ ] * scale + offsetY;
  21372. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  21373. laste = pts[ pts.length - 1 ];
  21374. if ( laste ) {
  21375. cpx0 = laste.x;
  21376. cpy0 = laste.y;
  21377. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21378. var t = i2 / divisions;
  21379. CubicBezier( t, cpx0, cpx1, cpx2, cpx );
  21380. CubicBezier( t, cpy0, cpy1, cpy2, cpy );
  21381. }
  21382. }
  21383. break;
  21384. }
  21385. }
  21386. }
  21387. return { offsetX: glyph.ha * scale, path: path };
  21388. }
  21389. //
  21390. if ( size === undefined ) size = 100;
  21391. if ( divisions === undefined ) divisions = 4;
  21392. var data = this.data;
  21393. var paths = createPaths( text );
  21394. var shapes = [];
  21395. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  21396. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  21397. }
  21398. return shapes;
  21399. }
  21400. } );
  21401. /**
  21402. * @author mrdoob / http://mrdoob.com/
  21403. */
  21404. function FontLoader( manager ) {
  21405. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21406. }
  21407. Object.assign( FontLoader.prototype, {
  21408. load: function ( url, onLoad, onProgress, onError ) {
  21409. var scope = this;
  21410. var loader = new FileLoader( this.manager );
  21411. loader.load( url, function ( text ) {
  21412. var json;
  21413. try {
  21414. json = JSON.parse( text );
  21415. } catch ( e ) {
  21416. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  21417. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  21418. }
  21419. var font = scope.parse( json );
  21420. if ( onLoad ) onLoad( font );
  21421. }, onProgress, onError );
  21422. },
  21423. parse: function ( json ) {
  21424. return new Font( json );
  21425. }
  21426. } );
  21427. var context;
  21428. var AudioContext = {
  21429. getContext: function () {
  21430. if ( context === undefined ) {
  21431. context = new ( window.AudioContext || window.webkitAudioContext )();
  21432. }
  21433. return context;
  21434. },
  21435. setContext: function ( value ) {
  21436. context = value;
  21437. }
  21438. };
  21439. /**
  21440. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  21441. */
  21442. function AudioLoader( manager ) {
  21443. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21444. }
  21445. Object.assign( AudioLoader.prototype, {
  21446. load: function ( url, onLoad, onProgress, onError ) {
  21447. var loader = new FileLoader( this.manager );
  21448. loader.setResponseType( 'arraybuffer' );
  21449. loader.load( url, function ( buffer ) {
  21450. var context = AudioContext.getContext();
  21451. context.decodeAudioData( buffer, function ( audioBuffer ) {
  21452. onLoad( audioBuffer );
  21453. } );
  21454. }, onProgress, onError );
  21455. }
  21456. } );
  21457. /**
  21458. * @author mrdoob / http://mrdoob.com/
  21459. */
  21460. function StereoCamera() {
  21461. this.type = 'StereoCamera';
  21462. this.aspect = 1;
  21463. this.eyeSep = 0.064;
  21464. this.cameraL = new PerspectiveCamera();
  21465. this.cameraL.layers.enable( 1 );
  21466. this.cameraL.matrixAutoUpdate = false;
  21467. this.cameraR = new PerspectiveCamera();
  21468. this.cameraR.layers.enable( 2 );
  21469. this.cameraR.matrixAutoUpdate = false;
  21470. }
  21471. Object.assign( StereoCamera.prototype, {
  21472. update: ( function () {
  21473. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  21474. var eyeRight = new Matrix4();
  21475. var eyeLeft = new Matrix4();
  21476. return function update( camera ) {
  21477. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  21478. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  21479. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  21480. if ( needsUpdate ) {
  21481. instance = this;
  21482. focus = camera.focus;
  21483. fov = camera.fov;
  21484. aspect = camera.aspect * this.aspect;
  21485. near = camera.near;
  21486. far = camera.far;
  21487. zoom = camera.zoom;
  21488. // Off-axis stereoscopic effect based on
  21489. // http://paulbourke.net/stereographics/stereorender/
  21490. var projectionMatrix = camera.projectionMatrix.clone();
  21491. eyeSep = this.eyeSep / 2;
  21492. var eyeSepOnProjection = eyeSep * near / focus;
  21493. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  21494. var xmin, xmax;
  21495. // translate xOffset
  21496. eyeLeft.elements[ 12 ] = - eyeSep;
  21497. eyeRight.elements[ 12 ] = eyeSep;
  21498. // for left eye
  21499. xmin = - ymax * aspect + eyeSepOnProjection;
  21500. xmax = ymax * aspect + eyeSepOnProjection;
  21501. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  21502. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  21503. this.cameraL.projectionMatrix.copy( projectionMatrix );
  21504. // for right eye
  21505. xmin = - ymax * aspect - eyeSepOnProjection;
  21506. xmax = ymax * aspect - eyeSepOnProjection;
  21507. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  21508. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  21509. this.cameraR.projectionMatrix.copy( projectionMatrix );
  21510. }
  21511. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  21512. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  21513. };
  21514. } )()
  21515. } );
  21516. /**
  21517. * Camera for rendering cube maps
  21518. * - renders scene into axis-aligned cube
  21519. *
  21520. * @author alteredq / http://alteredqualia.com/
  21521. */
  21522. function CubeCamera( near, far, cubeResolution ) {
  21523. Object3D.call( this );
  21524. this.type = 'CubeCamera';
  21525. var fov = 90, aspect = 1;
  21526. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  21527. cameraPX.up.set( 0, - 1, 0 );
  21528. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  21529. this.add( cameraPX );
  21530. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  21531. cameraNX.up.set( 0, - 1, 0 );
  21532. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  21533. this.add( cameraNX );
  21534. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  21535. cameraPY.up.set( 0, 0, 1 );
  21536. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  21537. this.add( cameraPY );
  21538. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  21539. cameraNY.up.set( 0, 0, - 1 );
  21540. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  21541. this.add( cameraNY );
  21542. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  21543. cameraPZ.up.set( 0, - 1, 0 );
  21544. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  21545. this.add( cameraPZ );
  21546. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  21547. cameraNZ.up.set( 0, - 1, 0 );
  21548. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  21549. this.add( cameraNZ );
  21550. var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  21551. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  21552. this.renderTarget.texture.name = "CubeCamera";
  21553. this.updateCubeMap = function ( renderer, scene ) {
  21554. if ( this.parent === null ) this.updateMatrixWorld();
  21555. var renderTarget = this.renderTarget;
  21556. var generateMipmaps = renderTarget.texture.generateMipmaps;
  21557. renderTarget.texture.generateMipmaps = false;
  21558. renderTarget.activeCubeFace = 0;
  21559. renderer.render( scene, cameraPX, renderTarget );
  21560. renderTarget.activeCubeFace = 1;
  21561. renderer.render( scene, cameraNX, renderTarget );
  21562. renderTarget.activeCubeFace = 2;
  21563. renderer.render( scene, cameraPY, renderTarget );
  21564. renderTarget.activeCubeFace = 3;
  21565. renderer.render( scene, cameraNY, renderTarget );
  21566. renderTarget.activeCubeFace = 4;
  21567. renderer.render( scene, cameraPZ, renderTarget );
  21568. renderTarget.texture.generateMipmaps = generateMipmaps;
  21569. renderTarget.activeCubeFace = 5;
  21570. renderer.render( scene, cameraNZ, renderTarget );
  21571. renderer.setRenderTarget( null );
  21572. };
  21573. }
  21574. CubeCamera.prototype = Object.create( Object3D.prototype );
  21575. CubeCamera.prototype.constructor = CubeCamera;
  21576. /**
  21577. * @author mrdoob / http://mrdoob.com/
  21578. */
  21579. function ArrayCamera( array ) {
  21580. PerspectiveCamera.call( this );
  21581. this.cameras = array || [];
  21582. }
  21583. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  21584. constructor: ArrayCamera,
  21585. isArrayCamera: true
  21586. } );
  21587. /**
  21588. * @author mrdoob / http://mrdoob.com/
  21589. */
  21590. function AudioListener() {
  21591. Object3D.call( this );
  21592. this.type = 'AudioListener';
  21593. this.context = AudioContext.getContext();
  21594. this.gain = this.context.createGain();
  21595. this.gain.connect( this.context.destination );
  21596. this.filter = null;
  21597. }
  21598. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  21599. constructor: AudioListener,
  21600. getInput: function () {
  21601. return this.gain;
  21602. },
  21603. removeFilter: function ( ) {
  21604. if ( this.filter !== null ) {
  21605. this.gain.disconnect( this.filter );
  21606. this.filter.disconnect( this.context.destination );
  21607. this.gain.connect( this.context.destination );
  21608. this.filter = null;
  21609. }
  21610. },
  21611. getFilter: function () {
  21612. return this.filter;
  21613. },
  21614. setFilter: function ( value ) {
  21615. if ( this.filter !== null ) {
  21616. this.gain.disconnect( this.filter );
  21617. this.filter.disconnect( this.context.destination );
  21618. } else {
  21619. this.gain.disconnect( this.context.destination );
  21620. }
  21621. this.filter = value;
  21622. this.gain.connect( this.filter );
  21623. this.filter.connect( this.context.destination );
  21624. },
  21625. getMasterVolume: function () {
  21626. return this.gain.gain.value;
  21627. },
  21628. setMasterVolume: function ( value ) {
  21629. this.gain.gain.value = value;
  21630. },
  21631. updateMatrixWorld: ( function () {
  21632. var position = new Vector3();
  21633. var quaternion = new Quaternion();
  21634. var scale = new Vector3();
  21635. var orientation = new Vector3();
  21636. return function updateMatrixWorld( force ) {
  21637. Object3D.prototype.updateMatrixWorld.call( this, force );
  21638. var listener = this.context.listener;
  21639. var up = this.up;
  21640. this.matrixWorld.decompose( position, quaternion, scale );
  21641. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  21642. if ( listener.positionX ) {
  21643. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  21644. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  21645. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  21646. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  21647. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  21648. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  21649. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  21650. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  21651. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  21652. } else {
  21653. listener.setPosition( position.x, position.y, position.z );
  21654. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  21655. }
  21656. };
  21657. } )()
  21658. } );
  21659. /**
  21660. * @author mrdoob / http://mrdoob.com/
  21661. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  21662. */
  21663. function Audio( listener ) {
  21664. Object3D.call( this );
  21665. this.type = 'Audio';
  21666. this.context = listener.context;
  21667. this.gain = this.context.createGain();
  21668. this.gain.connect( listener.getInput() );
  21669. this.autoplay = false;
  21670. this.buffer = null;
  21671. this.loop = false;
  21672. this.startTime = 0;
  21673. this.playbackRate = 1;
  21674. this.isPlaying = false;
  21675. this.hasPlaybackControl = true;
  21676. this.sourceType = 'empty';
  21677. this.filters = [];
  21678. }
  21679. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  21680. constructor: Audio,
  21681. getOutput: function () {
  21682. return this.gain;
  21683. },
  21684. setNodeSource: function ( audioNode ) {
  21685. this.hasPlaybackControl = false;
  21686. this.sourceType = 'audioNode';
  21687. this.source = audioNode;
  21688. this.connect();
  21689. return this;
  21690. },
  21691. setBuffer: function ( audioBuffer ) {
  21692. this.buffer = audioBuffer;
  21693. this.sourceType = 'buffer';
  21694. if ( this.autoplay ) this.play();
  21695. return this;
  21696. },
  21697. play: function () {
  21698. if ( this.isPlaying === true ) {
  21699. console.warn( 'THREE.Audio: Audio is already playing.' );
  21700. return;
  21701. }
  21702. if ( this.hasPlaybackControl === false ) {
  21703. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21704. return;
  21705. }
  21706. var source = this.context.createBufferSource();
  21707. source.buffer = this.buffer;
  21708. source.loop = this.loop;
  21709. source.onended = this.onEnded.bind( this );
  21710. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  21711. source.start( 0, this.startTime );
  21712. this.isPlaying = true;
  21713. this.source = source;
  21714. return this.connect();
  21715. },
  21716. pause: function () {
  21717. if ( this.hasPlaybackControl === false ) {
  21718. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21719. return;
  21720. }
  21721. this.source.stop();
  21722. this.startTime = this.context.currentTime;
  21723. this.isPlaying = false;
  21724. return this;
  21725. },
  21726. stop: function () {
  21727. if ( this.hasPlaybackControl === false ) {
  21728. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21729. return;
  21730. }
  21731. this.source.stop();
  21732. this.startTime = 0;
  21733. this.isPlaying = false;
  21734. return this;
  21735. },
  21736. connect: function () {
  21737. if ( this.filters.length > 0 ) {
  21738. this.source.connect( this.filters[ 0 ] );
  21739. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  21740. this.filters[ i - 1 ].connect( this.filters[ i ] );
  21741. }
  21742. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  21743. } else {
  21744. this.source.connect( this.getOutput() );
  21745. }
  21746. return this;
  21747. },
  21748. disconnect: function () {
  21749. if ( this.filters.length > 0 ) {
  21750. this.source.disconnect( this.filters[ 0 ] );
  21751. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  21752. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  21753. }
  21754. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  21755. } else {
  21756. this.source.disconnect( this.getOutput() );
  21757. }
  21758. return this;
  21759. },
  21760. getFilters: function () {
  21761. return this.filters;
  21762. },
  21763. setFilters: function ( value ) {
  21764. if ( ! value ) value = [];
  21765. if ( this.isPlaying === true ) {
  21766. this.disconnect();
  21767. this.filters = value;
  21768. this.connect();
  21769. } else {
  21770. this.filters = value;
  21771. }
  21772. return this;
  21773. },
  21774. getFilter: function () {
  21775. return this.getFilters()[ 0 ];
  21776. },
  21777. setFilter: function ( filter ) {
  21778. return this.setFilters( filter ? [ filter ] : [] );
  21779. },
  21780. setPlaybackRate: function ( value ) {
  21781. if ( this.hasPlaybackControl === false ) {
  21782. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21783. return;
  21784. }
  21785. this.playbackRate = value;
  21786. if ( this.isPlaying === true ) {
  21787. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  21788. }
  21789. return this;
  21790. },
  21791. getPlaybackRate: function () {
  21792. return this.playbackRate;
  21793. },
  21794. onEnded: function () {
  21795. this.isPlaying = false;
  21796. },
  21797. getLoop: function () {
  21798. if ( this.hasPlaybackControl === false ) {
  21799. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21800. return false;
  21801. }
  21802. return this.loop;
  21803. },
  21804. setLoop: function ( value ) {
  21805. if ( this.hasPlaybackControl === false ) {
  21806. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21807. return;
  21808. }
  21809. this.loop = value;
  21810. if ( this.isPlaying === true ) {
  21811. this.source.loop = this.loop;
  21812. }
  21813. return this;
  21814. },
  21815. getVolume: function () {
  21816. return this.gain.gain.value;
  21817. },
  21818. setVolume: function ( value ) {
  21819. this.gain.gain.value = value;
  21820. return this;
  21821. }
  21822. } );
  21823. /**
  21824. * @author mrdoob / http://mrdoob.com/
  21825. */
  21826. function PositionalAudio( listener ) {
  21827. Audio.call( this, listener );
  21828. this.panner = this.context.createPanner();
  21829. this.panner.connect( this.gain );
  21830. }
  21831. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  21832. constructor: PositionalAudio,
  21833. getOutput: function () {
  21834. return this.panner;
  21835. },
  21836. getRefDistance: function () {
  21837. return this.panner.refDistance;
  21838. },
  21839. setRefDistance: function ( value ) {
  21840. this.panner.refDistance = value;
  21841. },
  21842. getRolloffFactor: function () {
  21843. return this.panner.rolloffFactor;
  21844. },
  21845. setRolloffFactor: function ( value ) {
  21846. this.panner.rolloffFactor = value;
  21847. },
  21848. getDistanceModel: function () {
  21849. return this.panner.distanceModel;
  21850. },
  21851. setDistanceModel: function ( value ) {
  21852. this.panner.distanceModel = value;
  21853. },
  21854. getMaxDistance: function () {
  21855. return this.panner.maxDistance;
  21856. },
  21857. setMaxDistance: function ( value ) {
  21858. this.panner.maxDistance = value;
  21859. },
  21860. updateMatrixWorld: ( function () {
  21861. var position = new Vector3();
  21862. return function updateMatrixWorld( force ) {
  21863. Object3D.prototype.updateMatrixWorld.call( this, force );
  21864. position.setFromMatrixPosition( this.matrixWorld );
  21865. this.panner.setPosition( position.x, position.y, position.z );
  21866. };
  21867. } )()
  21868. } );
  21869. /**
  21870. * @author mrdoob / http://mrdoob.com/
  21871. */
  21872. function AudioAnalyser( audio, fftSize ) {
  21873. this.analyser = audio.context.createAnalyser();
  21874. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  21875. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  21876. audio.getOutput().connect( this.analyser );
  21877. }
  21878. Object.assign( AudioAnalyser.prototype, {
  21879. getFrequencyData: function () {
  21880. this.analyser.getByteFrequencyData( this.data );
  21881. return this.data;
  21882. },
  21883. getAverageFrequency: function () {
  21884. var value = 0, data = this.getFrequencyData();
  21885. for ( var i = 0; i < data.length; i ++ ) {
  21886. value += data[ i ];
  21887. }
  21888. return value / data.length;
  21889. }
  21890. } );
  21891. /**
  21892. *
  21893. * Buffered scene graph property that allows weighted accumulation.
  21894. *
  21895. *
  21896. * @author Ben Houston / http://clara.io/
  21897. * @author David Sarno / http://lighthaus.us/
  21898. * @author tschw
  21899. */
  21900. function PropertyMixer( binding, typeName, valueSize ) {
  21901. this.binding = binding;
  21902. this.valueSize = valueSize;
  21903. var bufferType = Float64Array,
  21904. mixFunction;
  21905. switch ( typeName ) {
  21906. case 'quaternion':
  21907. mixFunction = this._slerp;
  21908. break;
  21909. case 'string':
  21910. case 'bool':
  21911. bufferType = Array;
  21912. mixFunction = this._select;
  21913. break;
  21914. default:
  21915. mixFunction = this._lerp;
  21916. }
  21917. this.buffer = new bufferType( valueSize * 4 );
  21918. // layout: [ incoming | accu0 | accu1 | orig ]
  21919. //
  21920. // interpolators can use .buffer as their .result
  21921. // the data then goes to 'incoming'
  21922. //
  21923. // 'accu0' and 'accu1' are used frame-interleaved for
  21924. // the cumulative result and are compared to detect
  21925. // changes
  21926. //
  21927. // 'orig' stores the original state of the property
  21928. this._mixBufferRegion = mixFunction;
  21929. this.cumulativeWeight = 0;
  21930. this.useCount = 0;
  21931. this.referenceCount = 0;
  21932. }
  21933. Object.assign( PropertyMixer.prototype, {
  21934. // accumulate data in the 'incoming' region into 'accu<i>'
  21935. accumulate: function ( accuIndex, weight ) {
  21936. // note: happily accumulating nothing when weight = 0, the caller knows
  21937. // the weight and shouldn't have made the call in the first place
  21938. var buffer = this.buffer,
  21939. stride = this.valueSize,
  21940. offset = accuIndex * stride + stride,
  21941. currentWeight = this.cumulativeWeight;
  21942. if ( currentWeight === 0 ) {
  21943. // accuN := incoming * weight
  21944. for ( var i = 0; i !== stride; ++ i ) {
  21945. buffer[ offset + i ] = buffer[ i ];
  21946. }
  21947. currentWeight = weight;
  21948. } else {
  21949. // accuN := accuN + incoming * weight
  21950. currentWeight += weight;
  21951. var mix = weight / currentWeight;
  21952. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  21953. }
  21954. this.cumulativeWeight = currentWeight;
  21955. },
  21956. // apply the state of 'accu<i>' to the binding when accus differ
  21957. apply: function ( accuIndex ) {
  21958. var stride = this.valueSize,
  21959. buffer = this.buffer,
  21960. offset = accuIndex * stride + stride,
  21961. weight = this.cumulativeWeight,
  21962. binding = this.binding;
  21963. this.cumulativeWeight = 0;
  21964. if ( weight < 1 ) {
  21965. // accuN := accuN + original * ( 1 - cumulativeWeight )
  21966. var originalValueOffset = stride * 3;
  21967. this._mixBufferRegion(
  21968. buffer, offset, originalValueOffset, 1 - weight, stride );
  21969. }
  21970. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  21971. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  21972. // value has changed -> update scene graph
  21973. binding.setValue( buffer, offset );
  21974. break;
  21975. }
  21976. }
  21977. },
  21978. // remember the state of the bound property and copy it to both accus
  21979. saveOriginalState: function () {
  21980. var binding = this.binding;
  21981. var buffer = this.buffer,
  21982. stride = this.valueSize,
  21983. originalValueOffset = stride * 3;
  21984. binding.getValue( buffer, originalValueOffset );
  21985. // accu[0..1] := orig -- initially detect changes against the original
  21986. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  21987. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  21988. }
  21989. this.cumulativeWeight = 0;
  21990. },
  21991. // apply the state previously taken via 'saveOriginalState' to the binding
  21992. restoreOriginalState: function () {
  21993. var originalValueOffset = this.valueSize * 3;
  21994. this.binding.setValue( this.buffer, originalValueOffset );
  21995. },
  21996. // mix functions
  21997. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  21998. if ( t >= 0.5 ) {
  21999. for ( var i = 0; i !== stride; ++ i ) {
  22000. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  22001. }
  22002. }
  22003. },
  22004. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  22005. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  22006. },
  22007. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  22008. var s = 1 - t;
  22009. for ( var i = 0; i !== stride; ++ i ) {
  22010. var j = dstOffset + i;
  22011. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  22012. }
  22013. }
  22014. } );
  22015. /**
  22016. *
  22017. * A reference to a real property in the scene graph.
  22018. *
  22019. *
  22020. * @author Ben Houston / http://clara.io/
  22021. * @author David Sarno / http://lighthaus.us/
  22022. * @author tschw
  22023. */
  22024. function Composite( targetGroup, path, optionalParsedPath ) {
  22025. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  22026. this._targetGroup = targetGroup;
  22027. this._bindings = targetGroup.subscribe_( path, parsedPath );
  22028. }
  22029. Object.assign( Composite.prototype, {
  22030. getValue: function ( array, offset ) {
  22031. this.bind(); // bind all binding
  22032. var firstValidIndex = this._targetGroup.nCachedObjects_,
  22033. binding = this._bindings[ firstValidIndex ];
  22034. // and only call .getValue on the first
  22035. if ( binding !== undefined ) binding.getValue( array, offset );
  22036. },
  22037. setValue: function ( array, offset ) {
  22038. var bindings = this._bindings;
  22039. for ( var i = this._targetGroup.nCachedObjects_,
  22040. n = bindings.length; i !== n; ++ i ) {
  22041. bindings[ i ].setValue( array, offset );
  22042. }
  22043. },
  22044. bind: function () {
  22045. var bindings = this._bindings;
  22046. for ( var i = this._targetGroup.nCachedObjects_,
  22047. n = bindings.length; i !== n; ++ i ) {
  22048. bindings[ i ].bind();
  22049. }
  22050. },
  22051. unbind: function () {
  22052. var bindings = this._bindings;
  22053. for ( var i = this._targetGroup.nCachedObjects_,
  22054. n = bindings.length; i !== n; ++ i ) {
  22055. bindings[ i ].unbind();
  22056. }
  22057. }
  22058. } );
  22059. function PropertyBinding( rootNode, path, parsedPath ) {
  22060. this.path = path;
  22061. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  22062. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  22063. this.rootNode = rootNode;
  22064. }
  22065. Object.assign( PropertyBinding, {
  22066. Composite: Composite,
  22067. create: function ( root, path, parsedPath ) {
  22068. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  22069. return new PropertyBinding( root, path, parsedPath );
  22070. } else {
  22071. return new PropertyBinding.Composite( root, path, parsedPath );
  22072. }
  22073. },
  22074. parseTrackName: function () {
  22075. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  22076. // be matched to parse the rest of the track name.
  22077. var directoryRe = /((?:[\w-]+[\/:])*)/;
  22078. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  22079. var nodeRe = /([\w-\.]+)?/;
  22080. // Object on target node, and accessor. Name may contain only word
  22081. // characters. Accessor may contain any character except closing bracket.
  22082. var objectRe = /(?:\.([\w-]+)(?:\[(.+)\])?)?/;
  22083. // Property and accessor. May contain only word characters. Accessor may
  22084. // contain any non-bracket characters.
  22085. var propertyRe = /\.([\w-]+)(?:\[(.+)\])?/;
  22086. var trackRe = new RegExp(''
  22087. + '^'
  22088. + directoryRe.source
  22089. + nodeRe.source
  22090. + objectRe.source
  22091. + propertyRe.source
  22092. + '$'
  22093. );
  22094. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  22095. return function ( trackName ) {
  22096. var matches = trackRe.exec( trackName );
  22097. if ( ! matches ) {
  22098. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  22099. }
  22100. var results = {
  22101. // directoryName: matches[ 1 ], // (tschw) currently unused
  22102. nodeName: matches[ 2 ],
  22103. objectName: matches[ 3 ],
  22104. objectIndex: matches[ 4 ],
  22105. propertyName: matches[ 5 ], // required
  22106. propertyIndex: matches[ 6 ]
  22107. };
  22108. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  22109. if ( lastDot !== undefined && lastDot !== -1 ) {
  22110. var objectName = results.nodeName.substring( lastDot + 1 );
  22111. // Object names must be checked against a whitelist. Otherwise, there
  22112. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  22113. // 'bar' could be the objectName, or part of a nodeName (which can
  22114. // include '.' characters).
  22115. if ( supportedObjectNames.indexOf( objectName ) !== -1 ) {
  22116. results.nodeName = results.nodeName.substring( 0, lastDot );
  22117. results.objectName = objectName;
  22118. }
  22119. }
  22120. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  22121. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  22122. }
  22123. return results;
  22124. };
  22125. }(),
  22126. findNode: function ( root, nodeName ) {
  22127. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  22128. return root;
  22129. }
  22130. // search into skeleton bones.
  22131. if ( root.skeleton ) {
  22132. var searchSkeleton = function ( skeleton ) {
  22133. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  22134. var bone = skeleton.bones[ i ];
  22135. if ( bone.name === nodeName ) {
  22136. return bone;
  22137. }
  22138. }
  22139. return null;
  22140. };
  22141. var bone = searchSkeleton( root.skeleton );
  22142. if ( bone ) {
  22143. return bone;
  22144. }
  22145. }
  22146. // search into node subtree.
  22147. if ( root.children ) {
  22148. var searchNodeSubtree = function ( children ) {
  22149. for ( var i = 0; i < children.length; i ++ ) {
  22150. var childNode = children[ i ];
  22151. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  22152. return childNode;
  22153. }
  22154. var result = searchNodeSubtree( childNode.children );
  22155. if ( result ) return result;
  22156. }
  22157. return null;
  22158. };
  22159. var subTreeNode = searchNodeSubtree( root.children );
  22160. if ( subTreeNode ) {
  22161. return subTreeNode;
  22162. }
  22163. }
  22164. return null;
  22165. }
  22166. } );
  22167. Object.assign( PropertyBinding.prototype, { // prototype, continued
  22168. // these are used to "bind" a nonexistent property
  22169. _getValue_unavailable: function () {},
  22170. _setValue_unavailable: function () {},
  22171. BindingType: {
  22172. Direct: 0,
  22173. EntireArray: 1,
  22174. ArrayElement: 2,
  22175. HasFromToArray: 3
  22176. },
  22177. Versioning: {
  22178. None: 0,
  22179. NeedsUpdate: 1,
  22180. MatrixWorldNeedsUpdate: 2
  22181. },
  22182. GetterByBindingType: [
  22183. function getValue_direct( buffer, offset ) {
  22184. buffer[ offset ] = this.node[ this.propertyName ];
  22185. },
  22186. function getValue_array( buffer, offset ) {
  22187. var source = this.resolvedProperty;
  22188. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  22189. buffer[ offset ++ ] = source[ i ];
  22190. }
  22191. },
  22192. function getValue_arrayElement( buffer, offset ) {
  22193. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  22194. },
  22195. function getValue_toArray( buffer, offset ) {
  22196. this.resolvedProperty.toArray( buffer, offset );
  22197. }
  22198. ],
  22199. SetterByBindingTypeAndVersioning: [
  22200. [
  22201. // Direct
  22202. function setValue_direct( buffer, offset ) {
  22203. this.node[ this.propertyName ] = buffer[ offset ];
  22204. },
  22205. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  22206. this.node[ this.propertyName ] = buffer[ offset ];
  22207. this.targetObject.needsUpdate = true;
  22208. },
  22209. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22210. this.node[ this.propertyName ] = buffer[ offset ];
  22211. this.targetObject.matrixWorldNeedsUpdate = true;
  22212. }
  22213. ], [
  22214. // EntireArray
  22215. function setValue_array( buffer, offset ) {
  22216. var dest = this.resolvedProperty;
  22217. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  22218. dest[ i ] = buffer[ offset ++ ];
  22219. }
  22220. },
  22221. function setValue_array_setNeedsUpdate( buffer, offset ) {
  22222. var dest = this.resolvedProperty;
  22223. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  22224. dest[ i ] = buffer[ offset ++ ];
  22225. }
  22226. this.targetObject.needsUpdate = true;
  22227. },
  22228. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22229. var dest = this.resolvedProperty;
  22230. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  22231. dest[ i ] = buffer[ offset ++ ];
  22232. }
  22233. this.targetObject.matrixWorldNeedsUpdate = true;
  22234. }
  22235. ], [
  22236. // ArrayElement
  22237. function setValue_arrayElement( buffer, offset ) {
  22238. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  22239. },
  22240. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  22241. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  22242. this.targetObject.needsUpdate = true;
  22243. },
  22244. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22245. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  22246. this.targetObject.matrixWorldNeedsUpdate = true;
  22247. }
  22248. ], [
  22249. // HasToFromArray
  22250. function setValue_fromArray( buffer, offset ) {
  22251. this.resolvedProperty.fromArray( buffer, offset );
  22252. },
  22253. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  22254. this.resolvedProperty.fromArray( buffer, offset );
  22255. this.targetObject.needsUpdate = true;
  22256. },
  22257. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22258. this.resolvedProperty.fromArray( buffer, offset );
  22259. this.targetObject.matrixWorldNeedsUpdate = true;
  22260. }
  22261. ]
  22262. ],
  22263. getValue: function getValue_unbound( targetArray, offset ) {
  22264. this.bind();
  22265. this.getValue( targetArray, offset );
  22266. // Note: This class uses a State pattern on a per-method basis:
  22267. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  22268. // prototype version of these methods with one that represents
  22269. // the bound state. When the property is not found, the methods
  22270. // become no-ops.
  22271. },
  22272. setValue: function getValue_unbound( sourceArray, offset ) {
  22273. this.bind();
  22274. this.setValue( sourceArray, offset );
  22275. },
  22276. // create getter / setter pair for a property in the scene graph
  22277. bind: function () {
  22278. var targetObject = this.node,
  22279. parsedPath = this.parsedPath,
  22280. objectName = parsedPath.objectName,
  22281. propertyName = parsedPath.propertyName,
  22282. propertyIndex = parsedPath.propertyIndex;
  22283. if ( ! targetObject ) {
  22284. targetObject = PropertyBinding.findNode(
  22285. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  22286. this.node = targetObject;
  22287. }
  22288. // set fail state so we can just 'return' on error
  22289. this.getValue = this._getValue_unavailable;
  22290. this.setValue = this._setValue_unavailable;
  22291. // ensure there is a value node
  22292. if ( ! targetObject ) {
  22293. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  22294. return;
  22295. }
  22296. if ( objectName ) {
  22297. var objectIndex = parsedPath.objectIndex;
  22298. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  22299. switch ( objectName ) {
  22300. case 'materials':
  22301. if ( ! targetObject.material ) {
  22302. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  22303. return;
  22304. }
  22305. if ( ! targetObject.material.materials ) {
  22306. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  22307. return;
  22308. }
  22309. targetObject = targetObject.material.materials;
  22310. break;
  22311. case 'bones':
  22312. if ( ! targetObject.skeleton ) {
  22313. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  22314. return;
  22315. }
  22316. // potential future optimization: skip this if propertyIndex is already an integer
  22317. // and convert the integer string to a true integer.
  22318. targetObject = targetObject.skeleton.bones;
  22319. // support resolving morphTarget names into indices.
  22320. for ( var i = 0; i < targetObject.length; i ++ ) {
  22321. if ( targetObject[ i ].name === objectIndex ) {
  22322. objectIndex = i;
  22323. break;
  22324. }
  22325. }
  22326. break;
  22327. default:
  22328. if ( targetObject[ objectName ] === undefined ) {
  22329. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  22330. return;
  22331. }
  22332. targetObject = targetObject[ objectName ];
  22333. }
  22334. if ( objectIndex !== undefined ) {
  22335. if ( targetObject[ objectIndex ] === undefined ) {
  22336. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  22337. return;
  22338. }
  22339. targetObject = targetObject[ objectIndex ];
  22340. }
  22341. }
  22342. // resolve property
  22343. var nodeProperty = targetObject[ propertyName ];
  22344. if ( nodeProperty === undefined ) {
  22345. var nodeName = parsedPath.nodeName;
  22346. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  22347. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  22348. return;
  22349. }
  22350. // determine versioning scheme
  22351. var versioning = this.Versioning.None;
  22352. if ( targetObject.needsUpdate !== undefined ) { // material
  22353. versioning = this.Versioning.NeedsUpdate;
  22354. this.targetObject = targetObject;
  22355. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  22356. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  22357. this.targetObject = targetObject;
  22358. }
  22359. // determine how the property gets bound
  22360. var bindingType = this.BindingType.Direct;
  22361. if ( propertyIndex !== undefined ) {
  22362. // access a sub element of the property array (only primitives are supported right now)
  22363. if ( propertyName === "morphTargetInfluences" ) {
  22364. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  22365. // support resolving morphTarget names into indices.
  22366. if ( ! targetObject.geometry ) {
  22367. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  22368. return;
  22369. }
  22370. if ( targetObject.geometry.isBufferGeometry ) {
  22371. if ( ! targetObject.geometry.morphAttributes ) {
  22372. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  22373. return;
  22374. }
  22375. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  22376. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  22377. propertyIndex = i;
  22378. break;
  22379. }
  22380. }
  22381. } else {
  22382. if ( ! targetObject.geometry.morphTargets ) {
  22383. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  22384. return;
  22385. }
  22386. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  22387. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  22388. propertyIndex = i;
  22389. break;
  22390. }
  22391. }
  22392. }
  22393. }
  22394. bindingType = this.BindingType.ArrayElement;
  22395. this.resolvedProperty = nodeProperty;
  22396. this.propertyIndex = propertyIndex;
  22397. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  22398. // must use copy for Object3D.Euler/Quaternion
  22399. bindingType = this.BindingType.HasFromToArray;
  22400. this.resolvedProperty = nodeProperty;
  22401. } else if ( Array.isArray( nodeProperty ) ) {
  22402. bindingType = this.BindingType.EntireArray;
  22403. this.resolvedProperty = nodeProperty;
  22404. } else {
  22405. this.propertyName = propertyName;
  22406. }
  22407. // select getter / setter
  22408. this.getValue = this.GetterByBindingType[ bindingType ];
  22409. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  22410. },
  22411. unbind: function () {
  22412. this.node = null;
  22413. // back to the prototype version of getValue / setValue
  22414. // note: avoiding to mutate the shape of 'this' via 'delete'
  22415. this.getValue = this._getValue_unbound;
  22416. this.setValue = this._setValue_unbound;
  22417. }
  22418. } );
  22419. //!\ DECLARE ALIAS AFTER assign prototype !
  22420. Object.assign( PropertyBinding.prototype, {
  22421. // initial state of these methods that calls 'bind'
  22422. _getValue_unbound: PropertyBinding.prototype.getValue,
  22423. _setValue_unbound: PropertyBinding.prototype.setValue,
  22424. } );
  22425. /**
  22426. *
  22427. * A group of objects that receives a shared animation state.
  22428. *
  22429. * Usage:
  22430. *
  22431. * - Add objects you would otherwise pass as 'root' to the
  22432. * constructor or the .clipAction method of AnimationMixer.
  22433. *
  22434. * - Instead pass this object as 'root'.
  22435. *
  22436. * - You can also add and remove objects later when the mixer
  22437. * is running.
  22438. *
  22439. * Note:
  22440. *
  22441. * Objects of this class appear as one object to the mixer,
  22442. * so cache control of the individual objects must be done
  22443. * on the group.
  22444. *
  22445. * Limitation:
  22446. *
  22447. * - The animated properties must be compatible among the
  22448. * all objects in the group.
  22449. *
  22450. * - A single property can either be controlled through a
  22451. * target group or directly, but not both.
  22452. *
  22453. * @author tschw
  22454. */
  22455. function AnimationObjectGroup( var_args ) {
  22456. this.uuid = _Math.generateUUID();
  22457. // cached objects followed by the active ones
  22458. this._objects = Array.prototype.slice.call( arguments );
  22459. this.nCachedObjects_ = 0; // threshold
  22460. // note: read by PropertyBinding.Composite
  22461. var indices = {};
  22462. this._indicesByUUID = indices; // for bookkeeping
  22463. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22464. indices[ arguments[ i ].uuid ] = i;
  22465. }
  22466. this._paths = []; // inside: string
  22467. this._parsedPaths = []; // inside: { we don't care, here }
  22468. this._bindings = []; // inside: Array< PropertyBinding >
  22469. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  22470. var scope = this;
  22471. this.stats = {
  22472. objects: {
  22473. get total() { return scope._objects.length; },
  22474. get inUse() { return this.total - scope.nCachedObjects_; }
  22475. },
  22476. get bindingsPerObject() { return scope._bindings.length; }
  22477. };
  22478. }
  22479. Object.assign( AnimationObjectGroup.prototype, {
  22480. isAnimationObjectGroup: true,
  22481. add: function( var_args ) {
  22482. var objects = this._objects,
  22483. nObjects = objects.length,
  22484. nCachedObjects = this.nCachedObjects_,
  22485. indicesByUUID = this._indicesByUUID,
  22486. paths = this._paths,
  22487. parsedPaths = this._parsedPaths,
  22488. bindings = this._bindings,
  22489. nBindings = bindings.length;
  22490. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22491. var object = arguments[ i ],
  22492. uuid = object.uuid,
  22493. index = indicesByUUID[ uuid ],
  22494. knownObject = undefined;
  22495. if ( index === undefined ) {
  22496. // unknown object -> add it to the ACTIVE region
  22497. index = nObjects ++;
  22498. indicesByUUID[ uuid ] = index;
  22499. objects.push( object );
  22500. // accounting is done, now do the same for all bindings
  22501. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22502. bindings[ j ].push(
  22503. new PropertyBinding(
  22504. object, paths[ j ], parsedPaths[ j ] ) );
  22505. }
  22506. } else if ( index < nCachedObjects ) {
  22507. knownObject = objects[ index ];
  22508. // move existing object to the ACTIVE region
  22509. var firstActiveIndex = -- nCachedObjects,
  22510. lastCachedObject = objects[ firstActiveIndex ];
  22511. indicesByUUID[ lastCachedObject.uuid ] = index;
  22512. objects[ index ] = lastCachedObject;
  22513. indicesByUUID[ uuid ] = firstActiveIndex;
  22514. objects[ firstActiveIndex ] = object;
  22515. // accounting is done, now do the same for all bindings
  22516. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22517. var bindingsForPath = bindings[ j ],
  22518. lastCached = bindingsForPath[ firstActiveIndex ],
  22519. binding = bindingsForPath[ index ];
  22520. bindingsForPath[ index ] = lastCached;
  22521. if ( binding === undefined ) {
  22522. // since we do not bother to create new bindings
  22523. // for objects that are cached, the binding may
  22524. // or may not exist
  22525. binding = new PropertyBinding(
  22526. object, paths[ j ], parsedPaths[ j ] );
  22527. }
  22528. bindingsForPath[ firstActiveIndex ] = binding;
  22529. }
  22530. } else if ( objects[ index ] !== knownObject ) {
  22531. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  22532. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  22533. } // else the object is already where we want it to be
  22534. } // for arguments
  22535. this.nCachedObjects_ = nCachedObjects;
  22536. },
  22537. remove: function( var_args ) {
  22538. var objects = this._objects,
  22539. nCachedObjects = this.nCachedObjects_,
  22540. indicesByUUID = this._indicesByUUID,
  22541. bindings = this._bindings,
  22542. nBindings = bindings.length;
  22543. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22544. var object = arguments[ i ],
  22545. uuid = object.uuid,
  22546. index = indicesByUUID[ uuid ];
  22547. if ( index !== undefined && index >= nCachedObjects ) {
  22548. // move existing object into the CACHED region
  22549. var lastCachedIndex = nCachedObjects ++,
  22550. firstActiveObject = objects[ lastCachedIndex ];
  22551. indicesByUUID[ firstActiveObject.uuid ] = index;
  22552. objects[ index ] = firstActiveObject;
  22553. indicesByUUID[ uuid ] = lastCachedIndex;
  22554. objects[ lastCachedIndex ] = object;
  22555. // accounting is done, now do the same for all bindings
  22556. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22557. var bindingsForPath = bindings[ j ],
  22558. firstActive = bindingsForPath[ lastCachedIndex ],
  22559. binding = bindingsForPath[ index ];
  22560. bindingsForPath[ index ] = firstActive;
  22561. bindingsForPath[ lastCachedIndex ] = binding;
  22562. }
  22563. }
  22564. } // for arguments
  22565. this.nCachedObjects_ = nCachedObjects;
  22566. },
  22567. // remove & forget
  22568. uncache: function( var_args ) {
  22569. var objects = this._objects,
  22570. nObjects = objects.length,
  22571. nCachedObjects = this.nCachedObjects_,
  22572. indicesByUUID = this._indicesByUUID,
  22573. bindings = this._bindings,
  22574. nBindings = bindings.length;
  22575. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22576. var object = arguments[ i ],
  22577. uuid = object.uuid,
  22578. index = indicesByUUID[ uuid ];
  22579. if ( index !== undefined ) {
  22580. delete indicesByUUID[ uuid ];
  22581. if ( index < nCachedObjects ) {
  22582. // object is cached, shrink the CACHED region
  22583. var firstActiveIndex = -- nCachedObjects,
  22584. lastCachedObject = objects[ firstActiveIndex ],
  22585. lastIndex = -- nObjects,
  22586. lastObject = objects[ lastIndex ];
  22587. // last cached object takes this object's place
  22588. indicesByUUID[ lastCachedObject.uuid ] = index;
  22589. objects[ index ] = lastCachedObject;
  22590. // last object goes to the activated slot and pop
  22591. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  22592. objects[ firstActiveIndex ] = lastObject;
  22593. objects.pop();
  22594. // accounting is done, now do the same for all bindings
  22595. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22596. var bindingsForPath = bindings[ j ],
  22597. lastCached = bindingsForPath[ firstActiveIndex ],
  22598. last = bindingsForPath[ lastIndex ];
  22599. bindingsForPath[ index ] = lastCached;
  22600. bindingsForPath[ firstActiveIndex ] = last;
  22601. bindingsForPath.pop();
  22602. }
  22603. } else {
  22604. // object is active, just swap with the last and pop
  22605. var lastIndex = -- nObjects,
  22606. lastObject = objects[ lastIndex ];
  22607. indicesByUUID[ lastObject.uuid ] = index;
  22608. objects[ index ] = lastObject;
  22609. objects.pop();
  22610. // accounting is done, now do the same for all bindings
  22611. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22612. var bindingsForPath = bindings[ j ];
  22613. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  22614. bindingsForPath.pop();
  22615. }
  22616. } // cached or active
  22617. } // if object is known
  22618. } // for arguments
  22619. this.nCachedObjects_ = nCachedObjects;
  22620. },
  22621. // Internal interface used by befriended PropertyBinding.Composite:
  22622. subscribe_: function ( path, parsedPath ) {
  22623. // returns an array of bindings for the given path that is changed
  22624. // according to the contained objects in the group
  22625. var indicesByPath = this._bindingsIndicesByPath,
  22626. index = indicesByPath[ path ],
  22627. bindings = this._bindings;
  22628. if ( index !== undefined ) return bindings[ index ];
  22629. var paths = this._paths,
  22630. parsedPaths = this._parsedPaths,
  22631. objects = this._objects,
  22632. nObjects = objects.length,
  22633. nCachedObjects = this.nCachedObjects_,
  22634. bindingsForPath = new Array( nObjects );
  22635. index = bindings.length;
  22636. indicesByPath[ path ] = index;
  22637. paths.push( path );
  22638. parsedPaths.push( parsedPath );
  22639. bindings.push( bindingsForPath );
  22640. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  22641. var object = objects[ i ];
  22642. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  22643. }
  22644. return bindingsForPath;
  22645. },
  22646. unsubscribe_: function ( path ) {
  22647. // tells the group to forget about a property path and no longer
  22648. // update the array previously obtained with 'subscribe_'
  22649. var indicesByPath = this._bindingsIndicesByPath,
  22650. index = indicesByPath[ path ];
  22651. if ( index !== undefined ) {
  22652. var paths = this._paths,
  22653. parsedPaths = this._parsedPaths,
  22654. bindings = this._bindings,
  22655. lastBindingsIndex = bindings.length - 1,
  22656. lastBindings = bindings[ lastBindingsIndex ],
  22657. lastBindingsPath = path[ lastBindingsIndex ];
  22658. indicesByPath[ lastBindingsPath ] = index;
  22659. bindings[ index ] = lastBindings;
  22660. bindings.pop();
  22661. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  22662. parsedPaths.pop();
  22663. paths[ index ] = paths[ lastBindingsIndex ];
  22664. paths.pop();
  22665. }
  22666. }
  22667. } );
  22668. /**
  22669. *
  22670. * Action provided by AnimationMixer for scheduling clip playback on specific
  22671. * objects.
  22672. *
  22673. * @author Ben Houston / http://clara.io/
  22674. * @author David Sarno / http://lighthaus.us/
  22675. * @author tschw
  22676. *
  22677. */
  22678. function AnimationAction( mixer, clip, localRoot ) {
  22679. this._mixer = mixer;
  22680. this._clip = clip;
  22681. this._localRoot = localRoot || null;
  22682. var tracks = clip.tracks,
  22683. nTracks = tracks.length,
  22684. interpolants = new Array( nTracks );
  22685. var interpolantSettings = {
  22686. endingStart: ZeroCurvatureEnding,
  22687. endingEnd: ZeroCurvatureEnding
  22688. };
  22689. for ( var i = 0; i !== nTracks; ++ i ) {
  22690. var interpolant = tracks[ i ].createInterpolant( null );
  22691. interpolants[ i ] = interpolant;
  22692. interpolant.settings = interpolantSettings;
  22693. }
  22694. this._interpolantSettings = interpolantSettings;
  22695. this._interpolants = interpolants; // bound by the mixer
  22696. // inside: PropertyMixer (managed by the mixer)
  22697. this._propertyBindings = new Array( nTracks );
  22698. this._cacheIndex = null; // for the memory manager
  22699. this._byClipCacheIndex = null; // for the memory manager
  22700. this._timeScaleInterpolant = null;
  22701. this._weightInterpolant = null;
  22702. this.loop = LoopRepeat;
  22703. this._loopCount = -1;
  22704. // global mixer time when the action is to be started
  22705. // it's set back to 'null' upon start of the action
  22706. this._startTime = null;
  22707. // scaled local time of the action
  22708. // gets clamped or wrapped to 0..clip.duration according to loop
  22709. this.time = 0;
  22710. this.timeScale = 1;
  22711. this._effectiveTimeScale = 1;
  22712. this.weight = 1;
  22713. this._effectiveWeight = 1;
  22714. this.repetitions = Infinity; // no. of repetitions when looping
  22715. this.paused = false; // true -> zero effective time scale
  22716. this.enabled = true; // false -> zero effective weight
  22717. this.clampWhenFinished = false; // keep feeding the last frame?
  22718. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  22719. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  22720. }
  22721. Object.assign( AnimationAction.prototype, {
  22722. // State & Scheduling
  22723. play: function() {
  22724. this._mixer._activateAction( this );
  22725. return this;
  22726. },
  22727. stop: function() {
  22728. this._mixer._deactivateAction( this );
  22729. return this.reset();
  22730. },
  22731. reset: function() {
  22732. this.paused = false;
  22733. this.enabled = true;
  22734. this.time = 0; // restart clip
  22735. this._loopCount = -1; // forget previous loops
  22736. this._startTime = null; // forget scheduling
  22737. return this.stopFading().stopWarping();
  22738. },
  22739. isRunning: function() {
  22740. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  22741. this._startTime === null && this._mixer._isActiveAction( this );
  22742. },
  22743. // return true when play has been called
  22744. isScheduled: function() {
  22745. return this._mixer._isActiveAction( this );
  22746. },
  22747. startAt: function( time ) {
  22748. this._startTime = time;
  22749. return this;
  22750. },
  22751. setLoop: function( mode, repetitions ) {
  22752. this.loop = mode;
  22753. this.repetitions = repetitions;
  22754. return this;
  22755. },
  22756. // Weight
  22757. // set the weight stopping any scheduled fading
  22758. // although .enabled = false yields an effective weight of zero, this
  22759. // method does *not* change .enabled, because it would be confusing
  22760. setEffectiveWeight: function( weight ) {
  22761. this.weight = weight;
  22762. // note: same logic as when updated at runtime
  22763. this._effectiveWeight = this.enabled ? weight : 0;
  22764. return this.stopFading();
  22765. },
  22766. // return the weight considering fading and .enabled
  22767. getEffectiveWeight: function() {
  22768. return this._effectiveWeight;
  22769. },
  22770. fadeIn: function( duration ) {
  22771. return this._scheduleFading( duration, 0, 1 );
  22772. },
  22773. fadeOut: function( duration ) {
  22774. return this._scheduleFading( duration, 1, 0 );
  22775. },
  22776. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  22777. fadeOutAction.fadeOut( duration );
  22778. this.fadeIn( duration );
  22779. if( warp ) {
  22780. var fadeInDuration = this._clip.duration,
  22781. fadeOutDuration = fadeOutAction._clip.duration,
  22782. startEndRatio = fadeOutDuration / fadeInDuration,
  22783. endStartRatio = fadeInDuration / fadeOutDuration;
  22784. fadeOutAction.warp( 1.0, startEndRatio, duration );
  22785. this.warp( endStartRatio, 1.0, duration );
  22786. }
  22787. return this;
  22788. },
  22789. crossFadeTo: function( fadeInAction, duration, warp ) {
  22790. return fadeInAction.crossFadeFrom( this, duration, warp );
  22791. },
  22792. stopFading: function() {
  22793. var weightInterpolant = this._weightInterpolant;
  22794. if ( weightInterpolant !== null ) {
  22795. this._weightInterpolant = null;
  22796. this._mixer._takeBackControlInterpolant( weightInterpolant );
  22797. }
  22798. return this;
  22799. },
  22800. // Time Scale Control
  22801. // set the time scale stopping any scheduled warping
  22802. // although .paused = true yields an effective time scale of zero, this
  22803. // method does *not* change .paused, because it would be confusing
  22804. setEffectiveTimeScale: function( timeScale ) {
  22805. this.timeScale = timeScale;
  22806. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  22807. return this.stopWarping();
  22808. },
  22809. // return the time scale considering warping and .paused
  22810. getEffectiveTimeScale: function() {
  22811. return this._effectiveTimeScale;
  22812. },
  22813. setDuration: function( duration ) {
  22814. this.timeScale = this._clip.duration / duration;
  22815. return this.stopWarping();
  22816. },
  22817. syncWith: function( action ) {
  22818. this.time = action.time;
  22819. this.timeScale = action.timeScale;
  22820. return this.stopWarping();
  22821. },
  22822. halt: function( duration ) {
  22823. return this.warp( this._effectiveTimeScale, 0, duration );
  22824. },
  22825. warp: function( startTimeScale, endTimeScale, duration ) {
  22826. var mixer = this._mixer, now = mixer.time,
  22827. interpolant = this._timeScaleInterpolant,
  22828. timeScale = this.timeScale;
  22829. if ( interpolant === null ) {
  22830. interpolant = mixer._lendControlInterpolant();
  22831. this._timeScaleInterpolant = interpolant;
  22832. }
  22833. var times = interpolant.parameterPositions,
  22834. values = interpolant.sampleValues;
  22835. times[ 0 ] = now;
  22836. times[ 1 ] = now + duration;
  22837. values[ 0 ] = startTimeScale / timeScale;
  22838. values[ 1 ] = endTimeScale / timeScale;
  22839. return this;
  22840. },
  22841. stopWarping: function() {
  22842. var timeScaleInterpolant = this._timeScaleInterpolant;
  22843. if ( timeScaleInterpolant !== null ) {
  22844. this._timeScaleInterpolant = null;
  22845. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  22846. }
  22847. return this;
  22848. },
  22849. // Object Accessors
  22850. getMixer: function() {
  22851. return this._mixer;
  22852. },
  22853. getClip: function() {
  22854. return this._clip;
  22855. },
  22856. getRoot: function() {
  22857. return this._localRoot || this._mixer._root;
  22858. },
  22859. // Interna
  22860. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  22861. // called by the mixer
  22862. if ( ! this.enabled ) {
  22863. // call ._updateWeight() to update ._effectiveWeight
  22864. this._updateWeight( time );
  22865. return;
  22866. }
  22867. var startTime = this._startTime;
  22868. if ( startTime !== null ) {
  22869. // check for scheduled start of action
  22870. var timeRunning = ( time - startTime ) * timeDirection;
  22871. if ( timeRunning < 0 || timeDirection === 0 ) {
  22872. return; // yet to come / don't decide when delta = 0
  22873. }
  22874. // start
  22875. this._startTime = null; // unschedule
  22876. deltaTime = timeDirection * timeRunning;
  22877. }
  22878. // apply time scale and advance time
  22879. deltaTime *= this._updateTimeScale( time );
  22880. var clipTime = this._updateTime( deltaTime );
  22881. // note: _updateTime may disable the action resulting in
  22882. // an effective weight of 0
  22883. var weight = this._updateWeight( time );
  22884. if ( weight > 0 ) {
  22885. var interpolants = this._interpolants;
  22886. var propertyMixers = this._propertyBindings;
  22887. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  22888. interpolants[ j ].evaluate( clipTime );
  22889. propertyMixers[ j ].accumulate( accuIndex, weight );
  22890. }
  22891. }
  22892. },
  22893. _updateWeight: function( time ) {
  22894. var weight = 0;
  22895. if ( this.enabled ) {
  22896. weight = this.weight;
  22897. var interpolant = this._weightInterpolant;
  22898. if ( interpolant !== null ) {
  22899. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  22900. weight *= interpolantValue;
  22901. if ( time > interpolant.parameterPositions[ 1 ] ) {
  22902. this.stopFading();
  22903. if ( interpolantValue === 0 ) {
  22904. // faded out, disable
  22905. this.enabled = false;
  22906. }
  22907. }
  22908. }
  22909. }
  22910. this._effectiveWeight = weight;
  22911. return weight;
  22912. },
  22913. _updateTimeScale: function( time ) {
  22914. var timeScale = 0;
  22915. if ( ! this.paused ) {
  22916. timeScale = this.timeScale;
  22917. var interpolant = this._timeScaleInterpolant;
  22918. if ( interpolant !== null ) {
  22919. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  22920. timeScale *= interpolantValue;
  22921. if ( time > interpolant.parameterPositions[ 1 ] ) {
  22922. this.stopWarping();
  22923. if ( timeScale === 0 ) {
  22924. // motion has halted, pause
  22925. this.paused = true;
  22926. } else {
  22927. // warp done - apply final time scale
  22928. this.timeScale = timeScale;
  22929. }
  22930. }
  22931. }
  22932. }
  22933. this._effectiveTimeScale = timeScale;
  22934. return timeScale;
  22935. },
  22936. _updateTime: function( deltaTime ) {
  22937. var time = this.time + deltaTime;
  22938. if ( deltaTime === 0 ) return time;
  22939. var duration = this._clip.duration,
  22940. loop = this.loop,
  22941. loopCount = this._loopCount;
  22942. if ( loop === LoopOnce ) {
  22943. if ( loopCount === -1 ) {
  22944. // just started
  22945. this._loopCount = 0;
  22946. this._setEndings( true, true, false );
  22947. }
  22948. handle_stop: {
  22949. if ( time >= duration ) {
  22950. time = duration;
  22951. } else if ( time < 0 ) {
  22952. time = 0;
  22953. } else break handle_stop;
  22954. if ( this.clampWhenFinished ) this.paused = true;
  22955. else this.enabled = false;
  22956. this._mixer.dispatchEvent( {
  22957. type: 'finished', action: this,
  22958. direction: deltaTime < 0 ? -1 : 1
  22959. } );
  22960. }
  22961. } else { // repetitive Repeat or PingPong
  22962. var pingPong = ( loop === LoopPingPong );
  22963. if ( loopCount === -1 ) {
  22964. // just started
  22965. if ( deltaTime >= 0 ) {
  22966. loopCount = 0;
  22967. this._setEndings(
  22968. true, this.repetitions === 0, pingPong );
  22969. } else {
  22970. // when looping in reverse direction, the initial
  22971. // transition through zero counts as a repetition,
  22972. // so leave loopCount at -1
  22973. this._setEndings(
  22974. this.repetitions === 0, true, pingPong );
  22975. }
  22976. }
  22977. if ( time >= duration || time < 0 ) {
  22978. // wrap around
  22979. var loopDelta = Math.floor( time / duration ); // signed
  22980. time -= duration * loopDelta;
  22981. loopCount += Math.abs( loopDelta );
  22982. var pending = this.repetitions - loopCount;
  22983. if ( pending < 0 ) {
  22984. // have to stop (switch state, clamp time, fire event)
  22985. if ( this.clampWhenFinished ) this.paused = true;
  22986. else this.enabled = false;
  22987. time = deltaTime > 0 ? duration : 0;
  22988. this._mixer.dispatchEvent( {
  22989. type: 'finished', action: this,
  22990. direction: deltaTime > 0 ? 1 : -1
  22991. } );
  22992. } else {
  22993. // keep running
  22994. if ( pending === 0 ) {
  22995. // entering the last round
  22996. var atStart = deltaTime < 0;
  22997. this._setEndings( atStart, ! atStart, pingPong );
  22998. } else {
  22999. this._setEndings( false, false, pingPong );
  23000. }
  23001. this._loopCount = loopCount;
  23002. this._mixer.dispatchEvent( {
  23003. type: 'loop', action: this, loopDelta: loopDelta
  23004. } );
  23005. }
  23006. }
  23007. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  23008. // invert time for the "pong round"
  23009. this.time = time;
  23010. return duration - time;
  23011. }
  23012. }
  23013. this.time = time;
  23014. return time;
  23015. },
  23016. _setEndings: function( atStart, atEnd, pingPong ) {
  23017. var settings = this._interpolantSettings;
  23018. if ( pingPong ) {
  23019. settings.endingStart = ZeroSlopeEnding;
  23020. settings.endingEnd = ZeroSlopeEnding;
  23021. } else {
  23022. // assuming for LoopOnce atStart == atEnd == true
  23023. if ( atStart ) {
  23024. settings.endingStart = this.zeroSlopeAtStart ?
  23025. ZeroSlopeEnding : ZeroCurvatureEnding;
  23026. } else {
  23027. settings.endingStart = WrapAroundEnding;
  23028. }
  23029. if ( atEnd ) {
  23030. settings.endingEnd = this.zeroSlopeAtEnd ?
  23031. ZeroSlopeEnding : ZeroCurvatureEnding;
  23032. } else {
  23033. settings.endingEnd = WrapAroundEnding;
  23034. }
  23035. }
  23036. },
  23037. _scheduleFading: function( duration, weightNow, weightThen ) {
  23038. var mixer = this._mixer, now = mixer.time,
  23039. interpolant = this._weightInterpolant;
  23040. if ( interpolant === null ) {
  23041. interpolant = mixer._lendControlInterpolant();
  23042. this._weightInterpolant = interpolant;
  23043. }
  23044. var times = interpolant.parameterPositions,
  23045. values = interpolant.sampleValues;
  23046. times[ 0 ] = now; values[ 0 ] = weightNow;
  23047. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  23048. return this;
  23049. }
  23050. } );
  23051. /**
  23052. *
  23053. * Player for AnimationClips.
  23054. *
  23055. *
  23056. * @author Ben Houston / http://clara.io/
  23057. * @author David Sarno / http://lighthaus.us/
  23058. * @author tschw
  23059. */
  23060. function AnimationMixer( root ) {
  23061. this._root = root;
  23062. this._initMemoryManager();
  23063. this._accuIndex = 0;
  23064. this.time = 0;
  23065. this.timeScale = 1.0;
  23066. }
  23067. Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, {
  23068. _bindAction: function ( action, prototypeAction ) {
  23069. var root = action._localRoot || this._root,
  23070. tracks = action._clip.tracks,
  23071. nTracks = tracks.length,
  23072. bindings = action._propertyBindings,
  23073. interpolants = action._interpolants,
  23074. rootUuid = root.uuid,
  23075. bindingsByRoot = this._bindingsByRootAndName,
  23076. bindingsByName = bindingsByRoot[ rootUuid ];
  23077. if ( bindingsByName === undefined ) {
  23078. bindingsByName = {};
  23079. bindingsByRoot[ rootUuid ] = bindingsByName;
  23080. }
  23081. for ( var i = 0; i !== nTracks; ++ i ) {
  23082. var track = tracks[ i ],
  23083. trackName = track.name,
  23084. binding = bindingsByName[ trackName ];
  23085. if ( binding !== undefined ) {
  23086. bindings[ i ] = binding;
  23087. } else {
  23088. binding = bindings[ i ];
  23089. if ( binding !== undefined ) {
  23090. // existing binding, make sure the cache knows
  23091. if ( binding._cacheIndex === null ) {
  23092. ++ binding.referenceCount;
  23093. this._addInactiveBinding( binding, rootUuid, trackName );
  23094. }
  23095. continue;
  23096. }
  23097. var path = prototypeAction && prototypeAction.
  23098. _propertyBindings[ i ].binding.parsedPath;
  23099. binding = new PropertyMixer(
  23100. PropertyBinding.create( root, trackName, path ),
  23101. track.ValueTypeName, track.getValueSize() );
  23102. ++ binding.referenceCount;
  23103. this._addInactiveBinding( binding, rootUuid, trackName );
  23104. bindings[ i ] = binding;
  23105. }
  23106. interpolants[ i ].resultBuffer = binding.buffer;
  23107. }
  23108. },
  23109. _activateAction: function ( action ) {
  23110. if ( ! this._isActiveAction( action ) ) {
  23111. if ( action._cacheIndex === null ) {
  23112. // this action has been forgotten by the cache, but the user
  23113. // appears to be still using it -> rebind
  23114. var rootUuid = ( action._localRoot || this._root ).uuid,
  23115. clipUuid = action._clip.uuid,
  23116. actionsForClip = this._actionsByClip[ clipUuid ];
  23117. this._bindAction( action,
  23118. actionsForClip && actionsForClip.knownActions[ 0 ] );
  23119. this._addInactiveAction( action, clipUuid, rootUuid );
  23120. }
  23121. var bindings = action._propertyBindings;
  23122. // increment reference counts / sort out state
  23123. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  23124. var binding = bindings[ i ];
  23125. if ( binding.useCount ++ === 0 ) {
  23126. this._lendBinding( binding );
  23127. binding.saveOriginalState();
  23128. }
  23129. }
  23130. this._lendAction( action );
  23131. }
  23132. },
  23133. _deactivateAction: function ( action ) {
  23134. if ( this._isActiveAction( action ) ) {
  23135. var bindings = action._propertyBindings;
  23136. // decrement reference counts / sort out state
  23137. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  23138. var binding = bindings[ i ];
  23139. if ( -- binding.useCount === 0 ) {
  23140. binding.restoreOriginalState();
  23141. this._takeBackBinding( binding );
  23142. }
  23143. }
  23144. this._takeBackAction( action );
  23145. }
  23146. },
  23147. // Memory manager
  23148. _initMemoryManager: function () {
  23149. this._actions = []; // 'nActiveActions' followed by inactive ones
  23150. this._nActiveActions = 0;
  23151. this._actionsByClip = {};
  23152. // inside:
  23153. // {
  23154. // knownActions: Array< AnimationAction > - used as prototypes
  23155. // actionByRoot: AnimationAction - lookup
  23156. // }
  23157. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  23158. this._nActiveBindings = 0;
  23159. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  23160. this._controlInterpolants = []; // same game as above
  23161. this._nActiveControlInterpolants = 0;
  23162. var scope = this;
  23163. this.stats = {
  23164. actions: {
  23165. get total() { return scope._actions.length; },
  23166. get inUse() { return scope._nActiveActions; }
  23167. },
  23168. bindings: {
  23169. get total() { return scope._bindings.length; },
  23170. get inUse() { return scope._nActiveBindings; }
  23171. },
  23172. controlInterpolants: {
  23173. get total() { return scope._controlInterpolants.length; },
  23174. get inUse() { return scope._nActiveControlInterpolants; }
  23175. }
  23176. };
  23177. },
  23178. // Memory management for AnimationAction objects
  23179. _isActiveAction: function ( action ) {
  23180. var index = action._cacheIndex;
  23181. return index !== null && index < this._nActiveActions;
  23182. },
  23183. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  23184. var actions = this._actions,
  23185. actionsByClip = this._actionsByClip,
  23186. actionsForClip = actionsByClip[ clipUuid ];
  23187. if ( actionsForClip === undefined ) {
  23188. actionsForClip = {
  23189. knownActions: [ action ],
  23190. actionByRoot: {}
  23191. };
  23192. action._byClipCacheIndex = 0;
  23193. actionsByClip[ clipUuid ] = actionsForClip;
  23194. } else {
  23195. var knownActions = actionsForClip.knownActions;
  23196. action._byClipCacheIndex = knownActions.length;
  23197. knownActions.push( action );
  23198. }
  23199. action._cacheIndex = actions.length;
  23200. actions.push( action );
  23201. actionsForClip.actionByRoot[ rootUuid ] = action;
  23202. },
  23203. _removeInactiveAction: function ( action ) {
  23204. var actions = this._actions,
  23205. lastInactiveAction = actions[ actions.length - 1 ],
  23206. cacheIndex = action._cacheIndex;
  23207. lastInactiveAction._cacheIndex = cacheIndex;
  23208. actions[ cacheIndex ] = lastInactiveAction;
  23209. actions.pop();
  23210. action._cacheIndex = null;
  23211. var clipUuid = action._clip.uuid,
  23212. actionsByClip = this._actionsByClip,
  23213. actionsForClip = actionsByClip[ clipUuid ],
  23214. knownActionsForClip = actionsForClip.knownActions,
  23215. lastKnownAction =
  23216. knownActionsForClip[ knownActionsForClip.length - 1 ],
  23217. byClipCacheIndex = action._byClipCacheIndex;
  23218. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  23219. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  23220. knownActionsForClip.pop();
  23221. action._byClipCacheIndex = null;
  23222. var actionByRoot = actionsForClip.actionByRoot,
  23223. rootUuid = ( action._localRoot || this._root ).uuid;
  23224. delete actionByRoot[ rootUuid ];
  23225. if ( knownActionsForClip.length === 0 ) {
  23226. delete actionsByClip[ clipUuid ];
  23227. }
  23228. this._removeInactiveBindingsForAction( action );
  23229. },
  23230. _removeInactiveBindingsForAction: function ( action ) {
  23231. var bindings = action._propertyBindings;
  23232. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  23233. var binding = bindings[ i ];
  23234. if ( -- binding.referenceCount === 0 ) {
  23235. this._removeInactiveBinding( binding );
  23236. }
  23237. }
  23238. },
  23239. _lendAction: function ( action ) {
  23240. // [ active actions | inactive actions ]
  23241. // [ active actions >| inactive actions ]
  23242. // s a
  23243. // <-swap->
  23244. // a s
  23245. var actions = this._actions,
  23246. prevIndex = action._cacheIndex,
  23247. lastActiveIndex = this._nActiveActions ++,
  23248. firstInactiveAction = actions[ lastActiveIndex ];
  23249. action._cacheIndex = lastActiveIndex;
  23250. actions[ lastActiveIndex ] = action;
  23251. firstInactiveAction._cacheIndex = prevIndex;
  23252. actions[ prevIndex ] = firstInactiveAction;
  23253. },
  23254. _takeBackAction: function ( action ) {
  23255. // [ active actions | inactive actions ]
  23256. // [ active actions |< inactive actions ]
  23257. // a s
  23258. // <-swap->
  23259. // s a
  23260. var actions = this._actions,
  23261. prevIndex = action._cacheIndex,
  23262. firstInactiveIndex = -- this._nActiveActions,
  23263. lastActiveAction = actions[ firstInactiveIndex ];
  23264. action._cacheIndex = firstInactiveIndex;
  23265. actions[ firstInactiveIndex ] = action;
  23266. lastActiveAction._cacheIndex = prevIndex;
  23267. actions[ prevIndex ] = lastActiveAction;
  23268. },
  23269. // Memory management for PropertyMixer objects
  23270. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  23271. var bindingsByRoot = this._bindingsByRootAndName,
  23272. bindingByName = bindingsByRoot[ rootUuid ],
  23273. bindings = this._bindings;
  23274. if ( bindingByName === undefined ) {
  23275. bindingByName = {};
  23276. bindingsByRoot[ rootUuid ] = bindingByName;
  23277. }
  23278. bindingByName[ trackName ] = binding;
  23279. binding._cacheIndex = bindings.length;
  23280. bindings.push( binding );
  23281. },
  23282. _removeInactiveBinding: function ( binding ) {
  23283. var bindings = this._bindings,
  23284. propBinding = binding.binding,
  23285. rootUuid = propBinding.rootNode.uuid,
  23286. trackName = propBinding.path,
  23287. bindingsByRoot = this._bindingsByRootAndName,
  23288. bindingByName = bindingsByRoot[ rootUuid ],
  23289. lastInactiveBinding = bindings[ bindings.length - 1 ],
  23290. cacheIndex = binding._cacheIndex;
  23291. lastInactiveBinding._cacheIndex = cacheIndex;
  23292. bindings[ cacheIndex ] = lastInactiveBinding;
  23293. bindings.pop();
  23294. delete bindingByName[ trackName ];
  23295. remove_empty_map: {
  23296. for ( var _ in bindingByName ) break remove_empty_map;
  23297. delete bindingsByRoot[ rootUuid ];
  23298. }
  23299. },
  23300. _lendBinding: function ( binding ) {
  23301. var bindings = this._bindings,
  23302. prevIndex = binding._cacheIndex,
  23303. lastActiveIndex = this._nActiveBindings ++,
  23304. firstInactiveBinding = bindings[ lastActiveIndex ];
  23305. binding._cacheIndex = lastActiveIndex;
  23306. bindings[ lastActiveIndex ] = binding;
  23307. firstInactiveBinding._cacheIndex = prevIndex;
  23308. bindings[ prevIndex ] = firstInactiveBinding;
  23309. },
  23310. _takeBackBinding: function ( binding ) {
  23311. var bindings = this._bindings,
  23312. prevIndex = binding._cacheIndex,
  23313. firstInactiveIndex = -- this._nActiveBindings,
  23314. lastActiveBinding = bindings[ firstInactiveIndex ];
  23315. binding._cacheIndex = firstInactiveIndex;
  23316. bindings[ firstInactiveIndex ] = binding;
  23317. lastActiveBinding._cacheIndex = prevIndex;
  23318. bindings[ prevIndex ] = lastActiveBinding;
  23319. },
  23320. // Memory management of Interpolants for weight and time scale
  23321. _lendControlInterpolant: function () {
  23322. var interpolants = this._controlInterpolants,
  23323. lastActiveIndex = this._nActiveControlInterpolants ++,
  23324. interpolant = interpolants[ lastActiveIndex ];
  23325. if ( interpolant === undefined ) {
  23326. interpolant = new LinearInterpolant(
  23327. new Float32Array( 2 ), new Float32Array( 2 ),
  23328. 1, this._controlInterpolantsResultBuffer );
  23329. interpolant.__cacheIndex = lastActiveIndex;
  23330. interpolants[ lastActiveIndex ] = interpolant;
  23331. }
  23332. return interpolant;
  23333. },
  23334. _takeBackControlInterpolant: function ( interpolant ) {
  23335. var interpolants = this._controlInterpolants,
  23336. prevIndex = interpolant.__cacheIndex,
  23337. firstInactiveIndex = -- this._nActiveControlInterpolants,
  23338. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  23339. interpolant.__cacheIndex = firstInactiveIndex;
  23340. interpolants[ firstInactiveIndex ] = interpolant;
  23341. lastActiveInterpolant.__cacheIndex = prevIndex;
  23342. interpolants[ prevIndex ] = lastActiveInterpolant;
  23343. },
  23344. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  23345. // return an action for a clip optionally using a custom root target
  23346. // object (this method allocates a lot of dynamic memory in case a
  23347. // previously unknown clip/root combination is specified)
  23348. clipAction: function ( clip, optionalRoot ) {
  23349. var root = optionalRoot || this._root,
  23350. rootUuid = root.uuid,
  23351. clipObject = typeof clip === 'string' ?
  23352. AnimationClip.findByName( root, clip ) : clip,
  23353. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  23354. actionsForClip = this._actionsByClip[ clipUuid ],
  23355. prototypeAction = null;
  23356. if ( actionsForClip !== undefined ) {
  23357. var existingAction =
  23358. actionsForClip.actionByRoot[ rootUuid ];
  23359. if ( existingAction !== undefined ) {
  23360. return existingAction;
  23361. }
  23362. // we know the clip, so we don't have to parse all
  23363. // the bindings again but can just copy
  23364. prototypeAction = actionsForClip.knownActions[ 0 ];
  23365. // also, take the clip from the prototype action
  23366. if ( clipObject === null )
  23367. clipObject = prototypeAction._clip;
  23368. }
  23369. // clip must be known when specified via string
  23370. if ( clipObject === null ) return null;
  23371. // allocate all resources required to run it
  23372. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  23373. this._bindAction( newAction, prototypeAction );
  23374. // and make the action known to the memory manager
  23375. this._addInactiveAction( newAction, clipUuid, rootUuid );
  23376. return newAction;
  23377. },
  23378. // get an existing action
  23379. existingAction: function ( clip, optionalRoot ) {
  23380. var root = optionalRoot || this._root,
  23381. rootUuid = root.uuid,
  23382. clipObject = typeof clip === 'string' ?
  23383. AnimationClip.findByName( root, clip ) : clip,
  23384. clipUuid = clipObject ? clipObject.uuid : clip,
  23385. actionsForClip = this._actionsByClip[ clipUuid ];
  23386. if ( actionsForClip !== undefined ) {
  23387. return actionsForClip.actionByRoot[ rootUuid ] || null;
  23388. }
  23389. return null;
  23390. },
  23391. // deactivates all previously scheduled actions
  23392. stopAllAction: function () {
  23393. var actions = this._actions,
  23394. nActions = this._nActiveActions,
  23395. bindings = this._bindings,
  23396. nBindings = this._nActiveBindings;
  23397. this._nActiveActions = 0;
  23398. this._nActiveBindings = 0;
  23399. for ( var i = 0; i !== nActions; ++ i ) {
  23400. actions[ i ].reset();
  23401. }
  23402. for ( var i = 0; i !== nBindings; ++ i ) {
  23403. bindings[ i ].useCount = 0;
  23404. }
  23405. return this;
  23406. },
  23407. // advance the time and update apply the animation
  23408. update: function ( deltaTime ) {
  23409. deltaTime *= this.timeScale;
  23410. var actions = this._actions,
  23411. nActions = this._nActiveActions,
  23412. time = this.time += deltaTime,
  23413. timeDirection = Math.sign( deltaTime ),
  23414. accuIndex = this._accuIndex ^= 1;
  23415. // run active actions
  23416. for ( var i = 0; i !== nActions; ++ i ) {
  23417. var action = actions[ i ];
  23418. action._update( time, deltaTime, timeDirection, accuIndex );
  23419. }
  23420. // update scene graph
  23421. var bindings = this._bindings,
  23422. nBindings = this._nActiveBindings;
  23423. for ( var i = 0; i !== nBindings; ++ i ) {
  23424. bindings[ i ].apply( accuIndex );
  23425. }
  23426. return this;
  23427. },
  23428. // return this mixer's root target object
  23429. getRoot: function () {
  23430. return this._root;
  23431. },
  23432. // free all resources specific to a particular clip
  23433. uncacheClip: function ( clip ) {
  23434. var actions = this._actions,
  23435. clipUuid = clip.uuid,
  23436. actionsByClip = this._actionsByClip,
  23437. actionsForClip = actionsByClip[ clipUuid ];
  23438. if ( actionsForClip !== undefined ) {
  23439. // note: just calling _removeInactiveAction would mess up the
  23440. // iteration state and also require updating the state we can
  23441. // just throw away
  23442. var actionsToRemove = actionsForClip.knownActions;
  23443. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  23444. var action = actionsToRemove[ i ];
  23445. this._deactivateAction( action );
  23446. var cacheIndex = action._cacheIndex,
  23447. lastInactiveAction = actions[ actions.length - 1 ];
  23448. action._cacheIndex = null;
  23449. action._byClipCacheIndex = null;
  23450. lastInactiveAction._cacheIndex = cacheIndex;
  23451. actions[ cacheIndex ] = lastInactiveAction;
  23452. actions.pop();
  23453. this._removeInactiveBindingsForAction( action );
  23454. }
  23455. delete actionsByClip[ clipUuid ];
  23456. }
  23457. },
  23458. // free all resources specific to a particular root target object
  23459. uncacheRoot: function ( root ) {
  23460. var rootUuid = root.uuid,
  23461. actionsByClip = this._actionsByClip;
  23462. for ( var clipUuid in actionsByClip ) {
  23463. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  23464. action = actionByRoot[ rootUuid ];
  23465. if ( action !== undefined ) {
  23466. this._deactivateAction( action );
  23467. this._removeInactiveAction( action );
  23468. }
  23469. }
  23470. var bindingsByRoot = this._bindingsByRootAndName,
  23471. bindingByName = bindingsByRoot[ rootUuid ];
  23472. if ( bindingByName !== undefined ) {
  23473. for ( var trackName in bindingByName ) {
  23474. var binding = bindingByName[ trackName ];
  23475. binding.restoreOriginalState();
  23476. this._removeInactiveBinding( binding );
  23477. }
  23478. }
  23479. },
  23480. // remove a targeted clip from the cache
  23481. uncacheAction: function ( clip, optionalRoot ) {
  23482. var action = this.existingAction( clip, optionalRoot );
  23483. if ( action !== null ) {
  23484. this._deactivateAction( action );
  23485. this._removeInactiveAction( action );
  23486. }
  23487. }
  23488. } );
  23489. /**
  23490. * @author mrdoob / http://mrdoob.com/
  23491. */
  23492. function Uniform( value ) {
  23493. if ( typeof value === 'string' ) {
  23494. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  23495. value = arguments[ 1 ];
  23496. }
  23497. this.value = value;
  23498. }
  23499. Uniform.prototype.clone = function () {
  23500. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  23501. };
  23502. /**
  23503. * @author benaadams / https://twitter.com/ben_a_adams
  23504. */
  23505. function InstancedBufferGeometry() {
  23506. BufferGeometry.call( this );
  23507. this.type = 'InstancedBufferGeometry';
  23508. this.maxInstancedCount = undefined;
  23509. }
  23510. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  23511. constructor: InstancedBufferGeometry,
  23512. isInstancedBufferGeometry: true,
  23513. addGroup: function ( start, count, materialIndex ) {
  23514. this.groups.push( {
  23515. start: start,
  23516. count: count,
  23517. materialIndex: materialIndex
  23518. } );
  23519. },
  23520. copy: function ( source ) {
  23521. var index = source.index;
  23522. if ( index !== null ) {
  23523. this.setIndex( index.clone() );
  23524. }
  23525. var attributes = source.attributes;
  23526. for ( var name in attributes ) {
  23527. var attribute = attributes[ name ];
  23528. this.addAttribute( name, attribute.clone() );
  23529. }
  23530. var groups = source.groups;
  23531. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  23532. var group = groups[ i ];
  23533. this.addGroup( group.start, group.count, group.materialIndex );
  23534. }
  23535. return this;
  23536. }
  23537. } );
  23538. /**
  23539. * @author benaadams / https://twitter.com/ben_a_adams
  23540. */
  23541. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  23542. this.uuid = _Math.generateUUID();
  23543. this.data = interleavedBuffer;
  23544. this.itemSize = itemSize;
  23545. this.offset = offset;
  23546. this.normalized = normalized === true;
  23547. }
  23548. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  23549. count: {
  23550. get: function () {
  23551. return this.data.count;
  23552. }
  23553. },
  23554. array: {
  23555. get: function () {
  23556. return this.data.array;
  23557. }
  23558. }
  23559. } );
  23560. Object.assign( InterleavedBufferAttribute.prototype, {
  23561. isInterleavedBufferAttribute: true,
  23562. setX: function ( index, x ) {
  23563. this.data.array[ index * this.data.stride + this.offset ] = x;
  23564. return this;
  23565. },
  23566. setY: function ( index, y ) {
  23567. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  23568. return this;
  23569. },
  23570. setZ: function ( index, z ) {
  23571. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  23572. return this;
  23573. },
  23574. setW: function ( index, w ) {
  23575. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  23576. return this;
  23577. },
  23578. getX: function ( index ) {
  23579. return this.data.array[ index * this.data.stride + this.offset ];
  23580. },
  23581. getY: function ( index ) {
  23582. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  23583. },
  23584. getZ: function ( index ) {
  23585. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  23586. },
  23587. getW: function ( index ) {
  23588. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  23589. },
  23590. setXY: function ( index, x, y ) {
  23591. index = index * this.data.stride + this.offset;
  23592. this.data.array[ index + 0 ] = x;
  23593. this.data.array[ index + 1 ] = y;
  23594. return this;
  23595. },
  23596. setXYZ: function ( index, x, y, z ) {
  23597. index = index * this.data.stride + this.offset;
  23598. this.data.array[ index + 0 ] = x;
  23599. this.data.array[ index + 1 ] = y;
  23600. this.data.array[ index + 2 ] = z;
  23601. return this;
  23602. },
  23603. setXYZW: function ( index, x, y, z, w ) {
  23604. index = index * this.data.stride + this.offset;
  23605. this.data.array[ index + 0 ] = x;
  23606. this.data.array[ index + 1 ] = y;
  23607. this.data.array[ index + 2 ] = z;
  23608. this.data.array[ index + 3 ] = w;
  23609. return this;
  23610. }
  23611. } );
  23612. /**
  23613. * @author benaadams / https://twitter.com/ben_a_adams
  23614. */
  23615. function InterleavedBuffer( array, stride ) {
  23616. this.uuid = _Math.generateUUID();
  23617. this.array = array;
  23618. this.stride = stride;
  23619. this.count = array !== undefined ? array.length / stride : 0;
  23620. this.dynamic = false;
  23621. this.updateRange = { offset: 0, count: - 1 };
  23622. this.onUploadCallback = function () {};
  23623. this.version = 0;
  23624. }
  23625. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  23626. set: function ( value ) {
  23627. if ( value === true ) this.version ++;
  23628. }
  23629. } );
  23630. Object.assign( InterleavedBuffer.prototype, {
  23631. isInterleavedBuffer: true,
  23632. setArray: function ( array ) {
  23633. if ( Array.isArray( array ) ) {
  23634. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  23635. }
  23636. this.count = array !== undefined ? array.length / this.stride : 0;
  23637. this.array = array;
  23638. },
  23639. setDynamic: function ( value ) {
  23640. this.dynamic = value;
  23641. return this;
  23642. },
  23643. copy: function ( source ) {
  23644. this.array = new source.array.constructor( source.array );
  23645. this.count = source.count;
  23646. this.stride = source.stride;
  23647. this.dynamic = source.dynamic;
  23648. return this;
  23649. },
  23650. copyAt: function ( index1, attribute, index2 ) {
  23651. index1 *= this.stride;
  23652. index2 *= attribute.stride;
  23653. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  23654. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  23655. }
  23656. return this;
  23657. },
  23658. set: function ( value, offset ) {
  23659. if ( offset === undefined ) offset = 0;
  23660. this.array.set( value, offset );
  23661. return this;
  23662. },
  23663. clone: function () {
  23664. return new this.constructor().copy( this );
  23665. },
  23666. onUpload: function ( callback ) {
  23667. this.onUploadCallback = callback;
  23668. return this;
  23669. }
  23670. } );
  23671. /**
  23672. * @author benaadams / https://twitter.com/ben_a_adams
  23673. */
  23674. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  23675. InterleavedBuffer.call( this, array, stride );
  23676. this.meshPerAttribute = meshPerAttribute || 1;
  23677. }
  23678. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  23679. constructor: InstancedInterleavedBuffer,
  23680. isInstancedInterleavedBuffer: true,
  23681. copy: function ( source ) {
  23682. InterleavedBuffer.prototype.copy.call( this, source );
  23683. this.meshPerAttribute = source.meshPerAttribute;
  23684. return this;
  23685. }
  23686. } );
  23687. /**
  23688. * @author benaadams / https://twitter.com/ben_a_adams
  23689. */
  23690. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  23691. BufferAttribute.call( this, array, itemSize );
  23692. this.meshPerAttribute = meshPerAttribute || 1;
  23693. }
  23694. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23695. constructor: InstancedBufferAttribute,
  23696. isInstancedBufferAttribute: true,
  23697. copy: function ( source ) {
  23698. BufferAttribute.prototype.copy.call( this, source );
  23699. this.meshPerAttribute = source.meshPerAttribute;
  23700. return this;
  23701. }
  23702. } );
  23703. /**
  23704. * @author mrdoob / http://mrdoob.com/
  23705. * @author bhouston / http://clara.io/
  23706. * @author stephomi / http://stephaneginier.com/
  23707. */
  23708. function Raycaster( origin, direction, near, far ) {
  23709. this.ray = new Ray( origin, direction );
  23710. // direction is assumed to be normalized (for accurate distance calculations)
  23711. this.near = near || 0;
  23712. this.far = far || Infinity;
  23713. this.params = {
  23714. Mesh: {},
  23715. Line: {},
  23716. LOD: {},
  23717. Points: { threshold: 1 },
  23718. Sprite: {}
  23719. };
  23720. Object.defineProperties( this.params, {
  23721. PointCloud: {
  23722. get: function () {
  23723. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  23724. return this.Points;
  23725. }
  23726. }
  23727. } );
  23728. }
  23729. function ascSort( a, b ) {
  23730. return a.distance - b.distance;
  23731. }
  23732. function intersectObject( object, raycaster, intersects, recursive ) {
  23733. if ( object.visible === false ) return;
  23734. object.raycast( raycaster, intersects );
  23735. if ( recursive === true ) {
  23736. var children = object.children;
  23737. for ( var i = 0, l = children.length; i < l; i ++ ) {
  23738. intersectObject( children[ i ], raycaster, intersects, true );
  23739. }
  23740. }
  23741. }
  23742. Object.assign( Raycaster.prototype, {
  23743. linePrecision: 1,
  23744. set: function ( origin, direction ) {
  23745. // direction is assumed to be normalized (for accurate distance calculations)
  23746. this.ray.set( origin, direction );
  23747. },
  23748. setFromCamera: function ( coords, camera ) {
  23749. if ( ( camera && camera.isPerspectiveCamera ) ) {
  23750. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  23751. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  23752. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  23753. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  23754. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  23755. } else {
  23756. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  23757. }
  23758. },
  23759. intersectObject: function ( object, recursive ) {
  23760. var intersects = [];
  23761. intersectObject( object, this, intersects, recursive );
  23762. intersects.sort( ascSort );
  23763. return intersects;
  23764. },
  23765. intersectObjects: function ( objects, recursive ) {
  23766. var intersects = [];
  23767. if ( Array.isArray( objects ) === false ) {
  23768. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  23769. return intersects;
  23770. }
  23771. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  23772. intersectObject( objects[ i ], this, intersects, recursive );
  23773. }
  23774. intersects.sort( ascSort );
  23775. return intersects;
  23776. }
  23777. } );
  23778. /**
  23779. * @author alteredq / http://alteredqualia.com/
  23780. */
  23781. function Clock( autoStart ) {
  23782. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  23783. this.startTime = 0;
  23784. this.oldTime = 0;
  23785. this.elapsedTime = 0;
  23786. this.running = false;
  23787. }
  23788. Object.assign( Clock.prototype, {
  23789. start: function () {
  23790. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  23791. this.oldTime = this.startTime;
  23792. this.elapsedTime = 0;
  23793. this.running = true;
  23794. },
  23795. stop: function () {
  23796. this.getElapsedTime();
  23797. this.running = false;
  23798. },
  23799. getElapsedTime: function () {
  23800. this.getDelta();
  23801. return this.elapsedTime;
  23802. },
  23803. getDelta: function () {
  23804. var diff = 0;
  23805. if ( this.autoStart && ! this.running ) {
  23806. this.start();
  23807. return 0;
  23808. }
  23809. if ( this.running ) {
  23810. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  23811. diff = ( newTime - this.oldTime ) / 1000;
  23812. this.oldTime = newTime;
  23813. this.elapsedTime += diff;
  23814. }
  23815. return diff;
  23816. }
  23817. } );
  23818. /**
  23819. * @author bhouston / http://clara.io
  23820. * @author WestLangley / http://github.com/WestLangley
  23821. *
  23822. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  23823. *
  23824. * The poles (phi) are at the positive and negative y axis.
  23825. * The equator starts at positive z.
  23826. */
  23827. function Spherical( radius, phi, theta ) {
  23828. this.radius = ( radius !== undefined ) ? radius : 1.0;
  23829. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  23830. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  23831. return this;
  23832. }
  23833. Object.assign( Spherical.prototype, {
  23834. set: function ( radius, phi, theta ) {
  23835. this.radius = radius;
  23836. this.phi = phi;
  23837. this.theta = theta;
  23838. return this;
  23839. },
  23840. clone: function () {
  23841. return new this.constructor().copy( this );
  23842. },
  23843. copy: function ( other ) {
  23844. this.radius = other.radius;
  23845. this.phi = other.phi;
  23846. this.theta = other.theta;
  23847. return this;
  23848. },
  23849. // restrict phi to be betwee EPS and PI-EPS
  23850. makeSafe: function() {
  23851. var EPS = 0.000001;
  23852. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  23853. return this;
  23854. },
  23855. setFromVector3: function( vec3 ) {
  23856. this.radius = vec3.length();
  23857. if ( this.radius === 0 ) {
  23858. this.theta = 0;
  23859. this.phi = 0;
  23860. } else {
  23861. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  23862. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  23863. }
  23864. return this;
  23865. }
  23866. } );
  23867. /**
  23868. * @author Mugen87 / https://github.com/Mugen87
  23869. *
  23870. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  23871. *
  23872. */
  23873. function Cylindrical( radius, theta, y ) {
  23874. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  23875. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  23876. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  23877. return this;
  23878. }
  23879. Object.assign( Cylindrical.prototype, {
  23880. set: function ( radius, theta, y ) {
  23881. this.radius = radius;
  23882. this.theta = theta;
  23883. this.y = y;
  23884. return this;
  23885. },
  23886. clone: function () {
  23887. return new this.constructor().copy( this );
  23888. },
  23889. copy: function ( other ) {
  23890. this.radius = other.radius;
  23891. this.theta = other.theta;
  23892. this.y = other.y;
  23893. return this;
  23894. },
  23895. setFromVector3: function( vec3 ) {
  23896. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  23897. this.theta = Math.atan2( vec3.x, vec3.z );
  23898. this.y = vec3.y;
  23899. return this;
  23900. }
  23901. } );
  23902. /**
  23903. * @author alteredq / http://alteredqualia.com/
  23904. */
  23905. function MorphBlendMesh( geometry, material ) {
  23906. Mesh.call( this, geometry, material );
  23907. this.animationsMap = {};
  23908. this.animationsList = [];
  23909. // prepare default animation
  23910. // (all frames played together in 1 second)
  23911. var numFrames = this.geometry.morphTargets.length;
  23912. var name = "__default";
  23913. var startFrame = 0;
  23914. var endFrame = numFrames - 1;
  23915. var fps = numFrames / 1;
  23916. this.createAnimation( name, startFrame, endFrame, fps );
  23917. this.setAnimationWeight( name, 1 );
  23918. }
  23919. MorphBlendMesh.prototype = Object.create( Mesh.prototype );
  23920. MorphBlendMesh.prototype.constructor = MorphBlendMesh;
  23921. MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  23922. var animation = {
  23923. start: start,
  23924. end: end,
  23925. length: end - start + 1,
  23926. fps: fps,
  23927. duration: ( end - start ) / fps,
  23928. lastFrame: 0,
  23929. currentFrame: 0,
  23930. active: false,
  23931. time: 0,
  23932. direction: 1,
  23933. weight: 1,
  23934. directionBackwards: false,
  23935. mirroredLoop: false
  23936. };
  23937. this.animationsMap[ name ] = animation;
  23938. this.animationsList.push( animation );
  23939. };
  23940. MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  23941. var pattern = /([a-z]+)_?(\d+)/i;
  23942. var firstAnimation, frameRanges = {};
  23943. var geometry = this.geometry;
  23944. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  23945. var morph = geometry.morphTargets[ i ];
  23946. var chunks = morph.name.match( pattern );
  23947. if ( chunks && chunks.length > 1 ) {
  23948. var name = chunks[ 1 ];
  23949. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  23950. var range = frameRanges[ name ];
  23951. if ( i < range.start ) range.start = i;
  23952. if ( i > range.end ) range.end = i;
  23953. if ( ! firstAnimation ) firstAnimation = name;
  23954. }
  23955. }
  23956. for ( var name in frameRanges ) {
  23957. var range = frameRanges[ name ];
  23958. this.createAnimation( name, range.start, range.end, fps );
  23959. }
  23960. this.firstAnimation = firstAnimation;
  23961. };
  23962. MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  23963. var animation = this.animationsMap[ name ];
  23964. if ( animation ) {
  23965. animation.direction = 1;
  23966. animation.directionBackwards = false;
  23967. }
  23968. };
  23969. MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  23970. var animation = this.animationsMap[ name ];
  23971. if ( animation ) {
  23972. animation.direction = - 1;
  23973. animation.directionBackwards = true;
  23974. }
  23975. };
  23976. MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  23977. var animation = this.animationsMap[ name ];
  23978. if ( animation ) {
  23979. animation.fps = fps;
  23980. animation.duration = ( animation.end - animation.start ) / animation.fps;
  23981. }
  23982. };
  23983. MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  23984. var animation = this.animationsMap[ name ];
  23985. if ( animation ) {
  23986. animation.duration = duration;
  23987. animation.fps = ( animation.end - animation.start ) / animation.duration;
  23988. }
  23989. };
  23990. MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  23991. var animation = this.animationsMap[ name ];
  23992. if ( animation ) {
  23993. animation.weight = weight;
  23994. }
  23995. };
  23996. MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  23997. var animation = this.animationsMap[ name ];
  23998. if ( animation ) {
  23999. animation.time = time;
  24000. }
  24001. };
  24002. MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24003. var time = 0;
  24004. var animation = this.animationsMap[ name ];
  24005. if ( animation ) {
  24006. time = animation.time;
  24007. }
  24008. return time;
  24009. };
  24010. MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24011. var duration = - 1;
  24012. var animation = this.animationsMap[ name ];
  24013. if ( animation ) {
  24014. duration = animation.duration;
  24015. }
  24016. return duration;
  24017. };
  24018. MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24019. var animation = this.animationsMap[ name ];
  24020. if ( animation ) {
  24021. animation.time = 0;
  24022. animation.active = true;
  24023. } else {
  24024. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24025. }
  24026. };
  24027. MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24028. var animation = this.animationsMap[ name ];
  24029. if ( animation ) {
  24030. animation.active = false;
  24031. }
  24032. };
  24033. MorphBlendMesh.prototype.update = function ( delta ) {
  24034. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24035. var animation = this.animationsList[ i ];
  24036. if ( ! animation.active ) continue;
  24037. var frameTime = animation.duration / animation.length;
  24038. animation.time += animation.direction * delta;
  24039. if ( animation.mirroredLoop ) {
  24040. if ( animation.time > animation.duration || animation.time < 0 ) {
  24041. animation.direction *= - 1;
  24042. if ( animation.time > animation.duration ) {
  24043. animation.time = animation.duration;
  24044. animation.directionBackwards = true;
  24045. }
  24046. if ( animation.time < 0 ) {
  24047. animation.time = 0;
  24048. animation.directionBackwards = false;
  24049. }
  24050. }
  24051. } else {
  24052. animation.time = animation.time % animation.duration;
  24053. if ( animation.time < 0 ) animation.time += animation.duration;
  24054. }
  24055. var keyframe = animation.start + _Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24056. var weight = animation.weight;
  24057. if ( keyframe !== animation.currentFrame ) {
  24058. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24059. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24060. this.morphTargetInfluences[ keyframe ] = 0;
  24061. animation.lastFrame = animation.currentFrame;
  24062. animation.currentFrame = keyframe;
  24063. }
  24064. var mix = ( animation.time % frameTime ) / frameTime;
  24065. if ( animation.directionBackwards ) mix = 1 - mix;
  24066. if ( animation.currentFrame !== animation.lastFrame ) {
  24067. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24068. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24069. } else {
  24070. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24071. }
  24072. }
  24073. };
  24074. /**
  24075. * @author alteredq / http://alteredqualia.com/
  24076. */
  24077. function ImmediateRenderObject( material ) {
  24078. Object3D.call( this );
  24079. this.material = material;
  24080. this.render = function ( renderCallback ) {};
  24081. }
  24082. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  24083. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  24084. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  24085. /**
  24086. * @author mrdoob / http://mrdoob.com/
  24087. * @author WestLangley / http://github.com/WestLangley
  24088. */
  24089. function VertexNormalsHelper( object, size, hex, linewidth ) {
  24090. this.object = object;
  24091. this.size = ( size !== undefined ) ? size : 1;
  24092. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24093. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24094. //
  24095. var nNormals = 0;
  24096. var objGeometry = this.object.geometry;
  24097. if ( objGeometry && objGeometry.isGeometry ) {
  24098. nNormals = objGeometry.faces.length * 3;
  24099. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  24100. nNormals = objGeometry.attributes.normal.count;
  24101. }
  24102. //
  24103. var geometry = new BufferGeometry();
  24104. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  24105. geometry.addAttribute( 'position', positions );
  24106. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  24107. //
  24108. this.matrixAutoUpdate = false;
  24109. this.update();
  24110. }
  24111. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  24112. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  24113. VertexNormalsHelper.prototype.update = ( function () {
  24114. var v1 = new Vector3();
  24115. var v2 = new Vector3();
  24116. var normalMatrix = new Matrix3();
  24117. return function update() {
  24118. var keys = [ 'a', 'b', 'c' ];
  24119. this.object.updateMatrixWorld( true );
  24120. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24121. var matrixWorld = this.object.matrixWorld;
  24122. var position = this.geometry.attributes.position;
  24123. //
  24124. var objGeometry = this.object.geometry;
  24125. if ( objGeometry && objGeometry.isGeometry ) {
  24126. var vertices = objGeometry.vertices;
  24127. var faces = objGeometry.faces;
  24128. var idx = 0;
  24129. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24130. var face = faces[ i ];
  24131. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24132. var vertex = vertices[ face[ keys[ j ] ] ];
  24133. var normal = face.vertexNormals[ j ];
  24134. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24135. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24136. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24137. idx = idx + 1;
  24138. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24139. idx = idx + 1;
  24140. }
  24141. }
  24142. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  24143. var objPos = objGeometry.attributes.position;
  24144. var objNorm = objGeometry.attributes.normal;
  24145. var idx = 0;
  24146. // for simplicity, ignore index and drawcalls, and render every normal
  24147. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24148. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24149. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24150. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24151. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24152. idx = idx + 1;
  24153. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24154. idx = idx + 1;
  24155. }
  24156. }
  24157. position.needsUpdate = true;
  24158. };
  24159. }() );
  24160. /**
  24161. * @author alteredq / http://alteredqualia.com/
  24162. * @author mrdoob / http://mrdoob.com/
  24163. * @author WestLangley / http://github.com/WestLangley
  24164. */
  24165. function SpotLightHelper( light ) {
  24166. Object3D.call( this );
  24167. this.light = light;
  24168. this.light.updateMatrixWorld();
  24169. this.matrix = light.matrixWorld;
  24170. this.matrixAutoUpdate = false;
  24171. var geometry = new BufferGeometry();
  24172. var positions = [
  24173. 0, 0, 0, 0, 0, 1,
  24174. 0, 0, 0, 1, 0, 1,
  24175. 0, 0, 0, - 1, 0, 1,
  24176. 0, 0, 0, 0, 1, 1,
  24177. 0, 0, 0, 0, - 1, 1
  24178. ];
  24179. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  24180. var p1 = ( i / l ) * Math.PI * 2;
  24181. var p2 = ( j / l ) * Math.PI * 2;
  24182. positions.push(
  24183. Math.cos( p1 ), Math.sin( p1 ), 1,
  24184. Math.cos( p2 ), Math.sin( p2 ), 1
  24185. );
  24186. }
  24187. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  24188. var material = new LineBasicMaterial( { fog: false } );
  24189. this.cone = new LineSegments( geometry, material );
  24190. this.add( this.cone );
  24191. this.update();
  24192. }
  24193. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  24194. SpotLightHelper.prototype.constructor = SpotLightHelper;
  24195. SpotLightHelper.prototype.dispose = function () {
  24196. this.cone.geometry.dispose();
  24197. this.cone.material.dispose();
  24198. };
  24199. SpotLightHelper.prototype.update = function () {
  24200. var vector = new Vector3();
  24201. var vector2 = new Vector3();
  24202. return function update() {
  24203. this.light.updateMatrixWorld();
  24204. var coneLength = this.light.distance ? this.light.distance : 1000;
  24205. var coneWidth = coneLength * Math.tan( this.light.angle );
  24206. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24207. vector.setFromMatrixPosition( this.light.matrixWorld );
  24208. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24209. this.cone.lookAt( vector2.sub( vector ) );
  24210. this.cone.material.color.copy( this.light.color );
  24211. };
  24212. }();
  24213. /**
  24214. * @author Sean Griffin / http://twitter.com/sgrif
  24215. * @author Michael Guerrero / http://realitymeltdown.com
  24216. * @author mrdoob / http://mrdoob.com/
  24217. * @author ikerr / http://verold.com
  24218. * @author Mugen87 / https://github.com/Mugen87
  24219. */
  24220. function getBoneList( object ) {
  24221. var boneList = [];
  24222. if ( object && object.isBone ) {
  24223. boneList.push( object );
  24224. }
  24225. for ( var i = 0; i < object.children.length; i ++ ) {
  24226. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  24227. }
  24228. return boneList;
  24229. }
  24230. function SkeletonHelper( object ) {
  24231. var bones = getBoneList( object );
  24232. var geometry = new BufferGeometry();
  24233. var vertices = [];
  24234. var colors = [];
  24235. var color1 = new Color( 0, 0, 1 );
  24236. var color2 = new Color( 0, 1, 0 );
  24237. for ( var i = 0; i < bones.length; i ++ ) {
  24238. var bone = bones[ i ];
  24239. if ( bone.parent && bone.parent.isBone ) {
  24240. vertices.push( 0, 0, 0 );
  24241. vertices.push( 0, 0, 0 );
  24242. colors.push( color1.r, color1.g, color1.b );
  24243. colors.push( color2.r, color2.g, color2.b );
  24244. }
  24245. }
  24246. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24247. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24248. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24249. LineSegments.call( this, geometry, material );
  24250. this.root = object;
  24251. this.bones = bones;
  24252. this.matrix = object.matrixWorld;
  24253. this.matrixAutoUpdate = false;
  24254. this.onBeforeRender();
  24255. }
  24256. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  24257. SkeletonHelper.prototype.constructor = SkeletonHelper;
  24258. SkeletonHelper.prototype.onBeforeRender = function () {
  24259. var vector = new Vector3();
  24260. var boneMatrix = new Matrix4();
  24261. var matrixWorldInv = new Matrix4();
  24262. return function onBeforeRender() {
  24263. var bones = this.bones;
  24264. var geometry = this.geometry;
  24265. var position = geometry.getAttribute( 'position' );
  24266. matrixWorldInv.getInverse( this.root.matrixWorld );
  24267. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  24268. var bone = bones[ i ];
  24269. if ( bone.parent && bone.parent.isBone ) {
  24270. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24271. vector.setFromMatrixPosition( boneMatrix );
  24272. position.setXYZ( j, vector.x, vector.y, vector.z );
  24273. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24274. vector.setFromMatrixPosition( boneMatrix );
  24275. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  24276. j += 2;
  24277. }
  24278. }
  24279. geometry.getAttribute( 'position' ).needsUpdate = true;
  24280. };
  24281. }();
  24282. /**
  24283. * @author alteredq / http://alteredqualia.com/
  24284. * @author mrdoob / http://mrdoob.com/
  24285. */
  24286. function PointLightHelper( light, sphereSize ) {
  24287. this.light = light;
  24288. this.light.updateMatrixWorld();
  24289. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  24290. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  24291. material.color.copy( this.light.color );
  24292. Mesh.call( this, geometry, material );
  24293. this.matrix = this.light.matrixWorld;
  24294. this.matrixAutoUpdate = false;
  24295. /*
  24296. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24297. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24298. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24299. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24300. var d = light.distance;
  24301. if ( d === 0.0 ) {
  24302. this.lightDistance.visible = false;
  24303. } else {
  24304. this.lightDistance.scale.set( d, d, d );
  24305. }
  24306. this.add( this.lightDistance );
  24307. */
  24308. }
  24309. PointLightHelper.prototype = Object.create( Mesh.prototype );
  24310. PointLightHelper.prototype.constructor = PointLightHelper;
  24311. PointLightHelper.prototype.dispose = function () {
  24312. this.geometry.dispose();
  24313. this.material.dispose();
  24314. };
  24315. PointLightHelper.prototype.update = function () {
  24316. this.material.color.copy( this.light.color );
  24317. /*
  24318. var d = this.light.distance;
  24319. if ( d === 0.0 ) {
  24320. this.lightDistance.visible = false;
  24321. } else {
  24322. this.lightDistance.visible = true;
  24323. this.lightDistance.scale.set( d, d, d );
  24324. }
  24325. */
  24326. };
  24327. /**
  24328. * @author abelnation / http://github.com/abelnation
  24329. * @author Mugen87 / http://github.com/Mugen87
  24330. * @author WestLangley / http://github.com/WestLangley
  24331. */
  24332. function RectAreaLightHelper( light ) {
  24333. Object3D.call( this );
  24334. this.light = light;
  24335. this.light.updateMatrixWorld();
  24336. this.matrix = light.matrixWorld;
  24337. this.matrixAutoUpdate = false;
  24338. var material = new LineBasicMaterial( { color: light.color } );
  24339. var geometry = new BufferGeometry();
  24340. geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) );
  24341. this.add( new Line( geometry, material ) );
  24342. this.update();
  24343. }
  24344. RectAreaLightHelper.prototype = Object.create( Object3D.prototype );
  24345. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  24346. RectAreaLightHelper.prototype.dispose = function () {
  24347. this.children[ 0 ].geometry.dispose();
  24348. this.children[ 0 ].material.dispose();
  24349. };
  24350. RectAreaLightHelper.prototype.update = function () {
  24351. var line = this.children[ 0 ];
  24352. // update material
  24353. line.material.color.copy( this.light.color );
  24354. // calculate new dimensions of the helper
  24355. var hx = this.light.width * 0.5;
  24356. var hy = this.light.height * 0.5;
  24357. var position = line.geometry.attributes.position;
  24358. var array = position.array;
  24359. // update vertices
  24360. array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0;
  24361. array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0;
  24362. array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0;
  24363. array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0;
  24364. array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0;
  24365. position.needsUpdate = true;
  24366. };
  24367. /**
  24368. * @author alteredq / http://alteredqualia.com/
  24369. * @author mrdoob / http://mrdoob.com/
  24370. * @author Mugen87 / https://github.com/Mugen87
  24371. */
  24372. function HemisphereLightHelper( light, size ) {
  24373. Object3D.call( this );
  24374. this.light = light;
  24375. this.light.updateMatrixWorld();
  24376. this.matrix = light.matrixWorld;
  24377. this.matrixAutoUpdate = false;
  24378. var geometry = new OctahedronBufferGeometry( size );
  24379. geometry.rotateY( Math.PI * 0.5 );
  24380. var material = new MeshBasicMaterial( { vertexColors: VertexColors, wireframe: true } );
  24381. var position = geometry.getAttribute( 'position' );
  24382. var colors = new Float32Array( position.count * 3 );
  24383. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  24384. this.add( new Mesh( geometry, material ) );
  24385. this.update();
  24386. }
  24387. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  24388. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  24389. HemisphereLightHelper.prototype.dispose = function () {
  24390. this.children[ 0 ].geometry.dispose();
  24391. this.children[ 0 ].material.dispose();
  24392. };
  24393. HemisphereLightHelper.prototype.update = function () {
  24394. var vector = new Vector3();
  24395. var color1 = new Color();
  24396. var color2 = new Color();
  24397. return function update() {
  24398. var mesh = this.children[ 0 ];
  24399. var colors = mesh.geometry.getAttribute( 'color' );
  24400. color1.copy( this.light.color );
  24401. color2.copy( this.light.groundColor );
  24402. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  24403. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  24404. colors.setXYZ( i, color.r, color.g, color.b );
  24405. }
  24406. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24407. colors.needsUpdate = true;
  24408. };
  24409. }();
  24410. /**
  24411. * @author mrdoob / http://mrdoob.com/
  24412. */
  24413. function GridHelper( size, divisions, color1, color2 ) {
  24414. size = size || 10;
  24415. divisions = divisions || 10;
  24416. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  24417. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  24418. var center = divisions / 2;
  24419. var step = size / divisions;
  24420. var halfSize = size / 2;
  24421. var vertices = [], colors = [];
  24422. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  24423. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  24424. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  24425. var color = i === center ? color1 : color2;
  24426. color.toArray( colors, j ); j += 3;
  24427. color.toArray( colors, j ); j += 3;
  24428. color.toArray( colors, j ); j += 3;
  24429. color.toArray( colors, j ); j += 3;
  24430. }
  24431. var geometry = new BufferGeometry();
  24432. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24433. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24434. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  24435. LineSegments.call( this, geometry, material );
  24436. }
  24437. GridHelper.prototype = Object.create( LineSegments.prototype );
  24438. GridHelper.prototype.constructor = GridHelper;
  24439. /**
  24440. * @author mrdoob / http://mrdoob.com/
  24441. * @author Mugen87 / http://github.com/Mugen87
  24442. * @author Hectate / http://www.github.com/Hectate
  24443. */
  24444. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  24445. radius = radius || 10;
  24446. radials = radials || 16;
  24447. circles = circles || 8;
  24448. divisions = divisions || 64;
  24449. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  24450. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  24451. var vertices = [];
  24452. var colors = [];
  24453. var x, z;
  24454. var v, i, j, r, color;
  24455. // create the radials
  24456. for ( i = 0; i <= radials; i ++ ) {
  24457. v = ( i / radials ) * ( Math.PI * 2 );
  24458. x = Math.sin( v ) * radius;
  24459. z = Math.cos( v ) * radius;
  24460. vertices.push( 0, 0, 0 );
  24461. vertices.push( x, 0, z );
  24462. color = ( i & 1 ) ? color1 : color2;
  24463. colors.push( color.r, color.g, color.b );
  24464. colors.push( color.r, color.g, color.b );
  24465. }
  24466. // create the circles
  24467. for ( i = 0; i <= circles; i ++ ) {
  24468. color = ( i & 1 ) ? color1 : color2;
  24469. r = radius - ( radius / circles * i );
  24470. for ( j = 0; j < divisions; j ++ ) {
  24471. // first vertex
  24472. v = ( j / divisions ) * ( Math.PI * 2 );
  24473. x = Math.sin( v ) * r;
  24474. z = Math.cos( v ) * r;
  24475. vertices.push( x, 0, z );
  24476. colors.push( color.r, color.g, color.b );
  24477. // second vertex
  24478. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  24479. x = Math.sin( v ) * r;
  24480. z = Math.cos( v ) * r;
  24481. vertices.push( x, 0, z );
  24482. colors.push( color.r, color.g, color.b );
  24483. }
  24484. }
  24485. var geometry = new BufferGeometry();
  24486. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24487. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24488. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  24489. LineSegments.call( this, geometry, material );
  24490. }
  24491. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  24492. PolarGridHelper.prototype.constructor = PolarGridHelper;
  24493. /**
  24494. * @author mrdoob / http://mrdoob.com/
  24495. * @author WestLangley / http://github.com/WestLangley
  24496. */
  24497. function FaceNormalsHelper( object, size, hex, linewidth ) {
  24498. // FaceNormalsHelper only supports THREE.Geometry
  24499. this.object = object;
  24500. this.size = ( size !== undefined ) ? size : 1;
  24501. var color = ( hex !== undefined ) ? hex : 0xffff00;
  24502. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24503. //
  24504. var nNormals = 0;
  24505. var objGeometry = this.object.geometry;
  24506. if ( objGeometry && objGeometry.isGeometry ) {
  24507. nNormals = objGeometry.faces.length;
  24508. } else {
  24509. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  24510. }
  24511. //
  24512. var geometry = new BufferGeometry();
  24513. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  24514. geometry.addAttribute( 'position', positions );
  24515. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  24516. //
  24517. this.matrixAutoUpdate = false;
  24518. this.update();
  24519. }
  24520. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  24521. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  24522. FaceNormalsHelper.prototype.update = ( function () {
  24523. var v1 = new Vector3();
  24524. var v2 = new Vector3();
  24525. var normalMatrix = new Matrix3();
  24526. return function update() {
  24527. this.object.updateMatrixWorld( true );
  24528. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24529. var matrixWorld = this.object.matrixWorld;
  24530. var position = this.geometry.attributes.position;
  24531. //
  24532. var objGeometry = this.object.geometry;
  24533. var vertices = objGeometry.vertices;
  24534. var faces = objGeometry.faces;
  24535. var idx = 0;
  24536. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24537. var face = faces[ i ];
  24538. var normal = face.normal;
  24539. v1.copy( vertices[ face.a ] )
  24540. .add( vertices[ face.b ] )
  24541. .add( vertices[ face.c ] )
  24542. .divideScalar( 3 )
  24543. .applyMatrix4( matrixWorld );
  24544. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24545. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24546. idx = idx + 1;
  24547. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24548. idx = idx + 1;
  24549. }
  24550. position.needsUpdate = true;
  24551. };
  24552. }() );
  24553. /**
  24554. * @author alteredq / http://alteredqualia.com/
  24555. * @author mrdoob / http://mrdoob.com/
  24556. * @author WestLangley / http://github.com/WestLangley
  24557. */
  24558. function DirectionalLightHelper( light, size ) {
  24559. Object3D.call( this );
  24560. this.light = light;
  24561. this.light.updateMatrixWorld();
  24562. this.matrix = light.matrixWorld;
  24563. this.matrixAutoUpdate = false;
  24564. if ( size === undefined ) size = 1;
  24565. var geometry = new BufferGeometry();
  24566. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  24567. - size, size, 0,
  24568. size, size, 0,
  24569. size, - size, 0,
  24570. - size, - size, 0,
  24571. - size, size, 0
  24572. ], 3 ) );
  24573. var material = new LineBasicMaterial( { fog: false } );
  24574. this.add( new Line( geometry, material ) );
  24575. geometry = new BufferGeometry();
  24576. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  24577. this.add( new Line( geometry, material ));
  24578. this.update();
  24579. }
  24580. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  24581. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  24582. DirectionalLightHelper.prototype.dispose = function () {
  24583. var lightPlane = this.children[ 0 ];
  24584. var targetLine = this.children[ 1 ];
  24585. lightPlane.geometry.dispose();
  24586. lightPlane.material.dispose();
  24587. targetLine.geometry.dispose();
  24588. targetLine.material.dispose();
  24589. };
  24590. DirectionalLightHelper.prototype.update = function () {
  24591. var v1 = new Vector3();
  24592. var v2 = new Vector3();
  24593. var v3 = new Vector3();
  24594. return function update() {
  24595. v1.setFromMatrixPosition( this.light.matrixWorld );
  24596. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  24597. v3.subVectors( v2, v1 );
  24598. var lightPlane = this.children[ 0 ];
  24599. var targetLine = this.children[ 1 ];
  24600. lightPlane.lookAt( v3 );
  24601. lightPlane.material.color.copy( this.light.color );
  24602. targetLine.lookAt( v3 );
  24603. targetLine.scale.z = v3.length();
  24604. };
  24605. }();
  24606. /**
  24607. * @author alteredq / http://alteredqualia.com/
  24608. * @author Mugen87 / https://github.com/Mugen87
  24609. *
  24610. * - shows frustum, line of sight and up of the camera
  24611. * - suitable for fast updates
  24612. * - based on frustum visualization in lightgl.js shadowmap example
  24613. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  24614. */
  24615. function CameraHelper( camera ) {
  24616. var geometry = new BufferGeometry();
  24617. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  24618. var vertices = [];
  24619. var colors = [];
  24620. var pointMap = {};
  24621. // colors
  24622. var colorFrustum = new Color( 0xffaa00 );
  24623. var colorCone = new Color( 0xff0000 );
  24624. var colorUp = new Color( 0x00aaff );
  24625. var colorTarget = new Color( 0xffffff );
  24626. var colorCross = new Color( 0x333333 );
  24627. // near
  24628. addLine( "n1", "n2", colorFrustum );
  24629. addLine( "n2", "n4", colorFrustum );
  24630. addLine( "n4", "n3", colorFrustum );
  24631. addLine( "n3", "n1", colorFrustum );
  24632. // far
  24633. addLine( "f1", "f2", colorFrustum );
  24634. addLine( "f2", "f4", colorFrustum );
  24635. addLine( "f4", "f3", colorFrustum );
  24636. addLine( "f3", "f1", colorFrustum );
  24637. // sides
  24638. addLine( "n1", "f1", colorFrustum );
  24639. addLine( "n2", "f2", colorFrustum );
  24640. addLine( "n3", "f3", colorFrustum );
  24641. addLine( "n4", "f4", colorFrustum );
  24642. // cone
  24643. addLine( "p", "n1", colorCone );
  24644. addLine( "p", "n2", colorCone );
  24645. addLine( "p", "n3", colorCone );
  24646. addLine( "p", "n4", colorCone );
  24647. // up
  24648. addLine( "u1", "u2", colorUp );
  24649. addLine( "u2", "u3", colorUp );
  24650. addLine( "u3", "u1", colorUp );
  24651. // target
  24652. addLine( "c", "t", colorTarget );
  24653. addLine( "p", "c", colorCross );
  24654. // cross
  24655. addLine( "cn1", "cn2", colorCross );
  24656. addLine( "cn3", "cn4", colorCross );
  24657. addLine( "cf1", "cf2", colorCross );
  24658. addLine( "cf3", "cf4", colorCross );
  24659. function addLine( a, b, color ) {
  24660. addPoint( a, color );
  24661. addPoint( b, color );
  24662. }
  24663. function addPoint( id, color ) {
  24664. vertices.push( 0, 0, 0 );
  24665. colors.push( color.r, color.g, color.b );
  24666. if ( pointMap[ id ] === undefined ) {
  24667. pointMap[ id ] = [];
  24668. }
  24669. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  24670. }
  24671. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24672. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24673. LineSegments.call( this, geometry, material );
  24674. this.camera = camera;
  24675. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  24676. this.matrix = camera.matrixWorld;
  24677. this.matrixAutoUpdate = false;
  24678. this.pointMap = pointMap;
  24679. this.update();
  24680. }
  24681. CameraHelper.prototype = Object.create( LineSegments.prototype );
  24682. CameraHelper.prototype.constructor = CameraHelper;
  24683. CameraHelper.prototype.update = function () {
  24684. var geometry, pointMap;
  24685. var vector = new Vector3();
  24686. var camera = new Camera();
  24687. function setPoint( point, x, y, z ) {
  24688. vector.set( x, y, z ).unproject( camera );
  24689. var points = pointMap[ point ];
  24690. if ( points !== undefined ) {
  24691. var position = geometry.getAttribute( 'position' );
  24692. for ( var i = 0, l = points.length; i < l; i ++ ) {
  24693. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  24694. }
  24695. }
  24696. }
  24697. return function update() {
  24698. geometry = this.geometry;
  24699. pointMap = this.pointMap;
  24700. var w = 1, h = 1;
  24701. // we need just camera projection matrix
  24702. // world matrix must be identity
  24703. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  24704. // center / target
  24705. setPoint( "c", 0, 0, - 1 );
  24706. setPoint( "t", 0, 0, 1 );
  24707. // near
  24708. setPoint( "n1", - w, - h, - 1 );
  24709. setPoint( "n2", w, - h, - 1 );
  24710. setPoint( "n3", - w, h, - 1 );
  24711. setPoint( "n4", w, h, - 1 );
  24712. // far
  24713. setPoint( "f1", - w, - h, 1 );
  24714. setPoint( "f2", w, - h, 1 );
  24715. setPoint( "f3", - w, h, 1 );
  24716. setPoint( "f4", w, h, 1 );
  24717. // up
  24718. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  24719. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  24720. setPoint( "u3", 0, h * 2, - 1 );
  24721. // cross
  24722. setPoint( "cf1", - w, 0, 1 );
  24723. setPoint( "cf2", w, 0, 1 );
  24724. setPoint( "cf3", 0, - h, 1 );
  24725. setPoint( "cf4", 0, h, 1 );
  24726. setPoint( "cn1", - w, 0, - 1 );
  24727. setPoint( "cn2", w, 0, - 1 );
  24728. setPoint( "cn3", 0, - h, - 1 );
  24729. setPoint( "cn4", 0, h, - 1 );
  24730. geometry.getAttribute( 'position' ).needsUpdate = true;
  24731. };
  24732. }();
  24733. /**
  24734. * @author mrdoob / http://mrdoob.com/
  24735. * @author Mugen87 / http://github.com/Mugen87
  24736. */
  24737. function BoxHelper( object, color ) {
  24738. this.object = object;
  24739. if ( color === undefined ) color = 0xffff00;
  24740. 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 ] );
  24741. var positions = new Float32Array( 8 * 3 );
  24742. var geometry = new BufferGeometry();
  24743. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  24744. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  24745. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  24746. this.matrixAutoUpdate = false;
  24747. this.update();
  24748. }
  24749. BoxHelper.prototype = Object.create( LineSegments.prototype );
  24750. BoxHelper.prototype.constructor = BoxHelper;
  24751. BoxHelper.prototype.update = ( function () {
  24752. var box = new Box3();
  24753. return function update( object ) {
  24754. if ( object !== undefined ) {
  24755. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  24756. }
  24757. if ( this.object !== undefined ) {
  24758. box.setFromObject( this.object );
  24759. }
  24760. if ( box.isEmpty() ) return;
  24761. var min = box.min;
  24762. var max = box.max;
  24763. /*
  24764. 5____4
  24765. 1/___0/|
  24766. | 6__|_7
  24767. 2/___3/
  24768. 0: max.x, max.y, max.z
  24769. 1: min.x, max.y, max.z
  24770. 2: min.x, min.y, max.z
  24771. 3: max.x, min.y, max.z
  24772. 4: max.x, max.y, min.z
  24773. 5: min.x, max.y, min.z
  24774. 6: min.x, min.y, min.z
  24775. 7: max.x, min.y, min.z
  24776. */
  24777. var position = this.geometry.attributes.position;
  24778. var array = position.array;
  24779. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  24780. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  24781. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  24782. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  24783. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  24784. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  24785. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  24786. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  24787. position.needsUpdate = true;
  24788. this.geometry.computeBoundingSphere();
  24789. };
  24790. } )();
  24791. BoxHelper.prototype.setFromObject = function ( object ) {
  24792. this.object = object;
  24793. this.update();
  24794. return this;
  24795. };
  24796. /**
  24797. * @author WestLangley / http://github.com/WestLangley
  24798. * @author zz85 / http://github.com/zz85
  24799. * @author bhouston / http://clara.io
  24800. *
  24801. * Creates an arrow for visualizing directions
  24802. *
  24803. * Parameters:
  24804. * dir - Vector3
  24805. * origin - Vector3
  24806. * length - Number
  24807. * color - color in hex value
  24808. * headLength - Number
  24809. * headWidth - Number
  24810. */
  24811. var lineGeometry;
  24812. var coneGeometry;
  24813. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  24814. // dir is assumed to be normalized
  24815. Object3D.call( this );
  24816. if ( color === undefined ) color = 0xffff00;
  24817. if ( length === undefined ) length = 1;
  24818. if ( headLength === undefined ) headLength = 0.2 * length;
  24819. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24820. if ( lineGeometry === undefined ) {
  24821. lineGeometry = new BufferGeometry();
  24822. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  24823. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  24824. coneGeometry.translate( 0, - 0.5, 0 );
  24825. }
  24826. this.position.copy( origin );
  24827. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  24828. this.line.matrixAutoUpdate = false;
  24829. this.add( this.line );
  24830. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  24831. this.cone.matrixAutoUpdate = false;
  24832. this.add( this.cone );
  24833. this.setDirection( dir );
  24834. this.setLength( length, headLength, headWidth );
  24835. }
  24836. ArrowHelper.prototype = Object.create( Object3D.prototype );
  24837. ArrowHelper.prototype.constructor = ArrowHelper;
  24838. ArrowHelper.prototype.setDirection = ( function () {
  24839. var axis = new Vector3();
  24840. var radians;
  24841. return function setDirection( dir ) {
  24842. // dir is assumed to be normalized
  24843. if ( dir.y > 0.99999 ) {
  24844. this.quaternion.set( 0, 0, 0, 1 );
  24845. } else if ( dir.y < - 0.99999 ) {
  24846. this.quaternion.set( 1, 0, 0, 0 );
  24847. } else {
  24848. axis.set( dir.z, 0, - dir.x ).normalize();
  24849. radians = Math.acos( dir.y );
  24850. this.quaternion.setFromAxisAngle( axis, radians );
  24851. }
  24852. };
  24853. }() );
  24854. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  24855. if ( headLength === undefined ) headLength = 0.2 * length;
  24856. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24857. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  24858. this.line.updateMatrix();
  24859. this.cone.scale.set( headWidth, headLength, headWidth );
  24860. this.cone.position.y = length;
  24861. this.cone.updateMatrix();
  24862. };
  24863. ArrowHelper.prototype.setColor = function ( color ) {
  24864. this.line.material.color.copy( color );
  24865. this.cone.material.color.copy( color );
  24866. };
  24867. /**
  24868. * @author sroucheray / http://sroucheray.org/
  24869. * @author mrdoob / http://mrdoob.com/
  24870. */
  24871. function AxisHelper( size ) {
  24872. size = size || 1;
  24873. var vertices = [
  24874. 0, 0, 0, size, 0, 0,
  24875. 0, 0, 0, 0, size, 0,
  24876. 0, 0, 0, 0, 0, size
  24877. ];
  24878. var colors = [
  24879. 1, 0, 0, 1, 0.6, 0,
  24880. 0, 1, 0, 0.6, 1, 0,
  24881. 0, 0, 1, 0, 0.6, 1
  24882. ];
  24883. var geometry = new BufferGeometry();
  24884. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24885. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24886. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  24887. LineSegments.call( this, geometry, material );
  24888. }
  24889. AxisHelper.prototype = Object.create( LineSegments.prototype );
  24890. AxisHelper.prototype.constructor = AxisHelper;
  24891. /**
  24892. * @author zz85 https://github.com/zz85
  24893. *
  24894. * Centripetal CatmullRom Curve - which is useful for avoiding
  24895. * cusps and self-intersections in non-uniform catmull rom curves.
  24896. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  24897. *
  24898. * curve.type accepts centripetal(default), chordal and catmullrom
  24899. * curve.tension is used for catmullrom which defaults to 0.5
  24900. */
  24901. /*
  24902. Based on an optimized c++ solution in
  24903. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  24904. - http://ideone.com/NoEbVM
  24905. This CubicPoly class could be used for reusing some variables and calculations,
  24906. but for three.js curve use, it could be possible inlined and flatten into a single function call
  24907. which can be placed in CurveUtils.
  24908. */
  24909. function CubicPoly() {
  24910. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  24911. /*
  24912. * Compute coefficients for a cubic polynomial
  24913. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  24914. * such that
  24915. * p(0) = x0, p(1) = x1
  24916. * and
  24917. * p'(0) = t0, p'(1) = t1.
  24918. */
  24919. function init( x0, x1, t0, t1 ) {
  24920. c0 = x0;
  24921. c1 = t0;
  24922. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  24923. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  24924. }
  24925. return {
  24926. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  24927. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  24928. },
  24929. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  24930. // compute tangents when parameterized in [t1,t2]
  24931. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  24932. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  24933. // rescale tangents for parametrization in [0,1]
  24934. t1 *= dt1;
  24935. t2 *= dt1;
  24936. init( x1, x2, t1, t2 );
  24937. },
  24938. calc: function ( t ) {
  24939. var t2 = t * t;
  24940. var t3 = t2 * t;
  24941. return c0 + c1 * t + c2 * t2 + c3 * t3;
  24942. }
  24943. };
  24944. }
  24945. //
  24946. var tmp = new Vector3();
  24947. var px = new CubicPoly();
  24948. var py = new CubicPoly();
  24949. var pz = new CubicPoly();
  24950. function CatmullRomCurve3( points ) {
  24951. Curve.call( this );
  24952. if ( points.length < 2 ) console.warn( 'THREE.CatmullRomCurve3: Points array needs at least two entries.' );
  24953. this.points = points || [];
  24954. this.closed = false;
  24955. }
  24956. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  24957. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  24958. CatmullRomCurve3.prototype.getPoint = function ( t ) {
  24959. var points = this.points;
  24960. var l = points.length;
  24961. var point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  24962. var intPoint = Math.floor( point );
  24963. var weight = point - intPoint;
  24964. if ( this.closed ) {
  24965. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  24966. } else if ( weight === 0 && intPoint === l - 1 ) {
  24967. intPoint = l - 2;
  24968. weight = 1;
  24969. }
  24970. var p0, p1, p2, p3; // 4 points
  24971. if ( this.closed || intPoint > 0 ) {
  24972. p0 = points[ ( intPoint - 1 ) % l ];
  24973. } else {
  24974. // extrapolate first point
  24975. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  24976. p0 = tmp;
  24977. }
  24978. p1 = points[ intPoint % l ];
  24979. p2 = points[ ( intPoint + 1 ) % l ];
  24980. if ( this.closed || intPoint + 2 < l ) {
  24981. p3 = points[ ( intPoint + 2 ) % l ];
  24982. } else {
  24983. // extrapolate last point
  24984. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  24985. p3 = tmp;
  24986. }
  24987. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  24988. // init Centripetal / Chordal Catmull-Rom
  24989. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  24990. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  24991. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  24992. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  24993. // safety check for repeated points
  24994. if ( dt1 < 1e-4 ) dt1 = 1.0;
  24995. if ( dt0 < 1e-4 ) dt0 = dt1;
  24996. if ( dt2 < 1e-4 ) dt2 = dt1;
  24997. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  24998. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  24999. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  25000. } else if ( this.type === 'catmullrom' ) {
  25001. var tension = this.tension !== undefined ? this.tension : 0.5;
  25002. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  25003. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  25004. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  25005. }
  25006. return new Vector3( px.calc( weight ), py.calc( weight ), pz.calc( weight ) );
  25007. };
  25008. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  25009. Curve.call( this );
  25010. this.v0 = v0;
  25011. this.v1 = v1;
  25012. this.v2 = v2;
  25013. this.v3 = v3;
  25014. }
  25015. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  25016. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  25017. CubicBezierCurve3.prototype.getPoint = function ( t ) {
  25018. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  25019. return new Vector3(
  25020. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  25021. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  25022. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  25023. );
  25024. };
  25025. function QuadraticBezierCurve3( v0, v1, v2 ) {
  25026. Curve.call( this );
  25027. this.v0 = v0;
  25028. this.v1 = v1;
  25029. this.v2 = v2;
  25030. }
  25031. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  25032. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  25033. QuadraticBezierCurve3.prototype.getPoint = function ( t ) {
  25034. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  25035. return new Vector3(
  25036. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  25037. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  25038. QuadraticBezier( t, v0.z, v1.z, v2.z )
  25039. );
  25040. };
  25041. function LineCurve3( v1, v2 ) {
  25042. Curve.call( this );
  25043. this.v1 = v1;
  25044. this.v2 = v2;
  25045. }
  25046. LineCurve3.prototype = Object.create( Curve.prototype );
  25047. LineCurve3.prototype.constructor = LineCurve3;
  25048. LineCurve3.prototype.getPoint = function ( t ) {
  25049. if ( t === 1 ) {
  25050. return this.v2.clone();
  25051. }
  25052. var vector = new Vector3();
  25053. vector.subVectors( this.v2, this.v1 ); // diff
  25054. vector.multiplyScalar( t );
  25055. vector.add( this.v1 );
  25056. return vector;
  25057. };
  25058. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  25059. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  25060. }
  25061. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  25062. ArcCurve.prototype.constructor = ArcCurve;
  25063. /**
  25064. * @author alteredq / http://alteredqualia.com/
  25065. */
  25066. var SceneUtils = {
  25067. createMultiMaterialObject: function ( geometry, materials ) {
  25068. var group = new Group();
  25069. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  25070. group.add( new Mesh( geometry, materials[ i ] ) );
  25071. }
  25072. return group;
  25073. },
  25074. detach: function ( child, parent, scene ) {
  25075. child.applyMatrix( parent.matrixWorld );
  25076. parent.remove( child );
  25077. scene.add( child );
  25078. },
  25079. attach: function ( child, scene, parent ) {
  25080. child.applyMatrix( new Matrix4().getInverse( parent.matrixWorld ) );
  25081. scene.remove( child );
  25082. parent.add( child );
  25083. }
  25084. };
  25085. /**
  25086. * @author mrdoob / http://mrdoob.com/
  25087. */
  25088. function Face4( a, b, c, d, normal, color, materialIndex ) {
  25089. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  25090. return new Face3( a, b, c, normal, color, materialIndex );
  25091. }
  25092. var LineStrip = 0;
  25093. var LinePieces = 1;
  25094. function MeshFaceMaterial( materials ) {
  25095. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  25096. return materials;
  25097. }
  25098. function MultiMaterial( materials ) {
  25099. if ( materials === undefined ) materials = [];
  25100. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  25101. materials.isMultiMaterial = true;
  25102. materials.materials = materials;
  25103. materials.clone = function () {
  25104. return materials.slice();
  25105. };
  25106. return materials;
  25107. }
  25108. function PointCloud( geometry, material ) {
  25109. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  25110. return new Points( geometry, material );
  25111. }
  25112. function Particle( material ) {
  25113. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  25114. return new Sprite( material );
  25115. }
  25116. function ParticleSystem( geometry, material ) {
  25117. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  25118. return new Points( geometry, material );
  25119. }
  25120. function PointCloudMaterial( parameters ) {
  25121. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  25122. return new PointsMaterial( parameters );
  25123. }
  25124. function ParticleBasicMaterial( parameters ) {
  25125. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  25126. return new PointsMaterial( parameters );
  25127. }
  25128. function ParticleSystemMaterial( parameters ) {
  25129. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  25130. return new PointsMaterial( parameters );
  25131. }
  25132. function Vertex( x, y, z ) {
  25133. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  25134. return new Vector3( x, y, z );
  25135. }
  25136. //
  25137. function DynamicBufferAttribute( array, itemSize ) {
  25138. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  25139. return new BufferAttribute( array, itemSize ).setDynamic( true );
  25140. }
  25141. function Int8Attribute( array, itemSize ) {
  25142. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  25143. return new Int8BufferAttribute( array, itemSize );
  25144. }
  25145. function Uint8Attribute( array, itemSize ) {
  25146. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  25147. return new Uint8BufferAttribute( array, itemSize );
  25148. }
  25149. function Uint8ClampedAttribute( array, itemSize ) {
  25150. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  25151. return new Uint8ClampedBufferAttribute( array, itemSize );
  25152. }
  25153. function Int16Attribute( array, itemSize ) {
  25154. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  25155. return new Int16BufferAttribute( array, itemSize );
  25156. }
  25157. function Uint16Attribute( array, itemSize ) {
  25158. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  25159. return new Uint16BufferAttribute( array, itemSize );
  25160. }
  25161. function Int32Attribute( array, itemSize ) {
  25162. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  25163. return new Int32BufferAttribute( array, itemSize );
  25164. }
  25165. function Uint32Attribute( array, itemSize ) {
  25166. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  25167. return new Uint32BufferAttribute( array, itemSize );
  25168. }
  25169. function Float32Attribute( array, itemSize ) {
  25170. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  25171. return new Float32BufferAttribute( array, itemSize );
  25172. }
  25173. function Float64Attribute( array, itemSize ) {
  25174. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  25175. return new Float64BufferAttribute( array, itemSize );
  25176. }
  25177. //
  25178. Curve.create = function ( construct, getPoint ) {
  25179. console.log( 'THREE.Curve.create() has been deprecated' );
  25180. construct.prototype = Object.create( Curve.prototype );
  25181. construct.prototype.constructor = construct;
  25182. construct.prototype.getPoint = getPoint;
  25183. return construct;
  25184. };
  25185. //
  25186. function ClosedSplineCurve3( points ) {
  25187. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  25188. CatmullRomCurve3.call( this, points );
  25189. this.type = 'catmullrom';
  25190. this.closed = true;
  25191. }
  25192. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  25193. //
  25194. function SplineCurve3( points ) {
  25195. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  25196. CatmullRomCurve3.call( this, points );
  25197. this.type = 'catmullrom';
  25198. }
  25199. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  25200. //
  25201. function Spline( points ) {
  25202. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  25203. CatmullRomCurve3.call( this, points );
  25204. this.type = 'catmullrom';
  25205. }
  25206. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  25207. Object.assign( Spline.prototype, {
  25208. initFromArray: function ( a ) {
  25209. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  25210. },
  25211. getControlPointsArray: function ( optionalTarget ) {
  25212. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  25213. },
  25214. reparametrizeByArcLength: function ( samplingCoef ) {
  25215. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  25216. }
  25217. } );
  25218. //
  25219. function BoundingBoxHelper( object, color ) {
  25220. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  25221. return new BoxHelper( object, color );
  25222. }
  25223. function EdgesHelper( object, hex ) {
  25224. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  25225. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  25226. }
  25227. GridHelper.prototype.setColors = function () {
  25228. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  25229. };
  25230. SkeletonHelper.prototype.update = function () {
  25231. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  25232. };
  25233. function WireframeHelper( object, hex ) {
  25234. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  25235. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  25236. }
  25237. //
  25238. function XHRLoader( manager ) {
  25239. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  25240. return new FileLoader( manager );
  25241. }
  25242. function BinaryTextureLoader( manager ) {
  25243. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  25244. return new DataTextureLoader( manager );
  25245. }
  25246. //
  25247. Object.assign( Box2.prototype, {
  25248. center: function ( optionalTarget ) {
  25249. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  25250. return this.getCenter( optionalTarget );
  25251. },
  25252. empty: function () {
  25253. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  25254. return this.isEmpty();
  25255. },
  25256. isIntersectionBox: function ( box ) {
  25257. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  25258. return this.intersectsBox( box );
  25259. },
  25260. size: function ( optionalTarget ) {
  25261. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  25262. return this.getSize( optionalTarget );
  25263. }
  25264. } );
  25265. Object.assign( Box3.prototype, {
  25266. center: function ( optionalTarget ) {
  25267. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  25268. return this.getCenter( optionalTarget );
  25269. },
  25270. empty: function () {
  25271. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  25272. return this.isEmpty();
  25273. },
  25274. isIntersectionBox: function ( box ) {
  25275. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  25276. return this.intersectsBox( box );
  25277. },
  25278. isIntersectionSphere: function ( sphere ) {
  25279. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  25280. return this.intersectsSphere( sphere );
  25281. },
  25282. size: function ( optionalTarget ) {
  25283. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  25284. return this.getSize( optionalTarget );
  25285. }
  25286. } );
  25287. Line3.prototype.center = function ( optionalTarget ) {
  25288. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  25289. return this.getCenter( optionalTarget );
  25290. };
  25291. _Math.random16 = function () {
  25292. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  25293. return Math.random();
  25294. };
  25295. Object.assign( Matrix3.prototype, {
  25296. flattenToArrayOffset: function ( array, offset ) {
  25297. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  25298. return this.toArray( array, offset );
  25299. },
  25300. multiplyVector3: function ( vector ) {
  25301. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  25302. return vector.applyMatrix3( this );
  25303. },
  25304. multiplyVector3Array: function ( a ) {
  25305. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  25306. },
  25307. applyToBuffer: function( buffer, offset, length ) {
  25308. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  25309. return this.applyToBufferAttribute( buffer );
  25310. },
  25311. applyToVector3Array: function( array, offset, length ) {
  25312. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  25313. }
  25314. } );
  25315. Object.assign( Matrix4.prototype, {
  25316. extractPosition: function ( m ) {
  25317. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  25318. return this.copyPosition( m );
  25319. },
  25320. flattenToArrayOffset: function ( array, offset ) {
  25321. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  25322. return this.toArray( array, offset );
  25323. },
  25324. getPosition: function () {
  25325. var v1;
  25326. return function getPosition() {
  25327. if ( v1 === undefined ) v1 = new Vector3();
  25328. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  25329. return v1.setFromMatrixColumn( this, 3 );
  25330. };
  25331. }(),
  25332. setRotationFromQuaternion: function ( q ) {
  25333. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  25334. return this.makeRotationFromQuaternion( q );
  25335. },
  25336. multiplyToArray: function () {
  25337. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  25338. },
  25339. multiplyVector3: function ( vector ) {
  25340. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  25341. return vector.applyMatrix4( this );
  25342. },
  25343. multiplyVector4: function ( vector ) {
  25344. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  25345. return vector.applyMatrix4( this );
  25346. },
  25347. multiplyVector3Array: function ( a ) {
  25348. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  25349. },
  25350. rotateAxis: function ( v ) {
  25351. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  25352. v.transformDirection( this );
  25353. },
  25354. crossVector: function ( vector ) {
  25355. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  25356. return vector.applyMatrix4( this );
  25357. },
  25358. translate: function () {
  25359. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  25360. },
  25361. rotateX: function () {
  25362. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  25363. },
  25364. rotateY: function () {
  25365. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  25366. },
  25367. rotateZ: function () {
  25368. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  25369. },
  25370. rotateByAxis: function () {
  25371. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  25372. },
  25373. applyToBuffer: function( buffer, offset, length ) {
  25374. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  25375. return this.applyToBufferAttribute( buffer );
  25376. },
  25377. applyToVector3Array: function( array, offset, length ) {
  25378. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  25379. },
  25380. makeFrustum: function( left, right, bottom, top, near, far ) {
  25381. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  25382. return this.makePerspective( left, right, top, bottom, near, far );
  25383. }
  25384. } );
  25385. Plane.prototype.isIntersectionLine = function ( line ) {
  25386. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  25387. return this.intersectsLine( line );
  25388. };
  25389. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  25390. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  25391. return vector.applyQuaternion( this );
  25392. };
  25393. Object.assign( Ray.prototype, {
  25394. isIntersectionBox: function ( box ) {
  25395. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  25396. return this.intersectsBox( box );
  25397. },
  25398. isIntersectionPlane: function ( plane ) {
  25399. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  25400. return this.intersectsPlane( plane );
  25401. },
  25402. isIntersectionSphere: function ( sphere ) {
  25403. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  25404. return this.intersectsSphere( sphere );
  25405. }
  25406. } );
  25407. Object.assign( Shape.prototype, {
  25408. extrude: function ( options ) {
  25409. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  25410. return new ExtrudeGeometry( this, options );
  25411. },
  25412. makeGeometry: function ( options ) {
  25413. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  25414. return new ShapeGeometry( this, options );
  25415. }
  25416. } );
  25417. Object.assign( Vector2.prototype, {
  25418. fromAttribute: function ( attribute, index, offset ) {
  25419. console.error( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  25420. return this.fromBufferAttribute( attribute, index, offset );
  25421. }
  25422. } );
  25423. Object.assign( Vector3.prototype, {
  25424. setEulerFromRotationMatrix: function () {
  25425. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  25426. },
  25427. setEulerFromQuaternion: function () {
  25428. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  25429. },
  25430. getPositionFromMatrix: function ( m ) {
  25431. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  25432. return this.setFromMatrixPosition( m );
  25433. },
  25434. getScaleFromMatrix: function ( m ) {
  25435. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  25436. return this.setFromMatrixScale( m );
  25437. },
  25438. getColumnFromMatrix: function ( index, matrix ) {
  25439. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  25440. return this.setFromMatrixColumn( matrix, index );
  25441. },
  25442. applyProjection: function ( m ) {
  25443. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  25444. return this.applyMatrix4( m );
  25445. },
  25446. fromAttribute: function ( attribute, index, offset ) {
  25447. console.error( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  25448. return this.fromBufferAttribute( attribute, index, offset );
  25449. }
  25450. } );
  25451. Object.assign( Vector4.prototype, {
  25452. fromAttribute: function ( attribute, index, offset ) {
  25453. console.error( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  25454. return this.fromBufferAttribute( attribute, index, offset );
  25455. }
  25456. } );
  25457. //
  25458. Geometry.prototype.computeTangents = function () {
  25459. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  25460. };
  25461. Object.assign( Object3D.prototype, {
  25462. getChildByName: function ( name ) {
  25463. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  25464. return this.getObjectByName( name );
  25465. },
  25466. renderDepth: function () {
  25467. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  25468. },
  25469. translate: function ( distance, axis ) {
  25470. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  25471. return this.translateOnAxis( axis, distance );
  25472. }
  25473. } );
  25474. Object.defineProperties( Object3D.prototype, {
  25475. eulerOrder: {
  25476. get: function () {
  25477. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  25478. return this.rotation.order;
  25479. },
  25480. set: function ( value ) {
  25481. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  25482. this.rotation.order = value;
  25483. }
  25484. },
  25485. useQuaternion: {
  25486. get: function () {
  25487. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  25488. },
  25489. set: function () {
  25490. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  25491. }
  25492. }
  25493. } );
  25494. Object.defineProperties( LOD.prototype, {
  25495. objects: {
  25496. get: function () {
  25497. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  25498. return this.levels;
  25499. }
  25500. }
  25501. } );
  25502. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  25503. get: function () {
  25504. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  25505. },
  25506. set: function () {
  25507. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  25508. }
  25509. } );
  25510. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  25511. get: function () {
  25512. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  25513. return this.arcLengthDivisions;
  25514. },
  25515. set: function ( value ) {
  25516. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  25517. this.arcLengthDivisions = value;
  25518. }
  25519. } );
  25520. //
  25521. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  25522. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  25523. "Use .setFocalLength and .filmGauge for a photographic setup." );
  25524. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  25525. this.setFocalLength( focalLength );
  25526. };
  25527. //
  25528. Object.defineProperties( Light.prototype, {
  25529. onlyShadow: {
  25530. set: function () {
  25531. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  25532. }
  25533. },
  25534. shadowCameraFov: {
  25535. set: function ( value ) {
  25536. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  25537. this.shadow.camera.fov = value;
  25538. }
  25539. },
  25540. shadowCameraLeft: {
  25541. set: function ( value ) {
  25542. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  25543. this.shadow.camera.left = value;
  25544. }
  25545. },
  25546. shadowCameraRight: {
  25547. set: function ( value ) {
  25548. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  25549. this.shadow.camera.right = value;
  25550. }
  25551. },
  25552. shadowCameraTop: {
  25553. set: function ( value ) {
  25554. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  25555. this.shadow.camera.top = value;
  25556. }
  25557. },
  25558. shadowCameraBottom: {
  25559. set: function ( value ) {
  25560. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  25561. this.shadow.camera.bottom = value;
  25562. }
  25563. },
  25564. shadowCameraNear: {
  25565. set: function ( value ) {
  25566. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  25567. this.shadow.camera.near = value;
  25568. }
  25569. },
  25570. shadowCameraFar: {
  25571. set: function ( value ) {
  25572. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  25573. this.shadow.camera.far = value;
  25574. }
  25575. },
  25576. shadowCameraVisible: {
  25577. set: function () {
  25578. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  25579. }
  25580. },
  25581. shadowBias: {
  25582. set: function ( value ) {
  25583. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  25584. this.shadow.bias = value;
  25585. }
  25586. },
  25587. shadowDarkness: {
  25588. set: function () {
  25589. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  25590. }
  25591. },
  25592. shadowMapWidth: {
  25593. set: function ( value ) {
  25594. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  25595. this.shadow.mapSize.width = value;
  25596. }
  25597. },
  25598. shadowMapHeight: {
  25599. set: function ( value ) {
  25600. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  25601. this.shadow.mapSize.height = value;
  25602. }
  25603. }
  25604. } );
  25605. //
  25606. Object.defineProperties( BufferAttribute.prototype, {
  25607. length: {
  25608. get: function () {
  25609. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  25610. return this.array.length;
  25611. }
  25612. }
  25613. } );
  25614. Object.assign( BufferGeometry.prototype, {
  25615. addIndex: function ( index ) {
  25616. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  25617. this.setIndex( index );
  25618. },
  25619. addDrawCall: function ( start, count, indexOffset ) {
  25620. if ( indexOffset !== undefined ) {
  25621. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  25622. }
  25623. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  25624. this.addGroup( start, count );
  25625. },
  25626. clearDrawCalls: function () {
  25627. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  25628. this.clearGroups();
  25629. },
  25630. computeTangents: function () {
  25631. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  25632. },
  25633. computeOffsets: function () {
  25634. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  25635. }
  25636. } );
  25637. Object.defineProperties( BufferGeometry.prototype, {
  25638. drawcalls: {
  25639. get: function () {
  25640. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  25641. return this.groups;
  25642. }
  25643. },
  25644. offsets: {
  25645. get: function () {
  25646. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  25647. return this.groups;
  25648. }
  25649. }
  25650. } );
  25651. //
  25652. Object.defineProperties( Uniform.prototype, {
  25653. dynamic: {
  25654. set: function () {
  25655. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  25656. }
  25657. },
  25658. onUpdate: {
  25659. value: function () {
  25660. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  25661. return this;
  25662. }
  25663. }
  25664. } );
  25665. //
  25666. Object.defineProperties( Material.prototype, {
  25667. wrapAround: {
  25668. get: function () {
  25669. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  25670. },
  25671. set: function () {
  25672. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  25673. }
  25674. },
  25675. wrapRGB: {
  25676. get: function () {
  25677. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  25678. return new Color();
  25679. }
  25680. }
  25681. } );
  25682. Object.defineProperties( MeshPhongMaterial.prototype, {
  25683. metal: {
  25684. get: function () {
  25685. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  25686. return false;
  25687. },
  25688. set: function () {
  25689. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  25690. }
  25691. }
  25692. } );
  25693. Object.defineProperties( ShaderMaterial.prototype, {
  25694. derivatives: {
  25695. get: function () {
  25696. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  25697. return this.extensions.derivatives;
  25698. },
  25699. set: function ( value ) {
  25700. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  25701. this.extensions.derivatives = value;
  25702. }
  25703. }
  25704. } );
  25705. //
  25706. Object.assign( WebGLRenderer.prototype, {
  25707. getCurrentRenderTarget: function () {
  25708. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  25709. return this.getRenderTarget();
  25710. },
  25711. supportsFloatTextures: function () {
  25712. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  25713. return this.extensions.get( 'OES_texture_float' );
  25714. },
  25715. supportsHalfFloatTextures: function () {
  25716. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  25717. return this.extensions.get( 'OES_texture_half_float' );
  25718. },
  25719. supportsStandardDerivatives: function () {
  25720. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  25721. return this.extensions.get( 'OES_standard_derivatives' );
  25722. },
  25723. supportsCompressedTextureS3TC: function () {
  25724. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  25725. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  25726. },
  25727. supportsCompressedTexturePVRTC: function () {
  25728. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  25729. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  25730. },
  25731. supportsBlendMinMax: function () {
  25732. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  25733. return this.extensions.get( 'EXT_blend_minmax' );
  25734. },
  25735. supportsVertexTextures: function () {
  25736. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  25737. return this.capabilities.vertexTextures;
  25738. },
  25739. supportsInstancedArrays: function () {
  25740. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  25741. return this.extensions.get( 'ANGLE_instanced_arrays' );
  25742. },
  25743. enableScissorTest: function ( boolean ) {
  25744. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  25745. this.setScissorTest( boolean );
  25746. },
  25747. initMaterial: function () {
  25748. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  25749. },
  25750. addPrePlugin: function () {
  25751. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  25752. },
  25753. addPostPlugin: function () {
  25754. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  25755. },
  25756. updateShadowMap: function () {
  25757. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  25758. }
  25759. } );
  25760. Object.defineProperties( WebGLRenderer.prototype, {
  25761. shadowMapEnabled: {
  25762. get: function () {
  25763. return this.shadowMap.enabled;
  25764. },
  25765. set: function ( value ) {
  25766. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  25767. this.shadowMap.enabled = value;
  25768. }
  25769. },
  25770. shadowMapType: {
  25771. get: function () {
  25772. return this.shadowMap.type;
  25773. },
  25774. set: function ( value ) {
  25775. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  25776. this.shadowMap.type = value;
  25777. }
  25778. },
  25779. shadowMapCullFace: {
  25780. get: function () {
  25781. return this.shadowMap.cullFace;
  25782. },
  25783. set: function ( value ) {
  25784. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  25785. this.shadowMap.cullFace = value;
  25786. }
  25787. }
  25788. } );
  25789. Object.defineProperties( WebGLShadowMap.prototype, {
  25790. cullFace: {
  25791. get: function () {
  25792. return this.renderReverseSided ? CullFaceFront : CullFaceBack;
  25793. },
  25794. set: function ( cullFace ) {
  25795. var value = ( cullFace !== CullFaceBack );
  25796. console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. Set .shadowMap.renderReverseSided to " + value + "." );
  25797. this.renderReverseSided = value;
  25798. }
  25799. }
  25800. } );
  25801. //
  25802. Object.defineProperties( WebGLRenderTarget.prototype, {
  25803. wrapS: {
  25804. get: function () {
  25805. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  25806. return this.texture.wrapS;
  25807. },
  25808. set: function ( value ) {
  25809. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  25810. this.texture.wrapS = value;
  25811. }
  25812. },
  25813. wrapT: {
  25814. get: function () {
  25815. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  25816. return this.texture.wrapT;
  25817. },
  25818. set: function ( value ) {
  25819. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  25820. this.texture.wrapT = value;
  25821. }
  25822. },
  25823. magFilter: {
  25824. get: function () {
  25825. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  25826. return this.texture.magFilter;
  25827. },
  25828. set: function ( value ) {
  25829. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  25830. this.texture.magFilter = value;
  25831. }
  25832. },
  25833. minFilter: {
  25834. get: function () {
  25835. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  25836. return this.texture.minFilter;
  25837. },
  25838. set: function ( value ) {
  25839. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  25840. this.texture.minFilter = value;
  25841. }
  25842. },
  25843. anisotropy: {
  25844. get: function () {
  25845. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  25846. return this.texture.anisotropy;
  25847. },
  25848. set: function ( value ) {
  25849. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  25850. this.texture.anisotropy = value;
  25851. }
  25852. },
  25853. offset: {
  25854. get: function () {
  25855. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  25856. return this.texture.offset;
  25857. },
  25858. set: function ( value ) {
  25859. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  25860. this.texture.offset = value;
  25861. }
  25862. },
  25863. repeat: {
  25864. get: function () {
  25865. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  25866. return this.texture.repeat;
  25867. },
  25868. set: function ( value ) {
  25869. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  25870. this.texture.repeat = value;
  25871. }
  25872. },
  25873. format: {
  25874. get: function () {
  25875. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  25876. return this.texture.format;
  25877. },
  25878. set: function ( value ) {
  25879. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  25880. this.texture.format = value;
  25881. }
  25882. },
  25883. type: {
  25884. get: function () {
  25885. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  25886. return this.texture.type;
  25887. },
  25888. set: function ( value ) {
  25889. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  25890. this.texture.type = value;
  25891. }
  25892. },
  25893. generateMipmaps: {
  25894. get: function () {
  25895. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  25896. return this.texture.generateMipmaps;
  25897. },
  25898. set: function ( value ) {
  25899. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  25900. this.texture.generateMipmaps = value;
  25901. }
  25902. }
  25903. } );
  25904. //
  25905. Audio.prototype.load = function ( file ) {
  25906. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  25907. var scope = this;
  25908. var audioLoader = new AudioLoader();
  25909. audioLoader.load( file, function ( buffer ) {
  25910. scope.setBuffer( buffer );
  25911. } );
  25912. return this;
  25913. };
  25914. AudioAnalyser.prototype.getData = function () {
  25915. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  25916. return this.getFrequencyData();
  25917. };
  25918. //
  25919. var GeometryUtils = {
  25920. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  25921. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  25922. var matrix;
  25923. if ( geometry2.isMesh ) {
  25924. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  25925. matrix = geometry2.matrix;
  25926. geometry2 = geometry2.geometry;
  25927. }
  25928. geometry1.merge( geometry2, matrix, materialIndexOffset );
  25929. },
  25930. center: function ( geometry ) {
  25931. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  25932. return geometry.center();
  25933. }
  25934. };
  25935. var ImageUtils = {
  25936. crossOrigin: undefined,
  25937. loadTexture: function ( url, mapping, onLoad, onError ) {
  25938. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  25939. var loader = new TextureLoader();
  25940. loader.setCrossOrigin( this.crossOrigin );
  25941. var texture = loader.load( url, onLoad, undefined, onError );
  25942. if ( mapping ) texture.mapping = mapping;
  25943. return texture;
  25944. },
  25945. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  25946. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  25947. var loader = new CubeTextureLoader();
  25948. loader.setCrossOrigin( this.crossOrigin );
  25949. var texture = loader.load( urls, onLoad, undefined, onError );
  25950. if ( mapping ) texture.mapping = mapping;
  25951. return texture;
  25952. },
  25953. loadCompressedTexture: function () {
  25954. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  25955. },
  25956. loadCompressedTextureCube: function () {
  25957. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  25958. }
  25959. };
  25960. //
  25961. function Projector() {
  25962. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  25963. this.projectVector = function ( vector, camera ) {
  25964. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  25965. vector.project( camera );
  25966. };
  25967. this.unprojectVector = function ( vector, camera ) {
  25968. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  25969. vector.unproject( camera );
  25970. };
  25971. this.pickingRay = function () {
  25972. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  25973. };
  25974. }
  25975. //
  25976. function CanvasRenderer() {
  25977. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  25978. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  25979. this.clear = function () {};
  25980. this.render = function () {};
  25981. this.setClearColor = function () {};
  25982. this.setSize = function () {};
  25983. }
  25984. export { WebGLRenderTargetCube, WebGLRenderTarget, WebGLRenderer, ShaderLib, UniformsLib, UniformsUtils, ShaderChunk, FogExp2, Fog, Scene, LensFlare, Sprite, LOD, SkinnedMesh, Skeleton, Bone, Mesh, LineSegments, LineLoop, Line, Points, Group, VideoTexture, DataTexture, CompressedTexture, CubeTexture, CanvasTexture, DepthTexture, Texture, CompressedTextureLoader, DataTextureLoader, CubeTextureLoader, TextureLoader, ObjectLoader, MaterialLoader, BufferGeometryLoader, DefaultLoadingManager, LoadingManager, JSONLoader, ImageLoader, FontLoader, FileLoader, Loader, Cache, AudioLoader, SpotLightShadow, SpotLight, PointLight, RectAreaLight, HemisphereLight, DirectionalLightShadow, DirectionalLight, AmbientLight, LightShadow, Light, StereoCamera, PerspectiveCamera, OrthographicCamera, CubeCamera, ArrayCamera, Camera, AudioListener, PositionalAudio, AudioContext, AudioAnalyser, Audio, VectorKeyframeTrack, StringKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, ColorKeyframeTrack, BooleanKeyframeTrack, PropertyMixer, PropertyBinding, KeyframeTrack, AnimationUtils, AnimationObjectGroup, AnimationMixer, AnimationClip, Uniform, InstancedBufferGeometry, BufferGeometry, GeometryIdCount, Geometry, InterleavedBufferAttribute, InstancedInterleavedBuffer, InterleavedBuffer, InstancedBufferAttribute, Face3, Object3D, Raycaster, Layers, EventDispatcher, Clock, QuaternionLinearInterpolant, LinearInterpolant, DiscreteInterpolant, CubicInterpolant, Interpolant, Triangle, _Math as Math, Spherical, Cylindrical, Plane, Frustum, Sphere, Ray, Matrix4, Matrix3, Box3, Box2, Line3, Euler, Vector4, Vector3, Vector2, Quaternion, Color, MorphBlendMesh, ImmediateRenderObject, VertexNormalsHelper, SpotLightHelper, SkeletonHelper, PointLightHelper, RectAreaLightHelper, HemisphereLightHelper, GridHelper, PolarGridHelper, FaceNormalsHelper, DirectionalLightHelper, CameraHelper, BoxHelper, ArrowHelper, AxisHelper, CatmullRomCurve3, CubicBezierCurve3, QuadraticBezierCurve3, LineCurve3, ArcCurve, EllipseCurve, SplineCurve, CubicBezierCurve, QuadraticBezierCurve, LineCurve, Shape, Path, ShapePath, Font, CurvePath, Curve, ShapeUtils, SceneUtils, WireframeGeometry, ParametricGeometry, ParametricBufferGeometry, TetrahedronGeometry, TetrahedronBufferGeometry, OctahedronGeometry, OctahedronBufferGeometry, IcosahedronGeometry, IcosahedronBufferGeometry, DodecahedronGeometry, DodecahedronBufferGeometry, PolyhedronGeometry, PolyhedronBufferGeometry, TubeGeometry, TubeBufferGeometry, TorusKnotGeometry, TorusKnotBufferGeometry, TorusGeometry, TorusBufferGeometry, TextGeometry, TextBufferGeometry, SphereGeometry, SphereBufferGeometry, RingGeometry, RingBufferGeometry, PlaneGeometry, PlaneBufferGeometry, LatheGeometry, LatheBufferGeometry, ShapeGeometry, ShapeBufferGeometry, ExtrudeGeometry, ExtrudeBufferGeometry, EdgesGeometry, ConeGeometry, ConeBufferGeometry, CylinderGeometry, CylinderBufferGeometry, CircleGeometry, CircleBufferGeometry, BoxGeometry, BoxBufferGeometry, ShadowMaterial, SpriteMaterial, RawShaderMaterial, ShaderMaterial, PointsMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshPhongMaterial, MeshToonMaterial, MeshNormalMaterial, MeshLambertMaterial, MeshDepthMaterial, MeshBasicMaterial, LineDashedMaterial, LineBasicMaterial, Material, Float64BufferAttribute, Float32BufferAttribute, Uint32BufferAttribute, Int32BufferAttribute, Uint16BufferAttribute, Int16BufferAttribute, Uint8ClampedBufferAttribute, Uint8BufferAttribute, Int8BufferAttribute, BufferAttribute, REVISION, MOUSE, CullFaceNone, CullFaceBack, CullFaceFront, CullFaceFrontBack, FrontFaceDirectionCW, FrontFaceDirectionCCW, BasicShadowMap, PCFShadowMap, PCFSoftShadowMap, FrontSide, BackSide, DoubleSide, FlatShading, SmoothShading, NoColors, FaceColors, VertexColors, NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor, NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth, MultiplyOperation, MixOperation, AddOperation, NoToneMapping, LinearToneMapping, ReinhardToneMapping, Uncharted2ToneMapping, CineonToneMapping, UVMapping, CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, SphericalReflectionMapping, CubeUVReflectionMapping, CubeUVRefractionMapping, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter, LinearFilter, LinearMipMapNearestFilter, LinearMipMapLinearFilter, UnsignedByteType, ByteType, ShortType, UnsignedShortType, IntType, UnsignedIntType, FloatType, HalfFloatType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedInt248Type, AlphaFormat, RGBFormat, RGBAFormat, LuminanceFormat, LuminanceAlphaFormat, RGBEFormat, DepthFormat, DepthStencilFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, LoopOnce, LoopRepeat, LoopPingPong, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, ZeroCurvatureEnding, ZeroSlopeEnding, WrapAroundEnding, TrianglesDrawMode, TriangleStripDrawMode, TriangleFanDrawMode, LinearEncoding, sRGBEncoding, GammaEncoding, RGBEEncoding, LogLuvEncoding, RGBM7Encoding, RGBM16Encoding, RGBDEncoding, BasicDepthPacking, RGBADepthPacking, BoxGeometry as CubeGeometry, Face4, LineStrip, LinePieces, MeshFaceMaterial, MultiMaterial, PointCloud, Particle, ParticleSystem, PointCloudMaterial, ParticleBasicMaterial, ParticleSystemMaterial, Vertex, DynamicBufferAttribute, Int8Attribute, Uint8Attribute, Uint8ClampedAttribute, Int16Attribute, Uint16Attribute, Int32Attribute, Uint32Attribute, Float32Attribute, Float64Attribute, ClosedSplineCurve3, SplineCurve3, Spline, BoundingBoxHelper, EdgesHelper, WireframeHelper, XHRLoader, BinaryTextureLoader, GeometryUtils, ImageUtils, Projector, CanvasRenderer };