three.js 1009 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.THREE = global.THREE || {})));
  5. }(this, (function (exports) { 'use strict';
  6. // Polyfills
  7. if ( Number.EPSILON === undefined ) {
  8. Number.EPSILON = Math.pow( 2, - 52 );
  9. }
  10. if ( Number.isInteger === undefined ) {
  11. // Missing in IE
  12. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  13. Number.isInteger = function ( value ) {
  14. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  15. };
  16. }
  17. //
  18. if ( Math.sign === undefined ) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function ( x ) {
  21. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  22. };
  23. }
  24. if ( Function.prototype.name === undefined ) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty( Function.prototype, 'name', {
  28. get: function () {
  29. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  30. }
  31. } );
  32. }
  33. if ( Object.assign === undefined ) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. ( function () {
  37. Object.assign = function ( target ) {
  38. 'use strict';
  39. if ( target === undefined || target === null ) {
  40. throw new TypeError( 'Cannot convert undefined or null to object' );
  41. }
  42. var output = Object( target );
  43. for ( var index = 1; index < arguments.length; index ++ ) {
  44. var source = arguments[ index ];
  45. if ( source !== undefined && source !== null ) {
  46. for ( var nextKey in source ) {
  47. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  48. output[ nextKey ] = source[ nextKey ];
  49. }
  50. }
  51. }
  52. }
  53. return output;
  54. };
  55. } )();
  56. }
  57. /**
  58. * https://github.com/mrdoob/eventdispatcher.js/
  59. */
  60. function EventDispatcher() {}
  61. Object.assign( EventDispatcher.prototype, {
  62. addEventListener: function ( type, listener ) {
  63. if ( this._listeners === undefined ) this._listeners = {};
  64. var listeners = this._listeners;
  65. if ( listeners[ type ] === undefined ) {
  66. listeners[ type ] = [];
  67. }
  68. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  69. listeners[ type ].push( listener );
  70. }
  71. },
  72. hasEventListener: function ( type, listener ) {
  73. if ( this._listeners === undefined ) return false;
  74. var listeners = this._listeners;
  75. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  76. },
  77. removeEventListener: function ( type, listener ) {
  78. if ( this._listeners === undefined ) return;
  79. var listeners = this._listeners;
  80. var listenerArray = listeners[ type ];
  81. if ( listenerArray !== undefined ) {
  82. var index = listenerArray.indexOf( listener );
  83. if ( index !== - 1 ) {
  84. listenerArray.splice( index, 1 );
  85. }
  86. }
  87. },
  88. dispatchEvent: function ( event ) {
  89. if ( this._listeners === undefined ) return;
  90. var listeners = this._listeners;
  91. var listenerArray = listeners[ event.type ];
  92. if ( listenerArray !== undefined ) {
  93. event.target = this;
  94. var array = [], i = 0;
  95. var length = listenerArray.length;
  96. for ( i = 0; i < length; i ++ ) {
  97. array[ i ] = listenerArray[ i ];
  98. }
  99. for ( i = 0; i < length; i ++ ) {
  100. array[ i ].call( this, event );
  101. }
  102. }
  103. }
  104. } );
  105. var REVISION = '86dev';
  106. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  107. var CullFaceNone = 0;
  108. var CullFaceBack = 1;
  109. var CullFaceFront = 2;
  110. var CullFaceFrontBack = 3;
  111. var FrontFaceDirectionCW = 0;
  112. var FrontFaceDirectionCCW = 1;
  113. var BasicShadowMap = 0;
  114. var PCFShadowMap = 1;
  115. var PCFSoftShadowMap = 2;
  116. var FrontSide = 0;
  117. var BackSide = 1;
  118. var DoubleSide = 2;
  119. var FlatShading = 1;
  120. var SmoothShading = 2;
  121. var NoColors = 0;
  122. var FaceColors = 1;
  123. var VertexColors = 2;
  124. var NoBlending = 0;
  125. var NormalBlending = 1;
  126. var AdditiveBlending = 2;
  127. var SubtractiveBlending = 3;
  128. var MultiplyBlending = 4;
  129. var CustomBlending = 5;
  130. var AddEquation = 100;
  131. var SubtractEquation = 101;
  132. var ReverseSubtractEquation = 102;
  133. var MinEquation = 103;
  134. var MaxEquation = 104;
  135. var ZeroFactor = 200;
  136. var OneFactor = 201;
  137. var SrcColorFactor = 202;
  138. var OneMinusSrcColorFactor = 203;
  139. var SrcAlphaFactor = 204;
  140. var OneMinusSrcAlphaFactor = 205;
  141. var DstAlphaFactor = 206;
  142. var OneMinusDstAlphaFactor = 207;
  143. var DstColorFactor = 208;
  144. var OneMinusDstColorFactor = 209;
  145. var SrcAlphaSaturateFactor = 210;
  146. var NeverDepth = 0;
  147. var AlwaysDepth = 1;
  148. var LessDepth = 2;
  149. var LessEqualDepth = 3;
  150. var EqualDepth = 4;
  151. var GreaterEqualDepth = 5;
  152. var GreaterDepth = 6;
  153. var NotEqualDepth = 7;
  154. var MultiplyOperation = 0;
  155. var MixOperation = 1;
  156. var AddOperation = 2;
  157. var NoToneMapping = 0;
  158. var LinearToneMapping = 1;
  159. var ReinhardToneMapping = 2;
  160. var Uncharted2ToneMapping = 3;
  161. var CineonToneMapping = 4;
  162. var UVMapping = 300;
  163. var CubeReflectionMapping = 301;
  164. var CubeRefractionMapping = 302;
  165. var EquirectangularReflectionMapping = 303;
  166. var EquirectangularRefractionMapping = 304;
  167. var SphericalReflectionMapping = 305;
  168. var CubeUVReflectionMapping = 306;
  169. var CubeUVRefractionMapping = 307;
  170. var RepeatWrapping = 1000;
  171. var ClampToEdgeWrapping = 1001;
  172. var MirroredRepeatWrapping = 1002;
  173. var NearestFilter = 1003;
  174. var NearestMipMapNearestFilter = 1004;
  175. var NearestMipMapLinearFilter = 1005;
  176. var LinearFilter = 1006;
  177. var LinearMipMapNearestFilter = 1007;
  178. var LinearMipMapLinearFilter = 1008;
  179. var UnsignedByteType = 1009;
  180. var ByteType = 1010;
  181. var ShortType = 1011;
  182. var UnsignedShortType = 1012;
  183. var IntType = 1013;
  184. var UnsignedIntType = 1014;
  185. var FloatType = 1015;
  186. var HalfFloatType = 1016;
  187. var UnsignedShort4444Type = 1017;
  188. var UnsignedShort5551Type = 1018;
  189. var UnsignedShort565Type = 1019;
  190. var UnsignedInt248Type = 1020;
  191. var AlphaFormat = 1021;
  192. var RGBFormat = 1022;
  193. var RGBAFormat = 1023;
  194. var LuminanceFormat = 1024;
  195. var LuminanceAlphaFormat = 1025;
  196. var RGBEFormat = RGBAFormat;
  197. var DepthFormat = 1026;
  198. var DepthStencilFormat = 1027;
  199. var RGB_S3TC_DXT1_Format = 2001;
  200. var RGBA_S3TC_DXT1_Format = 2002;
  201. var RGBA_S3TC_DXT3_Format = 2003;
  202. var RGBA_S3TC_DXT5_Format = 2004;
  203. var RGB_PVRTC_4BPPV1_Format = 2100;
  204. var RGB_PVRTC_2BPPV1_Format = 2101;
  205. var RGBA_PVRTC_4BPPV1_Format = 2102;
  206. var RGBA_PVRTC_2BPPV1_Format = 2103;
  207. var RGB_ETC1_Format = 2151;
  208. var LoopOnce = 2200;
  209. var LoopRepeat = 2201;
  210. var LoopPingPong = 2202;
  211. var InterpolateDiscrete = 2300;
  212. var InterpolateLinear = 2301;
  213. var InterpolateSmooth = 2302;
  214. var ZeroCurvatureEnding = 2400;
  215. var ZeroSlopeEnding = 2401;
  216. var WrapAroundEnding = 2402;
  217. var TrianglesDrawMode = 0;
  218. var TriangleStripDrawMode = 1;
  219. var TriangleFanDrawMode = 2;
  220. var LinearEncoding = 3000;
  221. var sRGBEncoding = 3001;
  222. var GammaEncoding = 3007;
  223. var RGBEEncoding = 3002;
  224. var LogLuvEncoding = 3003;
  225. var RGBM7Encoding = 3004;
  226. var RGBM16Encoding = 3005;
  227. var RGBDEncoding = 3006;
  228. var BasicDepthPacking = 3200;
  229. var RGBADepthPacking = 3201;
  230. /**
  231. * @author alteredq / http://alteredqualia.com/
  232. * @author mrdoob / http://mrdoob.com/
  233. */
  234. var _Math = {
  235. DEG2RAD: Math.PI / 180,
  236. RAD2DEG: 180 / Math.PI,
  237. generateUUID: function () {
  238. // http://www.broofa.com/Tools/Math.uuid.htm
  239. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  240. var uuid = new Array( 36 );
  241. var rnd = 0, r;
  242. return function generateUUID() {
  243. for ( var i = 0; i < 36; i ++ ) {
  244. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  245. uuid[ i ] = '-';
  246. } else if ( i === 14 ) {
  247. uuid[ i ] = '4';
  248. } else {
  249. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  250. r = rnd & 0xf;
  251. rnd = rnd >> 4;
  252. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  253. }
  254. }
  255. return uuid.join( '' );
  256. };
  257. }(),
  258. clamp: function ( value, min, max ) {
  259. return Math.max( min, Math.min( max, value ) );
  260. },
  261. // compute euclidian modulo of m % n
  262. // https://en.wikipedia.org/wiki/Modulo_operation
  263. euclideanModulo: function ( n, m ) {
  264. return ( ( n % m ) + m ) % m;
  265. },
  266. // Linear mapping from range <a1, a2> to range <b1, b2>
  267. mapLinear: function ( x, a1, a2, b1, b2 ) {
  268. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  269. },
  270. // https://en.wikipedia.org/wiki/Linear_interpolation
  271. lerp: function ( x, y, t ) {
  272. return ( 1 - t ) * x + t * y;
  273. },
  274. // http://en.wikipedia.org/wiki/Smoothstep
  275. smoothstep: function ( x, min, max ) {
  276. if ( x <= min ) return 0;
  277. if ( x >= max ) return 1;
  278. x = ( x - min ) / ( max - min );
  279. return x * x * ( 3 - 2 * x );
  280. },
  281. smootherstep: function ( x, min, max ) {
  282. if ( x <= min ) return 0;
  283. if ( x >= max ) return 1;
  284. x = ( x - min ) / ( max - min );
  285. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  286. },
  287. // Random integer from <low, high> interval
  288. randInt: function ( low, high ) {
  289. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  290. },
  291. // Random float from <low, high> interval
  292. randFloat: function ( low, high ) {
  293. return low + Math.random() * ( high - low );
  294. },
  295. // Random float from <-range/2, range/2> interval
  296. randFloatSpread: function ( range ) {
  297. return range * ( 0.5 - Math.random() );
  298. },
  299. degToRad: function ( degrees ) {
  300. return degrees * _Math.DEG2RAD;
  301. },
  302. radToDeg: function ( radians ) {
  303. return radians * _Math.RAD2DEG;
  304. },
  305. isPowerOfTwo: function ( value ) {
  306. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  307. },
  308. nearestPowerOfTwo: function ( value ) {
  309. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  310. },
  311. nextPowerOfTwo: function ( value ) {
  312. value --;
  313. value |= value >> 1;
  314. value |= value >> 2;
  315. value |= value >> 4;
  316. value |= value >> 8;
  317. value |= value >> 16;
  318. value ++;
  319. return value;
  320. }
  321. };
  322. /**
  323. * @author mrdoob / http://mrdoob.com/
  324. * @author philogb / http://blog.thejit.org/
  325. * @author egraether / http://egraether.com/
  326. * @author zz85 / http://www.lab4games.net/zz85/blog
  327. */
  328. function Vector2( x, y ) {
  329. this.x = x || 0;
  330. this.y = y || 0;
  331. }
  332. Object.defineProperties( Vector2.prototype, {
  333. "width" : {
  334. get: function () {
  335. return this.x;
  336. },
  337. set: function ( value ) {
  338. this.x = value;
  339. }
  340. },
  341. "height" : {
  342. get: function () {
  343. return this.y;
  344. },
  345. set: function ( value ) {
  346. this.y = value;
  347. }
  348. }
  349. } );
  350. Object.assign( Vector2.prototype, {
  351. isVector2: true,
  352. set: function ( x, y ) {
  353. this.x = x;
  354. this.y = y;
  355. return this;
  356. },
  357. setScalar: function ( scalar ) {
  358. this.x = scalar;
  359. this.y = scalar;
  360. return this;
  361. },
  362. setX: function ( x ) {
  363. this.x = x;
  364. return this;
  365. },
  366. setY: function ( y ) {
  367. this.y = y;
  368. return this;
  369. },
  370. setComponent: function ( index, value ) {
  371. switch ( index ) {
  372. case 0: this.x = value; break;
  373. case 1: this.y = value; break;
  374. default: throw new Error( 'index is out of range: ' + index );
  375. }
  376. return this;
  377. },
  378. getComponent: function ( index ) {
  379. switch ( index ) {
  380. case 0: return this.x;
  381. case 1: return this.y;
  382. default: throw new Error( 'index is out of range: ' + index );
  383. }
  384. },
  385. clone: function () {
  386. return new this.constructor( this.x, this.y );
  387. },
  388. copy: function ( v ) {
  389. this.x = v.x;
  390. this.y = v.y;
  391. return this;
  392. },
  393. add: function ( v, w ) {
  394. if ( w !== undefined ) {
  395. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  396. return this.addVectors( v, w );
  397. }
  398. this.x += v.x;
  399. this.y += v.y;
  400. return this;
  401. },
  402. addScalar: function ( s ) {
  403. this.x += s;
  404. this.y += s;
  405. return this;
  406. },
  407. addVectors: function ( a, b ) {
  408. this.x = a.x + b.x;
  409. this.y = a.y + b.y;
  410. return this;
  411. },
  412. addScaledVector: function ( v, s ) {
  413. this.x += v.x * s;
  414. this.y += v.y * s;
  415. return this;
  416. },
  417. sub: function ( v, w ) {
  418. if ( w !== undefined ) {
  419. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  420. return this.subVectors( v, w );
  421. }
  422. this.x -= v.x;
  423. this.y -= v.y;
  424. return this;
  425. },
  426. subScalar: function ( s ) {
  427. this.x -= s;
  428. this.y -= s;
  429. return this;
  430. },
  431. subVectors: function ( a, b ) {
  432. this.x = a.x - b.x;
  433. this.y = a.y - b.y;
  434. return this;
  435. },
  436. multiply: function ( v ) {
  437. this.x *= v.x;
  438. this.y *= v.y;
  439. return this;
  440. },
  441. multiplyScalar: function ( scalar ) {
  442. this.x *= scalar;
  443. this.y *= scalar;
  444. return this;
  445. },
  446. divide: function ( v ) {
  447. this.x /= v.x;
  448. this.y /= v.y;
  449. return this;
  450. },
  451. divideScalar: function ( scalar ) {
  452. return this.multiplyScalar( 1 / scalar );
  453. },
  454. min: function ( v ) {
  455. this.x = Math.min( this.x, v.x );
  456. this.y = Math.min( this.y, v.y );
  457. return this;
  458. },
  459. max: function ( v ) {
  460. this.x = Math.max( this.x, v.x );
  461. this.y = Math.max( this.y, v.y );
  462. return this;
  463. },
  464. clamp: function ( min, max ) {
  465. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  466. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  467. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  468. return this;
  469. },
  470. clampScalar: function () {
  471. var min = new Vector2();
  472. var max = new Vector2();
  473. return function clampScalar( minVal, maxVal ) {
  474. min.set( minVal, minVal );
  475. max.set( maxVal, maxVal );
  476. return this.clamp( min, max );
  477. };
  478. }(),
  479. clampLength: function ( min, max ) {
  480. var length = this.length();
  481. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  482. },
  483. floor: function () {
  484. this.x = Math.floor( this.x );
  485. this.y = Math.floor( this.y );
  486. return this;
  487. },
  488. ceil: function () {
  489. this.x = Math.ceil( this.x );
  490. this.y = Math.ceil( this.y );
  491. return this;
  492. },
  493. round: function () {
  494. this.x = Math.round( this.x );
  495. this.y = Math.round( this.y );
  496. return this;
  497. },
  498. roundToZero: function () {
  499. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  500. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  501. return this;
  502. },
  503. negate: function () {
  504. this.x = - this.x;
  505. this.y = - this.y;
  506. return this;
  507. },
  508. dot: function ( v ) {
  509. return this.x * v.x + this.y * v.y;
  510. },
  511. lengthSq: function () {
  512. return this.x * this.x + this.y * this.y;
  513. },
  514. length: function () {
  515. return Math.sqrt( this.x * this.x + this.y * this.y );
  516. },
  517. lengthManhattan: function() {
  518. return Math.abs( this.x ) + Math.abs( this.y );
  519. },
  520. normalize: function () {
  521. return this.divideScalar( this.length() );
  522. },
  523. angle: function () {
  524. // computes the angle in radians with respect to the positive x-axis
  525. var angle = Math.atan2( this.y, this.x );
  526. if ( angle < 0 ) angle += 2 * Math.PI;
  527. return angle;
  528. },
  529. distanceTo: function ( v ) {
  530. return Math.sqrt( this.distanceToSquared( v ) );
  531. },
  532. distanceToSquared: function ( v ) {
  533. var dx = this.x - v.x, dy = this.y - v.y;
  534. return dx * dx + dy * dy;
  535. },
  536. distanceToManhattan: function ( v ) {
  537. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  538. },
  539. setLength: function ( length ) {
  540. return this.multiplyScalar( length / this.length() );
  541. },
  542. lerp: function ( v, alpha ) {
  543. this.x += ( v.x - this.x ) * alpha;
  544. this.y += ( v.y - this.y ) * alpha;
  545. return this;
  546. },
  547. lerpVectors: function ( v1, v2, alpha ) {
  548. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  549. },
  550. equals: function ( v ) {
  551. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  552. },
  553. fromArray: function ( array, offset ) {
  554. if ( offset === undefined ) offset = 0;
  555. this.x = array[ offset ];
  556. this.y = array[ offset + 1 ];
  557. return this;
  558. },
  559. toArray: function ( array, offset ) {
  560. if ( array === undefined ) array = [];
  561. if ( offset === undefined ) offset = 0;
  562. array[ offset ] = this.x;
  563. array[ offset + 1 ] = this.y;
  564. return array;
  565. },
  566. fromBufferAttribute: function ( attribute, index, offset ) {
  567. if ( offset !== undefined ) {
  568. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  569. }
  570. this.x = attribute.getX( index );
  571. this.y = attribute.getY( index );
  572. return this;
  573. },
  574. rotateAround: function ( center, angle ) {
  575. var c = Math.cos( angle ), s = Math.sin( angle );
  576. var x = this.x - center.x;
  577. var y = this.y - center.y;
  578. this.x = x * c - y * s + center.x;
  579. this.y = x * s + y * c + center.y;
  580. return this;
  581. }
  582. } );
  583. /**
  584. * @author mrdoob / http://mrdoob.com/
  585. * @author alteredq / http://alteredqualia.com/
  586. * @author szimek / https://github.com/szimek/
  587. */
  588. var textureId = 0;
  589. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  590. Object.defineProperty( this, 'id', { value: textureId ++ } );
  591. this.uuid = _Math.generateUUID();
  592. this.name = '';
  593. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  594. this.mipmaps = [];
  595. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  596. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  597. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  598. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  599. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  600. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  601. this.format = format !== undefined ? format : RGBAFormat;
  602. this.type = type !== undefined ? type : UnsignedByteType;
  603. this.offset = new Vector2( 0, 0 );
  604. this.repeat = new Vector2( 1, 1 );
  605. this.generateMipmaps = true;
  606. this.premultiplyAlpha = false;
  607. this.flipY = true;
  608. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  609. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  610. //
  611. // Also changing the encoding after already used by a Material will not automatically make the Material
  612. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  613. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  614. this.version = 0;
  615. this.onUpdate = null;
  616. }
  617. Texture.DEFAULT_IMAGE = undefined;
  618. Texture.DEFAULT_MAPPING = UVMapping;
  619. Object.defineProperty( Texture.prototype, "needsUpdate", {
  620. set: function ( value ) {
  621. if ( value === true ) this.version ++;
  622. }
  623. } );
  624. Object.assign( Texture.prototype, EventDispatcher.prototype, {
  625. constructor: Texture,
  626. isTexture: true,
  627. clone: function () {
  628. return new this.constructor().copy( this );
  629. },
  630. copy: function ( source ) {
  631. this.name = source.name;
  632. this.image = source.image;
  633. this.mipmaps = source.mipmaps.slice( 0 );
  634. this.mapping = source.mapping;
  635. this.wrapS = source.wrapS;
  636. this.wrapT = source.wrapT;
  637. this.magFilter = source.magFilter;
  638. this.minFilter = source.minFilter;
  639. this.anisotropy = source.anisotropy;
  640. this.format = source.format;
  641. this.type = source.type;
  642. this.offset.copy( source.offset );
  643. this.repeat.copy( source.repeat );
  644. this.generateMipmaps = source.generateMipmaps;
  645. this.premultiplyAlpha = source.premultiplyAlpha;
  646. this.flipY = source.flipY;
  647. this.unpackAlignment = source.unpackAlignment;
  648. this.encoding = source.encoding;
  649. return this;
  650. },
  651. toJSON: function ( meta ) {
  652. if ( meta.textures[ this.uuid ] !== undefined ) {
  653. return meta.textures[ this.uuid ];
  654. }
  655. function getDataURL( image ) {
  656. var canvas;
  657. if ( image.toDataURL !== undefined ) {
  658. canvas = image;
  659. } else {
  660. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  661. canvas.width = image.width;
  662. canvas.height = image.height;
  663. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  664. }
  665. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  666. return canvas.toDataURL( 'image/jpeg', 0.6 );
  667. } else {
  668. return canvas.toDataURL( 'image/png' );
  669. }
  670. }
  671. var output = {
  672. metadata: {
  673. version: 4.5,
  674. type: 'Texture',
  675. generator: 'Texture.toJSON'
  676. },
  677. uuid: this.uuid,
  678. name: this.name,
  679. mapping: this.mapping,
  680. repeat: [ this.repeat.x, this.repeat.y ],
  681. offset: [ this.offset.x, this.offset.y ],
  682. wrap: [ this.wrapS, this.wrapT ],
  683. minFilter: this.minFilter,
  684. magFilter: this.magFilter,
  685. anisotropy: this.anisotropy,
  686. flipY: this.flipY
  687. };
  688. if ( this.image !== undefined ) {
  689. // TODO: Move to THREE.Image
  690. var image = this.image;
  691. if ( image.uuid === undefined ) {
  692. image.uuid = _Math.generateUUID(); // UGH
  693. }
  694. if ( meta.images[ image.uuid ] === undefined ) {
  695. meta.images[ image.uuid ] = {
  696. uuid: image.uuid,
  697. url: getDataURL( image )
  698. };
  699. }
  700. output.image = image.uuid;
  701. }
  702. meta.textures[ this.uuid ] = output;
  703. return output;
  704. },
  705. dispose: function () {
  706. this.dispatchEvent( { type: 'dispose' } );
  707. },
  708. transformUv: function ( uv ) {
  709. if ( this.mapping !== UVMapping ) return;
  710. uv.multiply( this.repeat );
  711. uv.add( this.offset );
  712. if ( uv.x < 0 || uv.x > 1 ) {
  713. switch ( this.wrapS ) {
  714. case RepeatWrapping:
  715. uv.x = uv.x - Math.floor( uv.x );
  716. break;
  717. case ClampToEdgeWrapping:
  718. uv.x = uv.x < 0 ? 0 : 1;
  719. break;
  720. case MirroredRepeatWrapping:
  721. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  722. uv.x = Math.ceil( uv.x ) - uv.x;
  723. } else {
  724. uv.x = uv.x - Math.floor( uv.x );
  725. }
  726. break;
  727. }
  728. }
  729. if ( uv.y < 0 || uv.y > 1 ) {
  730. switch ( this.wrapT ) {
  731. case RepeatWrapping:
  732. uv.y = uv.y - Math.floor( uv.y );
  733. break;
  734. case ClampToEdgeWrapping:
  735. uv.y = uv.y < 0 ? 0 : 1;
  736. break;
  737. case MirroredRepeatWrapping:
  738. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  739. uv.y = Math.ceil( uv.y ) - uv.y;
  740. } else {
  741. uv.y = uv.y - Math.floor( uv.y );
  742. }
  743. break;
  744. }
  745. }
  746. if ( this.flipY ) {
  747. uv.y = 1 - uv.y;
  748. }
  749. }
  750. } );
  751. /**
  752. * @author supereggbert / http://www.paulbrunt.co.uk/
  753. * @author philogb / http://blog.thejit.org/
  754. * @author mikael emtinger / http://gomo.se/
  755. * @author egraether / http://egraether.com/
  756. * @author WestLangley / http://github.com/WestLangley
  757. */
  758. function Vector4( x, y, z, w ) {
  759. this.x = x || 0;
  760. this.y = y || 0;
  761. this.z = z || 0;
  762. this.w = ( w !== undefined ) ? w : 1;
  763. }
  764. Object.assign( Vector4.prototype, {
  765. isVector4: true,
  766. set: function ( x, y, z, w ) {
  767. this.x = x;
  768. this.y = y;
  769. this.z = z;
  770. this.w = w;
  771. return this;
  772. },
  773. setScalar: function ( scalar ) {
  774. this.x = scalar;
  775. this.y = scalar;
  776. this.z = scalar;
  777. this.w = scalar;
  778. return this;
  779. },
  780. setX: function ( x ) {
  781. this.x = x;
  782. return this;
  783. },
  784. setY: function ( y ) {
  785. this.y = y;
  786. return this;
  787. },
  788. setZ: function ( z ) {
  789. this.z = z;
  790. return this;
  791. },
  792. setW: function ( w ) {
  793. this.w = w;
  794. return this;
  795. },
  796. setComponent: function ( index, value ) {
  797. switch ( index ) {
  798. case 0: this.x = value; break;
  799. case 1: this.y = value; break;
  800. case 2: this.z = value; break;
  801. case 3: this.w = value; break;
  802. default: throw new Error( 'index is out of range: ' + index );
  803. }
  804. return this;
  805. },
  806. getComponent: function ( index ) {
  807. switch ( index ) {
  808. case 0: return this.x;
  809. case 1: return this.y;
  810. case 2: return this.z;
  811. case 3: return this.w;
  812. default: throw new Error( 'index is out of range: ' + index );
  813. }
  814. },
  815. clone: function () {
  816. return new this.constructor( this.x, this.y, this.z, this.w );
  817. },
  818. copy: function ( v ) {
  819. this.x = v.x;
  820. this.y = v.y;
  821. this.z = v.z;
  822. this.w = ( v.w !== undefined ) ? v.w : 1;
  823. return this;
  824. },
  825. add: function ( v, w ) {
  826. if ( w !== undefined ) {
  827. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  828. return this.addVectors( v, w );
  829. }
  830. this.x += v.x;
  831. this.y += v.y;
  832. this.z += v.z;
  833. this.w += v.w;
  834. return this;
  835. },
  836. addScalar: function ( s ) {
  837. this.x += s;
  838. this.y += s;
  839. this.z += s;
  840. this.w += s;
  841. return this;
  842. },
  843. addVectors: function ( a, b ) {
  844. this.x = a.x + b.x;
  845. this.y = a.y + b.y;
  846. this.z = a.z + b.z;
  847. this.w = a.w + b.w;
  848. return this;
  849. },
  850. addScaledVector: function ( v, s ) {
  851. this.x += v.x * s;
  852. this.y += v.y * s;
  853. this.z += v.z * s;
  854. this.w += v.w * s;
  855. return this;
  856. },
  857. sub: function ( v, w ) {
  858. if ( w !== undefined ) {
  859. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  860. return this.subVectors( v, w );
  861. }
  862. this.x -= v.x;
  863. this.y -= v.y;
  864. this.z -= v.z;
  865. this.w -= v.w;
  866. return this;
  867. },
  868. subScalar: function ( s ) {
  869. this.x -= s;
  870. this.y -= s;
  871. this.z -= s;
  872. this.w -= s;
  873. return this;
  874. },
  875. subVectors: function ( a, b ) {
  876. this.x = a.x - b.x;
  877. this.y = a.y - b.y;
  878. this.z = a.z - b.z;
  879. this.w = a.w - b.w;
  880. return this;
  881. },
  882. multiplyScalar: function ( scalar ) {
  883. this.x *= scalar;
  884. this.y *= scalar;
  885. this.z *= scalar;
  886. this.w *= scalar;
  887. return this;
  888. },
  889. applyMatrix4: function ( m ) {
  890. var x = this.x, y = this.y, z = this.z, w = this.w;
  891. var e = m.elements;
  892. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  893. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  894. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  895. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  896. return this;
  897. },
  898. divideScalar: function ( scalar ) {
  899. return this.multiplyScalar( 1 / scalar );
  900. },
  901. setAxisAngleFromQuaternion: function ( q ) {
  902. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  903. // q is assumed to be normalized
  904. this.w = 2 * Math.acos( q.w );
  905. var s = Math.sqrt( 1 - q.w * q.w );
  906. if ( s < 0.0001 ) {
  907. this.x = 1;
  908. this.y = 0;
  909. this.z = 0;
  910. } else {
  911. this.x = q.x / s;
  912. this.y = q.y / s;
  913. this.z = q.z / s;
  914. }
  915. return this;
  916. },
  917. setAxisAngleFromRotationMatrix: function ( m ) {
  918. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  919. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  920. var angle, x, y, z, // variables for result
  921. epsilon = 0.01, // margin to allow for rounding errors
  922. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  923. te = m.elements,
  924. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  925. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  926. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  927. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  928. ( Math.abs( m13 - m31 ) < epsilon ) &&
  929. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  930. // singularity found
  931. // first check for identity matrix which must have +1 for all terms
  932. // in leading diagonal and zero in other terms
  933. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  934. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  935. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  936. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  937. // this singularity is identity matrix so angle = 0
  938. this.set( 1, 0, 0, 0 );
  939. return this; // zero angle, arbitrary axis
  940. }
  941. // otherwise this singularity is angle = 180
  942. angle = Math.PI;
  943. var xx = ( m11 + 1 ) / 2;
  944. var yy = ( m22 + 1 ) / 2;
  945. var zz = ( m33 + 1 ) / 2;
  946. var xy = ( m12 + m21 ) / 4;
  947. var xz = ( m13 + m31 ) / 4;
  948. var yz = ( m23 + m32 ) / 4;
  949. if ( ( xx > yy ) && ( xx > zz ) ) {
  950. // m11 is the largest diagonal term
  951. if ( xx < epsilon ) {
  952. x = 0;
  953. y = 0.707106781;
  954. z = 0.707106781;
  955. } else {
  956. x = Math.sqrt( xx );
  957. y = xy / x;
  958. z = xz / x;
  959. }
  960. } else if ( yy > zz ) {
  961. // m22 is the largest diagonal term
  962. if ( yy < epsilon ) {
  963. x = 0.707106781;
  964. y = 0;
  965. z = 0.707106781;
  966. } else {
  967. y = Math.sqrt( yy );
  968. x = xy / y;
  969. z = yz / y;
  970. }
  971. } else {
  972. // m33 is the largest diagonal term so base result on this
  973. if ( zz < epsilon ) {
  974. x = 0.707106781;
  975. y = 0.707106781;
  976. z = 0;
  977. } else {
  978. z = Math.sqrt( zz );
  979. x = xz / z;
  980. y = yz / z;
  981. }
  982. }
  983. this.set( x, y, z, angle );
  984. return this; // return 180 deg rotation
  985. }
  986. // as we have reached here there are no singularities so we can handle normally
  987. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  988. ( m13 - m31 ) * ( m13 - m31 ) +
  989. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  990. if ( Math.abs( s ) < 0.001 ) s = 1;
  991. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  992. // caught by singularity test above, but I've left it in just in case
  993. this.x = ( m32 - m23 ) / s;
  994. this.y = ( m13 - m31 ) / s;
  995. this.z = ( m21 - m12 ) / s;
  996. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  997. return this;
  998. },
  999. min: function ( v ) {
  1000. this.x = Math.min( this.x, v.x );
  1001. this.y = Math.min( this.y, v.y );
  1002. this.z = Math.min( this.z, v.z );
  1003. this.w = Math.min( this.w, v.w );
  1004. return this;
  1005. },
  1006. max: function ( v ) {
  1007. this.x = Math.max( this.x, v.x );
  1008. this.y = Math.max( this.y, v.y );
  1009. this.z = Math.max( this.z, v.z );
  1010. this.w = Math.max( this.w, v.w );
  1011. return this;
  1012. },
  1013. clamp: function ( min, max ) {
  1014. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1015. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1016. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1017. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1018. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1019. return this;
  1020. },
  1021. clampScalar: function () {
  1022. var min = new Vector4();
  1023. var max = new Vector4();
  1024. return function clampScalar( minVal, maxVal ) {
  1025. min.set( minVal, minVal, minVal, minVal );
  1026. max.set( maxVal, maxVal, maxVal, maxVal );
  1027. return this.clamp( min, max );
  1028. };
  1029. }(),
  1030. floor: function () {
  1031. this.x = Math.floor( this.x );
  1032. this.y = Math.floor( this.y );
  1033. this.z = Math.floor( this.z );
  1034. this.w = Math.floor( this.w );
  1035. return this;
  1036. },
  1037. ceil: function () {
  1038. this.x = Math.ceil( this.x );
  1039. this.y = Math.ceil( this.y );
  1040. this.z = Math.ceil( this.z );
  1041. this.w = Math.ceil( this.w );
  1042. return this;
  1043. },
  1044. round: function () {
  1045. this.x = Math.round( this.x );
  1046. this.y = Math.round( this.y );
  1047. this.z = Math.round( this.z );
  1048. this.w = Math.round( this.w );
  1049. return this;
  1050. },
  1051. roundToZero: function () {
  1052. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1053. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1054. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1055. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1056. return this;
  1057. },
  1058. negate: function () {
  1059. this.x = - this.x;
  1060. this.y = - this.y;
  1061. this.z = - this.z;
  1062. this.w = - this.w;
  1063. return this;
  1064. },
  1065. dot: function ( v ) {
  1066. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1067. },
  1068. lengthSq: function () {
  1069. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1070. },
  1071. length: function () {
  1072. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1073. },
  1074. lengthManhattan: function () {
  1075. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1076. },
  1077. normalize: function () {
  1078. return this.divideScalar( this.length() );
  1079. },
  1080. setLength: function ( length ) {
  1081. return this.multiplyScalar( length / this.length() );
  1082. },
  1083. lerp: function ( v, alpha ) {
  1084. this.x += ( v.x - this.x ) * alpha;
  1085. this.y += ( v.y - this.y ) * alpha;
  1086. this.z += ( v.z - this.z ) * alpha;
  1087. this.w += ( v.w - this.w ) * alpha;
  1088. return this;
  1089. },
  1090. lerpVectors: function ( v1, v2, alpha ) {
  1091. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1092. },
  1093. equals: function ( v ) {
  1094. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1095. },
  1096. fromArray: function ( array, offset ) {
  1097. if ( offset === undefined ) offset = 0;
  1098. this.x = array[ offset ];
  1099. this.y = array[ offset + 1 ];
  1100. this.z = array[ offset + 2 ];
  1101. this.w = array[ offset + 3 ];
  1102. return this;
  1103. },
  1104. toArray: function ( array, offset ) {
  1105. if ( array === undefined ) array = [];
  1106. if ( offset === undefined ) offset = 0;
  1107. array[ offset ] = this.x;
  1108. array[ offset + 1 ] = this.y;
  1109. array[ offset + 2 ] = this.z;
  1110. array[ offset + 3 ] = this.w;
  1111. return array;
  1112. },
  1113. fromBufferAttribute: function ( attribute, index, offset ) {
  1114. if ( offset !== undefined ) {
  1115. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1116. }
  1117. this.x = attribute.getX( index );
  1118. this.y = attribute.getY( index );
  1119. this.z = attribute.getZ( index );
  1120. this.w = attribute.getW( index );
  1121. return this;
  1122. }
  1123. } );
  1124. /**
  1125. * @author szimek / https://github.com/szimek/
  1126. * @author alteredq / http://alteredqualia.com/
  1127. * @author Marius Kintel / https://github.com/kintel
  1128. */
  1129. /*
  1130. In options, we can specify:
  1131. * Texture parameters for an auto-generated target texture
  1132. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1133. */
  1134. function WebGLRenderTarget( width, height, options ) {
  1135. this.uuid = _Math.generateUUID();
  1136. this.width = width;
  1137. this.height = height;
  1138. this.scissor = new Vector4( 0, 0, width, height );
  1139. this.scissorTest = false;
  1140. this.viewport = new Vector4( 0, 0, width, height );
  1141. options = options || {};
  1142. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  1143. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1144. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1145. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  1146. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1147. }
  1148. Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, {
  1149. isWebGLRenderTarget: true,
  1150. setSize: function ( width, height ) {
  1151. if ( this.width !== width || this.height !== height ) {
  1152. this.width = width;
  1153. this.height = height;
  1154. this.dispose();
  1155. }
  1156. this.viewport.set( 0, 0, width, height );
  1157. this.scissor.set( 0, 0, width, height );
  1158. },
  1159. clone: function () {
  1160. return new this.constructor().copy( this );
  1161. },
  1162. copy: function ( source ) {
  1163. this.width = source.width;
  1164. this.height = source.height;
  1165. this.viewport.copy( source.viewport );
  1166. this.texture = source.texture.clone();
  1167. this.depthBuffer = source.depthBuffer;
  1168. this.stencilBuffer = source.stencilBuffer;
  1169. this.depthTexture = source.depthTexture;
  1170. return this;
  1171. },
  1172. dispose: function () {
  1173. this.dispatchEvent( { type: 'dispose' } );
  1174. }
  1175. } );
  1176. /**
  1177. * @author alteredq / http://alteredqualia.com
  1178. */
  1179. function WebGLRenderTargetCube( width, height, options ) {
  1180. WebGLRenderTarget.call( this, width, height, options );
  1181. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  1182. this.activeMipMapLevel = 0;
  1183. }
  1184. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  1185. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  1186. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  1187. /**
  1188. * @author mikael emtinger / http://gomo.se/
  1189. * @author alteredq / http://alteredqualia.com/
  1190. * @author WestLangley / http://github.com/WestLangley
  1191. * @author bhouston / http://clara.io
  1192. */
  1193. function Quaternion( x, y, z, w ) {
  1194. this._x = x || 0;
  1195. this._y = y || 0;
  1196. this._z = z || 0;
  1197. this._w = ( w !== undefined ) ? w : 1;
  1198. }
  1199. Object.assign( Quaternion, {
  1200. slerp: function ( qa, qb, qm, t ) {
  1201. return qm.copy( qa ).slerp( qb, t );
  1202. },
  1203. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1204. // fuzz-free, array-based Quaternion SLERP operation
  1205. var x0 = src0[ srcOffset0 + 0 ],
  1206. y0 = src0[ srcOffset0 + 1 ],
  1207. z0 = src0[ srcOffset0 + 2 ],
  1208. w0 = src0[ srcOffset0 + 3 ],
  1209. x1 = src1[ srcOffset1 + 0 ],
  1210. y1 = src1[ srcOffset1 + 1 ],
  1211. z1 = src1[ srcOffset1 + 2 ],
  1212. w1 = src1[ srcOffset1 + 3 ];
  1213. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1214. var s = 1 - t,
  1215. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1216. dir = ( cos >= 0 ? 1 : - 1 ),
  1217. sqrSin = 1 - cos * cos;
  1218. // Skip the Slerp for tiny steps to avoid numeric problems:
  1219. if ( sqrSin > Number.EPSILON ) {
  1220. var sin = Math.sqrt( sqrSin ),
  1221. len = Math.atan2( sin, cos * dir );
  1222. s = Math.sin( s * len ) / sin;
  1223. t = Math.sin( t * len ) / sin;
  1224. }
  1225. var tDir = t * dir;
  1226. x0 = x0 * s + x1 * tDir;
  1227. y0 = y0 * s + y1 * tDir;
  1228. z0 = z0 * s + z1 * tDir;
  1229. w0 = w0 * s + w1 * tDir;
  1230. // Normalize in case we just did a lerp:
  1231. if ( s === 1 - t ) {
  1232. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1233. x0 *= f;
  1234. y0 *= f;
  1235. z0 *= f;
  1236. w0 *= f;
  1237. }
  1238. }
  1239. dst[ dstOffset ] = x0;
  1240. dst[ dstOffset + 1 ] = y0;
  1241. dst[ dstOffset + 2 ] = z0;
  1242. dst[ dstOffset + 3 ] = w0;
  1243. }
  1244. } );
  1245. Object.defineProperties( Quaternion.prototype, {
  1246. x: {
  1247. get: function () {
  1248. return this._x;
  1249. },
  1250. set: function ( value ) {
  1251. this._x = value;
  1252. this.onChangeCallback();
  1253. }
  1254. },
  1255. y: {
  1256. get: function () {
  1257. return this._y;
  1258. },
  1259. set: function ( value ) {
  1260. this._y = value;
  1261. this.onChangeCallback();
  1262. }
  1263. },
  1264. z: {
  1265. get: function () {
  1266. return this._z;
  1267. },
  1268. set: function ( value ) {
  1269. this._z = value;
  1270. this.onChangeCallback();
  1271. }
  1272. },
  1273. w: {
  1274. get: function () {
  1275. return this._w;
  1276. },
  1277. set: function ( value ) {
  1278. this._w = value;
  1279. this.onChangeCallback();
  1280. }
  1281. }
  1282. } );
  1283. Object.assign( Quaternion.prototype, {
  1284. set: function ( x, y, z, w ) {
  1285. this._x = x;
  1286. this._y = y;
  1287. this._z = z;
  1288. this._w = w;
  1289. this.onChangeCallback();
  1290. return this;
  1291. },
  1292. clone: function () {
  1293. return new this.constructor( this._x, this._y, this._z, this._w );
  1294. },
  1295. copy: function ( quaternion ) {
  1296. this._x = quaternion.x;
  1297. this._y = quaternion.y;
  1298. this._z = quaternion.z;
  1299. this._w = quaternion.w;
  1300. this.onChangeCallback();
  1301. return this;
  1302. },
  1303. setFromEuler: function ( euler, update ) {
  1304. if ( ( euler && euler.isEuler ) === false ) {
  1305. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1306. }
  1307. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1308. // http://www.mathworks.com/matlabcentral/fileexchange/
  1309. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1310. // content/SpinCalc.m
  1311. var cos = Math.cos;
  1312. var sin = Math.sin;
  1313. var c1 = cos( x / 2 );
  1314. var c2 = cos( y / 2 );
  1315. var c3 = cos( z / 2 );
  1316. var s1 = sin( x / 2 );
  1317. var s2 = sin( y / 2 );
  1318. var s3 = sin( z / 2 );
  1319. if ( order === 'XYZ' ) {
  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 === 'YXZ' ) {
  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 === 'ZXY' ) {
  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 === 'ZYX' ) {
  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 === 'YZX' ) {
  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. } else if ( order === 'XZY' ) {
  1345. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1346. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1347. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1348. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1349. }
  1350. if ( update !== false ) this.onChangeCallback();
  1351. return this;
  1352. },
  1353. setFromAxisAngle: function ( axis, angle ) {
  1354. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1355. // assumes axis is normalized
  1356. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1357. this._x = axis.x * s;
  1358. this._y = axis.y * s;
  1359. this._z = axis.z * s;
  1360. this._w = Math.cos( halfAngle );
  1361. this.onChangeCallback();
  1362. return this;
  1363. },
  1364. setFromRotationMatrix: function ( m ) {
  1365. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1366. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1367. var te = m.elements,
  1368. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1369. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1370. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1371. trace = m11 + m22 + m33,
  1372. s;
  1373. if ( trace > 0 ) {
  1374. s = 0.5 / Math.sqrt( trace + 1.0 );
  1375. this._w = 0.25 / s;
  1376. this._x = ( m32 - m23 ) * s;
  1377. this._y = ( m13 - m31 ) * s;
  1378. this._z = ( m21 - m12 ) * s;
  1379. } else if ( m11 > m22 && m11 > m33 ) {
  1380. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1381. this._w = ( m32 - m23 ) / s;
  1382. this._x = 0.25 * s;
  1383. this._y = ( m12 + m21 ) / s;
  1384. this._z = ( m13 + m31 ) / s;
  1385. } else if ( m22 > m33 ) {
  1386. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1387. this._w = ( m13 - m31 ) / s;
  1388. this._x = ( m12 + m21 ) / s;
  1389. this._y = 0.25 * s;
  1390. this._z = ( m23 + m32 ) / s;
  1391. } else {
  1392. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1393. this._w = ( m21 - m12 ) / s;
  1394. this._x = ( m13 + m31 ) / s;
  1395. this._y = ( m23 + m32 ) / s;
  1396. this._z = 0.25 * s;
  1397. }
  1398. this.onChangeCallback();
  1399. return this;
  1400. },
  1401. setFromUnitVectors: function () {
  1402. // assumes direction vectors vFrom and vTo are normalized
  1403. var v1 = new Vector3();
  1404. var r;
  1405. var EPS = 0.000001;
  1406. return function setFromUnitVectors( vFrom, vTo ) {
  1407. if ( v1 === undefined ) v1 = new Vector3();
  1408. r = vFrom.dot( vTo ) + 1;
  1409. if ( r < EPS ) {
  1410. r = 0;
  1411. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1412. v1.set( - vFrom.y, vFrom.x, 0 );
  1413. } else {
  1414. v1.set( 0, - vFrom.z, vFrom.y );
  1415. }
  1416. } else {
  1417. v1.crossVectors( vFrom, vTo );
  1418. }
  1419. this._x = v1.x;
  1420. this._y = v1.y;
  1421. this._z = v1.z;
  1422. this._w = r;
  1423. return this.normalize();
  1424. };
  1425. }(),
  1426. inverse: function () {
  1427. return this.conjugate().normalize();
  1428. },
  1429. conjugate: function () {
  1430. this._x *= - 1;
  1431. this._y *= - 1;
  1432. this._z *= - 1;
  1433. this.onChangeCallback();
  1434. return this;
  1435. },
  1436. dot: function ( v ) {
  1437. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1438. },
  1439. lengthSq: function () {
  1440. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1441. },
  1442. length: function () {
  1443. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1444. },
  1445. normalize: function () {
  1446. var l = this.length();
  1447. if ( l === 0 ) {
  1448. this._x = 0;
  1449. this._y = 0;
  1450. this._z = 0;
  1451. this._w = 1;
  1452. } else {
  1453. l = 1 / l;
  1454. this._x = this._x * l;
  1455. this._y = this._y * l;
  1456. this._z = this._z * l;
  1457. this._w = this._w * l;
  1458. }
  1459. this.onChangeCallback();
  1460. return this;
  1461. },
  1462. multiply: function ( q, p ) {
  1463. if ( p !== undefined ) {
  1464. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1465. return this.multiplyQuaternions( q, p );
  1466. }
  1467. return this.multiplyQuaternions( this, q );
  1468. },
  1469. premultiply: function ( q ) {
  1470. return this.multiplyQuaternions( q, this );
  1471. },
  1472. multiplyQuaternions: function ( a, b ) {
  1473. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1474. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1475. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1476. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1477. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1478. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1479. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1480. this.onChangeCallback();
  1481. return this;
  1482. },
  1483. slerp: function ( qb, t ) {
  1484. if ( t === 0 ) return this;
  1485. if ( t === 1 ) return this.copy( qb );
  1486. var x = this._x, y = this._y, z = this._z, w = this._w;
  1487. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1488. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1489. if ( cosHalfTheta < 0 ) {
  1490. this._w = - qb._w;
  1491. this._x = - qb._x;
  1492. this._y = - qb._y;
  1493. this._z = - qb._z;
  1494. cosHalfTheta = - cosHalfTheta;
  1495. } else {
  1496. this.copy( qb );
  1497. }
  1498. if ( cosHalfTheta >= 1.0 ) {
  1499. this._w = w;
  1500. this._x = x;
  1501. this._y = y;
  1502. this._z = z;
  1503. return this;
  1504. }
  1505. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1506. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1507. this._w = 0.5 * ( w + this._w );
  1508. this._x = 0.5 * ( x + this._x );
  1509. this._y = 0.5 * ( y + this._y );
  1510. this._z = 0.5 * ( z + this._z );
  1511. return this;
  1512. }
  1513. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1514. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1515. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1516. this._w = ( w * ratioA + this._w * ratioB );
  1517. this._x = ( x * ratioA + this._x * ratioB );
  1518. this._y = ( y * ratioA + this._y * ratioB );
  1519. this._z = ( z * ratioA + this._z * ratioB );
  1520. this.onChangeCallback();
  1521. return this;
  1522. },
  1523. equals: function ( quaternion ) {
  1524. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1525. },
  1526. fromArray: function ( array, offset ) {
  1527. if ( offset === undefined ) offset = 0;
  1528. this._x = array[ offset ];
  1529. this._y = array[ offset + 1 ];
  1530. this._z = array[ offset + 2 ];
  1531. this._w = array[ offset + 3 ];
  1532. this.onChangeCallback();
  1533. return this;
  1534. },
  1535. toArray: function ( array, offset ) {
  1536. if ( array === undefined ) array = [];
  1537. if ( offset === undefined ) offset = 0;
  1538. array[ offset ] = this._x;
  1539. array[ offset + 1 ] = this._y;
  1540. array[ offset + 2 ] = this._z;
  1541. array[ offset + 3 ] = this._w;
  1542. return array;
  1543. },
  1544. onChange: function ( callback ) {
  1545. this.onChangeCallback = callback;
  1546. return this;
  1547. },
  1548. onChangeCallback: function () {}
  1549. } );
  1550. /**
  1551. * @author mrdoob / http://mrdoob.com/
  1552. * @author *kile / http://kile.stravaganza.org/
  1553. * @author philogb / http://blog.thejit.org/
  1554. * @author mikael emtinger / http://gomo.se/
  1555. * @author egraether / http://egraether.com/
  1556. * @author WestLangley / http://github.com/WestLangley
  1557. */
  1558. function Vector3( x, y, z ) {
  1559. this.x = x || 0;
  1560. this.y = y || 0;
  1561. this.z = z || 0;
  1562. }
  1563. Object.assign( Vector3.prototype, {
  1564. isVector3: true,
  1565. set: function ( x, y, z ) {
  1566. this.x = x;
  1567. this.y = y;
  1568. this.z = z;
  1569. return this;
  1570. },
  1571. setScalar: function ( scalar ) {
  1572. this.x = scalar;
  1573. this.y = scalar;
  1574. this.z = scalar;
  1575. return this;
  1576. },
  1577. setX: function ( x ) {
  1578. this.x = x;
  1579. return this;
  1580. },
  1581. setY: function ( y ) {
  1582. this.y = y;
  1583. return this;
  1584. },
  1585. setZ: function ( z ) {
  1586. this.z = z;
  1587. return this;
  1588. },
  1589. setComponent: function ( index, value ) {
  1590. switch ( index ) {
  1591. case 0: this.x = value; break;
  1592. case 1: this.y = value; break;
  1593. case 2: this.z = value; break;
  1594. default: throw new Error( 'index is out of range: ' + index );
  1595. }
  1596. return this;
  1597. },
  1598. getComponent: function ( index ) {
  1599. switch ( index ) {
  1600. case 0: return this.x;
  1601. case 1: return this.y;
  1602. case 2: return this.z;
  1603. default: throw new Error( 'index is out of range: ' + index );
  1604. }
  1605. },
  1606. clone: function () {
  1607. return new this.constructor( this.x, this.y, this.z );
  1608. },
  1609. copy: function ( v ) {
  1610. this.x = v.x;
  1611. this.y = v.y;
  1612. this.z = v.z;
  1613. return this;
  1614. },
  1615. add: function ( v, w ) {
  1616. if ( w !== undefined ) {
  1617. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1618. return this.addVectors( v, w );
  1619. }
  1620. this.x += v.x;
  1621. this.y += v.y;
  1622. this.z += v.z;
  1623. return this;
  1624. },
  1625. addScalar: function ( s ) {
  1626. this.x += s;
  1627. this.y += s;
  1628. this.z += s;
  1629. return this;
  1630. },
  1631. addVectors: function ( a, b ) {
  1632. this.x = a.x + b.x;
  1633. this.y = a.y + b.y;
  1634. this.z = a.z + b.z;
  1635. return this;
  1636. },
  1637. addScaledVector: function ( v, s ) {
  1638. this.x += v.x * s;
  1639. this.y += v.y * s;
  1640. this.z += v.z * s;
  1641. return this;
  1642. },
  1643. sub: function ( v, w ) {
  1644. if ( w !== undefined ) {
  1645. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1646. return this.subVectors( v, w );
  1647. }
  1648. this.x -= v.x;
  1649. this.y -= v.y;
  1650. this.z -= v.z;
  1651. return this;
  1652. },
  1653. subScalar: function ( s ) {
  1654. this.x -= s;
  1655. this.y -= s;
  1656. this.z -= s;
  1657. return this;
  1658. },
  1659. subVectors: function ( a, b ) {
  1660. this.x = a.x - b.x;
  1661. this.y = a.y - b.y;
  1662. this.z = a.z - b.z;
  1663. return this;
  1664. },
  1665. multiply: function ( v, w ) {
  1666. if ( w !== undefined ) {
  1667. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1668. return this.multiplyVectors( v, w );
  1669. }
  1670. this.x *= v.x;
  1671. this.y *= v.y;
  1672. this.z *= v.z;
  1673. return this;
  1674. },
  1675. multiplyScalar: function ( scalar ) {
  1676. this.x *= scalar;
  1677. this.y *= scalar;
  1678. this.z *= scalar;
  1679. return this;
  1680. },
  1681. multiplyVectors: function ( a, b ) {
  1682. this.x = a.x * b.x;
  1683. this.y = a.y * b.y;
  1684. this.z = a.z * b.z;
  1685. return this;
  1686. },
  1687. applyEuler: function () {
  1688. var quaternion = new Quaternion();
  1689. return function applyEuler( euler ) {
  1690. if ( ( euler && euler.isEuler ) === false ) {
  1691. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1692. }
  1693. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1694. };
  1695. }(),
  1696. applyAxisAngle: function () {
  1697. var quaternion = new Quaternion();
  1698. return function applyAxisAngle( axis, angle ) {
  1699. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1700. };
  1701. }(),
  1702. applyMatrix3: function ( m ) {
  1703. var x = this.x, y = this.y, z = this.z;
  1704. var e = m.elements;
  1705. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1706. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1707. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1708. return this;
  1709. },
  1710. applyMatrix4: function ( m ) {
  1711. var x = this.x, y = this.y, z = this.z;
  1712. var e = m.elements;
  1713. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1714. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1715. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1716. var w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ];
  1717. return this.divideScalar( w );
  1718. },
  1719. applyQuaternion: function ( q ) {
  1720. var x = this.x, y = this.y, z = this.z;
  1721. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1722. // calculate quat * vector
  1723. var ix = qw * x + qy * z - qz * y;
  1724. var iy = qw * y + qz * x - qx * z;
  1725. var iz = qw * z + qx * y - qy * x;
  1726. var iw = - qx * x - qy * y - qz * z;
  1727. // calculate result * inverse quat
  1728. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1729. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1730. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1731. return this;
  1732. },
  1733. project: function () {
  1734. var matrix = new Matrix4();
  1735. return function project( camera ) {
  1736. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1737. return this.applyMatrix4( matrix );
  1738. };
  1739. }(),
  1740. unproject: function () {
  1741. var matrix = new Matrix4();
  1742. return function unproject( camera ) {
  1743. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1744. return this.applyMatrix4( matrix );
  1745. };
  1746. }(),
  1747. transformDirection: function ( m ) {
  1748. // input: THREE.Matrix4 affine matrix
  1749. // vector interpreted as a direction
  1750. var x = this.x, y = this.y, z = this.z;
  1751. var e = m.elements;
  1752. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1753. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1754. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1755. return this.normalize();
  1756. },
  1757. divide: function ( v ) {
  1758. this.x /= v.x;
  1759. this.y /= v.y;
  1760. this.z /= v.z;
  1761. return this;
  1762. },
  1763. divideScalar: function ( scalar ) {
  1764. return this.multiplyScalar( 1 / scalar );
  1765. },
  1766. min: function ( v ) {
  1767. this.x = Math.min( this.x, v.x );
  1768. this.y = Math.min( this.y, v.y );
  1769. this.z = Math.min( this.z, v.z );
  1770. return this;
  1771. },
  1772. max: function ( v ) {
  1773. this.x = Math.max( this.x, v.x );
  1774. this.y = Math.max( this.y, v.y );
  1775. this.z = Math.max( this.z, v.z );
  1776. return this;
  1777. },
  1778. clamp: function ( min, max ) {
  1779. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1780. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1781. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1782. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1783. return this;
  1784. },
  1785. clampScalar: function () {
  1786. var min = new Vector3();
  1787. var max = new Vector3();
  1788. return function clampScalar( minVal, maxVal ) {
  1789. min.set( minVal, minVal, minVal );
  1790. max.set( maxVal, maxVal, maxVal );
  1791. return this.clamp( min, max );
  1792. };
  1793. }(),
  1794. clampLength: function ( min, max ) {
  1795. var length = this.length();
  1796. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1797. },
  1798. floor: function () {
  1799. this.x = Math.floor( this.x );
  1800. this.y = Math.floor( this.y );
  1801. this.z = Math.floor( this.z );
  1802. return this;
  1803. },
  1804. ceil: function () {
  1805. this.x = Math.ceil( this.x );
  1806. this.y = Math.ceil( this.y );
  1807. this.z = Math.ceil( this.z );
  1808. return this;
  1809. },
  1810. round: function () {
  1811. this.x = Math.round( this.x );
  1812. this.y = Math.round( this.y );
  1813. this.z = Math.round( this.z );
  1814. return this;
  1815. },
  1816. roundToZero: function () {
  1817. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1818. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1819. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1820. return this;
  1821. },
  1822. negate: function () {
  1823. this.x = - this.x;
  1824. this.y = - this.y;
  1825. this.z = - this.z;
  1826. return this;
  1827. },
  1828. dot: function ( v ) {
  1829. return this.x * v.x + this.y * v.y + this.z * v.z;
  1830. },
  1831. // TODO lengthSquared?
  1832. lengthSq: function () {
  1833. return this.x * this.x + this.y * this.y + this.z * this.z;
  1834. },
  1835. length: function () {
  1836. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1837. },
  1838. lengthManhattan: function () {
  1839. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1840. },
  1841. normalize: function () {
  1842. return this.divideScalar( this.length() );
  1843. },
  1844. setLength: function ( length ) {
  1845. return this.multiplyScalar( length / this.length() );
  1846. },
  1847. lerp: function ( v, alpha ) {
  1848. this.x += ( v.x - this.x ) * alpha;
  1849. this.y += ( v.y - this.y ) * alpha;
  1850. this.z += ( v.z - this.z ) * alpha;
  1851. return this;
  1852. },
  1853. lerpVectors: function ( v1, v2, alpha ) {
  1854. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1855. },
  1856. cross: function ( v, w ) {
  1857. if ( w !== undefined ) {
  1858. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1859. return this.crossVectors( v, w );
  1860. }
  1861. var x = this.x, y = this.y, z = this.z;
  1862. this.x = y * v.z - z * v.y;
  1863. this.y = z * v.x - x * v.z;
  1864. this.z = x * v.y - y * v.x;
  1865. return this;
  1866. },
  1867. crossVectors: function ( a, b ) {
  1868. var ax = a.x, ay = a.y, az = a.z;
  1869. var bx = b.x, by = b.y, bz = b.z;
  1870. this.x = ay * bz - az * by;
  1871. this.y = az * bx - ax * bz;
  1872. this.z = ax * by - ay * bx;
  1873. return this;
  1874. },
  1875. projectOnVector: function ( vector ) {
  1876. var scalar = vector.dot( this ) / vector.lengthSq();
  1877. return this.copy( vector ).multiplyScalar( scalar );
  1878. },
  1879. projectOnPlane: function () {
  1880. var v1 = new Vector3();
  1881. return function projectOnPlane( planeNormal ) {
  1882. v1.copy( this ).projectOnVector( planeNormal );
  1883. return this.sub( v1 );
  1884. };
  1885. }(),
  1886. reflect: function () {
  1887. // reflect incident vector off plane orthogonal to normal
  1888. // normal is assumed to have unit length
  1889. var v1 = new Vector3();
  1890. return function reflect( normal ) {
  1891. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1892. };
  1893. }(),
  1894. angleTo: function ( v ) {
  1895. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1896. // clamp, to handle numerical problems
  1897. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1898. },
  1899. distanceTo: function ( v ) {
  1900. return Math.sqrt( this.distanceToSquared( v ) );
  1901. },
  1902. distanceToSquared: function ( v ) {
  1903. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1904. return dx * dx + dy * dy + dz * dz;
  1905. },
  1906. distanceToManhattan: function ( v ) {
  1907. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1908. },
  1909. setFromSpherical: function ( s ) {
  1910. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1911. this.x = sinPhiRadius * Math.sin( s.theta );
  1912. this.y = Math.cos( s.phi ) * s.radius;
  1913. this.z = sinPhiRadius * Math.cos( s.theta );
  1914. return this;
  1915. },
  1916. setFromCylindrical: function ( c ) {
  1917. this.x = c.radius * Math.sin( c.theta );
  1918. this.y = c.y;
  1919. this.z = c.radius * Math.cos( c.theta );
  1920. return this;
  1921. },
  1922. setFromMatrixPosition: function ( m ) {
  1923. return this.setFromMatrixColumn( m, 3 );
  1924. },
  1925. setFromMatrixScale: function ( m ) {
  1926. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1927. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1928. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1929. this.x = sx;
  1930. this.y = sy;
  1931. this.z = sz;
  1932. return this;
  1933. },
  1934. setFromMatrixColumn: function ( m, index ) {
  1935. return this.fromArray( m.elements, index * 4 );
  1936. },
  1937. equals: function ( v ) {
  1938. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1939. },
  1940. fromArray: function ( array, offset ) {
  1941. if ( offset === undefined ) offset = 0;
  1942. this.x = array[ offset ];
  1943. this.y = array[ offset + 1 ];
  1944. this.z = array[ offset + 2 ];
  1945. return this;
  1946. },
  1947. toArray: function ( array, offset ) {
  1948. if ( array === undefined ) array = [];
  1949. if ( offset === undefined ) offset = 0;
  1950. array[ offset ] = this.x;
  1951. array[ offset + 1 ] = this.y;
  1952. array[ offset + 2 ] = this.z;
  1953. return array;
  1954. },
  1955. fromBufferAttribute: function ( attribute, index, offset ) {
  1956. if ( offset !== undefined ) {
  1957. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1958. }
  1959. this.x = attribute.getX( index );
  1960. this.y = attribute.getY( index );
  1961. this.z = attribute.getZ( index );
  1962. return this;
  1963. }
  1964. } );
  1965. /**
  1966. * @author mrdoob / http://mrdoob.com/
  1967. * @author supereggbert / http://www.paulbrunt.co.uk/
  1968. * @author philogb / http://blog.thejit.org/
  1969. * @author jordi_ros / http://plattsoft.com
  1970. * @author D1plo1d / http://github.com/D1plo1d
  1971. * @author alteredq / http://alteredqualia.com/
  1972. * @author mikael emtinger / http://gomo.se/
  1973. * @author timknip / http://www.floorplanner.com/
  1974. * @author bhouston / http://clara.io
  1975. * @author WestLangley / http://github.com/WestLangley
  1976. */
  1977. function Matrix4() {
  1978. this.elements = [
  1979. 1, 0, 0, 0,
  1980. 0, 1, 0, 0,
  1981. 0, 0, 1, 0,
  1982. 0, 0, 0, 1
  1983. ];
  1984. if ( arguments.length > 0 ) {
  1985. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  1986. }
  1987. }
  1988. Object.assign( Matrix4.prototype, {
  1989. isMatrix4: true,
  1990. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  1991. var te = this.elements;
  1992. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  1993. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  1994. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  1995. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  1996. return this;
  1997. },
  1998. identity: function () {
  1999. this.set(
  2000. 1, 0, 0, 0,
  2001. 0, 1, 0, 0,
  2002. 0, 0, 1, 0,
  2003. 0, 0, 0, 1
  2004. );
  2005. return this;
  2006. },
  2007. clone: function () {
  2008. return new Matrix4().fromArray( this.elements );
  2009. },
  2010. copy: function ( m ) {
  2011. var te = this.elements;
  2012. var me = m.elements;
  2013. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2014. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2015. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2016. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2017. return this;
  2018. },
  2019. copyPosition: function ( m ) {
  2020. var te = this.elements, me = m.elements;
  2021. te[ 12 ] = me[ 12 ];
  2022. te[ 13 ] = me[ 13 ];
  2023. te[ 14 ] = me[ 14 ];
  2024. return this;
  2025. },
  2026. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2027. xAxis.setFromMatrixColumn( this, 0 );
  2028. yAxis.setFromMatrixColumn( this, 1 );
  2029. zAxis.setFromMatrixColumn( this, 2 );
  2030. return this;
  2031. },
  2032. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2033. this.set(
  2034. xAxis.x, yAxis.x, zAxis.x, 0,
  2035. xAxis.y, yAxis.y, zAxis.y, 0,
  2036. xAxis.z, yAxis.z, zAxis.z, 0,
  2037. 0, 0, 0, 1
  2038. );
  2039. return this;
  2040. },
  2041. extractRotation: function () {
  2042. var v1 = new Vector3();
  2043. return function extractRotation( m ) {
  2044. var te = this.elements;
  2045. var me = m.elements;
  2046. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2047. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2048. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2049. te[ 0 ] = me[ 0 ] * scaleX;
  2050. te[ 1 ] = me[ 1 ] * scaleX;
  2051. te[ 2 ] = me[ 2 ] * scaleX;
  2052. te[ 4 ] = me[ 4 ] * scaleY;
  2053. te[ 5 ] = me[ 5 ] * scaleY;
  2054. te[ 6 ] = me[ 6 ] * scaleY;
  2055. te[ 8 ] = me[ 8 ] * scaleZ;
  2056. te[ 9 ] = me[ 9 ] * scaleZ;
  2057. te[ 10 ] = me[ 10 ] * scaleZ;
  2058. return this;
  2059. };
  2060. }(),
  2061. makeRotationFromEuler: function ( euler ) {
  2062. if ( ( euler && euler.isEuler ) === false ) {
  2063. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2064. }
  2065. var te = this.elements;
  2066. var x = euler.x, y = euler.y, z = euler.z;
  2067. var a = Math.cos( x ), b = Math.sin( x );
  2068. var c = Math.cos( y ), d = Math.sin( y );
  2069. var e = Math.cos( z ), f = Math.sin( z );
  2070. if ( euler.order === 'XYZ' ) {
  2071. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2072. te[ 0 ] = c * e;
  2073. te[ 4 ] = - c * f;
  2074. te[ 8 ] = d;
  2075. te[ 1 ] = af + be * d;
  2076. te[ 5 ] = ae - bf * d;
  2077. te[ 9 ] = - b * c;
  2078. te[ 2 ] = bf - ae * d;
  2079. te[ 6 ] = be + af * d;
  2080. te[ 10 ] = a * c;
  2081. } else if ( euler.order === 'YXZ' ) {
  2082. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2083. te[ 0 ] = ce + df * b;
  2084. te[ 4 ] = de * b - cf;
  2085. te[ 8 ] = a * d;
  2086. te[ 1 ] = a * f;
  2087. te[ 5 ] = a * e;
  2088. te[ 9 ] = - b;
  2089. te[ 2 ] = cf * b - de;
  2090. te[ 6 ] = df + ce * b;
  2091. te[ 10 ] = a * c;
  2092. } else if ( euler.order === 'ZXY' ) {
  2093. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2094. te[ 0 ] = ce - df * b;
  2095. te[ 4 ] = - a * f;
  2096. te[ 8 ] = de + cf * b;
  2097. te[ 1 ] = cf + de * b;
  2098. te[ 5 ] = a * e;
  2099. te[ 9 ] = df - ce * b;
  2100. te[ 2 ] = - a * d;
  2101. te[ 6 ] = b;
  2102. te[ 10 ] = a * c;
  2103. } else if ( euler.order === 'ZYX' ) {
  2104. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2105. te[ 0 ] = c * e;
  2106. te[ 4 ] = be * d - af;
  2107. te[ 8 ] = ae * d + bf;
  2108. te[ 1 ] = c * f;
  2109. te[ 5 ] = bf * d + ae;
  2110. te[ 9 ] = af * d - be;
  2111. te[ 2 ] = - d;
  2112. te[ 6 ] = b * c;
  2113. te[ 10 ] = a * c;
  2114. } else if ( euler.order === 'YZX' ) {
  2115. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2116. te[ 0 ] = c * e;
  2117. te[ 4 ] = bd - ac * f;
  2118. te[ 8 ] = bc * f + ad;
  2119. te[ 1 ] = f;
  2120. te[ 5 ] = a * e;
  2121. te[ 9 ] = - b * e;
  2122. te[ 2 ] = - d * e;
  2123. te[ 6 ] = ad * f + bc;
  2124. te[ 10 ] = ac - bd * f;
  2125. } else if ( euler.order === 'XZY' ) {
  2126. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2127. te[ 0 ] = c * e;
  2128. te[ 4 ] = - f;
  2129. te[ 8 ] = d * e;
  2130. te[ 1 ] = ac * f + bd;
  2131. te[ 5 ] = a * e;
  2132. te[ 9 ] = ad * f - bc;
  2133. te[ 2 ] = bc * f - ad;
  2134. te[ 6 ] = b * e;
  2135. te[ 10 ] = bd * f + ac;
  2136. }
  2137. // last column
  2138. te[ 3 ] = 0;
  2139. te[ 7 ] = 0;
  2140. te[ 11 ] = 0;
  2141. // bottom row
  2142. te[ 12 ] = 0;
  2143. te[ 13 ] = 0;
  2144. te[ 14 ] = 0;
  2145. te[ 15 ] = 1;
  2146. return this;
  2147. },
  2148. makeRotationFromQuaternion: function ( q ) {
  2149. var te = this.elements;
  2150. var x = q._x, y = q._y, z = q._z, w = q._w;
  2151. var x2 = x + x, y2 = y + y, z2 = z + z;
  2152. var xx = x * x2, xy = x * y2, xz = x * z2;
  2153. var yy = y * y2, yz = y * z2, zz = z * z2;
  2154. var wx = w * x2, wy = w * y2, wz = w * z2;
  2155. te[ 0 ] = 1 - ( yy + zz );
  2156. te[ 4 ] = xy - wz;
  2157. te[ 8 ] = xz + wy;
  2158. te[ 1 ] = xy + wz;
  2159. te[ 5 ] = 1 - ( xx + zz );
  2160. te[ 9 ] = yz - wx;
  2161. te[ 2 ] = xz - wy;
  2162. te[ 6 ] = yz + wx;
  2163. te[ 10 ] = 1 - ( xx + yy );
  2164. // last column
  2165. te[ 3 ] = 0;
  2166. te[ 7 ] = 0;
  2167. te[ 11 ] = 0;
  2168. // bottom row
  2169. te[ 12 ] = 0;
  2170. te[ 13 ] = 0;
  2171. te[ 14 ] = 0;
  2172. te[ 15 ] = 1;
  2173. return this;
  2174. },
  2175. lookAt: function () {
  2176. var x = new Vector3();
  2177. var y = new Vector3();
  2178. var z = new Vector3();
  2179. return function lookAt( eye, target, up ) {
  2180. var te = this.elements;
  2181. z.subVectors( eye, target );
  2182. if ( z.lengthSq() === 0 ) {
  2183. // eye and target are in the same position
  2184. z.z = 1;
  2185. }
  2186. z.normalize();
  2187. x.crossVectors( up, z );
  2188. if ( x.lengthSq() === 0 ) {
  2189. // eye and target are in the same vertical
  2190. z.z += 0.0001;
  2191. x.crossVectors( up, z );
  2192. }
  2193. x.normalize();
  2194. y.crossVectors( z, x );
  2195. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2196. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2197. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2198. return this;
  2199. };
  2200. }(),
  2201. multiply: function ( m, n ) {
  2202. if ( n !== undefined ) {
  2203. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2204. return this.multiplyMatrices( m, n );
  2205. }
  2206. return this.multiplyMatrices( this, m );
  2207. },
  2208. premultiply: function ( m ) {
  2209. return this.multiplyMatrices( m, this );
  2210. },
  2211. multiplyMatrices: function ( a, b ) {
  2212. var ae = a.elements;
  2213. var be = b.elements;
  2214. var te = this.elements;
  2215. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2216. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2217. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2218. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2219. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2220. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2221. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2222. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2223. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2224. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2225. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2226. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2227. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2228. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2229. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2230. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2231. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2232. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2233. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2234. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2235. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2236. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2237. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2238. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2239. return this;
  2240. },
  2241. multiplyScalar: function ( s ) {
  2242. var te = this.elements;
  2243. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2244. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2245. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2246. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2247. return this;
  2248. },
  2249. applyToBufferAttribute: function () {
  2250. var v1 = new Vector3();
  2251. return function applyToBufferAttribute( attribute ) {
  2252. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2253. v1.x = attribute.getX( i );
  2254. v1.y = attribute.getY( i );
  2255. v1.z = attribute.getZ( i );
  2256. v1.applyMatrix4( this );
  2257. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2258. }
  2259. return attribute;
  2260. };
  2261. }(),
  2262. determinant: function () {
  2263. var te = this.elements;
  2264. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2265. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2266. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2267. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2268. //TODO: make this more efficient
  2269. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2270. return (
  2271. n41 * (
  2272. + n14 * n23 * n32
  2273. - n13 * n24 * n32
  2274. - n14 * n22 * n33
  2275. + n12 * n24 * n33
  2276. + n13 * n22 * n34
  2277. - n12 * n23 * n34
  2278. ) +
  2279. n42 * (
  2280. + n11 * n23 * n34
  2281. - n11 * n24 * n33
  2282. + n14 * n21 * n33
  2283. - n13 * n21 * n34
  2284. + n13 * n24 * n31
  2285. - n14 * n23 * n31
  2286. ) +
  2287. n43 * (
  2288. + n11 * n24 * n32
  2289. - n11 * n22 * n34
  2290. - n14 * n21 * n32
  2291. + n12 * n21 * n34
  2292. + n14 * n22 * n31
  2293. - n12 * n24 * n31
  2294. ) +
  2295. n44 * (
  2296. - n13 * n22 * n31
  2297. - n11 * n23 * n32
  2298. + n11 * n22 * n33
  2299. + n13 * n21 * n32
  2300. - n12 * n21 * n33
  2301. + n12 * n23 * n31
  2302. )
  2303. );
  2304. },
  2305. transpose: function () {
  2306. var te = this.elements;
  2307. var tmp;
  2308. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2309. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2310. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2311. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2312. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2313. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2314. return this;
  2315. },
  2316. setPosition: function ( v ) {
  2317. var te = this.elements;
  2318. te[ 12 ] = v.x;
  2319. te[ 13 ] = v.y;
  2320. te[ 14 ] = v.z;
  2321. return this;
  2322. },
  2323. getInverse: function ( m, throwOnDegenerate ) {
  2324. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2325. var te = this.elements,
  2326. me = m.elements,
  2327. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2328. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2329. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2330. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2331. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2332. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2333. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2334. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2335. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2336. if ( det === 0 ) {
  2337. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  2338. if ( throwOnDegenerate === true ) {
  2339. throw new Error( msg );
  2340. } else {
  2341. console.warn( msg );
  2342. }
  2343. return this.identity();
  2344. }
  2345. var detInv = 1 / det;
  2346. te[ 0 ] = t11 * detInv;
  2347. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2348. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2349. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2350. te[ 4 ] = t12 * detInv;
  2351. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2352. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2353. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2354. te[ 8 ] = t13 * detInv;
  2355. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2356. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2357. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2358. te[ 12 ] = t14 * detInv;
  2359. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2360. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2361. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2362. return this;
  2363. },
  2364. scale: function ( v ) {
  2365. var te = this.elements;
  2366. var x = v.x, y = v.y, z = v.z;
  2367. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2368. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2369. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2370. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2371. return this;
  2372. },
  2373. getMaxScaleOnAxis: function () {
  2374. var te = this.elements;
  2375. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2376. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2377. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2378. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2379. },
  2380. makeTranslation: function ( x, y, z ) {
  2381. this.set(
  2382. 1, 0, 0, x,
  2383. 0, 1, 0, y,
  2384. 0, 0, 1, z,
  2385. 0, 0, 0, 1
  2386. );
  2387. return this;
  2388. },
  2389. makeRotationX: function ( theta ) {
  2390. var c = Math.cos( theta ), s = Math.sin( theta );
  2391. this.set(
  2392. 1, 0, 0, 0,
  2393. 0, c, - s, 0,
  2394. 0, s, c, 0,
  2395. 0, 0, 0, 1
  2396. );
  2397. return this;
  2398. },
  2399. makeRotationY: function ( theta ) {
  2400. var c = Math.cos( theta ), s = Math.sin( theta );
  2401. this.set(
  2402. c, 0, s, 0,
  2403. 0, 1, 0, 0,
  2404. - s, 0, c, 0,
  2405. 0, 0, 0, 1
  2406. );
  2407. return this;
  2408. },
  2409. makeRotationZ: function ( theta ) {
  2410. var c = Math.cos( theta ), s = Math.sin( theta );
  2411. this.set(
  2412. c, - s, 0, 0,
  2413. s, c, 0, 0,
  2414. 0, 0, 1, 0,
  2415. 0, 0, 0, 1
  2416. );
  2417. return this;
  2418. },
  2419. makeRotationAxis: function ( axis, angle ) {
  2420. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2421. var c = Math.cos( angle );
  2422. var s = Math.sin( angle );
  2423. var t = 1 - c;
  2424. var x = axis.x, y = axis.y, z = axis.z;
  2425. var tx = t * x, ty = t * y;
  2426. this.set(
  2427. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2428. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2429. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2430. 0, 0, 0, 1
  2431. );
  2432. return this;
  2433. },
  2434. makeScale: function ( x, y, z ) {
  2435. this.set(
  2436. x, 0, 0, 0,
  2437. 0, y, 0, 0,
  2438. 0, 0, z, 0,
  2439. 0, 0, 0, 1
  2440. );
  2441. return this;
  2442. },
  2443. makeShear: function ( x, y, z ) {
  2444. this.set(
  2445. 1, y, z, 0,
  2446. x, 1, z, 0,
  2447. x, y, 1, 0,
  2448. 0, 0, 0, 1
  2449. );
  2450. return this;
  2451. },
  2452. compose: function ( position, quaternion, scale ) {
  2453. this.makeRotationFromQuaternion( quaternion );
  2454. this.scale( scale );
  2455. this.setPosition( position );
  2456. return this;
  2457. },
  2458. decompose: function () {
  2459. var vector = new Vector3();
  2460. var matrix = new Matrix4();
  2461. return function decompose( position, quaternion, scale ) {
  2462. var te = this.elements;
  2463. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2464. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2465. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2466. // if determine is negative, we need to invert one scale
  2467. var det = this.determinant();
  2468. if ( det < 0 ) sx = - sx;
  2469. position.x = te[ 12 ];
  2470. position.y = te[ 13 ];
  2471. position.z = te[ 14 ];
  2472. // scale the rotation part
  2473. matrix.copy( this );
  2474. var invSX = 1 / sx;
  2475. var invSY = 1 / sy;
  2476. var invSZ = 1 / sz;
  2477. matrix.elements[ 0 ] *= invSX;
  2478. matrix.elements[ 1 ] *= invSX;
  2479. matrix.elements[ 2 ] *= invSX;
  2480. matrix.elements[ 4 ] *= invSY;
  2481. matrix.elements[ 5 ] *= invSY;
  2482. matrix.elements[ 6 ] *= invSY;
  2483. matrix.elements[ 8 ] *= invSZ;
  2484. matrix.elements[ 9 ] *= invSZ;
  2485. matrix.elements[ 10 ] *= invSZ;
  2486. quaternion.setFromRotationMatrix( matrix );
  2487. scale.x = sx;
  2488. scale.y = sy;
  2489. scale.z = sz;
  2490. return this;
  2491. };
  2492. }(),
  2493. makePerspective: function ( left, right, top, bottom, near, far ) {
  2494. if ( far === undefined ) {
  2495. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2496. }
  2497. var te = this.elements;
  2498. var x = 2 * near / ( right - left );
  2499. var y = 2 * near / ( top - bottom );
  2500. var a = ( right + left ) / ( right - left );
  2501. var b = ( top + bottom ) / ( top - bottom );
  2502. var c = - ( far + near ) / ( far - near );
  2503. var d = - 2 * far * near / ( far - near );
  2504. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2505. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2506. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2507. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2508. return this;
  2509. },
  2510. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2511. var te = this.elements;
  2512. var w = 1.0 / ( right - left );
  2513. var h = 1.0 / ( top - bottom );
  2514. var p = 1.0 / ( far - near );
  2515. var x = ( right + left ) * w;
  2516. var y = ( top + bottom ) * h;
  2517. var z = ( far + near ) * p;
  2518. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2519. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2520. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2521. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2522. return this;
  2523. },
  2524. equals: function ( matrix ) {
  2525. var te = this.elements;
  2526. var me = matrix.elements;
  2527. for ( var i = 0; i < 16; i ++ ) {
  2528. if ( te[ i ] !== me[ i ] ) return false;
  2529. }
  2530. return true;
  2531. },
  2532. fromArray: function ( array, offset ) {
  2533. if ( offset === undefined ) offset = 0;
  2534. for ( var i = 0; i < 16; i ++ ) {
  2535. this.elements[ i ] = array[ i + offset ];
  2536. }
  2537. return this;
  2538. },
  2539. toArray: function ( array, offset ) {
  2540. if ( array === undefined ) array = [];
  2541. if ( offset === undefined ) offset = 0;
  2542. var te = this.elements;
  2543. array[ offset ] = te[ 0 ];
  2544. array[ offset + 1 ] = te[ 1 ];
  2545. array[ offset + 2 ] = te[ 2 ];
  2546. array[ offset + 3 ] = te[ 3 ];
  2547. array[ offset + 4 ] = te[ 4 ];
  2548. array[ offset + 5 ] = te[ 5 ];
  2549. array[ offset + 6 ] = te[ 6 ];
  2550. array[ offset + 7 ] = te[ 7 ];
  2551. array[ offset + 8 ] = te[ 8 ];
  2552. array[ offset + 9 ] = te[ 9 ];
  2553. array[ offset + 10 ] = te[ 10 ];
  2554. array[ offset + 11 ] = te[ 11 ];
  2555. array[ offset + 12 ] = te[ 12 ];
  2556. array[ offset + 13 ] = te[ 13 ];
  2557. array[ offset + 14 ] = te[ 14 ];
  2558. array[ offset + 15 ] = te[ 15 ];
  2559. return array;
  2560. }
  2561. } );
  2562. /**
  2563. * @author alteredq / http://alteredqualia.com/
  2564. */
  2565. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2566. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2567. this.image = { data: data, width: width, height: height };
  2568. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2569. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2570. this.generateMipmaps = false;
  2571. this.flipY = false;
  2572. this.unpackAlignment = 1;
  2573. }
  2574. DataTexture.prototype = Object.create( Texture.prototype );
  2575. DataTexture.prototype.constructor = DataTexture;
  2576. DataTexture.prototype.isDataTexture = true;
  2577. /**
  2578. * @author mrdoob / http://mrdoob.com/
  2579. */
  2580. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2581. images = images !== undefined ? images : [];
  2582. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  2583. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2584. this.flipY = false;
  2585. }
  2586. CubeTexture.prototype = Object.create( Texture.prototype );
  2587. CubeTexture.prototype.constructor = CubeTexture;
  2588. CubeTexture.prototype.isCubeTexture = true;
  2589. Object.defineProperty( CubeTexture.prototype, 'images', {
  2590. get: function () {
  2591. return this.image;
  2592. },
  2593. set: function ( value ) {
  2594. this.image = value;
  2595. }
  2596. } );
  2597. /**
  2598. * @author tschw
  2599. *
  2600. * Uniforms of a program.
  2601. * Those form a tree structure with a special top-level container for the root,
  2602. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  2603. *
  2604. *
  2605. * Properties of inner nodes including the top-level container:
  2606. *
  2607. * .seq - array of nested uniforms
  2608. * .map - nested uniforms by name
  2609. *
  2610. *
  2611. * Methods of all nodes except the top-level container:
  2612. *
  2613. * .setValue( gl, value, [renderer] )
  2614. *
  2615. * uploads a uniform value(s)
  2616. * the 'renderer' parameter is needed for sampler uniforms
  2617. *
  2618. *
  2619. * Static methods of the top-level container (renderer factorizations):
  2620. *
  2621. * .upload( gl, seq, values, renderer )
  2622. *
  2623. * sets uniforms in 'seq' to 'values[id].value'
  2624. *
  2625. * .seqWithValue( seq, values ) : filteredSeq
  2626. *
  2627. * filters 'seq' entries with corresponding entry in values
  2628. *
  2629. *
  2630. * Methods of the top-level container (renderer factorizations):
  2631. *
  2632. * .setValue( gl, name, value )
  2633. *
  2634. * sets uniform with name 'name' to 'value'
  2635. *
  2636. * .set( gl, obj, prop )
  2637. *
  2638. * sets uniform from object and property with same name than uniform
  2639. *
  2640. * .setOptional( gl, obj, prop )
  2641. *
  2642. * like .set for an optional property of the object
  2643. *
  2644. */
  2645. var emptyTexture = new Texture();
  2646. var emptyCubeTexture = new CubeTexture();
  2647. // --- Base for inner nodes (including the root) ---
  2648. function UniformContainer() {
  2649. this.seq = [];
  2650. this.map = {};
  2651. }
  2652. // --- Utilities ---
  2653. // Array Caches (provide typed arrays for temporary by size)
  2654. var arrayCacheF32 = [];
  2655. var arrayCacheI32 = [];
  2656. // Float32Array caches used for uploading Matrix uniforms
  2657. var mat4array = new Float32Array( 16 );
  2658. var mat3array = new Float32Array( 9 );
  2659. // Flattening for arrays of vectors and matrices
  2660. function flatten( array, nBlocks, blockSize ) {
  2661. var firstElem = array[ 0 ];
  2662. if ( firstElem <= 0 || firstElem > 0 ) return array;
  2663. // unoptimized: ! isNaN( firstElem )
  2664. // see http://jacksondunstan.com/articles/983
  2665. var n = nBlocks * blockSize,
  2666. r = arrayCacheF32[ n ];
  2667. if ( r === undefined ) {
  2668. r = new Float32Array( n );
  2669. arrayCacheF32[ n ] = r;
  2670. }
  2671. if ( nBlocks !== 0 ) {
  2672. firstElem.toArray( r, 0 );
  2673. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  2674. offset += blockSize;
  2675. array[ i ].toArray( r, offset );
  2676. }
  2677. }
  2678. return r;
  2679. }
  2680. // Texture unit allocation
  2681. function allocTexUnits( renderer, n ) {
  2682. var r = arrayCacheI32[ n ];
  2683. if ( r === undefined ) {
  2684. r = new Int32Array( n );
  2685. arrayCacheI32[ n ] = r;
  2686. }
  2687. for ( var i = 0; i !== n; ++ i )
  2688. r[ i ] = renderer.allocTextureUnit();
  2689. return r;
  2690. }
  2691. // --- Setters ---
  2692. // Note: Defining these methods externally, because they come in a bunch
  2693. // and this way their names minify.
  2694. // Single scalar
  2695. function setValue1f( gl, v ) { gl.uniform1f( this.addr, v ); }
  2696. function setValue1i( gl, v ) { gl.uniform1i( this.addr, v ); }
  2697. // Single float vector (from flat array or THREE.VectorN)
  2698. function setValue2fv( gl, v ) {
  2699. if ( v.x === undefined ) gl.uniform2fv( this.addr, v );
  2700. else gl.uniform2f( this.addr, v.x, v.y );
  2701. }
  2702. function setValue3fv( gl, v ) {
  2703. if ( v.x !== undefined )
  2704. gl.uniform3f( this.addr, v.x, v.y, v.z );
  2705. else if ( v.r !== undefined )
  2706. gl.uniform3f( this.addr, v.r, v.g, v.b );
  2707. else
  2708. gl.uniform3fv( this.addr, v );
  2709. }
  2710. function setValue4fv( gl, v ) {
  2711. if ( v.x === undefined ) gl.uniform4fv( this.addr, v );
  2712. else gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  2713. }
  2714. // Single matrix (from flat array or MatrixN)
  2715. function setValue2fm( gl, v ) {
  2716. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  2717. }
  2718. function setValue3fm( gl, v ) {
  2719. if ( v.elements === undefined ) {
  2720. gl.uniformMatrix3fv( this.addr, false, v );
  2721. } else {
  2722. mat3array.set( v.elements );
  2723. gl.uniformMatrix3fv( this.addr, false, mat3array );
  2724. }
  2725. }
  2726. function setValue4fm( gl, v ) {
  2727. if ( v.elements === undefined ) {
  2728. gl.uniformMatrix4fv( this.addr, false, v );
  2729. } else {
  2730. mat4array.set( v.elements );
  2731. gl.uniformMatrix4fv( this.addr, false, mat4array );
  2732. }
  2733. }
  2734. // Single texture (2D / Cube)
  2735. function setValueT1( gl, v, renderer ) {
  2736. var unit = renderer.allocTextureUnit();
  2737. gl.uniform1i( this.addr, unit );
  2738. renderer.setTexture2D( v || emptyTexture, unit );
  2739. }
  2740. function setValueT6( gl, v, renderer ) {
  2741. var unit = renderer.allocTextureUnit();
  2742. gl.uniform1i( this.addr, unit );
  2743. renderer.setTextureCube( v || emptyCubeTexture, unit );
  2744. }
  2745. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  2746. function setValue2iv( gl, v ) { gl.uniform2iv( this.addr, v ); }
  2747. function setValue3iv( gl, v ) { gl.uniform3iv( this.addr, v ); }
  2748. function setValue4iv( gl, v ) { gl.uniform4iv( this.addr, v ); }
  2749. // Helper to pick the right setter for the singular case
  2750. function getSingularSetter( type ) {
  2751. switch ( type ) {
  2752. case 0x1406: return setValue1f; // FLOAT
  2753. case 0x8b50: return setValue2fv; // _VEC2
  2754. case 0x8b51: return setValue3fv; // _VEC3
  2755. case 0x8b52: return setValue4fv; // _VEC4
  2756. case 0x8b5a: return setValue2fm; // _MAT2
  2757. case 0x8b5b: return setValue3fm; // _MAT3
  2758. case 0x8b5c: return setValue4fm; // _MAT4
  2759. case 0x8b5e: return setValueT1; // SAMPLER_2D
  2760. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  2761. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  2762. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  2763. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  2764. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  2765. }
  2766. }
  2767. // Array of scalars
  2768. function setValue1fv( gl, v ) { gl.uniform1fv( this.addr, v ); }
  2769. function setValue1iv( gl, v ) { gl.uniform1iv( this.addr, v ); }
  2770. // Array of vectors (flat or from THREE classes)
  2771. function setValueV2a( gl, v ) {
  2772. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  2773. }
  2774. function setValueV3a( gl, v ) {
  2775. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  2776. }
  2777. function setValueV4a( gl, v ) {
  2778. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  2779. }
  2780. // Array of matrices (flat or from THREE clases)
  2781. function setValueM2a( gl, v ) {
  2782. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  2783. }
  2784. function setValueM3a( gl, v ) {
  2785. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  2786. }
  2787. function setValueM4a( gl, v ) {
  2788. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  2789. }
  2790. // Array of textures (2D / Cube)
  2791. function setValueT1a( gl, v, renderer ) {
  2792. var n = v.length,
  2793. units = allocTexUnits( renderer, n );
  2794. gl.uniform1iv( this.addr, units );
  2795. for ( var i = 0; i !== n; ++ i ) {
  2796. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  2797. }
  2798. }
  2799. function setValueT6a( gl, v, renderer ) {
  2800. var n = v.length,
  2801. units = allocTexUnits( renderer, n );
  2802. gl.uniform1iv( this.addr, units );
  2803. for ( var i = 0; i !== n; ++ i ) {
  2804. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  2805. }
  2806. }
  2807. // Helper to pick the right setter for a pure (bottom-level) array
  2808. function getPureArraySetter( type ) {
  2809. switch ( type ) {
  2810. case 0x1406: return setValue1fv; // FLOAT
  2811. case 0x8b50: return setValueV2a; // _VEC2
  2812. case 0x8b51: return setValueV3a; // _VEC3
  2813. case 0x8b52: return setValueV4a; // _VEC4
  2814. case 0x8b5a: return setValueM2a; // _MAT2
  2815. case 0x8b5b: return setValueM3a; // _MAT3
  2816. case 0x8b5c: return setValueM4a; // _MAT4
  2817. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  2818. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  2819. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  2820. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  2821. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  2822. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  2823. }
  2824. }
  2825. // --- Uniform Classes ---
  2826. function SingleUniform( id, activeInfo, addr ) {
  2827. this.id = id;
  2828. this.addr = addr;
  2829. this.setValue = getSingularSetter( activeInfo.type );
  2830. // this.path = activeInfo.name; // DEBUG
  2831. }
  2832. function PureArrayUniform( id, activeInfo, addr ) {
  2833. this.id = id;
  2834. this.addr = addr;
  2835. this.size = activeInfo.size;
  2836. this.setValue = getPureArraySetter( activeInfo.type );
  2837. // this.path = activeInfo.name; // DEBUG
  2838. }
  2839. function StructuredUniform( id ) {
  2840. this.id = id;
  2841. UniformContainer.call( this ); // mix-in
  2842. }
  2843. StructuredUniform.prototype.setValue = function ( gl, value ) {
  2844. // Note: Don't need an extra 'renderer' parameter, since samplers
  2845. // are not allowed in structured uniforms.
  2846. var seq = this.seq;
  2847. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  2848. var u = seq[ i ];
  2849. u.setValue( gl, value[ u.id ] );
  2850. }
  2851. };
  2852. // --- Top-level ---
  2853. // Parser - builds up the property tree from the path strings
  2854. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  2855. // extracts
  2856. // - the identifier (member name or array index)
  2857. // - followed by an optional right bracket (found when array index)
  2858. // - followed by an optional left bracket or dot (type of subscript)
  2859. //
  2860. // Note: These portions can be read in a non-overlapping fashion and
  2861. // allow straightforward parsing of the hierarchy that WebGL encodes
  2862. // in the uniform names.
  2863. function addUniform( container, uniformObject ) {
  2864. container.seq.push( uniformObject );
  2865. container.map[ uniformObject.id ] = uniformObject;
  2866. }
  2867. function parseUniform( activeInfo, addr, container ) {
  2868. var path = activeInfo.name,
  2869. pathLength = path.length;
  2870. // reset RegExp object, because of the early exit of a previous run
  2871. RePathPart.lastIndex = 0;
  2872. for ( ; ; ) {
  2873. var match = RePathPart.exec( path ),
  2874. matchEnd = RePathPart.lastIndex,
  2875. id = match[ 1 ],
  2876. idIsIndex = match[ 2 ] === ']',
  2877. subscript = match[ 3 ];
  2878. if ( idIsIndex ) id = id | 0; // convert to integer
  2879. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  2880. // bare name or "pure" bottom-level array "[0]" suffix
  2881. addUniform( container, subscript === undefined ?
  2882. new SingleUniform( id, activeInfo, addr ) :
  2883. new PureArrayUniform( id, activeInfo, addr ) );
  2884. break;
  2885. } else {
  2886. // step into inner node / create it in case it doesn't exist
  2887. var map = container.map, next = map[ id ];
  2888. if ( next === undefined ) {
  2889. next = new StructuredUniform( id );
  2890. addUniform( container, next );
  2891. }
  2892. container = next;
  2893. }
  2894. }
  2895. }
  2896. // Root Container
  2897. function WebGLUniforms( gl, program, renderer ) {
  2898. UniformContainer.call( this );
  2899. this.renderer = renderer;
  2900. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  2901. for ( var i = 0; i < n; ++ i ) {
  2902. var info = gl.getActiveUniform( program, i ),
  2903. path = info.name,
  2904. addr = gl.getUniformLocation( program, path );
  2905. parseUniform( info, addr, this );
  2906. }
  2907. }
  2908. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  2909. var u = this.map[ name ];
  2910. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  2911. };
  2912. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  2913. var v = object[ name ];
  2914. if ( v !== undefined ) this.setValue( gl, name, v );
  2915. };
  2916. // Static interface
  2917. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  2918. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  2919. var u = seq[ i ],
  2920. v = values[ u.id ];
  2921. if ( v.needsUpdate !== false ) {
  2922. // note: always updating when .needsUpdate is undefined
  2923. u.setValue( gl, v.value, renderer );
  2924. }
  2925. }
  2926. };
  2927. WebGLUniforms.seqWithValue = function ( seq, values ) {
  2928. var r = [];
  2929. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  2930. var u = seq[ i ];
  2931. if ( u.id in values ) r.push( u );
  2932. }
  2933. return r;
  2934. };
  2935. /**
  2936. * @author mrdoob / http://mrdoob.com/
  2937. */
  2938. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  2939. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  2940. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  2941. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  2942. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  2943. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  2944. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  2945. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  2946. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  2947. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  2948. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  2949. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  2950. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  2951. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  2952. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  2953. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  2954. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  2955. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  2956. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  2957. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  2958. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  2959. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  2960. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  2961. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  2962. function Color( r, g, b ) {
  2963. if ( g === undefined && b === undefined ) {
  2964. // r is THREE.Color, hex or string
  2965. return this.set( r );
  2966. }
  2967. return this.setRGB( r, g, b );
  2968. }
  2969. Object.assign( Color.prototype, {
  2970. isColor: true,
  2971. r: 1, g: 1, b: 1,
  2972. set: function ( value ) {
  2973. if ( value && value.isColor ) {
  2974. this.copy( value );
  2975. } else if ( typeof value === 'number' ) {
  2976. this.setHex( value );
  2977. } else if ( typeof value === 'string' ) {
  2978. this.setStyle( value );
  2979. }
  2980. return this;
  2981. },
  2982. setScalar: function ( scalar ) {
  2983. this.r = scalar;
  2984. this.g = scalar;
  2985. this.b = scalar;
  2986. return this;
  2987. },
  2988. setHex: function ( hex ) {
  2989. hex = Math.floor( hex );
  2990. this.r = ( hex >> 16 & 255 ) / 255;
  2991. this.g = ( hex >> 8 & 255 ) / 255;
  2992. this.b = ( hex & 255 ) / 255;
  2993. return this;
  2994. },
  2995. setRGB: function ( r, g, b ) {
  2996. this.r = r;
  2997. this.g = g;
  2998. this.b = b;
  2999. return this;
  3000. },
  3001. setHSL: function () {
  3002. function hue2rgb( p, q, t ) {
  3003. if ( t < 0 ) t += 1;
  3004. if ( t > 1 ) t -= 1;
  3005. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3006. if ( t < 1 / 2 ) return q;
  3007. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3008. return p;
  3009. }
  3010. return function setHSL( h, s, l ) {
  3011. // h,s,l ranges are in 0.0 - 1.0
  3012. h = _Math.euclideanModulo( h, 1 );
  3013. s = _Math.clamp( s, 0, 1 );
  3014. l = _Math.clamp( l, 0, 1 );
  3015. if ( s === 0 ) {
  3016. this.r = this.g = this.b = l;
  3017. } else {
  3018. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3019. var q = ( 2 * l ) - p;
  3020. this.r = hue2rgb( q, p, h + 1 / 3 );
  3021. this.g = hue2rgb( q, p, h );
  3022. this.b = hue2rgb( q, p, h - 1 / 3 );
  3023. }
  3024. return this;
  3025. };
  3026. }(),
  3027. setStyle: function ( style ) {
  3028. function handleAlpha( string ) {
  3029. if ( string === undefined ) return;
  3030. if ( parseFloat( string ) < 1 ) {
  3031. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3032. }
  3033. }
  3034. var m;
  3035. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3036. // rgb / hsl
  3037. var color;
  3038. var name = m[ 1 ];
  3039. var components = m[ 2 ];
  3040. switch ( name ) {
  3041. case 'rgb':
  3042. case 'rgba':
  3043. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3044. // rgb(255,0,0) rgba(255,0,0,0.5)
  3045. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3046. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3047. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3048. handleAlpha( color[ 5 ] );
  3049. return this;
  3050. }
  3051. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3052. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  3053. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  3054. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  3055. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  3056. handleAlpha( color[ 5 ] );
  3057. return this;
  3058. }
  3059. break;
  3060. case 'hsl':
  3061. case 'hsla':
  3062. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3063. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  3064. var h = parseFloat( color[ 1 ] ) / 360;
  3065. var s = parseInt( color[ 2 ], 10 ) / 100;
  3066. var l = parseInt( color[ 3 ], 10 ) / 100;
  3067. handleAlpha( color[ 5 ] );
  3068. return this.setHSL( h, s, l );
  3069. }
  3070. break;
  3071. }
  3072. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  3073. // hex color
  3074. var hex = m[ 1 ];
  3075. var size = hex.length;
  3076. if ( size === 3 ) {
  3077. // #ff0
  3078. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  3079. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  3080. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  3081. return this;
  3082. } else if ( size === 6 ) {
  3083. // #ff0000
  3084. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  3085. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  3086. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  3087. return this;
  3088. }
  3089. }
  3090. if ( style && style.length > 0 ) {
  3091. // color keywords
  3092. var hex = ColorKeywords[ style ];
  3093. if ( hex !== undefined ) {
  3094. // red
  3095. this.setHex( hex );
  3096. } else {
  3097. // unknown color
  3098. console.warn( 'THREE.Color: Unknown color ' + style );
  3099. }
  3100. }
  3101. return this;
  3102. },
  3103. clone: function () {
  3104. return new this.constructor( this.r, this.g, this.b );
  3105. },
  3106. copy: function ( color ) {
  3107. this.r = color.r;
  3108. this.g = color.g;
  3109. this.b = color.b;
  3110. return this;
  3111. },
  3112. copyGammaToLinear: function ( color, gammaFactor ) {
  3113. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3114. this.r = Math.pow( color.r, gammaFactor );
  3115. this.g = Math.pow( color.g, gammaFactor );
  3116. this.b = Math.pow( color.b, gammaFactor );
  3117. return this;
  3118. },
  3119. copyLinearToGamma: function ( color, gammaFactor ) {
  3120. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3121. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  3122. this.r = Math.pow( color.r, safeInverse );
  3123. this.g = Math.pow( color.g, safeInverse );
  3124. this.b = Math.pow( color.b, safeInverse );
  3125. return this;
  3126. },
  3127. convertGammaToLinear: function () {
  3128. var r = this.r, g = this.g, b = this.b;
  3129. this.r = r * r;
  3130. this.g = g * g;
  3131. this.b = b * b;
  3132. return this;
  3133. },
  3134. convertLinearToGamma: function () {
  3135. this.r = Math.sqrt( this.r );
  3136. this.g = Math.sqrt( this.g );
  3137. this.b = Math.sqrt( this.b );
  3138. return this;
  3139. },
  3140. getHex: function () {
  3141. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  3142. },
  3143. getHexString: function () {
  3144. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  3145. },
  3146. getHSL: function ( optionalTarget ) {
  3147. // h,s,l ranges are in 0.0 - 1.0
  3148. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  3149. var r = this.r, g = this.g, b = this.b;
  3150. var max = Math.max( r, g, b );
  3151. var min = Math.min( r, g, b );
  3152. var hue, saturation;
  3153. var lightness = ( min + max ) / 2.0;
  3154. if ( min === max ) {
  3155. hue = 0;
  3156. saturation = 0;
  3157. } else {
  3158. var delta = max - min;
  3159. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  3160. switch ( max ) {
  3161. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  3162. case g: hue = ( b - r ) / delta + 2; break;
  3163. case b: hue = ( r - g ) / delta + 4; break;
  3164. }
  3165. hue /= 6;
  3166. }
  3167. hsl.h = hue;
  3168. hsl.s = saturation;
  3169. hsl.l = lightness;
  3170. return hsl;
  3171. },
  3172. getStyle: function () {
  3173. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  3174. },
  3175. offsetHSL: function ( h, s, l ) {
  3176. var hsl = this.getHSL();
  3177. hsl.h += h; hsl.s += s; hsl.l += l;
  3178. this.setHSL( hsl.h, hsl.s, hsl.l );
  3179. return this;
  3180. },
  3181. add: function ( color ) {
  3182. this.r += color.r;
  3183. this.g += color.g;
  3184. this.b += color.b;
  3185. return this;
  3186. },
  3187. addColors: function ( color1, color2 ) {
  3188. this.r = color1.r + color2.r;
  3189. this.g = color1.g + color2.g;
  3190. this.b = color1.b + color2.b;
  3191. return this;
  3192. },
  3193. addScalar: function ( s ) {
  3194. this.r += s;
  3195. this.g += s;
  3196. this.b += s;
  3197. return this;
  3198. },
  3199. sub: function( color ) {
  3200. this.r = Math.max( 0, this.r - color.r );
  3201. this.g = Math.max( 0, this.g - color.g );
  3202. this.b = Math.max( 0, this.b - color.b );
  3203. return this;
  3204. },
  3205. multiply: function ( color ) {
  3206. this.r *= color.r;
  3207. this.g *= color.g;
  3208. this.b *= color.b;
  3209. return this;
  3210. },
  3211. multiplyScalar: function ( s ) {
  3212. this.r *= s;
  3213. this.g *= s;
  3214. this.b *= s;
  3215. return this;
  3216. },
  3217. lerp: function ( color, alpha ) {
  3218. this.r += ( color.r - this.r ) * alpha;
  3219. this.g += ( color.g - this.g ) * alpha;
  3220. this.b += ( color.b - this.b ) * alpha;
  3221. return this;
  3222. },
  3223. equals: function ( c ) {
  3224. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  3225. },
  3226. fromArray: function ( array, offset ) {
  3227. if ( offset === undefined ) offset = 0;
  3228. this.r = array[ offset ];
  3229. this.g = array[ offset + 1 ];
  3230. this.b = array[ offset + 2 ];
  3231. return this;
  3232. },
  3233. toArray: function ( array, offset ) {
  3234. if ( array === undefined ) array = [];
  3235. if ( offset === undefined ) offset = 0;
  3236. array[ offset ] = this.r;
  3237. array[ offset + 1 ] = this.g;
  3238. array[ offset + 2 ] = this.b;
  3239. return array;
  3240. },
  3241. toJSON: function () {
  3242. return this.getHex();
  3243. }
  3244. } );
  3245. /**
  3246. * Uniforms library for shared webgl shaders
  3247. */
  3248. var UniformsLib = {
  3249. common: {
  3250. diffuse: { value: new Color( 0xeeeeee ) },
  3251. opacity: { value: 1.0 },
  3252. map: { value: null },
  3253. offsetRepeat: { value: new Vector4( 0, 0, 1, 1 ) },
  3254. specularMap: { value: null },
  3255. alphaMap: { value: null },
  3256. envMap: { value: null },
  3257. flipEnvMap: { value: - 1 },
  3258. reflectivity: { value: 1.0 },
  3259. refractionRatio: { value: 0.98 }
  3260. },
  3261. aomap: {
  3262. aoMap: { value: null },
  3263. aoMapIntensity: { value: 1 }
  3264. },
  3265. lightmap: {
  3266. lightMap: { value: null },
  3267. lightMapIntensity: { value: 1 }
  3268. },
  3269. emissivemap: {
  3270. emissiveMap: { value: null }
  3271. },
  3272. bumpmap: {
  3273. bumpMap: { value: null },
  3274. bumpScale: { value: 1 }
  3275. },
  3276. normalmap: {
  3277. normalMap: { value: null },
  3278. normalScale: { value: new Vector2( 1, 1 ) }
  3279. },
  3280. displacementmap: {
  3281. displacementMap: { value: null },
  3282. displacementScale: { value: 1 },
  3283. displacementBias: { value: 0 }
  3284. },
  3285. roughnessmap: {
  3286. roughnessMap: { value: null }
  3287. },
  3288. metalnessmap: {
  3289. metalnessMap: { value: null }
  3290. },
  3291. gradientmap: {
  3292. gradientMap: { value: null }
  3293. },
  3294. fog: {
  3295. fogDensity: { value: 0.00025 },
  3296. fogNear: { value: 1 },
  3297. fogFar: { value: 2000 },
  3298. fogColor: { value: new Color( 0xffffff ) }
  3299. },
  3300. lights: {
  3301. ambientLightColor: { value: [] },
  3302. directionalLights: { value: [], properties: {
  3303. direction: {},
  3304. color: {},
  3305. shadow: {},
  3306. shadowBias: {},
  3307. shadowRadius: {},
  3308. shadowMapSize: {}
  3309. } },
  3310. directionalShadowMap: { value: [] },
  3311. directionalShadowMatrix: { value: [] },
  3312. spotLights: { value: [], properties: {
  3313. color: {},
  3314. position: {},
  3315. direction: {},
  3316. distance: {},
  3317. coneCos: {},
  3318. penumbraCos: {},
  3319. decay: {},
  3320. shadow: {},
  3321. shadowBias: {},
  3322. shadowRadius: {},
  3323. shadowMapSize: {}
  3324. } },
  3325. spotShadowMap: { value: [] },
  3326. spotShadowMatrix: { value: [] },
  3327. pointLights: { value: [], properties: {
  3328. color: {},
  3329. position: {},
  3330. decay: {},
  3331. distance: {},
  3332. shadow: {},
  3333. shadowBias: {},
  3334. shadowRadius: {},
  3335. shadowMapSize: {}
  3336. } },
  3337. pointShadowMap: { value: [] },
  3338. pointShadowMatrix: { value: [] },
  3339. hemisphereLights: { value: [], properties: {
  3340. direction: {},
  3341. skyColor: {},
  3342. groundColor: {}
  3343. } },
  3344. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  3345. rectAreaLights: { value: [], properties: {
  3346. color: {},
  3347. position: {},
  3348. width: {},
  3349. height: {}
  3350. } }
  3351. },
  3352. points: {
  3353. diffuse: { value: new Color( 0xeeeeee ) },
  3354. opacity: { value: 1.0 },
  3355. size: { value: 1.0 },
  3356. scale: { value: 1.0 },
  3357. map: { value: null },
  3358. offsetRepeat: { value: new Vector4( 0, 0, 1, 1 ) }
  3359. }
  3360. };
  3361. /**
  3362. * Uniform Utilities
  3363. */
  3364. var UniformsUtils = {
  3365. merge: function ( uniforms ) {
  3366. var merged = {};
  3367. for ( var u = 0; u < uniforms.length; u ++ ) {
  3368. var tmp = this.clone( uniforms[ u ] );
  3369. for ( var p in tmp ) {
  3370. merged[ p ] = tmp[ p ];
  3371. }
  3372. }
  3373. return merged;
  3374. },
  3375. clone: function ( uniforms_src ) {
  3376. var uniforms_dst = {};
  3377. for ( var u in uniforms_src ) {
  3378. uniforms_dst[ u ] = {};
  3379. for ( var p in uniforms_src[ u ] ) {
  3380. var parameter_src = uniforms_src[ u ][ p ];
  3381. if ( parameter_src && ( parameter_src.isColor ||
  3382. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  3383. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  3384. parameter_src.isTexture ) ) {
  3385. uniforms_dst[ u ][ p ] = parameter_src.clone();
  3386. } else if ( Array.isArray( parameter_src ) ) {
  3387. uniforms_dst[ u ][ p ] = parameter_src.slice();
  3388. } else {
  3389. uniforms_dst[ u ][ p ] = parameter_src;
  3390. }
  3391. }
  3392. }
  3393. return uniforms_dst;
  3394. }
  3395. };
  3396. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  3397. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif\n";
  3398. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  3399. 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";
  3400. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3401. var begin_vertex = "\nvec3 transformed = vec3( position );\n";
  3402. var beginnormal_vertex = "\nvec3 objectNormal = vec3( normal );\n";
  3403. 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";
  3404. 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 = dFdx( surf_pos );\n\t\tvec3 vSigmaY = dFdy( surf_pos );\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";
  3405. 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";
  3406. 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";
  3407. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvarying vec3 vViewPosition;\n#endif\n";
  3408. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n";
  3409. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3410. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif\n";
  3411. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3412. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3413. 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";
  3414. 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";
  3415. var defaultnormal_vertex = "#ifdef FLIP_SIDED\n\tobjectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  3416. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif\n";
  3417. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  3418. 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";
  3419. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif\n";
  3420. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  3421. 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";
  3422. 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";
  3423. 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";
  3424. 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";
  3425. 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";
  3426. var fog_vertex = "\n#ifdef USE_FOG\nfogDepth = -mvPosition.z;\n#endif";
  3427. var fog_pars_vertex = "#ifdef USE_FOG\n varying float fogDepth;\n#endif\n";
  3428. 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";
  3429. 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";
  3430. 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";
  3431. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  3432. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3433. 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";
  3434. 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";
  3435. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  3436. 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";
  3437. 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";
  3438. 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";
  3439. 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";
  3440. var logdepthbuf_fragment = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\tgl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  3441. 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";
  3442. 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";
  3443. 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";
  3444. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif\n";
  3445. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n";
  3446. 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";
  3447. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform vec4 offsetRepeat;\n\tuniform sampler2D map;\n#endif\n";
  3448. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif\n";
  3449. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3450. 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";
  3451. 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";
  3452. 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";
  3453. 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";
  3454. 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";
  3455. 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 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\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";
  3456. 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";
  3457. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  3458. 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";
  3459. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif\n";
  3460. 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";
  3461. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif\n";
  3462. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3463. 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";
  3464. 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";
  3465. 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";
  3466. 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";
  3467. 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";
  3468. 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";
  3469. 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";
  3470. 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";
  3471. 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";
  3472. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3473. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  3474. 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";
  3475. 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";
  3476. 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";
  3477. 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";
  3478. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3479. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3480. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3481. 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";
  3482. 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";
  3483. 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";
  3484. 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";
  3485. 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";
  3486. 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";
  3487. 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";
  3488. 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";
  3489. 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";
  3490. 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";
  3491. 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";
  3492. 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";
  3493. 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";
  3494. 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";
  3495. 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";
  3496. 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";
  3497. 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";
  3498. 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";
  3499. 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";
  3500. 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";
  3501. 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";
  3502. 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";
  3503. 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";
  3504. 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";
  3505. 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";
  3506. var ShaderChunk = {
  3507. alphamap_fragment: alphamap_fragment,
  3508. alphamap_pars_fragment: alphamap_pars_fragment,
  3509. alphatest_fragment: alphatest_fragment,
  3510. aomap_fragment: aomap_fragment,
  3511. aomap_pars_fragment: aomap_pars_fragment,
  3512. begin_vertex: begin_vertex,
  3513. beginnormal_vertex: beginnormal_vertex,
  3514. bsdfs: bsdfs,
  3515. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3516. clipping_planes_fragment: clipping_planes_fragment,
  3517. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3518. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3519. clipping_planes_vertex: clipping_planes_vertex,
  3520. color_fragment: color_fragment,
  3521. color_pars_fragment: color_pars_fragment,
  3522. color_pars_vertex: color_pars_vertex,
  3523. color_vertex: color_vertex,
  3524. common: common,
  3525. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3526. defaultnormal_vertex: defaultnormal_vertex,
  3527. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3528. displacementmap_vertex: displacementmap_vertex,
  3529. emissivemap_fragment: emissivemap_fragment,
  3530. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3531. encodings_fragment: encodings_fragment,
  3532. encodings_pars_fragment: encodings_pars_fragment,
  3533. envmap_fragment: envmap_fragment,
  3534. envmap_pars_fragment: envmap_pars_fragment,
  3535. envmap_pars_vertex: envmap_pars_vertex,
  3536. envmap_vertex: envmap_vertex,
  3537. fog_vertex: fog_vertex,
  3538. fog_pars_vertex: fog_pars_vertex,
  3539. fog_fragment: fog_fragment,
  3540. fog_pars_fragment: fog_pars_fragment,
  3541. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3542. lightmap_fragment: lightmap_fragment,
  3543. lightmap_pars_fragment: lightmap_pars_fragment,
  3544. lights_lambert_vertex: lights_lambert_vertex,
  3545. lights_pars: lights_pars,
  3546. lights_phong_fragment: lights_phong_fragment,
  3547. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3548. lights_physical_fragment: lights_physical_fragment,
  3549. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3550. lights_template: lights_template,
  3551. logdepthbuf_fragment: logdepthbuf_fragment,
  3552. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3553. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3554. logdepthbuf_vertex: logdepthbuf_vertex,
  3555. map_fragment: map_fragment,
  3556. map_pars_fragment: map_pars_fragment,
  3557. map_particle_fragment: map_particle_fragment,
  3558. map_particle_pars_fragment: map_particle_pars_fragment,
  3559. metalnessmap_fragment: metalnessmap_fragment,
  3560. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3561. morphnormal_vertex: morphnormal_vertex,
  3562. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3563. morphtarget_vertex: morphtarget_vertex,
  3564. normal_flip: normal_flip,
  3565. normal_fragment: normal_fragment,
  3566. normalmap_pars_fragment: normalmap_pars_fragment,
  3567. packing: packing,
  3568. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3569. project_vertex: project_vertex,
  3570. dithering_fragment: dithering_fragment,
  3571. dithering_pars_fragment: dithering_pars_fragment,
  3572. roughnessmap_fragment: roughnessmap_fragment,
  3573. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3574. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3575. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3576. shadowmap_vertex: shadowmap_vertex,
  3577. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3578. skinbase_vertex: skinbase_vertex,
  3579. skinning_pars_vertex: skinning_pars_vertex,
  3580. skinning_vertex: skinning_vertex,
  3581. skinnormal_vertex: skinnormal_vertex,
  3582. specularmap_fragment: specularmap_fragment,
  3583. specularmap_pars_fragment: specularmap_pars_fragment,
  3584. tonemapping_fragment: tonemapping_fragment,
  3585. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3586. uv_pars_fragment: uv_pars_fragment,
  3587. uv_pars_vertex: uv_pars_vertex,
  3588. uv_vertex: uv_vertex,
  3589. uv2_pars_fragment: uv2_pars_fragment,
  3590. uv2_pars_vertex: uv2_pars_vertex,
  3591. uv2_vertex: uv2_vertex,
  3592. worldpos_vertex: worldpos_vertex,
  3593. cube_frag: cube_frag,
  3594. cube_vert: cube_vert,
  3595. depth_frag: depth_frag,
  3596. depth_vert: depth_vert,
  3597. distanceRGBA_frag: distanceRGBA_frag,
  3598. distanceRGBA_vert: distanceRGBA_vert,
  3599. equirect_frag: equirect_frag,
  3600. equirect_vert: equirect_vert,
  3601. linedashed_frag: linedashed_frag,
  3602. linedashed_vert: linedashed_vert,
  3603. meshbasic_frag: meshbasic_frag,
  3604. meshbasic_vert: meshbasic_vert,
  3605. meshlambert_frag: meshlambert_frag,
  3606. meshlambert_vert: meshlambert_vert,
  3607. meshphong_frag: meshphong_frag,
  3608. meshphong_vert: meshphong_vert,
  3609. meshphysical_frag: meshphysical_frag,
  3610. meshphysical_vert: meshphysical_vert,
  3611. normal_frag: normal_frag,
  3612. normal_vert: normal_vert,
  3613. points_frag: points_frag,
  3614. points_vert: points_vert,
  3615. shadow_frag: shadow_frag,
  3616. shadow_vert: shadow_vert
  3617. };
  3618. /**
  3619. * @author alteredq / http://alteredqualia.com/
  3620. * @author mrdoob / http://mrdoob.com/
  3621. * @author mikael emtinger / http://gomo.se/
  3622. */
  3623. var ShaderLib = {
  3624. basic: {
  3625. uniforms: UniformsUtils.merge( [
  3626. UniformsLib.common,
  3627. UniformsLib.aomap,
  3628. UniformsLib.lightmap,
  3629. UniformsLib.fog
  3630. ] ),
  3631. vertexShader: ShaderChunk.meshbasic_vert,
  3632. fragmentShader: ShaderChunk.meshbasic_frag
  3633. },
  3634. lambert: {
  3635. uniforms: UniformsUtils.merge( [
  3636. UniformsLib.common,
  3637. UniformsLib.aomap,
  3638. UniformsLib.lightmap,
  3639. UniformsLib.emissivemap,
  3640. UniformsLib.fog,
  3641. UniformsLib.lights,
  3642. {
  3643. emissive: { value: new Color( 0x000000 ) }
  3644. }
  3645. ] ),
  3646. vertexShader: ShaderChunk.meshlambert_vert,
  3647. fragmentShader: ShaderChunk.meshlambert_frag
  3648. },
  3649. phong: {
  3650. uniforms: UniformsUtils.merge( [
  3651. UniformsLib.common,
  3652. UniformsLib.aomap,
  3653. UniformsLib.lightmap,
  3654. UniformsLib.emissivemap,
  3655. UniformsLib.bumpmap,
  3656. UniformsLib.normalmap,
  3657. UniformsLib.displacementmap,
  3658. UniformsLib.gradientmap,
  3659. UniformsLib.fog,
  3660. UniformsLib.lights,
  3661. {
  3662. emissive: { value: new Color( 0x000000 ) },
  3663. specular: { value: new Color( 0x111111 ) },
  3664. shininess: { value: 30 }
  3665. }
  3666. ] ),
  3667. vertexShader: ShaderChunk.meshphong_vert,
  3668. fragmentShader: ShaderChunk.meshphong_frag
  3669. },
  3670. standard: {
  3671. uniforms: UniformsUtils.merge( [
  3672. UniformsLib.common,
  3673. UniformsLib.aomap,
  3674. UniformsLib.lightmap,
  3675. UniformsLib.emissivemap,
  3676. UniformsLib.bumpmap,
  3677. UniformsLib.normalmap,
  3678. UniformsLib.displacementmap,
  3679. UniformsLib.roughnessmap,
  3680. UniformsLib.metalnessmap,
  3681. UniformsLib.fog,
  3682. UniformsLib.lights,
  3683. {
  3684. emissive: { value: new Color( 0x000000 ) },
  3685. roughness: { value: 0.5 },
  3686. metalness: { value: 0.5 },
  3687. envMapIntensity: { value: 1 } // temporary
  3688. }
  3689. ] ),
  3690. vertexShader: ShaderChunk.meshphysical_vert,
  3691. fragmentShader: ShaderChunk.meshphysical_frag
  3692. },
  3693. points: {
  3694. uniforms: UniformsUtils.merge( [
  3695. UniformsLib.points,
  3696. UniformsLib.fog
  3697. ] ),
  3698. vertexShader: ShaderChunk.points_vert,
  3699. fragmentShader: ShaderChunk.points_frag
  3700. },
  3701. dashed: {
  3702. uniforms: UniformsUtils.merge( [
  3703. UniformsLib.common,
  3704. UniformsLib.fog,
  3705. {
  3706. scale: { value: 1 },
  3707. dashSize: { value: 1 },
  3708. totalSize: { value: 2 }
  3709. }
  3710. ] ),
  3711. vertexShader: ShaderChunk.linedashed_vert,
  3712. fragmentShader: ShaderChunk.linedashed_frag
  3713. },
  3714. depth: {
  3715. uniforms: UniformsUtils.merge( [
  3716. UniformsLib.common,
  3717. UniformsLib.displacementmap
  3718. ] ),
  3719. vertexShader: ShaderChunk.depth_vert,
  3720. fragmentShader: ShaderChunk.depth_frag
  3721. },
  3722. normal: {
  3723. uniforms: UniformsUtils.merge( [
  3724. UniformsLib.common,
  3725. UniformsLib.bumpmap,
  3726. UniformsLib.normalmap,
  3727. UniformsLib.displacementmap,
  3728. {
  3729. opacity: { value: 1.0 }
  3730. }
  3731. ] ),
  3732. vertexShader: ShaderChunk.normal_vert,
  3733. fragmentShader: ShaderChunk.normal_frag
  3734. },
  3735. /* -------------------------------------------------------------------------
  3736. // Cube map shader
  3737. ------------------------------------------------------------------------- */
  3738. cube: {
  3739. uniforms: {
  3740. tCube: { value: null },
  3741. tFlip: { value: - 1 },
  3742. opacity: { value: 1.0 }
  3743. },
  3744. vertexShader: ShaderChunk.cube_vert,
  3745. fragmentShader: ShaderChunk.cube_frag
  3746. },
  3747. /* -------------------------------------------------------------------------
  3748. // Cube map shader
  3749. ------------------------------------------------------------------------- */
  3750. equirect: {
  3751. uniforms: {
  3752. tEquirect: { value: null },
  3753. tFlip: { value: - 1 }
  3754. },
  3755. vertexShader: ShaderChunk.equirect_vert,
  3756. fragmentShader: ShaderChunk.equirect_frag
  3757. },
  3758. distanceRGBA: {
  3759. uniforms: {
  3760. lightPos: { value: new Vector3() }
  3761. },
  3762. vertexShader: ShaderChunk.distanceRGBA_vert,
  3763. fragmentShader: ShaderChunk.distanceRGBA_frag
  3764. }
  3765. };
  3766. ShaderLib.physical = {
  3767. uniforms: UniformsUtils.merge( [
  3768. ShaderLib.standard.uniforms,
  3769. {
  3770. clearCoat: { value: 0 },
  3771. clearCoatRoughness: { value: 0 }
  3772. }
  3773. ] ),
  3774. vertexShader: ShaderChunk.meshphysical_vert,
  3775. fragmentShader: ShaderChunk.meshphysical_frag
  3776. };
  3777. /**
  3778. * @author bhouston / http://clara.io
  3779. */
  3780. function Box2( min, max ) {
  3781. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  3782. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  3783. }
  3784. Object.assign( Box2.prototype, {
  3785. set: function ( min, max ) {
  3786. this.min.copy( min );
  3787. this.max.copy( max );
  3788. return this;
  3789. },
  3790. setFromPoints: function ( points ) {
  3791. this.makeEmpty();
  3792. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3793. this.expandByPoint( points[ i ] );
  3794. }
  3795. return this;
  3796. },
  3797. setFromCenterAndSize: function () {
  3798. var v1 = new Vector2();
  3799. return function setFromCenterAndSize( center, size ) {
  3800. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  3801. this.min.copy( center ).sub( halfSize );
  3802. this.max.copy( center ).add( halfSize );
  3803. return this;
  3804. };
  3805. }(),
  3806. clone: function () {
  3807. return new this.constructor().copy( this );
  3808. },
  3809. copy: function ( box ) {
  3810. this.min.copy( box.min );
  3811. this.max.copy( box.max );
  3812. return this;
  3813. },
  3814. makeEmpty: function () {
  3815. this.min.x = this.min.y = + Infinity;
  3816. this.max.x = this.max.y = - Infinity;
  3817. return this;
  3818. },
  3819. isEmpty: function () {
  3820. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3821. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  3822. },
  3823. getCenter: function ( optionalTarget ) {
  3824. var result = optionalTarget || new Vector2();
  3825. return this.isEmpty() ? result.set( 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3826. },
  3827. getSize: function ( optionalTarget ) {
  3828. var result = optionalTarget || new Vector2();
  3829. return this.isEmpty() ? result.set( 0, 0 ) : result.subVectors( this.max, this.min );
  3830. },
  3831. expandByPoint: function ( point ) {
  3832. this.min.min( point );
  3833. this.max.max( point );
  3834. return this;
  3835. },
  3836. expandByVector: function ( vector ) {
  3837. this.min.sub( vector );
  3838. this.max.add( vector );
  3839. return this;
  3840. },
  3841. expandByScalar: function ( scalar ) {
  3842. this.min.addScalar( - scalar );
  3843. this.max.addScalar( scalar );
  3844. return this;
  3845. },
  3846. containsPoint: function ( point ) {
  3847. return point.x < this.min.x || point.x > this.max.x ||
  3848. point.y < this.min.y || point.y > this.max.y ? false : true;
  3849. },
  3850. containsBox: function ( box ) {
  3851. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3852. this.min.y <= box.min.y && box.max.y <= this.max.y;
  3853. },
  3854. getParameter: function ( point, optionalTarget ) {
  3855. // This can potentially have a divide by zero if the box
  3856. // has a size dimension of 0.
  3857. var result = optionalTarget || new Vector2();
  3858. return result.set(
  3859. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3860. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  3861. );
  3862. },
  3863. intersectsBox: function ( box ) {
  3864. // using 4 splitting planes to rule out intersections
  3865. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3866. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  3867. },
  3868. clampPoint: function ( point, optionalTarget ) {
  3869. var result = optionalTarget || new Vector2();
  3870. return result.copy( point ).clamp( this.min, this.max );
  3871. },
  3872. distanceToPoint: function () {
  3873. var v1 = new Vector2();
  3874. return function distanceToPoint( point ) {
  3875. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3876. return clampedPoint.sub( point ).length();
  3877. };
  3878. }(),
  3879. intersect: function ( box ) {
  3880. this.min.max( box.min );
  3881. this.max.min( box.max );
  3882. return this;
  3883. },
  3884. union: function ( box ) {
  3885. this.min.min( box.min );
  3886. this.max.max( box.max );
  3887. return this;
  3888. },
  3889. translate: function ( offset ) {
  3890. this.min.add( offset );
  3891. this.max.add( offset );
  3892. return this;
  3893. },
  3894. equals: function ( box ) {
  3895. return box.min.equals( this.min ) && box.max.equals( this.max );
  3896. }
  3897. } );
  3898. /**
  3899. * @author mikael emtinger / http://gomo.se/
  3900. * @author alteredq / http://alteredqualia.com/
  3901. */
  3902. function LensFlarePlugin( renderer, flares ) {
  3903. var gl = renderer.context;
  3904. var state = renderer.state;
  3905. var vertexBuffer, elementBuffer;
  3906. var shader, program, attributes, uniforms;
  3907. var tempTexture, occlusionTexture;
  3908. function init() {
  3909. var vertices = new Float32Array( [
  3910. - 1, - 1, 0, 0,
  3911. 1, - 1, 1, 0,
  3912. 1, 1, 1, 1,
  3913. - 1, 1, 0, 1
  3914. ] );
  3915. var faces = new Uint16Array( [
  3916. 0, 1, 2,
  3917. 0, 2, 3
  3918. ] );
  3919. // buffers
  3920. vertexBuffer = gl.createBuffer();
  3921. elementBuffer = gl.createBuffer();
  3922. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  3923. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  3924. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  3925. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  3926. // textures
  3927. tempTexture = gl.createTexture();
  3928. occlusionTexture = gl.createTexture();
  3929. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  3930. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  3931. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  3932. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  3933. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  3934. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  3935. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  3936. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  3937. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  3938. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  3939. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  3940. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  3941. shader = {
  3942. vertexShader: [
  3943. "uniform lowp int renderType;",
  3944. "uniform vec3 screenPosition;",
  3945. "uniform vec2 scale;",
  3946. "uniform float rotation;",
  3947. "uniform sampler2D occlusionMap;",
  3948. "attribute vec2 position;",
  3949. "attribute vec2 uv;",
  3950. "varying vec2 vUV;",
  3951. "varying float vVisibility;",
  3952. "void main() {",
  3953. "vUV = uv;",
  3954. "vec2 pos = position;",
  3955. "if ( renderType == 2 ) {",
  3956. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  3957. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  3958. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  3959. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  3960. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  3961. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  3962. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  3963. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  3964. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  3965. "vVisibility = visibility.r / 9.0;",
  3966. "vVisibility *= 1.0 - visibility.g / 9.0;",
  3967. "vVisibility *= visibility.b / 9.0;",
  3968. "vVisibility *= 1.0 - visibility.a / 9.0;",
  3969. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  3970. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  3971. "}",
  3972. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  3973. "}"
  3974. ].join( "\n" ),
  3975. fragmentShader: [
  3976. "uniform lowp int renderType;",
  3977. "uniform sampler2D map;",
  3978. "uniform float opacity;",
  3979. "uniform vec3 color;",
  3980. "varying vec2 vUV;",
  3981. "varying float vVisibility;",
  3982. "void main() {",
  3983. // pink square
  3984. "if ( renderType == 0 ) {",
  3985. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  3986. // restore
  3987. "} else if ( renderType == 1 ) {",
  3988. "gl_FragColor = texture2D( map, vUV );",
  3989. // flare
  3990. "} else {",
  3991. "vec4 texture = texture2D( map, vUV );",
  3992. "texture.a *= opacity * vVisibility;",
  3993. "gl_FragColor = texture;",
  3994. "gl_FragColor.rgb *= color;",
  3995. "}",
  3996. "}"
  3997. ].join( "\n" )
  3998. };
  3999. program = createProgram( shader );
  4000. attributes = {
  4001. vertex: gl.getAttribLocation ( program, "position" ),
  4002. uv: gl.getAttribLocation ( program, "uv" )
  4003. };
  4004. uniforms = {
  4005. renderType: gl.getUniformLocation( program, "renderType" ),
  4006. map: gl.getUniformLocation( program, "map" ),
  4007. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  4008. opacity: gl.getUniformLocation( program, "opacity" ),
  4009. color: gl.getUniformLocation( program, "color" ),
  4010. scale: gl.getUniformLocation( program, "scale" ),
  4011. rotation: gl.getUniformLocation( program, "rotation" ),
  4012. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  4013. };
  4014. }
  4015. /*
  4016. * Render lens flares
  4017. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  4018. * reads these back and calculates occlusion.
  4019. */
  4020. this.render = function ( scene, camera, viewport ) {
  4021. if ( flares.length === 0 ) return;
  4022. var tempPosition = new Vector3();
  4023. var invAspect = viewport.w / viewport.z,
  4024. halfViewportWidth = viewport.z * 0.5,
  4025. halfViewportHeight = viewport.w * 0.5;
  4026. var size = 16 / viewport.w,
  4027. scale = new Vector2( size * invAspect, size );
  4028. var screenPosition = new Vector3( 1, 1, 0 ),
  4029. screenPositionPixels = new Vector2( 1, 1 );
  4030. var validArea = new Box2();
  4031. validArea.min.set( viewport.x, viewport.y );
  4032. validArea.max.set( viewport.x + ( viewport.z - 16 ), viewport.y + ( viewport.w - 16 ) );
  4033. if ( program === undefined ) {
  4034. init();
  4035. }
  4036. gl.useProgram( program );
  4037. state.initAttributes();
  4038. state.enableAttribute( attributes.vertex );
  4039. state.enableAttribute( attributes.uv );
  4040. state.disableUnusedAttributes();
  4041. // loop through all lens flares to update their occlusion and positions
  4042. // setup gl and common used attribs/uniforms
  4043. gl.uniform1i( uniforms.occlusionMap, 0 );
  4044. gl.uniform1i( uniforms.map, 1 );
  4045. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4046. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  4047. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  4048. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4049. state.disable( gl.CULL_FACE );
  4050. state.buffers.depth.setMask( false );
  4051. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  4052. size = 16 / viewport.w;
  4053. scale.set( size * invAspect, size );
  4054. // calc object screen position
  4055. var flare = flares[ i ];
  4056. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  4057. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  4058. tempPosition.applyMatrix4( camera.projectionMatrix );
  4059. // setup arrays for gl programs
  4060. screenPosition.copy( tempPosition );
  4061. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  4062. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  4063. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  4064. // screen cull
  4065. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  4066. // save current RGB to temp texture
  4067. state.activeTexture( gl.TEXTURE0 );
  4068. state.bindTexture( gl.TEXTURE_2D, null );
  4069. state.activeTexture( gl.TEXTURE1 );
  4070. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  4071. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  4072. // render pink quad
  4073. gl.uniform1i( uniforms.renderType, 0 );
  4074. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  4075. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  4076. state.disable( gl.BLEND );
  4077. state.enable( gl.DEPTH_TEST );
  4078. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4079. // copy result to occlusionMap
  4080. state.activeTexture( gl.TEXTURE0 );
  4081. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  4082. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  4083. // restore graphics
  4084. gl.uniform1i( uniforms.renderType, 1 );
  4085. state.disable( gl.DEPTH_TEST );
  4086. state.activeTexture( gl.TEXTURE1 );
  4087. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  4088. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4089. // update object positions
  4090. flare.positionScreen.copy( screenPosition );
  4091. if ( flare.customUpdateCallback ) {
  4092. flare.customUpdateCallback( flare );
  4093. } else {
  4094. flare.updateLensFlares();
  4095. }
  4096. // render flares
  4097. gl.uniform1i( uniforms.renderType, 2 );
  4098. state.enable( gl.BLEND );
  4099. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  4100. var sprite = flare.lensFlares[ j ];
  4101. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  4102. screenPosition.x = sprite.x;
  4103. screenPosition.y = sprite.y;
  4104. screenPosition.z = sprite.z;
  4105. size = sprite.size * sprite.scale / viewport.w;
  4106. scale.x = size * invAspect;
  4107. scale.y = size;
  4108. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  4109. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  4110. gl.uniform1f( uniforms.rotation, sprite.rotation );
  4111. gl.uniform1f( uniforms.opacity, sprite.opacity );
  4112. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  4113. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  4114. renderer.setTexture2D( sprite.texture, 1 );
  4115. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4116. }
  4117. }
  4118. }
  4119. }
  4120. // restore gl
  4121. state.enable( gl.CULL_FACE );
  4122. state.enable( gl.DEPTH_TEST );
  4123. state.buffers.depth.setMask( true );
  4124. renderer.resetGLState();
  4125. };
  4126. function createProgram( shader ) {
  4127. var program = gl.createProgram();
  4128. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  4129. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  4130. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  4131. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  4132. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  4133. gl.compileShader( fragmentShader );
  4134. gl.compileShader( vertexShader );
  4135. gl.attachShader( program, fragmentShader );
  4136. gl.attachShader( program, vertexShader );
  4137. gl.linkProgram( program );
  4138. return program;
  4139. }
  4140. }
  4141. /**
  4142. * @author mikael emtinger / http://gomo.se/
  4143. * @author alteredq / http://alteredqualia.com/
  4144. */
  4145. function SpritePlugin( renderer, sprites ) {
  4146. var gl = renderer.context;
  4147. var state = renderer.state;
  4148. var vertexBuffer, elementBuffer;
  4149. var program, attributes, uniforms;
  4150. var texture;
  4151. // decompose matrixWorld
  4152. var spritePosition = new Vector3();
  4153. var spriteRotation = new Quaternion();
  4154. var spriteScale = new Vector3();
  4155. function init() {
  4156. var vertices = new Float32Array( [
  4157. - 0.5, - 0.5, 0, 0,
  4158. 0.5, - 0.5, 1, 0,
  4159. 0.5, 0.5, 1, 1,
  4160. - 0.5, 0.5, 0, 1
  4161. ] );
  4162. var faces = new Uint16Array( [
  4163. 0, 1, 2,
  4164. 0, 2, 3
  4165. ] );
  4166. vertexBuffer = gl.createBuffer();
  4167. elementBuffer = gl.createBuffer();
  4168. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4169. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  4170. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4171. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  4172. program = createProgram();
  4173. attributes = {
  4174. position: gl.getAttribLocation ( program, 'position' ),
  4175. uv: gl.getAttribLocation ( program, 'uv' )
  4176. };
  4177. uniforms = {
  4178. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  4179. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  4180. rotation: gl.getUniformLocation( program, 'rotation' ),
  4181. scale: gl.getUniformLocation( program, 'scale' ),
  4182. color: gl.getUniformLocation( program, 'color' ),
  4183. map: gl.getUniformLocation( program, 'map' ),
  4184. opacity: gl.getUniformLocation( program, 'opacity' ),
  4185. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  4186. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  4187. fogType: gl.getUniformLocation( program, 'fogType' ),
  4188. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  4189. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  4190. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  4191. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  4192. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  4193. };
  4194. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  4195. canvas.width = 8;
  4196. canvas.height = 8;
  4197. var context = canvas.getContext( '2d' );
  4198. context.fillStyle = 'white';
  4199. context.fillRect( 0, 0, 8, 8 );
  4200. texture = new Texture( canvas );
  4201. texture.needsUpdate = true;
  4202. }
  4203. this.render = function ( scene, camera ) {
  4204. if ( sprites.length === 0 ) return;
  4205. // setup gl
  4206. if ( program === undefined ) {
  4207. init();
  4208. }
  4209. gl.useProgram( program );
  4210. state.initAttributes();
  4211. state.enableAttribute( attributes.position );
  4212. state.enableAttribute( attributes.uv );
  4213. state.disableUnusedAttributes();
  4214. state.disable( gl.CULL_FACE );
  4215. state.enable( gl.BLEND );
  4216. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  4217. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  4218. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  4219. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  4220. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  4221. state.activeTexture( gl.TEXTURE0 );
  4222. gl.uniform1i( uniforms.map, 0 );
  4223. var oldFogType = 0;
  4224. var sceneFogType = 0;
  4225. var fog = scene.fog;
  4226. if ( fog ) {
  4227. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  4228. if ( fog.isFog ) {
  4229. gl.uniform1f( uniforms.fogNear, fog.near );
  4230. gl.uniform1f( uniforms.fogFar, fog.far );
  4231. gl.uniform1i( uniforms.fogType, 1 );
  4232. oldFogType = 1;
  4233. sceneFogType = 1;
  4234. } else if ( fog.isFogExp2 ) {
  4235. gl.uniform1f( uniforms.fogDensity, fog.density );
  4236. gl.uniform1i( uniforms.fogType, 2 );
  4237. oldFogType = 2;
  4238. sceneFogType = 2;
  4239. }
  4240. } else {
  4241. gl.uniform1i( uniforms.fogType, 0 );
  4242. oldFogType = 0;
  4243. sceneFogType = 0;
  4244. }
  4245. // update positions and sort
  4246. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  4247. var sprite = sprites[ i ];
  4248. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  4249. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  4250. }
  4251. sprites.sort( painterSortStable );
  4252. // render all sprites
  4253. var scale = [];
  4254. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  4255. var sprite = sprites[ i ];
  4256. var material = sprite.material;
  4257. if ( material.visible === false ) continue;
  4258. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  4259. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  4260. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  4261. scale[ 0 ] = spriteScale.x;
  4262. scale[ 1 ] = spriteScale.y;
  4263. var fogType = 0;
  4264. if ( scene.fog && material.fog ) {
  4265. fogType = sceneFogType;
  4266. }
  4267. if ( oldFogType !== fogType ) {
  4268. gl.uniform1i( uniforms.fogType, fogType );
  4269. oldFogType = fogType;
  4270. }
  4271. if ( material.map !== null ) {
  4272. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  4273. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  4274. } else {
  4275. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  4276. gl.uniform2f( uniforms.uvScale, 1, 1 );
  4277. }
  4278. gl.uniform1f( uniforms.opacity, material.opacity );
  4279. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  4280. gl.uniform1f( uniforms.rotation, material.rotation );
  4281. gl.uniform2fv( uniforms.scale, scale );
  4282. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  4283. state.buffers.depth.setTest( material.depthTest );
  4284. state.buffers.depth.setMask( material.depthWrite );
  4285. if ( material.map ) {
  4286. renderer.setTexture2D( material.map, 0 );
  4287. } else {
  4288. renderer.setTexture2D( texture, 0 );
  4289. }
  4290. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  4291. }
  4292. // restore gl
  4293. state.enable( gl.CULL_FACE );
  4294. renderer.resetGLState();
  4295. };
  4296. function createProgram() {
  4297. var program = gl.createProgram();
  4298. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  4299. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  4300. gl.shaderSource( vertexShader, [
  4301. 'precision ' + renderer.getPrecision() + ' float;',
  4302. 'uniform mat4 modelViewMatrix;',
  4303. 'uniform mat4 projectionMatrix;',
  4304. 'uniform float rotation;',
  4305. 'uniform vec2 scale;',
  4306. 'uniform vec2 uvOffset;',
  4307. 'uniform vec2 uvScale;',
  4308. 'attribute vec2 position;',
  4309. 'attribute vec2 uv;',
  4310. 'varying vec2 vUV;',
  4311. 'void main() {',
  4312. 'vUV = uvOffset + uv * uvScale;',
  4313. 'vec2 alignedPosition = position * scale;',
  4314. 'vec2 rotatedPosition;',
  4315. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  4316. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  4317. 'vec4 finalPosition;',
  4318. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  4319. 'finalPosition.xy += rotatedPosition;',
  4320. 'finalPosition = projectionMatrix * finalPosition;',
  4321. 'gl_Position = finalPosition;',
  4322. '}'
  4323. ].join( '\n' ) );
  4324. gl.shaderSource( fragmentShader, [
  4325. 'precision ' + renderer.getPrecision() + ' float;',
  4326. 'uniform vec3 color;',
  4327. 'uniform sampler2D map;',
  4328. 'uniform float opacity;',
  4329. 'uniform int fogType;',
  4330. 'uniform vec3 fogColor;',
  4331. 'uniform float fogDensity;',
  4332. 'uniform float fogNear;',
  4333. 'uniform float fogFar;',
  4334. 'uniform float alphaTest;',
  4335. 'varying vec2 vUV;',
  4336. 'void main() {',
  4337. 'vec4 texture = texture2D( map, vUV );',
  4338. 'if ( texture.a < alphaTest ) discard;',
  4339. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  4340. 'if ( fogType > 0 ) {',
  4341. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  4342. 'float fogFactor = 0.0;',
  4343. 'if ( fogType == 1 ) {',
  4344. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  4345. '} else {',
  4346. 'const float LOG2 = 1.442695;',
  4347. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  4348. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  4349. '}',
  4350. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  4351. '}',
  4352. '}'
  4353. ].join( '\n' ) );
  4354. gl.compileShader( vertexShader );
  4355. gl.compileShader( fragmentShader );
  4356. gl.attachShader( program, vertexShader );
  4357. gl.attachShader( program, fragmentShader );
  4358. gl.linkProgram( program );
  4359. return program;
  4360. }
  4361. function painterSortStable( a, b ) {
  4362. if ( a.renderOrder !== b.renderOrder ) {
  4363. return a.renderOrder - b.renderOrder;
  4364. } else if ( a.z !== b.z ) {
  4365. return b.z - a.z;
  4366. } else {
  4367. return b.id - a.id;
  4368. }
  4369. }
  4370. }
  4371. /**
  4372. * @author mrdoob / http://mrdoob.com/
  4373. * @author alteredq / http://alteredqualia.com/
  4374. */
  4375. var materialId = 0;
  4376. function Material() {
  4377. Object.defineProperty( this, 'id', { value: materialId ++ } );
  4378. this.uuid = _Math.generateUUID();
  4379. this.name = '';
  4380. this.type = 'Material';
  4381. this.fog = true;
  4382. this.lights = true;
  4383. this.blending = NormalBlending;
  4384. this.side = FrontSide;
  4385. this.shading = SmoothShading; // THREE.FlatShading, THREE.SmoothShading
  4386. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  4387. this.opacity = 1;
  4388. this.transparent = false;
  4389. this.blendSrc = SrcAlphaFactor;
  4390. this.blendDst = OneMinusSrcAlphaFactor;
  4391. this.blendEquation = AddEquation;
  4392. this.blendSrcAlpha = null;
  4393. this.blendDstAlpha = null;
  4394. this.blendEquationAlpha = null;
  4395. this.depthFunc = LessEqualDepth;
  4396. this.depthTest = true;
  4397. this.depthWrite = true;
  4398. this.clippingPlanes = null;
  4399. this.clipIntersection = false;
  4400. this.clipShadows = false;
  4401. this.colorWrite = true;
  4402. this.precision = null; // override the renderer's default precision for this material
  4403. this.polygonOffset = false;
  4404. this.polygonOffsetFactor = 0;
  4405. this.polygonOffsetUnits = 0;
  4406. this.dithering = false;
  4407. this.alphaTest = 0;
  4408. this.premultipliedAlpha = false;
  4409. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  4410. this.visible = true;
  4411. this.needsUpdate = true;
  4412. }
  4413. Object.assign( Material.prototype, EventDispatcher.prototype, {
  4414. isMaterial: true,
  4415. setValues: function ( values ) {
  4416. if ( values === undefined ) return;
  4417. for ( var key in values ) {
  4418. var newValue = values[ key ];
  4419. if ( newValue === undefined ) {
  4420. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  4421. continue;
  4422. }
  4423. var currentValue = this[ key ];
  4424. if ( currentValue === undefined ) {
  4425. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  4426. continue;
  4427. }
  4428. if ( currentValue && currentValue.isColor ) {
  4429. currentValue.set( newValue );
  4430. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  4431. currentValue.copy( newValue );
  4432. } else if ( key === 'overdraw' ) {
  4433. // ensure overdraw is backwards-compatible with legacy boolean type
  4434. this[ key ] = Number( newValue );
  4435. } else {
  4436. this[ key ] = newValue;
  4437. }
  4438. }
  4439. },
  4440. toJSON: function ( meta ) {
  4441. var isRoot = meta === undefined;
  4442. if ( isRoot ) {
  4443. meta = {
  4444. textures: {},
  4445. images: {}
  4446. };
  4447. }
  4448. var data = {
  4449. metadata: {
  4450. version: 4.5,
  4451. type: 'Material',
  4452. generator: 'Material.toJSON'
  4453. }
  4454. };
  4455. // standard Material serialization
  4456. data.uuid = this.uuid;
  4457. data.type = this.type;
  4458. if ( this.name !== '' ) data.name = this.name;
  4459. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  4460. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  4461. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  4462. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  4463. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  4464. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  4465. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  4466. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  4467. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  4468. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  4469. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  4470. if ( this.bumpMap && this.bumpMap.isTexture ) {
  4471. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  4472. data.bumpScale = this.bumpScale;
  4473. }
  4474. if ( this.normalMap && this.normalMap.isTexture ) {
  4475. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  4476. data.normalScale = this.normalScale.toArray();
  4477. }
  4478. if ( this.displacementMap && this.displacementMap.isTexture ) {
  4479. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  4480. data.displacementScale = this.displacementScale;
  4481. data.displacementBias = this.displacementBias;
  4482. }
  4483. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  4484. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  4485. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  4486. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  4487. if ( this.envMap && this.envMap.isTexture ) {
  4488. data.envMap = this.envMap.toJSON( meta ).uuid;
  4489. data.reflectivity = this.reflectivity; // Scale behind envMap
  4490. }
  4491. if ( this.gradientMap && this.gradientMap.isTexture ) {
  4492. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  4493. }
  4494. if ( this.size !== undefined ) data.size = this.size;
  4495. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  4496. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  4497. if ( this.shading !== SmoothShading ) data.shading = this.shading;
  4498. if ( this.side !== FrontSide ) data.side = this.side;
  4499. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  4500. if ( this.opacity < 1 ) data.opacity = this.opacity;
  4501. if ( this.transparent === true ) data.transparent = this.transparent;
  4502. data.depthFunc = this.depthFunc;
  4503. data.depthTest = this.depthTest;
  4504. data.depthWrite = this.depthWrite;
  4505. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  4506. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  4507. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  4508. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  4509. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  4510. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  4511. data.skinning = this.skinning;
  4512. data.morphTargets = this.morphTargets;
  4513. data.dithering = this.dithering;
  4514. // TODO: Copied from Object3D.toJSON
  4515. function extractFromCache( cache ) {
  4516. var values = [];
  4517. for ( var key in cache ) {
  4518. var data = cache[ key ];
  4519. delete data.metadata;
  4520. values.push( data );
  4521. }
  4522. return values;
  4523. }
  4524. if ( isRoot ) {
  4525. var textures = extractFromCache( meta.textures );
  4526. var images = extractFromCache( meta.images );
  4527. if ( textures.length > 0 ) data.textures = textures;
  4528. if ( images.length > 0 ) data.images = images;
  4529. }
  4530. return data;
  4531. },
  4532. clone: function () {
  4533. return new this.constructor().copy( this );
  4534. },
  4535. copy: function ( source ) {
  4536. this.name = source.name;
  4537. this.fog = source.fog;
  4538. this.lights = source.lights;
  4539. this.blending = source.blending;
  4540. this.side = source.side;
  4541. this.shading = source.shading;
  4542. this.vertexColors = source.vertexColors;
  4543. this.opacity = source.opacity;
  4544. this.transparent = source.transparent;
  4545. this.blendSrc = source.blendSrc;
  4546. this.blendDst = source.blendDst;
  4547. this.blendEquation = source.blendEquation;
  4548. this.blendSrcAlpha = source.blendSrcAlpha;
  4549. this.blendDstAlpha = source.blendDstAlpha;
  4550. this.blendEquationAlpha = source.blendEquationAlpha;
  4551. this.depthFunc = source.depthFunc;
  4552. this.depthTest = source.depthTest;
  4553. this.depthWrite = source.depthWrite;
  4554. this.colorWrite = source.colorWrite;
  4555. this.precision = source.precision;
  4556. this.polygonOffset = source.polygonOffset;
  4557. this.polygonOffsetFactor = source.polygonOffsetFactor;
  4558. this.polygonOffsetUnits = source.polygonOffsetUnits;
  4559. this.dithering = source.dithering;
  4560. this.alphaTest = source.alphaTest;
  4561. this.premultipliedAlpha = source.premultipliedAlpha;
  4562. this.overdraw = source.overdraw;
  4563. this.visible = source.visible;
  4564. this.clipShadows = source.clipShadows;
  4565. this.clipIntersection = source.clipIntersection;
  4566. var srcPlanes = source.clippingPlanes,
  4567. dstPlanes = null;
  4568. if ( srcPlanes !== null ) {
  4569. var n = srcPlanes.length;
  4570. dstPlanes = new Array( n );
  4571. for ( var i = 0; i !== n; ++ i )
  4572. dstPlanes[ i ] = srcPlanes[ i ].clone();
  4573. }
  4574. this.clippingPlanes = dstPlanes;
  4575. return this;
  4576. },
  4577. dispose: function () {
  4578. this.dispatchEvent( { type: 'dispose' } );
  4579. }
  4580. } );
  4581. /**
  4582. * @author alteredq / http://alteredqualia.com/
  4583. *
  4584. * parameters = {
  4585. * defines: { "label" : "value" },
  4586. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  4587. *
  4588. * fragmentShader: <string>,
  4589. * vertexShader: <string>,
  4590. *
  4591. * wireframe: <boolean>,
  4592. * wireframeLinewidth: <float>,
  4593. *
  4594. * lights: <bool>,
  4595. *
  4596. * skinning: <bool>,
  4597. * morphTargets: <bool>,
  4598. * morphNormals: <bool>
  4599. * }
  4600. */
  4601. function ShaderMaterial( parameters ) {
  4602. Material.call( this );
  4603. this.type = 'ShaderMaterial';
  4604. this.defines = {};
  4605. this.uniforms = {};
  4606. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  4607. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  4608. this.linewidth = 1;
  4609. this.wireframe = false;
  4610. this.wireframeLinewidth = 1;
  4611. this.fog = false; // set to use scene fog
  4612. this.lights = false; // set to use scene lights
  4613. this.clipping = false; // set to use user-defined clipping planes
  4614. this.skinning = false; // set to use skinning attribute streams
  4615. this.morphTargets = false; // set to use morph targets
  4616. this.morphNormals = false; // set to use morph normals
  4617. this.extensions = {
  4618. derivatives: false, // set to use derivatives
  4619. fragDepth: false, // set to use fragment depth values
  4620. drawBuffers: false, // set to use draw buffers
  4621. shaderTextureLOD: false // set to use shader texture LOD
  4622. };
  4623. // When rendered geometry doesn't include these attributes but the material does,
  4624. // use these default values in WebGL. This avoids errors when buffer data is missing.
  4625. this.defaultAttributeValues = {
  4626. 'color': [ 1, 1, 1 ],
  4627. 'uv': [ 0, 0 ],
  4628. 'uv2': [ 0, 0 ]
  4629. };
  4630. this.index0AttributeName = undefined;
  4631. if ( parameters !== undefined ) {
  4632. if ( parameters.attributes !== undefined ) {
  4633. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  4634. }
  4635. this.setValues( parameters );
  4636. }
  4637. }
  4638. ShaderMaterial.prototype = Object.create( Material.prototype );
  4639. ShaderMaterial.prototype.constructor = ShaderMaterial;
  4640. ShaderMaterial.prototype.isShaderMaterial = true;
  4641. ShaderMaterial.prototype.copy = function ( source ) {
  4642. Material.prototype.copy.call( this, source );
  4643. this.fragmentShader = source.fragmentShader;
  4644. this.vertexShader = source.vertexShader;
  4645. this.uniforms = UniformsUtils.clone( source.uniforms );
  4646. this.defines = source.defines;
  4647. this.wireframe = source.wireframe;
  4648. this.wireframeLinewidth = source.wireframeLinewidth;
  4649. this.lights = source.lights;
  4650. this.clipping = source.clipping;
  4651. this.skinning = source.skinning;
  4652. this.morphTargets = source.morphTargets;
  4653. this.morphNormals = source.morphNormals;
  4654. this.extensions = source.extensions;
  4655. return this;
  4656. };
  4657. ShaderMaterial.prototype.toJSON = function ( meta ) {
  4658. var data = Material.prototype.toJSON.call( this, meta );
  4659. data.uniforms = this.uniforms;
  4660. data.vertexShader = this.vertexShader;
  4661. data.fragmentShader = this.fragmentShader;
  4662. return data;
  4663. };
  4664. /**
  4665. * @author mrdoob / http://mrdoob.com/
  4666. * @author alteredq / http://alteredqualia.com/
  4667. * @author bhouston / https://clara.io
  4668. * @author WestLangley / http://github.com/WestLangley
  4669. *
  4670. * parameters = {
  4671. *
  4672. * opacity: <float>,
  4673. *
  4674. * map: new THREE.Texture( <Image> ),
  4675. *
  4676. * alphaMap: new THREE.Texture( <Image> ),
  4677. *
  4678. * displacementMap: new THREE.Texture( <Image> ),
  4679. * displacementScale: <float>,
  4680. * displacementBias: <float>,
  4681. *
  4682. * wireframe: <boolean>,
  4683. * wireframeLinewidth: <float>
  4684. * }
  4685. */
  4686. function MeshDepthMaterial( parameters ) {
  4687. Material.call( this );
  4688. this.type = 'MeshDepthMaterial';
  4689. this.depthPacking = BasicDepthPacking;
  4690. this.skinning = false;
  4691. this.morphTargets = false;
  4692. this.map = null;
  4693. this.alphaMap = null;
  4694. this.displacementMap = null;
  4695. this.displacementScale = 1;
  4696. this.displacementBias = 0;
  4697. this.wireframe = false;
  4698. this.wireframeLinewidth = 1;
  4699. this.fog = false;
  4700. this.lights = false;
  4701. this.setValues( parameters );
  4702. }
  4703. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  4704. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  4705. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  4706. MeshDepthMaterial.prototype.copy = function ( source ) {
  4707. Material.prototype.copy.call( this, source );
  4708. this.depthPacking = source.depthPacking;
  4709. this.skinning = source.skinning;
  4710. this.morphTargets = source.morphTargets;
  4711. this.map = source.map;
  4712. this.alphaMap = source.alphaMap;
  4713. this.displacementMap = source.displacementMap;
  4714. this.displacementScale = source.displacementScale;
  4715. this.displacementBias = source.displacementBias;
  4716. this.wireframe = source.wireframe;
  4717. this.wireframeLinewidth = source.wireframeLinewidth;
  4718. return this;
  4719. };
  4720. /**
  4721. * @author bhouston / http://clara.io
  4722. * @author WestLangley / http://github.com/WestLangley
  4723. */
  4724. function Box3( min, max ) {
  4725. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  4726. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  4727. }
  4728. Object.assign( Box3.prototype, {
  4729. isBox3: true,
  4730. set: function ( min, max ) {
  4731. this.min.copy( min );
  4732. this.max.copy( max );
  4733. return this;
  4734. },
  4735. setFromArray: function ( array ) {
  4736. var minX = + Infinity;
  4737. var minY = + Infinity;
  4738. var minZ = + Infinity;
  4739. var maxX = - Infinity;
  4740. var maxY = - Infinity;
  4741. var maxZ = - Infinity;
  4742. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  4743. var x = array[ i ];
  4744. var y = array[ i + 1 ];
  4745. var z = array[ i + 2 ];
  4746. if ( x < minX ) minX = x;
  4747. if ( y < minY ) minY = y;
  4748. if ( z < minZ ) minZ = z;
  4749. if ( x > maxX ) maxX = x;
  4750. if ( y > maxY ) maxY = y;
  4751. if ( z > maxZ ) maxZ = z;
  4752. }
  4753. this.min.set( minX, minY, minZ );
  4754. this.max.set( maxX, maxY, maxZ );
  4755. return this;
  4756. },
  4757. setFromBufferAttribute: function ( attribute ) {
  4758. var minX = + Infinity;
  4759. var minY = + Infinity;
  4760. var minZ = + Infinity;
  4761. var maxX = - Infinity;
  4762. var maxY = - Infinity;
  4763. var maxZ = - Infinity;
  4764. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  4765. var x = attribute.getX( i );
  4766. var y = attribute.getY( i );
  4767. var z = attribute.getZ( i );
  4768. if ( x < minX ) minX = x;
  4769. if ( y < minY ) minY = y;
  4770. if ( z < minZ ) minZ = z;
  4771. if ( x > maxX ) maxX = x;
  4772. if ( y > maxY ) maxY = y;
  4773. if ( z > maxZ ) maxZ = z;
  4774. }
  4775. this.min.set( minX, minY, minZ );
  4776. this.max.set( maxX, maxY, maxZ );
  4777. return this;
  4778. },
  4779. setFromPoints: function ( points ) {
  4780. this.makeEmpty();
  4781. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4782. this.expandByPoint( points[ i ] );
  4783. }
  4784. return this;
  4785. },
  4786. setFromCenterAndSize: function () {
  4787. var v1 = new Vector3();
  4788. return function setFromCenterAndSize( center, size ) {
  4789. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  4790. this.min.copy( center ).sub( halfSize );
  4791. this.max.copy( center ).add( halfSize );
  4792. return this;
  4793. };
  4794. }(),
  4795. setFromObject: function ( object ) {
  4796. this.makeEmpty();
  4797. return this.expandByObject( object );
  4798. },
  4799. clone: function () {
  4800. return new this.constructor().copy( this );
  4801. },
  4802. copy: function ( box ) {
  4803. this.min.copy( box.min );
  4804. this.max.copy( box.max );
  4805. return this;
  4806. },
  4807. makeEmpty: function () {
  4808. this.min.x = this.min.y = this.min.z = + Infinity;
  4809. this.max.x = this.max.y = this.max.z = - Infinity;
  4810. return this;
  4811. },
  4812. isEmpty: function () {
  4813. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  4814. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  4815. },
  4816. getCenter: function ( optionalTarget ) {
  4817. var result = optionalTarget || new Vector3();
  4818. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  4819. },
  4820. getSize: function ( optionalTarget ) {
  4821. var result = optionalTarget || new Vector3();
  4822. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.subVectors( this.max, this.min );
  4823. },
  4824. expandByPoint: function ( point ) {
  4825. this.min.min( point );
  4826. this.max.max( point );
  4827. return this;
  4828. },
  4829. expandByVector: function ( vector ) {
  4830. this.min.sub( vector );
  4831. this.max.add( vector );
  4832. return this;
  4833. },
  4834. expandByScalar: function ( scalar ) {
  4835. this.min.addScalar( - scalar );
  4836. this.max.addScalar( scalar );
  4837. return this;
  4838. },
  4839. expandByObject: function () {
  4840. // Computes the world-axis-aligned bounding box of an object (including its children),
  4841. // accounting for both the object's, and children's, world transforms
  4842. var v1 = new Vector3();
  4843. return function expandByObject( object ) {
  4844. var scope = this;
  4845. object.updateMatrixWorld( true );
  4846. object.traverse( function ( node ) {
  4847. var i, l;
  4848. var geometry = node.geometry;
  4849. if ( geometry !== undefined ) {
  4850. if ( geometry.isGeometry ) {
  4851. var vertices = geometry.vertices;
  4852. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  4853. v1.copy( vertices[ i ] );
  4854. v1.applyMatrix4( node.matrixWorld );
  4855. scope.expandByPoint( v1 );
  4856. }
  4857. } else if ( geometry.isBufferGeometry ) {
  4858. var attribute = geometry.attributes.position;
  4859. if ( attribute !== undefined ) {
  4860. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  4861. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  4862. scope.expandByPoint( v1 );
  4863. }
  4864. }
  4865. }
  4866. }
  4867. } );
  4868. return this;
  4869. };
  4870. }(),
  4871. containsPoint: function ( point ) {
  4872. return point.x < this.min.x || point.x > this.max.x ||
  4873. point.y < this.min.y || point.y > this.max.y ||
  4874. point.z < this.min.z || point.z > this.max.z ? false : true;
  4875. },
  4876. containsBox: function ( box ) {
  4877. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  4878. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  4879. this.min.z <= box.min.z && box.max.z <= this.max.z;
  4880. },
  4881. getParameter: function ( point, optionalTarget ) {
  4882. // This can potentially have a divide by zero if the box
  4883. // has a size dimension of 0.
  4884. var result = optionalTarget || new Vector3();
  4885. return result.set(
  4886. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  4887. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  4888. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  4889. );
  4890. },
  4891. intersectsBox: function ( box ) {
  4892. // using 6 splitting planes to rule out intersections.
  4893. return box.max.x < this.min.x || box.min.x > this.max.x ||
  4894. box.max.y < this.min.y || box.min.y > this.max.y ||
  4895. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  4896. },
  4897. intersectsSphere: ( function () {
  4898. var closestPoint = new Vector3();
  4899. return function intersectsSphere( sphere ) {
  4900. // Find the point on the AABB closest to the sphere center.
  4901. this.clampPoint( sphere.center, closestPoint );
  4902. // If that point is inside the sphere, the AABB and sphere intersect.
  4903. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  4904. };
  4905. } )(),
  4906. intersectsPlane: function ( plane ) {
  4907. // We compute the minimum and maximum dot product values. If those values
  4908. // are on the same side (back or front) of the plane, then there is no intersection.
  4909. var min, max;
  4910. if ( plane.normal.x > 0 ) {
  4911. min = plane.normal.x * this.min.x;
  4912. max = plane.normal.x * this.max.x;
  4913. } else {
  4914. min = plane.normal.x * this.max.x;
  4915. max = plane.normal.x * this.min.x;
  4916. }
  4917. if ( plane.normal.y > 0 ) {
  4918. min += plane.normal.y * this.min.y;
  4919. max += plane.normal.y * this.max.y;
  4920. } else {
  4921. min += plane.normal.y * this.max.y;
  4922. max += plane.normal.y * this.min.y;
  4923. }
  4924. if ( plane.normal.z > 0 ) {
  4925. min += plane.normal.z * this.min.z;
  4926. max += plane.normal.z * this.max.z;
  4927. } else {
  4928. min += plane.normal.z * this.max.z;
  4929. max += plane.normal.z * this.min.z;
  4930. }
  4931. return ( min <= plane.constant && max >= plane.constant );
  4932. },
  4933. clampPoint: function ( point, optionalTarget ) {
  4934. var result = optionalTarget || new Vector3();
  4935. return result.copy( point ).clamp( this.min, this.max );
  4936. },
  4937. distanceToPoint: function () {
  4938. var v1 = new Vector3();
  4939. return function distanceToPoint( point ) {
  4940. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  4941. return clampedPoint.sub( point ).length();
  4942. };
  4943. }(),
  4944. getBoundingSphere: function () {
  4945. var v1 = new Vector3();
  4946. return function getBoundingSphere( optionalTarget ) {
  4947. var result = optionalTarget || new Sphere();
  4948. this.getCenter( result.center );
  4949. result.radius = this.getSize( v1 ).length() * 0.5;
  4950. return result;
  4951. };
  4952. }(),
  4953. intersect: function ( box ) {
  4954. this.min.max( box.min );
  4955. this.max.min( box.max );
  4956. // 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.
  4957. if( this.isEmpty() ) this.makeEmpty();
  4958. return this;
  4959. },
  4960. union: function ( box ) {
  4961. this.min.min( box.min );
  4962. this.max.max( box.max );
  4963. return this;
  4964. },
  4965. applyMatrix4: function () {
  4966. var points = [
  4967. new Vector3(),
  4968. new Vector3(),
  4969. new Vector3(),
  4970. new Vector3(),
  4971. new Vector3(),
  4972. new Vector3(),
  4973. new Vector3(),
  4974. new Vector3()
  4975. ];
  4976. return function applyMatrix4( matrix ) {
  4977. // transform of empty box is an empty box.
  4978. if( this.isEmpty() ) return this;
  4979. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4980. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4981. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4982. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4983. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4984. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4985. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4986. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4987. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4988. this.setFromPoints( points );
  4989. return this;
  4990. };
  4991. }(),
  4992. translate: function ( offset ) {
  4993. this.min.add( offset );
  4994. this.max.add( offset );
  4995. return this;
  4996. },
  4997. equals: function ( box ) {
  4998. return box.min.equals( this.min ) && box.max.equals( this.max );
  4999. }
  5000. } );
  5001. /**
  5002. * @author bhouston / http://clara.io
  5003. * @author mrdoob / http://mrdoob.com/
  5004. */
  5005. function Sphere( center, radius ) {
  5006. this.center = ( center !== undefined ) ? center : new Vector3();
  5007. this.radius = ( radius !== undefined ) ? radius : 0;
  5008. }
  5009. Object.assign( Sphere.prototype, {
  5010. set: function ( center, radius ) {
  5011. this.center.copy( center );
  5012. this.radius = radius;
  5013. return this;
  5014. },
  5015. setFromPoints: function () {
  5016. var box = new Box3();
  5017. return function setFromPoints( points, optionalCenter ) {
  5018. var center = this.center;
  5019. if ( optionalCenter !== undefined ) {
  5020. center.copy( optionalCenter );
  5021. } else {
  5022. box.setFromPoints( points ).getCenter( center );
  5023. }
  5024. var maxRadiusSq = 0;
  5025. for ( var i = 0, il = points.length; i < il; i ++ ) {
  5026. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  5027. }
  5028. this.radius = Math.sqrt( maxRadiusSq );
  5029. return this;
  5030. };
  5031. }(),
  5032. clone: function () {
  5033. return new this.constructor().copy( this );
  5034. },
  5035. copy: function ( sphere ) {
  5036. this.center.copy( sphere.center );
  5037. this.radius = sphere.radius;
  5038. return this;
  5039. },
  5040. empty: function () {
  5041. return ( this.radius <= 0 );
  5042. },
  5043. containsPoint: function ( point ) {
  5044. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  5045. },
  5046. distanceToPoint: function ( point ) {
  5047. return ( point.distanceTo( this.center ) - this.radius );
  5048. },
  5049. intersectsSphere: function ( sphere ) {
  5050. var radiusSum = this.radius + sphere.radius;
  5051. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  5052. },
  5053. intersectsBox: function ( box ) {
  5054. return box.intersectsSphere( this );
  5055. },
  5056. intersectsPlane: function ( plane ) {
  5057. // We use the following equation to compute the signed distance from
  5058. // the center of the sphere to the plane.
  5059. //
  5060. // distance = q * n - d
  5061. //
  5062. // If this distance is greater than the radius of the sphere,
  5063. // then there is no intersection.
  5064. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  5065. },
  5066. clampPoint: function ( point, optionalTarget ) {
  5067. var deltaLengthSq = this.center.distanceToSquared( point );
  5068. var result = optionalTarget || new Vector3();
  5069. result.copy( point );
  5070. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  5071. result.sub( this.center ).normalize();
  5072. result.multiplyScalar( this.radius ).add( this.center );
  5073. }
  5074. return result;
  5075. },
  5076. getBoundingBox: function ( optionalTarget ) {
  5077. var box = optionalTarget || new Box3();
  5078. box.set( this.center, this.center );
  5079. box.expandByScalar( this.radius );
  5080. return box;
  5081. },
  5082. applyMatrix4: function ( matrix ) {
  5083. this.center.applyMatrix4( matrix );
  5084. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  5085. return this;
  5086. },
  5087. translate: function ( offset ) {
  5088. this.center.add( offset );
  5089. return this;
  5090. },
  5091. equals: function ( sphere ) {
  5092. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  5093. }
  5094. } );
  5095. /**
  5096. * @author alteredq / http://alteredqualia.com/
  5097. * @author WestLangley / http://github.com/WestLangley
  5098. * @author bhouston / http://clara.io
  5099. * @author tschw
  5100. */
  5101. function Matrix3() {
  5102. this.elements = [
  5103. 1, 0, 0,
  5104. 0, 1, 0,
  5105. 0, 0, 1
  5106. ];
  5107. if ( arguments.length > 0 ) {
  5108. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  5109. }
  5110. }
  5111. Object.assign( Matrix3.prototype, {
  5112. isMatrix3: true,
  5113. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  5114. var te = this.elements;
  5115. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  5116. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  5117. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  5118. return this;
  5119. },
  5120. identity: function () {
  5121. this.set(
  5122. 1, 0, 0,
  5123. 0, 1, 0,
  5124. 0, 0, 1
  5125. );
  5126. return this;
  5127. },
  5128. clone: function () {
  5129. return new this.constructor().fromArray( this.elements );
  5130. },
  5131. copy: function ( m ) {
  5132. var te = this.elements;
  5133. var me = m.elements;
  5134. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  5135. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  5136. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  5137. return this;
  5138. },
  5139. setFromMatrix4: function ( m ) {
  5140. var me = m.elements;
  5141. this.set(
  5142. me[ 0 ], me[ 4 ], me[ 8 ],
  5143. me[ 1 ], me[ 5 ], me[ 9 ],
  5144. me[ 2 ], me[ 6 ], me[ 10 ]
  5145. );
  5146. return this;
  5147. },
  5148. applyToBufferAttribute: function () {
  5149. var v1 = new Vector3();
  5150. return function applyToBufferAttribute( attribute ) {
  5151. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  5152. v1.x = attribute.getX( i );
  5153. v1.y = attribute.getY( i );
  5154. v1.z = attribute.getZ( i );
  5155. v1.applyMatrix3( this );
  5156. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  5157. }
  5158. return attribute;
  5159. };
  5160. }(),
  5161. multiply: function ( m ) {
  5162. return this.multiplyMatrices( this, m );
  5163. },
  5164. premultiply: function ( m ) {
  5165. return this.multiplyMatrices( m, this );
  5166. },
  5167. multiplyMatrices: function ( a, b ) {
  5168. var ae = a.elements;
  5169. var be = b.elements;
  5170. var te = this.elements;
  5171. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  5172. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  5173. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  5174. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  5175. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  5176. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  5177. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  5178. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  5179. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  5180. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  5181. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  5182. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  5183. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  5184. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  5185. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  5186. return this;
  5187. },
  5188. multiplyScalar: function ( s ) {
  5189. var te = this.elements;
  5190. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  5191. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  5192. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  5193. return this;
  5194. },
  5195. determinant: function () {
  5196. var te = this.elements;
  5197. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  5198. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  5199. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  5200. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  5201. },
  5202. getInverse: function ( matrix, throwOnDegenerate ) {
  5203. if ( matrix && matrix.isMatrix4 ) {
  5204. console.error( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  5205. }
  5206. var me = matrix.elements,
  5207. te = this.elements,
  5208. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  5209. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  5210. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  5211. t11 = n33 * n22 - n32 * n23,
  5212. t12 = n32 * n13 - n33 * n12,
  5213. t13 = n23 * n12 - n22 * n13,
  5214. det = n11 * t11 + n21 * t12 + n31 * t13;
  5215. if ( det === 0 ) {
  5216. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  5217. if ( throwOnDegenerate === true ) {
  5218. throw new Error( msg );
  5219. } else {
  5220. console.warn( msg );
  5221. }
  5222. return this.identity();
  5223. }
  5224. var detInv = 1 / det;
  5225. te[ 0 ] = t11 * detInv;
  5226. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  5227. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  5228. te[ 3 ] = t12 * detInv;
  5229. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  5230. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  5231. te[ 6 ] = t13 * detInv;
  5232. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  5233. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  5234. return this;
  5235. },
  5236. transpose: function () {
  5237. var tmp, m = this.elements;
  5238. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  5239. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  5240. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  5241. return this;
  5242. },
  5243. getNormalMatrix: function ( matrix4 ) {
  5244. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  5245. },
  5246. transposeIntoArray: function ( r ) {
  5247. var m = this.elements;
  5248. r[ 0 ] = m[ 0 ];
  5249. r[ 1 ] = m[ 3 ];
  5250. r[ 2 ] = m[ 6 ];
  5251. r[ 3 ] = m[ 1 ];
  5252. r[ 4 ] = m[ 4 ];
  5253. r[ 5 ] = m[ 7 ];
  5254. r[ 6 ] = m[ 2 ];
  5255. r[ 7 ] = m[ 5 ];
  5256. r[ 8 ] = m[ 8 ];
  5257. return this;
  5258. },
  5259. equals: function ( matrix ) {
  5260. var te = this.elements;
  5261. var me = matrix.elements;
  5262. for ( var i = 0; i < 9; i ++ ) {
  5263. if ( te[ i ] !== me[ i ] ) return false;
  5264. }
  5265. return true;
  5266. },
  5267. fromArray: function ( array, offset ) {
  5268. if ( offset === undefined ) offset = 0;
  5269. for ( var i = 0; i < 9; i ++ ) {
  5270. this.elements[ i ] = array[ i + offset ];
  5271. }
  5272. return this;
  5273. },
  5274. toArray: function ( array, offset ) {
  5275. if ( array === undefined ) array = [];
  5276. if ( offset === undefined ) offset = 0;
  5277. var te = this.elements;
  5278. array[ offset ] = te[ 0 ];
  5279. array[ offset + 1 ] = te[ 1 ];
  5280. array[ offset + 2 ] = te[ 2 ];
  5281. array[ offset + 3 ] = te[ 3 ];
  5282. array[ offset + 4 ] = te[ 4 ];
  5283. array[ offset + 5 ] = te[ 5 ];
  5284. array[ offset + 6 ] = te[ 6 ];
  5285. array[ offset + 7 ] = te[ 7 ];
  5286. array[ offset + 8 ] = te[ 8 ];
  5287. return array;
  5288. }
  5289. } );
  5290. /**
  5291. * @author bhouston / http://clara.io
  5292. */
  5293. function Plane( normal, constant ) {
  5294. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  5295. this.constant = ( constant !== undefined ) ? constant : 0;
  5296. }
  5297. Object.assign( Plane.prototype, {
  5298. set: function ( normal, constant ) {
  5299. this.normal.copy( normal );
  5300. this.constant = constant;
  5301. return this;
  5302. },
  5303. setComponents: function ( x, y, z, w ) {
  5304. this.normal.set( x, y, z );
  5305. this.constant = w;
  5306. return this;
  5307. },
  5308. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  5309. this.normal.copy( normal );
  5310. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  5311. return this;
  5312. },
  5313. setFromCoplanarPoints: function () {
  5314. var v1 = new Vector3();
  5315. var v2 = new Vector3();
  5316. return function setFromCoplanarPoints( a, b, c ) {
  5317. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  5318. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  5319. this.setFromNormalAndCoplanarPoint( normal, a );
  5320. return this;
  5321. };
  5322. }(),
  5323. clone: function () {
  5324. return new this.constructor().copy( this );
  5325. },
  5326. copy: function ( plane ) {
  5327. this.normal.copy( plane.normal );
  5328. this.constant = plane.constant;
  5329. return this;
  5330. },
  5331. normalize: function () {
  5332. // Note: will lead to a divide by zero if the plane is invalid.
  5333. var inverseNormalLength = 1.0 / this.normal.length();
  5334. this.normal.multiplyScalar( inverseNormalLength );
  5335. this.constant *= inverseNormalLength;
  5336. return this;
  5337. },
  5338. negate: function () {
  5339. this.constant *= - 1;
  5340. this.normal.negate();
  5341. return this;
  5342. },
  5343. distanceToPoint: function ( point ) {
  5344. return this.normal.dot( point ) + this.constant;
  5345. },
  5346. distanceToSphere: function ( sphere ) {
  5347. return this.distanceToPoint( sphere.center ) - sphere.radius;
  5348. },
  5349. projectPoint: function ( point, optionalTarget ) {
  5350. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  5351. },
  5352. orthoPoint: function ( point, optionalTarget ) {
  5353. var perpendicularMagnitude = this.distanceToPoint( point );
  5354. var result = optionalTarget || new Vector3();
  5355. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  5356. },
  5357. intersectLine: function () {
  5358. var v1 = new Vector3();
  5359. return function intersectLine( line, optionalTarget ) {
  5360. var result = optionalTarget || new Vector3();
  5361. var direction = line.delta( v1 );
  5362. var denominator = this.normal.dot( direction );
  5363. if ( denominator === 0 ) {
  5364. // line is coplanar, return origin
  5365. if ( this.distanceToPoint( line.start ) === 0 ) {
  5366. return result.copy( line.start );
  5367. }
  5368. // Unsure if this is the correct method to handle this case.
  5369. return undefined;
  5370. }
  5371. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  5372. if ( t < 0 || t > 1 ) {
  5373. return undefined;
  5374. }
  5375. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  5376. };
  5377. }(),
  5378. intersectsLine: function ( line ) {
  5379. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5380. var startSign = this.distanceToPoint( line.start );
  5381. var endSign = this.distanceToPoint( line.end );
  5382. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  5383. },
  5384. intersectsBox: function ( box ) {
  5385. return box.intersectsPlane( this );
  5386. },
  5387. intersectsSphere: function ( sphere ) {
  5388. return sphere.intersectsPlane( this );
  5389. },
  5390. coplanarPoint: function ( optionalTarget ) {
  5391. var result = optionalTarget || new Vector3();
  5392. return result.copy( this.normal ).multiplyScalar( - this.constant );
  5393. },
  5394. applyMatrix4: function () {
  5395. var v1 = new Vector3();
  5396. var m1 = new Matrix3();
  5397. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  5398. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  5399. // transform normal based on theory here:
  5400. // http://www.songho.ca/opengl/gl_normaltransform.html
  5401. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  5402. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  5403. // recalculate constant (like in setFromNormalAndCoplanarPoint)
  5404. this.constant = - referencePoint.dot( normal );
  5405. return this;
  5406. };
  5407. }(),
  5408. translate: function ( offset ) {
  5409. this.constant = this.constant - offset.dot( this.normal );
  5410. return this;
  5411. },
  5412. equals: function ( plane ) {
  5413. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  5414. }
  5415. } );
  5416. /**
  5417. * @author mrdoob / http://mrdoob.com/
  5418. * @author alteredq / http://alteredqualia.com/
  5419. * @author bhouston / http://clara.io
  5420. */
  5421. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  5422. this.planes = [
  5423. ( p0 !== undefined ) ? p0 : new Plane(),
  5424. ( p1 !== undefined ) ? p1 : new Plane(),
  5425. ( p2 !== undefined ) ? p2 : new Plane(),
  5426. ( p3 !== undefined ) ? p3 : new Plane(),
  5427. ( p4 !== undefined ) ? p4 : new Plane(),
  5428. ( p5 !== undefined ) ? p5 : new Plane()
  5429. ];
  5430. }
  5431. Object.assign( Frustum.prototype, {
  5432. set: function ( p0, p1, p2, p3, p4, p5 ) {
  5433. var planes = this.planes;
  5434. planes[ 0 ].copy( p0 );
  5435. planes[ 1 ].copy( p1 );
  5436. planes[ 2 ].copy( p2 );
  5437. planes[ 3 ].copy( p3 );
  5438. planes[ 4 ].copy( p4 );
  5439. planes[ 5 ].copy( p5 );
  5440. return this;
  5441. },
  5442. clone: function () {
  5443. return new this.constructor().copy( this );
  5444. },
  5445. copy: function ( frustum ) {
  5446. var planes = this.planes;
  5447. for ( var i = 0; i < 6; i ++ ) {
  5448. planes[ i ].copy( frustum.planes[ i ] );
  5449. }
  5450. return this;
  5451. },
  5452. setFromMatrix: function ( m ) {
  5453. var planes = this.planes;
  5454. var me = m.elements;
  5455. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  5456. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  5457. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  5458. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  5459. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  5460. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  5461. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  5462. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  5463. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  5464. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  5465. return this;
  5466. },
  5467. intersectsObject: function () {
  5468. var sphere = new Sphere();
  5469. return function intersectsObject( object ) {
  5470. var geometry = object.geometry;
  5471. if ( geometry.boundingSphere === null )
  5472. geometry.computeBoundingSphere();
  5473. sphere.copy( geometry.boundingSphere )
  5474. .applyMatrix4( object.matrixWorld );
  5475. return this.intersectsSphere( sphere );
  5476. };
  5477. }(),
  5478. intersectsSprite: function () {
  5479. var sphere = new Sphere();
  5480. return function intersectsSprite( sprite ) {
  5481. sphere.center.set( 0, 0, 0 );
  5482. sphere.radius = 0.7071067811865476;
  5483. sphere.applyMatrix4( sprite.matrixWorld );
  5484. return this.intersectsSphere( sphere );
  5485. };
  5486. }(),
  5487. intersectsSphere: function ( sphere ) {
  5488. var planes = this.planes;
  5489. var center = sphere.center;
  5490. var negRadius = - sphere.radius;
  5491. for ( var i = 0; i < 6; i ++ ) {
  5492. var distance = planes[ i ].distanceToPoint( center );
  5493. if ( distance < negRadius ) {
  5494. return false;
  5495. }
  5496. }
  5497. return true;
  5498. },
  5499. intersectsBox: function () {
  5500. var p1 = new Vector3(),
  5501. p2 = new Vector3();
  5502. return function intersectsBox( box ) {
  5503. var planes = this.planes;
  5504. for ( var i = 0; i < 6; i ++ ) {
  5505. var plane = planes[ i ];
  5506. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  5507. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  5508. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  5509. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  5510. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  5511. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  5512. var d1 = plane.distanceToPoint( p1 );
  5513. var d2 = plane.distanceToPoint( p2 );
  5514. // if both outside plane, no intersection
  5515. if ( d1 < 0 && d2 < 0 ) {
  5516. return false;
  5517. }
  5518. }
  5519. return true;
  5520. };
  5521. }(),
  5522. containsPoint: function ( point ) {
  5523. var planes = this.planes;
  5524. for ( var i = 0; i < 6; i ++ ) {
  5525. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  5526. return false;
  5527. }
  5528. }
  5529. return true;
  5530. }
  5531. } );
  5532. /**
  5533. * @author alteredq / http://alteredqualia.com/
  5534. * @author mrdoob / http://mrdoob.com/
  5535. */
  5536. function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
  5537. var _gl = _renderer.context,
  5538. _state = _renderer.state,
  5539. _frustum = new Frustum(),
  5540. _projScreenMatrix = new Matrix4(),
  5541. _lightShadows = _lights.shadows,
  5542. _shadowMapSize = new Vector2(),
  5543. _maxShadowMapSize = new Vector2( capabilities.maxTextureSize, capabilities.maxTextureSize ),
  5544. _lookTarget = new Vector3(),
  5545. _lightPositionWorld = new Vector3(),
  5546. _MorphingFlag = 1,
  5547. _SkinningFlag = 2,
  5548. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  5549. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  5550. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  5551. _materialCache = {};
  5552. var cubeDirections = [
  5553. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  5554. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  5555. ];
  5556. var cubeUps = [
  5557. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  5558. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  5559. ];
  5560. var cube2DViewPorts = [
  5561. new Vector4(), new Vector4(), new Vector4(),
  5562. new Vector4(), new Vector4(), new Vector4()
  5563. ];
  5564. // init
  5565. var depthMaterialTemplate = new MeshDepthMaterial();
  5566. depthMaterialTemplate.depthPacking = RGBADepthPacking;
  5567. depthMaterialTemplate.clipping = true;
  5568. var distanceShader = ShaderLib[ "distanceRGBA" ];
  5569. var distanceUniforms = UniformsUtils.clone( distanceShader.uniforms );
  5570. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  5571. var useMorphing = ( i & _MorphingFlag ) !== 0;
  5572. var useSkinning = ( i & _SkinningFlag ) !== 0;
  5573. var depthMaterial = depthMaterialTemplate.clone();
  5574. depthMaterial.morphTargets = useMorphing;
  5575. depthMaterial.skinning = useSkinning;
  5576. _depthMaterials[ i ] = depthMaterial;
  5577. var distanceMaterial = new ShaderMaterial( {
  5578. defines: {
  5579. 'USE_SHADOWMAP': ''
  5580. },
  5581. uniforms: distanceUniforms,
  5582. vertexShader: distanceShader.vertexShader,
  5583. fragmentShader: distanceShader.fragmentShader,
  5584. morphTargets: useMorphing,
  5585. skinning: useSkinning,
  5586. clipping: true
  5587. } );
  5588. _distanceMaterials[ i ] = distanceMaterial;
  5589. }
  5590. //
  5591. var scope = this;
  5592. this.enabled = false;
  5593. this.autoUpdate = true;
  5594. this.needsUpdate = false;
  5595. this.type = PCFShadowMap;
  5596. this.renderReverseSided = true;
  5597. this.renderSingleSided = true;
  5598. this.render = function ( scene, camera ) {
  5599. if ( scope.enabled === false ) return;
  5600. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  5601. if ( _lightShadows.length === 0 ) return;
  5602. // Set GL state for depth map.
  5603. _state.disable( _gl.BLEND );
  5604. _state.buffers.color.setClear( 1, 1, 1, 1 );
  5605. _state.buffers.depth.setTest( true );
  5606. _state.setScissorTest( false );
  5607. // render depth map
  5608. var faceCount;
  5609. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  5610. var light = _lightShadows[ i ];
  5611. var shadow = light.shadow;
  5612. var isPointLight = light && light.isPointLight;
  5613. if ( shadow === undefined ) {
  5614. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  5615. continue;
  5616. }
  5617. var shadowCamera = shadow.camera;
  5618. _shadowMapSize.copy( shadow.mapSize );
  5619. _shadowMapSize.min( _maxShadowMapSize );
  5620. if ( isPointLight ) {
  5621. var vpWidth = _shadowMapSize.x;
  5622. var vpHeight = _shadowMapSize.y;
  5623. // These viewports map a cube-map onto a 2D texture with the
  5624. // following orientation:
  5625. //
  5626. // xzXZ
  5627. // y Y
  5628. //
  5629. // X - Positive x direction
  5630. // x - Negative x direction
  5631. // Y - Positive y direction
  5632. // y - Negative y direction
  5633. // Z - Positive z direction
  5634. // z - Negative z direction
  5635. // positive X
  5636. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  5637. // negative X
  5638. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  5639. // positive Z
  5640. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  5641. // negative Z
  5642. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  5643. // positive Y
  5644. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  5645. // negative Y
  5646. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  5647. _shadowMapSize.x *= 4.0;
  5648. _shadowMapSize.y *= 2.0;
  5649. }
  5650. if ( shadow.map === null ) {
  5651. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  5652. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  5653. shadow.map.texture.name = light.name + ".shadowMap";
  5654. shadowCamera.updateProjectionMatrix();
  5655. }
  5656. if ( shadow.isSpotLightShadow ) {
  5657. shadow.update( light );
  5658. }
  5659. var shadowMap = shadow.map;
  5660. var shadowMatrix = shadow.matrix;
  5661. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  5662. shadowCamera.position.copy( _lightPositionWorld );
  5663. if ( isPointLight ) {
  5664. faceCount = 6;
  5665. // for point lights we set the shadow matrix to be a translation-only matrix
  5666. // equal to inverse of the light's position
  5667. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  5668. } else {
  5669. faceCount = 1;
  5670. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  5671. shadowCamera.lookAt( _lookTarget );
  5672. shadowCamera.updateMatrixWorld();
  5673. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  5674. // compute shadow matrix
  5675. shadowMatrix.set(
  5676. 0.5, 0.0, 0.0, 0.5,
  5677. 0.0, 0.5, 0.0, 0.5,
  5678. 0.0, 0.0, 0.5, 0.5,
  5679. 0.0, 0.0, 0.0, 1.0
  5680. );
  5681. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  5682. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  5683. }
  5684. _renderer.setRenderTarget( shadowMap );
  5685. _renderer.clear();
  5686. // render shadow map for each cube face (if omni-directional) or
  5687. // run a single pass if not
  5688. for ( var face = 0; face < faceCount; face ++ ) {
  5689. if ( isPointLight ) {
  5690. _lookTarget.copy( shadowCamera.position );
  5691. _lookTarget.add( cubeDirections[ face ] );
  5692. shadowCamera.up.copy( cubeUps[ face ] );
  5693. shadowCamera.lookAt( _lookTarget );
  5694. shadowCamera.updateMatrixWorld();
  5695. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  5696. var vpDimensions = cube2DViewPorts[ face ];
  5697. _state.viewport( vpDimensions );
  5698. }
  5699. // update camera matrices and frustum
  5700. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  5701. _frustum.setFromMatrix( _projScreenMatrix );
  5702. // set object matrices & frustum culling
  5703. renderObject( scene, camera, shadowCamera, isPointLight );
  5704. }
  5705. }
  5706. // Restore GL state.
  5707. var clearColor = _renderer.getClearColor();
  5708. var clearAlpha = _renderer.getClearAlpha();
  5709. _renderer.setClearColor( clearColor, clearAlpha );
  5710. scope.needsUpdate = false;
  5711. };
  5712. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  5713. var geometry = object.geometry;
  5714. var result = null;
  5715. var materialVariants = _depthMaterials;
  5716. var customMaterial = object.customDepthMaterial;
  5717. if ( isPointLight ) {
  5718. materialVariants = _distanceMaterials;
  5719. customMaterial = object.customDistanceMaterial;
  5720. }
  5721. if ( ! customMaterial ) {
  5722. var useMorphing = false;
  5723. if ( material.morphTargets ) {
  5724. if ( geometry && geometry.isBufferGeometry ) {
  5725. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  5726. } else if ( geometry && geometry.isGeometry ) {
  5727. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  5728. }
  5729. }
  5730. if ( object.isSkinnedMesh && material.skinning === false ) {
  5731. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  5732. }
  5733. var useSkinning = object.isSkinnedMesh && material.skinning;
  5734. var variantIndex = 0;
  5735. if ( useMorphing ) variantIndex |= _MorphingFlag;
  5736. if ( useSkinning ) variantIndex |= _SkinningFlag;
  5737. result = materialVariants[ variantIndex ];
  5738. } else {
  5739. result = customMaterial;
  5740. }
  5741. if ( _renderer.localClippingEnabled &&
  5742. material.clipShadows === true &&
  5743. material.clippingPlanes.length !== 0 ) {
  5744. // in this case we need a unique material instance reflecting the
  5745. // appropriate state
  5746. var keyA = result.uuid, keyB = material.uuid;
  5747. var materialsForVariant = _materialCache[ keyA ];
  5748. if ( materialsForVariant === undefined ) {
  5749. materialsForVariant = {};
  5750. _materialCache[ keyA ] = materialsForVariant;
  5751. }
  5752. var cachedMaterial = materialsForVariant[ keyB ];
  5753. if ( cachedMaterial === undefined ) {
  5754. cachedMaterial = result.clone();
  5755. materialsForVariant[ keyB ] = cachedMaterial;
  5756. }
  5757. result = cachedMaterial;
  5758. }
  5759. result.visible = material.visible;
  5760. result.wireframe = material.wireframe;
  5761. var side = material.side;
  5762. if ( scope.renderSingleSided && side == DoubleSide ) {
  5763. side = FrontSide;
  5764. }
  5765. if ( scope.renderReverseSided ) {
  5766. if ( side === FrontSide ) side = BackSide;
  5767. else if ( side === BackSide ) side = FrontSide;
  5768. }
  5769. result.side = side;
  5770. result.clipShadows = material.clipShadows;
  5771. result.clippingPlanes = material.clippingPlanes;
  5772. result.wireframeLinewidth = material.wireframeLinewidth;
  5773. result.linewidth = material.linewidth;
  5774. if ( isPointLight && result.uniforms.lightPos !== undefined ) {
  5775. result.uniforms.lightPos.value.copy( lightPositionWorld );
  5776. }
  5777. return result;
  5778. }
  5779. function renderObject( object, camera, shadowCamera, isPointLight ) {
  5780. if ( object.visible === false ) return;
  5781. var visible = object.layers.test( camera.layers );
  5782. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  5783. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  5784. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  5785. var geometry = _objects.update( object );
  5786. var material = object.material;
  5787. if ( Array.isArray( material ) ) {
  5788. var groups = geometry.groups;
  5789. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  5790. var group = groups[ k ];
  5791. var groupMaterial = material[ group.materialIndex ];
  5792. if ( groupMaterial && groupMaterial.visible ) {
  5793. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  5794. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  5795. }
  5796. }
  5797. } else if ( material.visible ) {
  5798. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  5799. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  5800. }
  5801. }
  5802. }
  5803. var children = object.children;
  5804. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5805. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  5806. }
  5807. }
  5808. }
  5809. /**
  5810. * @author bhouston / http://clara.io
  5811. */
  5812. function Ray( origin, direction ) {
  5813. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  5814. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  5815. }
  5816. Object.assign( Ray.prototype, {
  5817. set: function ( origin, direction ) {
  5818. this.origin.copy( origin );
  5819. this.direction.copy( direction );
  5820. return this;
  5821. },
  5822. clone: function () {
  5823. return new this.constructor().copy( this );
  5824. },
  5825. copy: function ( ray ) {
  5826. this.origin.copy( ray.origin );
  5827. this.direction.copy( ray.direction );
  5828. return this;
  5829. },
  5830. at: function ( t, optionalTarget ) {
  5831. var result = optionalTarget || new Vector3();
  5832. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  5833. },
  5834. lookAt: function ( v ) {
  5835. this.direction.copy( v ).sub( this.origin ).normalize();
  5836. return this;
  5837. },
  5838. recast: function () {
  5839. var v1 = new Vector3();
  5840. return function recast( t ) {
  5841. this.origin.copy( this.at( t, v1 ) );
  5842. return this;
  5843. };
  5844. }(),
  5845. closestPointToPoint: function ( point, optionalTarget ) {
  5846. var result = optionalTarget || new Vector3();
  5847. result.subVectors( point, this.origin );
  5848. var directionDistance = result.dot( this.direction );
  5849. if ( directionDistance < 0 ) {
  5850. return result.copy( this.origin );
  5851. }
  5852. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  5853. },
  5854. distanceToPoint: function ( point ) {
  5855. return Math.sqrt( this.distanceSqToPoint( point ) );
  5856. },
  5857. distanceSqToPoint: function () {
  5858. var v1 = new Vector3();
  5859. return function distanceSqToPoint( point ) {
  5860. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  5861. // point behind the ray
  5862. if ( directionDistance < 0 ) {
  5863. return this.origin.distanceToSquared( point );
  5864. }
  5865. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  5866. return v1.distanceToSquared( point );
  5867. };
  5868. }(),
  5869. distanceSqToSegment: function () {
  5870. var segCenter = new Vector3();
  5871. var segDir = new Vector3();
  5872. var diff = new Vector3();
  5873. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  5874. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  5875. // It returns the min distance between the ray and the segment
  5876. // defined by v0 and v1
  5877. // It can also set two optional targets :
  5878. // - The closest point on the ray
  5879. // - The closest point on the segment
  5880. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  5881. segDir.copy( v1 ).sub( v0 ).normalize();
  5882. diff.copy( this.origin ).sub( segCenter );
  5883. var segExtent = v0.distanceTo( v1 ) * 0.5;
  5884. var a01 = - this.direction.dot( segDir );
  5885. var b0 = diff.dot( this.direction );
  5886. var b1 = - diff.dot( segDir );
  5887. var c = diff.lengthSq();
  5888. var det = Math.abs( 1 - a01 * a01 );
  5889. var s0, s1, sqrDist, extDet;
  5890. if ( det > 0 ) {
  5891. // The ray and segment are not parallel.
  5892. s0 = a01 * b1 - b0;
  5893. s1 = a01 * b0 - b1;
  5894. extDet = segExtent * det;
  5895. if ( s0 >= 0 ) {
  5896. if ( s1 >= - extDet ) {
  5897. if ( s1 <= extDet ) {
  5898. // region 0
  5899. // Minimum at interior points of ray and segment.
  5900. var invDet = 1 / det;
  5901. s0 *= invDet;
  5902. s1 *= invDet;
  5903. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  5904. } else {
  5905. // region 1
  5906. s1 = segExtent;
  5907. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  5908. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5909. }
  5910. } else {
  5911. // region 5
  5912. s1 = - segExtent;
  5913. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  5914. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5915. }
  5916. } else {
  5917. if ( s1 <= - extDet ) {
  5918. // region 4
  5919. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  5920. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  5921. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5922. } else if ( s1 <= extDet ) {
  5923. // region 3
  5924. s0 = 0;
  5925. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  5926. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  5927. } else {
  5928. // region 2
  5929. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  5930. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  5931. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5932. }
  5933. }
  5934. } else {
  5935. // Ray and segment are parallel.
  5936. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  5937. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  5938. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  5939. }
  5940. if ( optionalPointOnRay ) {
  5941. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  5942. }
  5943. if ( optionalPointOnSegment ) {
  5944. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  5945. }
  5946. return sqrDist;
  5947. };
  5948. }(),
  5949. intersectSphere: function () {
  5950. var v1 = new Vector3();
  5951. return function intersectSphere( sphere, optionalTarget ) {
  5952. v1.subVectors( sphere.center, this.origin );
  5953. var tca = v1.dot( this.direction );
  5954. var d2 = v1.dot( v1 ) - tca * tca;
  5955. var radius2 = sphere.radius * sphere.radius;
  5956. if ( d2 > radius2 ) return null;
  5957. var thc = Math.sqrt( radius2 - d2 );
  5958. // t0 = first intersect point - entrance on front of sphere
  5959. var t0 = tca - thc;
  5960. // t1 = second intersect point - exit point on back of sphere
  5961. var t1 = tca + thc;
  5962. // test to see if both t0 and t1 are behind the ray - if so, return null
  5963. if ( t0 < 0 && t1 < 0 ) return null;
  5964. // test to see if t0 is behind the ray:
  5965. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  5966. // in order to always return an intersect point that is in front of the ray.
  5967. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  5968. // else t0 is in front of the ray, so return the first collision point scaled by t0
  5969. return this.at( t0, optionalTarget );
  5970. };
  5971. }(),
  5972. intersectsSphere: function ( sphere ) {
  5973. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  5974. },
  5975. distanceToPlane: function ( plane ) {
  5976. var denominator = plane.normal.dot( this.direction );
  5977. if ( denominator === 0 ) {
  5978. // line is coplanar, return origin
  5979. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  5980. return 0;
  5981. }
  5982. // Null is preferable to undefined since undefined means.... it is undefined
  5983. return null;
  5984. }
  5985. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  5986. // Return if the ray never intersects the plane
  5987. return t >= 0 ? t : null;
  5988. },
  5989. intersectPlane: function ( plane, optionalTarget ) {
  5990. var t = this.distanceToPlane( plane );
  5991. if ( t === null ) {
  5992. return null;
  5993. }
  5994. return this.at( t, optionalTarget );
  5995. },
  5996. intersectsPlane: function ( plane ) {
  5997. // check if the ray lies on the plane first
  5998. var distToPoint = plane.distanceToPoint( this.origin );
  5999. if ( distToPoint === 0 ) {
  6000. return true;
  6001. }
  6002. var denominator = plane.normal.dot( this.direction );
  6003. if ( denominator * distToPoint < 0 ) {
  6004. return true;
  6005. }
  6006. // ray origin is behind the plane (and is pointing behind it)
  6007. return false;
  6008. },
  6009. intersectBox: function ( box, optionalTarget ) {
  6010. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  6011. var invdirx = 1 / this.direction.x,
  6012. invdiry = 1 / this.direction.y,
  6013. invdirz = 1 / this.direction.z;
  6014. var origin = this.origin;
  6015. if ( invdirx >= 0 ) {
  6016. tmin = ( box.min.x - origin.x ) * invdirx;
  6017. tmax = ( box.max.x - origin.x ) * invdirx;
  6018. } else {
  6019. tmin = ( box.max.x - origin.x ) * invdirx;
  6020. tmax = ( box.min.x - origin.x ) * invdirx;
  6021. }
  6022. if ( invdiry >= 0 ) {
  6023. tymin = ( box.min.y - origin.y ) * invdiry;
  6024. tymax = ( box.max.y - origin.y ) * invdiry;
  6025. } else {
  6026. tymin = ( box.max.y - origin.y ) * invdiry;
  6027. tymax = ( box.min.y - origin.y ) * invdiry;
  6028. }
  6029. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  6030. // These lines also handle the case where tmin or tmax is NaN
  6031. // (result of 0 * Infinity). x !== x returns true if x is NaN
  6032. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  6033. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  6034. if ( invdirz >= 0 ) {
  6035. tzmin = ( box.min.z - origin.z ) * invdirz;
  6036. tzmax = ( box.max.z - origin.z ) * invdirz;
  6037. } else {
  6038. tzmin = ( box.max.z - origin.z ) * invdirz;
  6039. tzmax = ( box.min.z - origin.z ) * invdirz;
  6040. }
  6041. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  6042. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  6043. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  6044. //return point closest to the ray (positive side)
  6045. if ( tmax < 0 ) return null;
  6046. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  6047. },
  6048. intersectsBox: ( function () {
  6049. var v = new Vector3();
  6050. return function intersectsBox( box ) {
  6051. return this.intersectBox( box, v ) !== null;
  6052. };
  6053. } )(),
  6054. intersectTriangle: function () {
  6055. // Compute the offset origin, edges, and normal.
  6056. var diff = new Vector3();
  6057. var edge1 = new Vector3();
  6058. var edge2 = new Vector3();
  6059. var normal = new Vector3();
  6060. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  6061. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  6062. edge1.subVectors( b, a );
  6063. edge2.subVectors( c, a );
  6064. normal.crossVectors( edge1, edge2 );
  6065. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  6066. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  6067. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  6068. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  6069. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  6070. var DdN = this.direction.dot( normal );
  6071. var sign;
  6072. if ( DdN > 0 ) {
  6073. if ( backfaceCulling ) return null;
  6074. sign = 1;
  6075. } else if ( DdN < 0 ) {
  6076. sign = - 1;
  6077. DdN = - DdN;
  6078. } else {
  6079. return null;
  6080. }
  6081. diff.subVectors( this.origin, a );
  6082. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  6083. // b1 < 0, no intersection
  6084. if ( DdQxE2 < 0 ) {
  6085. return null;
  6086. }
  6087. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  6088. // b2 < 0, no intersection
  6089. if ( DdE1xQ < 0 ) {
  6090. return null;
  6091. }
  6092. // b1+b2 > 1, no intersection
  6093. if ( DdQxE2 + DdE1xQ > DdN ) {
  6094. return null;
  6095. }
  6096. // Line intersects triangle, check if ray does.
  6097. var QdN = - sign * diff.dot( normal );
  6098. // t < 0, no intersection
  6099. if ( QdN < 0 ) {
  6100. return null;
  6101. }
  6102. // Ray intersects triangle.
  6103. return this.at( QdN / DdN, optionalTarget );
  6104. };
  6105. }(),
  6106. applyMatrix4: function ( matrix4 ) {
  6107. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  6108. this.origin.applyMatrix4( matrix4 );
  6109. this.direction.sub( this.origin );
  6110. this.direction.normalize();
  6111. return this;
  6112. },
  6113. equals: function ( ray ) {
  6114. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  6115. }
  6116. } );
  6117. /**
  6118. * @author mrdoob / http://mrdoob.com/
  6119. * @author WestLangley / http://github.com/WestLangley
  6120. * @author bhouston / http://clara.io
  6121. */
  6122. function Euler( x, y, z, order ) {
  6123. this._x = x || 0;
  6124. this._y = y || 0;
  6125. this._z = z || 0;
  6126. this._order = order || Euler.DefaultOrder;
  6127. }
  6128. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  6129. Euler.DefaultOrder = 'XYZ';
  6130. Object.defineProperties( Euler.prototype, {
  6131. x: {
  6132. get: function () {
  6133. return this._x;
  6134. },
  6135. set: function ( value ) {
  6136. this._x = value;
  6137. this.onChangeCallback();
  6138. }
  6139. },
  6140. y: {
  6141. get: function () {
  6142. return this._y;
  6143. },
  6144. set: function ( value ) {
  6145. this._y = value;
  6146. this.onChangeCallback();
  6147. }
  6148. },
  6149. z: {
  6150. get: function () {
  6151. return this._z;
  6152. },
  6153. set: function ( value ) {
  6154. this._z = value;
  6155. this.onChangeCallback();
  6156. }
  6157. },
  6158. order: {
  6159. get: function () {
  6160. return this._order;
  6161. },
  6162. set: function ( value ) {
  6163. this._order = value;
  6164. this.onChangeCallback();
  6165. }
  6166. }
  6167. } );
  6168. Object.assign( Euler.prototype, {
  6169. isEuler: true,
  6170. set: function ( x, y, z, order ) {
  6171. this._x = x;
  6172. this._y = y;
  6173. this._z = z;
  6174. this._order = order || this._order;
  6175. this.onChangeCallback();
  6176. return this;
  6177. },
  6178. clone: function () {
  6179. return new this.constructor( this._x, this._y, this._z, this._order );
  6180. },
  6181. copy: function ( euler ) {
  6182. this._x = euler._x;
  6183. this._y = euler._y;
  6184. this._z = euler._z;
  6185. this._order = euler._order;
  6186. this.onChangeCallback();
  6187. return this;
  6188. },
  6189. setFromRotationMatrix: function ( m, order, update ) {
  6190. var clamp = _Math.clamp;
  6191. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  6192. var te = m.elements;
  6193. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  6194. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  6195. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  6196. order = order || this._order;
  6197. if ( order === 'XYZ' ) {
  6198. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  6199. if ( Math.abs( m13 ) < 0.99999 ) {
  6200. this._x = Math.atan2( - m23, m33 );
  6201. this._z = Math.atan2( - m12, m11 );
  6202. } else {
  6203. this._x = Math.atan2( m32, m22 );
  6204. this._z = 0;
  6205. }
  6206. } else if ( order === 'YXZ' ) {
  6207. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  6208. if ( Math.abs( m23 ) < 0.99999 ) {
  6209. this._y = Math.atan2( m13, m33 );
  6210. this._z = Math.atan2( m21, m22 );
  6211. } else {
  6212. this._y = Math.atan2( - m31, m11 );
  6213. this._z = 0;
  6214. }
  6215. } else if ( order === 'ZXY' ) {
  6216. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  6217. if ( Math.abs( m32 ) < 0.99999 ) {
  6218. this._y = Math.atan2( - m31, m33 );
  6219. this._z = Math.atan2( - m12, m22 );
  6220. } else {
  6221. this._y = 0;
  6222. this._z = Math.atan2( m21, m11 );
  6223. }
  6224. } else if ( order === 'ZYX' ) {
  6225. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  6226. if ( Math.abs( m31 ) < 0.99999 ) {
  6227. this._x = Math.atan2( m32, m33 );
  6228. this._z = Math.atan2( m21, m11 );
  6229. } else {
  6230. this._x = 0;
  6231. this._z = Math.atan2( - m12, m22 );
  6232. }
  6233. } else if ( order === 'YZX' ) {
  6234. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  6235. if ( Math.abs( m21 ) < 0.99999 ) {
  6236. this._x = Math.atan2( - m23, m22 );
  6237. this._y = Math.atan2( - m31, m11 );
  6238. } else {
  6239. this._x = 0;
  6240. this._y = Math.atan2( m13, m33 );
  6241. }
  6242. } else if ( order === 'XZY' ) {
  6243. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  6244. if ( Math.abs( m12 ) < 0.99999 ) {
  6245. this._x = Math.atan2( m32, m22 );
  6246. this._y = Math.atan2( m13, m11 );
  6247. } else {
  6248. this._x = Math.atan2( - m23, m33 );
  6249. this._y = 0;
  6250. }
  6251. } else {
  6252. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  6253. }
  6254. this._order = order;
  6255. if ( update !== false ) this.onChangeCallback();
  6256. return this;
  6257. },
  6258. setFromQuaternion: function () {
  6259. var matrix = new Matrix4();
  6260. return function setFromQuaternion( q, order, update ) {
  6261. matrix.makeRotationFromQuaternion( q );
  6262. return this.setFromRotationMatrix( matrix, order, update );
  6263. };
  6264. }(),
  6265. setFromVector3: function ( v, order ) {
  6266. return this.set( v.x, v.y, v.z, order || this._order );
  6267. },
  6268. reorder: function () {
  6269. // WARNING: this discards revolution information -bhouston
  6270. var q = new Quaternion();
  6271. return function reorder( newOrder ) {
  6272. q.setFromEuler( this );
  6273. return this.setFromQuaternion( q, newOrder );
  6274. };
  6275. }(),
  6276. equals: function ( euler ) {
  6277. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  6278. },
  6279. fromArray: function ( array ) {
  6280. this._x = array[ 0 ];
  6281. this._y = array[ 1 ];
  6282. this._z = array[ 2 ];
  6283. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  6284. this.onChangeCallback();
  6285. return this;
  6286. },
  6287. toArray: function ( array, offset ) {
  6288. if ( array === undefined ) array = [];
  6289. if ( offset === undefined ) offset = 0;
  6290. array[ offset ] = this._x;
  6291. array[ offset + 1 ] = this._y;
  6292. array[ offset + 2 ] = this._z;
  6293. array[ offset + 3 ] = this._order;
  6294. return array;
  6295. },
  6296. toVector3: function ( optionalResult ) {
  6297. if ( optionalResult ) {
  6298. return optionalResult.set( this._x, this._y, this._z );
  6299. } else {
  6300. return new Vector3( this._x, this._y, this._z );
  6301. }
  6302. },
  6303. onChange: function ( callback ) {
  6304. this.onChangeCallback = callback;
  6305. return this;
  6306. },
  6307. onChangeCallback: function () {}
  6308. } );
  6309. /**
  6310. * @author mrdoob / http://mrdoob.com/
  6311. */
  6312. function Layers() {
  6313. this.mask = 1 | 0;
  6314. }
  6315. Object.assign( Layers.prototype, {
  6316. set: function ( channel ) {
  6317. this.mask = 1 << channel | 0;
  6318. },
  6319. enable: function ( channel ) {
  6320. this.mask |= 1 << channel | 0;
  6321. },
  6322. toggle: function ( channel ) {
  6323. this.mask ^= 1 << channel | 0;
  6324. },
  6325. disable: function ( channel ) {
  6326. this.mask &= ~ ( 1 << channel | 0 );
  6327. },
  6328. test: function ( layers ) {
  6329. return ( this.mask & layers.mask ) !== 0;
  6330. }
  6331. } );
  6332. /**
  6333. * @author mrdoob / http://mrdoob.com/
  6334. * @author mikael emtinger / http://gomo.se/
  6335. * @author alteredq / http://alteredqualia.com/
  6336. * @author WestLangley / http://github.com/WestLangley
  6337. * @author elephantatwork / www.elephantatwork.ch
  6338. */
  6339. var object3DId = 0;
  6340. function Object3D() {
  6341. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  6342. this.uuid = _Math.generateUUID();
  6343. this.name = '';
  6344. this.type = 'Object3D';
  6345. this.parent = null;
  6346. this.children = [];
  6347. this.up = Object3D.DefaultUp.clone();
  6348. var position = new Vector3();
  6349. var rotation = new Euler();
  6350. var quaternion = new Quaternion();
  6351. var scale = new Vector3( 1, 1, 1 );
  6352. function onRotationChange() {
  6353. quaternion.setFromEuler( rotation, false );
  6354. }
  6355. function onQuaternionChange() {
  6356. rotation.setFromQuaternion( quaternion, undefined, false );
  6357. }
  6358. rotation.onChange( onRotationChange );
  6359. quaternion.onChange( onQuaternionChange );
  6360. Object.defineProperties( this, {
  6361. position: {
  6362. enumerable: true,
  6363. value: position
  6364. },
  6365. rotation: {
  6366. enumerable: true,
  6367. value: rotation
  6368. },
  6369. quaternion: {
  6370. enumerable: true,
  6371. value: quaternion
  6372. },
  6373. scale: {
  6374. enumerable: true,
  6375. value: scale
  6376. },
  6377. modelViewMatrix: {
  6378. value: new Matrix4()
  6379. },
  6380. normalMatrix: {
  6381. value: new Matrix3()
  6382. }
  6383. } );
  6384. this.matrix = new Matrix4();
  6385. this.matrixWorld = new Matrix4();
  6386. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  6387. this.matrixWorldNeedsUpdate = false;
  6388. this.layers = new Layers();
  6389. this.visible = true;
  6390. this.castShadow = false;
  6391. this.receiveShadow = false;
  6392. this.frustumCulled = true;
  6393. this.renderOrder = 0;
  6394. this.userData = {};
  6395. }
  6396. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  6397. Object3D.DefaultMatrixAutoUpdate = true;
  6398. Object.assign( Object3D.prototype, EventDispatcher.prototype, {
  6399. isObject3D: true,
  6400. onBeforeRender: function () {},
  6401. onAfterRender: function () {},
  6402. applyMatrix: function ( matrix ) {
  6403. this.matrix.multiplyMatrices( matrix, this.matrix );
  6404. this.matrix.decompose( this.position, this.quaternion, this.scale );
  6405. },
  6406. applyQuaternion: function ( q ) {
  6407. this.quaternion.premultiply( q );
  6408. return this;
  6409. },
  6410. setRotationFromAxisAngle: function ( axis, angle ) {
  6411. // assumes axis is normalized
  6412. this.quaternion.setFromAxisAngle( axis, angle );
  6413. },
  6414. setRotationFromEuler: function ( euler ) {
  6415. this.quaternion.setFromEuler( euler, true );
  6416. },
  6417. setRotationFromMatrix: function ( m ) {
  6418. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  6419. this.quaternion.setFromRotationMatrix( m );
  6420. },
  6421. setRotationFromQuaternion: function ( q ) {
  6422. // assumes q is normalized
  6423. this.quaternion.copy( q );
  6424. },
  6425. rotateOnAxis: function () {
  6426. // rotate object on axis in object space
  6427. // axis is assumed to be normalized
  6428. var q1 = new Quaternion();
  6429. return function rotateOnAxis( axis, angle ) {
  6430. q1.setFromAxisAngle( axis, angle );
  6431. this.quaternion.multiply( q1 );
  6432. return this;
  6433. };
  6434. }(),
  6435. rotateX: function () {
  6436. var v1 = new Vector3( 1, 0, 0 );
  6437. return function rotateX( angle ) {
  6438. return this.rotateOnAxis( v1, angle );
  6439. };
  6440. }(),
  6441. rotateY: function () {
  6442. var v1 = new Vector3( 0, 1, 0 );
  6443. return function rotateY( angle ) {
  6444. return this.rotateOnAxis( v1, angle );
  6445. };
  6446. }(),
  6447. rotateZ: function () {
  6448. var v1 = new Vector3( 0, 0, 1 );
  6449. return function rotateZ( angle ) {
  6450. return this.rotateOnAxis( v1, angle );
  6451. };
  6452. }(),
  6453. translateOnAxis: function () {
  6454. // translate object by distance along axis in object space
  6455. // axis is assumed to be normalized
  6456. var v1 = new Vector3();
  6457. return function translateOnAxis( axis, distance ) {
  6458. v1.copy( axis ).applyQuaternion( this.quaternion );
  6459. this.position.add( v1.multiplyScalar( distance ) );
  6460. return this;
  6461. };
  6462. }(),
  6463. translateX: function () {
  6464. var v1 = new Vector3( 1, 0, 0 );
  6465. return function translateX( distance ) {
  6466. return this.translateOnAxis( v1, distance );
  6467. };
  6468. }(),
  6469. translateY: function () {
  6470. var v1 = new Vector3( 0, 1, 0 );
  6471. return function translateY( distance ) {
  6472. return this.translateOnAxis( v1, distance );
  6473. };
  6474. }(),
  6475. translateZ: function () {
  6476. var v1 = new Vector3( 0, 0, 1 );
  6477. return function translateZ( distance ) {
  6478. return this.translateOnAxis( v1, distance );
  6479. };
  6480. }(),
  6481. localToWorld: function ( vector ) {
  6482. return vector.applyMatrix4( this.matrixWorld );
  6483. },
  6484. worldToLocal: function () {
  6485. var m1 = new Matrix4();
  6486. return function worldToLocal( vector ) {
  6487. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  6488. };
  6489. }(),
  6490. lookAt: function () {
  6491. // This method does not support objects with rotated and/or translated parent(s)
  6492. var m1 = new Matrix4();
  6493. return function lookAt( vector ) {
  6494. if ( this.isCamera ) {
  6495. m1.lookAt( this.position, vector, this.up );
  6496. } else {
  6497. m1.lookAt( vector, this.position, this.up );
  6498. }
  6499. this.quaternion.setFromRotationMatrix( m1 );
  6500. };
  6501. }(),
  6502. add: function ( object ) {
  6503. if ( arguments.length > 1 ) {
  6504. for ( var i = 0; i < arguments.length; i ++ ) {
  6505. this.add( arguments[ i ] );
  6506. }
  6507. return this;
  6508. }
  6509. if ( object === this ) {
  6510. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  6511. return this;
  6512. }
  6513. if ( ( object && object.isObject3D ) ) {
  6514. if ( object.parent !== null ) {
  6515. object.parent.remove( object );
  6516. }
  6517. object.parent = this;
  6518. object.dispatchEvent( { type: 'added' } );
  6519. this.children.push( object );
  6520. } else {
  6521. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  6522. }
  6523. return this;
  6524. },
  6525. remove: function ( object ) {
  6526. if ( arguments.length > 1 ) {
  6527. for ( var i = 0; i < arguments.length; i ++ ) {
  6528. this.remove( arguments[ i ] );
  6529. }
  6530. }
  6531. var index = this.children.indexOf( object );
  6532. if ( index !== - 1 ) {
  6533. object.parent = null;
  6534. object.dispatchEvent( { type: 'removed' } );
  6535. this.children.splice( index, 1 );
  6536. }
  6537. },
  6538. getObjectById: function ( id ) {
  6539. return this.getObjectByProperty( 'id', id );
  6540. },
  6541. getObjectByName: function ( name ) {
  6542. return this.getObjectByProperty( 'name', name );
  6543. },
  6544. getObjectByProperty: function ( name, value ) {
  6545. if ( this[ name ] === value ) return this;
  6546. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  6547. var child = this.children[ i ];
  6548. var object = child.getObjectByProperty( name, value );
  6549. if ( object !== undefined ) {
  6550. return object;
  6551. }
  6552. }
  6553. return undefined;
  6554. },
  6555. getWorldPosition: function ( optionalTarget ) {
  6556. var result = optionalTarget || new Vector3();
  6557. this.updateMatrixWorld( true );
  6558. return result.setFromMatrixPosition( this.matrixWorld );
  6559. },
  6560. getWorldQuaternion: function () {
  6561. var position = new Vector3();
  6562. var scale = new Vector3();
  6563. return function getWorldQuaternion( optionalTarget ) {
  6564. var result = optionalTarget || new Quaternion();
  6565. this.updateMatrixWorld( true );
  6566. this.matrixWorld.decompose( position, result, scale );
  6567. return result;
  6568. };
  6569. }(),
  6570. getWorldRotation: function () {
  6571. var quaternion = new Quaternion();
  6572. return function getWorldRotation( optionalTarget ) {
  6573. var result = optionalTarget || new Euler();
  6574. this.getWorldQuaternion( quaternion );
  6575. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  6576. };
  6577. }(),
  6578. getWorldScale: function () {
  6579. var position = new Vector3();
  6580. var quaternion = new Quaternion();
  6581. return function getWorldScale( optionalTarget ) {
  6582. var result = optionalTarget || new Vector3();
  6583. this.updateMatrixWorld( true );
  6584. this.matrixWorld.decompose( position, quaternion, result );
  6585. return result;
  6586. };
  6587. }(),
  6588. getWorldDirection: function () {
  6589. var quaternion = new Quaternion();
  6590. return function getWorldDirection( optionalTarget ) {
  6591. var result = optionalTarget || new Vector3();
  6592. this.getWorldQuaternion( quaternion );
  6593. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  6594. };
  6595. }(),
  6596. raycast: function () {},
  6597. traverse: function ( callback ) {
  6598. callback( this );
  6599. var children = this.children;
  6600. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6601. children[ i ].traverse( callback );
  6602. }
  6603. },
  6604. traverseVisible: function ( callback ) {
  6605. if ( this.visible === false ) return;
  6606. callback( this );
  6607. var children = this.children;
  6608. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6609. children[ i ].traverseVisible( callback );
  6610. }
  6611. },
  6612. traverseAncestors: function ( callback ) {
  6613. var parent = this.parent;
  6614. if ( parent !== null ) {
  6615. callback( parent );
  6616. parent.traverseAncestors( callback );
  6617. }
  6618. },
  6619. updateMatrix: function () {
  6620. this.matrix.compose( this.position, this.quaternion, this.scale );
  6621. this.matrixWorldNeedsUpdate = true;
  6622. },
  6623. updateMatrixWorld: function ( force ) {
  6624. if ( this.matrixAutoUpdate ) this.updateMatrix();
  6625. if ( this.matrixWorldNeedsUpdate || force ) {
  6626. if ( this.parent === null ) {
  6627. this.matrixWorld.copy( this.matrix );
  6628. } else {
  6629. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  6630. }
  6631. this.matrixWorldNeedsUpdate = false;
  6632. force = true;
  6633. }
  6634. // update children
  6635. var children = this.children;
  6636. for ( var i = 0, l = children.length; i < l; i ++ ) {
  6637. children[ i ].updateMatrixWorld( force );
  6638. }
  6639. },
  6640. toJSON: function ( meta ) {
  6641. // meta is '' when called from JSON.stringify
  6642. var isRootObject = ( meta === undefined || meta === '' );
  6643. var output = {};
  6644. // meta is a hash used to collect geometries, materials.
  6645. // not providing it implies that this is the root object
  6646. // being serialized.
  6647. if ( isRootObject ) {
  6648. // initialize meta obj
  6649. meta = {
  6650. geometries: {},
  6651. materials: {},
  6652. textures: {},
  6653. images: {}
  6654. };
  6655. output.metadata = {
  6656. version: 4.5,
  6657. type: 'Object',
  6658. generator: 'Object3D.toJSON'
  6659. };
  6660. }
  6661. // standard Object3D serialization
  6662. var object = {};
  6663. object.uuid = this.uuid;
  6664. object.type = this.type;
  6665. if ( this.name !== '' ) object.name = this.name;
  6666. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  6667. if ( this.castShadow === true ) object.castShadow = true;
  6668. if ( this.receiveShadow === true ) object.receiveShadow = true;
  6669. if ( this.visible === false ) object.visible = false;
  6670. object.matrix = this.matrix.toArray();
  6671. //
  6672. function serialize( library, element ) {
  6673. if ( library[ element.uuid ] === undefined ) {
  6674. library[ element.uuid ] = element.toJSON( meta );
  6675. }
  6676. return element.uuid;
  6677. }
  6678. if ( this.geometry !== undefined ) {
  6679. object.geometry = serialize( meta.geometries, this.geometry );
  6680. }
  6681. if ( this.material !== undefined ) {
  6682. if ( Array.isArray( this.material ) ) {
  6683. var uuids = [];
  6684. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  6685. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  6686. }
  6687. object.material = uuids;
  6688. } else {
  6689. object.material = serialize( meta.materials, this.material );
  6690. }
  6691. }
  6692. //
  6693. if ( this.children.length > 0 ) {
  6694. object.children = [];
  6695. for ( var i = 0; i < this.children.length; i ++ ) {
  6696. object.children.push( this.children[ i ].toJSON( meta ).object );
  6697. }
  6698. }
  6699. if ( isRootObject ) {
  6700. var geometries = extractFromCache( meta.geometries );
  6701. var materials = extractFromCache( meta.materials );
  6702. var textures = extractFromCache( meta.textures );
  6703. var images = extractFromCache( meta.images );
  6704. if ( geometries.length > 0 ) output.geometries = geometries;
  6705. if ( materials.length > 0 ) output.materials = materials;
  6706. if ( textures.length > 0 ) output.textures = textures;
  6707. if ( images.length > 0 ) output.images = images;
  6708. }
  6709. output.object = object;
  6710. return output;
  6711. // extract data from the cache hash
  6712. // remove metadata on each item
  6713. // and return as array
  6714. function extractFromCache( cache ) {
  6715. var values = [];
  6716. for ( var key in cache ) {
  6717. var data = cache[ key ];
  6718. delete data.metadata;
  6719. values.push( data );
  6720. }
  6721. return values;
  6722. }
  6723. },
  6724. clone: function ( recursive ) {
  6725. return new this.constructor().copy( this, recursive );
  6726. },
  6727. copy: function ( source, recursive ) {
  6728. if ( recursive === undefined ) recursive = true;
  6729. this.name = source.name;
  6730. this.up.copy( source.up );
  6731. this.position.copy( source.position );
  6732. this.quaternion.copy( source.quaternion );
  6733. this.scale.copy( source.scale );
  6734. this.matrix.copy( source.matrix );
  6735. this.matrixWorld.copy( source.matrixWorld );
  6736. this.matrixAutoUpdate = source.matrixAutoUpdate;
  6737. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  6738. this.layers.mask = source.layers.mask;
  6739. this.visible = source.visible;
  6740. this.castShadow = source.castShadow;
  6741. this.receiveShadow = source.receiveShadow;
  6742. this.frustumCulled = source.frustumCulled;
  6743. this.renderOrder = source.renderOrder;
  6744. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  6745. if ( recursive === true ) {
  6746. for ( var i = 0; i < source.children.length; i ++ ) {
  6747. var child = source.children[ i ];
  6748. this.add( child.clone() );
  6749. }
  6750. }
  6751. return this;
  6752. }
  6753. } );
  6754. /**
  6755. * @author bhouston / http://clara.io
  6756. */
  6757. function Line3( start, end ) {
  6758. this.start = ( start !== undefined ) ? start : new Vector3();
  6759. this.end = ( end !== undefined ) ? end : new Vector3();
  6760. }
  6761. Object.assign( Line3.prototype, {
  6762. set: function ( start, end ) {
  6763. this.start.copy( start );
  6764. this.end.copy( end );
  6765. return this;
  6766. },
  6767. clone: function () {
  6768. return new this.constructor().copy( this );
  6769. },
  6770. copy: function ( line ) {
  6771. this.start.copy( line.start );
  6772. this.end.copy( line.end );
  6773. return this;
  6774. },
  6775. getCenter: function ( optionalTarget ) {
  6776. var result = optionalTarget || new Vector3();
  6777. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  6778. },
  6779. delta: function ( optionalTarget ) {
  6780. var result = optionalTarget || new Vector3();
  6781. return result.subVectors( this.end, this.start );
  6782. },
  6783. distanceSq: function () {
  6784. return this.start.distanceToSquared( this.end );
  6785. },
  6786. distance: function () {
  6787. return this.start.distanceTo( this.end );
  6788. },
  6789. at: function ( t, optionalTarget ) {
  6790. var result = optionalTarget || new Vector3();
  6791. return this.delta( result ).multiplyScalar( t ).add( this.start );
  6792. },
  6793. closestPointToPointParameter: function () {
  6794. var startP = new Vector3();
  6795. var startEnd = new Vector3();
  6796. return function closestPointToPointParameter( point, clampToLine ) {
  6797. startP.subVectors( point, this.start );
  6798. startEnd.subVectors( this.end, this.start );
  6799. var startEnd2 = startEnd.dot( startEnd );
  6800. var startEnd_startP = startEnd.dot( startP );
  6801. var t = startEnd_startP / startEnd2;
  6802. if ( clampToLine ) {
  6803. t = _Math.clamp( t, 0, 1 );
  6804. }
  6805. return t;
  6806. };
  6807. }(),
  6808. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  6809. var t = this.closestPointToPointParameter( point, clampToLine );
  6810. var result = optionalTarget || new Vector3();
  6811. return this.delta( result ).multiplyScalar( t ).add( this.start );
  6812. },
  6813. applyMatrix4: function ( matrix ) {
  6814. this.start.applyMatrix4( matrix );
  6815. this.end.applyMatrix4( matrix );
  6816. return this;
  6817. },
  6818. equals: function ( line ) {
  6819. return line.start.equals( this.start ) && line.end.equals( this.end );
  6820. }
  6821. } );
  6822. /**
  6823. * @author bhouston / http://clara.io
  6824. * @author mrdoob / http://mrdoob.com/
  6825. */
  6826. function Triangle( a, b, c ) {
  6827. this.a = ( a !== undefined ) ? a : new Vector3();
  6828. this.b = ( b !== undefined ) ? b : new Vector3();
  6829. this.c = ( c !== undefined ) ? c : new Vector3();
  6830. }
  6831. Object.assign( Triangle, {
  6832. normal: function () {
  6833. var v0 = new Vector3();
  6834. return function normal( a, b, c, optionalTarget ) {
  6835. var result = optionalTarget || new Vector3();
  6836. result.subVectors( c, b );
  6837. v0.subVectors( a, b );
  6838. result.cross( v0 );
  6839. var resultLengthSq = result.lengthSq();
  6840. if ( resultLengthSq > 0 ) {
  6841. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  6842. }
  6843. return result.set( 0, 0, 0 );
  6844. };
  6845. }(),
  6846. // static/instance method to calculate barycentric coordinates
  6847. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  6848. barycoordFromPoint: function () {
  6849. var v0 = new Vector3();
  6850. var v1 = new Vector3();
  6851. var v2 = new Vector3();
  6852. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  6853. v0.subVectors( c, a );
  6854. v1.subVectors( b, a );
  6855. v2.subVectors( point, a );
  6856. var dot00 = v0.dot( v0 );
  6857. var dot01 = v0.dot( v1 );
  6858. var dot02 = v0.dot( v2 );
  6859. var dot11 = v1.dot( v1 );
  6860. var dot12 = v1.dot( v2 );
  6861. var denom = ( dot00 * dot11 - dot01 * dot01 );
  6862. var result = optionalTarget || new Vector3();
  6863. // collinear or singular triangle
  6864. if ( denom === 0 ) {
  6865. // arbitrary location outside of triangle?
  6866. // not sure if this is the best idea, maybe should be returning undefined
  6867. return result.set( - 2, - 1, - 1 );
  6868. }
  6869. var invDenom = 1 / denom;
  6870. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  6871. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  6872. // barycentric coordinates must always sum to 1
  6873. return result.set( 1 - u - v, v, u );
  6874. };
  6875. }(),
  6876. containsPoint: function () {
  6877. var v1 = new Vector3();
  6878. return function containsPoint( point, a, b, c ) {
  6879. var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
  6880. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  6881. };
  6882. }()
  6883. } );
  6884. Object.assign( Triangle.prototype, {
  6885. set: function ( a, b, c ) {
  6886. this.a.copy( a );
  6887. this.b.copy( b );
  6888. this.c.copy( c );
  6889. return this;
  6890. },
  6891. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  6892. this.a.copy( points[ i0 ] );
  6893. this.b.copy( points[ i1 ] );
  6894. this.c.copy( points[ i2 ] );
  6895. return this;
  6896. },
  6897. clone: function () {
  6898. return new this.constructor().copy( this );
  6899. },
  6900. copy: function ( triangle ) {
  6901. this.a.copy( triangle.a );
  6902. this.b.copy( triangle.b );
  6903. this.c.copy( triangle.c );
  6904. return this;
  6905. },
  6906. area: function () {
  6907. var v0 = new Vector3();
  6908. var v1 = new Vector3();
  6909. return function area() {
  6910. v0.subVectors( this.c, this.b );
  6911. v1.subVectors( this.a, this.b );
  6912. return v0.cross( v1 ).length() * 0.5;
  6913. };
  6914. }(),
  6915. midpoint: function ( optionalTarget ) {
  6916. var result = optionalTarget || new Vector3();
  6917. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  6918. },
  6919. normal: function ( optionalTarget ) {
  6920. return Triangle.normal( this.a, this.b, this.c, optionalTarget );
  6921. },
  6922. plane: function ( optionalTarget ) {
  6923. var result = optionalTarget || new Plane();
  6924. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  6925. },
  6926. barycoordFromPoint: function ( point, optionalTarget ) {
  6927. return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  6928. },
  6929. containsPoint: function ( point ) {
  6930. return Triangle.containsPoint( point, this.a, this.b, this.c );
  6931. },
  6932. closestPointToPoint: function () {
  6933. var plane = new Plane();
  6934. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  6935. var projectedPoint = new Vector3();
  6936. var closestPoint = new Vector3();
  6937. return function closestPointToPoint( point, optionalTarget ) {
  6938. var result = optionalTarget || new Vector3();
  6939. var minDistance = Infinity;
  6940. // project the point onto the plane of the triangle
  6941. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  6942. plane.projectPoint( point, projectedPoint );
  6943. // check if the projection lies within the triangle
  6944. if( this.containsPoint( projectedPoint ) === true ) {
  6945. // if so, this is the closest point
  6946. result.copy( projectedPoint );
  6947. } else {
  6948. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  6949. edgeList[ 0 ].set( this.a, this.b );
  6950. edgeList[ 1 ].set( this.b, this.c );
  6951. edgeList[ 2 ].set( this.c, this.a );
  6952. for( var i = 0; i < edgeList.length; i ++ ) {
  6953. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  6954. var distance = projectedPoint.distanceToSquared( closestPoint );
  6955. if( distance < minDistance ) {
  6956. minDistance = distance;
  6957. result.copy( closestPoint );
  6958. }
  6959. }
  6960. }
  6961. return result;
  6962. };
  6963. }(),
  6964. equals: function ( triangle ) {
  6965. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  6966. }
  6967. } );
  6968. /**
  6969. * @author mrdoob / http://mrdoob.com/
  6970. * @author alteredq / http://alteredqualia.com/
  6971. */
  6972. function Face3( a, b, c, normal, color, materialIndex ) {
  6973. this.a = a;
  6974. this.b = b;
  6975. this.c = c;
  6976. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  6977. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  6978. this.color = ( color && color.isColor ) ? color : new Color();
  6979. this.vertexColors = Array.isArray( color ) ? color : [];
  6980. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  6981. }
  6982. Object.assign( Face3.prototype, {
  6983. clone: function () {
  6984. return new this.constructor().copy( this );
  6985. },
  6986. copy: function ( source ) {
  6987. this.a = source.a;
  6988. this.b = source.b;
  6989. this.c = source.c;
  6990. this.normal.copy( source.normal );
  6991. this.color.copy( source.color );
  6992. this.materialIndex = source.materialIndex;
  6993. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  6994. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  6995. }
  6996. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  6997. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  6998. }
  6999. return this;
  7000. }
  7001. } );
  7002. /**
  7003. * @author mrdoob / http://mrdoob.com/
  7004. * @author alteredq / http://alteredqualia.com/
  7005. *
  7006. * parameters = {
  7007. * color: <hex>,
  7008. * opacity: <float>,
  7009. * map: new THREE.Texture( <Image> ),
  7010. *
  7011. * lightMap: new THREE.Texture( <Image> ),
  7012. * lightMapIntensity: <float>
  7013. *
  7014. * aoMap: new THREE.Texture( <Image> ),
  7015. * aoMapIntensity: <float>
  7016. *
  7017. * specularMap: new THREE.Texture( <Image> ),
  7018. *
  7019. * alphaMap: new THREE.Texture( <Image> ),
  7020. *
  7021. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  7022. * combine: THREE.Multiply,
  7023. * reflectivity: <float>,
  7024. * refractionRatio: <float>,
  7025. *
  7026. * shading: THREE.SmoothShading,
  7027. * depthTest: <bool>,
  7028. * depthWrite: <bool>,
  7029. *
  7030. * wireframe: <boolean>,
  7031. * wireframeLinewidth: <float>,
  7032. *
  7033. * skinning: <bool>,
  7034. * morphTargets: <bool>
  7035. * }
  7036. */
  7037. function MeshBasicMaterial( parameters ) {
  7038. Material.call( this );
  7039. this.type = 'MeshBasicMaterial';
  7040. this.color = new Color( 0xffffff ); // emissive
  7041. this.map = null;
  7042. this.lightMap = null;
  7043. this.lightMapIntensity = 1.0;
  7044. this.aoMap = null;
  7045. this.aoMapIntensity = 1.0;
  7046. this.specularMap = null;
  7047. this.alphaMap = null;
  7048. this.envMap = null;
  7049. this.combine = MultiplyOperation;
  7050. this.reflectivity = 1;
  7051. this.refractionRatio = 0.98;
  7052. this.wireframe = false;
  7053. this.wireframeLinewidth = 1;
  7054. this.wireframeLinecap = 'round';
  7055. this.wireframeLinejoin = 'round';
  7056. this.skinning = false;
  7057. this.morphTargets = false;
  7058. this.lights = false;
  7059. this.setValues( parameters );
  7060. }
  7061. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  7062. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  7063. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  7064. MeshBasicMaterial.prototype.copy = function ( source ) {
  7065. Material.prototype.copy.call( this, source );
  7066. this.color.copy( source.color );
  7067. this.map = source.map;
  7068. this.lightMap = source.lightMap;
  7069. this.lightMapIntensity = source.lightMapIntensity;
  7070. this.aoMap = source.aoMap;
  7071. this.aoMapIntensity = source.aoMapIntensity;
  7072. this.specularMap = source.specularMap;
  7073. this.alphaMap = source.alphaMap;
  7074. this.envMap = source.envMap;
  7075. this.combine = source.combine;
  7076. this.reflectivity = source.reflectivity;
  7077. this.refractionRatio = source.refractionRatio;
  7078. this.wireframe = source.wireframe;
  7079. this.wireframeLinewidth = source.wireframeLinewidth;
  7080. this.wireframeLinecap = source.wireframeLinecap;
  7081. this.wireframeLinejoin = source.wireframeLinejoin;
  7082. this.skinning = source.skinning;
  7083. this.morphTargets = source.morphTargets;
  7084. return this;
  7085. };
  7086. /**
  7087. * @author mrdoob / http://mrdoob.com/
  7088. */
  7089. function BufferAttribute( array, itemSize, normalized ) {
  7090. if ( Array.isArray( array ) ) {
  7091. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7092. }
  7093. this.uuid = _Math.generateUUID();
  7094. this.name = '';
  7095. this.array = array;
  7096. this.itemSize = itemSize;
  7097. this.count = array !== undefined ? array.length / itemSize : 0;
  7098. this.normalized = normalized === true;
  7099. this.dynamic = false;
  7100. this.updateRange = { offset: 0, count: - 1 };
  7101. this.onUploadCallback = function () {};
  7102. this.version = 0;
  7103. }
  7104. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  7105. set: function ( value ) {
  7106. if ( value === true ) this.version ++;
  7107. }
  7108. } );
  7109. Object.assign( BufferAttribute.prototype, {
  7110. isBufferAttribute: true,
  7111. setArray: function ( array ) {
  7112. if ( Array.isArray( array ) ) {
  7113. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7114. }
  7115. this.count = array !== undefined ? array.length / this.itemSize : 0;
  7116. this.array = array;
  7117. },
  7118. setDynamic: function ( value ) {
  7119. this.dynamic = value;
  7120. return this;
  7121. },
  7122. copy: function ( source ) {
  7123. this.array = new source.array.constructor( source.array );
  7124. this.itemSize = source.itemSize;
  7125. this.count = source.count;
  7126. this.normalized = source.normalized;
  7127. this.dynamic = source.dynamic;
  7128. return this;
  7129. },
  7130. copyAt: function ( index1, attribute, index2 ) {
  7131. index1 *= this.itemSize;
  7132. index2 *= attribute.itemSize;
  7133. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  7134. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  7135. }
  7136. return this;
  7137. },
  7138. copyArray: function ( array ) {
  7139. this.array.set( array );
  7140. return this;
  7141. },
  7142. copyColorsArray: function ( colors ) {
  7143. var array = this.array, offset = 0;
  7144. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  7145. var color = colors[ i ];
  7146. if ( color === undefined ) {
  7147. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  7148. color = new Color();
  7149. }
  7150. array[ offset ++ ] = color.r;
  7151. array[ offset ++ ] = color.g;
  7152. array[ offset ++ ] = color.b;
  7153. }
  7154. return this;
  7155. },
  7156. copyIndicesArray: function ( indices ) {
  7157. var array = this.array, offset = 0;
  7158. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7159. var index = indices[ i ];
  7160. array[ offset ++ ] = index.a;
  7161. array[ offset ++ ] = index.b;
  7162. array[ offset ++ ] = index.c;
  7163. }
  7164. return this;
  7165. },
  7166. copyVector2sArray: function ( vectors ) {
  7167. var array = this.array, offset = 0;
  7168. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7169. var vector = vectors[ i ];
  7170. if ( vector === undefined ) {
  7171. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  7172. vector = new Vector2();
  7173. }
  7174. array[ offset ++ ] = vector.x;
  7175. array[ offset ++ ] = vector.y;
  7176. }
  7177. return this;
  7178. },
  7179. copyVector3sArray: function ( vectors ) {
  7180. var array = this.array, offset = 0;
  7181. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7182. var vector = vectors[ i ];
  7183. if ( vector === undefined ) {
  7184. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  7185. vector = new Vector3();
  7186. }
  7187. array[ offset ++ ] = vector.x;
  7188. array[ offset ++ ] = vector.y;
  7189. array[ offset ++ ] = vector.z;
  7190. }
  7191. return this;
  7192. },
  7193. copyVector4sArray: function ( vectors ) {
  7194. var array = this.array, offset = 0;
  7195. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7196. var vector = vectors[ i ];
  7197. if ( vector === undefined ) {
  7198. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  7199. vector = new Vector4();
  7200. }
  7201. array[ offset ++ ] = vector.x;
  7202. array[ offset ++ ] = vector.y;
  7203. array[ offset ++ ] = vector.z;
  7204. array[ offset ++ ] = vector.w;
  7205. }
  7206. return this;
  7207. },
  7208. set: function ( value, offset ) {
  7209. if ( offset === undefined ) offset = 0;
  7210. this.array.set( value, offset );
  7211. return this;
  7212. },
  7213. getX: function ( index ) {
  7214. return this.array[ index * this.itemSize ];
  7215. },
  7216. setX: function ( index, x ) {
  7217. this.array[ index * this.itemSize ] = x;
  7218. return this;
  7219. },
  7220. getY: function ( index ) {
  7221. return this.array[ index * this.itemSize + 1 ];
  7222. },
  7223. setY: function ( index, y ) {
  7224. this.array[ index * this.itemSize + 1 ] = y;
  7225. return this;
  7226. },
  7227. getZ: function ( index ) {
  7228. return this.array[ index * this.itemSize + 2 ];
  7229. },
  7230. setZ: function ( index, z ) {
  7231. this.array[ index * this.itemSize + 2 ] = z;
  7232. return this;
  7233. },
  7234. getW: function ( index ) {
  7235. return this.array[ index * this.itemSize + 3 ];
  7236. },
  7237. setW: function ( index, w ) {
  7238. this.array[ index * this.itemSize + 3 ] = w;
  7239. return this;
  7240. },
  7241. setXY: function ( index, x, y ) {
  7242. index *= this.itemSize;
  7243. this.array[ index + 0 ] = x;
  7244. this.array[ index + 1 ] = y;
  7245. return this;
  7246. },
  7247. setXYZ: function ( index, x, y, z ) {
  7248. index *= this.itemSize;
  7249. this.array[ index + 0 ] = x;
  7250. this.array[ index + 1 ] = y;
  7251. this.array[ index + 2 ] = z;
  7252. return this;
  7253. },
  7254. setXYZW: function ( index, x, y, z, w ) {
  7255. index *= this.itemSize;
  7256. this.array[ index + 0 ] = x;
  7257. this.array[ index + 1 ] = y;
  7258. this.array[ index + 2 ] = z;
  7259. this.array[ index + 3 ] = w;
  7260. return this;
  7261. },
  7262. onUpload: function ( callback ) {
  7263. this.onUploadCallback = callback;
  7264. return this;
  7265. },
  7266. clone: function () {
  7267. return new this.constructor( this.array, this.itemSize ).copy( this );
  7268. }
  7269. } );
  7270. //
  7271. function Int8BufferAttribute( array, itemSize ) {
  7272. BufferAttribute.call( this, new Int8Array( array ), itemSize );
  7273. }
  7274. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7275. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  7276. function Uint8BufferAttribute( array, itemSize ) {
  7277. BufferAttribute.call( this, new Uint8Array( array ), itemSize );
  7278. }
  7279. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7280. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  7281. function Uint8ClampedBufferAttribute( array, itemSize ) {
  7282. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize );
  7283. }
  7284. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7285. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  7286. function Int16BufferAttribute( array, itemSize ) {
  7287. BufferAttribute.call( this, new Int16Array( array ), itemSize );
  7288. }
  7289. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7290. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  7291. function Uint16BufferAttribute( array, itemSize ) {
  7292. BufferAttribute.call( this, new Uint16Array( array ), itemSize );
  7293. }
  7294. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7295. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  7296. function Int32BufferAttribute( array, itemSize ) {
  7297. BufferAttribute.call( this, new Int32Array( array ), itemSize );
  7298. }
  7299. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7300. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  7301. function Uint32BufferAttribute( array, itemSize ) {
  7302. BufferAttribute.call( this, new Uint32Array( array ), itemSize );
  7303. }
  7304. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7305. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  7306. function Float32BufferAttribute( array, itemSize ) {
  7307. BufferAttribute.call( this, new Float32Array( array ), itemSize );
  7308. }
  7309. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7310. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  7311. function Float64BufferAttribute( array, itemSize ) {
  7312. BufferAttribute.call( this, new Float64Array( array ), itemSize );
  7313. }
  7314. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  7315. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  7316. /**
  7317. * @author mrdoob / http://mrdoob.com/
  7318. */
  7319. function DirectGeometry() {
  7320. this.indices = [];
  7321. this.vertices = [];
  7322. this.normals = [];
  7323. this.colors = [];
  7324. this.uvs = [];
  7325. this.uvs2 = [];
  7326. this.groups = [];
  7327. this.morphTargets = {};
  7328. this.skinWeights = [];
  7329. this.skinIndices = [];
  7330. // this.lineDistances = [];
  7331. this.boundingBox = null;
  7332. this.boundingSphere = null;
  7333. // update flags
  7334. this.verticesNeedUpdate = false;
  7335. this.normalsNeedUpdate = false;
  7336. this.colorsNeedUpdate = false;
  7337. this.uvsNeedUpdate = false;
  7338. this.groupsNeedUpdate = false;
  7339. }
  7340. Object.assign( DirectGeometry.prototype, {
  7341. computeGroups: function ( geometry ) {
  7342. var group;
  7343. var groups = [];
  7344. var materialIndex = undefined;
  7345. var faces = geometry.faces;
  7346. for ( var i = 0; i < faces.length; i ++ ) {
  7347. var face = faces[ i ];
  7348. // materials
  7349. if ( face.materialIndex !== materialIndex ) {
  7350. materialIndex = face.materialIndex;
  7351. if ( group !== undefined ) {
  7352. group.count = ( i * 3 ) - group.start;
  7353. groups.push( group );
  7354. }
  7355. group = {
  7356. start: i * 3,
  7357. materialIndex: materialIndex
  7358. };
  7359. }
  7360. }
  7361. if ( group !== undefined ) {
  7362. group.count = ( i * 3 ) - group.start;
  7363. groups.push( group );
  7364. }
  7365. this.groups = groups;
  7366. },
  7367. fromGeometry: function ( geometry ) {
  7368. var faces = geometry.faces;
  7369. var vertices = geometry.vertices;
  7370. var faceVertexUvs = geometry.faceVertexUvs;
  7371. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  7372. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  7373. // morphs
  7374. var morphTargets = geometry.morphTargets;
  7375. var morphTargetsLength = morphTargets.length;
  7376. var morphTargetsPosition;
  7377. if ( morphTargetsLength > 0 ) {
  7378. morphTargetsPosition = [];
  7379. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  7380. morphTargetsPosition[ i ] = [];
  7381. }
  7382. this.morphTargets.position = morphTargetsPosition;
  7383. }
  7384. var morphNormals = geometry.morphNormals;
  7385. var morphNormalsLength = morphNormals.length;
  7386. var morphTargetsNormal;
  7387. if ( morphNormalsLength > 0 ) {
  7388. morphTargetsNormal = [];
  7389. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  7390. morphTargetsNormal[ i ] = [];
  7391. }
  7392. this.morphTargets.normal = morphTargetsNormal;
  7393. }
  7394. // skins
  7395. var skinIndices = geometry.skinIndices;
  7396. var skinWeights = geometry.skinWeights;
  7397. var hasSkinIndices = skinIndices.length === vertices.length;
  7398. var hasSkinWeights = skinWeights.length === vertices.length;
  7399. //
  7400. for ( var i = 0; i < faces.length; i ++ ) {
  7401. var face = faces[ i ];
  7402. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  7403. var vertexNormals = face.vertexNormals;
  7404. if ( vertexNormals.length === 3 ) {
  7405. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  7406. } else {
  7407. var normal = face.normal;
  7408. this.normals.push( normal, normal, normal );
  7409. }
  7410. var vertexColors = face.vertexColors;
  7411. if ( vertexColors.length === 3 ) {
  7412. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  7413. } else {
  7414. var color = face.color;
  7415. this.colors.push( color, color, color );
  7416. }
  7417. if ( hasFaceVertexUv === true ) {
  7418. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  7419. if ( vertexUvs !== undefined ) {
  7420. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  7421. } else {
  7422. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  7423. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  7424. }
  7425. }
  7426. if ( hasFaceVertexUv2 === true ) {
  7427. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  7428. if ( vertexUvs !== undefined ) {
  7429. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  7430. } else {
  7431. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  7432. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  7433. }
  7434. }
  7435. // morphs
  7436. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  7437. var morphTarget = morphTargets[ j ].vertices;
  7438. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  7439. }
  7440. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  7441. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  7442. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  7443. }
  7444. // skins
  7445. if ( hasSkinIndices ) {
  7446. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  7447. }
  7448. if ( hasSkinWeights ) {
  7449. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  7450. }
  7451. }
  7452. this.computeGroups( geometry );
  7453. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  7454. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  7455. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  7456. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  7457. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  7458. return this;
  7459. }
  7460. } );
  7461. function arrayMax( array ) {
  7462. if ( array.length === 0 ) return - Infinity;
  7463. var max = array[ 0 ];
  7464. for ( var i = 1, l = array.length; i < l; ++ i ) {
  7465. if ( array[ i ] > max ) max = array[ i ];
  7466. }
  7467. return max;
  7468. }
  7469. /**
  7470. * @author mrdoob / http://mrdoob.com/
  7471. * @author kile / http://kile.stravaganza.org/
  7472. * @author alteredq / http://alteredqualia.com/
  7473. * @author mikael emtinger / http://gomo.se/
  7474. * @author zz85 / http://www.lab4games.net/zz85/blog
  7475. * @author bhouston / http://clara.io
  7476. */
  7477. var count = 0;
  7478. function GeometryIdCount() { return count++; }
  7479. function Geometry() {
  7480. Object.defineProperty( this, 'id', { value: GeometryIdCount() } );
  7481. this.uuid = _Math.generateUUID();
  7482. this.name = '';
  7483. this.type = 'Geometry';
  7484. this.vertices = [];
  7485. this.colors = [];
  7486. this.faces = [];
  7487. this.faceVertexUvs = [[]];
  7488. this.morphTargets = [];
  7489. this.morphNormals = [];
  7490. this.skinWeights = [];
  7491. this.skinIndices = [];
  7492. this.lineDistances = [];
  7493. this.boundingBox = null;
  7494. this.boundingSphere = null;
  7495. // update flags
  7496. this.elementsNeedUpdate = false;
  7497. this.verticesNeedUpdate = false;
  7498. this.uvsNeedUpdate = false;
  7499. this.normalsNeedUpdate = false;
  7500. this.colorsNeedUpdate = false;
  7501. this.lineDistancesNeedUpdate = false;
  7502. this.groupsNeedUpdate = false;
  7503. }
  7504. Object.assign( Geometry.prototype, EventDispatcher.prototype, {
  7505. isGeometry: true,
  7506. applyMatrix: function ( matrix ) {
  7507. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7508. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  7509. var vertex = this.vertices[ i ];
  7510. vertex.applyMatrix4( matrix );
  7511. }
  7512. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  7513. var face = this.faces[ i ];
  7514. face.normal.applyMatrix3( normalMatrix ).normalize();
  7515. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  7516. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  7517. }
  7518. }
  7519. if ( this.boundingBox !== null ) {
  7520. this.computeBoundingBox();
  7521. }
  7522. if ( this.boundingSphere !== null ) {
  7523. this.computeBoundingSphere();
  7524. }
  7525. this.verticesNeedUpdate = true;
  7526. this.normalsNeedUpdate = true;
  7527. return this;
  7528. },
  7529. rotateX: function () {
  7530. // rotate geometry around world x-axis
  7531. var m1 = new Matrix4();
  7532. return function rotateX( angle ) {
  7533. m1.makeRotationX( angle );
  7534. this.applyMatrix( m1 );
  7535. return this;
  7536. };
  7537. }(),
  7538. rotateY: function () {
  7539. // rotate geometry around world y-axis
  7540. var m1 = new Matrix4();
  7541. return function rotateY( angle ) {
  7542. m1.makeRotationY( angle );
  7543. this.applyMatrix( m1 );
  7544. return this;
  7545. };
  7546. }(),
  7547. rotateZ: function () {
  7548. // rotate geometry around world z-axis
  7549. var m1 = new Matrix4();
  7550. return function rotateZ( angle ) {
  7551. m1.makeRotationZ( angle );
  7552. this.applyMatrix( m1 );
  7553. return this;
  7554. };
  7555. }(),
  7556. translate: function () {
  7557. // translate geometry
  7558. var m1 = new Matrix4();
  7559. return function translate( x, y, z ) {
  7560. m1.makeTranslation( x, y, z );
  7561. this.applyMatrix( m1 );
  7562. return this;
  7563. };
  7564. }(),
  7565. scale: function () {
  7566. // scale geometry
  7567. var m1 = new Matrix4();
  7568. return function scale( x, y, z ) {
  7569. m1.makeScale( x, y, z );
  7570. this.applyMatrix( m1 );
  7571. return this;
  7572. };
  7573. }(),
  7574. lookAt: function () {
  7575. var obj = new Object3D();
  7576. return function lookAt( vector ) {
  7577. obj.lookAt( vector );
  7578. obj.updateMatrix();
  7579. this.applyMatrix( obj.matrix );
  7580. };
  7581. }(),
  7582. fromBufferGeometry: function ( geometry ) {
  7583. var scope = this;
  7584. var indices = geometry.index !== null ? geometry.index.array : undefined;
  7585. var attributes = geometry.attributes;
  7586. var positions = attributes.position.array;
  7587. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  7588. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  7589. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  7590. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  7591. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  7592. var tempNormals = [];
  7593. var tempUVs = [];
  7594. var tempUVs2 = [];
  7595. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  7596. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  7597. if ( normals !== undefined ) {
  7598. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  7599. }
  7600. if ( colors !== undefined ) {
  7601. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  7602. }
  7603. if ( uvs !== undefined ) {
  7604. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  7605. }
  7606. if ( uvs2 !== undefined ) {
  7607. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  7608. }
  7609. }
  7610. function addFace( a, b, c, materialIndex ) {
  7611. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  7612. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  7613. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  7614. scope.faces.push( face );
  7615. if ( uvs !== undefined ) {
  7616. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  7617. }
  7618. if ( uvs2 !== undefined ) {
  7619. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  7620. }
  7621. }
  7622. var groups = geometry.groups;
  7623. if ( groups.length > 0 ) {
  7624. for ( var i = 0; i < groups.length; i ++ ) {
  7625. var group = groups[ i ];
  7626. var start = group.start;
  7627. var count = group.count;
  7628. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  7629. if ( indices !== undefined ) {
  7630. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  7631. } else {
  7632. addFace( j, j + 1, j + 2, group.materialIndex );
  7633. }
  7634. }
  7635. }
  7636. } else {
  7637. if ( indices !== undefined ) {
  7638. for ( var i = 0; i < indices.length; i += 3 ) {
  7639. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  7640. }
  7641. } else {
  7642. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  7643. addFace( i, i + 1, i + 2 );
  7644. }
  7645. }
  7646. }
  7647. this.computeFaceNormals();
  7648. if ( geometry.boundingBox !== null ) {
  7649. this.boundingBox = geometry.boundingBox.clone();
  7650. }
  7651. if ( geometry.boundingSphere !== null ) {
  7652. this.boundingSphere = geometry.boundingSphere.clone();
  7653. }
  7654. return this;
  7655. },
  7656. center: function () {
  7657. this.computeBoundingBox();
  7658. var offset = this.boundingBox.getCenter().negate();
  7659. this.translate( offset.x, offset.y, offset.z );
  7660. return offset;
  7661. },
  7662. normalize: function () {
  7663. this.computeBoundingSphere();
  7664. var center = this.boundingSphere.center;
  7665. var radius = this.boundingSphere.radius;
  7666. var s = radius === 0 ? 1 : 1.0 / radius;
  7667. var matrix = new Matrix4();
  7668. matrix.set(
  7669. s, 0, 0, - s * center.x,
  7670. 0, s, 0, - s * center.y,
  7671. 0, 0, s, - s * center.z,
  7672. 0, 0, 0, 1
  7673. );
  7674. this.applyMatrix( matrix );
  7675. return this;
  7676. },
  7677. computeFaceNormals: function () {
  7678. var cb = new Vector3(), ab = new Vector3();
  7679. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7680. var face = this.faces[ f ];
  7681. var vA = this.vertices[ face.a ];
  7682. var vB = this.vertices[ face.b ];
  7683. var vC = this.vertices[ face.c ];
  7684. cb.subVectors( vC, vB );
  7685. ab.subVectors( vA, vB );
  7686. cb.cross( ab );
  7687. cb.normalize();
  7688. face.normal.copy( cb );
  7689. }
  7690. },
  7691. computeVertexNormals: function ( areaWeighted ) {
  7692. if ( areaWeighted === undefined ) areaWeighted = true;
  7693. var v, vl, f, fl, face, vertices;
  7694. vertices = new Array( this.vertices.length );
  7695. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7696. vertices[ v ] = new Vector3();
  7697. }
  7698. if ( areaWeighted ) {
  7699. // vertex normals weighted by triangle areas
  7700. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7701. var vA, vB, vC;
  7702. var cb = new Vector3(), ab = new Vector3();
  7703. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7704. face = this.faces[ f ];
  7705. vA = this.vertices[ face.a ];
  7706. vB = this.vertices[ face.b ];
  7707. vC = this.vertices[ face.c ];
  7708. cb.subVectors( vC, vB );
  7709. ab.subVectors( vA, vB );
  7710. cb.cross( ab );
  7711. vertices[ face.a ].add( cb );
  7712. vertices[ face.b ].add( cb );
  7713. vertices[ face.c ].add( cb );
  7714. }
  7715. } else {
  7716. this.computeFaceNormals();
  7717. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7718. face = this.faces[ f ];
  7719. vertices[ face.a ].add( face.normal );
  7720. vertices[ face.b ].add( face.normal );
  7721. vertices[ face.c ].add( face.normal );
  7722. }
  7723. }
  7724. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7725. vertices[ v ].normalize();
  7726. }
  7727. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7728. face = this.faces[ f ];
  7729. var vertexNormals = face.vertexNormals;
  7730. if ( vertexNormals.length === 3 ) {
  7731. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7732. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7733. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7734. } else {
  7735. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7736. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7737. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7738. }
  7739. }
  7740. if ( this.faces.length > 0 ) {
  7741. this.normalsNeedUpdate = true;
  7742. }
  7743. },
  7744. computeFlatVertexNormals: function () {
  7745. var f, fl, face;
  7746. this.computeFaceNormals();
  7747. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7748. face = this.faces[ f ];
  7749. var vertexNormals = face.vertexNormals;
  7750. if ( vertexNormals.length === 3 ) {
  7751. vertexNormals[ 0 ].copy( face.normal );
  7752. vertexNormals[ 1 ].copy( face.normal );
  7753. vertexNormals[ 2 ].copy( face.normal );
  7754. } else {
  7755. vertexNormals[ 0 ] = face.normal.clone();
  7756. vertexNormals[ 1 ] = face.normal.clone();
  7757. vertexNormals[ 2 ] = face.normal.clone();
  7758. }
  7759. }
  7760. if ( this.faces.length > 0 ) {
  7761. this.normalsNeedUpdate = true;
  7762. }
  7763. },
  7764. computeMorphNormals: function () {
  7765. var i, il, f, fl, face;
  7766. // save original normals
  7767. // - create temp variables on first access
  7768. // otherwise just copy (for faster repeated calls)
  7769. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7770. face = this.faces[ f ];
  7771. if ( ! face.__originalFaceNormal ) {
  7772. face.__originalFaceNormal = face.normal.clone();
  7773. } else {
  7774. face.__originalFaceNormal.copy( face.normal );
  7775. }
  7776. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7777. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7778. if ( ! face.__originalVertexNormals[ i ] ) {
  7779. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7780. } else {
  7781. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7782. }
  7783. }
  7784. }
  7785. // use temp geometry to compute face and vertex normals for each morph
  7786. var tmpGeo = new Geometry();
  7787. tmpGeo.faces = this.faces;
  7788. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7789. // create on first access
  7790. if ( ! this.morphNormals[ i ] ) {
  7791. this.morphNormals[ i ] = {};
  7792. this.morphNormals[ i ].faceNormals = [];
  7793. this.morphNormals[ i ].vertexNormals = [];
  7794. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7795. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7796. var faceNormal, vertexNormals;
  7797. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7798. faceNormal = new Vector3();
  7799. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7800. dstNormalsFace.push( faceNormal );
  7801. dstNormalsVertex.push( vertexNormals );
  7802. }
  7803. }
  7804. var morphNormals = this.morphNormals[ i ];
  7805. // set vertices to morph target
  7806. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7807. // compute morph normals
  7808. tmpGeo.computeFaceNormals();
  7809. tmpGeo.computeVertexNormals();
  7810. // store morph normals
  7811. var faceNormal, vertexNormals;
  7812. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7813. face = this.faces[ f ];
  7814. faceNormal = morphNormals.faceNormals[ f ];
  7815. vertexNormals = morphNormals.vertexNormals[ f ];
  7816. faceNormal.copy( face.normal );
  7817. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7818. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7819. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7820. }
  7821. }
  7822. // restore original normals
  7823. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7824. face = this.faces[ f ];
  7825. face.normal = face.__originalFaceNormal;
  7826. face.vertexNormals = face.__originalVertexNormals;
  7827. }
  7828. },
  7829. computeLineDistances: function () {
  7830. var d = 0;
  7831. var vertices = this.vertices;
  7832. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  7833. if ( i > 0 ) {
  7834. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  7835. }
  7836. this.lineDistances[ i ] = d;
  7837. }
  7838. },
  7839. computeBoundingBox: function () {
  7840. if ( this.boundingBox === null ) {
  7841. this.boundingBox = new Box3();
  7842. }
  7843. this.boundingBox.setFromPoints( this.vertices );
  7844. },
  7845. computeBoundingSphere: function () {
  7846. if ( this.boundingSphere === null ) {
  7847. this.boundingSphere = new Sphere();
  7848. }
  7849. this.boundingSphere.setFromPoints( this.vertices );
  7850. },
  7851. merge: function ( geometry, matrix, materialIndexOffset ) {
  7852. if ( ( geometry && geometry.isGeometry ) === false ) {
  7853. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7854. return;
  7855. }
  7856. var normalMatrix,
  7857. vertexOffset = this.vertices.length,
  7858. vertices1 = this.vertices,
  7859. vertices2 = geometry.vertices,
  7860. faces1 = this.faces,
  7861. faces2 = geometry.faces,
  7862. uvs1 = this.faceVertexUvs[ 0 ],
  7863. uvs2 = geometry.faceVertexUvs[ 0 ],
  7864. colors1 = this.colors,
  7865. colors2 = geometry.colors;
  7866. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7867. if ( matrix !== undefined ) {
  7868. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7869. }
  7870. // vertices
  7871. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7872. var vertex = vertices2[ i ];
  7873. var vertexCopy = vertex.clone();
  7874. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7875. vertices1.push( vertexCopy );
  7876. }
  7877. // colors
  7878. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7879. colors1.push( colors2[ i ].clone() );
  7880. }
  7881. // faces
  7882. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7883. var face = faces2[ i ], faceCopy, normal, color,
  7884. faceVertexNormals = face.vertexNormals,
  7885. faceVertexColors = face.vertexColors;
  7886. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7887. faceCopy.normal.copy( face.normal );
  7888. if ( normalMatrix !== undefined ) {
  7889. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7890. }
  7891. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7892. normal = faceVertexNormals[ j ].clone();
  7893. if ( normalMatrix !== undefined ) {
  7894. normal.applyMatrix3( normalMatrix ).normalize();
  7895. }
  7896. faceCopy.vertexNormals.push( normal );
  7897. }
  7898. faceCopy.color.copy( face.color );
  7899. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7900. color = faceVertexColors[ j ];
  7901. faceCopy.vertexColors.push( color.clone() );
  7902. }
  7903. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7904. faces1.push( faceCopy );
  7905. }
  7906. // uvs
  7907. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  7908. var uv = uvs2[ i ], uvCopy = [];
  7909. if ( uv === undefined ) {
  7910. continue;
  7911. }
  7912. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  7913. uvCopy.push( uv[ j ].clone() );
  7914. }
  7915. uvs1.push( uvCopy );
  7916. }
  7917. },
  7918. mergeMesh: function ( mesh ) {
  7919. if ( ( mesh && mesh.isMesh ) === false ) {
  7920. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7921. return;
  7922. }
  7923. mesh.matrixAutoUpdate && mesh.updateMatrix();
  7924. this.merge( mesh.geometry, mesh.matrix );
  7925. },
  7926. /*
  7927. * Checks for duplicate vertices with hashmap.
  7928. * Duplicated vertices are removed
  7929. * and faces' vertices are updated.
  7930. */
  7931. mergeVertices: function () {
  7932. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7933. var unique = [], changes = [];
  7934. var v, key;
  7935. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7936. var precision = Math.pow( 10, precisionPoints );
  7937. var i, il, face;
  7938. var indices, j, jl;
  7939. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7940. v = this.vertices[ i ];
  7941. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7942. if ( verticesMap[ key ] === undefined ) {
  7943. verticesMap[ key ] = i;
  7944. unique.push( this.vertices[ i ] );
  7945. changes[ i ] = unique.length - 1;
  7946. } else {
  7947. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7948. changes[ i ] = changes[ verticesMap[ key ] ];
  7949. }
  7950. }
  7951. // if faces are completely degenerate after merging vertices, we
  7952. // have to remove them from the geometry.
  7953. var faceIndicesToRemove = [];
  7954. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7955. face = this.faces[ i ];
  7956. face.a = changes[ face.a ];
  7957. face.b = changes[ face.b ];
  7958. face.c = changes[ face.c ];
  7959. indices = [ face.a, face.b, face.c ];
  7960. // if any duplicate vertices are found in a Face3
  7961. // we have to remove the face as nothing can be saved
  7962. for ( var n = 0; n < 3; n ++ ) {
  7963. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7964. faceIndicesToRemove.push( i );
  7965. break;
  7966. }
  7967. }
  7968. }
  7969. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7970. var idx = faceIndicesToRemove[ i ];
  7971. this.faces.splice( idx, 1 );
  7972. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7973. this.faceVertexUvs[ j ].splice( idx, 1 );
  7974. }
  7975. }
  7976. // Use unique set of vertices
  7977. var diff = this.vertices.length - unique.length;
  7978. this.vertices = unique;
  7979. return diff;
  7980. },
  7981. sortFacesByMaterialIndex: function () {
  7982. var faces = this.faces;
  7983. var length = faces.length;
  7984. // tag faces
  7985. for ( var i = 0; i < length; i ++ ) {
  7986. faces[ i ]._id = i;
  7987. }
  7988. // sort faces
  7989. function materialIndexSort( a, b ) {
  7990. return a.materialIndex - b.materialIndex;
  7991. }
  7992. faces.sort( materialIndexSort );
  7993. // sort uvs
  7994. var uvs1 = this.faceVertexUvs[ 0 ];
  7995. var uvs2 = this.faceVertexUvs[ 1 ];
  7996. var newUvs1, newUvs2;
  7997. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7998. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7999. for ( var i = 0; i < length; i ++ ) {
  8000. var id = faces[ i ]._id;
  8001. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  8002. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  8003. }
  8004. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  8005. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  8006. },
  8007. toJSON: function () {
  8008. var data = {
  8009. metadata: {
  8010. version: 4.5,
  8011. type: 'Geometry',
  8012. generator: 'Geometry.toJSON'
  8013. }
  8014. };
  8015. // standard Geometry serialization
  8016. data.uuid = this.uuid;
  8017. data.type = this.type;
  8018. if ( this.name !== '' ) data.name = this.name;
  8019. if ( this.parameters !== undefined ) {
  8020. var parameters = this.parameters;
  8021. for ( var key in parameters ) {
  8022. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8023. }
  8024. return data;
  8025. }
  8026. var vertices = [];
  8027. for ( var i = 0; i < this.vertices.length; i ++ ) {
  8028. var vertex = this.vertices[ i ];
  8029. vertices.push( vertex.x, vertex.y, vertex.z );
  8030. }
  8031. var faces = [];
  8032. var normals = [];
  8033. var normalsHash = {};
  8034. var colors = [];
  8035. var colorsHash = {};
  8036. var uvs = [];
  8037. var uvsHash = {};
  8038. for ( var i = 0; i < this.faces.length; i ++ ) {
  8039. var face = this.faces[ i ];
  8040. var hasMaterial = true;
  8041. var hasFaceUv = false; // deprecated
  8042. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  8043. var hasFaceNormal = face.normal.length() > 0;
  8044. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  8045. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  8046. var hasFaceVertexColor = face.vertexColors.length > 0;
  8047. var faceType = 0;
  8048. faceType = setBit( faceType, 0, 0 ); // isQuad
  8049. faceType = setBit( faceType, 1, hasMaterial );
  8050. faceType = setBit( faceType, 2, hasFaceUv );
  8051. faceType = setBit( faceType, 3, hasFaceVertexUv );
  8052. faceType = setBit( faceType, 4, hasFaceNormal );
  8053. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  8054. faceType = setBit( faceType, 6, hasFaceColor );
  8055. faceType = setBit( faceType, 7, hasFaceVertexColor );
  8056. faces.push( faceType );
  8057. faces.push( face.a, face.b, face.c );
  8058. faces.push( face.materialIndex );
  8059. if ( hasFaceVertexUv ) {
  8060. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  8061. faces.push(
  8062. getUvIndex( faceVertexUvs[ 0 ] ),
  8063. getUvIndex( faceVertexUvs[ 1 ] ),
  8064. getUvIndex( faceVertexUvs[ 2 ] )
  8065. );
  8066. }
  8067. if ( hasFaceNormal ) {
  8068. faces.push( getNormalIndex( face.normal ) );
  8069. }
  8070. if ( hasFaceVertexNormal ) {
  8071. var vertexNormals = face.vertexNormals;
  8072. faces.push(
  8073. getNormalIndex( vertexNormals[ 0 ] ),
  8074. getNormalIndex( vertexNormals[ 1 ] ),
  8075. getNormalIndex( vertexNormals[ 2 ] )
  8076. );
  8077. }
  8078. if ( hasFaceColor ) {
  8079. faces.push( getColorIndex( face.color ) );
  8080. }
  8081. if ( hasFaceVertexColor ) {
  8082. var vertexColors = face.vertexColors;
  8083. faces.push(
  8084. getColorIndex( vertexColors[ 0 ] ),
  8085. getColorIndex( vertexColors[ 1 ] ),
  8086. getColorIndex( vertexColors[ 2 ] )
  8087. );
  8088. }
  8089. }
  8090. function setBit( value, position, enabled ) {
  8091. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  8092. }
  8093. function getNormalIndex( normal ) {
  8094. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  8095. if ( normalsHash[ hash ] !== undefined ) {
  8096. return normalsHash[ hash ];
  8097. }
  8098. normalsHash[ hash ] = normals.length / 3;
  8099. normals.push( normal.x, normal.y, normal.z );
  8100. return normalsHash[ hash ];
  8101. }
  8102. function getColorIndex( color ) {
  8103. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  8104. if ( colorsHash[ hash ] !== undefined ) {
  8105. return colorsHash[ hash ];
  8106. }
  8107. colorsHash[ hash ] = colors.length;
  8108. colors.push( color.getHex() );
  8109. return colorsHash[ hash ];
  8110. }
  8111. function getUvIndex( uv ) {
  8112. var hash = uv.x.toString() + uv.y.toString();
  8113. if ( uvsHash[ hash ] !== undefined ) {
  8114. return uvsHash[ hash ];
  8115. }
  8116. uvsHash[ hash ] = uvs.length / 2;
  8117. uvs.push( uv.x, uv.y );
  8118. return uvsHash[ hash ];
  8119. }
  8120. data.data = {};
  8121. data.data.vertices = vertices;
  8122. data.data.normals = normals;
  8123. if ( colors.length > 0 ) data.data.colors = colors;
  8124. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  8125. data.data.faces = faces;
  8126. return data;
  8127. },
  8128. clone: function () {
  8129. /*
  8130. // Handle primitives
  8131. var parameters = this.parameters;
  8132. if ( parameters !== undefined ) {
  8133. var values = [];
  8134. for ( var key in parameters ) {
  8135. values.push( parameters[ key ] );
  8136. }
  8137. var geometry = Object.create( this.constructor.prototype );
  8138. this.constructor.apply( geometry, values );
  8139. return geometry;
  8140. }
  8141. return new this.constructor().copy( this );
  8142. */
  8143. return new Geometry().copy( this );
  8144. },
  8145. copy: function ( source ) {
  8146. var i, il, j, jl, k, kl;
  8147. // reset
  8148. this.vertices = [];
  8149. this.colors = [];
  8150. this.faces = [];
  8151. this.faceVertexUvs = [[]];
  8152. this.morphTargets = [];
  8153. this.morphNormals = [];
  8154. this.skinWeights = [];
  8155. this.skinIndices = [];
  8156. this.lineDistances = [];
  8157. this.boundingBox = null;
  8158. this.boundingSphere = null;
  8159. // name
  8160. this.name = source.name;
  8161. // vertices
  8162. var vertices = source.vertices;
  8163. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  8164. this.vertices.push( vertices[ i ].clone() );
  8165. }
  8166. // colors
  8167. var colors = source.colors;
  8168. for ( i = 0, il = colors.length; i < il; i ++ ) {
  8169. this.colors.push( colors[ i ].clone() );
  8170. }
  8171. // faces
  8172. var faces = source.faces;
  8173. for ( i = 0, il = faces.length; i < il; i ++ ) {
  8174. this.faces.push( faces[ i ].clone() );
  8175. }
  8176. // face vertex uvs
  8177. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  8178. var faceVertexUvs = source.faceVertexUvs[ i ];
  8179. if ( this.faceVertexUvs[ i ] === undefined ) {
  8180. this.faceVertexUvs[ i ] = [];
  8181. }
  8182. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  8183. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  8184. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  8185. var uv = uvs[ k ];
  8186. uvsCopy.push( uv.clone() );
  8187. }
  8188. this.faceVertexUvs[ i ].push( uvsCopy );
  8189. }
  8190. }
  8191. // morph targets
  8192. var morphTargets = source.morphTargets;
  8193. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  8194. var morphTarget = {};
  8195. morphTarget.name = morphTargets[ i ].name;
  8196. // vertices
  8197. if ( morphTargets[ i ].vertices !== undefined ) {
  8198. morphTarget.vertices = [];
  8199. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  8200. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  8201. }
  8202. }
  8203. // normals
  8204. if ( morphTargets[ i ].normals !== undefined ) {
  8205. morphTarget.normals = [];
  8206. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  8207. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  8208. }
  8209. }
  8210. this.morphTargets.push( morphTarget );
  8211. }
  8212. // morph normals
  8213. var morphNormals = source.morphNormals;
  8214. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  8215. var morphNormal = {};
  8216. // vertex normals
  8217. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  8218. morphNormal.vertexNormals = [];
  8219. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  8220. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  8221. var destVertexNormal = {};
  8222. destVertexNormal.a = srcVertexNormal.a.clone();
  8223. destVertexNormal.b = srcVertexNormal.b.clone();
  8224. destVertexNormal.c = srcVertexNormal.c.clone();
  8225. morphNormal.vertexNormals.push( destVertexNormal );
  8226. }
  8227. }
  8228. // face normals
  8229. if ( morphNormals[ i ].faceNormals !== undefined ) {
  8230. morphNormal.faceNormals = [];
  8231. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  8232. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  8233. }
  8234. }
  8235. this.morphNormals.push( morphNormal );
  8236. }
  8237. // skin weights
  8238. var skinWeights = source.skinWeights;
  8239. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  8240. this.skinWeights.push( skinWeights[ i ].clone() );
  8241. }
  8242. // skin indices
  8243. var skinIndices = source.skinIndices;
  8244. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  8245. this.skinIndices.push( skinIndices[ i ].clone() );
  8246. }
  8247. // line distances
  8248. var lineDistances = source.lineDistances;
  8249. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  8250. this.lineDistances.push( lineDistances[ i ] );
  8251. }
  8252. // bounding box
  8253. var boundingBox = source.boundingBox;
  8254. if ( boundingBox !== null ) {
  8255. this.boundingBox = boundingBox.clone();
  8256. }
  8257. // bounding sphere
  8258. var boundingSphere = source.boundingSphere;
  8259. if ( boundingSphere !== null ) {
  8260. this.boundingSphere = boundingSphere.clone();
  8261. }
  8262. // update flags
  8263. this.elementsNeedUpdate = source.elementsNeedUpdate;
  8264. this.verticesNeedUpdate = source.verticesNeedUpdate;
  8265. this.uvsNeedUpdate = source.uvsNeedUpdate;
  8266. this.normalsNeedUpdate = source.normalsNeedUpdate;
  8267. this.colorsNeedUpdate = source.colorsNeedUpdate;
  8268. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  8269. this.groupsNeedUpdate = source.groupsNeedUpdate;
  8270. return this;
  8271. },
  8272. dispose: function () {
  8273. this.dispatchEvent( { type: 'dispose' } );
  8274. }
  8275. } );
  8276. /**
  8277. * @author alteredq / http://alteredqualia.com/
  8278. * @author mrdoob / http://mrdoob.com/
  8279. */
  8280. function BufferGeometry() {
  8281. Object.defineProperty( this, 'id', { value: GeometryIdCount() } );
  8282. this.uuid = _Math.generateUUID();
  8283. this.name = '';
  8284. this.type = 'BufferGeometry';
  8285. this.index = null;
  8286. this.attributes = {};
  8287. this.morphAttributes = {};
  8288. this.groups = [];
  8289. this.boundingBox = null;
  8290. this.boundingSphere = null;
  8291. this.drawRange = { start: 0, count: Infinity };
  8292. }
  8293. BufferGeometry.MaxIndex = 65535;
  8294. Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
  8295. isBufferGeometry: true,
  8296. getIndex: function () {
  8297. return this.index;
  8298. },
  8299. setIndex: function ( index ) {
  8300. if ( Array.isArray( index ) ) {
  8301. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  8302. } else {
  8303. this.index = index;
  8304. }
  8305. },
  8306. addAttribute: function ( name, attribute ) {
  8307. if ( ( attribute && attribute.isBufferAttribute ) === false && ( attribute && attribute.isInterleavedBufferAttribute ) === false ) {
  8308. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  8309. this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  8310. return;
  8311. }
  8312. if ( name === 'index' ) {
  8313. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  8314. this.setIndex( attribute );
  8315. return;
  8316. }
  8317. this.attributes[ name ] = attribute;
  8318. return this;
  8319. },
  8320. getAttribute: function ( name ) {
  8321. return this.attributes[ name ];
  8322. },
  8323. removeAttribute: function ( name ) {
  8324. delete this.attributes[ name ];
  8325. return this;
  8326. },
  8327. addGroup: function ( start, count, materialIndex ) {
  8328. this.groups.push( {
  8329. start: start,
  8330. count: count,
  8331. materialIndex: materialIndex !== undefined ? materialIndex : 0
  8332. } );
  8333. },
  8334. clearGroups: function () {
  8335. this.groups = [];
  8336. },
  8337. setDrawRange: function ( start, count ) {
  8338. this.drawRange.start = start;
  8339. this.drawRange.count = count;
  8340. },
  8341. applyMatrix: function ( matrix ) {
  8342. var position = this.attributes.position;
  8343. if ( position !== undefined ) {
  8344. matrix.applyToBufferAttribute( position );
  8345. position.needsUpdate = true;
  8346. }
  8347. var normal = this.attributes.normal;
  8348. if ( normal !== undefined ) {
  8349. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  8350. normalMatrix.applyToBufferAttribute( normal );
  8351. normal.needsUpdate = true;
  8352. }
  8353. if ( this.boundingBox !== null ) {
  8354. this.computeBoundingBox();
  8355. }
  8356. if ( this.boundingSphere !== null ) {
  8357. this.computeBoundingSphere();
  8358. }
  8359. return this;
  8360. },
  8361. rotateX: function () {
  8362. // rotate geometry around world x-axis
  8363. var m1 = new Matrix4();
  8364. return function rotateX( angle ) {
  8365. m1.makeRotationX( angle );
  8366. this.applyMatrix( m1 );
  8367. return this;
  8368. };
  8369. }(),
  8370. rotateY: function () {
  8371. // rotate geometry around world y-axis
  8372. var m1 = new Matrix4();
  8373. return function rotateY( angle ) {
  8374. m1.makeRotationY( angle );
  8375. this.applyMatrix( m1 );
  8376. return this;
  8377. };
  8378. }(),
  8379. rotateZ: function () {
  8380. // rotate geometry around world z-axis
  8381. var m1 = new Matrix4();
  8382. return function rotateZ( angle ) {
  8383. m1.makeRotationZ( angle );
  8384. this.applyMatrix( m1 );
  8385. return this;
  8386. };
  8387. }(),
  8388. translate: function () {
  8389. // translate geometry
  8390. var m1 = new Matrix4();
  8391. return function translate( x, y, z ) {
  8392. m1.makeTranslation( x, y, z );
  8393. this.applyMatrix( m1 );
  8394. return this;
  8395. };
  8396. }(),
  8397. scale: function () {
  8398. // scale geometry
  8399. var m1 = new Matrix4();
  8400. return function scale( x, y, z ) {
  8401. m1.makeScale( x, y, z );
  8402. this.applyMatrix( m1 );
  8403. return this;
  8404. };
  8405. }(),
  8406. lookAt: function () {
  8407. var obj = new Object3D();
  8408. return function lookAt( vector ) {
  8409. obj.lookAt( vector );
  8410. obj.updateMatrix();
  8411. this.applyMatrix( obj.matrix );
  8412. };
  8413. }(),
  8414. center: function () {
  8415. this.computeBoundingBox();
  8416. var offset = this.boundingBox.getCenter().negate();
  8417. this.translate( offset.x, offset.y, offset.z );
  8418. return offset;
  8419. },
  8420. setFromObject: function ( object ) {
  8421. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  8422. var geometry = object.geometry;
  8423. if ( object.isPoints || object.isLine ) {
  8424. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  8425. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  8426. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  8427. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  8428. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  8429. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  8430. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  8431. }
  8432. if ( geometry.boundingSphere !== null ) {
  8433. this.boundingSphere = geometry.boundingSphere.clone();
  8434. }
  8435. if ( geometry.boundingBox !== null ) {
  8436. this.boundingBox = geometry.boundingBox.clone();
  8437. }
  8438. } else if ( object.isMesh ) {
  8439. if ( geometry && geometry.isGeometry ) {
  8440. this.fromGeometry( geometry );
  8441. }
  8442. }
  8443. return this;
  8444. },
  8445. updateFromObject: function ( object ) {
  8446. var geometry = object.geometry;
  8447. if ( object.isMesh ) {
  8448. var direct = geometry.__directGeometry;
  8449. if ( geometry.elementsNeedUpdate === true ) {
  8450. direct = undefined;
  8451. geometry.elementsNeedUpdate = false;
  8452. }
  8453. if ( direct === undefined ) {
  8454. return this.fromGeometry( geometry );
  8455. }
  8456. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8457. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8458. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8459. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8460. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8461. geometry.verticesNeedUpdate = false;
  8462. geometry.normalsNeedUpdate = false;
  8463. geometry.colorsNeedUpdate = false;
  8464. geometry.uvsNeedUpdate = false;
  8465. geometry.groupsNeedUpdate = false;
  8466. geometry = direct;
  8467. }
  8468. var attribute;
  8469. if ( geometry.verticesNeedUpdate === true ) {
  8470. attribute = this.attributes.position;
  8471. if ( attribute !== undefined ) {
  8472. attribute.copyVector3sArray( geometry.vertices );
  8473. attribute.needsUpdate = true;
  8474. }
  8475. geometry.verticesNeedUpdate = false;
  8476. }
  8477. if ( geometry.normalsNeedUpdate === true ) {
  8478. attribute = this.attributes.normal;
  8479. if ( attribute !== undefined ) {
  8480. attribute.copyVector3sArray( geometry.normals );
  8481. attribute.needsUpdate = true;
  8482. }
  8483. geometry.normalsNeedUpdate = false;
  8484. }
  8485. if ( geometry.colorsNeedUpdate === true ) {
  8486. attribute = this.attributes.color;
  8487. if ( attribute !== undefined ) {
  8488. attribute.copyColorsArray( geometry.colors );
  8489. attribute.needsUpdate = true;
  8490. }
  8491. geometry.colorsNeedUpdate = false;
  8492. }
  8493. if ( geometry.uvsNeedUpdate ) {
  8494. attribute = this.attributes.uv;
  8495. if ( attribute !== undefined ) {
  8496. attribute.copyVector2sArray( geometry.uvs );
  8497. attribute.needsUpdate = true;
  8498. }
  8499. geometry.uvsNeedUpdate = false;
  8500. }
  8501. if ( geometry.lineDistancesNeedUpdate ) {
  8502. attribute = this.attributes.lineDistance;
  8503. if ( attribute !== undefined ) {
  8504. attribute.copyArray( geometry.lineDistances );
  8505. attribute.needsUpdate = true;
  8506. }
  8507. geometry.lineDistancesNeedUpdate = false;
  8508. }
  8509. if ( geometry.groupsNeedUpdate ) {
  8510. geometry.computeGroups( object.geometry );
  8511. this.groups = geometry.groups;
  8512. geometry.groupsNeedUpdate = false;
  8513. }
  8514. return this;
  8515. },
  8516. fromGeometry: function ( geometry ) {
  8517. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  8518. return this.fromDirectGeometry( geometry.__directGeometry );
  8519. },
  8520. fromDirectGeometry: function ( geometry ) {
  8521. var positions = new Float32Array( geometry.vertices.length * 3 );
  8522. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  8523. if ( geometry.normals.length > 0 ) {
  8524. var normals = new Float32Array( geometry.normals.length * 3 );
  8525. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  8526. }
  8527. if ( geometry.colors.length > 0 ) {
  8528. var colors = new Float32Array( geometry.colors.length * 3 );
  8529. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  8530. }
  8531. if ( geometry.uvs.length > 0 ) {
  8532. var uvs = new Float32Array( geometry.uvs.length * 2 );
  8533. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  8534. }
  8535. if ( geometry.uvs2.length > 0 ) {
  8536. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  8537. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  8538. }
  8539. if ( geometry.indices.length > 0 ) {
  8540. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  8541. var indices = new TypeArray( geometry.indices.length * 3 );
  8542. this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  8543. }
  8544. // groups
  8545. this.groups = geometry.groups;
  8546. // morphs
  8547. for ( var name in geometry.morphTargets ) {
  8548. var array = [];
  8549. var morphTargets = geometry.morphTargets[ name ];
  8550. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  8551. var morphTarget = morphTargets[ i ];
  8552. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  8553. array.push( attribute.copyVector3sArray( morphTarget ) );
  8554. }
  8555. this.morphAttributes[ name ] = array;
  8556. }
  8557. // skinning
  8558. if ( geometry.skinIndices.length > 0 ) {
  8559. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  8560. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  8561. }
  8562. if ( geometry.skinWeights.length > 0 ) {
  8563. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  8564. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  8565. }
  8566. //
  8567. if ( geometry.boundingSphere !== null ) {
  8568. this.boundingSphere = geometry.boundingSphere.clone();
  8569. }
  8570. if ( geometry.boundingBox !== null ) {
  8571. this.boundingBox = geometry.boundingBox.clone();
  8572. }
  8573. return this;
  8574. },
  8575. computeBoundingBox: function () {
  8576. if ( this.boundingBox === null ) {
  8577. this.boundingBox = new Box3();
  8578. }
  8579. var position = this.attributes.position;
  8580. if ( position !== undefined ) {
  8581. this.boundingBox.setFromBufferAttribute( position );
  8582. } else {
  8583. this.boundingBox.makeEmpty();
  8584. }
  8585. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  8586. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  8587. }
  8588. },
  8589. computeBoundingSphere: function () {
  8590. var box = new Box3();
  8591. var vector = new Vector3();
  8592. return function computeBoundingSphere() {
  8593. if ( this.boundingSphere === null ) {
  8594. this.boundingSphere = new Sphere();
  8595. }
  8596. var position = this.attributes.position;
  8597. if ( position ) {
  8598. var center = this.boundingSphere.center;
  8599. box.setFromBufferAttribute( position );
  8600. box.getCenter( center );
  8601. // hoping to find a boundingSphere with a radius smaller than the
  8602. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  8603. var maxRadiusSq = 0;
  8604. for ( var i = 0, il = position.count; i < il; i ++ ) {
  8605. vector.x = position.getX( i );
  8606. vector.y = position.getY( i );
  8607. vector.z = position.getZ( i );
  8608. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  8609. }
  8610. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  8611. if ( isNaN( this.boundingSphere.radius ) ) {
  8612. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  8613. }
  8614. }
  8615. };
  8616. }(),
  8617. computeFaceNormals: function () {
  8618. // backwards compatibility
  8619. },
  8620. computeVertexNormals: function () {
  8621. var index = this.index;
  8622. var attributes = this.attributes;
  8623. var groups = this.groups;
  8624. if ( attributes.position ) {
  8625. var positions = attributes.position.array;
  8626. if ( attributes.normal === undefined ) {
  8627. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  8628. } else {
  8629. // reset existing normals to zero
  8630. var array = attributes.normal.array;
  8631. for ( var i = 0, il = array.length; i < il; i ++ ) {
  8632. array[ i ] = 0;
  8633. }
  8634. }
  8635. var normals = attributes.normal.array;
  8636. var vA, vB, vC;
  8637. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  8638. var cb = new Vector3(), ab = new Vector3();
  8639. // indexed elements
  8640. if ( index ) {
  8641. var indices = index.array;
  8642. if ( groups.length === 0 ) {
  8643. this.addGroup( 0, indices.length );
  8644. }
  8645. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  8646. var group = groups[ j ];
  8647. var start = group.start;
  8648. var count = group.count;
  8649. for ( var i = start, il = start + count; i < il; i += 3 ) {
  8650. vA = indices[ i + 0 ] * 3;
  8651. vB = indices[ i + 1 ] * 3;
  8652. vC = indices[ i + 2 ] * 3;
  8653. pA.fromArray( positions, vA );
  8654. pB.fromArray( positions, vB );
  8655. pC.fromArray( positions, vC );
  8656. cb.subVectors( pC, pB );
  8657. ab.subVectors( pA, pB );
  8658. cb.cross( ab );
  8659. normals[ vA ] += cb.x;
  8660. normals[ vA + 1 ] += cb.y;
  8661. normals[ vA + 2 ] += cb.z;
  8662. normals[ vB ] += cb.x;
  8663. normals[ vB + 1 ] += cb.y;
  8664. normals[ vB + 2 ] += cb.z;
  8665. normals[ vC ] += cb.x;
  8666. normals[ vC + 1 ] += cb.y;
  8667. normals[ vC + 2 ] += cb.z;
  8668. }
  8669. }
  8670. } else {
  8671. // non-indexed elements (unconnected triangle soup)
  8672. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  8673. pA.fromArray( positions, i );
  8674. pB.fromArray( positions, i + 3 );
  8675. pC.fromArray( positions, i + 6 );
  8676. cb.subVectors( pC, pB );
  8677. ab.subVectors( pA, pB );
  8678. cb.cross( ab );
  8679. normals[ i ] = cb.x;
  8680. normals[ i + 1 ] = cb.y;
  8681. normals[ i + 2 ] = cb.z;
  8682. normals[ i + 3 ] = cb.x;
  8683. normals[ i + 4 ] = cb.y;
  8684. normals[ i + 5 ] = cb.z;
  8685. normals[ i + 6 ] = cb.x;
  8686. normals[ i + 7 ] = cb.y;
  8687. normals[ i + 8 ] = cb.z;
  8688. }
  8689. }
  8690. this.normalizeNormals();
  8691. attributes.normal.needsUpdate = true;
  8692. }
  8693. },
  8694. merge: function ( geometry, offset ) {
  8695. if ( ( geometry && geometry.isBufferGeometry ) === false ) {
  8696. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  8697. return;
  8698. }
  8699. if ( offset === undefined ) offset = 0;
  8700. var attributes = this.attributes;
  8701. for ( var key in attributes ) {
  8702. if ( geometry.attributes[ key ] === undefined ) continue;
  8703. var attribute1 = attributes[ key ];
  8704. var attributeArray1 = attribute1.array;
  8705. var attribute2 = geometry.attributes[ key ];
  8706. var attributeArray2 = attribute2.array;
  8707. var attributeSize = attribute2.itemSize;
  8708. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  8709. attributeArray1[ j ] = attributeArray2[ i ];
  8710. }
  8711. }
  8712. return this;
  8713. },
  8714. normalizeNormals: function () {
  8715. var normals = this.attributes.normal;
  8716. var x, y, z, n;
  8717. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  8718. x = normals.getX( i );
  8719. y = normals.getY( i );
  8720. z = normals.getZ( i );
  8721. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  8722. normals.setXYZ( i, x * n, y * n, z * n );
  8723. }
  8724. },
  8725. toNonIndexed: function () {
  8726. if ( this.index === null ) {
  8727. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  8728. return this;
  8729. }
  8730. var geometry2 = new BufferGeometry();
  8731. var indices = this.index.array;
  8732. var attributes = this.attributes;
  8733. for ( var name in attributes ) {
  8734. var attribute = attributes[ name ];
  8735. var array = attribute.array;
  8736. var itemSize = attribute.itemSize;
  8737. var array2 = new array.constructor( indices.length * itemSize );
  8738. var index = 0, index2 = 0;
  8739. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8740. index = indices[ i ] * itemSize;
  8741. for ( var j = 0; j < itemSize; j ++ ) {
  8742. array2[ index2 ++ ] = array[ index ++ ];
  8743. }
  8744. }
  8745. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  8746. }
  8747. return geometry2;
  8748. },
  8749. toJSON: function () {
  8750. var data = {
  8751. metadata: {
  8752. version: 4.5,
  8753. type: 'BufferGeometry',
  8754. generator: 'BufferGeometry.toJSON'
  8755. }
  8756. };
  8757. // standard BufferGeometry serialization
  8758. data.uuid = this.uuid;
  8759. data.type = this.type;
  8760. if ( this.name !== '' ) data.name = this.name;
  8761. if ( this.parameters !== undefined ) {
  8762. var parameters = this.parameters;
  8763. for ( var key in parameters ) {
  8764. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8765. }
  8766. return data;
  8767. }
  8768. data.data = { attributes: {} };
  8769. var index = this.index;
  8770. if ( index !== null ) {
  8771. var array = Array.prototype.slice.call( index.array );
  8772. data.data.index = {
  8773. type: index.array.constructor.name,
  8774. array: array
  8775. };
  8776. }
  8777. var attributes = this.attributes;
  8778. for ( var key in attributes ) {
  8779. var attribute = attributes[ key ];
  8780. var array = Array.prototype.slice.call( attribute.array );
  8781. data.data.attributes[ key ] = {
  8782. itemSize: attribute.itemSize,
  8783. type: attribute.array.constructor.name,
  8784. array: array,
  8785. normalized: attribute.normalized
  8786. };
  8787. }
  8788. var groups = this.groups;
  8789. if ( groups.length > 0 ) {
  8790. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  8791. }
  8792. var boundingSphere = this.boundingSphere;
  8793. if ( boundingSphere !== null ) {
  8794. data.data.boundingSphere = {
  8795. center: boundingSphere.center.toArray(),
  8796. radius: boundingSphere.radius
  8797. };
  8798. }
  8799. return data;
  8800. },
  8801. clone: function () {
  8802. /*
  8803. // Handle primitives
  8804. var parameters = this.parameters;
  8805. if ( parameters !== undefined ) {
  8806. var values = [];
  8807. for ( var key in parameters ) {
  8808. values.push( parameters[ key ] );
  8809. }
  8810. var geometry = Object.create( this.constructor.prototype );
  8811. this.constructor.apply( geometry, values );
  8812. return geometry;
  8813. }
  8814. return new this.constructor().copy( this );
  8815. */
  8816. return new BufferGeometry().copy( this );
  8817. },
  8818. copy: function ( source ) {
  8819. var name, i, l;
  8820. // reset
  8821. this.index = null;
  8822. this.attributes = {};
  8823. this.morphAttributes = {};
  8824. this.groups = [];
  8825. this.boundingBox = null;
  8826. this.boundingSphere = null;
  8827. // name
  8828. this.name = source.name;
  8829. // index
  8830. var index = source.index;
  8831. if ( index !== null ) {
  8832. this.setIndex( index.clone() );
  8833. }
  8834. // attributes
  8835. var attributes = source.attributes;
  8836. for ( name in attributes ) {
  8837. var attribute = attributes[ name ];
  8838. this.addAttribute( name, attribute.clone() );
  8839. }
  8840. // morph attributes
  8841. var morphAttributes = source.morphAttributes;
  8842. for ( name in morphAttributes ) {
  8843. var array = [];
  8844. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  8845. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  8846. array.push( morphAttribute[ i ].clone() );
  8847. }
  8848. this.morphAttributes[ name ] = array;
  8849. }
  8850. // groups
  8851. var groups = source.groups;
  8852. for ( i = 0, l = groups.length; i < l; i ++ ) {
  8853. var group = groups[ i ];
  8854. this.addGroup( group.start, group.count, group.materialIndex );
  8855. }
  8856. // bounding box
  8857. var boundingBox = source.boundingBox;
  8858. if ( boundingBox !== null ) {
  8859. this.boundingBox = boundingBox.clone();
  8860. }
  8861. // bounding sphere
  8862. var boundingSphere = source.boundingSphere;
  8863. if ( boundingSphere !== null ) {
  8864. this.boundingSphere = boundingSphere.clone();
  8865. }
  8866. // draw range
  8867. this.drawRange.start = source.drawRange.start;
  8868. this.drawRange.count = source.drawRange.count;
  8869. return this;
  8870. },
  8871. dispose: function () {
  8872. this.dispatchEvent( { type: 'dispose' } );
  8873. }
  8874. } );
  8875. /**
  8876. * @author mrdoob / http://mrdoob.com/
  8877. * @author alteredq / http://alteredqualia.com/
  8878. * @author mikael emtinger / http://gomo.se/
  8879. * @author jonobr1 / http://jonobr1.com/
  8880. */
  8881. function Mesh( geometry, material ) {
  8882. Object3D.call( this );
  8883. this.type = 'Mesh';
  8884. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8885. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8886. this.drawMode = TrianglesDrawMode;
  8887. this.updateMorphTargets();
  8888. }
  8889. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8890. constructor: Mesh,
  8891. isMesh: true,
  8892. setDrawMode: function ( value ) {
  8893. this.drawMode = value;
  8894. },
  8895. copy: function ( source ) {
  8896. Object3D.prototype.copy.call( this, source );
  8897. this.drawMode = source.drawMode;
  8898. return this;
  8899. },
  8900. updateMorphTargets: function () {
  8901. var geometry = this.geometry;
  8902. var m, ml, name;
  8903. if ( geometry.isBufferGeometry ) {
  8904. var morphAttributes = geometry.morphAttributes;
  8905. var keys = Object.keys( morphAttributes );
  8906. if ( keys.length > 0 ) {
  8907. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8908. if ( morphAttribute !== undefined ) {
  8909. this.morphTargetInfluences = [];
  8910. this.morphTargetDictionary = {};
  8911. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8912. name = morphAttribute[ m ].name || String( m );
  8913. this.morphTargetInfluences.push( 0 );
  8914. this.morphTargetDictionary[ name ] = m;
  8915. }
  8916. }
  8917. }
  8918. } else {
  8919. var morphTargets = geometry.morphTargets;
  8920. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8921. this.morphTargetInfluences = [];
  8922. this.morphTargetDictionary = {};
  8923. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  8924. name = morphTargets[ m ].name || String( m );
  8925. this.morphTargetInfluences.push( 0 );
  8926. this.morphTargetDictionary[ name ] = m;
  8927. }
  8928. }
  8929. }
  8930. },
  8931. raycast: ( function () {
  8932. var inverseMatrix = new Matrix4();
  8933. var ray = new Ray();
  8934. var sphere = new Sphere();
  8935. var vA = new Vector3();
  8936. var vB = new Vector3();
  8937. var vC = new Vector3();
  8938. var tempA = new Vector3();
  8939. var tempB = new Vector3();
  8940. var tempC = new Vector3();
  8941. var uvA = new Vector2();
  8942. var uvB = new Vector2();
  8943. var uvC = new Vector2();
  8944. var barycoord = new Vector3();
  8945. var intersectionPoint = new Vector3();
  8946. var intersectionPointWorld = new Vector3();
  8947. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  8948. Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  8949. uv1.multiplyScalar( barycoord.x );
  8950. uv2.multiplyScalar( barycoord.y );
  8951. uv3.multiplyScalar( barycoord.z );
  8952. uv1.add( uv2 ).add( uv3 );
  8953. return uv1.clone();
  8954. }
  8955. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  8956. var intersect;
  8957. var material = object.material;
  8958. if ( material.side === BackSide ) {
  8959. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8960. } else {
  8961. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8962. }
  8963. if ( intersect === null ) return null;
  8964. intersectionPointWorld.copy( point );
  8965. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8966. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8967. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8968. return {
  8969. distance: distance,
  8970. point: intersectionPointWorld.clone(),
  8971. object: object
  8972. };
  8973. }
  8974. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  8975. vA.fromBufferAttribute( position, a );
  8976. vB.fromBufferAttribute( position, b );
  8977. vC.fromBufferAttribute( position, c );
  8978. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  8979. if ( intersection ) {
  8980. if ( uv ) {
  8981. uvA.fromBufferAttribute( uv, a );
  8982. uvB.fromBufferAttribute( uv, b );
  8983. uvC.fromBufferAttribute( uv, c );
  8984. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  8985. }
  8986. intersection.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) );
  8987. intersection.faceIndex = a;
  8988. }
  8989. return intersection;
  8990. }
  8991. return function raycast( raycaster, intersects ) {
  8992. var geometry = this.geometry;
  8993. var material = this.material;
  8994. var matrixWorld = this.matrixWorld;
  8995. if ( material === undefined ) return;
  8996. // Checking boundingSphere distance to ray
  8997. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8998. sphere.copy( geometry.boundingSphere );
  8999. sphere.applyMatrix4( matrixWorld );
  9000. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  9001. //
  9002. inverseMatrix.getInverse( matrixWorld );
  9003. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9004. // Check boundingBox before continuing
  9005. if ( geometry.boundingBox !== null ) {
  9006. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  9007. }
  9008. var intersection;
  9009. if ( geometry.isBufferGeometry ) {
  9010. var a, b, c;
  9011. var index = geometry.index;
  9012. var position = geometry.attributes.position;
  9013. var uv = geometry.attributes.uv;
  9014. var i, l;
  9015. if ( index !== null ) {
  9016. // indexed buffer geometry
  9017. for ( i = 0, l = index.count; i < l; i += 3 ) {
  9018. a = index.getX( i );
  9019. b = index.getX( i + 1 );
  9020. c = index.getX( i + 2 );
  9021. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9022. if ( intersection ) {
  9023. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  9024. intersects.push( intersection );
  9025. }
  9026. }
  9027. } else {
  9028. // non-indexed buffer geometry
  9029. for ( i = 0, l = position.count; i < l; i += 3 ) {
  9030. a = i;
  9031. b = i + 1;
  9032. c = i + 2;
  9033. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9034. if ( intersection ) {
  9035. intersection.index = a; // triangle number in positions buffer semantics
  9036. intersects.push( intersection );
  9037. }
  9038. }
  9039. }
  9040. } else if ( geometry.isGeometry ) {
  9041. var fvA, fvB, fvC;
  9042. var isMultiMaterial = Array.isArray( material );
  9043. var vertices = geometry.vertices;
  9044. var faces = geometry.faces;
  9045. var uvs;
  9046. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  9047. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  9048. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  9049. var face = faces[ f ];
  9050. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  9051. if ( faceMaterial === undefined ) continue;
  9052. fvA = vertices[ face.a ];
  9053. fvB = vertices[ face.b ];
  9054. fvC = vertices[ face.c ];
  9055. if ( faceMaterial.morphTargets === true ) {
  9056. var morphTargets = geometry.morphTargets;
  9057. var morphInfluences = this.morphTargetInfluences;
  9058. vA.set( 0, 0, 0 );
  9059. vB.set( 0, 0, 0 );
  9060. vC.set( 0, 0, 0 );
  9061. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  9062. var influence = morphInfluences[ t ];
  9063. if ( influence === 0 ) continue;
  9064. var targets = morphTargets[ t ].vertices;
  9065. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  9066. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  9067. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  9068. }
  9069. vA.add( fvA );
  9070. vB.add( fvB );
  9071. vC.add( fvC );
  9072. fvA = vA;
  9073. fvB = vB;
  9074. fvC = vC;
  9075. }
  9076. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  9077. if ( intersection ) {
  9078. if ( uvs && uvs[ f ] ) {
  9079. var uvs_f = uvs[ f ];
  9080. uvA.copy( uvs_f[ 0 ] );
  9081. uvB.copy( uvs_f[ 1 ] );
  9082. uvC.copy( uvs_f[ 2 ] );
  9083. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  9084. }
  9085. intersection.face = face;
  9086. intersection.faceIndex = f;
  9087. intersects.push( intersection );
  9088. }
  9089. }
  9090. }
  9091. };
  9092. }() ),
  9093. clone: function () {
  9094. return new this.constructor( this.geometry, this.material ).copy( this );
  9095. }
  9096. } );
  9097. /**
  9098. * @author mrdoob / http://mrdoob.com/
  9099. * @author Mugen87 / https://github.com/Mugen87
  9100. */
  9101. // BoxGeometry
  9102. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9103. Geometry.call( this );
  9104. this.type = 'BoxGeometry';
  9105. this.parameters = {
  9106. width: width,
  9107. height: height,
  9108. depth: depth,
  9109. widthSegments: widthSegments,
  9110. heightSegments: heightSegments,
  9111. depthSegments: depthSegments
  9112. };
  9113. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  9114. this.mergeVertices();
  9115. }
  9116. BoxGeometry.prototype = Object.create( Geometry.prototype );
  9117. BoxGeometry.prototype.constructor = BoxGeometry;
  9118. // BoxBufferGeometry
  9119. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9120. BufferGeometry.call( this );
  9121. this.type = 'BoxBufferGeometry';
  9122. this.parameters = {
  9123. width: width,
  9124. height: height,
  9125. depth: depth,
  9126. widthSegments: widthSegments,
  9127. heightSegments: heightSegments,
  9128. depthSegments: depthSegments
  9129. };
  9130. var scope = this;
  9131. // segments
  9132. widthSegments = Math.floor( widthSegments ) || 1;
  9133. heightSegments = Math.floor( heightSegments ) || 1;
  9134. depthSegments = Math.floor( depthSegments ) || 1;
  9135. // buffers
  9136. var indices = [];
  9137. var vertices = [];
  9138. var normals = [];
  9139. var uvs = [];
  9140. // helper variables
  9141. var numberOfVertices = 0;
  9142. var groupStart = 0;
  9143. // build each side of the box geometry
  9144. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  9145. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  9146. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  9147. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  9148. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  9149. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  9150. // build geometry
  9151. this.setIndex( indices );
  9152. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9153. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9154. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9155. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  9156. var segmentWidth = width / gridX;
  9157. var segmentHeight = height / gridY;
  9158. var widthHalf = width / 2;
  9159. var heightHalf = height / 2;
  9160. var depthHalf = depth / 2;
  9161. var gridX1 = gridX + 1;
  9162. var gridY1 = gridY + 1;
  9163. var vertexCounter = 0;
  9164. var groupCount = 0;
  9165. var ix, iy;
  9166. var vector = new Vector3();
  9167. // generate vertices, normals and uvs
  9168. for ( iy = 0; iy < gridY1; iy ++ ) {
  9169. var y = iy * segmentHeight - heightHalf;
  9170. for ( ix = 0; ix < gridX1; ix ++ ) {
  9171. var x = ix * segmentWidth - widthHalf;
  9172. // set values to correct vector component
  9173. vector[ u ] = x * udir;
  9174. vector[ v ] = y * vdir;
  9175. vector[ w ] = depthHalf;
  9176. // now apply vector to vertex buffer
  9177. vertices.push( vector.x, vector.y, vector.z );
  9178. // set values to correct vector component
  9179. vector[ u ] = 0;
  9180. vector[ v ] = 0;
  9181. vector[ w ] = depth > 0 ? 1 : - 1;
  9182. // now apply vector to normal buffer
  9183. normals.push( vector.x, vector.y, vector.z );
  9184. // uvs
  9185. uvs.push( ix / gridX );
  9186. uvs.push( 1 - ( iy / gridY ) );
  9187. // counters
  9188. vertexCounter += 1;
  9189. }
  9190. }
  9191. // indices
  9192. // 1. you need three indices to draw a single face
  9193. // 2. a single segment consists of two faces
  9194. // 3. so we need to generate six (2*3) indices per segment
  9195. for ( iy = 0; iy < gridY; iy ++ ) {
  9196. for ( ix = 0; ix < gridX; ix ++ ) {
  9197. var a = numberOfVertices + ix + gridX1 * iy;
  9198. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  9199. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  9200. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  9201. // faces
  9202. indices.push( a, b, d );
  9203. indices.push( b, c, d );
  9204. // increase counter
  9205. groupCount += 6;
  9206. }
  9207. }
  9208. // add a group to the geometry. this will ensure multi material support
  9209. scope.addGroup( groupStart, groupCount, materialIndex );
  9210. // calculate new start value for groups
  9211. groupStart += groupCount;
  9212. // update total number of vertices
  9213. numberOfVertices += vertexCounter;
  9214. }
  9215. }
  9216. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9217. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  9218. /**
  9219. * @author mrdoob / http://mrdoob.com/
  9220. * @author Mugen87 / https://github.com/Mugen87
  9221. */
  9222. // PlaneGeometry
  9223. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  9224. Geometry.call( this );
  9225. this.type = 'PlaneGeometry';
  9226. this.parameters = {
  9227. width: width,
  9228. height: height,
  9229. widthSegments: widthSegments,
  9230. heightSegments: heightSegments
  9231. };
  9232. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  9233. this.mergeVertices();
  9234. }
  9235. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  9236. PlaneGeometry.prototype.constructor = PlaneGeometry;
  9237. // PlaneBufferGeometry
  9238. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  9239. BufferGeometry.call( this );
  9240. this.type = 'PlaneBufferGeometry';
  9241. this.parameters = {
  9242. width: width,
  9243. height: height,
  9244. widthSegments: widthSegments,
  9245. heightSegments: heightSegments
  9246. };
  9247. var width_half = width / 2;
  9248. var height_half = height / 2;
  9249. var gridX = Math.floor( widthSegments ) || 1;
  9250. var gridY = Math.floor( heightSegments ) || 1;
  9251. var gridX1 = gridX + 1;
  9252. var gridY1 = gridY + 1;
  9253. var segment_width = width / gridX;
  9254. var segment_height = height / gridY;
  9255. var ix, iy;
  9256. // buffers
  9257. var indices = [];
  9258. var vertices = [];
  9259. var normals = [];
  9260. var uvs = [];
  9261. // generate vertices, normals and uvs
  9262. for ( iy = 0; iy < gridY1; iy ++ ) {
  9263. var y = iy * segment_height - height_half;
  9264. for ( ix = 0; ix < gridX1; ix ++ ) {
  9265. var x = ix * segment_width - width_half;
  9266. vertices.push( x, - y, 0 );
  9267. normals.push( 0, 0, 1 );
  9268. uvs.push( ix / gridX );
  9269. uvs.push( 1 - ( iy / gridY ) );
  9270. }
  9271. }
  9272. // indices
  9273. for ( iy = 0; iy < gridY; iy ++ ) {
  9274. for ( ix = 0; ix < gridX; ix ++ ) {
  9275. var a = ix + gridX1 * iy;
  9276. var b = ix + gridX1 * ( iy + 1 );
  9277. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  9278. var d = ( ix + 1 ) + gridX1 * iy;
  9279. // faces
  9280. indices.push( a, b, d );
  9281. indices.push( b, c, d );
  9282. }
  9283. }
  9284. // build geometry
  9285. this.setIndex( indices );
  9286. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9287. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9288. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9289. }
  9290. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9291. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  9292. /**
  9293. * @author mrdoob / http://mrdoob.com/
  9294. * @author mikael emtinger / http://gomo.se/
  9295. * @author WestLangley / http://github.com/WestLangley
  9296. */
  9297. function Camera() {
  9298. Object3D.call( this );
  9299. this.type = 'Camera';
  9300. this.matrixWorldInverse = new Matrix4();
  9301. this.projectionMatrix = new Matrix4();
  9302. }
  9303. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  9304. constructor: Camera,
  9305. isCamera: true,
  9306. copy: function ( source ) {
  9307. Object3D.prototype.copy.call( this, source );
  9308. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9309. this.projectionMatrix.copy( source.projectionMatrix );
  9310. return this;
  9311. },
  9312. getWorldDirection: function () {
  9313. var quaternion = new Quaternion();
  9314. return function getWorldDirection( optionalTarget ) {
  9315. var result = optionalTarget || new Vector3();
  9316. this.getWorldQuaternion( quaternion );
  9317. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9318. };
  9319. }(),
  9320. clone: function () {
  9321. return new this.constructor().copy( this );
  9322. }
  9323. } );
  9324. /**
  9325. * @author mrdoob / http://mrdoob.com/
  9326. * @author greggman / http://games.greggman.com/
  9327. * @author zz85 / http://www.lab4games.net/zz85/blog
  9328. * @author tschw
  9329. */
  9330. function PerspectiveCamera( fov, aspect, near, far ) {
  9331. Camera.call( this );
  9332. this.type = 'PerspectiveCamera';
  9333. this.fov = fov !== undefined ? fov : 50;
  9334. this.zoom = 1;
  9335. this.near = near !== undefined ? near : 0.1;
  9336. this.far = far !== undefined ? far : 2000;
  9337. this.focus = 10;
  9338. this.aspect = aspect !== undefined ? aspect : 1;
  9339. this.view = null;
  9340. this.filmGauge = 35; // width of the film (default in millimeters)
  9341. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  9342. this.updateProjectionMatrix();
  9343. }
  9344. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  9345. constructor: PerspectiveCamera,
  9346. isPerspectiveCamera: true,
  9347. copy: function ( source ) {
  9348. Camera.prototype.copy.call( this, source );
  9349. this.fov = source.fov;
  9350. this.zoom = source.zoom;
  9351. this.near = source.near;
  9352. this.far = source.far;
  9353. this.focus = source.focus;
  9354. this.aspect = source.aspect;
  9355. this.view = source.view === null ? null : Object.assign( {}, source.view );
  9356. this.filmGauge = source.filmGauge;
  9357. this.filmOffset = source.filmOffset;
  9358. return this;
  9359. },
  9360. /**
  9361. * Sets the FOV by focal length in respect to the current .filmGauge.
  9362. *
  9363. * The default film gauge is 35, so that the focal length can be specified for
  9364. * a 35mm (full frame) camera.
  9365. *
  9366. * Values for focal length and film gauge must have the same unit.
  9367. */
  9368. setFocalLength: function ( focalLength ) {
  9369. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  9370. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  9371. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  9372. this.updateProjectionMatrix();
  9373. },
  9374. /**
  9375. * Calculates the focal length from the current .fov and .filmGauge.
  9376. */
  9377. getFocalLength: function () {
  9378. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  9379. return 0.5 * this.getFilmHeight() / vExtentSlope;
  9380. },
  9381. getEffectiveFOV: function () {
  9382. return _Math.RAD2DEG * 2 * Math.atan(
  9383. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  9384. },
  9385. getFilmWidth: function () {
  9386. // film not completely covered in portrait format (aspect < 1)
  9387. return this.filmGauge * Math.min( this.aspect, 1 );
  9388. },
  9389. getFilmHeight: function () {
  9390. // film not completely covered in landscape format (aspect > 1)
  9391. return this.filmGauge / Math.max( this.aspect, 1 );
  9392. },
  9393. /**
  9394. * Sets an offset in a larger frustum. This is useful for multi-window or
  9395. * multi-monitor/multi-machine setups.
  9396. *
  9397. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9398. * the monitors are in grid like this
  9399. *
  9400. * +---+---+---+
  9401. * | A | B | C |
  9402. * +---+---+---+
  9403. * | D | E | F |
  9404. * +---+---+---+
  9405. *
  9406. * then for each monitor you would call it like this
  9407. *
  9408. * var w = 1920;
  9409. * var h = 1080;
  9410. * var fullWidth = w * 3;
  9411. * var fullHeight = h * 2;
  9412. *
  9413. * --A--
  9414. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9415. * --B--
  9416. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  9417. * --C--
  9418. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  9419. * --D--
  9420. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  9421. * --E--
  9422. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  9423. * --F--
  9424. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  9425. *
  9426. * Note there is no reason monitors have to be the same size or in a grid.
  9427. */
  9428. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  9429. this.aspect = fullWidth / fullHeight;
  9430. this.view = {
  9431. fullWidth: fullWidth,
  9432. fullHeight: fullHeight,
  9433. offsetX: x,
  9434. offsetY: y,
  9435. width: width,
  9436. height: height
  9437. };
  9438. this.updateProjectionMatrix();
  9439. },
  9440. clearViewOffset: function () {
  9441. this.view = null;
  9442. this.updateProjectionMatrix();
  9443. },
  9444. updateProjectionMatrix: function () {
  9445. var near = this.near,
  9446. top = near * Math.tan(
  9447. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  9448. height = 2 * top,
  9449. width = this.aspect * height,
  9450. left = - 0.5 * width,
  9451. view = this.view;
  9452. if ( view !== null ) {
  9453. var fullWidth = view.fullWidth,
  9454. fullHeight = view.fullHeight;
  9455. left += view.offsetX * width / fullWidth;
  9456. top -= view.offsetY * height / fullHeight;
  9457. width *= view.width / fullWidth;
  9458. height *= view.height / fullHeight;
  9459. }
  9460. var skew = this.filmOffset;
  9461. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  9462. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  9463. },
  9464. toJSON: function ( meta ) {
  9465. var data = Object3D.prototype.toJSON.call( this, meta );
  9466. data.object.fov = this.fov;
  9467. data.object.zoom = this.zoom;
  9468. data.object.near = this.near;
  9469. data.object.far = this.far;
  9470. data.object.focus = this.focus;
  9471. data.object.aspect = this.aspect;
  9472. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  9473. data.object.filmGauge = this.filmGauge;
  9474. data.object.filmOffset = this.filmOffset;
  9475. return data;
  9476. }
  9477. } );
  9478. /**
  9479. * @author alteredq / http://alteredqualia.com/
  9480. * @author arose / http://github.com/arose
  9481. */
  9482. function OrthographicCamera( left, right, top, bottom, near, far ) {
  9483. Camera.call( this );
  9484. this.type = 'OrthographicCamera';
  9485. this.zoom = 1;
  9486. this.view = null;
  9487. this.left = left;
  9488. this.right = right;
  9489. this.top = top;
  9490. this.bottom = bottom;
  9491. this.near = ( near !== undefined ) ? near : 0.1;
  9492. this.far = ( far !== undefined ) ? far : 2000;
  9493. this.updateProjectionMatrix();
  9494. }
  9495. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  9496. constructor: OrthographicCamera,
  9497. isOrthographicCamera: true,
  9498. copy: function ( source ) {
  9499. Camera.prototype.copy.call( this, source );
  9500. this.left = source.left;
  9501. this.right = source.right;
  9502. this.top = source.top;
  9503. this.bottom = source.bottom;
  9504. this.near = source.near;
  9505. this.far = source.far;
  9506. this.zoom = source.zoom;
  9507. this.view = source.view === null ? null : Object.assign( {}, source.view );
  9508. return this;
  9509. },
  9510. setViewOffset: function( fullWidth, fullHeight, x, y, width, height ) {
  9511. this.view = {
  9512. fullWidth: fullWidth,
  9513. fullHeight: fullHeight,
  9514. offsetX: x,
  9515. offsetY: y,
  9516. width: width,
  9517. height: height
  9518. };
  9519. this.updateProjectionMatrix();
  9520. },
  9521. clearViewOffset: function() {
  9522. this.view = null;
  9523. this.updateProjectionMatrix();
  9524. },
  9525. updateProjectionMatrix: function () {
  9526. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9527. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9528. var cx = ( this.right + this.left ) / 2;
  9529. var cy = ( this.top + this.bottom ) / 2;
  9530. var left = cx - dx;
  9531. var right = cx + dx;
  9532. var top = cy + dy;
  9533. var bottom = cy - dy;
  9534. if ( this.view !== null ) {
  9535. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  9536. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  9537. var scaleW = ( this.right - this.left ) / this.view.width;
  9538. var scaleH = ( this.top - this.bottom ) / this.view.height;
  9539. left += scaleW * ( this.view.offsetX / zoomW );
  9540. right = left + scaleW * ( this.view.width / zoomW );
  9541. top -= scaleH * ( this.view.offsetY / zoomH );
  9542. bottom = top - scaleH * ( this.view.height / zoomH );
  9543. }
  9544. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  9545. },
  9546. toJSON: function ( meta ) {
  9547. var data = Object3D.prototype.toJSON.call( this, meta );
  9548. data.object.zoom = this.zoom;
  9549. data.object.left = this.left;
  9550. data.object.right = this.right;
  9551. data.object.top = this.top;
  9552. data.object.bottom = this.bottom;
  9553. data.object.near = this.near;
  9554. data.object.far = this.far;
  9555. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  9556. return data;
  9557. }
  9558. } );
  9559. /**
  9560. * @author mrdoob / http://mrdoob.com/
  9561. */
  9562. function WebGLAttributes( gl ) {
  9563. var buffers = {};
  9564. function createBuffer( attribute, bufferType ) {
  9565. var array = attribute.array;
  9566. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  9567. var buffer = gl.createBuffer();
  9568. gl.bindBuffer( bufferType, buffer );
  9569. gl.bufferData( bufferType, array, usage );
  9570. attribute.onUploadCallback();
  9571. var type = gl.FLOAT;
  9572. if ( array instanceof Float32Array ) {
  9573. type = gl.FLOAT;
  9574. } else if ( array instanceof Float64Array ) {
  9575. console.warn( "Unsupported data buffer format: Float64Array" );
  9576. } else if ( array instanceof Uint16Array ) {
  9577. type = gl.UNSIGNED_SHORT;
  9578. } else if ( array instanceof Int16Array ) {
  9579. type = gl.SHORT;
  9580. } else if ( array instanceof Uint32Array ) {
  9581. type = gl.UNSIGNED_INT;
  9582. } else if ( array instanceof Int32Array ) {
  9583. type = gl.INT;
  9584. } else if ( array instanceof Int8Array ) {
  9585. type = gl.BYTE;
  9586. } else if ( array instanceof Uint8Array ) {
  9587. type = gl.UNSIGNED_BYTE;
  9588. }
  9589. return {
  9590. buffer: buffer,
  9591. type: type,
  9592. bytesPerElement: array.BYTES_PER_ELEMENT,
  9593. version: attribute.version
  9594. };
  9595. }
  9596. function updateBuffer( buffer, attribute, bufferType ) {
  9597. var array = attribute.array;
  9598. var updateRange = attribute.updateRange;
  9599. gl.bindBuffer( bufferType, buffer );
  9600. if ( attribute.dynamic === false ) {
  9601. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  9602. } else if ( updateRange.count === - 1 ) {
  9603. // Not using update ranges
  9604. gl.bufferSubData( bufferType, 0, array );
  9605. } else if ( updateRange.count === 0 ) {
  9606. 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.' );
  9607. } else {
  9608. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9609. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9610. updateRange.count = 0; // reset range
  9611. }
  9612. }
  9613. //
  9614. function get( attribute ) {
  9615. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9616. return buffers[ attribute.uuid ];
  9617. }
  9618. function remove( attribute ) {
  9619. var data = buffers[ attribute.uuid ];
  9620. if ( data ) {
  9621. gl.deleteBuffer( data.buffer );
  9622. delete buffers[ attribute.uuid ];
  9623. }
  9624. }
  9625. function update( attribute, bufferType ) {
  9626. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9627. var data = buffers[ attribute.uuid ];
  9628. if ( data === undefined ) {
  9629. buffers[ attribute.uuid ] = createBuffer( attribute, bufferType );
  9630. } else if ( data.version < attribute.version ) {
  9631. updateBuffer( data.buffer, attribute, bufferType );
  9632. data.version = attribute.version;
  9633. }
  9634. }
  9635. return {
  9636. get: get,
  9637. remove: remove,
  9638. update: update
  9639. };
  9640. }
  9641. /**
  9642. * @author mrdoob / http://mrdoob.com/
  9643. */
  9644. function painterSortStable( a, b ) {
  9645. if ( a.renderOrder !== b.renderOrder ) {
  9646. return a.renderOrder - b.renderOrder;
  9647. } else if ( a.program && b.program && a.program !== b.program ) {
  9648. return a.program.id - b.program.id;
  9649. } else if ( a.material.id !== b.material.id ) {
  9650. return a.material.id - b.material.id;
  9651. } else if ( a.z !== b.z ) {
  9652. return a.z - b.z;
  9653. } else {
  9654. return a.id - b.id;
  9655. }
  9656. }
  9657. function reversePainterSortStable( a, b ) {
  9658. if ( a.renderOrder !== b.renderOrder ) {
  9659. return a.renderOrder - b.renderOrder;
  9660. } if ( a.z !== b.z ) {
  9661. return b.z - a.z;
  9662. } else {
  9663. return a.id - b.id;
  9664. }
  9665. }
  9666. function WebGLRenderList() {
  9667. var opaque = [];
  9668. var opaqueLastIndex = - 1;
  9669. var transparent = [];
  9670. var transparentLastIndex = - 1;
  9671. function init() {
  9672. opaqueLastIndex = - 1;
  9673. transparentLastIndex = - 1;
  9674. }
  9675. function push( object, geometry, material, z, group ) {
  9676. var array, index;
  9677. // allocate the next position in the appropriate array
  9678. if ( material.transparent ) {
  9679. array = transparent;
  9680. index = ++ transparentLastIndex;
  9681. } else {
  9682. array = opaque;
  9683. index = ++ opaqueLastIndex;
  9684. }
  9685. // recycle existing render item or grow the array
  9686. var renderItem = array[ index ];
  9687. if ( renderItem ) {
  9688. renderItem.id = object.id;
  9689. renderItem.object = object;
  9690. renderItem.geometry = geometry;
  9691. renderItem.material = material;
  9692. renderItem.program = material.program;
  9693. renderItem.renderOrder = object.renderOrder;
  9694. renderItem.z = z;
  9695. renderItem.group = group;
  9696. } else {
  9697. renderItem = {
  9698. id: object.id,
  9699. object: object,
  9700. geometry: geometry,
  9701. material: material,
  9702. program: material.program,
  9703. renderOrder: object.renderOrder,
  9704. z: z,
  9705. group: group
  9706. };
  9707. // assert( index === array.length );
  9708. array.push( renderItem );
  9709. }
  9710. }
  9711. function finish() {
  9712. opaque.length = opaqueLastIndex + 1;
  9713. transparent.length = transparentLastIndex + 1;
  9714. }
  9715. function sort() {
  9716. opaque.sort( painterSortStable );
  9717. transparent.sort( reversePainterSortStable );
  9718. }
  9719. return {
  9720. opaque: opaque,
  9721. transparent: transparent,
  9722. init: init,
  9723. push: push,
  9724. finish: finish,
  9725. sort: sort
  9726. };
  9727. }
  9728. function WebGLRenderLists() {
  9729. var lists = {};
  9730. function get( scene, camera ) {
  9731. var hash = scene.id + ',' + camera.id;
  9732. var list = lists[ hash ];
  9733. if ( list === undefined ) {
  9734. // console.log( 'THREE.WebGLRenderLists:', hash );
  9735. list = new WebGLRenderList();
  9736. lists[ hash ] = list;
  9737. }
  9738. return list;
  9739. }
  9740. function dispose() {
  9741. lists = {};
  9742. }
  9743. return {
  9744. get: get,
  9745. dispose: dispose
  9746. };
  9747. }
  9748. /**
  9749. * @author mrdoob / http://mrdoob.com/
  9750. */
  9751. function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
  9752. var mode;
  9753. function setMode( value ) {
  9754. mode = value;
  9755. }
  9756. var type, size;
  9757. function setIndex( index ) {
  9758. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  9759. type = gl.UNSIGNED_INT;
  9760. size = 4;
  9761. } else if ( index.array instanceof Uint16Array ) {
  9762. type = gl.UNSIGNED_SHORT;
  9763. size = 2;
  9764. } else {
  9765. type = gl.UNSIGNED_BYTE;
  9766. size = 1;
  9767. }
  9768. }
  9769. function render( start, count ) {
  9770. gl.drawElements( mode, count, type, start * size );
  9771. infoRender.calls ++;
  9772. infoRender.vertices += count;
  9773. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  9774. }
  9775. function renderInstances( geometry, start, count ) {
  9776. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9777. if ( extension === null ) {
  9778. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9779. return;
  9780. }
  9781. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  9782. infoRender.calls ++;
  9783. infoRender.vertices += count * geometry.maxInstancedCount;
  9784. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  9785. }
  9786. //
  9787. this.setMode = setMode;
  9788. this.setIndex = setIndex;
  9789. this.render = render;
  9790. this.renderInstances = renderInstances;
  9791. }
  9792. /**
  9793. * @author mrdoob / http://mrdoob.com/
  9794. */
  9795. function WebGLBufferRenderer( gl, extensions, infoRender ) {
  9796. var mode;
  9797. function setMode( value ) {
  9798. mode = value;
  9799. }
  9800. function render( start, count ) {
  9801. gl.drawArrays( mode, start, count );
  9802. infoRender.calls ++;
  9803. infoRender.vertices += count;
  9804. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  9805. }
  9806. function renderInstances( geometry, start, count ) {
  9807. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9808. if ( extension === null ) {
  9809. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9810. return;
  9811. }
  9812. var position = geometry.attributes.position;
  9813. if ( position.isInterleavedBufferAttribute ) {
  9814. count = position.data.count;
  9815. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  9816. } else {
  9817. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  9818. }
  9819. infoRender.calls ++;
  9820. infoRender.vertices += count * geometry.maxInstancedCount;
  9821. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  9822. }
  9823. //
  9824. this.setMode = setMode;
  9825. this.render = render;
  9826. this.renderInstances = renderInstances;
  9827. }
  9828. /**
  9829. * @author mrdoob / http://mrdoob.com/
  9830. */
  9831. function WebGLGeometries( gl, attributes, infoMemory ) {
  9832. var geometries = {};
  9833. var wireframeAttributes = {};
  9834. function onGeometryDispose( event ) {
  9835. var geometry = event.target;
  9836. var buffergeometry = geometries[ geometry.id ];
  9837. if ( buffergeometry.index !== null ) {
  9838. attributes.remove( buffergeometry.index );
  9839. }
  9840. for ( var name in buffergeometry.attributes ) {
  9841. attributes.remove( buffergeometry.attributes[ name ] );
  9842. }
  9843. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9844. delete geometries[ geometry.id ];
  9845. // TODO Remove duplicate code
  9846. var attribute = wireframeAttributes[ geometry.id ];
  9847. if ( attribute ) {
  9848. attributes.remove( attribute );
  9849. delete wireframeAttributes[ geometry.id ];
  9850. }
  9851. attribute = wireframeAttributes[ buffergeometry.id ];
  9852. if ( attribute ) {
  9853. attributes.remove( attribute );
  9854. delete wireframeAttributes[ buffergeometry.id ];
  9855. }
  9856. //
  9857. infoMemory.geometries --;
  9858. }
  9859. function get( object, geometry ) {
  9860. var buffergeometry = geometries[ geometry.id ];
  9861. if ( buffergeometry ) return buffergeometry;
  9862. geometry.addEventListener( 'dispose', onGeometryDispose );
  9863. if ( geometry.isBufferGeometry ) {
  9864. buffergeometry = geometry;
  9865. } else if ( geometry.isGeometry ) {
  9866. if ( geometry._bufferGeometry === undefined ) {
  9867. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9868. }
  9869. buffergeometry = geometry._bufferGeometry;
  9870. }
  9871. geometries[ geometry.id ] = buffergeometry;
  9872. infoMemory.geometries ++;
  9873. return buffergeometry;
  9874. }
  9875. function update( geometry ) {
  9876. var index = geometry.index;
  9877. var geometryAttributes = geometry.attributes;
  9878. if ( index !== null ) {
  9879. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  9880. }
  9881. for ( var name in geometryAttributes ) {
  9882. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  9883. }
  9884. // morph targets
  9885. var morphAttributes = geometry.morphAttributes;
  9886. for ( var name in morphAttributes ) {
  9887. var array = morphAttributes[ name ];
  9888. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9889. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  9890. }
  9891. }
  9892. }
  9893. function getWireframeAttribute( geometry ) {
  9894. var attribute = wireframeAttributes[ geometry.id ];
  9895. if ( attribute ) return attribute;
  9896. var indices = [];
  9897. var geometryIndex = geometry.index;
  9898. var geometryAttributes = geometry.attributes;
  9899. // console.time( 'wireframe' );
  9900. if ( geometryIndex !== null ) {
  9901. var array = geometryIndex.array;
  9902. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9903. var a = array[ i + 0 ];
  9904. var b = array[ i + 1 ];
  9905. var c = array[ i + 2 ];
  9906. indices.push( a, b, b, c, c, a );
  9907. }
  9908. } else {
  9909. var array = geometryAttributes.position.array;
  9910. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9911. var a = i + 0;
  9912. var b = i + 1;
  9913. var c = i + 2;
  9914. indices.push( a, b, b, c, c, a );
  9915. }
  9916. }
  9917. // console.timeEnd( 'wireframe' );
  9918. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9919. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  9920. wireframeAttributes[ geometry.id ] = attribute;
  9921. return attribute;
  9922. }
  9923. return {
  9924. get: get,
  9925. update: update,
  9926. getWireframeAttribute: getWireframeAttribute
  9927. };
  9928. }
  9929. /**
  9930. * @author mrdoob / http://mrdoob.com/
  9931. */
  9932. function WebGLLights() {
  9933. var lights = {};
  9934. return {
  9935. get: function ( light ) {
  9936. if ( lights[ light.id ] !== undefined ) {
  9937. return lights[ light.id ];
  9938. }
  9939. var uniforms;
  9940. switch ( light.type ) {
  9941. case 'DirectionalLight':
  9942. uniforms = {
  9943. direction: new Vector3(),
  9944. color: new Color(),
  9945. shadow: false,
  9946. shadowBias: 0,
  9947. shadowRadius: 1,
  9948. shadowMapSize: new Vector2()
  9949. };
  9950. break;
  9951. case 'SpotLight':
  9952. uniforms = {
  9953. position: new Vector3(),
  9954. direction: new Vector3(),
  9955. color: new Color(),
  9956. distance: 0,
  9957. coneCos: 0,
  9958. penumbraCos: 0,
  9959. decay: 0,
  9960. shadow: false,
  9961. shadowBias: 0,
  9962. shadowRadius: 1,
  9963. shadowMapSize: new Vector2()
  9964. };
  9965. break;
  9966. case 'PointLight':
  9967. uniforms = {
  9968. position: new Vector3(),
  9969. color: new Color(),
  9970. distance: 0,
  9971. decay: 0,
  9972. shadow: false,
  9973. shadowBias: 0,
  9974. shadowRadius: 1,
  9975. shadowMapSize: new Vector2()
  9976. };
  9977. break;
  9978. case 'HemisphereLight':
  9979. uniforms = {
  9980. direction: new Vector3(),
  9981. skyColor: new Color(),
  9982. groundColor: new Color()
  9983. };
  9984. break;
  9985. case 'RectAreaLight':
  9986. uniforms = {
  9987. color: new Color(),
  9988. position: new Vector3(),
  9989. halfWidth: new Vector3(),
  9990. halfHeight: new Vector3()
  9991. // TODO (abelnation): set RectAreaLight shadow uniforms
  9992. };
  9993. break;
  9994. }
  9995. lights[ light.id ] = uniforms;
  9996. return uniforms;
  9997. }
  9998. };
  9999. }
  10000. /**
  10001. * @author mrdoob / http://mrdoob.com/
  10002. */
  10003. function WebGLObjects( gl, geometries, infoRender ) {
  10004. var updateList = {};
  10005. function update( object ) {
  10006. var frame = infoRender.frame;
  10007. var geometry = object.geometry;
  10008. var buffergeometry = geometries.get( object, geometry );
  10009. // Update once per frame
  10010. if ( updateList[ buffergeometry.id ] !== frame ) {
  10011. if ( geometry.isGeometry ) {
  10012. buffergeometry.updateFromObject( object );
  10013. }
  10014. geometries.update( buffergeometry );
  10015. updateList[ buffergeometry.id ] = frame;
  10016. }
  10017. return buffergeometry;
  10018. }
  10019. function clear() {
  10020. updateList = {};
  10021. }
  10022. return {
  10023. update: update,
  10024. clear: clear
  10025. };
  10026. }
  10027. /**
  10028. * @author mrdoob / http://mrdoob.com/
  10029. */
  10030. function addLineNumbers( string ) {
  10031. var lines = string.split( '\n' );
  10032. for ( var i = 0; i < lines.length; i ++ ) {
  10033. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10034. }
  10035. return lines.join( '\n' );
  10036. }
  10037. function WebGLShader( gl, type, string ) {
  10038. var shader = gl.createShader( type );
  10039. gl.shaderSource( shader, string );
  10040. gl.compileShader( shader );
  10041. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  10042. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  10043. }
  10044. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  10045. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  10046. }
  10047. // --enable-privileged-webgl-extension
  10048. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10049. return shader;
  10050. }
  10051. /**
  10052. * @author mrdoob / http://mrdoob.com/
  10053. */
  10054. var programIdCount = 0;
  10055. function getEncodingComponents( encoding ) {
  10056. switch ( encoding ) {
  10057. case LinearEncoding:
  10058. return [ 'Linear','( value )' ];
  10059. case sRGBEncoding:
  10060. return [ 'sRGB','( value )' ];
  10061. case RGBEEncoding:
  10062. return [ 'RGBE','( value )' ];
  10063. case RGBM7Encoding:
  10064. return [ 'RGBM','( value, 7.0 )' ];
  10065. case RGBM16Encoding:
  10066. return [ 'RGBM','( value, 16.0 )' ];
  10067. case RGBDEncoding:
  10068. return [ 'RGBD','( value, 256.0 )' ];
  10069. case GammaEncoding:
  10070. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  10071. default:
  10072. throw new Error( 'unsupported encoding: ' + encoding );
  10073. }
  10074. }
  10075. function getTexelDecodingFunction( functionName, encoding ) {
  10076. var components = getEncodingComponents( encoding );
  10077. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  10078. }
  10079. function getTexelEncodingFunction( functionName, encoding ) {
  10080. var components = getEncodingComponents( encoding );
  10081. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  10082. }
  10083. function getToneMappingFunction( functionName, toneMapping ) {
  10084. var toneMappingName;
  10085. switch ( toneMapping ) {
  10086. case LinearToneMapping:
  10087. toneMappingName = "Linear";
  10088. break;
  10089. case ReinhardToneMapping:
  10090. toneMappingName = "Reinhard";
  10091. break;
  10092. case Uncharted2ToneMapping:
  10093. toneMappingName = "Uncharted2";
  10094. break;
  10095. case CineonToneMapping:
  10096. toneMappingName = "OptimizedCineon";
  10097. break;
  10098. default:
  10099. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10100. }
  10101. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  10102. }
  10103. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10104. extensions = extensions || {};
  10105. var chunks = [
  10106. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10107. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10108. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10109. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10110. ];
  10111. return chunks.filter( filterEmptyLine ).join( '\n' );
  10112. }
  10113. function generateDefines( defines ) {
  10114. var chunks = [];
  10115. for ( var name in defines ) {
  10116. var value = defines[ name ];
  10117. if ( value === false ) continue;
  10118. chunks.push( '#define ' + name + ' ' + value );
  10119. }
  10120. return chunks.join( '\n' );
  10121. }
  10122. function fetchAttributeLocations( gl, program, identifiers ) {
  10123. var attributes = {};
  10124. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  10125. for ( var i = 0; i < n; i ++ ) {
  10126. var info = gl.getActiveAttrib( program, i );
  10127. var name = info.name;
  10128. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  10129. attributes[ name ] = gl.getAttribLocation( program, name );
  10130. }
  10131. return attributes;
  10132. }
  10133. function filterEmptyLine( string ) {
  10134. return string !== '';
  10135. }
  10136. function replaceLightNums( string, parameters ) {
  10137. return string
  10138. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10139. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10140. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10141. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10142. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10143. }
  10144. function parseIncludes( string ) {
  10145. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  10146. function replace( match, include ) {
  10147. var replace = ShaderChunk[ include ];
  10148. if ( replace === undefined ) {
  10149. throw new Error( 'Can not resolve #include <' + include + '>' );
  10150. }
  10151. return parseIncludes( replace );
  10152. }
  10153. return string.replace( pattern, replace );
  10154. }
  10155. function unrollLoops( string ) {
  10156. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10157. function replace( match, start, end, snippet ) {
  10158. var unroll = '';
  10159. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10160. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10161. }
  10162. return unroll;
  10163. }
  10164. return string.replace( pattern, replace );
  10165. }
  10166. function WebGLProgram( renderer, code, material, parameters ) {
  10167. var gl = renderer.context;
  10168. var extensions = material.extensions;
  10169. var defines = material.defines;
  10170. var vertexShader = material.__webglShader.vertexShader;
  10171. var fragmentShader = material.__webglShader.fragmentShader;
  10172. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10173. if ( parameters.shadowMapType === PCFShadowMap ) {
  10174. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10175. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10176. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10177. }
  10178. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10179. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10180. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10181. if ( parameters.envMap ) {
  10182. switch ( material.envMap.mapping ) {
  10183. case CubeReflectionMapping:
  10184. case CubeRefractionMapping:
  10185. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10186. break;
  10187. case CubeUVReflectionMapping:
  10188. case CubeUVRefractionMapping:
  10189. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10190. break;
  10191. case EquirectangularReflectionMapping:
  10192. case EquirectangularRefractionMapping:
  10193. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10194. break;
  10195. case SphericalReflectionMapping:
  10196. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10197. break;
  10198. }
  10199. switch ( material.envMap.mapping ) {
  10200. case CubeRefractionMapping:
  10201. case EquirectangularRefractionMapping:
  10202. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10203. break;
  10204. }
  10205. switch ( material.combine ) {
  10206. case MultiplyOperation:
  10207. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10208. break;
  10209. case MixOperation:
  10210. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10211. break;
  10212. case AddOperation:
  10213. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10214. break;
  10215. }
  10216. }
  10217. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10218. // console.log( 'building new program ' );
  10219. //
  10220. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  10221. var customDefines = generateDefines( defines );
  10222. //
  10223. var program = gl.createProgram();
  10224. var prefixVertex, prefixFragment;
  10225. if ( material.isRawShaderMaterial ) {
  10226. prefixVertex = [
  10227. customDefines,
  10228. '\n'
  10229. ].filter( filterEmptyLine ).join( '\n' );
  10230. prefixFragment = [
  10231. customExtensions,
  10232. customDefines,
  10233. '\n'
  10234. ].filter( filterEmptyLine ).join( '\n' );
  10235. } else {
  10236. prefixVertex = [
  10237. 'precision ' + parameters.precision + ' float;',
  10238. 'precision ' + parameters.precision + ' int;',
  10239. '#define SHADER_NAME ' + material.__webglShader.name,
  10240. customDefines,
  10241. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10242. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10243. '#define MAX_BONES ' + parameters.maxBones,
  10244. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10245. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10246. parameters.map ? '#define USE_MAP' : '',
  10247. parameters.envMap ? '#define USE_ENVMAP' : '',
  10248. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10249. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10250. parameters.aoMap ? '#define USE_AOMAP' : '',
  10251. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10252. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10253. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10254. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10255. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10256. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10257. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10258. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10259. parameters.vertexColors ? '#define USE_COLOR' : '',
  10260. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10261. parameters.skinning ? '#define USE_SKINNING' : '',
  10262. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10263. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10264. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10265. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10266. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10267. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  10268. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10269. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10270. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10271. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10272. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10273. 'uniform mat4 modelMatrix;',
  10274. 'uniform mat4 modelViewMatrix;',
  10275. 'uniform mat4 projectionMatrix;',
  10276. 'uniform mat4 viewMatrix;',
  10277. 'uniform mat3 normalMatrix;',
  10278. 'uniform vec3 cameraPosition;',
  10279. 'attribute vec3 position;',
  10280. 'attribute vec3 normal;',
  10281. 'attribute vec2 uv;',
  10282. '#ifdef USE_COLOR',
  10283. ' attribute vec3 color;',
  10284. '#endif',
  10285. '#ifdef USE_MORPHTARGETS',
  10286. ' attribute vec3 morphTarget0;',
  10287. ' attribute vec3 morphTarget1;',
  10288. ' attribute vec3 morphTarget2;',
  10289. ' attribute vec3 morphTarget3;',
  10290. ' #ifdef USE_MORPHNORMALS',
  10291. ' attribute vec3 morphNormal0;',
  10292. ' attribute vec3 morphNormal1;',
  10293. ' attribute vec3 morphNormal2;',
  10294. ' attribute vec3 morphNormal3;',
  10295. ' #else',
  10296. ' attribute vec3 morphTarget4;',
  10297. ' attribute vec3 morphTarget5;',
  10298. ' attribute vec3 morphTarget6;',
  10299. ' attribute vec3 morphTarget7;',
  10300. ' #endif',
  10301. '#endif',
  10302. '#ifdef USE_SKINNING',
  10303. ' attribute vec4 skinIndex;',
  10304. ' attribute vec4 skinWeight;',
  10305. '#endif',
  10306. '\n'
  10307. ].filter( filterEmptyLine ).join( '\n' );
  10308. prefixFragment = [
  10309. customExtensions,
  10310. 'precision ' + parameters.precision + ' float;',
  10311. 'precision ' + parameters.precision + ' int;',
  10312. '#define SHADER_NAME ' + material.__webglShader.name,
  10313. customDefines,
  10314. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  10315. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10316. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10317. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10318. parameters.map ? '#define USE_MAP' : '',
  10319. parameters.envMap ? '#define USE_ENVMAP' : '',
  10320. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10321. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10322. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10323. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10324. parameters.aoMap ? '#define USE_AOMAP' : '',
  10325. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10326. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10327. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10328. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10329. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10330. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10331. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10332. parameters.vertexColors ? '#define USE_COLOR' : '',
  10333. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10334. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10335. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10336. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10337. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  10338. '#define UNION_CLIPPING_PLANES ' + (parameters.numClippingPlanes - parameters.numClipIntersection),
  10339. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10340. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10341. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  10342. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  10343. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10344. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10345. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  10346. 'uniform mat4 viewMatrix;',
  10347. 'uniform vec3 cameraPosition;',
  10348. ( parameters.toneMapping !== NoToneMapping ) ? "#define TONE_MAPPING" : '',
  10349. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10350. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  10351. parameters.dithering ? '#define DITHERING' : '',
  10352. ( 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
  10353. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10354. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10355. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10356. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  10357. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  10358. '\n'
  10359. ].filter( filterEmptyLine ).join( '\n' );
  10360. }
  10361. vertexShader = parseIncludes( vertexShader, parameters );
  10362. vertexShader = replaceLightNums( vertexShader, parameters );
  10363. fragmentShader = parseIncludes( fragmentShader, parameters );
  10364. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10365. if ( ! material.isShaderMaterial ) {
  10366. vertexShader = unrollLoops( vertexShader );
  10367. fragmentShader = unrollLoops( fragmentShader );
  10368. }
  10369. var vertexGlsl = prefixVertex + vertexShader;
  10370. var fragmentGlsl = prefixFragment + fragmentShader;
  10371. // console.log( '*VERTEX*', vertexGlsl );
  10372. // console.log( '*FRAGMENT*', fragmentGlsl );
  10373. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  10374. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  10375. gl.attachShader( program, glVertexShader );
  10376. gl.attachShader( program, glFragmentShader );
  10377. // Force a particular attribute to index 0.
  10378. if ( material.index0AttributeName !== undefined ) {
  10379. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10380. } else if ( parameters.morphTargets === true ) {
  10381. // programs with morphTargets displace position out of attribute 0
  10382. gl.bindAttribLocation( program, 0, 'position' );
  10383. }
  10384. gl.linkProgram( program );
  10385. var programLog = gl.getProgramInfoLog( program );
  10386. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  10387. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  10388. var runnable = true;
  10389. var haveDiagnostics = true;
  10390. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10391. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10392. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  10393. runnable = false;
  10394. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10395. } else if ( programLog !== '' ) {
  10396. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10397. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10398. haveDiagnostics = false;
  10399. }
  10400. if ( haveDiagnostics ) {
  10401. this.diagnostics = {
  10402. runnable: runnable,
  10403. material: material,
  10404. programLog: programLog,
  10405. vertexShader: {
  10406. log: vertexLog,
  10407. prefix: prefixVertex
  10408. },
  10409. fragmentShader: {
  10410. log: fragmentLog,
  10411. prefix: prefixFragment
  10412. }
  10413. };
  10414. }
  10415. // clean up
  10416. gl.deleteShader( glVertexShader );
  10417. gl.deleteShader( glFragmentShader );
  10418. // set up caching for uniform locations
  10419. var cachedUniforms;
  10420. this.getUniforms = function() {
  10421. if ( cachedUniforms === undefined ) {
  10422. cachedUniforms =
  10423. new WebGLUniforms( gl, program, renderer );
  10424. }
  10425. return cachedUniforms;
  10426. };
  10427. // set up caching for attribute locations
  10428. var cachedAttributes;
  10429. this.getAttributes = function() {
  10430. if ( cachedAttributes === undefined ) {
  10431. cachedAttributes = fetchAttributeLocations( gl, program );
  10432. }
  10433. return cachedAttributes;
  10434. };
  10435. // free resource
  10436. this.destroy = function() {
  10437. gl.deleteProgram( program );
  10438. this.program = undefined;
  10439. };
  10440. // DEPRECATED
  10441. Object.defineProperties( this, {
  10442. uniforms: {
  10443. get: function() {
  10444. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10445. return this.getUniforms();
  10446. }
  10447. },
  10448. attributes: {
  10449. get: function() {
  10450. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10451. return this.getAttributes();
  10452. }
  10453. }
  10454. } );
  10455. //
  10456. this.id = programIdCount ++;
  10457. this.code = code;
  10458. this.usedTimes = 1;
  10459. this.program = program;
  10460. this.vertexShader = glVertexShader;
  10461. this.fragmentShader = glFragmentShader;
  10462. return this;
  10463. }
  10464. /**
  10465. * @author mrdoob / http://mrdoob.com/
  10466. */
  10467. function WebGLPrograms( renderer, capabilities ) {
  10468. var programs = [];
  10469. var shaderIDs = {
  10470. MeshDepthMaterial: 'depth',
  10471. MeshNormalMaterial: 'normal',
  10472. MeshBasicMaterial: 'basic',
  10473. MeshLambertMaterial: 'lambert',
  10474. MeshPhongMaterial: 'phong',
  10475. MeshToonMaterial: 'phong',
  10476. MeshStandardMaterial: 'physical',
  10477. MeshPhysicalMaterial: 'physical',
  10478. LineBasicMaterial: 'basic',
  10479. LineDashedMaterial: 'dashed',
  10480. PointsMaterial: 'points'
  10481. };
  10482. var parameterNames = [
  10483. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10484. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  10485. "roughnessMap", "metalnessMap", "gradientMap",
  10486. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  10487. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10488. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10489. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10490. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10491. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10492. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10493. ];
  10494. function allocateBones( object ) {
  10495. var skeleton = object.skeleton;
  10496. var bones = skeleton.bones;
  10497. if ( capabilities.floatVertexTextures ) {
  10498. return 1024;
  10499. } else {
  10500. // default for when object is not specified
  10501. // ( for example when prebuilding shader to be used with multiple objects )
  10502. //
  10503. // - leave some extra space for other uniforms
  10504. // - limit here is ANGLE's 254 max uniform vectors
  10505. // (up to 54 should be safe)
  10506. var nVertexUniforms = capabilities.maxVertexUniforms;
  10507. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10508. var maxBones = Math.min( nVertexMatrices, bones.length );
  10509. if ( maxBones < bones.length ) {
  10510. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10511. return 0;
  10512. }
  10513. return maxBones;
  10514. }
  10515. }
  10516. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10517. var encoding;
  10518. if ( ! map ) {
  10519. encoding = LinearEncoding;
  10520. } else if ( map.isTexture ) {
  10521. encoding = map.encoding;
  10522. } else if ( map.isWebGLRenderTarget ) {
  10523. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10524. encoding = map.texture.encoding;
  10525. }
  10526. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10527. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10528. encoding = GammaEncoding;
  10529. }
  10530. return encoding;
  10531. }
  10532. this.getParameters = function ( material, lights, fog, nClipPlanes, nClipIntersection, object ) {
  10533. var shaderID = shaderIDs[ material.type ];
  10534. // heuristics to create shader parameters according to lights in the scene
  10535. // (not to blow over maxLights budget)
  10536. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10537. var precision = renderer.getPrecision();
  10538. if ( material.precision !== null ) {
  10539. precision = capabilities.getMaxPrecision( material.precision );
  10540. if ( precision !== material.precision ) {
  10541. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10542. }
  10543. }
  10544. var currentRenderTarget = renderer.getRenderTarget();
  10545. var parameters = {
  10546. shaderID: shaderID,
  10547. precision: precision,
  10548. supportsVertexTextures: capabilities.vertexTextures,
  10549. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10550. map: !! material.map,
  10551. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10552. envMap: !! material.envMap,
  10553. envMapMode: material.envMap && material.envMap.mapping,
  10554. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10555. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10556. lightMap: !! material.lightMap,
  10557. aoMap: !! material.aoMap,
  10558. emissiveMap: !! material.emissiveMap,
  10559. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10560. bumpMap: !! material.bumpMap,
  10561. normalMap: !! material.normalMap,
  10562. displacementMap: !! material.displacementMap,
  10563. roughnessMap: !! material.roughnessMap,
  10564. metalnessMap: !! material.metalnessMap,
  10565. specularMap: !! material.specularMap,
  10566. alphaMap: !! material.alphaMap,
  10567. gradientMap: !! material.gradientMap,
  10568. combine: material.combine,
  10569. vertexColors: material.vertexColors,
  10570. fog: !! fog,
  10571. useFog: material.fog,
  10572. fogExp: ( fog && fog.isFogExp2 ),
  10573. flatShading: material.shading === FlatShading,
  10574. sizeAttenuation: material.sizeAttenuation,
  10575. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10576. skinning: material.skinning && maxBones > 0,
  10577. maxBones: maxBones,
  10578. useVertexTexture: capabilities.floatVertexTextures,
  10579. morphTargets: material.morphTargets,
  10580. morphNormals: material.morphNormals,
  10581. maxMorphTargets: renderer.maxMorphTargets,
  10582. maxMorphNormals: renderer.maxMorphNormals,
  10583. numDirLights: lights.directional.length,
  10584. numPointLights: lights.point.length,
  10585. numSpotLights: lights.spot.length,
  10586. numRectAreaLights: lights.rectArea.length,
  10587. numHemiLights: lights.hemi.length,
  10588. numClippingPlanes: nClipPlanes,
  10589. numClipIntersection: nClipIntersection,
  10590. dithering: material.dithering,
  10591. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  10592. shadowMapType: renderer.shadowMap.type,
  10593. toneMapping: renderer.toneMapping,
  10594. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10595. premultipliedAlpha: material.premultipliedAlpha,
  10596. alphaTest: material.alphaTest,
  10597. doubleSided: material.side === DoubleSide,
  10598. flipSided: material.side === BackSide,
  10599. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10600. };
  10601. return parameters;
  10602. };
  10603. this.getProgramCode = function ( material, parameters ) {
  10604. var array = [];
  10605. if ( parameters.shaderID ) {
  10606. array.push( parameters.shaderID );
  10607. } else {
  10608. array.push( material.fragmentShader );
  10609. array.push( material.vertexShader );
  10610. }
  10611. if ( material.defines !== undefined ) {
  10612. for ( var name in material.defines ) {
  10613. array.push( name );
  10614. array.push( material.defines[ name ] );
  10615. }
  10616. }
  10617. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10618. array.push( parameters[ parameterNames[ i ] ] );
  10619. }
  10620. array.push( renderer.gammaOutput );
  10621. return array.join();
  10622. };
  10623. this.acquireProgram = function ( material, parameters, code ) {
  10624. var program;
  10625. // Check if code has been already compiled
  10626. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10627. var programInfo = programs[ p ];
  10628. if ( programInfo.code === code ) {
  10629. program = programInfo;
  10630. ++ program.usedTimes;
  10631. break;
  10632. }
  10633. }
  10634. if ( program === undefined ) {
  10635. program = new WebGLProgram( renderer, code, material, parameters );
  10636. programs.push( program );
  10637. }
  10638. return program;
  10639. };
  10640. this.releaseProgram = function ( program ) {
  10641. if ( -- program.usedTimes === 0 ) {
  10642. // Remove from unordered set
  10643. var i = programs.indexOf( program );
  10644. programs[ i ] = programs[ programs.length - 1 ];
  10645. programs.pop();
  10646. // Free WebGL resources
  10647. program.destroy();
  10648. }
  10649. };
  10650. // Exposed for resource monitoring & error feedback via renderer.info:
  10651. this.programs = programs;
  10652. }
  10653. /**
  10654. * @author mrdoob / http://mrdoob.com/
  10655. */
  10656. function WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, infoMemory ) {
  10657. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
  10658. //
  10659. function clampToMaxSize( image, maxSize ) {
  10660. if ( image.width > maxSize || image.height > maxSize ) {
  10661. // Warning: Scaling through the canvas will only work with images that use
  10662. // premultiplied alpha.
  10663. var scale = maxSize / Math.max( image.width, image.height );
  10664. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  10665. canvas.width = Math.floor( image.width * scale );
  10666. canvas.height = Math.floor( image.height * scale );
  10667. var context = canvas.getContext( '2d' );
  10668. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  10669. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  10670. return canvas;
  10671. }
  10672. return image;
  10673. }
  10674. function isPowerOfTwo( image ) {
  10675. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  10676. }
  10677. function makePowerOfTwo( image ) {
  10678. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  10679. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  10680. canvas.width = _Math.nearestPowerOfTwo( image.width );
  10681. canvas.height = _Math.nearestPowerOfTwo( image.height );
  10682. var context = canvas.getContext( '2d' );
  10683. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  10684. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  10685. return canvas;
  10686. }
  10687. return image;
  10688. }
  10689. function textureNeedsPowerOfTwo( texture ) {
  10690. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  10691. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  10692. }
  10693. // Fallback filters for non-power-of-2 textures
  10694. function filterFallback( f ) {
  10695. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  10696. return _gl.NEAREST;
  10697. }
  10698. return _gl.LINEAR;
  10699. }
  10700. //
  10701. function onTextureDispose( event ) {
  10702. var texture = event.target;
  10703. texture.removeEventListener( 'dispose', onTextureDispose );
  10704. deallocateTexture( texture );
  10705. infoMemory.textures --;
  10706. }
  10707. function onRenderTargetDispose( event ) {
  10708. var renderTarget = event.target;
  10709. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  10710. deallocateRenderTarget( renderTarget );
  10711. infoMemory.textures --;
  10712. }
  10713. //
  10714. function deallocateTexture( texture ) {
  10715. var textureProperties = properties.get( texture );
  10716. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  10717. // cube texture
  10718. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  10719. } else {
  10720. // 2D texture
  10721. if ( textureProperties.__webglInit === undefined ) return;
  10722. _gl.deleteTexture( textureProperties.__webglTexture );
  10723. }
  10724. // remove all webgl properties
  10725. properties.remove( texture );
  10726. }
  10727. function deallocateRenderTarget( renderTarget ) {
  10728. var renderTargetProperties = properties.get( renderTarget );
  10729. var textureProperties = properties.get( renderTarget.texture );
  10730. if ( ! renderTarget ) return;
  10731. if ( textureProperties.__webglTexture !== undefined ) {
  10732. _gl.deleteTexture( textureProperties.__webglTexture );
  10733. }
  10734. if ( renderTarget.depthTexture ) {
  10735. renderTarget.depthTexture.dispose();
  10736. }
  10737. if ( renderTarget.isWebGLRenderTargetCube ) {
  10738. for ( var i = 0; i < 6; i ++ ) {
  10739. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  10740. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  10741. }
  10742. } else {
  10743. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  10744. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  10745. }
  10746. properties.remove( renderTarget.texture );
  10747. properties.remove( renderTarget );
  10748. }
  10749. //
  10750. function setTexture2D( texture, slot ) {
  10751. var textureProperties = properties.get( texture );
  10752. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  10753. var image = texture.image;
  10754. if ( image === undefined ) {
  10755. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  10756. } else if ( image.complete === false ) {
  10757. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  10758. } else {
  10759. uploadTexture( textureProperties, texture, slot );
  10760. return;
  10761. }
  10762. }
  10763. state.activeTexture( _gl.TEXTURE0 + slot );
  10764. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  10765. }
  10766. function setTextureCube( texture, slot ) {
  10767. var textureProperties = properties.get( texture );
  10768. if ( texture.image.length === 6 ) {
  10769. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  10770. if ( ! textureProperties.__image__webglTextureCube ) {
  10771. texture.addEventListener( 'dispose', onTextureDispose );
  10772. textureProperties.__image__webglTextureCube = _gl.createTexture();
  10773. infoMemory.textures ++;
  10774. }
  10775. state.activeTexture( _gl.TEXTURE0 + slot );
  10776. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  10777. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  10778. var isCompressed = ( texture && texture.isCompressedTexture );
  10779. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  10780. var cubeImage = [];
  10781. for ( var i = 0; i < 6; i ++ ) {
  10782. if ( ! isCompressed && ! isDataTexture ) {
  10783. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  10784. } else {
  10785. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  10786. }
  10787. }
  10788. var image = cubeImage[ 0 ],
  10789. isPowerOfTwoImage = isPowerOfTwo( image ),
  10790. glFormat = paramThreeToGL( texture.format ),
  10791. glType = paramThreeToGL( texture.type );
  10792. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  10793. for ( var i = 0; i < 6; i ++ ) {
  10794. if ( ! isCompressed ) {
  10795. if ( isDataTexture ) {
  10796. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  10797. } else {
  10798. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  10799. }
  10800. } else {
  10801. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  10802. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  10803. mipmap = mipmaps[ j ];
  10804. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  10805. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  10806. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  10807. } else {
  10808. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()" );
  10809. }
  10810. } else {
  10811. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10812. }
  10813. }
  10814. }
  10815. }
  10816. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  10817. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  10818. }
  10819. textureProperties.__version = texture.version;
  10820. if ( texture.onUpdate ) texture.onUpdate( texture );
  10821. } else {
  10822. state.activeTexture( _gl.TEXTURE0 + slot );
  10823. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  10824. }
  10825. }
  10826. }
  10827. function setTextureCubeDynamic( texture, slot ) {
  10828. state.activeTexture( _gl.TEXTURE0 + slot );
  10829. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  10830. }
  10831. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  10832. var extension;
  10833. if ( isPowerOfTwoImage ) {
  10834. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  10835. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  10836. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  10837. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  10838. } else {
  10839. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  10840. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  10841. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  10842. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  10843. }
  10844. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  10845. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  10846. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  10847. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  10848. }
  10849. }
  10850. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  10851. if ( extension ) {
  10852. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  10853. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  10854. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  10855. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  10856. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  10857. }
  10858. }
  10859. }
  10860. function uploadTexture( textureProperties, texture, slot ) {
  10861. if ( textureProperties.__webglInit === undefined ) {
  10862. textureProperties.__webglInit = true;
  10863. texture.addEventListener( 'dispose', onTextureDispose );
  10864. textureProperties.__webglTexture = _gl.createTexture();
  10865. infoMemory.textures ++;
  10866. }
  10867. state.activeTexture( _gl.TEXTURE0 + slot );
  10868. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  10869. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  10870. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  10871. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  10872. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  10873. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  10874. image = makePowerOfTwo( image );
  10875. }
  10876. var isPowerOfTwoImage = isPowerOfTwo( image ),
  10877. glFormat = paramThreeToGL( texture.format ),
  10878. glType = paramThreeToGL( texture.type );
  10879. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  10880. var mipmap, mipmaps = texture.mipmaps;
  10881. if ( texture.isDepthTexture ) {
  10882. // populate depth texture with dummy data
  10883. var internalFormat = _gl.DEPTH_COMPONENT;
  10884. if ( texture.type === FloatType ) {
  10885. if ( !_isWebGL2 ) throw new Error('Float Depth Texture only supported in WebGL2.0');
  10886. internalFormat = _gl.DEPTH_COMPONENT32F;
  10887. } else if ( _isWebGL2 ) {
  10888. // WebGL 2.0 requires signed internalformat for glTexImage2D
  10889. internalFormat = _gl.DEPTH_COMPONENT16;
  10890. }
  10891. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  10892. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  10893. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  10894. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10895. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  10896. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  10897. texture.type = UnsignedShortType;
  10898. glType = paramThreeToGL( texture.type );
  10899. }
  10900. }
  10901. // Depth stencil textures need the DEPTH_STENCIL internal format
  10902. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10903. if ( texture.format === DepthStencilFormat ) {
  10904. internalFormat = _gl.DEPTH_STENCIL;
  10905. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  10906. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  10907. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  10908. if ( texture.type !== UnsignedInt248Type ) {
  10909. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  10910. texture.type = UnsignedInt248Type;
  10911. glType = paramThreeToGL( texture.type );
  10912. }
  10913. }
  10914. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  10915. } else if ( texture.isDataTexture ) {
  10916. // use manually created mipmaps if available
  10917. // if there are no manual mipmaps
  10918. // set 0 level mipmap and then use GL to generate other mipmap levels
  10919. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  10920. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10921. mipmap = mipmaps[ i ];
  10922. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10923. }
  10924. texture.generateMipmaps = false;
  10925. } else {
  10926. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  10927. }
  10928. } else if ( texture.isCompressedTexture ) {
  10929. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10930. mipmap = mipmaps[ i ];
  10931. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  10932. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  10933. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  10934. } else {
  10935. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  10936. }
  10937. } else {
  10938. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  10939. }
  10940. }
  10941. } else {
  10942. // regular Texture (image, video, canvas)
  10943. // use manually created mipmaps if available
  10944. // if there are no manual mipmaps
  10945. // set 0 level mipmap and then use GL to generate other mipmap levels
  10946. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  10947. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  10948. mipmap = mipmaps[ i ];
  10949. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  10950. }
  10951. texture.generateMipmaps = false;
  10952. } else {
  10953. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  10954. }
  10955. }
  10956. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  10957. textureProperties.__version = texture.version;
  10958. if ( texture.onUpdate ) texture.onUpdate( texture );
  10959. }
  10960. // Render targets
  10961. // Setup storage for target texture and bind it to correct framebuffer
  10962. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  10963. var glFormat = paramThreeToGL( renderTarget.texture.format );
  10964. var glType = paramThreeToGL( renderTarget.texture.type );
  10965. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  10966. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  10967. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  10968. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  10969. }
  10970. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  10971. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  10972. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  10973. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  10974. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  10975. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  10976. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  10977. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  10978. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  10979. } else {
  10980. // FIXME: We don't support !depth !stencil
  10981. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  10982. }
  10983. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  10984. }
  10985. // Setup resources for a Depth Texture for a FBO (needs an extension)
  10986. function setupDepthTexture( framebuffer, renderTarget ) {
  10987. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  10988. if ( isCube ) throw new Error('Depth Texture with cube render targets is not supported!');
  10989. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  10990. if ( !( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  10991. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  10992. }
  10993. // upload an empty depth texture with framebuffer size
  10994. if ( !properties.get( renderTarget.depthTexture ).__webglTexture ||
  10995. renderTarget.depthTexture.image.width !== renderTarget.width ||
  10996. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  10997. renderTarget.depthTexture.image.width = renderTarget.width;
  10998. renderTarget.depthTexture.image.height = renderTarget.height;
  10999. renderTarget.depthTexture.needsUpdate = true;
  11000. }
  11001. setTexture2D( renderTarget.depthTexture, 0 );
  11002. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  11003. if ( renderTarget.depthTexture.format === DepthFormat ) {
  11004. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  11005. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  11006. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  11007. } else {
  11008. throw new Error('Unknown depthTexture format')
  11009. }
  11010. }
  11011. // Setup GL resources for a non-texture depth buffer
  11012. function setupDepthRenderbuffer( renderTarget ) {
  11013. var renderTargetProperties = properties.get( renderTarget );
  11014. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  11015. if ( renderTarget.depthTexture ) {
  11016. if ( isCube ) throw new Error('target.depthTexture not supported in Cube render targets');
  11017. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  11018. } else {
  11019. if ( isCube ) {
  11020. renderTargetProperties.__webglDepthbuffer = [];
  11021. for ( var i = 0; i < 6; i ++ ) {
  11022. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  11023. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  11024. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  11025. }
  11026. } else {
  11027. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  11028. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  11029. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  11030. }
  11031. }
  11032. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  11033. }
  11034. // Set up GL resources for the render target
  11035. function setupRenderTarget( renderTarget ) {
  11036. var renderTargetProperties = properties.get( renderTarget );
  11037. var textureProperties = properties.get( renderTarget.texture );
  11038. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  11039. textureProperties.__webglTexture = _gl.createTexture();
  11040. infoMemory.textures ++;
  11041. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  11042. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  11043. // Setup framebuffer
  11044. if ( isCube ) {
  11045. renderTargetProperties.__webglFramebuffer = [];
  11046. for ( var i = 0; i < 6; i ++ ) {
  11047. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  11048. }
  11049. } else {
  11050. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  11051. }
  11052. // Setup color buffer
  11053. if ( isCube ) {
  11054. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  11055. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  11056. for ( var i = 0; i < 6; i ++ ) {
  11057. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  11058. }
  11059. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  11060. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  11061. } else {
  11062. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  11063. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  11064. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  11065. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  11066. state.bindTexture( _gl.TEXTURE_2D, null );
  11067. }
  11068. // Setup depth and stencil buffers
  11069. if ( renderTarget.depthBuffer ) {
  11070. setupDepthRenderbuffer( renderTarget );
  11071. }
  11072. }
  11073. function updateRenderTargetMipmap( renderTarget ) {
  11074. var texture = renderTarget.texture;
  11075. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  11076. texture.minFilter !== NearestFilter &&
  11077. texture.minFilter !== LinearFilter ) {
  11078. var target = (renderTarget && renderTarget.isWebGLRenderTargetCube) ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  11079. var webglTexture = properties.get( texture ).__webglTexture;
  11080. state.bindTexture( target, webglTexture );
  11081. _gl.generateMipmap( target );
  11082. state.bindTexture( target, null );
  11083. }
  11084. }
  11085. this.setTexture2D = setTexture2D;
  11086. this.setTextureCube = setTextureCube;
  11087. this.setTextureCubeDynamic = setTextureCubeDynamic;
  11088. this.setupRenderTarget = setupRenderTarget;
  11089. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  11090. }
  11091. /**
  11092. * @author fordacious / fordacious.github.io
  11093. */
  11094. function WebGLProperties() {
  11095. var properties = {};
  11096. function get( object ) {
  11097. var uuid = object.uuid;
  11098. var map = properties[ uuid ];
  11099. if ( map === undefined ) {
  11100. map = {};
  11101. properties[ uuid ] = map;
  11102. }
  11103. return map;
  11104. }
  11105. function remove( object ) {
  11106. delete properties[ object.uuid ];
  11107. }
  11108. function clear() {
  11109. properties = {};
  11110. }
  11111. return {
  11112. get: get,
  11113. remove: remove,
  11114. clear: clear
  11115. };
  11116. }
  11117. /**
  11118. * @author mrdoob / http://mrdoob.com/
  11119. */
  11120. function WebGLState( gl, extensions, paramThreeToGL ) {
  11121. function ColorBuffer() {
  11122. var locked = false;
  11123. var color = new Vector4();
  11124. var currentColorMask = null;
  11125. var currentColorClear = new Vector4();
  11126. return {
  11127. setMask: function ( colorMask ) {
  11128. if ( currentColorMask !== colorMask && ! locked ) {
  11129. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11130. currentColorMask = colorMask;
  11131. }
  11132. },
  11133. setLocked: function ( lock ) {
  11134. locked = lock;
  11135. },
  11136. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11137. if ( premultipliedAlpha === true ) {
  11138. r *= a; g *= a; b *= a;
  11139. }
  11140. color.set( r, g, b, a );
  11141. if ( currentColorClear.equals( color ) === false ) {
  11142. gl.clearColor( r, g, b, a );
  11143. currentColorClear.copy( color );
  11144. }
  11145. },
  11146. reset: function () {
  11147. locked = false;
  11148. currentColorMask = null;
  11149. currentColorClear.set( 0, 0, 0, 1 );
  11150. }
  11151. };
  11152. }
  11153. function DepthBuffer() {
  11154. var locked = false;
  11155. var currentDepthMask = null;
  11156. var currentDepthFunc = null;
  11157. var currentDepthClear = null;
  11158. return {
  11159. setTest: function ( depthTest ) {
  11160. if ( depthTest ) {
  11161. enable( gl.DEPTH_TEST );
  11162. } else {
  11163. disable( gl.DEPTH_TEST );
  11164. }
  11165. },
  11166. setMask: function ( depthMask ) {
  11167. if ( currentDepthMask !== depthMask && ! locked ) {
  11168. gl.depthMask( depthMask );
  11169. currentDepthMask = depthMask;
  11170. }
  11171. },
  11172. setFunc: function ( depthFunc ) {
  11173. if ( currentDepthFunc !== depthFunc ) {
  11174. if ( depthFunc ) {
  11175. switch ( depthFunc ) {
  11176. case NeverDepth:
  11177. gl.depthFunc( gl.NEVER );
  11178. break;
  11179. case AlwaysDepth:
  11180. gl.depthFunc( gl.ALWAYS );
  11181. break;
  11182. case LessDepth:
  11183. gl.depthFunc( gl.LESS );
  11184. break;
  11185. case LessEqualDepth:
  11186. gl.depthFunc( gl.LEQUAL );
  11187. break;
  11188. case EqualDepth:
  11189. gl.depthFunc( gl.EQUAL );
  11190. break;
  11191. case GreaterEqualDepth:
  11192. gl.depthFunc( gl.GEQUAL );
  11193. break;
  11194. case GreaterDepth:
  11195. gl.depthFunc( gl.GREATER );
  11196. break;
  11197. case NotEqualDepth:
  11198. gl.depthFunc( gl.NOTEQUAL );
  11199. break;
  11200. default:
  11201. gl.depthFunc( gl.LEQUAL );
  11202. }
  11203. } else {
  11204. gl.depthFunc( gl.LEQUAL );
  11205. }
  11206. currentDepthFunc = depthFunc;
  11207. }
  11208. },
  11209. setLocked: function ( lock ) {
  11210. locked = lock;
  11211. },
  11212. setClear: function ( depth ) {
  11213. if ( currentDepthClear !== depth ) {
  11214. gl.clearDepth( depth );
  11215. currentDepthClear = depth;
  11216. }
  11217. },
  11218. reset: function () {
  11219. locked = false;
  11220. currentDepthMask = null;
  11221. currentDepthFunc = null;
  11222. currentDepthClear = null;
  11223. }
  11224. };
  11225. }
  11226. function StencilBuffer() {
  11227. var locked = false;
  11228. var currentStencilMask = null;
  11229. var currentStencilFunc = null;
  11230. var currentStencilRef = null;
  11231. var currentStencilFuncMask = null;
  11232. var currentStencilFail = null;
  11233. var currentStencilZFail = null;
  11234. var currentStencilZPass = null;
  11235. var currentStencilClear = null;
  11236. return {
  11237. setTest: function ( stencilTest ) {
  11238. if ( stencilTest ) {
  11239. enable( gl.STENCIL_TEST );
  11240. } else {
  11241. disable( gl.STENCIL_TEST );
  11242. }
  11243. },
  11244. setMask: function ( stencilMask ) {
  11245. if ( currentStencilMask !== stencilMask && ! locked ) {
  11246. gl.stencilMask( stencilMask );
  11247. currentStencilMask = stencilMask;
  11248. }
  11249. },
  11250. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11251. if ( currentStencilFunc !== stencilFunc ||
  11252. currentStencilRef !== stencilRef ||
  11253. currentStencilFuncMask !== stencilMask ) {
  11254. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11255. currentStencilFunc = stencilFunc;
  11256. currentStencilRef = stencilRef;
  11257. currentStencilFuncMask = stencilMask;
  11258. }
  11259. },
  11260. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11261. if ( currentStencilFail !== stencilFail ||
  11262. currentStencilZFail !== stencilZFail ||
  11263. currentStencilZPass !== stencilZPass ) {
  11264. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11265. currentStencilFail = stencilFail;
  11266. currentStencilZFail = stencilZFail;
  11267. currentStencilZPass = stencilZPass;
  11268. }
  11269. },
  11270. setLocked: function ( lock ) {
  11271. locked = lock;
  11272. },
  11273. setClear: function ( stencil ) {
  11274. if ( currentStencilClear !== stencil ) {
  11275. gl.clearStencil( stencil );
  11276. currentStencilClear = stencil;
  11277. }
  11278. },
  11279. reset: function () {
  11280. locked = false;
  11281. currentStencilMask = null;
  11282. currentStencilFunc = null;
  11283. currentStencilRef = null;
  11284. currentStencilFuncMask = null;
  11285. currentStencilFail = null;
  11286. currentStencilZFail = null;
  11287. currentStencilZPass = null;
  11288. currentStencilClear = null;
  11289. }
  11290. };
  11291. }
  11292. //
  11293. var colorBuffer = new ColorBuffer();
  11294. var depthBuffer = new DepthBuffer();
  11295. var stencilBuffer = new StencilBuffer();
  11296. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11297. var newAttributes = new Uint8Array( maxVertexAttributes );
  11298. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11299. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11300. var capabilities = {};
  11301. var compressedTextureFormats = null;
  11302. var currentBlending = null;
  11303. var currentBlendEquation = null;
  11304. var currentBlendSrc = null;
  11305. var currentBlendDst = null;
  11306. var currentBlendEquationAlpha = null;
  11307. var currentBlendSrcAlpha = null;
  11308. var currentBlendDstAlpha = null;
  11309. var currentPremultipledAlpha = false;
  11310. var currentFlipSided = null;
  11311. var currentCullFace = null;
  11312. var currentLineWidth = null;
  11313. var currentPolygonOffsetFactor = null;
  11314. var currentPolygonOffsetUnits = null;
  11315. var currentScissorTest = null;
  11316. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  11317. var version = parseFloat( /^WebGL\ ([0-9])/.exec( gl.getParameter( gl.VERSION ) )[ 1 ] );
  11318. var lineWidthAvailable = parseFloat( version ) >= 1.0;
  11319. var currentTextureSlot = null;
  11320. var currentBoundTextures = {};
  11321. var currentScissor = new Vector4();
  11322. var currentViewport = new Vector4();
  11323. function createTexture( type, target, count ) {
  11324. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11325. var texture = gl.createTexture();
  11326. gl.bindTexture( type, texture );
  11327. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  11328. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  11329. for ( var i = 0; i < count; i ++ ) {
  11330. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  11331. }
  11332. return texture;
  11333. }
  11334. var emptyTextures = {};
  11335. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  11336. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  11337. //
  11338. function init() {
  11339. colorBuffer.setClear( 0, 0, 0, 1 );
  11340. depthBuffer.setClear( 1 );
  11341. stencilBuffer.setClear( 0 );
  11342. enable( gl.DEPTH_TEST );
  11343. depthBuffer.setFunc( LessEqualDepth );
  11344. setFlipSided( false );
  11345. setCullFace( CullFaceBack );
  11346. enable( gl.CULL_FACE );
  11347. enable( gl.BLEND );
  11348. setBlending( NormalBlending );
  11349. }
  11350. function initAttributes() {
  11351. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11352. newAttributes[ i ] = 0;
  11353. }
  11354. }
  11355. function enableAttribute( attribute ) {
  11356. newAttributes[ attribute ] = 1;
  11357. if ( enabledAttributes[ attribute ] === 0 ) {
  11358. gl.enableVertexAttribArray( attribute );
  11359. enabledAttributes[ attribute ] = 1;
  11360. }
  11361. if ( attributeDivisors[ attribute ] !== 0 ) {
  11362. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11363. extension.vertexAttribDivisorANGLE( attribute, 0 );
  11364. attributeDivisors[ attribute ] = 0;
  11365. }
  11366. }
  11367. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11368. newAttributes[ attribute ] = 1;
  11369. if ( enabledAttributes[ attribute ] === 0 ) {
  11370. gl.enableVertexAttribArray( attribute );
  11371. enabledAttributes[ attribute ] = 1;
  11372. }
  11373. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11374. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11375. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  11376. attributeDivisors[ attribute ] = meshPerAttribute;
  11377. }
  11378. }
  11379. function disableUnusedAttributes() {
  11380. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11381. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11382. gl.disableVertexAttribArray( i );
  11383. enabledAttributes[ i ] = 0;
  11384. }
  11385. }
  11386. }
  11387. function enable( id ) {
  11388. if ( capabilities[ id ] !== true ) {
  11389. gl.enable( id );
  11390. capabilities[ id ] = true;
  11391. }
  11392. }
  11393. function disable( id ) {
  11394. if ( capabilities[ id ] !== false ) {
  11395. gl.disable( id );
  11396. capabilities[ id ] = false;
  11397. }
  11398. }
  11399. function getCompressedTextureFormats() {
  11400. if ( compressedTextureFormats === null ) {
  11401. compressedTextureFormats = [];
  11402. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11403. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11404. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  11405. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  11406. for ( var i = 0; i < formats.length; i ++ ) {
  11407. compressedTextureFormats.push( formats[ i ] );
  11408. }
  11409. }
  11410. }
  11411. return compressedTextureFormats;
  11412. }
  11413. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11414. if ( blending !== NoBlending ) {
  11415. enable( gl.BLEND );
  11416. } else {
  11417. disable( gl.BLEND );
  11418. }
  11419. if ( ( blending !== CustomBlending ) && ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) ) {
  11420. if ( blending === AdditiveBlending ) {
  11421. if ( premultipliedAlpha ) {
  11422. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11423. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  11424. } else {
  11425. gl.blendEquation( gl.FUNC_ADD );
  11426. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  11427. }
  11428. } else if ( blending === SubtractiveBlending ) {
  11429. if ( premultipliedAlpha ) {
  11430. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11431. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  11432. } else {
  11433. gl.blendEquation( gl.FUNC_ADD );
  11434. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  11435. }
  11436. } else if ( blending === MultiplyBlending ) {
  11437. if ( premultipliedAlpha ) {
  11438. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11439. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  11440. } else {
  11441. gl.blendEquation( gl.FUNC_ADD );
  11442. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  11443. }
  11444. } else {
  11445. if ( premultipliedAlpha ) {
  11446. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11447. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11448. } else {
  11449. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11450. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11451. }
  11452. }
  11453. currentBlending = blending;
  11454. currentPremultipledAlpha = premultipliedAlpha;
  11455. }
  11456. if ( blending === CustomBlending ) {
  11457. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11458. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11459. blendDstAlpha = blendDstAlpha || blendDst;
  11460. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11461. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  11462. currentBlendEquation = blendEquation;
  11463. currentBlendEquationAlpha = blendEquationAlpha;
  11464. }
  11465. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11466. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  11467. currentBlendSrc = blendSrc;
  11468. currentBlendDst = blendDst;
  11469. currentBlendSrcAlpha = blendSrcAlpha;
  11470. currentBlendDstAlpha = blendDstAlpha;
  11471. }
  11472. } else {
  11473. currentBlendEquation = null;
  11474. currentBlendSrc = null;
  11475. currentBlendDst = null;
  11476. currentBlendEquationAlpha = null;
  11477. currentBlendSrcAlpha = null;
  11478. currentBlendDstAlpha = null;
  11479. }
  11480. }
  11481. function setMaterial( material ) {
  11482. material.side === DoubleSide
  11483. ? disable( gl.CULL_FACE )
  11484. : enable( gl.CULL_FACE );
  11485. setFlipSided( material.side === BackSide );
  11486. material.transparent === true
  11487. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  11488. : setBlending( NoBlending );
  11489. depthBuffer.setFunc( material.depthFunc );
  11490. depthBuffer.setTest( material.depthTest );
  11491. depthBuffer.setMask( material.depthWrite );
  11492. colorBuffer.setMask( material.colorWrite );
  11493. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11494. }
  11495. //
  11496. function setFlipSided( flipSided ) {
  11497. if ( currentFlipSided !== flipSided ) {
  11498. if ( flipSided ) {
  11499. gl.frontFace( gl.CW );
  11500. } else {
  11501. gl.frontFace( gl.CCW );
  11502. }
  11503. currentFlipSided = flipSided;
  11504. }
  11505. }
  11506. function setCullFace( cullFace ) {
  11507. if ( cullFace !== CullFaceNone ) {
  11508. enable( gl.CULL_FACE );
  11509. if ( cullFace !== currentCullFace ) {
  11510. if ( cullFace === CullFaceBack ) {
  11511. gl.cullFace( gl.BACK );
  11512. } else if ( cullFace === CullFaceFront ) {
  11513. gl.cullFace( gl.FRONT );
  11514. } else {
  11515. gl.cullFace( gl.FRONT_AND_BACK );
  11516. }
  11517. }
  11518. } else {
  11519. disable( gl.CULL_FACE );
  11520. }
  11521. currentCullFace = cullFace;
  11522. }
  11523. function setLineWidth( width ) {
  11524. if ( width !== currentLineWidth ) {
  11525. if ( lineWidthAvailable ) gl.lineWidth( width );
  11526. currentLineWidth = width;
  11527. }
  11528. }
  11529. function setPolygonOffset( polygonOffset, factor, units ) {
  11530. if ( polygonOffset ) {
  11531. enable( gl.POLYGON_OFFSET_FILL );
  11532. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11533. gl.polygonOffset( factor, units );
  11534. currentPolygonOffsetFactor = factor;
  11535. currentPolygonOffsetUnits = units;
  11536. }
  11537. } else {
  11538. disable( gl.POLYGON_OFFSET_FILL );
  11539. }
  11540. }
  11541. function getScissorTest() {
  11542. return currentScissorTest;
  11543. }
  11544. function setScissorTest( scissorTest ) {
  11545. currentScissorTest = scissorTest;
  11546. if ( scissorTest ) {
  11547. enable( gl.SCISSOR_TEST );
  11548. } else {
  11549. disable( gl.SCISSOR_TEST );
  11550. }
  11551. }
  11552. // texture
  11553. function activeTexture( webglSlot ) {
  11554. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  11555. if ( currentTextureSlot !== webglSlot ) {
  11556. gl.activeTexture( webglSlot );
  11557. currentTextureSlot = webglSlot;
  11558. }
  11559. }
  11560. function bindTexture( webglType, webglTexture ) {
  11561. if ( currentTextureSlot === null ) {
  11562. activeTexture();
  11563. }
  11564. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11565. if ( boundTexture === undefined ) {
  11566. boundTexture = { type: undefined, texture: undefined };
  11567. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11568. }
  11569. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11570. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11571. boundTexture.type = webglType;
  11572. boundTexture.texture = webglTexture;
  11573. }
  11574. }
  11575. function compressedTexImage2D() {
  11576. try {
  11577. gl.compressedTexImage2D.apply( gl, arguments );
  11578. } catch ( error ) {
  11579. console.error( error );
  11580. }
  11581. }
  11582. function texImage2D() {
  11583. try {
  11584. gl.texImage2D.apply( gl, arguments );
  11585. } catch ( error ) {
  11586. console.error( error );
  11587. }
  11588. }
  11589. //
  11590. function scissor( scissor ) {
  11591. if ( currentScissor.equals( scissor ) === false ) {
  11592. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11593. currentScissor.copy( scissor );
  11594. }
  11595. }
  11596. function viewport( viewport ) {
  11597. if ( currentViewport.equals( viewport ) === false ) {
  11598. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11599. currentViewport.copy( viewport );
  11600. }
  11601. }
  11602. //
  11603. function reset() {
  11604. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11605. if ( enabledAttributes[ i ] === 1 ) {
  11606. gl.disableVertexAttribArray( i );
  11607. enabledAttributes[ i ] = 0;
  11608. }
  11609. }
  11610. capabilities = {};
  11611. compressedTextureFormats = null;
  11612. currentTextureSlot = null;
  11613. currentBoundTextures = {};
  11614. currentBlending = null;
  11615. currentFlipSided = null;
  11616. currentCullFace = null;
  11617. colorBuffer.reset();
  11618. depthBuffer.reset();
  11619. stencilBuffer.reset();
  11620. }
  11621. return {
  11622. buffers: {
  11623. color: colorBuffer,
  11624. depth: depthBuffer,
  11625. stencil: stencilBuffer
  11626. },
  11627. init: init,
  11628. initAttributes: initAttributes,
  11629. enableAttribute: enableAttribute,
  11630. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11631. disableUnusedAttributes: disableUnusedAttributes,
  11632. enable: enable,
  11633. disable: disable,
  11634. getCompressedTextureFormats: getCompressedTextureFormats,
  11635. setBlending: setBlending,
  11636. setMaterial: setMaterial,
  11637. setFlipSided: setFlipSided,
  11638. setCullFace: setCullFace,
  11639. setLineWidth: setLineWidth,
  11640. setPolygonOffset: setPolygonOffset,
  11641. getScissorTest: getScissorTest,
  11642. setScissorTest: setScissorTest,
  11643. activeTexture: activeTexture,
  11644. bindTexture: bindTexture,
  11645. compressedTexImage2D: compressedTexImage2D,
  11646. texImage2D: texImage2D,
  11647. scissor: scissor,
  11648. viewport: viewport,
  11649. reset: reset
  11650. };
  11651. }
  11652. /**
  11653. * @author mrdoob / http://mrdoob.com/
  11654. */
  11655. function WebGLCapabilities( gl, extensions, parameters ) {
  11656. var maxAnisotropy;
  11657. function getMaxAnisotropy() {
  11658. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  11659. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11660. if ( extension !== null ) {
  11661. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11662. } else {
  11663. maxAnisotropy = 0;
  11664. }
  11665. return maxAnisotropy;
  11666. }
  11667. function getMaxPrecision( precision ) {
  11668. if ( precision === 'highp' ) {
  11669. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  11670. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  11671. return 'highp';
  11672. }
  11673. precision = 'mediump';
  11674. }
  11675. if ( precision === 'mediump' ) {
  11676. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  11677. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  11678. return 'mediump';
  11679. }
  11680. }
  11681. return 'lowp';
  11682. }
  11683. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  11684. var maxPrecision = getMaxPrecision( precision );
  11685. if ( maxPrecision !== precision ) {
  11686. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  11687. precision = maxPrecision;
  11688. }
  11689. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true && !! extensions.get( 'EXT_frag_depth' );
  11690. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  11691. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11692. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  11693. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11694. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11695. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  11696. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  11697. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  11698. var vertexTextures = maxVertexTextures > 0;
  11699. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  11700. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  11701. return {
  11702. getMaxAnisotropy: getMaxAnisotropy,
  11703. getMaxPrecision: getMaxPrecision,
  11704. precision: precision,
  11705. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11706. maxTextures: maxTextures,
  11707. maxVertexTextures: maxVertexTextures,
  11708. maxTextureSize: maxTextureSize,
  11709. maxCubemapSize: maxCubemapSize,
  11710. maxAttributes: maxAttributes,
  11711. maxVertexUniforms: maxVertexUniforms,
  11712. maxVaryings: maxVaryings,
  11713. maxFragmentUniforms: maxFragmentUniforms,
  11714. vertexTextures: vertexTextures,
  11715. floatFragmentTextures: floatFragmentTextures,
  11716. floatVertexTextures: floatVertexTextures
  11717. };
  11718. }
  11719. /**
  11720. * @author mrdoob / http://mrdoob.com/
  11721. */
  11722. function WebGLExtensions( gl ) {
  11723. var extensions = {};
  11724. return {
  11725. get: function ( name ) {
  11726. if ( extensions[ name ] !== undefined ) {
  11727. return extensions[ name ];
  11728. }
  11729. var extension;
  11730. switch ( name ) {
  11731. case 'WEBGL_depth_texture':
  11732. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  11733. break;
  11734. case 'EXT_texture_filter_anisotropic':
  11735. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  11736. break;
  11737. case 'WEBGL_compressed_texture_s3tc':
  11738. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  11739. break;
  11740. case 'WEBGL_compressed_texture_pvrtc':
  11741. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  11742. break;
  11743. case 'WEBGL_compressed_texture_etc1':
  11744. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  11745. break;
  11746. default:
  11747. extension = gl.getExtension( name );
  11748. }
  11749. if ( extension === null ) {
  11750. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  11751. }
  11752. extensions[ name ] = extension;
  11753. return extension;
  11754. }
  11755. };
  11756. }
  11757. /**
  11758. * @author tschw
  11759. */
  11760. function WebGLClipping() {
  11761. var scope = this,
  11762. globalState = null,
  11763. numGlobalPlanes = 0,
  11764. localClippingEnabled = false,
  11765. renderingShadows = false,
  11766. plane = new Plane(),
  11767. viewNormalMatrix = new Matrix3(),
  11768. uniform = { value: null, needsUpdate: false };
  11769. this.uniform = uniform;
  11770. this.numPlanes = 0;
  11771. this.numIntersection = 0;
  11772. this.init = function( planes, enableLocalClipping, camera ) {
  11773. var enabled =
  11774. planes.length !== 0 ||
  11775. enableLocalClipping ||
  11776. // enable state of previous frame - the clipping code has to
  11777. // run another frame in order to reset the state:
  11778. numGlobalPlanes !== 0 ||
  11779. localClippingEnabled;
  11780. localClippingEnabled = enableLocalClipping;
  11781. globalState = projectPlanes( planes, camera, 0 );
  11782. numGlobalPlanes = planes.length;
  11783. return enabled;
  11784. };
  11785. this.beginShadows = function() {
  11786. renderingShadows = true;
  11787. projectPlanes( null );
  11788. };
  11789. this.endShadows = function() {
  11790. renderingShadows = false;
  11791. resetGlobalState();
  11792. };
  11793. this.setState = function( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  11794. if ( ! localClippingEnabled ||
  11795. planes === null || planes.length === 0 ||
  11796. renderingShadows && ! clipShadows ) {
  11797. // there's no local clipping
  11798. if ( renderingShadows ) {
  11799. // there's no global clipping
  11800. projectPlanes( null );
  11801. } else {
  11802. resetGlobalState();
  11803. }
  11804. } else {
  11805. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  11806. lGlobal = nGlobal * 4,
  11807. dstArray = cache.clippingState || null;
  11808. uniform.value = dstArray; // ensure unique state
  11809. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  11810. for ( var i = 0; i !== lGlobal; ++ i ) {
  11811. dstArray[ i ] = globalState[ i ];
  11812. }
  11813. cache.clippingState = dstArray;
  11814. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  11815. this.numPlanes += nGlobal;
  11816. }
  11817. };
  11818. function resetGlobalState() {
  11819. if ( uniform.value !== globalState ) {
  11820. uniform.value = globalState;
  11821. uniform.needsUpdate = numGlobalPlanes > 0;
  11822. }
  11823. scope.numPlanes = numGlobalPlanes;
  11824. scope.numIntersection = 0;
  11825. }
  11826. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  11827. var nPlanes = planes !== null ? planes.length : 0,
  11828. dstArray = null;
  11829. if ( nPlanes !== 0 ) {
  11830. dstArray = uniform.value;
  11831. if ( skipTransform !== true || dstArray === null ) {
  11832. var flatSize = dstOffset + nPlanes * 4,
  11833. viewMatrix = camera.matrixWorldInverse;
  11834. viewNormalMatrix.getNormalMatrix( viewMatrix );
  11835. if ( dstArray === null || dstArray.length < flatSize ) {
  11836. dstArray = new Float32Array( flatSize );
  11837. }
  11838. for ( var i = 0, i4 = dstOffset;
  11839. i !== nPlanes; ++ i, i4 += 4 ) {
  11840. plane.copy( planes[ i ] ).
  11841. applyMatrix4( viewMatrix, viewNormalMatrix );
  11842. plane.normal.toArray( dstArray, i4 );
  11843. dstArray[ i4 + 3 ] = plane.constant;
  11844. }
  11845. }
  11846. uniform.value = dstArray;
  11847. uniform.needsUpdate = true;
  11848. }
  11849. scope.numPlanes = nPlanes;
  11850. return dstArray;
  11851. }
  11852. }
  11853. // import { Sphere } from '../math/Sphere';
  11854. /**
  11855. * @author supereggbert / http://www.paulbrunt.co.uk/
  11856. * @author mrdoob / http://mrdoob.com/
  11857. * @author alteredq / http://alteredqualia.com/
  11858. * @author szimek / https://github.com/szimek/
  11859. * @author tschw
  11860. */
  11861. function WebGLRenderer( parameters ) {
  11862. console.log( 'THREE.WebGLRenderer', REVISION );
  11863. parameters = parameters || {};
  11864. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  11865. _context = parameters.context !== undefined ? parameters.context : null,
  11866. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11867. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11868. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11869. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11870. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11871. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  11872. var lights = [];
  11873. var currentRenderList = null;
  11874. var morphInfluences = new Float32Array( 8 );
  11875. var sprites = [];
  11876. var lensFlares = [];
  11877. // public properties
  11878. this.domElement = _canvas;
  11879. this.context = null;
  11880. // clearing
  11881. this.autoClear = true;
  11882. this.autoClearColor = true;
  11883. this.autoClearDepth = true;
  11884. this.autoClearStencil = true;
  11885. // scene graph
  11886. this.sortObjects = true;
  11887. // user-defined clipping
  11888. this.clippingPlanes = [];
  11889. this.localClippingEnabled = false;
  11890. // physically based shading
  11891. this.gammaFactor = 2.0; // for backwards compatibility
  11892. this.gammaInput = false;
  11893. this.gammaOutput = false;
  11894. // physical lights
  11895. this.physicallyCorrectLights = false;
  11896. // tone mapping
  11897. this.toneMapping = LinearToneMapping;
  11898. this.toneMappingExposure = 1.0;
  11899. this.toneMappingWhitePoint = 1.0;
  11900. // morphs
  11901. this.maxMorphTargets = 8;
  11902. this.maxMorphNormals = 4;
  11903. // internal properties
  11904. var _this = this,
  11905. // internal state cache
  11906. _currentProgram = null,
  11907. _currentRenderTarget = null,
  11908. _currentFramebuffer = null,
  11909. _currentMaterialId = - 1,
  11910. _currentGeometryProgram = '',
  11911. _currentCamera = null,
  11912. _currentScissor = new Vector4(),
  11913. _currentScissorTest = null,
  11914. _currentViewport = new Vector4(),
  11915. //
  11916. _usedTextureUnits = 0,
  11917. //
  11918. _clearColor = new Color( 0x000000 ),
  11919. _clearAlpha = 0,
  11920. _width = _canvas.width,
  11921. _height = _canvas.height,
  11922. _pixelRatio = 1,
  11923. _scissor = new Vector4( 0, 0, _width, _height ),
  11924. _scissorTest = false,
  11925. _viewport = new Vector4( 0, 0, _width, _height ),
  11926. // frustum
  11927. _frustum = new Frustum(),
  11928. // clipping
  11929. _clipping = new WebGLClipping(),
  11930. _clippingEnabled = false,
  11931. _localClippingEnabled = false,
  11932. // camera matrices cache
  11933. _projScreenMatrix = new Matrix4(),
  11934. _vector3 = new Vector3(),
  11935. _matrix4 = new Matrix4(),
  11936. _matrix42 = new Matrix4(),
  11937. // light arrays cache
  11938. _lights = {
  11939. hash: '',
  11940. ambient: [ 0, 0, 0 ],
  11941. directional: [],
  11942. directionalShadowMap: [],
  11943. directionalShadowMatrix: [],
  11944. spot: [],
  11945. spotShadowMap: [],
  11946. spotShadowMatrix: [],
  11947. rectArea: [],
  11948. point: [],
  11949. pointShadowMap: [],
  11950. pointShadowMatrix: [],
  11951. hemi: [],
  11952. shadows: []
  11953. },
  11954. // info
  11955. _infoMemory = {
  11956. geometries: 0,
  11957. textures: 0
  11958. },
  11959. _infoRender = {
  11960. frame: 0,
  11961. calls: 0,
  11962. vertices: 0,
  11963. faces: 0,
  11964. points: 0
  11965. };
  11966. this.info = {
  11967. render: _infoRender,
  11968. memory: _infoMemory,
  11969. programs: null
  11970. };
  11971. // initialize
  11972. var _gl;
  11973. try {
  11974. var contextAttributes = {
  11975. alpha: _alpha,
  11976. depth: _depth,
  11977. stencil: _stencil,
  11978. antialias: _antialias,
  11979. premultipliedAlpha: _premultipliedAlpha,
  11980. preserveDrawingBuffer: _preserveDrawingBuffer
  11981. };
  11982. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  11983. if ( _gl === null ) {
  11984. if ( _canvas.getContext( 'webgl' ) !== null ) {
  11985. throw 'Error creating WebGL context with your selected attributes.';
  11986. } else {
  11987. throw 'Error creating WebGL context.';
  11988. }
  11989. }
  11990. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  11991. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11992. _gl.getShaderPrecisionFormat = function () {
  11993. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  11994. };
  11995. }
  11996. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  11997. } catch ( error ) {
  11998. console.error( 'THREE.WebGLRenderer: ' + error );
  11999. }
  12000. var extensions = new WebGLExtensions( _gl );
  12001. extensions.get( 'WEBGL_depth_texture' );
  12002. extensions.get( 'OES_texture_float' );
  12003. extensions.get( 'OES_texture_float_linear' );
  12004. extensions.get( 'OES_texture_half_float' );
  12005. extensions.get( 'OES_texture_half_float_linear' );
  12006. extensions.get( 'OES_standard_derivatives' );
  12007. extensions.get( 'ANGLE_instanced_arrays' );
  12008. if ( extensions.get( 'OES_element_index_uint' ) ) {
  12009. BufferGeometry.MaxIndex = 4294967296;
  12010. }
  12011. var capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  12012. var state = new WebGLState( _gl, extensions, paramThreeToGL );
  12013. var properties = new WebGLProperties();
  12014. var textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, _infoMemory );
  12015. var attributes = new WebGLAttributes( _gl );
  12016. var geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
  12017. var objects = new WebGLObjects( _gl, geometries, _infoRender );
  12018. var programCache = new WebGLPrograms( this, capabilities );
  12019. var lightCache = new WebGLLights();
  12020. var renderLists = new WebGLRenderLists();
  12021. this.info.programs = programCache.programs;
  12022. var bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
  12023. var indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12024. //
  12025. var backgroundPlaneCamera, backgroundPlaneMesh;
  12026. var backgroundBoxCamera, backgroundBoxMesh;
  12027. //
  12028. function getTargetPixelRatio() {
  12029. return _currentRenderTarget === null ? _pixelRatio : 1;
  12030. }
  12031. function setDefaultGLState() {
  12032. state.init();
  12033. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  12034. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  12035. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12036. }
  12037. function resetGLState() {
  12038. _currentProgram = null;
  12039. _currentCamera = null;
  12040. _currentGeometryProgram = '';
  12041. _currentMaterialId = - 1;
  12042. state.reset();
  12043. }
  12044. setDefaultGLState();
  12045. this.context = _gl;
  12046. this.capabilities = capabilities;
  12047. this.extensions = extensions;
  12048. this.properties = properties;
  12049. this.state = state;
  12050. // shadow map
  12051. var shadowMap = new WebGLShadowMap( this, _lights, objects, capabilities );
  12052. this.shadowMap = shadowMap;
  12053. // Plugins
  12054. var spritePlugin = new SpritePlugin( this, sprites );
  12055. var lensFlarePlugin = new LensFlarePlugin( this, lensFlares );
  12056. // API
  12057. this.getContext = function () {
  12058. return _gl;
  12059. };
  12060. this.getContextAttributes = function () {
  12061. return _gl.getContextAttributes();
  12062. };
  12063. this.forceContextLoss = function () {
  12064. var extension = extensions.get( 'WEBGL_lose_context' );
  12065. if ( extension ) extension.loseContext();
  12066. };
  12067. this.getMaxAnisotropy = function () {
  12068. return capabilities.getMaxAnisotropy();
  12069. };
  12070. this.getPrecision = function () {
  12071. return capabilities.precision;
  12072. };
  12073. this.getPixelRatio = function () {
  12074. return _pixelRatio;
  12075. };
  12076. this.setPixelRatio = function ( value ) {
  12077. if ( value === undefined ) return;
  12078. _pixelRatio = value;
  12079. this.setSize( _viewport.z, _viewport.w, false );
  12080. };
  12081. this.getSize = function () {
  12082. return {
  12083. width: _width,
  12084. height: _height
  12085. };
  12086. };
  12087. this.setSize = function ( width, height, updateStyle ) {
  12088. _width = width;
  12089. _height = height;
  12090. _canvas.width = width * _pixelRatio;
  12091. _canvas.height = height * _pixelRatio;
  12092. if ( updateStyle !== false ) {
  12093. _canvas.style.width = width + 'px';
  12094. _canvas.style.height = height + 'px';
  12095. }
  12096. this.setViewport( 0, 0, width, height );
  12097. };
  12098. this.setViewport = function ( x, y, width, height ) {
  12099. state.viewport( _viewport.set( x, y, width, height ) );
  12100. };
  12101. this.setScissor = function ( x, y, width, height ) {
  12102. state.scissor( _scissor.set( x, y, width, height ) );
  12103. };
  12104. this.setScissorTest = function ( boolean ) {
  12105. state.setScissorTest( _scissorTest = boolean );
  12106. };
  12107. // Clearing
  12108. this.getClearColor = function () {
  12109. return _clearColor;
  12110. };
  12111. this.setClearColor = function ( color, alpha ) {
  12112. _clearColor.set( color );
  12113. _clearAlpha = alpha !== undefined ? alpha : 1;
  12114. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12115. };
  12116. this.getClearAlpha = function () {
  12117. return _clearAlpha;
  12118. };
  12119. this.setClearAlpha = function ( alpha ) {
  12120. _clearAlpha = alpha;
  12121. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12122. };
  12123. this.clear = function ( color, depth, stencil ) {
  12124. var bits = 0;
  12125. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12126. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12127. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12128. _gl.clear( bits );
  12129. };
  12130. this.clearColor = function () {
  12131. this.clear( true, false, false );
  12132. };
  12133. this.clearDepth = function () {
  12134. this.clear( false, true, false );
  12135. };
  12136. this.clearStencil = function () {
  12137. this.clear( false, false, true );
  12138. };
  12139. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12140. this.setRenderTarget( renderTarget );
  12141. this.clear( color, depth, stencil );
  12142. };
  12143. // Reset
  12144. this.resetGLState = resetGLState;
  12145. this.dispose = function () {
  12146. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12147. renderLists.dispose();
  12148. };
  12149. // Events
  12150. function onContextLost( event ) {
  12151. event.preventDefault();
  12152. resetGLState();
  12153. setDefaultGLState();
  12154. properties.clear();
  12155. objects.clear();
  12156. }
  12157. function onMaterialDispose( event ) {
  12158. var material = event.target;
  12159. material.removeEventListener( 'dispose', onMaterialDispose );
  12160. deallocateMaterial( material );
  12161. }
  12162. // Buffer deallocation
  12163. function deallocateMaterial( material ) {
  12164. releaseMaterialProgramReference( material );
  12165. properties.remove( material );
  12166. }
  12167. function releaseMaterialProgramReference( material ) {
  12168. var programInfo = properties.get( material ).program;
  12169. material.program = undefined;
  12170. if ( programInfo !== undefined ) {
  12171. programCache.releaseProgram( programInfo );
  12172. }
  12173. }
  12174. // Buffer rendering
  12175. function renderObjectImmediate( object, program, material ) {
  12176. object.render( function ( object ) {
  12177. _this.renderBufferImmediate( object, program, material );
  12178. } );
  12179. }
  12180. this.renderBufferImmediate = function ( object, program, material ) {
  12181. state.initAttributes();
  12182. var buffers = properties.get( object );
  12183. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  12184. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  12185. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  12186. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  12187. var programAttributes = program.getAttributes();
  12188. if ( object.hasPositions ) {
  12189. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  12190. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12191. state.enableAttribute( programAttributes.position );
  12192. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12193. }
  12194. if ( object.hasNormals ) {
  12195. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  12196. if ( ! material.isMeshPhongMaterial &&
  12197. ! material.isMeshStandardMaterial &&
  12198. ! material.isMeshNormalMaterial &&
  12199. material.shading === FlatShading ) {
  12200. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  12201. var array = object.normalArray;
  12202. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  12203. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  12204. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  12205. array[ i + 0 ] = nx;
  12206. array[ i + 1 ] = ny;
  12207. array[ i + 2 ] = nz;
  12208. array[ i + 3 ] = nx;
  12209. array[ i + 4 ] = ny;
  12210. array[ i + 5 ] = nz;
  12211. array[ i + 6 ] = nx;
  12212. array[ i + 7 ] = ny;
  12213. array[ i + 8 ] = nz;
  12214. }
  12215. }
  12216. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12217. state.enableAttribute( programAttributes.normal );
  12218. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12219. }
  12220. if ( object.hasUvs && material.map ) {
  12221. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  12222. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12223. state.enableAttribute( programAttributes.uv );
  12224. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12225. }
  12226. if ( object.hasColors && material.vertexColors !== NoColors ) {
  12227. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  12228. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12229. state.enableAttribute( programAttributes.color );
  12230. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12231. }
  12232. state.disableUnusedAttributes();
  12233. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12234. object.count = 0;
  12235. };
  12236. function absNumericalSort( a, b ) {
  12237. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  12238. }
  12239. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  12240. state.setMaterial( material );
  12241. var program = setProgram( camera, fog, material, object );
  12242. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  12243. var updateBuffers = false;
  12244. if ( geometryProgram !== _currentGeometryProgram ) {
  12245. _currentGeometryProgram = geometryProgram;
  12246. updateBuffers = true;
  12247. }
  12248. // morph targets
  12249. var morphTargetInfluences = object.morphTargetInfluences;
  12250. if ( morphTargetInfluences !== undefined ) {
  12251. // TODO Remove allocations
  12252. var activeInfluences = [];
  12253. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  12254. var influence = morphTargetInfluences[ i ];
  12255. activeInfluences.push( [ influence, i ] );
  12256. }
  12257. activeInfluences.sort( absNumericalSort );
  12258. if ( activeInfluences.length > 8 ) {
  12259. activeInfluences.length = 8;
  12260. }
  12261. var morphAttributes = geometry.morphAttributes;
  12262. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  12263. var influence = activeInfluences[ i ];
  12264. morphInfluences[ i ] = influence[ 0 ];
  12265. if ( influence[ 0 ] !== 0 ) {
  12266. var index = influence[ 1 ];
  12267. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  12268. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  12269. } else {
  12270. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  12271. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  12272. }
  12273. }
  12274. for ( var i = activeInfluences.length, il = morphInfluences.length; i < il; i ++ ) {
  12275. morphInfluences[ i ] = 0.0;
  12276. }
  12277. program.getUniforms().setValue( _gl, 'morphTargetInfluences', morphInfluences );
  12278. updateBuffers = true;
  12279. }
  12280. //
  12281. var index = geometry.index;
  12282. var position = geometry.attributes.position;
  12283. var rangeFactor = 1;
  12284. if ( material.wireframe === true ) {
  12285. index = geometries.getWireframeAttribute( geometry );
  12286. rangeFactor = 2;
  12287. }
  12288. var renderer = bufferRenderer;
  12289. if ( index !== null ) {
  12290. renderer = indexedBufferRenderer;
  12291. renderer.setIndex( index );
  12292. }
  12293. if ( updateBuffers ) {
  12294. setupVertexAttributes( material, program, geometry );
  12295. if ( index !== null ) {
  12296. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attributes.get( index ).buffer );
  12297. }
  12298. }
  12299. //
  12300. var dataCount = 0;
  12301. if ( index !== null ) {
  12302. dataCount = index.count;
  12303. } else if ( position !== undefined ) {
  12304. dataCount = position.count;
  12305. }
  12306. var rangeStart = geometry.drawRange.start * rangeFactor;
  12307. var rangeCount = geometry.drawRange.count * rangeFactor;
  12308. var groupStart = group !== null ? group.start * rangeFactor : 0;
  12309. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  12310. var drawStart = Math.max( rangeStart, groupStart );
  12311. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  12312. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  12313. if ( drawCount === 0 ) return;
  12314. //
  12315. if ( object.isMesh ) {
  12316. if ( material.wireframe === true ) {
  12317. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  12318. renderer.setMode( _gl.LINES );
  12319. } else {
  12320. switch ( object.drawMode ) {
  12321. case TrianglesDrawMode:
  12322. renderer.setMode( _gl.TRIANGLES );
  12323. break;
  12324. case TriangleStripDrawMode:
  12325. renderer.setMode( _gl.TRIANGLE_STRIP );
  12326. break;
  12327. case TriangleFanDrawMode:
  12328. renderer.setMode( _gl.TRIANGLE_FAN );
  12329. break;
  12330. }
  12331. }
  12332. } else if ( object.isLine ) {
  12333. var lineWidth = material.linewidth;
  12334. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  12335. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  12336. if ( object.isLineSegments ) {
  12337. renderer.setMode( _gl.LINES );
  12338. } else if ( object.isLineLoop ) {
  12339. renderer.setMode( _gl.LINE_LOOP );
  12340. } else {
  12341. renderer.setMode( _gl.LINE_STRIP );
  12342. }
  12343. } else if ( object.isPoints ) {
  12344. renderer.setMode( _gl.POINTS );
  12345. }
  12346. if ( geometry && geometry.isInstancedBufferGeometry ) {
  12347. if ( geometry.maxInstancedCount > 0 ) {
  12348. renderer.renderInstances( geometry, drawStart, drawCount );
  12349. }
  12350. } else {
  12351. renderer.render( drawStart, drawCount );
  12352. }
  12353. };
  12354. function setupVertexAttributes( material, program, geometry, startIndex ) {
  12355. if ( geometry && geometry.isInstancedBufferGeometry ) {
  12356. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  12357. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12358. return;
  12359. }
  12360. }
  12361. if ( startIndex === undefined ) startIndex = 0;
  12362. state.initAttributes();
  12363. var geometryAttributes = geometry.attributes;
  12364. var programAttributes = program.getAttributes();
  12365. var materialDefaultAttributeValues = material.defaultAttributeValues;
  12366. for ( var name in programAttributes ) {
  12367. var programAttribute = programAttributes[ name ];
  12368. if ( programAttribute >= 0 ) {
  12369. var geometryAttribute = geometryAttributes[ name ];
  12370. if ( geometryAttribute !== undefined ) {
  12371. var normalized = geometryAttribute.normalized;
  12372. var size = geometryAttribute.itemSize;
  12373. var attributeProperties = attributes.get( geometryAttribute );
  12374. var buffer = attributeProperties.buffer;
  12375. var type = attributeProperties.type;
  12376. var bytesPerElement = attributeProperties.bytesPerElement;
  12377. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  12378. var data = geometryAttribute.data;
  12379. var stride = data.stride;
  12380. var offset = geometryAttribute.offset;
  12381. if ( data && data.isInstancedInterleavedBuffer ) {
  12382. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  12383. if ( geometry.maxInstancedCount === undefined ) {
  12384. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  12385. }
  12386. } else {
  12387. state.enableAttribute( programAttribute );
  12388. }
  12389. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12390. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement );
  12391. } else {
  12392. if ( geometryAttribute.isInstancedBufferAttribute ) {
  12393. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  12394. if ( geometry.maxInstancedCount === undefined ) {
  12395. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  12396. }
  12397. } else {
  12398. state.enableAttribute( programAttribute );
  12399. }
  12400. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12401. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement );
  12402. }
  12403. } else if ( materialDefaultAttributeValues !== undefined ) {
  12404. var value = materialDefaultAttributeValues[ name ];
  12405. if ( value !== undefined ) {
  12406. switch ( value.length ) {
  12407. case 2:
  12408. _gl.vertexAttrib2fv( programAttribute, value );
  12409. break;
  12410. case 3:
  12411. _gl.vertexAttrib3fv( programAttribute, value );
  12412. break;
  12413. case 4:
  12414. _gl.vertexAttrib4fv( programAttribute, value );
  12415. break;
  12416. default:
  12417. _gl.vertexAttrib1fv( programAttribute, value );
  12418. }
  12419. }
  12420. }
  12421. }
  12422. }
  12423. state.disableUnusedAttributes();
  12424. }
  12425. // Compile
  12426. this.compile = function ( scene, camera ) {
  12427. lights = [];
  12428. scene.traverse( function ( object ) {
  12429. if ( object.isLight ) {
  12430. lights.push( object );
  12431. }
  12432. } );
  12433. setupLights( lights, camera );
  12434. scene.traverse( function ( object ) {
  12435. if ( object.material ) {
  12436. if ( Array.isArray( object.material ) ) {
  12437. for ( var i = 0; i < object.material.length; i ++ ) {
  12438. initMaterial( object.material[ i ], scene.fog, object );
  12439. }
  12440. } else {
  12441. initMaterial( object.material, scene.fog, object );
  12442. }
  12443. }
  12444. } );
  12445. };
  12446. // Rendering
  12447. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12448. if ( camera !== undefined && camera.isCamera !== true ) {
  12449. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12450. return;
  12451. }
  12452. // reset caching for this frame
  12453. _currentGeometryProgram = '';
  12454. _currentMaterialId = - 1;
  12455. _currentCamera = null;
  12456. // update scene graph
  12457. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12458. // update camera matrices and frustum
  12459. camera.onBeforeRender( _this );
  12460. if ( camera.parent === null ) camera.updateMatrixWorld();
  12461. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12462. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12463. _frustum.setFromMatrix( _projScreenMatrix );
  12464. lights.length = 0;
  12465. sprites.length = 0;
  12466. lensFlares.length = 0;
  12467. _localClippingEnabled = this.localClippingEnabled;
  12468. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  12469. currentRenderList = renderLists.get( scene, camera );
  12470. currentRenderList.init();
  12471. projectObject( scene, camera, _this.sortObjects );
  12472. currentRenderList.finish();
  12473. if ( _this.sortObjects === true ) {
  12474. currentRenderList.sort();
  12475. }
  12476. //
  12477. if ( _clippingEnabled ) _clipping.beginShadows();
  12478. setupShadows( lights );
  12479. shadowMap.render( scene, camera );
  12480. setupLights( lights, camera );
  12481. if ( _clippingEnabled ) _clipping.endShadows();
  12482. //
  12483. _infoRender.frame ++;
  12484. _infoRender.calls = 0;
  12485. _infoRender.vertices = 0;
  12486. _infoRender.faces = 0;
  12487. _infoRender.points = 0;
  12488. if ( renderTarget === undefined ) {
  12489. renderTarget = null;
  12490. }
  12491. this.setRenderTarget( renderTarget );
  12492. //
  12493. var background = scene.background;
  12494. if ( background === null ) {
  12495. state.buffers.color.setClear( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha, _premultipliedAlpha );
  12496. } else if ( background && background.isColor ) {
  12497. state.buffers.color.setClear( background.r, background.g, background.b, 1, _premultipliedAlpha );
  12498. forceClear = true;
  12499. }
  12500. if ( this.autoClear || forceClear ) {
  12501. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12502. }
  12503. if ( background && background.isCubeTexture ) {
  12504. if ( backgroundBoxCamera === undefined ) {
  12505. backgroundBoxCamera = new PerspectiveCamera();
  12506. backgroundBoxMesh = new Mesh(
  12507. new BoxBufferGeometry( 5, 5, 5 ),
  12508. new ShaderMaterial( {
  12509. uniforms: ShaderLib.cube.uniforms,
  12510. vertexShader: ShaderLib.cube.vertexShader,
  12511. fragmentShader: ShaderLib.cube.fragmentShader,
  12512. side: BackSide,
  12513. depthTest: false,
  12514. depthWrite: false,
  12515. fog: false
  12516. } )
  12517. );
  12518. }
  12519. backgroundBoxCamera.projectionMatrix.copy( camera.projectionMatrix );
  12520. backgroundBoxCamera.matrixWorld.extractRotation( camera.matrixWorld );
  12521. backgroundBoxCamera.matrixWorldInverse.getInverse( backgroundBoxCamera.matrixWorld );
  12522. backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
  12523. backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundBoxCamera.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
  12524. objects.update( backgroundBoxMesh );
  12525. _this.renderBufferDirect( backgroundBoxCamera, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
  12526. } else if ( background && background.isTexture ) {
  12527. if ( backgroundPlaneCamera === undefined ) {
  12528. backgroundPlaneCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  12529. backgroundPlaneMesh = new Mesh(
  12530. new PlaneBufferGeometry( 2, 2 ),
  12531. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  12532. );
  12533. }
  12534. backgroundPlaneMesh.material.map = background;
  12535. objects.update( backgroundPlaneMesh );
  12536. _this.renderBufferDirect( backgroundPlaneCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
  12537. }
  12538. //
  12539. var opaqueObjects = currentRenderList.opaque;
  12540. var transparentObjects = currentRenderList.transparent;
  12541. if ( scene.overrideMaterial ) {
  12542. var overrideMaterial = scene.overrideMaterial;
  12543. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  12544. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  12545. } else {
  12546. // opaque pass (front-to-back order)
  12547. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  12548. // transparent pass (back-to-front order)
  12549. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  12550. }
  12551. // custom render plugins (post pass)
  12552. spritePlugin.render( scene, camera );
  12553. lensFlarePlugin.render( scene, camera, _currentViewport );
  12554. // Generate mipmap if we're using any kind of mipmap filtering
  12555. if ( renderTarget ) {
  12556. textures.updateRenderTargetMipmap( renderTarget );
  12557. }
  12558. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12559. state.buffers.depth.setTest( true );
  12560. state.buffers.depth.setMask( true );
  12561. state.buffers.color.setMask( true );
  12562. if ( camera.isArrayCamera && camera.enabled ) {
  12563. _this.setScissorTest( false );
  12564. }
  12565. camera.onAfterRender( _this );
  12566. // _gl.finish();
  12567. };
  12568. /*
  12569. // TODO Duplicated code (Frustum)
  12570. var _sphere = new Sphere();
  12571. function isObjectViewable( object ) {
  12572. var geometry = object.geometry;
  12573. if ( geometry.boundingSphere === null )
  12574. geometry.computeBoundingSphere();
  12575. _sphere.copy( geometry.boundingSphere ).
  12576. applyMatrix4( object.matrixWorld );
  12577. return isSphereViewable( _sphere );
  12578. }
  12579. function isSpriteViewable( sprite ) {
  12580. _sphere.center.set( 0, 0, 0 );
  12581. _sphere.radius = 0.7071067811865476;
  12582. _sphere.applyMatrix4( sprite.matrixWorld );
  12583. return isSphereViewable( _sphere );
  12584. }
  12585. function isSphereViewable( sphere ) {
  12586. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  12587. var numPlanes = _clipping.numPlanes;
  12588. if ( numPlanes === 0 ) return true;
  12589. var planes = _this.clippingPlanes,
  12590. center = sphere.center,
  12591. negRad = - sphere.radius,
  12592. i = 0;
  12593. do {
  12594. // out when deeper than radius in the negative halfspace
  12595. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  12596. } while ( ++ i !== numPlanes );
  12597. return true;
  12598. }
  12599. */
  12600. function projectObject( object, camera, sortObjects ) {
  12601. if ( ! object.visible ) return;
  12602. var visible = object.layers.test( camera.layers );
  12603. if ( visible ) {
  12604. if ( object.isLight ) {
  12605. lights.push( object );
  12606. } else if ( object.isSprite ) {
  12607. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  12608. sprites.push( object );
  12609. }
  12610. } else if ( object.isLensFlare ) {
  12611. lensFlares.push( object );
  12612. } else if ( object.isImmediateRenderObject ) {
  12613. if ( sortObjects ) {
  12614. _vector3.setFromMatrixPosition( object.matrixWorld )
  12615. .applyMatrix4( _projScreenMatrix );
  12616. }
  12617. currentRenderList.push( object, null, object.material, _vector3.z, null );
  12618. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  12619. if ( object.isSkinnedMesh ) {
  12620. object.skeleton.update();
  12621. }
  12622. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  12623. if ( sortObjects ) {
  12624. _vector3.setFromMatrixPosition( object.matrixWorld )
  12625. .applyMatrix4( _projScreenMatrix );
  12626. }
  12627. var geometry = objects.update( object );
  12628. var material = object.material;
  12629. if ( Array.isArray( material ) ) {
  12630. var groups = geometry.groups;
  12631. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  12632. var group = groups[ i ];
  12633. var groupMaterial = material[ group.materialIndex ];
  12634. if ( groupMaterial && groupMaterial.visible ) {
  12635. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  12636. }
  12637. }
  12638. } else if ( material.visible ) {
  12639. currentRenderList.push( object, geometry, material, _vector3.z, null );
  12640. }
  12641. }
  12642. }
  12643. }
  12644. var children = object.children;
  12645. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12646. projectObject( children[ i ], camera, sortObjects );
  12647. }
  12648. }
  12649. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  12650. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12651. var renderItem = renderList[ i ];
  12652. var object = renderItem.object;
  12653. var geometry = renderItem.geometry;
  12654. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  12655. var group = renderItem.group;
  12656. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  12657. if ( camera.isArrayCamera && camera.enabled ) {
  12658. var cameras = camera.cameras;
  12659. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  12660. var camera2 = cameras[ j ];
  12661. var bounds = camera2.bounds;
  12662. _this.setViewport(
  12663. bounds.x * _width * _pixelRatio, bounds.y * _height * _pixelRatio,
  12664. bounds.z * _width * _pixelRatio, bounds.w * _height * _pixelRatio
  12665. );
  12666. _this.setScissor(
  12667. bounds.x * _width * _pixelRatio, bounds.y * _height * _pixelRatio,
  12668. bounds.z * _width * _pixelRatio, bounds.w * _height * _pixelRatio
  12669. );
  12670. _this.setScissorTest( true );
  12671. renderObject( object, scene, camera2, geometry, material, group );
  12672. }
  12673. } else {
  12674. renderObject( object, scene, camera, geometry, material, group );
  12675. }
  12676. object.onAfterRender( _this, scene, camera, geometry, material, group );
  12677. }
  12678. }
  12679. function renderObject( object, scene, camera, geometry, material, group ) {
  12680. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  12681. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  12682. if ( object.isImmediateRenderObject ) {
  12683. state.setMaterial( material );
  12684. var program = setProgram( camera, scene.fog, material, object );
  12685. _currentGeometryProgram = '';
  12686. renderObjectImmediate( object, program, material );
  12687. } else {
  12688. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  12689. }
  12690. }
  12691. function initMaterial( material, fog, object ) {
  12692. var materialProperties = properties.get( material );
  12693. var parameters = programCache.getParameters(
  12694. material, _lights, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  12695. var code = programCache.getProgramCode( material, parameters );
  12696. var program = materialProperties.program;
  12697. var programChange = true;
  12698. if ( program === undefined ) {
  12699. // new material
  12700. material.addEventListener( 'dispose', onMaterialDispose );
  12701. } else if ( program.code !== code ) {
  12702. // changed glsl or parameters
  12703. releaseMaterialProgramReference( material );
  12704. } else if ( parameters.shaderID !== undefined ) {
  12705. // same glsl and uniform list
  12706. return;
  12707. } else {
  12708. // only rebuild uniform list
  12709. programChange = false;
  12710. }
  12711. if ( programChange ) {
  12712. if ( parameters.shaderID ) {
  12713. var shader = ShaderLib[ parameters.shaderID ];
  12714. materialProperties.__webglShader = {
  12715. name: material.type,
  12716. uniforms: UniformsUtils.clone( shader.uniforms ),
  12717. vertexShader: shader.vertexShader,
  12718. fragmentShader: shader.fragmentShader
  12719. };
  12720. } else {
  12721. materialProperties.__webglShader = {
  12722. name: material.type,
  12723. uniforms: material.uniforms,
  12724. vertexShader: material.vertexShader,
  12725. fragmentShader: material.fragmentShader
  12726. };
  12727. }
  12728. material.__webglShader = materialProperties.__webglShader;
  12729. program = programCache.acquireProgram( material, parameters, code );
  12730. materialProperties.program = program;
  12731. material.program = program;
  12732. }
  12733. var programAttributes = program.getAttributes();
  12734. if ( material.morphTargets ) {
  12735. material.numSupportedMorphTargets = 0;
  12736. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12737. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  12738. material.numSupportedMorphTargets ++;
  12739. }
  12740. }
  12741. }
  12742. if ( material.morphNormals ) {
  12743. material.numSupportedMorphNormals = 0;
  12744. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  12745. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  12746. material.numSupportedMorphNormals ++;
  12747. }
  12748. }
  12749. }
  12750. var uniforms = materialProperties.__webglShader.uniforms;
  12751. if ( ! material.isShaderMaterial &&
  12752. ! material.isRawShaderMaterial ||
  12753. material.clipping === true ) {
  12754. materialProperties.numClippingPlanes = _clipping.numPlanes;
  12755. materialProperties.numIntersection = _clipping.numIntersection;
  12756. uniforms.clippingPlanes = _clipping.uniform;
  12757. }
  12758. materialProperties.fog = fog;
  12759. // store the light setup it was created for
  12760. materialProperties.lightsHash = _lights.hash;
  12761. if ( material.lights ) {
  12762. // wire up the material to this renderer's lighting state
  12763. uniforms.ambientLightColor.value = _lights.ambient;
  12764. uniforms.directionalLights.value = _lights.directional;
  12765. uniforms.spotLights.value = _lights.spot;
  12766. uniforms.rectAreaLights.value = _lights.rectArea;
  12767. uniforms.pointLights.value = _lights.point;
  12768. uniforms.hemisphereLights.value = _lights.hemi;
  12769. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  12770. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  12771. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  12772. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  12773. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  12774. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  12775. // TODO (abelnation): add area lights shadow info to uniforms
  12776. }
  12777. var progUniforms = materialProperties.program.getUniforms(),
  12778. uniformsList =
  12779. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  12780. materialProperties.uniformsList = uniformsList;
  12781. }
  12782. function setProgram( camera, fog, material, object ) {
  12783. _usedTextureUnits = 0;
  12784. var materialProperties = properties.get( material );
  12785. if ( _clippingEnabled ) {
  12786. if ( _localClippingEnabled || camera !== _currentCamera ) {
  12787. var useCache =
  12788. camera === _currentCamera &&
  12789. material.id === _currentMaterialId;
  12790. // we might want to call this function with some ClippingGroup
  12791. // object instead of the material, once it becomes feasible
  12792. // (#8465, #8379)
  12793. _clipping.setState(
  12794. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  12795. camera, materialProperties, useCache );
  12796. }
  12797. }
  12798. if ( material.needsUpdate === false ) {
  12799. if ( materialProperties.program === undefined ) {
  12800. material.needsUpdate = true;
  12801. } else if ( material.fog && materialProperties.fog !== fog ) {
  12802. material.needsUpdate = true;
  12803. } else if ( material.lights && materialProperties.lightsHash !== _lights.hash ) {
  12804. material.needsUpdate = true;
  12805. } else if ( materialProperties.numClippingPlanes !== undefined &&
  12806. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  12807. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  12808. material.needsUpdate = true;
  12809. }
  12810. }
  12811. if ( material.needsUpdate ) {
  12812. initMaterial( material, fog, object );
  12813. material.needsUpdate = false;
  12814. }
  12815. var refreshProgram = false;
  12816. var refreshMaterial = false;
  12817. var refreshLights = false;
  12818. var program = materialProperties.program,
  12819. p_uniforms = program.getUniforms(),
  12820. m_uniforms = materialProperties.__webglShader.uniforms;
  12821. if ( program.id !== _currentProgram ) {
  12822. _gl.useProgram( program.program );
  12823. _currentProgram = program.id;
  12824. refreshProgram = true;
  12825. refreshMaterial = true;
  12826. refreshLights = true;
  12827. }
  12828. if ( material.id !== _currentMaterialId ) {
  12829. _currentMaterialId = material.id;
  12830. refreshMaterial = true;
  12831. }
  12832. if ( refreshProgram || camera !== _currentCamera ) {
  12833. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  12834. if ( capabilities.logarithmicDepthBuffer ) {
  12835. p_uniforms.setValue( _gl, 'logDepthBufFC',
  12836. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12837. }
  12838. if ( camera !== _currentCamera ) {
  12839. _currentCamera = camera;
  12840. // lighting uniforms depend on the camera so enforce an update
  12841. // now, in case this material supports lights - or later, when
  12842. // the next material that does gets activated:
  12843. refreshMaterial = true; // set to true on material change
  12844. refreshLights = true; // remains set until update done
  12845. }
  12846. // load material specific uniforms
  12847. // (shader material also gets them for the sake of genericity)
  12848. if ( material.isShaderMaterial ||
  12849. material.isMeshPhongMaterial ||
  12850. material.isMeshStandardMaterial ||
  12851. material.envMap ) {
  12852. var uCamPos = p_uniforms.map.cameraPosition;
  12853. if ( uCamPos !== undefined ) {
  12854. uCamPos.setValue( _gl,
  12855. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  12856. }
  12857. }
  12858. if ( material.isMeshPhongMaterial ||
  12859. material.isMeshLambertMaterial ||
  12860. material.isMeshBasicMaterial ||
  12861. material.isMeshStandardMaterial ||
  12862. material.isShaderMaterial ||
  12863. material.skinning ) {
  12864. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  12865. }
  12866. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  12867. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  12868. }
  12869. // skinning uniforms must be set even if material didn't change
  12870. // auto-setting of texture unit for bone texture must go before other textures
  12871. // not sure why, but otherwise weird things happen
  12872. if ( material.skinning ) {
  12873. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  12874. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  12875. var skeleton = object.skeleton;
  12876. if ( skeleton ) {
  12877. var bones = skeleton.bones;
  12878. if ( capabilities.floatVertexTextures ) {
  12879. if ( skeleton.boneTexture === undefined ) {
  12880. // layout (1 matrix = 4 pixels)
  12881. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  12882. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  12883. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  12884. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  12885. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  12886. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  12887. size = _Math.nextPowerOfTwo( Math.ceil( size ) );
  12888. size = Math.max( size, 4 );
  12889. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  12890. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  12891. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  12892. skeleton.boneMatrices = boneMatrices;
  12893. skeleton.boneTexture = boneTexture;
  12894. skeleton.boneTextureSize = size;
  12895. }
  12896. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  12897. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  12898. } else {
  12899. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  12900. }
  12901. }
  12902. }
  12903. if ( refreshMaterial ) {
  12904. if ( material.lights ) {
  12905. // the current material requires lighting info
  12906. // note: all lighting uniforms are always set correctly
  12907. // they simply reference the renderer's state for their
  12908. // values
  12909. //
  12910. // use the current material's .needsUpdate flags to set
  12911. // the GL state when required
  12912. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  12913. }
  12914. // refresh uniforms common to several materials
  12915. if ( fog && material.fog ) {
  12916. refreshUniformsFog( m_uniforms, fog );
  12917. }
  12918. if ( material.isMeshBasicMaterial ||
  12919. material.isMeshLambertMaterial ||
  12920. material.isMeshPhongMaterial ||
  12921. material.isMeshStandardMaterial ||
  12922. material.isMeshNormalMaterial ||
  12923. material.isMeshDepthMaterial ) {
  12924. refreshUniformsCommon( m_uniforms, material );
  12925. }
  12926. // refresh single material specific uniforms
  12927. if ( material.isLineBasicMaterial ) {
  12928. refreshUniformsLine( m_uniforms, material );
  12929. } else if ( material.isLineDashedMaterial ) {
  12930. refreshUniformsLine( m_uniforms, material );
  12931. refreshUniformsDash( m_uniforms, material );
  12932. } else if ( material.isPointsMaterial ) {
  12933. refreshUniformsPoints( m_uniforms, material );
  12934. } else if ( material.isMeshLambertMaterial ) {
  12935. refreshUniformsLambert( m_uniforms, material );
  12936. } else if ( material.isMeshToonMaterial ) {
  12937. refreshUniformsToon( m_uniforms, material );
  12938. } else if ( material.isMeshPhongMaterial ) {
  12939. refreshUniformsPhong( m_uniforms, material );
  12940. } else if ( material.isMeshPhysicalMaterial ) {
  12941. refreshUniformsPhysical( m_uniforms, material );
  12942. } else if ( material.isMeshStandardMaterial ) {
  12943. refreshUniformsStandard( m_uniforms, material );
  12944. } else if ( material.isMeshDepthMaterial ) {
  12945. if ( material.displacementMap ) {
  12946. m_uniforms.displacementMap.value = material.displacementMap;
  12947. m_uniforms.displacementScale.value = material.displacementScale;
  12948. m_uniforms.displacementBias.value = material.displacementBias;
  12949. }
  12950. } else if ( material.isMeshNormalMaterial ) {
  12951. refreshUniformsNormal( m_uniforms, material );
  12952. }
  12953. // RectAreaLight Texture
  12954. // TODO (mrdoob): Find a nicer implementation
  12955. if ( m_uniforms.ltcMat !== undefined ) m_uniforms.ltcMat.value = UniformsLib.LTC_MAT_TEXTURE;
  12956. if ( m_uniforms.ltcMag !== undefined ) m_uniforms.ltcMag.value = UniformsLib.LTC_MAG_TEXTURE;
  12957. WebGLUniforms.upload(
  12958. _gl, materialProperties.uniformsList, m_uniforms, _this );
  12959. }
  12960. // common matrices
  12961. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  12962. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  12963. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  12964. return program;
  12965. }
  12966. // Uniforms (refresh uniforms objects)
  12967. function refreshUniformsCommon( uniforms, material ) {
  12968. uniforms.opacity.value = material.opacity;
  12969. uniforms.diffuse.value = material.color;
  12970. if ( material.emissive ) {
  12971. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  12972. }
  12973. uniforms.map.value = material.map;
  12974. uniforms.specularMap.value = material.specularMap;
  12975. uniforms.alphaMap.value = material.alphaMap;
  12976. if ( material.lightMap ) {
  12977. uniforms.lightMap.value = material.lightMap;
  12978. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  12979. }
  12980. if ( material.aoMap ) {
  12981. uniforms.aoMap.value = material.aoMap;
  12982. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12983. }
  12984. // uv repeat and offset setting priorities
  12985. // 1. color map
  12986. // 2. specular map
  12987. // 3. normal map
  12988. // 4. bump map
  12989. // 5. alpha map
  12990. // 6. emissive map
  12991. var uvScaleMap;
  12992. if ( material.map ) {
  12993. uvScaleMap = material.map;
  12994. } else if ( material.specularMap ) {
  12995. uvScaleMap = material.specularMap;
  12996. } else if ( material.displacementMap ) {
  12997. uvScaleMap = material.displacementMap;
  12998. } else if ( material.normalMap ) {
  12999. uvScaleMap = material.normalMap;
  13000. } else if ( material.bumpMap ) {
  13001. uvScaleMap = material.bumpMap;
  13002. } else if ( material.roughnessMap ) {
  13003. uvScaleMap = material.roughnessMap;
  13004. } else if ( material.metalnessMap ) {
  13005. uvScaleMap = material.metalnessMap;
  13006. } else if ( material.alphaMap ) {
  13007. uvScaleMap = material.alphaMap;
  13008. } else if ( material.emissiveMap ) {
  13009. uvScaleMap = material.emissiveMap;
  13010. }
  13011. if ( uvScaleMap !== undefined ) {
  13012. // backwards compatibility
  13013. if ( uvScaleMap.isWebGLRenderTarget ) {
  13014. uvScaleMap = uvScaleMap.texture;
  13015. }
  13016. var offset = uvScaleMap.offset;
  13017. var repeat = uvScaleMap.repeat;
  13018. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13019. }
  13020. uniforms.envMap.value = material.envMap;
  13021. // don't flip CubeTexture envMaps, flip everything else:
  13022. // WebGLRenderTargetCube will be flipped for backwards compatibility
  13023. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  13024. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  13025. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  13026. uniforms.reflectivity.value = material.reflectivity;
  13027. uniforms.refractionRatio.value = material.refractionRatio;
  13028. }
  13029. function refreshUniformsLine( uniforms, material ) {
  13030. uniforms.diffuse.value = material.color;
  13031. uniforms.opacity.value = material.opacity;
  13032. }
  13033. function refreshUniformsDash( uniforms, material ) {
  13034. uniforms.dashSize.value = material.dashSize;
  13035. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13036. uniforms.scale.value = material.scale;
  13037. }
  13038. function refreshUniformsPoints( uniforms, material ) {
  13039. uniforms.diffuse.value = material.color;
  13040. uniforms.opacity.value = material.opacity;
  13041. uniforms.size.value = material.size * _pixelRatio;
  13042. uniforms.scale.value = _height * 0.5;
  13043. uniforms.map.value = material.map;
  13044. if ( material.map !== null ) {
  13045. var offset = material.map.offset;
  13046. var repeat = material.map.repeat;
  13047. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13048. }
  13049. }
  13050. function refreshUniformsFog( uniforms, fog ) {
  13051. uniforms.fogColor.value = fog.color;
  13052. if ( fog.isFog ) {
  13053. uniforms.fogNear.value = fog.near;
  13054. uniforms.fogFar.value = fog.far;
  13055. } else if ( fog.isFogExp2 ) {
  13056. uniforms.fogDensity.value = fog.density;
  13057. }
  13058. }
  13059. function refreshUniformsLambert( uniforms, material ) {
  13060. if ( material.emissiveMap ) {
  13061. uniforms.emissiveMap.value = material.emissiveMap;
  13062. }
  13063. }
  13064. function refreshUniformsPhong( uniforms, material ) {
  13065. uniforms.specular.value = material.specular;
  13066. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13067. if ( material.emissiveMap ) {
  13068. uniforms.emissiveMap.value = material.emissiveMap;
  13069. }
  13070. if ( material.bumpMap ) {
  13071. uniforms.bumpMap.value = material.bumpMap;
  13072. uniforms.bumpScale.value = material.bumpScale;
  13073. }
  13074. if ( material.normalMap ) {
  13075. uniforms.normalMap.value = material.normalMap;
  13076. uniforms.normalScale.value.copy( material.normalScale );
  13077. }
  13078. if ( material.displacementMap ) {
  13079. uniforms.displacementMap.value = material.displacementMap;
  13080. uniforms.displacementScale.value = material.displacementScale;
  13081. uniforms.displacementBias.value = material.displacementBias;
  13082. }
  13083. }
  13084. function refreshUniformsToon( uniforms, material ) {
  13085. refreshUniformsPhong( uniforms, material );
  13086. if ( material.gradientMap ) {
  13087. uniforms.gradientMap.value = material.gradientMap;
  13088. }
  13089. }
  13090. function refreshUniformsStandard( uniforms, material ) {
  13091. uniforms.roughness.value = material.roughness;
  13092. uniforms.metalness.value = material.metalness;
  13093. if ( material.roughnessMap ) {
  13094. uniforms.roughnessMap.value = material.roughnessMap;
  13095. }
  13096. if ( material.metalnessMap ) {
  13097. uniforms.metalnessMap.value = material.metalnessMap;
  13098. }
  13099. if ( material.emissiveMap ) {
  13100. uniforms.emissiveMap.value = material.emissiveMap;
  13101. }
  13102. if ( material.bumpMap ) {
  13103. uniforms.bumpMap.value = material.bumpMap;
  13104. uniforms.bumpScale.value = material.bumpScale;
  13105. }
  13106. if ( material.normalMap ) {
  13107. uniforms.normalMap.value = material.normalMap;
  13108. uniforms.normalScale.value.copy( material.normalScale );
  13109. }
  13110. if ( material.displacementMap ) {
  13111. uniforms.displacementMap.value = material.displacementMap;
  13112. uniforms.displacementScale.value = material.displacementScale;
  13113. uniforms.displacementBias.value = material.displacementBias;
  13114. }
  13115. if ( material.envMap ) {
  13116. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13117. uniforms.envMapIntensity.value = material.envMapIntensity;
  13118. }
  13119. }
  13120. function refreshUniformsPhysical( uniforms, material ) {
  13121. uniforms.clearCoat.value = material.clearCoat;
  13122. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  13123. refreshUniformsStandard( uniforms, material );
  13124. }
  13125. function refreshUniformsNormal( uniforms, material ) {
  13126. if ( material.bumpMap ) {
  13127. uniforms.bumpMap.value = material.bumpMap;
  13128. uniforms.bumpScale.value = material.bumpScale;
  13129. }
  13130. if ( material.normalMap ) {
  13131. uniforms.normalMap.value = material.normalMap;
  13132. uniforms.normalScale.value.copy( material.normalScale );
  13133. }
  13134. if ( material.displacementMap ) {
  13135. uniforms.displacementMap.value = material.displacementMap;
  13136. uniforms.displacementScale.value = material.displacementScale;
  13137. uniforms.displacementBias.value = material.displacementBias;
  13138. }
  13139. }
  13140. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13141. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  13142. uniforms.ambientLightColor.needsUpdate = value;
  13143. uniforms.directionalLights.needsUpdate = value;
  13144. uniforms.pointLights.needsUpdate = value;
  13145. uniforms.spotLights.needsUpdate = value;
  13146. uniforms.rectAreaLights.needsUpdate = value;
  13147. uniforms.hemisphereLights.needsUpdate = value;
  13148. }
  13149. // Lighting
  13150. function setupShadows( lights ) {
  13151. var lightShadowsLength = 0;
  13152. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  13153. var light = lights[ i ];
  13154. if ( light.castShadow ) {
  13155. _lights.shadows[ lightShadowsLength ] = light;
  13156. lightShadowsLength ++;
  13157. }
  13158. }
  13159. _lights.shadows.length = lightShadowsLength;
  13160. }
  13161. function setupLights( lights, camera ) {
  13162. var l, ll, light, shadow,
  13163. r = 0, g = 0, b = 0,
  13164. color,
  13165. intensity,
  13166. distance,
  13167. shadowMap,
  13168. viewMatrix = camera.matrixWorldInverse,
  13169. directionalLength = 0,
  13170. pointLength = 0,
  13171. spotLength = 0,
  13172. rectAreaLength = 0,
  13173. hemiLength = 0;
  13174. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13175. light = lights[ l ];
  13176. color = light.color;
  13177. intensity = light.intensity;
  13178. distance = light.distance;
  13179. shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  13180. if ( light.isAmbientLight ) {
  13181. r += color.r * intensity;
  13182. g += color.g * intensity;
  13183. b += color.b * intensity;
  13184. } else if ( light.isDirectionalLight ) {
  13185. var uniforms = lightCache.get( light );
  13186. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  13187. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  13188. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13189. uniforms.direction.sub( _vector3 );
  13190. uniforms.direction.transformDirection( viewMatrix );
  13191. uniforms.shadow = light.castShadow;
  13192. if ( light.castShadow ) {
  13193. shadow = light.shadow;
  13194. uniforms.shadowBias = shadow.bias;
  13195. uniforms.shadowRadius = shadow.radius;
  13196. uniforms.shadowMapSize = shadow.mapSize;
  13197. }
  13198. _lights.directionalShadowMap[ directionalLength ] = shadowMap;
  13199. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  13200. _lights.directional[ directionalLength ] = uniforms;
  13201. directionalLength ++;
  13202. } else if ( light.isSpotLight ) {
  13203. var uniforms = lightCache.get( light );
  13204. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  13205. uniforms.position.applyMatrix4( viewMatrix );
  13206. uniforms.color.copy( color ).multiplyScalar( intensity );
  13207. uniforms.distance = distance;
  13208. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  13209. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13210. uniforms.direction.sub( _vector3 );
  13211. uniforms.direction.transformDirection( viewMatrix );
  13212. uniforms.coneCos = Math.cos( light.angle );
  13213. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  13214. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  13215. uniforms.shadow = light.castShadow;
  13216. if ( light.castShadow ) {
  13217. shadow = light.shadow;
  13218. uniforms.shadowBias = shadow.bias;
  13219. uniforms.shadowRadius = shadow.radius;
  13220. uniforms.shadowMapSize = shadow.mapSize;
  13221. }
  13222. _lights.spotShadowMap[ spotLength ] = shadowMap;
  13223. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  13224. _lights.spot[ spotLength ] = uniforms;
  13225. spotLength ++;
  13226. } else if ( light.isRectAreaLight ) {
  13227. var uniforms = lightCache.get( light );
  13228. // (a) intensity controls irradiance of entire light
  13229. uniforms.color
  13230. .copy( color )
  13231. .multiplyScalar( intensity / ( light.width * light.height ) );
  13232. // (b) intensity controls the radiance per light area
  13233. // uniforms.color.copy( color ).multiplyScalar( intensity );
  13234. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  13235. uniforms.position.applyMatrix4( viewMatrix );
  13236. // extract local rotation of light to derive width/height half vectors
  13237. _matrix42.identity();
  13238. _matrix4.copy( light.matrixWorld );
  13239. _matrix4.premultiply( viewMatrix );
  13240. _matrix42.extractRotation( _matrix4 );
  13241. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  13242. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  13243. uniforms.halfWidth.applyMatrix4( _matrix42 );
  13244. uniforms.halfHeight.applyMatrix4( _matrix42 );
  13245. // TODO (abelnation): RectAreaLight distance?
  13246. // uniforms.distance = distance;
  13247. _lights.rectArea[ rectAreaLength ] = uniforms;
  13248. rectAreaLength ++;
  13249. } else if ( light.isPointLight ) {
  13250. var uniforms = lightCache.get( light );
  13251. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  13252. uniforms.position.applyMatrix4( viewMatrix );
  13253. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  13254. uniforms.distance = light.distance;
  13255. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  13256. uniforms.shadow = light.castShadow;
  13257. if ( light.castShadow ) {
  13258. shadow = light.shadow;
  13259. uniforms.shadowBias = shadow.bias;
  13260. uniforms.shadowRadius = shadow.radius;
  13261. uniforms.shadowMapSize = shadow.mapSize;
  13262. }
  13263. _lights.pointShadowMap[ pointLength ] = shadowMap;
  13264. _lights.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  13265. _lights.point[ pointLength ] = uniforms;
  13266. pointLength ++;
  13267. } else if ( light.isHemisphereLight ) {
  13268. var uniforms = lightCache.get( light );
  13269. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  13270. uniforms.direction.transformDirection( viewMatrix );
  13271. uniforms.direction.normalize();
  13272. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  13273. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  13274. _lights.hemi[ hemiLength ] = uniforms;
  13275. hemiLength ++;
  13276. }
  13277. }
  13278. _lights.ambient[ 0 ] = r;
  13279. _lights.ambient[ 1 ] = g;
  13280. _lights.ambient[ 2 ] = b;
  13281. _lights.directional.length = directionalLength;
  13282. _lights.spot.length = spotLength;
  13283. _lights.rectArea.length = rectAreaLength;
  13284. _lights.point.length = pointLength;
  13285. _lights.hemi.length = hemiLength;
  13286. // TODO (sam-g-steel) why aren't we using join
  13287. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + _lights.shadows.length;
  13288. }
  13289. // GL state setting
  13290. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13291. state.setCullFace( cullFace );
  13292. state.setFlipSided( frontFaceDirection === FrontFaceDirectionCW );
  13293. };
  13294. // Textures
  13295. function allocTextureUnit() {
  13296. var textureUnit = _usedTextureUnits;
  13297. if ( textureUnit >= capabilities.maxTextures ) {
  13298. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13299. }
  13300. _usedTextureUnits += 1;
  13301. return textureUnit;
  13302. }
  13303. this.allocTextureUnit = allocTextureUnit;
  13304. // this.setTexture2D = setTexture2D;
  13305. this.setTexture2D = ( function () {
  13306. var warned = false;
  13307. // backwards compatibility: peel texture.texture
  13308. return function setTexture2D( texture, slot ) {
  13309. if ( texture && texture.isWebGLRenderTarget ) {
  13310. if ( ! warned ) {
  13311. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13312. warned = true;
  13313. }
  13314. texture = texture.texture;
  13315. }
  13316. textures.setTexture2D( texture, slot );
  13317. };
  13318. }() );
  13319. this.setTexture = ( function () {
  13320. var warned = false;
  13321. return function setTexture( texture, slot ) {
  13322. if ( ! warned ) {
  13323. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  13324. warned = true;
  13325. }
  13326. textures.setTexture2D( texture, slot );
  13327. };
  13328. }() );
  13329. this.setTextureCube = ( function () {
  13330. var warned = false;
  13331. return function setTextureCube( texture, slot ) {
  13332. // backwards compatibility: peel texture.texture
  13333. if ( texture && texture.isWebGLRenderTargetCube ) {
  13334. if ( ! warned ) {
  13335. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13336. warned = true;
  13337. }
  13338. texture = texture.texture;
  13339. }
  13340. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13341. // TODO: unify these code paths
  13342. if ( ( texture && texture.isCubeTexture ) ||
  13343. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13344. // CompressedTexture can have Array in image :/
  13345. // this function alone should take care of cube textures
  13346. textures.setTextureCube( texture, slot );
  13347. } else {
  13348. // assumed: texture property of THREE.WebGLRenderTargetCube
  13349. textures.setTextureCubeDynamic( texture, slot );
  13350. }
  13351. };
  13352. }() );
  13353. this.getRenderTarget = function () {
  13354. return _currentRenderTarget;
  13355. };
  13356. this.setRenderTarget = function ( renderTarget ) {
  13357. _currentRenderTarget = renderTarget;
  13358. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13359. textures.setupRenderTarget( renderTarget );
  13360. }
  13361. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  13362. var framebuffer;
  13363. if ( renderTarget ) {
  13364. var renderTargetProperties = properties.get( renderTarget );
  13365. if ( isCube ) {
  13366. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13367. } else {
  13368. framebuffer = renderTargetProperties.__webglFramebuffer;
  13369. }
  13370. _currentScissor.copy( renderTarget.scissor );
  13371. _currentScissorTest = renderTarget.scissorTest;
  13372. _currentViewport.copy( renderTarget.viewport );
  13373. } else {
  13374. framebuffer = null;
  13375. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  13376. _currentScissorTest = _scissorTest;
  13377. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  13378. }
  13379. if ( _currentFramebuffer !== framebuffer ) {
  13380. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13381. _currentFramebuffer = framebuffer;
  13382. }
  13383. state.scissor( _currentScissor );
  13384. state.setScissorTest( _currentScissorTest );
  13385. state.viewport( _currentViewport );
  13386. if ( isCube ) {
  13387. var textureProperties = properties.get( renderTarget.texture );
  13388. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  13389. }
  13390. };
  13391. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  13392. if ( ( renderTarget && renderTarget.isWebGLRenderTarget ) === false ) {
  13393. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13394. return;
  13395. }
  13396. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  13397. if ( framebuffer ) {
  13398. var restore = false;
  13399. if ( framebuffer !== _currentFramebuffer ) {
  13400. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13401. restore = true;
  13402. }
  13403. try {
  13404. var texture = renderTarget.texture;
  13405. var textureFormat = texture.format;
  13406. var textureType = texture.type;
  13407. if ( textureFormat !== RGBAFormat && paramThreeToGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  13408. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  13409. return;
  13410. }
  13411. if ( textureType !== UnsignedByteType && paramThreeToGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  13412. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  13413. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  13414. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  13415. return;
  13416. }
  13417. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13418. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  13419. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  13420. _gl.readPixels( x, y, width, height, paramThreeToGL( textureFormat ), paramThreeToGL( textureType ), buffer );
  13421. }
  13422. } else {
  13423. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13424. }
  13425. } finally {
  13426. if ( restore ) {
  13427. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13428. }
  13429. }
  13430. }
  13431. };
  13432. // Map three.js constants to WebGL constants
  13433. function paramThreeToGL( p ) {
  13434. var extension;
  13435. if ( p === RepeatWrapping ) return _gl.REPEAT;
  13436. if ( p === ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13437. if ( p === MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13438. if ( p === NearestFilter ) return _gl.NEAREST;
  13439. if ( p === NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13440. if ( p === NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13441. if ( p === LinearFilter ) return _gl.LINEAR;
  13442. if ( p === LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13443. if ( p === LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13444. if ( p === UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13445. if ( p === UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13446. if ( p === UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13447. if ( p === UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13448. if ( p === ByteType ) return _gl.BYTE;
  13449. if ( p === ShortType ) return _gl.SHORT;
  13450. if ( p === UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13451. if ( p === IntType ) return _gl.INT;
  13452. if ( p === UnsignedIntType ) return _gl.UNSIGNED_INT;
  13453. if ( p === FloatType ) return _gl.FLOAT;
  13454. if ( p === HalfFloatType ) {
  13455. extension = extensions.get( 'OES_texture_half_float' );
  13456. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  13457. }
  13458. if ( p === AlphaFormat ) return _gl.ALPHA;
  13459. if ( p === RGBFormat ) return _gl.RGB;
  13460. if ( p === RGBAFormat ) return _gl.RGBA;
  13461. if ( p === LuminanceFormat ) return _gl.LUMINANCE;
  13462. if ( p === LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13463. if ( p === DepthFormat ) return _gl.DEPTH_COMPONENT;
  13464. if ( p === DepthStencilFormat ) return _gl.DEPTH_STENCIL;
  13465. if ( p === AddEquation ) return _gl.FUNC_ADD;
  13466. if ( p === SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13467. if ( p === ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13468. if ( p === ZeroFactor ) return _gl.ZERO;
  13469. if ( p === OneFactor ) return _gl.ONE;
  13470. if ( p === SrcColorFactor ) return _gl.SRC_COLOR;
  13471. if ( p === OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13472. if ( p === SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13473. if ( p === OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13474. if ( p === DstAlphaFactor ) return _gl.DST_ALPHA;
  13475. if ( p === OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13476. if ( p === DstColorFactor ) return _gl.DST_COLOR;
  13477. if ( p === OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13478. if ( p === SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13479. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13480. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13481. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13482. if ( extension !== null ) {
  13483. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13484. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13485. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13486. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13487. }
  13488. }
  13489. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13490. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13491. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13492. if ( extension !== null ) {
  13493. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13494. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13495. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13496. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13497. }
  13498. }
  13499. if ( p === RGB_ETC1_Format ) {
  13500. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13501. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13502. }
  13503. if ( p === MinEquation || p === MaxEquation ) {
  13504. extension = extensions.get( 'EXT_blend_minmax' );
  13505. if ( extension !== null ) {
  13506. if ( p === MinEquation ) return extension.MIN_EXT;
  13507. if ( p === MaxEquation ) return extension.MAX_EXT;
  13508. }
  13509. }
  13510. if ( p === UnsignedInt248Type ) {
  13511. extension = extensions.get( 'WEBGL_depth_texture' );
  13512. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  13513. }
  13514. return 0;
  13515. }
  13516. }
  13517. /**
  13518. * @author mrdoob / http://mrdoob.com/
  13519. * @author alteredq / http://alteredqualia.com/
  13520. */
  13521. function FogExp2 ( color, density ) {
  13522. this.name = '';
  13523. this.color = new Color( color );
  13524. this.density = ( density !== undefined ) ? density : 0.00025;
  13525. }
  13526. FogExp2.prototype.isFogExp2 = true;
  13527. FogExp2.prototype.clone = function () {
  13528. return new FogExp2( this.color.getHex(), this.density );
  13529. };
  13530. FogExp2.prototype.toJSON = function ( meta ) {
  13531. return {
  13532. type: 'FogExp2',
  13533. color: this.color.getHex(),
  13534. density: this.density
  13535. };
  13536. };
  13537. /**
  13538. * @author mrdoob / http://mrdoob.com/
  13539. * @author alteredq / http://alteredqualia.com/
  13540. */
  13541. function Fog ( color, near, far ) {
  13542. this.name = '';
  13543. this.color = new Color( color );
  13544. this.near = ( near !== undefined ) ? near : 1;
  13545. this.far = ( far !== undefined ) ? far : 1000;
  13546. }
  13547. Fog.prototype.isFog = true;
  13548. Fog.prototype.clone = function () {
  13549. return new Fog( this.color.getHex(), this.near, this.far );
  13550. };
  13551. Fog.prototype.toJSON = function ( meta ) {
  13552. return {
  13553. type: 'Fog',
  13554. color: this.color.getHex(),
  13555. near: this.near,
  13556. far: this.far
  13557. };
  13558. };
  13559. /**
  13560. * @author mrdoob / http://mrdoob.com/
  13561. */
  13562. function Scene () {
  13563. Object3D.call( this );
  13564. this.type = 'Scene';
  13565. this.background = null;
  13566. this.fog = null;
  13567. this.overrideMaterial = null;
  13568. this.autoUpdate = true; // checked by the renderer
  13569. }
  13570. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13571. constructor: Scene,
  13572. copy: function ( source, recursive ) {
  13573. Object3D.prototype.copy.call( this, source, recursive );
  13574. if ( source.background !== null ) this.background = source.background.clone();
  13575. if ( source.fog !== null ) this.fog = source.fog.clone();
  13576. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13577. this.autoUpdate = source.autoUpdate;
  13578. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13579. return this;
  13580. },
  13581. toJSON: function ( meta ) {
  13582. var data = Object3D.prototype.toJSON.call( this, meta );
  13583. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  13584. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  13585. return data;
  13586. }
  13587. } );
  13588. /**
  13589. * @author mikael emtinger / http://gomo.se/
  13590. * @author alteredq / http://alteredqualia.com/
  13591. */
  13592. function LensFlare( texture, size, distance, blending, color ) {
  13593. Object3D.call( this );
  13594. this.lensFlares = [];
  13595. this.positionScreen = new Vector3();
  13596. this.customUpdateCallback = undefined;
  13597. if ( texture !== undefined ) {
  13598. this.add( texture, size, distance, blending, color );
  13599. }
  13600. }
  13601. LensFlare.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13602. constructor: LensFlare,
  13603. isLensFlare: true,
  13604. copy: function ( source ) {
  13605. Object3D.prototype.copy.call( this, source );
  13606. this.positionScreen.copy( source.positionScreen );
  13607. this.customUpdateCallback = source.customUpdateCallback;
  13608. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13609. this.lensFlares.push( source.lensFlares[ i ] );
  13610. }
  13611. return this;
  13612. },
  13613. add: function ( texture, size, distance, blending, color, opacity ) {
  13614. if ( size === undefined ) size = - 1;
  13615. if ( distance === undefined ) distance = 0;
  13616. if ( opacity === undefined ) opacity = 1;
  13617. if ( color === undefined ) color = new Color( 0xffffff );
  13618. if ( blending === undefined ) blending = NormalBlending;
  13619. distance = Math.min( distance, Math.max( 0, distance ) );
  13620. this.lensFlares.push( {
  13621. texture: texture, // THREE.Texture
  13622. size: size, // size in pixels (-1 = use texture.width)
  13623. distance: distance, // distance (0-1) from light source (0=at light source)
  13624. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13625. scale: 1, // scale
  13626. rotation: 0, // rotation
  13627. opacity: opacity, // opacity
  13628. color: color, // color
  13629. blending: blending // blending
  13630. } );
  13631. },
  13632. /*
  13633. * Update lens flares update positions on all flares based on the screen position
  13634. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13635. */
  13636. updateLensFlares: function () {
  13637. var f, fl = this.lensFlares.length;
  13638. var flare;
  13639. var vecX = - this.positionScreen.x * 2;
  13640. var vecY = - this.positionScreen.y * 2;
  13641. for ( f = 0; f < fl; f ++ ) {
  13642. flare = this.lensFlares[ f ];
  13643. flare.x = this.positionScreen.x + vecX * flare.distance;
  13644. flare.y = this.positionScreen.y + vecY * flare.distance;
  13645. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13646. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13647. }
  13648. }
  13649. } );
  13650. /**
  13651. * @author alteredq / http://alteredqualia.com/
  13652. *
  13653. * parameters = {
  13654. * color: <hex>,
  13655. * opacity: <float>,
  13656. * map: new THREE.Texture( <Image> ),
  13657. *
  13658. * uvOffset: new THREE.Vector2(),
  13659. * uvScale: new THREE.Vector2()
  13660. * }
  13661. */
  13662. function SpriteMaterial( parameters ) {
  13663. Material.call( this );
  13664. this.type = 'SpriteMaterial';
  13665. this.color = new Color( 0xffffff );
  13666. this.map = null;
  13667. this.rotation = 0;
  13668. this.fog = false;
  13669. this.lights = false;
  13670. this.setValues( parameters );
  13671. }
  13672. SpriteMaterial.prototype = Object.create( Material.prototype );
  13673. SpriteMaterial.prototype.constructor = SpriteMaterial;
  13674. SpriteMaterial.prototype.isSpriteMaterial = true;
  13675. SpriteMaterial.prototype.copy = function ( source ) {
  13676. Material.prototype.copy.call( this, source );
  13677. this.color.copy( source.color );
  13678. this.map = source.map;
  13679. this.rotation = source.rotation;
  13680. return this;
  13681. };
  13682. /**
  13683. * @author mikael emtinger / http://gomo.se/
  13684. * @author alteredq / http://alteredqualia.com/
  13685. */
  13686. function Sprite( material ) {
  13687. Object3D.call( this );
  13688. this.type = 'Sprite';
  13689. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  13690. }
  13691. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13692. constructor: Sprite,
  13693. isSprite: true,
  13694. raycast: ( function () {
  13695. var intersectPoint = new Vector3();
  13696. var worldPosition = new Vector3();
  13697. var worldScale = new Vector3();
  13698. return function raycast( raycaster, intersects ) {
  13699. worldPosition.setFromMatrixPosition( this.matrixWorld );
  13700. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  13701. worldScale.setFromMatrixScale( this.matrixWorld );
  13702. var guessSizeSq = worldScale.x * worldScale.y / 4;
  13703. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  13704. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13705. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13706. intersects.push( {
  13707. distance: distance,
  13708. point: intersectPoint.clone(),
  13709. face: null,
  13710. object: this
  13711. } );
  13712. };
  13713. }() ),
  13714. clone: function () {
  13715. return new this.constructor( this.material ).copy( this );
  13716. }
  13717. } );
  13718. /**
  13719. * @author mikael emtinger / http://gomo.se/
  13720. * @author alteredq / http://alteredqualia.com/
  13721. * @author mrdoob / http://mrdoob.com/
  13722. */
  13723. function LOD() {
  13724. Object3D.call( this );
  13725. this.type = 'LOD';
  13726. Object.defineProperties( this, {
  13727. levels: {
  13728. enumerable: true,
  13729. value: []
  13730. }
  13731. } );
  13732. }
  13733. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13734. constructor: LOD,
  13735. copy: function ( source ) {
  13736. Object3D.prototype.copy.call( this, source, false );
  13737. var levels = source.levels;
  13738. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13739. var level = levels[ i ];
  13740. this.addLevel( level.object.clone(), level.distance );
  13741. }
  13742. return this;
  13743. },
  13744. addLevel: function ( object, distance ) {
  13745. if ( distance === undefined ) distance = 0;
  13746. distance = Math.abs( distance );
  13747. var levels = this.levels;
  13748. for ( var l = 0; l < levels.length; l ++ ) {
  13749. if ( distance < levels[ l ].distance ) {
  13750. break;
  13751. }
  13752. }
  13753. levels.splice( l, 0, { distance: distance, object: object } );
  13754. this.add( object );
  13755. },
  13756. getObjectForDistance: function ( distance ) {
  13757. var levels = this.levels;
  13758. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13759. if ( distance < levels[ i ].distance ) {
  13760. break;
  13761. }
  13762. }
  13763. return levels[ i - 1 ].object;
  13764. },
  13765. raycast: ( function () {
  13766. var matrixPosition = new Vector3();
  13767. return function raycast( raycaster, intersects ) {
  13768. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13769. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13770. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13771. };
  13772. }() ),
  13773. update: function () {
  13774. var v1 = new Vector3();
  13775. var v2 = new Vector3();
  13776. return function update( camera ) {
  13777. var levels = this.levels;
  13778. if ( levels.length > 1 ) {
  13779. v1.setFromMatrixPosition( camera.matrixWorld );
  13780. v2.setFromMatrixPosition( this.matrixWorld );
  13781. var distance = v1.distanceTo( v2 );
  13782. levels[ 0 ].object.visible = true;
  13783. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13784. if ( distance >= levels[ i ].distance ) {
  13785. levels[ i - 1 ].object.visible = false;
  13786. levels[ i ].object.visible = true;
  13787. } else {
  13788. break;
  13789. }
  13790. }
  13791. for ( ; i < l; i ++ ) {
  13792. levels[ i ].object.visible = false;
  13793. }
  13794. }
  13795. };
  13796. }(),
  13797. toJSON: function ( meta ) {
  13798. var data = Object3D.prototype.toJSON.call( this, meta );
  13799. data.object.levels = [];
  13800. var levels = this.levels;
  13801. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13802. var level = levels[ i ];
  13803. data.object.levels.push( {
  13804. object: level.object.uuid,
  13805. distance: level.distance
  13806. } );
  13807. }
  13808. return data;
  13809. }
  13810. } );
  13811. /**
  13812. * @author mikael emtinger / http://gomo.se/
  13813. * @author alteredq / http://alteredqualia.com/
  13814. * @author michael guerrero / http://realitymeltdown.com
  13815. * @author ikerr / http://verold.com
  13816. */
  13817. function Skeleton( bones, boneInverses ) {
  13818. // copy the bone array
  13819. bones = bones || [];
  13820. this.bones = bones.slice( 0 );
  13821. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  13822. // use the supplied bone inverses or calculate the inverses
  13823. if ( boneInverses === undefined ) {
  13824. this.calculateInverses();
  13825. } else {
  13826. if ( this.bones.length === boneInverses.length ) {
  13827. this.boneInverses = boneInverses.slice( 0 );
  13828. } else {
  13829. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  13830. this.boneInverses = [];
  13831. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  13832. this.boneInverses.push( new Matrix4() );
  13833. }
  13834. }
  13835. }
  13836. }
  13837. Object.assign( Skeleton.prototype, {
  13838. calculateInverses: function () {
  13839. this.boneInverses = [];
  13840. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  13841. var inverse = new Matrix4();
  13842. if ( this.bones[ i ] ) {
  13843. inverse.getInverse( this.bones[ i ].matrixWorld );
  13844. }
  13845. this.boneInverses.push( inverse );
  13846. }
  13847. },
  13848. pose: function () {
  13849. var bone, i, il;
  13850. // recover the bind-time world matrices
  13851. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  13852. bone = this.bones[ i ];
  13853. if ( bone ) {
  13854. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  13855. }
  13856. }
  13857. // compute the local matrices, positions, rotations and scales
  13858. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  13859. bone = this.bones[ i ];
  13860. if ( bone ) {
  13861. if ( bone.parent && bone.parent.isBone ) {
  13862. bone.matrix.getInverse( bone.parent.matrixWorld );
  13863. bone.matrix.multiply( bone.matrixWorld );
  13864. } else {
  13865. bone.matrix.copy( bone.matrixWorld );
  13866. }
  13867. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13868. }
  13869. }
  13870. },
  13871. update: ( function () {
  13872. var offsetMatrix = new Matrix4();
  13873. var identityMatrix = new Matrix4();
  13874. return function update() {
  13875. var bones = this.bones;
  13876. var boneInverses = this.boneInverses;
  13877. var boneMatrices = this.boneMatrices;
  13878. var boneTexture = this.boneTexture;
  13879. // flatten bone matrices to array
  13880. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  13881. // compute the offset between the current and the original transform
  13882. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  13883. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  13884. offsetMatrix.toArray( boneMatrices, i * 16 );
  13885. }
  13886. if ( boneTexture !== undefined ) {
  13887. boneTexture.needsUpdate = true;
  13888. }
  13889. };
  13890. } )(),
  13891. clone: function () {
  13892. return new Skeleton( this.bones, this.boneInverses );
  13893. }
  13894. } );
  13895. /**
  13896. * @author mikael emtinger / http://gomo.se/
  13897. * @author alteredq / http://alteredqualia.com/
  13898. * @author ikerr / http://verold.com
  13899. */
  13900. function Bone() {
  13901. Object3D.call( this );
  13902. this.type = 'Bone';
  13903. }
  13904. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13905. constructor: Bone,
  13906. isBone: true
  13907. } );
  13908. /**
  13909. * @author mikael emtinger / http://gomo.se/
  13910. * @author alteredq / http://alteredqualia.com/
  13911. * @author ikerr / http://verold.com
  13912. */
  13913. function SkinnedMesh( geometry, material ) {
  13914. Mesh.call( this, geometry, material );
  13915. this.type = 'SkinnedMesh';
  13916. this.bindMode = 'attached';
  13917. this.bindMatrix = new Matrix4();
  13918. this.bindMatrixInverse = new Matrix4();
  13919. var bones = this.initBones();
  13920. var skeleton = new Skeleton( bones );
  13921. this.bind( skeleton, this.matrixWorld );
  13922. this.normalizeSkinWeights();
  13923. }
  13924. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  13925. constructor: SkinnedMesh,
  13926. isSkinnedMesh: true,
  13927. initBones: function () {
  13928. var bones = [], bone, gbone;
  13929. var i, il;
  13930. if ( this.geometry && this.geometry.bones !== undefined ) {
  13931. // first, create array of 'Bone' objects from geometry data
  13932. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  13933. gbone = this.geometry.bones[ i ];
  13934. // create new 'Bone' object
  13935. bone = new Bone();
  13936. bones.push( bone );
  13937. // apply values
  13938. bone.name = gbone.name;
  13939. bone.position.fromArray( gbone.pos );
  13940. bone.quaternion.fromArray( gbone.rotq );
  13941. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13942. }
  13943. // second, create bone hierarchy
  13944. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  13945. gbone = this.geometry.bones[ i ];
  13946. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  13947. // subsequent bones in the hierarchy
  13948. bones[ gbone.parent ].add( bones[ i ] );
  13949. } else {
  13950. // topmost bone, immediate child of the skinned mesh
  13951. this.add( bones[ i ] );
  13952. }
  13953. }
  13954. }
  13955. // now the bones are part of the scene graph and children of the skinned mesh.
  13956. // let's update the corresponding matrices
  13957. this.updateMatrixWorld( true );
  13958. return bones;
  13959. },
  13960. bind: function ( skeleton, bindMatrix ) {
  13961. this.skeleton = skeleton;
  13962. if ( bindMatrix === undefined ) {
  13963. this.updateMatrixWorld( true );
  13964. this.skeleton.calculateInverses();
  13965. bindMatrix = this.matrixWorld;
  13966. }
  13967. this.bindMatrix.copy( bindMatrix );
  13968. this.bindMatrixInverse.getInverse( bindMatrix );
  13969. },
  13970. pose: function () {
  13971. this.skeleton.pose();
  13972. },
  13973. normalizeSkinWeights: function () {
  13974. var scale, i;
  13975. if ( this.geometry && this.geometry.isGeometry ) {
  13976. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13977. var sw = this.geometry.skinWeights[ i ];
  13978. scale = 1.0 / sw.lengthManhattan();
  13979. if ( scale !== Infinity ) {
  13980. sw.multiplyScalar( scale );
  13981. } else {
  13982. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13983. }
  13984. }
  13985. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  13986. var vec = new Vector4();
  13987. var skinWeight = this.geometry.attributes.skinWeight;
  13988. for ( i = 0; i < skinWeight.count; i ++ ) {
  13989. vec.x = skinWeight.getX( i );
  13990. vec.y = skinWeight.getY( i );
  13991. vec.z = skinWeight.getZ( i );
  13992. vec.w = skinWeight.getW( i );
  13993. scale = 1.0 / vec.lengthManhattan();
  13994. if ( scale !== Infinity ) {
  13995. vec.multiplyScalar( scale );
  13996. } else {
  13997. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13998. }
  13999. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  14000. }
  14001. }
  14002. },
  14003. updateMatrixWorld: function ( force ) {
  14004. Mesh.prototype.updateMatrixWorld.call( this, force );
  14005. if ( this.bindMode === 'attached' ) {
  14006. this.bindMatrixInverse.getInverse( this.matrixWorld );
  14007. } else if ( this.bindMode === 'detached' ) {
  14008. this.bindMatrixInverse.getInverse( this.bindMatrix );
  14009. } else {
  14010. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  14011. }
  14012. },
  14013. clone: function () {
  14014. return new this.constructor( this.geometry, this.material ).copy( this );
  14015. }
  14016. } );
  14017. /**
  14018. * @author mrdoob / http://mrdoob.com/
  14019. * @author alteredq / http://alteredqualia.com/
  14020. *
  14021. * parameters = {
  14022. * color: <hex>,
  14023. * opacity: <float>,
  14024. *
  14025. * linewidth: <float>,
  14026. * linecap: "round",
  14027. * linejoin: "round"
  14028. * }
  14029. */
  14030. function LineBasicMaterial( parameters ) {
  14031. Material.call( this );
  14032. this.type = 'LineBasicMaterial';
  14033. this.color = new Color( 0xffffff );
  14034. this.linewidth = 1;
  14035. this.linecap = 'round';
  14036. this.linejoin = 'round';
  14037. this.lights = false;
  14038. this.setValues( parameters );
  14039. }
  14040. LineBasicMaterial.prototype = Object.create( Material.prototype );
  14041. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  14042. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  14043. LineBasicMaterial.prototype.copy = function ( source ) {
  14044. Material.prototype.copy.call( this, source );
  14045. this.color.copy( source.color );
  14046. this.linewidth = source.linewidth;
  14047. this.linecap = source.linecap;
  14048. this.linejoin = source.linejoin;
  14049. return this;
  14050. };
  14051. /**
  14052. * @author mrdoob / http://mrdoob.com/
  14053. */
  14054. function Line( geometry, material, mode ) {
  14055. if ( mode === 1 ) {
  14056. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14057. return new LineSegments( geometry, material );
  14058. }
  14059. Object3D.call( this );
  14060. this.type = 'Line';
  14061. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14062. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14063. }
  14064. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14065. constructor: Line,
  14066. isLine: true,
  14067. raycast: ( function () {
  14068. var inverseMatrix = new Matrix4();
  14069. var ray = new Ray();
  14070. var sphere = new Sphere();
  14071. return function raycast( raycaster, intersects ) {
  14072. var precision = raycaster.linePrecision;
  14073. var precisionSq = precision * precision;
  14074. var geometry = this.geometry;
  14075. var matrixWorld = this.matrixWorld;
  14076. // Checking boundingSphere distance to ray
  14077. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14078. sphere.copy( geometry.boundingSphere );
  14079. sphere.applyMatrix4( matrixWorld );
  14080. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14081. //
  14082. inverseMatrix.getInverse( matrixWorld );
  14083. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14084. var vStart = new Vector3();
  14085. var vEnd = new Vector3();
  14086. var interSegment = new Vector3();
  14087. var interRay = new Vector3();
  14088. var step = (this && this.isLineSegments) ? 2 : 1;
  14089. if ( geometry.isBufferGeometry ) {
  14090. var index = geometry.index;
  14091. var attributes = geometry.attributes;
  14092. var positions = attributes.position.array;
  14093. if ( index !== null ) {
  14094. var indices = index.array;
  14095. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14096. var a = indices[ i ];
  14097. var b = indices[ i + 1 ];
  14098. vStart.fromArray( positions, a * 3 );
  14099. vEnd.fromArray( positions, b * 3 );
  14100. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14101. if ( distSq > precisionSq ) continue;
  14102. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14103. var distance = raycaster.ray.origin.distanceTo( interRay );
  14104. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14105. intersects.push( {
  14106. distance: distance,
  14107. // What do we want? intersection point on the ray or on the segment??
  14108. // point: raycaster.ray.at( distance ),
  14109. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14110. index: i,
  14111. face: null,
  14112. faceIndex: null,
  14113. object: this
  14114. } );
  14115. }
  14116. } else {
  14117. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14118. vStart.fromArray( positions, 3 * i );
  14119. vEnd.fromArray( positions, 3 * i + 3 );
  14120. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14121. if ( distSq > precisionSq ) continue;
  14122. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14123. var distance = raycaster.ray.origin.distanceTo( interRay );
  14124. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14125. intersects.push( {
  14126. distance: distance,
  14127. // What do we want? intersection point on the ray or on the segment??
  14128. // point: raycaster.ray.at( distance ),
  14129. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14130. index: i,
  14131. face: null,
  14132. faceIndex: null,
  14133. object: this
  14134. } );
  14135. }
  14136. }
  14137. } else if ( geometry.isGeometry ) {
  14138. var vertices = geometry.vertices;
  14139. var nbVertices = vertices.length;
  14140. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14141. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14142. if ( distSq > precisionSq ) continue;
  14143. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14144. var distance = raycaster.ray.origin.distanceTo( interRay );
  14145. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14146. intersects.push( {
  14147. distance: distance,
  14148. // What do we want? intersection point on the ray or on the segment??
  14149. // point: raycaster.ray.at( distance ),
  14150. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14151. index: i,
  14152. face: null,
  14153. faceIndex: null,
  14154. object: this
  14155. } );
  14156. }
  14157. }
  14158. };
  14159. }() ),
  14160. clone: function () {
  14161. return new this.constructor( this.geometry, this.material ).copy( this );
  14162. }
  14163. } );
  14164. /**
  14165. * @author mrdoob / http://mrdoob.com/
  14166. */
  14167. function LineSegments( geometry, material ) {
  14168. Line.call( this, geometry, material );
  14169. this.type = 'LineSegments';
  14170. }
  14171. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14172. constructor: LineSegments,
  14173. isLineSegments: true
  14174. } );
  14175. /**
  14176. * @author mgreter / http://github.com/mgreter
  14177. */
  14178. function LineLoop( geometry, material ) {
  14179. Line.call( this, geometry, material );
  14180. this.type = 'LineLoop';
  14181. }
  14182. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  14183. constructor: LineLoop,
  14184. isLineLoop: true,
  14185. } );
  14186. /**
  14187. * @author mrdoob / http://mrdoob.com/
  14188. * @author alteredq / http://alteredqualia.com/
  14189. *
  14190. * parameters = {
  14191. * color: <hex>,
  14192. * opacity: <float>,
  14193. * map: new THREE.Texture( <Image> ),
  14194. *
  14195. * size: <float>,
  14196. * sizeAttenuation: <bool>
  14197. * }
  14198. */
  14199. function PointsMaterial( parameters ) {
  14200. Material.call( this );
  14201. this.type = 'PointsMaterial';
  14202. this.color = new Color( 0xffffff );
  14203. this.map = null;
  14204. this.size = 1;
  14205. this.sizeAttenuation = true;
  14206. this.lights = false;
  14207. this.setValues( parameters );
  14208. }
  14209. PointsMaterial.prototype = Object.create( Material.prototype );
  14210. PointsMaterial.prototype.constructor = PointsMaterial;
  14211. PointsMaterial.prototype.isPointsMaterial = true;
  14212. PointsMaterial.prototype.copy = function ( source ) {
  14213. Material.prototype.copy.call( this, source );
  14214. this.color.copy( source.color );
  14215. this.map = source.map;
  14216. this.size = source.size;
  14217. this.sizeAttenuation = source.sizeAttenuation;
  14218. return this;
  14219. };
  14220. /**
  14221. * @author alteredq / http://alteredqualia.com/
  14222. */
  14223. function Points( geometry, material ) {
  14224. Object3D.call( this );
  14225. this.type = 'Points';
  14226. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14227. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  14228. }
  14229. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14230. constructor: Points,
  14231. isPoints: true,
  14232. raycast: ( function () {
  14233. var inverseMatrix = new Matrix4();
  14234. var ray = new Ray();
  14235. var sphere = new Sphere();
  14236. return function raycast( raycaster, intersects ) {
  14237. var object = this;
  14238. var geometry = this.geometry;
  14239. var matrixWorld = this.matrixWorld;
  14240. var threshold = raycaster.params.Points.threshold;
  14241. // Checking boundingSphere distance to ray
  14242. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14243. sphere.copy( geometry.boundingSphere );
  14244. sphere.applyMatrix4( matrixWorld );
  14245. sphere.radius += threshold;
  14246. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14247. //
  14248. inverseMatrix.getInverse( matrixWorld );
  14249. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14250. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  14251. var localThresholdSq = localThreshold * localThreshold;
  14252. var position = new Vector3();
  14253. function testPoint( point, index ) {
  14254. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  14255. if ( rayPointDistanceSq < localThresholdSq ) {
  14256. var intersectPoint = ray.closestPointToPoint( point );
  14257. intersectPoint.applyMatrix4( matrixWorld );
  14258. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14259. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14260. intersects.push( {
  14261. distance: distance,
  14262. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  14263. point: intersectPoint.clone(),
  14264. index: index,
  14265. face: null,
  14266. object: object
  14267. } );
  14268. }
  14269. }
  14270. if ( geometry.isBufferGeometry ) {
  14271. var index = geometry.index;
  14272. var attributes = geometry.attributes;
  14273. var positions = attributes.position.array;
  14274. if ( index !== null ) {
  14275. var indices = index.array;
  14276. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  14277. var a = indices[ i ];
  14278. position.fromArray( positions, a * 3 );
  14279. testPoint( position, a );
  14280. }
  14281. } else {
  14282. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  14283. position.fromArray( positions, i * 3 );
  14284. testPoint( position, i );
  14285. }
  14286. }
  14287. } else {
  14288. var vertices = geometry.vertices;
  14289. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  14290. testPoint( vertices[ i ], i );
  14291. }
  14292. }
  14293. };
  14294. }() ),
  14295. clone: function () {
  14296. return new this.constructor( this.geometry, this.material ).copy( this );
  14297. }
  14298. } );
  14299. /**
  14300. * @author mrdoob / http://mrdoob.com/
  14301. */
  14302. function Group() {
  14303. Object3D.call( this );
  14304. this.type = 'Group';
  14305. }
  14306. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14307. constructor: Group
  14308. } );
  14309. /**
  14310. * @author mrdoob / http://mrdoob.com/
  14311. */
  14312. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  14313. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14314. this.generateMipmaps = false;
  14315. var scope = this;
  14316. function update() {
  14317. requestAnimationFrame( update );
  14318. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  14319. scope.needsUpdate = true;
  14320. }
  14321. }
  14322. update();
  14323. }
  14324. VideoTexture.prototype = Object.create( Texture.prototype );
  14325. VideoTexture.prototype.constructor = VideoTexture;
  14326. /**
  14327. * @author alteredq / http://alteredqualia.com/
  14328. */
  14329. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  14330. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  14331. this.image = { width: width, height: height };
  14332. this.mipmaps = mipmaps;
  14333. // no flipping for cube textures
  14334. // (also flipping doesn't work for compressed textures )
  14335. this.flipY = false;
  14336. // can't generate mipmaps for compressed textures
  14337. // mips must be embedded in DDS files
  14338. this.generateMipmaps = false;
  14339. }
  14340. CompressedTexture.prototype = Object.create( Texture.prototype );
  14341. CompressedTexture.prototype.constructor = CompressedTexture;
  14342. CompressedTexture.prototype.isCompressedTexture = true;
  14343. /**
  14344. * @author mrdoob / http://mrdoob.com/
  14345. */
  14346. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  14347. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14348. this.needsUpdate = true;
  14349. }
  14350. CanvasTexture.prototype = Object.create( Texture.prototype );
  14351. CanvasTexture.prototype.constructor = CanvasTexture;
  14352. /**
  14353. * @author Matt DesLauriers / @mattdesl
  14354. * @author atix / arthursilber.de
  14355. */
  14356. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  14357. format = format !== undefined ? format : DepthFormat;
  14358. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  14359. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' )
  14360. }
  14361. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  14362. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  14363. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14364. this.image = { width: width, height: height };
  14365. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  14366. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  14367. this.flipY = false;
  14368. this.generateMipmaps = false;
  14369. }
  14370. DepthTexture.prototype = Object.create( Texture.prototype );
  14371. DepthTexture.prototype.constructor = DepthTexture;
  14372. DepthTexture.prototype.isDepthTexture = true;
  14373. /**
  14374. * @author mrdoob / http://mrdoob.com/
  14375. * @author Mugen87 / https://github.com/Mugen87
  14376. */
  14377. function WireframeGeometry( geometry ) {
  14378. BufferGeometry.call( this );
  14379. this.type = 'WireframeGeometry';
  14380. // buffer
  14381. var vertices = [];
  14382. // helper variables
  14383. var i, j, l, o, ol;
  14384. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  14385. var key, keys = [ 'a', 'b', 'c' ];
  14386. var vertex;
  14387. // different logic for Geometry and BufferGeometry
  14388. if ( geometry && geometry.isGeometry ) {
  14389. // create a data structure that contains all edges without duplicates
  14390. var faces = geometry.faces;
  14391. for ( i = 0, l = faces.length; i < l; i ++ ) {
  14392. var face = faces[ i ];
  14393. for ( j = 0; j < 3; j ++ ) {
  14394. edge1 = face[ keys[ j ] ];
  14395. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  14396. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14397. edge[ 1 ] = Math.max( edge1, edge2 );
  14398. key = edge[ 0 ] + ',' + edge[ 1 ];
  14399. if ( edges[ key ] === undefined ) {
  14400. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14401. }
  14402. }
  14403. }
  14404. // generate vertices
  14405. for ( key in edges ) {
  14406. e = edges[ key ];
  14407. vertex = geometry.vertices[ e.index1 ];
  14408. vertices.push( vertex.x, vertex.y, vertex.z );
  14409. vertex = geometry.vertices[ e.index2 ];
  14410. vertices.push( vertex.x, vertex.y, vertex.z );
  14411. }
  14412. } else if ( geometry && geometry.isBufferGeometry ) {
  14413. var position, indices, groups;
  14414. var group, start, count;
  14415. var index1, index2;
  14416. vertex = new Vector3();
  14417. if ( geometry.index !== null ) {
  14418. // indexed BufferGeometry
  14419. position = geometry.attributes.position;
  14420. indices = geometry.index;
  14421. groups = geometry.groups;
  14422. if ( groups.length === 0 ) {
  14423. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  14424. }
  14425. // create a data structure that contains all eges without duplicates
  14426. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  14427. group = groups[ o ];
  14428. start = group.start;
  14429. count = group.count;
  14430. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  14431. for ( j = 0; j < 3; j ++ ) {
  14432. edge1 = indices.getX( i + j );
  14433. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  14434. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14435. edge[ 1 ] = Math.max( edge1, edge2 );
  14436. key = edge[ 0 ] + ',' + edge[ 1 ];
  14437. if ( edges[ key ] === undefined ) {
  14438. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14439. }
  14440. }
  14441. }
  14442. }
  14443. // generate vertices
  14444. for ( key in edges ) {
  14445. e = edges[ key ];
  14446. vertex.fromBufferAttribute( position, e.index1 );
  14447. vertices.push( vertex.x, vertex.y, vertex.z );
  14448. vertex.fromBufferAttribute( position, e.index2 );
  14449. vertices.push( vertex.x, vertex.y, vertex.z );
  14450. }
  14451. } else {
  14452. // non-indexed BufferGeometry
  14453. position = geometry.attributes.position;
  14454. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  14455. for ( j = 0; j < 3; j ++ ) {
  14456. // three edges per triangle, an edge is represented as (index1, index2)
  14457. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  14458. index1 = 3 * i + j;
  14459. vertex.fromBufferAttribute( position, index1 );
  14460. vertices.push( vertex.x, vertex.y, vertex.z );
  14461. index2 = 3 * i + ( ( j + 1 ) % 3 );
  14462. vertex.fromBufferAttribute( position, index2 );
  14463. vertices.push( vertex.x, vertex.y, vertex.z );
  14464. }
  14465. }
  14466. }
  14467. }
  14468. // build geometry
  14469. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14470. }
  14471. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  14472. WireframeGeometry.prototype.constructor = WireframeGeometry;
  14473. /**
  14474. * @author zz85 / https://github.com/zz85
  14475. * @author Mugen87 / https://github.com/Mugen87
  14476. *
  14477. * Parametric Surfaces Geometry
  14478. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  14479. */
  14480. // ParametricGeometry
  14481. function ParametricGeometry( func, slices, stacks ) {
  14482. Geometry.call( this );
  14483. this.type = 'ParametricGeometry';
  14484. this.parameters = {
  14485. func: func,
  14486. slices: slices,
  14487. stacks: stacks
  14488. };
  14489. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  14490. this.mergeVertices();
  14491. }
  14492. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  14493. ParametricGeometry.prototype.constructor = ParametricGeometry;
  14494. // ParametricBufferGeometry
  14495. function ParametricBufferGeometry( func, slices, stacks ) {
  14496. BufferGeometry.call( this );
  14497. this.type = 'ParametricBufferGeometry';
  14498. this.parameters = {
  14499. func: func,
  14500. slices: slices,
  14501. stacks: stacks
  14502. };
  14503. // buffers
  14504. var indices = [];
  14505. var vertices = [];
  14506. var normals = [];
  14507. var uvs = [];
  14508. var EPS = 0.00001;
  14509. var normal = new Vector3();
  14510. var p0 = new Vector3(), p1 = new Vector3();
  14511. var pu = new Vector3(), pv = new Vector3();
  14512. var i, j;
  14513. // generate vertices, normals and uvs
  14514. var sliceCount = slices + 1;
  14515. for ( i = 0; i <= stacks; i ++ ) {
  14516. var v = i / stacks;
  14517. for ( j = 0; j <= slices; j ++ ) {
  14518. var u = j / slices;
  14519. // vertex
  14520. p0 = func( u, v, p0 );
  14521. vertices.push( p0.x, p0.y, p0.z );
  14522. // normal
  14523. // approximate tangent vectors via finite differences
  14524. if ( u - EPS >= 0 ) {
  14525. p1 = func( u - EPS, v, p1 );
  14526. pu.subVectors( p0, p1 );
  14527. } else {
  14528. p1 = func( u + EPS, v, p1 );
  14529. pu.subVectors( p1, p0 );
  14530. }
  14531. if ( v - EPS >= 0 ) {
  14532. p1 = func( u, v - EPS, p1 );
  14533. pv.subVectors( p0, p1 );
  14534. } else {
  14535. p1 = func( u, v + EPS, p1 );
  14536. pv.subVectors( p1, p0 );
  14537. }
  14538. // cross product of tangent vectors returns surface normal
  14539. normal.crossVectors( pu, pv ).normalize();
  14540. normals.push( normal.x, normal.y, normal.z );
  14541. // uv
  14542. uvs.push( u, v );
  14543. }
  14544. }
  14545. // generate indices
  14546. for ( i = 0; i < stacks; i ++ ) {
  14547. for ( j = 0; j < slices; j ++ ) {
  14548. var a = i * sliceCount + j;
  14549. var b = i * sliceCount + j + 1;
  14550. var c = ( i + 1 ) * sliceCount + j + 1;
  14551. var d = ( i + 1 ) * sliceCount + j;
  14552. // faces one and two
  14553. indices.push( a, b, d );
  14554. indices.push( b, c, d );
  14555. }
  14556. }
  14557. // build geometry
  14558. this.setIndex( indices );
  14559. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14560. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  14561. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  14562. }
  14563. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  14564. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  14565. /**
  14566. * @author clockworkgeek / https://github.com/clockworkgeek
  14567. * @author timothypratley / https://github.com/timothypratley
  14568. * @author WestLangley / http://github.com/WestLangley
  14569. * @author Mugen87 / https://github.com/Mugen87
  14570. */
  14571. // PolyhedronGeometry
  14572. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  14573. Geometry.call( this );
  14574. this.type = 'PolyhedronGeometry';
  14575. this.parameters = {
  14576. vertices: vertices,
  14577. indices: indices,
  14578. radius: radius,
  14579. detail: detail
  14580. };
  14581. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  14582. this.mergeVertices();
  14583. }
  14584. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  14585. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  14586. // PolyhedronBufferGeometry
  14587. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  14588. BufferGeometry.call( this );
  14589. this.type = 'PolyhedronBufferGeometry';
  14590. this.parameters = {
  14591. vertices: vertices,
  14592. indices: indices,
  14593. radius: radius,
  14594. detail: detail
  14595. };
  14596. radius = radius || 1;
  14597. detail = detail || 0;
  14598. // default buffer data
  14599. var vertexBuffer = [];
  14600. var uvBuffer = [];
  14601. // the subdivision creates the vertex buffer data
  14602. subdivide( detail );
  14603. // all vertices should lie on a conceptual sphere with a given radius
  14604. appplyRadius( radius );
  14605. // finally, create the uv data
  14606. generateUVs();
  14607. // build non-indexed geometry
  14608. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  14609. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  14610. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  14611. if ( detail === 0 ) {
  14612. this.computeVertexNormals(); // flat normals
  14613. } else {
  14614. this.normalizeNormals(); // smooth normals
  14615. }
  14616. // helper functions
  14617. function subdivide( detail ) {
  14618. var a = new Vector3();
  14619. var b = new Vector3();
  14620. var c = new Vector3();
  14621. // iterate over all faces and apply a subdivison with the given detail value
  14622. for ( var i = 0; i < indices.length; i += 3 ) {
  14623. // get the vertices of the face
  14624. getVertexByIndex( indices[ i + 0 ], a );
  14625. getVertexByIndex( indices[ i + 1 ], b );
  14626. getVertexByIndex( indices[ i + 2 ], c );
  14627. // perform subdivision
  14628. subdivideFace( a, b, c, detail );
  14629. }
  14630. }
  14631. function subdivideFace( a, b, c, detail ) {
  14632. var cols = Math.pow( 2, detail );
  14633. // we use this multidimensional array as a data structure for creating the subdivision
  14634. var v = [];
  14635. var i, j;
  14636. // construct all of the vertices for this subdivision
  14637. for ( i = 0; i <= cols; i ++ ) {
  14638. v[ i ] = [];
  14639. var aj = a.clone().lerp( c, i / cols );
  14640. var bj = b.clone().lerp( c, i / cols );
  14641. var rows = cols - i;
  14642. for ( j = 0; j <= rows; j ++ ) {
  14643. if ( j === 0 && i === cols ) {
  14644. v[ i ][ j ] = aj;
  14645. } else {
  14646. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  14647. }
  14648. }
  14649. }
  14650. // construct all of the faces
  14651. for ( i = 0; i < cols; i ++ ) {
  14652. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  14653. var k = Math.floor( j / 2 );
  14654. if ( j % 2 === 0 ) {
  14655. pushVertex( v[ i ][ k + 1 ] );
  14656. pushVertex( v[ i + 1 ][ k ] );
  14657. pushVertex( v[ i ][ k ] );
  14658. } else {
  14659. pushVertex( v[ i ][ k + 1 ] );
  14660. pushVertex( v[ i + 1 ][ k + 1 ] );
  14661. pushVertex( v[ i + 1 ][ k ] );
  14662. }
  14663. }
  14664. }
  14665. }
  14666. function appplyRadius( radius ) {
  14667. var vertex = new Vector3();
  14668. // iterate over the entire buffer and apply the radius to each vertex
  14669. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  14670. vertex.x = vertexBuffer[ i + 0 ];
  14671. vertex.y = vertexBuffer[ i + 1 ];
  14672. vertex.z = vertexBuffer[ i + 2 ];
  14673. vertex.normalize().multiplyScalar( radius );
  14674. vertexBuffer[ i + 0 ] = vertex.x;
  14675. vertexBuffer[ i + 1 ] = vertex.y;
  14676. vertexBuffer[ i + 2 ] = vertex.z;
  14677. }
  14678. }
  14679. function generateUVs() {
  14680. var vertex = new Vector3();
  14681. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  14682. vertex.x = vertexBuffer[ i + 0 ];
  14683. vertex.y = vertexBuffer[ i + 1 ];
  14684. vertex.z = vertexBuffer[ i + 2 ];
  14685. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  14686. var v = inclination( vertex ) / Math.PI + 0.5;
  14687. uvBuffer.push( u, 1 - v );
  14688. }
  14689. correctUVs();
  14690. correctSeam();
  14691. }
  14692. function correctSeam() {
  14693. // handle case when face straddles the seam, see #3269
  14694. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  14695. // uv data of a single face
  14696. var x0 = uvBuffer[ i + 0 ];
  14697. var x1 = uvBuffer[ i + 2 ];
  14698. var x2 = uvBuffer[ i + 4 ];
  14699. var max = Math.max( x0, x1, x2 );
  14700. var min = Math.min( x0, x1, x2 );
  14701. // 0.9 is somewhat arbitrary
  14702. if ( max > 0.9 && min < 0.1 ) {
  14703. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  14704. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  14705. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  14706. }
  14707. }
  14708. }
  14709. function pushVertex( vertex ) {
  14710. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  14711. }
  14712. function getVertexByIndex( index, vertex ) {
  14713. var stride = index * 3;
  14714. vertex.x = vertices[ stride + 0 ];
  14715. vertex.y = vertices[ stride + 1 ];
  14716. vertex.z = vertices[ stride + 2 ];
  14717. }
  14718. function correctUVs() {
  14719. var a = new Vector3();
  14720. var b = new Vector3();
  14721. var c = new Vector3();
  14722. var centroid = new Vector3();
  14723. var uvA = new Vector2();
  14724. var uvB = new Vector2();
  14725. var uvC = new Vector2();
  14726. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  14727. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  14728. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  14729. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  14730. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  14731. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  14732. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  14733. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  14734. var azi = azimuth( centroid );
  14735. correctUV( uvA, j + 0, a, azi );
  14736. correctUV( uvB, j + 2, b, azi );
  14737. correctUV( uvC, j + 4, c, azi );
  14738. }
  14739. }
  14740. function correctUV( uv, stride, vector, azimuth ) {
  14741. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  14742. uvBuffer[ stride ] = uv.x - 1;
  14743. }
  14744. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  14745. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  14746. }
  14747. }
  14748. // Angle around the Y axis, counter-clockwise when looking from above.
  14749. function azimuth( vector ) {
  14750. return Math.atan2( vector.z, - vector.x );
  14751. }
  14752. // Angle above the XZ plane.
  14753. function inclination( vector ) {
  14754. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  14755. }
  14756. }
  14757. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  14758. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  14759. /**
  14760. * @author timothypratley / https://github.com/timothypratley
  14761. * @author Mugen87 / https://github.com/Mugen87
  14762. */
  14763. // TetrahedronGeometry
  14764. function TetrahedronGeometry( radius, detail ) {
  14765. Geometry.call( this );
  14766. this.type = 'TetrahedronGeometry';
  14767. this.parameters = {
  14768. radius: radius,
  14769. detail: detail
  14770. };
  14771. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  14772. this.mergeVertices();
  14773. }
  14774. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  14775. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  14776. // TetrahedronBufferGeometry
  14777. function TetrahedronBufferGeometry( radius, detail ) {
  14778. var vertices = [
  14779. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  14780. ];
  14781. var indices = [
  14782. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  14783. ];
  14784. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14785. this.type = 'TetrahedronBufferGeometry';
  14786. this.parameters = {
  14787. radius: radius,
  14788. detail: detail
  14789. };
  14790. }
  14791. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14792. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  14793. /**
  14794. * @author timothypratley / https://github.com/timothypratley
  14795. * @author Mugen87 / https://github.com/Mugen87
  14796. */
  14797. // OctahedronGeometry
  14798. function OctahedronGeometry( radius, detail ) {
  14799. Geometry.call( this );
  14800. this.type = 'OctahedronGeometry';
  14801. this.parameters = {
  14802. radius: radius,
  14803. detail: detail
  14804. };
  14805. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  14806. this.mergeVertices();
  14807. }
  14808. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  14809. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  14810. // OctahedronBufferGeometry
  14811. function OctahedronBufferGeometry( radius, detail ) {
  14812. var vertices = [
  14813. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  14814. ];
  14815. var indices = [
  14816. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  14817. ];
  14818. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14819. this.type = 'OctahedronBufferGeometry';
  14820. this.parameters = {
  14821. radius: radius,
  14822. detail: detail
  14823. };
  14824. }
  14825. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14826. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  14827. /**
  14828. * @author timothypratley / https://github.com/timothypratley
  14829. * @author Mugen87 / https://github.com/Mugen87
  14830. */
  14831. // IcosahedronGeometry
  14832. function IcosahedronGeometry( radius, detail ) {
  14833. Geometry.call( this );
  14834. this.type = 'IcosahedronGeometry';
  14835. this.parameters = {
  14836. radius: radius,
  14837. detail: detail
  14838. };
  14839. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  14840. this.mergeVertices();
  14841. }
  14842. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  14843. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  14844. // IcosahedronBufferGeometry
  14845. function IcosahedronBufferGeometry( radius, detail ) {
  14846. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  14847. var vertices = [
  14848. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  14849. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  14850. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  14851. ];
  14852. var indices = [
  14853. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  14854. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  14855. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  14856. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  14857. ];
  14858. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14859. this.type = 'IcosahedronBufferGeometry';
  14860. this.parameters = {
  14861. radius: radius,
  14862. detail: detail
  14863. };
  14864. }
  14865. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14866. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  14867. /**
  14868. * @author Abe Pazos / https://hamoid.com
  14869. * @author Mugen87 / https://github.com/Mugen87
  14870. */
  14871. // DodecahedronGeometry
  14872. function DodecahedronGeometry( radius, detail ) {
  14873. Geometry.call( this );
  14874. this.type = 'DodecahedronGeometry';
  14875. this.parameters = {
  14876. radius: radius,
  14877. detail: detail
  14878. };
  14879. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  14880. this.mergeVertices();
  14881. }
  14882. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  14883. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  14884. // DodecahedronBufferGeometry
  14885. function DodecahedronBufferGeometry( radius, detail ) {
  14886. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  14887. var r = 1 / t;
  14888. var vertices = [
  14889. // (±1, ±1, ±1)
  14890. - 1, - 1, - 1, - 1, - 1, 1,
  14891. - 1, 1, - 1, - 1, 1, 1,
  14892. 1, - 1, - 1, 1, - 1, 1,
  14893. 1, 1, - 1, 1, 1, 1,
  14894. // (0, ±1/φ, ±φ)
  14895. 0, - r, - t, 0, - r, t,
  14896. 0, r, - t, 0, r, t,
  14897. // (±1/φ, ±φ, 0)
  14898. - r, - t, 0, - r, t, 0,
  14899. r, - t, 0, r, t, 0,
  14900. // (±φ, 0, ±1/φ)
  14901. - t, 0, - r, t, 0, - r,
  14902. - t, 0, r, t, 0, r
  14903. ];
  14904. var indices = [
  14905. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  14906. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  14907. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  14908. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  14909. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  14910. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  14911. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  14912. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  14913. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  14914. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  14915. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  14916. 1, 12, 14, 1, 14, 5, 1, 5, 9
  14917. ];
  14918. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  14919. this.type = 'DodecahedronBufferGeometry';
  14920. this.parameters = {
  14921. radius: radius,
  14922. detail: detail
  14923. };
  14924. }
  14925. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  14926. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  14927. /**
  14928. * @author oosmoxiecode / https://github.com/oosmoxiecode
  14929. * @author WestLangley / https://github.com/WestLangley
  14930. * @author zz85 / https://github.com/zz85
  14931. * @author miningold / https://github.com/miningold
  14932. * @author jonobr1 / https://github.com/jonobr1
  14933. * @author Mugen87 / https://github.com/Mugen87
  14934. *
  14935. */
  14936. // TubeGeometry
  14937. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  14938. Geometry.call( this );
  14939. this.type = 'TubeGeometry';
  14940. this.parameters = {
  14941. path: path,
  14942. tubularSegments: tubularSegments,
  14943. radius: radius,
  14944. radialSegments: radialSegments,
  14945. closed: closed
  14946. };
  14947. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  14948. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  14949. // expose internals
  14950. this.tangents = bufferGeometry.tangents;
  14951. this.normals = bufferGeometry.normals;
  14952. this.binormals = bufferGeometry.binormals;
  14953. // create geometry
  14954. this.fromBufferGeometry( bufferGeometry );
  14955. this.mergeVertices();
  14956. }
  14957. TubeGeometry.prototype = Object.create( Geometry.prototype );
  14958. TubeGeometry.prototype.constructor = TubeGeometry;
  14959. // TubeBufferGeometry
  14960. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  14961. BufferGeometry.call( this );
  14962. this.type = 'TubeBufferGeometry';
  14963. this.parameters = {
  14964. path: path,
  14965. tubularSegments: tubularSegments,
  14966. radius: radius,
  14967. radialSegments: radialSegments,
  14968. closed: closed
  14969. };
  14970. tubularSegments = tubularSegments || 64;
  14971. radius = radius || 1;
  14972. radialSegments = radialSegments || 8;
  14973. closed = closed || false;
  14974. var frames = path.computeFrenetFrames( tubularSegments, closed );
  14975. // expose internals
  14976. this.tangents = frames.tangents;
  14977. this.normals = frames.normals;
  14978. this.binormals = frames.binormals;
  14979. // helper variables
  14980. var vertex = new Vector3();
  14981. var normal = new Vector3();
  14982. var uv = new Vector2();
  14983. var i, j;
  14984. // buffer
  14985. var vertices = [];
  14986. var normals = [];
  14987. var uvs = [];
  14988. var indices = [];
  14989. // create buffer data
  14990. generateBufferData();
  14991. // build geometry
  14992. this.setIndex( indices );
  14993. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14994. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  14995. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  14996. // functions
  14997. function generateBufferData() {
  14998. for ( i = 0; i < tubularSegments; i ++ ) {
  14999. generateSegment( i );
  15000. }
  15001. // if the geometry is not closed, generate the last row of vertices and normals
  15002. // at the regular position on the given path
  15003. //
  15004. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  15005. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  15006. // uvs are generated in a separate function.
  15007. // this makes it easy compute correct values for closed geometries
  15008. generateUVs();
  15009. // finally create faces
  15010. generateIndices();
  15011. }
  15012. function generateSegment( i ) {
  15013. // we use getPointAt to sample evenly distributed points from the given path
  15014. var P = path.getPointAt( i / tubularSegments );
  15015. // retrieve corresponding normal and binormal
  15016. var N = frames.normals[ i ];
  15017. var B = frames.binormals[ i ];
  15018. // generate normals and vertices for the current segment
  15019. for ( j = 0; j <= radialSegments; j ++ ) {
  15020. var v = j / radialSegments * Math.PI * 2;
  15021. var sin = Math.sin( v );
  15022. var cos = - Math.cos( v );
  15023. // normal
  15024. normal.x = ( cos * N.x + sin * B.x );
  15025. normal.y = ( cos * N.y + sin * B.y );
  15026. normal.z = ( cos * N.z + sin * B.z );
  15027. normal.normalize();
  15028. normals.push( normal.x, normal.y, normal.z );
  15029. // vertex
  15030. vertex.x = P.x + radius * normal.x;
  15031. vertex.y = P.y + radius * normal.y;
  15032. vertex.z = P.z + radius * normal.z;
  15033. vertices.push( vertex.x, vertex.y, vertex.z );
  15034. }
  15035. }
  15036. function generateIndices() {
  15037. for ( j = 1; j <= tubularSegments; j ++ ) {
  15038. for ( i = 1; i <= radialSegments; i ++ ) {
  15039. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15040. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15041. var c = ( radialSegments + 1 ) * j + i;
  15042. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15043. // faces
  15044. indices.push( a, b, d );
  15045. indices.push( b, c, d );
  15046. }
  15047. }
  15048. }
  15049. function generateUVs() {
  15050. for ( i = 0; i <= tubularSegments; i ++ ) {
  15051. for ( j = 0; j <= radialSegments; j ++ ) {
  15052. uv.x = i / tubularSegments;
  15053. uv.y = j / radialSegments;
  15054. uvs.push( uv.x, uv.y );
  15055. }
  15056. }
  15057. }
  15058. }
  15059. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15060. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  15061. /**
  15062. * @author oosmoxiecode
  15063. * @author Mugen87 / https://github.com/Mugen87
  15064. *
  15065. * based on http://www.blackpawn.com/texts/pqtorus/
  15066. */
  15067. // TorusKnotGeometry
  15068. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  15069. Geometry.call( this );
  15070. this.type = 'TorusKnotGeometry';
  15071. this.parameters = {
  15072. radius: radius,
  15073. tube: tube,
  15074. tubularSegments: tubularSegments,
  15075. radialSegments: radialSegments,
  15076. p: p,
  15077. q: q
  15078. };
  15079. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  15080. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  15081. this.mergeVertices();
  15082. }
  15083. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  15084. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  15085. // TorusKnotBufferGeometry
  15086. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  15087. BufferGeometry.call( this );
  15088. this.type = 'TorusKnotBufferGeometry';
  15089. this.parameters = {
  15090. radius: radius,
  15091. tube: tube,
  15092. tubularSegments: tubularSegments,
  15093. radialSegments: radialSegments,
  15094. p: p,
  15095. q: q
  15096. };
  15097. radius = radius || 100;
  15098. tube = tube || 40;
  15099. tubularSegments = Math.floor( tubularSegments ) || 64;
  15100. radialSegments = Math.floor( radialSegments ) || 8;
  15101. p = p || 2;
  15102. q = q || 3;
  15103. // buffers
  15104. var indices = [];
  15105. var vertices = [];
  15106. var normals = [];
  15107. var uvs = [];
  15108. // helper variables
  15109. var i, j;
  15110. var vertex = new Vector3();
  15111. var normal = new Vector3();
  15112. var P1 = new Vector3();
  15113. var P2 = new Vector3();
  15114. var B = new Vector3();
  15115. var T = new Vector3();
  15116. var N = new Vector3();
  15117. // generate vertices, normals and uvs
  15118. for ( i = 0; i <= tubularSegments; ++ i ) {
  15119. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  15120. var u = i / tubularSegments * p * Math.PI * 2;
  15121. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  15122. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  15123. calculatePositionOnCurve( u, p, q, radius, P1 );
  15124. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  15125. // calculate orthonormal basis
  15126. T.subVectors( P2, P1 );
  15127. N.addVectors( P2, P1 );
  15128. B.crossVectors( T, N );
  15129. N.crossVectors( B, T );
  15130. // normalize B, N. T can be ignored, we don't use it
  15131. B.normalize();
  15132. N.normalize();
  15133. for ( j = 0; j <= radialSegments; ++ j ) {
  15134. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  15135. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  15136. var v = j / radialSegments * Math.PI * 2;
  15137. var cx = - tube * Math.cos( v );
  15138. var cy = tube * Math.sin( v );
  15139. // now calculate the final vertex position.
  15140. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  15141. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  15142. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  15143. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  15144. vertices.push( vertex.x, vertex.y, vertex.z );
  15145. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  15146. normal.subVectors( vertex, P1 ).normalize();
  15147. normals.push( normal.x, normal.y, normal.z );
  15148. // uv
  15149. uvs.push( i / tubularSegments );
  15150. uvs.push( j / radialSegments );
  15151. }
  15152. }
  15153. // generate indices
  15154. for ( j = 1; j <= tubularSegments; j ++ ) {
  15155. for ( i = 1; i <= radialSegments; i ++ ) {
  15156. // indices
  15157. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15158. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15159. var c = ( radialSegments + 1 ) * j + i;
  15160. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15161. // faces
  15162. indices.push( a, b, d );
  15163. indices.push( b, c, d );
  15164. }
  15165. }
  15166. // build geometry
  15167. this.setIndex( indices );
  15168. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15169. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15170. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15171. // this function calculates the current position on the torus curve
  15172. function calculatePositionOnCurve( u, p, q, radius, position ) {
  15173. var cu = Math.cos( u );
  15174. var su = Math.sin( u );
  15175. var quOverP = q / p * u;
  15176. var cs = Math.cos( quOverP );
  15177. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  15178. position.y = radius * ( 2 + cs ) * su * 0.5;
  15179. position.z = radius * Math.sin( quOverP ) * 0.5;
  15180. }
  15181. }
  15182. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15183. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  15184. /**
  15185. * @author oosmoxiecode
  15186. * @author mrdoob / http://mrdoob.com/
  15187. * @author Mugen87 / https://github.com/Mugen87
  15188. */
  15189. // TorusGeometry
  15190. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15191. Geometry.call( this );
  15192. this.type = 'TorusGeometry';
  15193. this.parameters = {
  15194. radius: radius,
  15195. tube: tube,
  15196. radialSegments: radialSegments,
  15197. tubularSegments: tubularSegments,
  15198. arc: arc
  15199. };
  15200. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  15201. this.mergeVertices();
  15202. }
  15203. TorusGeometry.prototype = Object.create( Geometry.prototype );
  15204. TorusGeometry.prototype.constructor = TorusGeometry;
  15205. // TorusBufferGeometry
  15206. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15207. BufferGeometry.call( this );
  15208. this.type = 'TorusBufferGeometry';
  15209. this.parameters = {
  15210. radius: radius,
  15211. tube: tube,
  15212. radialSegments: radialSegments,
  15213. tubularSegments: tubularSegments,
  15214. arc: arc
  15215. };
  15216. radius = radius || 100;
  15217. tube = tube || 40;
  15218. radialSegments = Math.floor( radialSegments ) || 8;
  15219. tubularSegments = Math.floor( tubularSegments ) || 6;
  15220. arc = arc || Math.PI * 2;
  15221. // buffers
  15222. var indices = [];
  15223. var vertices = [];
  15224. var normals = [];
  15225. var uvs = [];
  15226. // helper variables
  15227. var center = new Vector3();
  15228. var vertex = new Vector3();
  15229. var normal = new Vector3();
  15230. var j, i;
  15231. // generate vertices, normals and uvs
  15232. for ( j = 0; j <= radialSegments; j ++ ) {
  15233. for ( i = 0; i <= tubularSegments; i ++ ) {
  15234. var u = i / tubularSegments * arc;
  15235. var v = j / radialSegments * Math.PI * 2;
  15236. // vertex
  15237. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  15238. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  15239. vertex.z = tube * Math.sin( v );
  15240. vertices.push( vertex.x, vertex.y, vertex.z );
  15241. // normal
  15242. center.x = radius * Math.cos( u );
  15243. center.y = radius * Math.sin( u );
  15244. normal.subVectors( vertex, center ).normalize();
  15245. normals.push( normal.x, normal.y, normal.z );
  15246. // uv
  15247. uvs.push( i / tubularSegments );
  15248. uvs.push( j / radialSegments );
  15249. }
  15250. }
  15251. // generate indices
  15252. for ( j = 1; j <= radialSegments; j ++ ) {
  15253. for ( i = 1; i <= tubularSegments; i ++ ) {
  15254. // indices
  15255. var a = ( tubularSegments + 1 ) * j + i - 1;
  15256. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  15257. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  15258. var d = ( tubularSegments + 1 ) * j + i;
  15259. // faces
  15260. indices.push( a, b, d );
  15261. indices.push( b, c, d );
  15262. }
  15263. }
  15264. // build geometry
  15265. this.setIndex( indices );
  15266. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15267. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15268. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15269. }
  15270. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15271. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  15272. /**
  15273. * @author zz85 / http://www.lab4games.net/zz85/blog
  15274. */
  15275. var ShapeUtils = {
  15276. // calculate area of the contour polygon
  15277. area: function ( contour ) {
  15278. var n = contour.length;
  15279. var a = 0.0;
  15280. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  15281. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15282. }
  15283. return a * 0.5;
  15284. },
  15285. triangulate: ( function () {
  15286. /**
  15287. * This code is a quick port of code written in C++ which was submitted to
  15288. * flipcode.com by John W. Ratcliff // July 22, 2000
  15289. * See original code and more information here:
  15290. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15291. *
  15292. * ported to actionscript by Zevan Rosser
  15293. * www.actionsnippet.com
  15294. *
  15295. * ported to javascript by Joshua Koo
  15296. * http://www.lab4games.net/zz85/blog
  15297. *
  15298. */
  15299. function snip( contour, u, v, w, n, verts ) {
  15300. var p;
  15301. var ax, ay, bx, by;
  15302. var cx, cy, px, py;
  15303. ax = contour[ verts[ u ] ].x;
  15304. ay = contour[ verts[ u ] ].y;
  15305. bx = contour[ verts[ v ] ].x;
  15306. by = contour[ verts[ v ] ].y;
  15307. cx = contour[ verts[ w ] ].x;
  15308. cy = contour[ verts[ w ] ].y;
  15309. if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
  15310. var aX, aY, bX, bY, cX, cY;
  15311. var apx, apy, bpx, bpy, cpx, cpy;
  15312. var cCROSSap, bCROSScp, aCROSSbp;
  15313. aX = cx - bx; aY = cy - by;
  15314. bX = ax - cx; bY = ay - cy;
  15315. cX = bx - ax; cY = by - ay;
  15316. for ( p = 0; p < n; p ++ ) {
  15317. px = contour[ verts[ p ] ].x;
  15318. py = contour[ verts[ p ] ].y;
  15319. if ( ( ( px === ax ) && ( py === ay ) ) ||
  15320. ( ( px === bx ) && ( py === by ) ) ||
  15321. ( ( px === cx ) && ( py === cy ) ) ) continue;
  15322. apx = px - ax; apy = py - ay;
  15323. bpx = px - bx; bpy = py - by;
  15324. cpx = px - cx; cpy = py - cy;
  15325. // see if p is inside triangle abc
  15326. aCROSSbp = aX * bpy - aY * bpx;
  15327. cCROSSap = cX * apy - cY * apx;
  15328. bCROSScp = bX * cpy - bY * cpx;
  15329. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  15330. }
  15331. return true;
  15332. }
  15333. // takes in an contour array and returns
  15334. return function triangulate( contour, indices ) {
  15335. var n = contour.length;
  15336. if ( n < 3 ) return null;
  15337. var result = [],
  15338. verts = [],
  15339. vertIndices = [];
  15340. /* we want a counter-clockwise polygon in verts */
  15341. var u, v, w;
  15342. if ( ShapeUtils.area( contour ) > 0.0 ) {
  15343. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  15344. } else {
  15345. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  15346. }
  15347. var nv = n;
  15348. /* remove nv - 2 vertices, creating 1 triangle every time */
  15349. var count = 2 * nv; /* error detection */
  15350. for ( v = nv - 1; nv > 2; ) {
  15351. /* if we loop, it is probably a non-simple polygon */
  15352. if ( ( count -- ) <= 0 ) {
  15353. //** Triangulate: ERROR - probable bad polygon!
  15354. //throw ( "Warning, unable to triangulate polygon!" );
  15355. //return null;
  15356. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15357. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  15358. if ( indices ) return vertIndices;
  15359. return result;
  15360. }
  15361. /* three consecutive vertices in current polygon, <u,v,w> */
  15362. u = v; if ( nv <= u ) u = 0; /* previous */
  15363. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15364. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15365. if ( snip( contour, u, v, w, nv, verts ) ) {
  15366. var a, b, c, s, t;
  15367. /* true names of the vertices */
  15368. a = verts[ u ];
  15369. b = verts[ v ];
  15370. c = verts[ w ];
  15371. /* output Triangle */
  15372. result.push( [ contour[ a ],
  15373. contour[ b ],
  15374. contour[ c ] ] );
  15375. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15376. /* remove v from the remaining polygon */
  15377. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  15378. verts[ s ] = verts[ t ];
  15379. }
  15380. nv --;
  15381. /* reset error detection counter */
  15382. count = 2 * nv;
  15383. }
  15384. }
  15385. if ( indices ) return vertIndices;
  15386. return result;
  15387. }
  15388. } )(),
  15389. triangulateShape: function ( contour, holes ) {
  15390. function removeDupEndPts(points) {
  15391. var l = points.length;
  15392. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  15393. points.pop();
  15394. }
  15395. }
  15396. removeDupEndPts( contour );
  15397. holes.forEach( removeDupEndPts );
  15398. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  15399. // inOtherPt needs to be collinear to the inSegment
  15400. if ( inSegPt1.x !== inSegPt2.x ) {
  15401. if ( inSegPt1.x < inSegPt2.x ) {
  15402. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  15403. } else {
  15404. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  15405. }
  15406. } else {
  15407. if ( inSegPt1.y < inSegPt2.y ) {
  15408. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  15409. } else {
  15410. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  15411. }
  15412. }
  15413. }
  15414. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  15415. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  15416. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  15417. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  15418. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  15419. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  15420. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  15421. if ( Math.abs( limit ) > Number.EPSILON ) {
  15422. // not parallel
  15423. var perpSeg2;
  15424. if ( limit > 0 ) {
  15425. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  15426. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  15427. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  15428. } else {
  15429. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  15430. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  15431. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  15432. }
  15433. // i.e. to reduce rounding errors
  15434. // intersection at endpoint of segment#1?
  15435. if ( perpSeg2 === 0 ) {
  15436. if ( ( inExcludeAdjacentSegs ) &&
  15437. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  15438. return [ inSeg1Pt1 ];
  15439. }
  15440. if ( perpSeg2 === limit ) {
  15441. if ( ( inExcludeAdjacentSegs ) &&
  15442. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  15443. return [ inSeg1Pt2 ];
  15444. }
  15445. // intersection at endpoint of segment#2?
  15446. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  15447. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  15448. // return real intersection point
  15449. var factorSeg1 = perpSeg2 / limit;
  15450. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  15451. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  15452. } else {
  15453. // parallel or collinear
  15454. if ( ( perpSeg1 !== 0 ) ||
  15455. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  15456. // they are collinear or degenerate
  15457. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  15458. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  15459. // both segments are points
  15460. if ( seg1Pt && seg2Pt ) {
  15461. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  15462. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  15463. return [ inSeg1Pt1 ]; // they are the same point
  15464. }
  15465. // segment#1 is a single point
  15466. if ( seg1Pt ) {
  15467. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  15468. return [ inSeg1Pt1 ];
  15469. }
  15470. // segment#2 is a single point
  15471. if ( seg2Pt ) {
  15472. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  15473. return [ inSeg2Pt1 ];
  15474. }
  15475. // they are collinear segments, which might overlap
  15476. var seg1min, seg1max, seg1minVal, seg1maxVal;
  15477. var seg2min, seg2max, seg2minVal, seg2maxVal;
  15478. if ( seg1dx !== 0 ) {
  15479. // the segments are NOT on a vertical line
  15480. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  15481. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  15482. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  15483. } else {
  15484. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  15485. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  15486. }
  15487. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  15488. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  15489. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  15490. } else {
  15491. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  15492. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  15493. }
  15494. } else {
  15495. // the segments are on a vertical line
  15496. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  15497. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  15498. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  15499. } else {
  15500. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  15501. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  15502. }
  15503. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  15504. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  15505. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  15506. } else {
  15507. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  15508. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  15509. }
  15510. }
  15511. if ( seg1minVal <= seg2minVal ) {
  15512. if ( seg1maxVal < seg2minVal ) return [];
  15513. if ( seg1maxVal === seg2minVal ) {
  15514. if ( inExcludeAdjacentSegs ) return [];
  15515. return [ seg2min ];
  15516. }
  15517. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  15518. return [ seg2min, seg2max ];
  15519. } else {
  15520. if ( seg1minVal > seg2maxVal ) return [];
  15521. if ( seg1minVal === seg2maxVal ) {
  15522. if ( inExcludeAdjacentSegs ) return [];
  15523. return [ seg1min ];
  15524. }
  15525. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  15526. return [ seg1min, seg2max ];
  15527. }
  15528. }
  15529. }
  15530. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  15531. // The order of legs is important
  15532. // translation of all points, so that Vertex is at (0,0)
  15533. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  15534. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  15535. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  15536. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  15537. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  15538. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  15539. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  15540. // angle != 180 deg.
  15541. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  15542. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  15543. if ( from2toAngle > 0 ) {
  15544. // main angle < 180 deg.
  15545. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  15546. } else {
  15547. // main angle > 180 deg.
  15548. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  15549. }
  15550. } else {
  15551. // angle == 180 deg.
  15552. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  15553. return ( from2otherAngle > 0 );
  15554. }
  15555. }
  15556. function removeHoles( contour, holes ) {
  15557. var shape = contour.concat(); // work on this shape
  15558. var hole;
  15559. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  15560. // Check if hole point lies within angle around shape point
  15561. var lastShapeIdx = shape.length - 1;
  15562. var prevShapeIdx = inShapeIdx - 1;
  15563. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  15564. var nextShapeIdx = inShapeIdx + 1;
  15565. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  15566. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  15567. if ( ! insideAngle ) {
  15568. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  15569. return false;
  15570. }
  15571. // Check if shape point lies within angle around hole point
  15572. var lastHoleIdx = hole.length - 1;
  15573. var prevHoleIdx = inHoleIdx - 1;
  15574. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  15575. var nextHoleIdx = inHoleIdx + 1;
  15576. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  15577. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  15578. if ( ! insideAngle ) {
  15579. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  15580. return false;
  15581. }
  15582. return true;
  15583. }
  15584. function intersectsShapeEdge( inShapePt, inHolePt ) {
  15585. // checks for intersections with shape edges
  15586. var sIdx, nextIdx, intersection;
  15587. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  15588. nextIdx = sIdx + 1; nextIdx %= shape.length;
  15589. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  15590. if ( intersection.length > 0 ) return true;
  15591. }
  15592. return false;
  15593. }
  15594. var indepHoles = [];
  15595. function intersectsHoleEdge( inShapePt, inHolePt ) {
  15596. // checks for intersections with hole edges
  15597. var ihIdx, chkHole,
  15598. hIdx, nextIdx, intersection;
  15599. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  15600. chkHole = holes[ indepHoles[ ihIdx ]];
  15601. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  15602. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  15603. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  15604. if ( intersection.length > 0 ) return true;
  15605. }
  15606. }
  15607. return false;
  15608. }
  15609. var holeIndex, shapeIndex,
  15610. shapePt, holePt,
  15611. holeIdx, cutKey, failedCuts = [],
  15612. tmpShape1, tmpShape2,
  15613. tmpHole1, tmpHole2;
  15614. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  15615. indepHoles.push( h );
  15616. }
  15617. var minShapeIndex = 0;
  15618. var counter = indepHoles.length * 2;
  15619. while ( indepHoles.length > 0 ) {
  15620. counter --;
  15621. if ( counter < 0 ) {
  15622. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  15623. break;
  15624. }
  15625. // search for shape-vertex and hole-vertex,
  15626. // which can be connected without intersections
  15627. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  15628. shapePt = shape[ shapeIndex ];
  15629. holeIndex = - 1;
  15630. // search for hole which can be reached without intersections
  15631. for ( var h = 0; h < indepHoles.length; h ++ ) {
  15632. holeIdx = indepHoles[ h ];
  15633. // prevent multiple checks
  15634. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  15635. if ( failedCuts[ cutKey ] !== undefined ) continue;
  15636. hole = holes[ holeIdx ];
  15637. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  15638. holePt = hole[ h2 ];
  15639. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  15640. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  15641. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  15642. holeIndex = h2;
  15643. indepHoles.splice( h, 1 );
  15644. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  15645. tmpShape2 = shape.slice( shapeIndex );
  15646. tmpHole1 = hole.slice( holeIndex );
  15647. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  15648. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  15649. minShapeIndex = shapeIndex;
  15650. // Debug only, to show the selected cuts
  15651. // glob_CutLines.push( [ shapePt, holePt ] );
  15652. break;
  15653. }
  15654. if ( holeIndex >= 0 ) break; // hole-vertex found
  15655. failedCuts[ cutKey ] = true; // remember failure
  15656. }
  15657. if ( holeIndex >= 0 ) break; // hole-vertex found
  15658. }
  15659. }
  15660. return shape; /* shape with no holes */
  15661. }
  15662. var i, il, f, face,
  15663. key, index,
  15664. allPointsMap = {};
  15665. // 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.
  15666. var allpoints = contour.concat();
  15667. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  15668. Array.prototype.push.apply( allpoints, holes[ h ] );
  15669. }
  15670. //console.log( "allpoints",allpoints, allpoints.length );
  15671. // prepare all points map
  15672. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  15673. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  15674. if ( allPointsMap[ key ] !== undefined ) {
  15675. console.warn( "THREE.ShapeUtils: Duplicate point", key, i );
  15676. }
  15677. allPointsMap[ key ] = i;
  15678. }
  15679. // remove holes by cutting paths to holes and adding them to the shape
  15680. var shapeWithoutHoles = removeHoles( contour, holes );
  15681. var triangles = ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  15682. //console.log( "triangles",triangles, triangles.length );
  15683. // check all face vertices against all points map
  15684. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  15685. face = triangles[ i ];
  15686. for ( f = 0; f < 3; f ++ ) {
  15687. key = face[ f ].x + ":" + face[ f ].y;
  15688. index = allPointsMap[ key ];
  15689. if ( index !== undefined ) {
  15690. face[ f ] = index;
  15691. }
  15692. }
  15693. }
  15694. return triangles.concat();
  15695. },
  15696. isClockWise: function ( pts ) {
  15697. return ShapeUtils.area( pts ) < 0;
  15698. }
  15699. };
  15700. /**
  15701. * @author zz85 / http://www.lab4games.net/zz85/blog
  15702. *
  15703. * Creates extruded geometry from a path shape.
  15704. *
  15705. * parameters = {
  15706. *
  15707. * curveSegments: <int>, // number of points on the curves
  15708. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  15709. * amount: <int>, // Depth to extrude the shape
  15710. *
  15711. * bevelEnabled: <bool>, // turn on bevel
  15712. * bevelThickness: <float>, // how deep into the original shape bevel goes
  15713. * bevelSize: <float>, // how far from shape outline is bevel
  15714. * bevelSegments: <int>, // number of bevel layers
  15715. *
  15716. * extrudePath: <THREE.Curve> // curve to extrude shape along
  15717. * frames: <Object> // containing arrays of tangents, normals, binormals
  15718. *
  15719. * UVGenerator: <Object> // object that provides UV generator functions
  15720. *
  15721. * }
  15722. */
  15723. // ExtrudeGeometry
  15724. function ExtrudeGeometry( shapes, options ) {
  15725. Geometry.call( this );
  15726. this.type = 'ExtrudeGeometry';
  15727. this.parameters = {
  15728. shapes: shapes,
  15729. options: options
  15730. };
  15731. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  15732. this.mergeVertices();
  15733. }
  15734. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  15735. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  15736. // ExtrudeBufferGeometry
  15737. function ExtrudeBufferGeometry( shapes, options ) {
  15738. if ( typeof ( shapes ) === "undefined" ) {
  15739. shapes = [];
  15740. return;
  15741. }
  15742. BufferGeometry.call( this );
  15743. this.type = 'ExtrudeBufferGeometry';
  15744. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  15745. this.addShapeList( shapes, options );
  15746. this.computeVertexNormals();
  15747. // can't really use automatic vertex normals
  15748. // as then front and back sides get smoothed too
  15749. // should do separate smoothing just for sides
  15750. //this.computeVertexNormals();
  15751. //console.log( "took", ( Date.now() - startTime ) );
  15752. }
  15753. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15754. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  15755. ExtrudeBufferGeometry.prototype.getArrays = function () {
  15756. var positionAttribute = this.getAttribute( "position" );
  15757. var verticesArray = positionAttribute ? Array.prototype.slice.call( positionAttribute.array ) : [];
  15758. var uvAttribute = this.getAttribute( "uv" );
  15759. var uvArray = uvAttribute ? Array.prototype.slice.call( uvAttribute.array ) : [];
  15760. var IndexAttribute = this.index;
  15761. var indicesArray = IndexAttribute ? Array.prototype.slice.call( IndexAttribute.array ) : [];
  15762. return {
  15763. position: verticesArray,
  15764. uv: uvArray,
  15765. index: indicesArray
  15766. };
  15767. };
  15768. ExtrudeBufferGeometry.prototype.addShapeList = function ( shapes, options ) {
  15769. var sl = shapes.length;
  15770. options.arrays = this.getArrays();
  15771. for ( var s = 0; s < sl; s ++ ) {
  15772. var shape = shapes[ s ];
  15773. this.addShape( shape, options );
  15774. }
  15775. this.setIndex( options.arrays.index );
  15776. this.addAttribute( 'position', new Float32BufferAttribute( options.arrays.position, 3 ) );
  15777. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  15778. };
  15779. ExtrudeBufferGeometry.prototype.addShape = function ( shape, options ) {
  15780. var arrays = options.arrays ? options.arrays : this.getArrays();
  15781. var verticesArray = arrays.position;
  15782. var indicesArray = arrays.index;
  15783. var uvArray = arrays.uv;
  15784. var placeholder = [];
  15785. var amount = options.amount !== undefined ? options.amount : 100;
  15786. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  15787. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  15788. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  15789. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  15790. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  15791. var steps = options.steps !== undefined ? options.steps : 1;
  15792. var extrudePath = options.extrudePath;
  15793. var extrudePts, extrudeByPath = false;
  15794. // Use default WorldUVGenerator if no UV generators are specified.
  15795. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
  15796. var splineTube, binormal, normal, position2;
  15797. if ( extrudePath ) {
  15798. extrudePts = extrudePath.getSpacedPoints( steps );
  15799. extrudeByPath = true;
  15800. bevelEnabled = false; // bevels not supported for path extrusion
  15801. // SETUP TNB variables
  15802. // TODO1 - have a .isClosed in spline?
  15803. splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
  15804. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  15805. binormal = new Vector3();
  15806. normal = new Vector3();
  15807. position2 = new Vector3();
  15808. }
  15809. // Safeguards if bevels are not enabled
  15810. if ( ! bevelEnabled ) {
  15811. bevelSegments = 0;
  15812. bevelThickness = 0;
  15813. bevelSize = 0;
  15814. }
  15815. // Variables initialization
  15816. var ahole, h, hl; // looping of holes
  15817. var scope = this;
  15818. var shapePoints = shape.extractPoints( curveSegments );
  15819. var vertices = shapePoints.shape;
  15820. var holes = shapePoints.holes;
  15821. var reverse = ! ShapeUtils.isClockWise( vertices );
  15822. if ( reverse ) {
  15823. vertices = vertices.reverse();
  15824. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  15825. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15826. ahole = holes[ h ];
  15827. if ( ShapeUtils.isClockWise( ahole ) ) {
  15828. holes[ h ] = ahole.reverse();
  15829. }
  15830. }
  15831. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  15832. }
  15833. var faces = ShapeUtils.triangulateShape( vertices, holes );
  15834. /* Vertices */
  15835. var contour = vertices; // vertices has all points but contour has only points of circumference
  15836. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15837. ahole = holes[ h ];
  15838. vertices = vertices.concat( ahole );
  15839. }
  15840. function scalePt2( pt, vec, size ) {
  15841. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  15842. return vec.clone().multiplyScalar( size ).add( pt );
  15843. }
  15844. var b, bs, t, z,
  15845. vert, vlen = vertices.length,
  15846. face, flen = faces.length;
  15847. // Find directions for point movement
  15848. function getBevelVec( inPt, inPrev, inNext ) {
  15849. // computes for inPt the corresponding point inPt' on a new contour
  15850. // shifted by 1 unit (length of normalized vector) to the left
  15851. // if we walk along contour clockwise, this new contour is outside the old one
  15852. //
  15853. // inPt' is the intersection of the two lines parallel to the two
  15854. // adjacent edges of inPt at a distance of 1 unit on the left side.
  15855. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  15856. // good reading for geometry algorithms (here: line-line intersection)
  15857. // http://geomalgorithms.com/a05-_intersect-1.html
  15858. var v_prev_x = inPt.x - inPrev.x,
  15859. v_prev_y = inPt.y - inPrev.y;
  15860. var v_next_x = inNext.x - inPt.x,
  15861. v_next_y = inNext.y - inPt.y;
  15862. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  15863. // check for collinear edges
  15864. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  15865. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  15866. // not collinear
  15867. // length of vectors for normalizing
  15868. var v_prev_len = Math.sqrt( v_prev_lensq );
  15869. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  15870. // shift adjacent points by unit vectors to the left
  15871. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  15872. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  15873. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  15874. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  15875. // scaling factor for v_prev to intersection point
  15876. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  15877. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  15878. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  15879. // vector from inPt to intersection point
  15880. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  15881. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  15882. // Don't normalize!, otherwise sharp corners become ugly
  15883. // but prevent crazy spikes
  15884. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  15885. if ( v_trans_lensq <= 2 ) {
  15886. return new Vector2( v_trans_x, v_trans_y );
  15887. } else {
  15888. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  15889. }
  15890. } else {
  15891. // handle special case of collinear edges
  15892. var direction_eq = false; // assumes: opposite
  15893. if ( v_prev_x > Number.EPSILON ) {
  15894. if ( v_next_x > Number.EPSILON ) {
  15895. direction_eq = true;
  15896. }
  15897. } else {
  15898. if ( v_prev_x < - Number.EPSILON ) {
  15899. if ( v_next_x < - Number.EPSILON ) {
  15900. direction_eq = true;
  15901. }
  15902. } else {
  15903. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  15904. direction_eq = true;
  15905. }
  15906. }
  15907. }
  15908. if ( direction_eq ) {
  15909. // console.log("Warning: lines are a straight sequence");
  15910. v_trans_x = - v_prev_y;
  15911. v_trans_y = v_prev_x;
  15912. shrink_by = Math.sqrt( v_prev_lensq );
  15913. } else {
  15914. // console.log("Warning: lines are a straight spike");
  15915. v_trans_x = v_prev_x;
  15916. v_trans_y = v_prev_y;
  15917. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  15918. }
  15919. }
  15920. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  15921. }
  15922. var contourMovements = [];
  15923. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  15924. if ( j === il ) j = 0;
  15925. if ( k === il ) k = 0;
  15926. // (j)---(i)---(k)
  15927. // console.log('i,j,k', i, j , k)
  15928. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  15929. }
  15930. var holesMovements = [],
  15931. oneHoleMovements, verticesMovements = contourMovements.concat();
  15932. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15933. ahole = holes[ h ];
  15934. oneHoleMovements = [];
  15935. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  15936. if ( j === il ) j = 0;
  15937. if ( k === il ) k = 0;
  15938. // (j)---(i)---(k)
  15939. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  15940. }
  15941. holesMovements.push( oneHoleMovements );
  15942. verticesMovements = verticesMovements.concat( oneHoleMovements );
  15943. }
  15944. // Loop bevelSegments, 1 for the front, 1 for the back
  15945. for ( b = 0; b < bevelSegments; b ++ ) {
  15946. //for ( b = bevelSegments; b > 0; b -- ) {
  15947. t = b / bevelSegments;
  15948. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  15949. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  15950. // contract shape
  15951. for ( i = 0, il = contour.length; i < il; i ++ ) {
  15952. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  15953. v( vert.x, vert.y, - z );
  15954. }
  15955. // expand holes
  15956. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15957. ahole = holes[ h ];
  15958. oneHoleMovements = holesMovements[ h ];
  15959. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  15960. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  15961. v( vert.x, vert.y, - z );
  15962. }
  15963. }
  15964. }
  15965. bs = bevelSize;
  15966. // Back facing vertices
  15967. for ( i = 0; i < vlen; i ++ ) {
  15968. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  15969. if ( ! extrudeByPath ) {
  15970. v( vert.x, vert.y, 0 );
  15971. } else {
  15972. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  15973. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  15974. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  15975. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  15976. v( position2.x, position2.y, position2.z );
  15977. }
  15978. }
  15979. // Add stepped vertices...
  15980. // Including front facing vertices
  15981. var s;
  15982. for ( s = 1; s <= steps; s ++ ) {
  15983. for ( i = 0; i < vlen; i ++ ) {
  15984. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  15985. if ( ! extrudeByPath ) {
  15986. v( vert.x, vert.y, amount / steps * s );
  15987. } else {
  15988. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  15989. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  15990. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  15991. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  15992. v( position2.x, position2.y, position2.z );
  15993. }
  15994. }
  15995. }
  15996. // Add bevel segments planes
  15997. //for ( b = 1; b <= bevelSegments; b ++ ) {
  15998. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  15999. t = b / bevelSegments;
  16000. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16001. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16002. // contract shape
  16003. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16004. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16005. v( vert.x, vert.y, amount + z );
  16006. }
  16007. // expand holes
  16008. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16009. ahole = holes[ h ];
  16010. oneHoleMovements = holesMovements[ h ];
  16011. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16012. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16013. if ( ! extrudeByPath ) {
  16014. v( vert.x, vert.y, amount + z );
  16015. } else {
  16016. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  16017. }
  16018. }
  16019. }
  16020. }
  16021. /* Faces */
  16022. // Top and bottom faces
  16023. buildLidFaces();
  16024. // Sides faces
  16025. buildSideFaces();
  16026. ///// Internal functions
  16027. function buildLidFaces() {
  16028. var start = verticesArray.length/3;
  16029. if ( bevelEnabled ) {
  16030. var layer = 0; // steps + 1
  16031. var offset = vlen * layer;
  16032. // Bottom faces
  16033. for ( i = 0; i < flen; i ++ ) {
  16034. face = faces[ i ];
  16035. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  16036. }
  16037. layer = steps + bevelSegments * 2;
  16038. offset = vlen * layer;
  16039. // Top faces
  16040. for ( i = 0; i < flen; i ++ ) {
  16041. face = faces[ i ];
  16042. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  16043. }
  16044. } else {
  16045. // Bottom faces
  16046. for ( i = 0; i < flen; i ++ ) {
  16047. face = faces[ i ];
  16048. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  16049. }
  16050. // Top faces
  16051. for ( i = 0; i < flen; i ++ ) {
  16052. face = faces[ i ];
  16053. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  16054. }
  16055. }
  16056. scope.addGroup( start, verticesArray.length/3 -start, options.material !== undefined ? options.material : 0);
  16057. }
  16058. // Create faces for the z-sides of the shape
  16059. function buildSideFaces() {
  16060. var start = verticesArray.length/3;
  16061. var layeroffset = 0;
  16062. sidewalls( contour, layeroffset );
  16063. layeroffset += contour.length;
  16064. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16065. ahole = holes[ h ];
  16066. sidewalls( ahole, layeroffset );
  16067. //, true
  16068. layeroffset += ahole.length;
  16069. }
  16070. scope.addGroup( start, verticesArray.length/3 -start, options.extrudeMaterial !== undefined ? options.extrudeMaterial : 1);
  16071. }
  16072. function sidewalls( contour, layeroffset ) {
  16073. var j, k;
  16074. i = contour.length;
  16075. while ( -- i >= 0 ) {
  16076. j = i;
  16077. k = i - 1;
  16078. if ( k < 0 ) k = contour.length - 1;
  16079. //console.log('b', i,j, i-1, k,vertices.length);
  16080. var s = 0,
  16081. sl = steps + bevelSegments * 2;
  16082. for ( s = 0; s < sl; s ++ ) {
  16083. var slen1 = vlen * s;
  16084. var slen2 = vlen * ( s + 1 );
  16085. var a = layeroffset + j + slen1,
  16086. b = layeroffset + k + slen1,
  16087. c = layeroffset + k + slen2,
  16088. d = layeroffset + j + slen2;
  16089. f4( a, b, c, d, contour, s, sl, j, k );
  16090. }
  16091. }
  16092. }
  16093. function v( x, y, z ) {
  16094. placeholder.push( x );
  16095. placeholder.push( y );
  16096. placeholder.push( z );
  16097. }
  16098. function f3( a, b, c ) {
  16099. addVertex( a );
  16100. addVertex( b );
  16101. addVertex( c );
  16102. var nextIndex = verticesArray.length / 3;
  16103. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16104. addUV( uvs[ 0 ] );
  16105. addUV( uvs[ 1 ] );
  16106. addUV( uvs[ 2 ] );
  16107. }
  16108. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  16109. addVertex( a );
  16110. addVertex( b );
  16111. addVertex( d );
  16112. addVertex( b );
  16113. addVertex( c );
  16114. addVertex( d );
  16115. var nextIndex = verticesArray.length / 3;
  16116. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16117. addUV( uvs[ 0 ] );
  16118. addUV( uvs[ 1 ] );
  16119. addUV( uvs[ 3 ] );
  16120. addUV( uvs[ 1 ] );
  16121. addUV( uvs[ 2 ] );
  16122. addUV( uvs[ 3 ] );
  16123. }
  16124. function addVertex( index ) {
  16125. indicesArray.push( verticesArray.length / 3 );
  16126. verticesArray.push( placeholder[ index * 3 + 0 ] );
  16127. verticesArray.push( placeholder[ index * 3 + 1 ] );
  16128. verticesArray.push( placeholder[ index * 3 + 2 ] );
  16129. }
  16130. function addUV( vector2 ) {
  16131. uvArray.push( vector2.x );
  16132. uvArray.push( vector2.y );
  16133. }
  16134. if ( ! options.arrays ) {
  16135. this.setIndex( indicesArray );
  16136. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  16137. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  16138. }
  16139. };
  16140. ExtrudeGeometry.WorldUVGenerator = {
  16141. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  16142. var a_x = vertices[ indexA * 3 ];
  16143. var a_y = vertices[ indexA * 3 + 1 ];
  16144. var b_x = vertices[ indexB * 3 ];
  16145. var b_y = vertices[ indexB * 3 + 1 ];
  16146. var c_x = vertices[ indexC * 3 ];
  16147. var c_y = vertices[ indexC * 3 + 1 ];
  16148. return [
  16149. new Vector2( a_x, a_y ),
  16150. new Vector2( b_x, b_y ),
  16151. new Vector2( c_x, c_y )
  16152. ];
  16153. },
  16154. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  16155. var a_x = vertices[ indexA * 3 ];
  16156. var a_y = vertices[ indexA * 3 + 1 ];
  16157. var a_z = vertices[ indexA * 3 + 2 ];
  16158. var b_x = vertices[ indexB * 3 ];
  16159. var b_y = vertices[ indexB * 3 + 1 ];
  16160. var b_z = vertices[ indexB * 3 + 2 ];
  16161. var c_x = vertices[ indexC * 3 ];
  16162. var c_y = vertices[ indexC * 3 + 1 ];
  16163. var c_z = vertices[ indexC * 3 + 2 ];
  16164. var d_x = vertices[ indexD * 3 ];
  16165. var d_y = vertices[ indexD * 3 + 1 ];
  16166. var d_z = vertices[ indexD * 3 + 2 ];
  16167. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  16168. return [
  16169. new Vector2( a_x, 1 - a_z ),
  16170. new Vector2( b_x, 1 - b_z ),
  16171. new Vector2( c_x, 1 - c_z ),
  16172. new Vector2( d_x, 1 - d_z )
  16173. ];
  16174. } else {
  16175. return [
  16176. new Vector2( a_y, 1 - a_z ),
  16177. new Vector2( b_y, 1 - b_z ),
  16178. new Vector2( c_y, 1 - c_z ),
  16179. new Vector2( d_y, 1 - d_z )
  16180. ];
  16181. }
  16182. }
  16183. };
  16184. /**
  16185. * @author zz85 / http://www.lab4games.net/zz85/blog
  16186. * @author alteredq / http://alteredqualia.com/
  16187. *
  16188. * Text = 3D Text
  16189. *
  16190. * parameters = {
  16191. * font: <THREE.Font>, // font
  16192. *
  16193. * size: <float>, // size of the text
  16194. * height: <float>, // thickness to extrude text
  16195. * curveSegments: <int>, // number of points on the curves
  16196. *
  16197. * bevelEnabled: <bool>, // turn on bevel
  16198. * bevelThickness: <float>, // how deep into text bevel goes
  16199. * bevelSize: <float> // how far from text outline is bevel
  16200. * }
  16201. */
  16202. // TextGeometry
  16203. function TextGeometry( text, parameters ) {
  16204. Geometry.call( this );
  16205. this.type = 'TextGeometry';
  16206. this.parameters = {
  16207. text: text,
  16208. parameters: parameters
  16209. };
  16210. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  16211. this.mergeVertices();
  16212. }
  16213. TextGeometry.prototype = Object.create( Geometry.prototype );
  16214. TextGeometry.prototype.constructor = TextGeometry;
  16215. // TextBufferGeometry
  16216. function TextBufferGeometry( text, parameters ) {
  16217. parameters = parameters || {};
  16218. var font = parameters.font;
  16219. if ( ( font && font.isFont ) === false ) {
  16220. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  16221. return new Geometry();
  16222. }
  16223. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  16224. // translate parameters to ExtrudeGeometry API
  16225. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  16226. // defaults
  16227. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  16228. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  16229. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  16230. ExtrudeBufferGeometry.call( this, shapes, parameters );
  16231. this.type = 'TextBufferGeometry';
  16232. }
  16233. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  16234. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  16235. /**
  16236. * @author mrdoob / http://mrdoob.com/
  16237. * @author benaadams / https://twitter.com/ben_a_adams
  16238. * @author Mugen87 / https://github.com/Mugen87
  16239. */
  16240. // SphereGeometry
  16241. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16242. Geometry.call( this );
  16243. this.type = 'SphereGeometry';
  16244. this.parameters = {
  16245. radius: radius,
  16246. widthSegments: widthSegments,
  16247. heightSegments: heightSegments,
  16248. phiStart: phiStart,
  16249. phiLength: phiLength,
  16250. thetaStart: thetaStart,
  16251. thetaLength: thetaLength
  16252. };
  16253. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  16254. this.mergeVertices();
  16255. }
  16256. SphereGeometry.prototype = Object.create( Geometry.prototype );
  16257. SphereGeometry.prototype.constructor = SphereGeometry;
  16258. // SphereBufferGeometry
  16259. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16260. BufferGeometry.call( this );
  16261. this.type = 'SphereBufferGeometry';
  16262. this.parameters = {
  16263. radius: radius,
  16264. widthSegments: widthSegments,
  16265. heightSegments: heightSegments,
  16266. phiStart: phiStart,
  16267. phiLength: phiLength,
  16268. thetaStart: thetaStart,
  16269. thetaLength: thetaLength
  16270. };
  16271. radius = radius || 50;
  16272. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  16273. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  16274. phiStart = phiStart !== undefined ? phiStart : 0;
  16275. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  16276. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16277. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  16278. var thetaEnd = thetaStart + thetaLength;
  16279. var ix, iy;
  16280. var index = 0;
  16281. var grid = [];
  16282. var vertex = new Vector3();
  16283. var normal = new Vector3();
  16284. // buffers
  16285. var indices = [];
  16286. var vertices = [];
  16287. var normals = [];
  16288. var uvs = [];
  16289. // generate vertices, normals and uvs
  16290. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  16291. var verticesRow = [];
  16292. var v = iy / heightSegments;
  16293. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  16294. var u = ix / widthSegments;
  16295. // vertex
  16296. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16297. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  16298. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16299. vertices.push( vertex.x, vertex.y, vertex.z );
  16300. // normal
  16301. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  16302. normals.push( normal.x, normal.y, normal.z );
  16303. // uv
  16304. uvs.push( u, 1 - v );
  16305. verticesRow.push( index ++ );
  16306. }
  16307. grid.push( verticesRow );
  16308. }
  16309. // indices
  16310. for ( iy = 0; iy < heightSegments; iy ++ ) {
  16311. for ( ix = 0; ix < widthSegments; ix ++ ) {
  16312. var a = grid[ iy ][ ix + 1 ];
  16313. var b = grid[ iy ][ ix ];
  16314. var c = grid[ iy + 1 ][ ix ];
  16315. var d = grid[ iy + 1 ][ ix + 1 ];
  16316. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  16317. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  16318. }
  16319. }
  16320. // build geometry
  16321. this.setIndex( indices );
  16322. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16323. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16324. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16325. }
  16326. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16327. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  16328. /**
  16329. * @author Kaleb Murphy
  16330. * @author Mugen87 / https://github.com/Mugen87
  16331. */
  16332. // RingGeometry
  16333. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16334. Geometry.call( this );
  16335. this.type = 'RingGeometry';
  16336. this.parameters = {
  16337. innerRadius: innerRadius,
  16338. outerRadius: outerRadius,
  16339. thetaSegments: thetaSegments,
  16340. phiSegments: phiSegments,
  16341. thetaStart: thetaStart,
  16342. thetaLength: thetaLength
  16343. };
  16344. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  16345. this.mergeVertices();
  16346. }
  16347. RingGeometry.prototype = Object.create( Geometry.prototype );
  16348. RingGeometry.prototype.constructor = RingGeometry;
  16349. // RingBufferGeometry
  16350. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16351. BufferGeometry.call( this );
  16352. this.type = 'RingBufferGeometry';
  16353. this.parameters = {
  16354. innerRadius: innerRadius,
  16355. outerRadius: outerRadius,
  16356. thetaSegments: thetaSegments,
  16357. phiSegments: phiSegments,
  16358. thetaStart: thetaStart,
  16359. thetaLength: thetaLength
  16360. };
  16361. innerRadius = innerRadius || 20;
  16362. outerRadius = outerRadius || 50;
  16363. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16364. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  16365. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  16366. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  16367. // buffers
  16368. var indices = [];
  16369. var vertices = [];
  16370. var normals = [];
  16371. var uvs = [];
  16372. // some helper variables
  16373. var segment;
  16374. var radius = innerRadius;
  16375. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  16376. var vertex = new Vector3();
  16377. var uv = new Vector2();
  16378. var j, i;
  16379. // generate vertices, normals and uvs
  16380. for ( j = 0; j <= phiSegments; j ++ ) {
  16381. for ( i = 0; i <= thetaSegments; i ++ ) {
  16382. // values are generate from the inside of the ring to the outside
  16383. segment = thetaStart + i / thetaSegments * thetaLength;
  16384. // vertex
  16385. vertex.x = radius * Math.cos( segment );
  16386. vertex.y = radius * Math.sin( segment );
  16387. vertices.push( vertex.x, vertex.y, vertex.z );
  16388. // normal
  16389. normals.push( 0, 0, 1 );
  16390. // uv
  16391. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  16392. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  16393. uvs.push( uv.x, uv.y );
  16394. }
  16395. // increase the radius for next row of vertices
  16396. radius += radiusStep;
  16397. }
  16398. // indices
  16399. for ( j = 0; j < phiSegments; j ++ ) {
  16400. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  16401. for ( i = 0; i < thetaSegments; i ++ ) {
  16402. segment = i + thetaSegmentLevel;
  16403. var a = segment;
  16404. var b = segment + thetaSegments + 1;
  16405. var c = segment + thetaSegments + 2;
  16406. var d = segment + 1;
  16407. // faces
  16408. indices.push( a, b, d );
  16409. indices.push( b, c, d );
  16410. }
  16411. }
  16412. // build geometry
  16413. this.setIndex( indices );
  16414. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16415. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16416. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16417. }
  16418. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16419. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  16420. /**
  16421. * @author astrodud / http://astrodud.isgreat.org/
  16422. * @author zz85 / https://github.com/zz85
  16423. * @author bhouston / http://clara.io
  16424. * @author Mugen87 / https://github.com/Mugen87
  16425. */
  16426. // LatheGeometry
  16427. function LatheGeometry( points, segments, phiStart, phiLength ) {
  16428. Geometry.call( this );
  16429. this.type = 'LatheGeometry';
  16430. this.parameters = {
  16431. points: points,
  16432. segments: segments,
  16433. phiStart: phiStart,
  16434. phiLength: phiLength
  16435. };
  16436. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  16437. this.mergeVertices();
  16438. }
  16439. LatheGeometry.prototype = Object.create( Geometry.prototype );
  16440. LatheGeometry.prototype.constructor = LatheGeometry;
  16441. // LatheBufferGeometry
  16442. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  16443. BufferGeometry.call( this );
  16444. this.type = 'LatheBufferGeometry';
  16445. this.parameters = {
  16446. points: points,
  16447. segments: segments,
  16448. phiStart: phiStart,
  16449. phiLength: phiLength
  16450. };
  16451. segments = Math.floor( segments ) || 12;
  16452. phiStart = phiStart || 0;
  16453. phiLength = phiLength || Math.PI * 2;
  16454. // clamp phiLength so it's in range of [ 0, 2PI ]
  16455. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  16456. // buffers
  16457. var indices = [];
  16458. var vertices = [];
  16459. var uvs = [];
  16460. // helper variables
  16461. var base;
  16462. var inverseSegments = 1.0 / segments;
  16463. var vertex = new Vector3();
  16464. var uv = new Vector2();
  16465. var i, j;
  16466. // generate vertices and uvs
  16467. for ( i = 0; i <= segments; i ++ ) {
  16468. var phi = phiStart + i * inverseSegments * phiLength;
  16469. var sin = Math.sin( phi );
  16470. var cos = Math.cos( phi );
  16471. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  16472. // vertex
  16473. vertex.x = points[ j ].x * sin;
  16474. vertex.y = points[ j ].y;
  16475. vertex.z = points[ j ].x * cos;
  16476. vertices.push( vertex.x, vertex.y, vertex.z );
  16477. // uv
  16478. uv.x = i / segments;
  16479. uv.y = j / ( points.length - 1 );
  16480. uvs.push( uv.x, uv.y );
  16481. }
  16482. }
  16483. // indices
  16484. for ( i = 0; i < segments; i ++ ) {
  16485. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  16486. base = j + i * points.length;
  16487. var a = base;
  16488. var b = base + points.length;
  16489. var c = base + points.length + 1;
  16490. var d = base + 1;
  16491. // faces
  16492. indices.push( a, b, d );
  16493. indices.push( b, c, d );
  16494. }
  16495. }
  16496. // build geometry
  16497. this.setIndex( indices );
  16498. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16499. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16500. // generate normals
  16501. this.computeVertexNormals();
  16502. // if the geometry is closed, we need to average the normals along the seam.
  16503. // because the corresponding vertices are identical (but still have different UVs).
  16504. if ( phiLength === Math.PI * 2 ) {
  16505. var normals = this.attributes.normal.array;
  16506. var n1 = new Vector3();
  16507. var n2 = new Vector3();
  16508. var n = new Vector3();
  16509. // this is the buffer offset for the last line of vertices
  16510. base = segments * points.length * 3;
  16511. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  16512. // select the normal of the vertex in the first line
  16513. n1.x = normals[ j + 0 ];
  16514. n1.y = normals[ j + 1 ];
  16515. n1.z = normals[ j + 2 ];
  16516. // select the normal of the vertex in the last line
  16517. n2.x = normals[ base + j + 0 ];
  16518. n2.y = normals[ base + j + 1 ];
  16519. n2.z = normals[ base + j + 2 ];
  16520. // average normals
  16521. n.addVectors( n1, n2 ).normalize();
  16522. // assign the new values to both normals
  16523. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  16524. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  16525. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  16526. }
  16527. }
  16528. }
  16529. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16530. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  16531. /**
  16532. * @author jonobr1 / http://jonobr1.com
  16533. * @author Mugen87 / https://github.com/Mugen87
  16534. */
  16535. // ShapeGeometry
  16536. function ShapeGeometry( shapes, curveSegments ) {
  16537. Geometry.call( this );
  16538. this.type = 'ShapeGeometry';
  16539. if ( typeof curveSegments === 'object' ) {
  16540. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  16541. curveSegments = curveSegments.curveSegments;
  16542. }
  16543. this.parameters = {
  16544. shapes: shapes,
  16545. curveSegments: curveSegments
  16546. };
  16547. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  16548. this.mergeVertices();
  16549. }
  16550. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  16551. ShapeGeometry.prototype.constructor = ShapeGeometry;
  16552. // ShapeBufferGeometry
  16553. function ShapeBufferGeometry( shapes, curveSegments ) {
  16554. BufferGeometry.call( this );
  16555. this.type = 'ShapeBufferGeometry';
  16556. this.parameters = {
  16557. shapes: shapes,
  16558. curveSegments: curveSegments
  16559. };
  16560. curveSegments = curveSegments || 12;
  16561. // buffers
  16562. var indices = [];
  16563. var vertices = [];
  16564. var normals = [];
  16565. var uvs = [];
  16566. // helper variables
  16567. var groupStart = 0;
  16568. var groupCount = 0;
  16569. // allow single and array values for "shapes" parameter
  16570. if ( Array.isArray( shapes ) === false ) {
  16571. addShape( shapes );
  16572. } else {
  16573. for ( var i = 0; i < shapes.length; i ++ ) {
  16574. addShape( shapes[ i ] );
  16575. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  16576. groupStart += groupCount;
  16577. groupCount = 0;
  16578. }
  16579. }
  16580. // build geometry
  16581. this.setIndex( indices );
  16582. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16583. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16584. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16585. // helper functions
  16586. function addShape( shape ) {
  16587. var i, l, shapeHole;
  16588. var indexOffset = vertices.length / 3;
  16589. var points = shape.extractPoints( curveSegments );
  16590. var shapeVertices = points.shape;
  16591. var shapeHoles = points.holes;
  16592. // check direction of vertices
  16593. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  16594. shapeVertices = shapeVertices.reverse();
  16595. // also check if holes are in the opposite direction
  16596. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  16597. shapeHole = shapeHoles[ i ];
  16598. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  16599. shapeHoles[ i ] = shapeHole.reverse();
  16600. }
  16601. }
  16602. }
  16603. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  16604. // join vertices of inner and outer paths to a single array
  16605. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  16606. shapeHole = shapeHoles[ i ];
  16607. shapeVertices = shapeVertices.concat( shapeHole );
  16608. }
  16609. // vertices, normals, uvs
  16610. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  16611. var vertex = shapeVertices[ i ];
  16612. vertices.push( vertex.x, vertex.y, 0 );
  16613. normals.push( 0, 0, 1 );
  16614. uvs.push( vertex.x, vertex.y ); // world uvs
  16615. }
  16616. // incides
  16617. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16618. var face = faces[ i ];
  16619. var a = face[ 0 ] + indexOffset;
  16620. var b = face[ 1 ] + indexOffset;
  16621. var c = face[ 2 ] + indexOffset;
  16622. indices.push( a, b, c );
  16623. groupCount += 3;
  16624. }
  16625. }
  16626. }
  16627. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16628. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  16629. /**
  16630. * @author WestLangley / http://github.com/WestLangley
  16631. * @author Mugen87 / https://github.com/Mugen87
  16632. */
  16633. function EdgesGeometry( geometry, thresholdAngle ) {
  16634. BufferGeometry.call( this );
  16635. this.type = 'EdgesGeometry';
  16636. this.parameters = {
  16637. thresholdAngle: thresholdAngle
  16638. };
  16639. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  16640. // buffer
  16641. var vertices = [];
  16642. // helper variables
  16643. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  16644. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  16645. var key, keys = [ 'a', 'b', 'c' ];
  16646. // prepare source geometry
  16647. var geometry2;
  16648. if ( geometry.isBufferGeometry ) {
  16649. geometry2 = new Geometry();
  16650. geometry2.fromBufferGeometry( geometry );
  16651. } else {
  16652. geometry2 = geometry.clone();
  16653. }
  16654. geometry2.mergeVertices();
  16655. geometry2.computeFaceNormals();
  16656. var sourceVertices = geometry2.vertices;
  16657. var faces = geometry2.faces;
  16658. // now create a data structure where each entry represents an edge with its adjoining faces
  16659. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  16660. var face = faces[ i ];
  16661. for ( var j = 0; j < 3; j ++ ) {
  16662. edge1 = face[ keys[ j ] ];
  16663. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16664. edge[ 0 ] = Math.min( edge1, edge2 );
  16665. edge[ 1 ] = Math.max( edge1, edge2 );
  16666. key = edge[ 0 ] + ',' + edge[ 1 ];
  16667. if ( edges[ key ] === undefined ) {
  16668. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  16669. } else {
  16670. edges[ key ].face2 = i;
  16671. }
  16672. }
  16673. }
  16674. // generate vertices
  16675. for ( key in edges ) {
  16676. var e = edges[ key ];
  16677. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  16678. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  16679. var vertex = sourceVertices[ e.index1 ];
  16680. vertices.push( vertex.x, vertex.y, vertex.z );
  16681. vertex = sourceVertices[ e.index2 ];
  16682. vertices.push( vertex.x, vertex.y, vertex.z );
  16683. }
  16684. }
  16685. // build geometry
  16686. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16687. }
  16688. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  16689. EdgesGeometry.prototype.constructor = EdgesGeometry;
  16690. /**
  16691. * @author mrdoob / http://mrdoob.com/
  16692. * @author Mugen87 / https://github.com/Mugen87
  16693. */
  16694. // CylinderGeometry
  16695. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16696. Geometry.call( this );
  16697. this.type = 'CylinderGeometry';
  16698. this.parameters = {
  16699. radiusTop: radiusTop,
  16700. radiusBottom: radiusBottom,
  16701. height: height,
  16702. radialSegments: radialSegments,
  16703. heightSegments: heightSegments,
  16704. openEnded: openEnded,
  16705. thetaStart: thetaStart,
  16706. thetaLength: thetaLength
  16707. };
  16708. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  16709. this.mergeVertices();
  16710. }
  16711. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  16712. CylinderGeometry.prototype.constructor = CylinderGeometry;
  16713. // CylinderBufferGeometry
  16714. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16715. BufferGeometry.call( this );
  16716. this.type = 'CylinderBufferGeometry';
  16717. this.parameters = {
  16718. radiusTop: radiusTop,
  16719. radiusBottom: radiusBottom,
  16720. height: height,
  16721. radialSegments: radialSegments,
  16722. heightSegments: heightSegments,
  16723. openEnded: openEnded,
  16724. thetaStart: thetaStart,
  16725. thetaLength: thetaLength
  16726. };
  16727. var scope = this;
  16728. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  16729. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  16730. height = height !== undefined ? height : 100;
  16731. radialSegments = Math.floor( radialSegments ) || 8;
  16732. heightSegments = Math.floor( heightSegments ) || 1;
  16733. openEnded = openEnded !== undefined ? openEnded : false;
  16734. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  16735. thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
  16736. // buffers
  16737. var indices = [];
  16738. var vertices = [];
  16739. var normals = [];
  16740. var uvs = [];
  16741. // helper variables
  16742. var index = 0;
  16743. var indexArray = [];
  16744. var halfHeight = height / 2;
  16745. var groupStart = 0;
  16746. // generate geometry
  16747. generateTorso();
  16748. if ( openEnded === false ) {
  16749. if ( radiusTop > 0 ) generateCap( true );
  16750. if ( radiusBottom > 0 ) generateCap( false );
  16751. }
  16752. // build geometry
  16753. this.setIndex( indices );
  16754. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16755. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16756. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16757. function generateTorso() {
  16758. var x, y;
  16759. var normal = new Vector3();
  16760. var vertex = new Vector3();
  16761. var groupCount = 0;
  16762. // this will be used to calculate the normal
  16763. var slope = ( radiusBottom - radiusTop ) / height;
  16764. // generate vertices, normals and uvs
  16765. for ( y = 0; y <= heightSegments; y ++ ) {
  16766. var indexRow = [];
  16767. var v = y / heightSegments;
  16768. // calculate the radius of the current row
  16769. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  16770. for ( x = 0; x <= radialSegments; x ++ ) {
  16771. var u = x / radialSegments;
  16772. var theta = u * thetaLength + thetaStart;
  16773. var sinTheta = Math.sin( theta );
  16774. var cosTheta = Math.cos( theta );
  16775. // vertex
  16776. vertex.x = radius * sinTheta;
  16777. vertex.y = - v * height + halfHeight;
  16778. vertex.z = radius * cosTheta;
  16779. vertices.push( vertex.x, vertex.y, vertex.z );
  16780. // normal
  16781. normal.set( sinTheta, slope, cosTheta ).normalize();
  16782. normals.push( normal.x, normal.y, normal.z );
  16783. // uv
  16784. uvs.push( u, 1 - v );
  16785. // save index of vertex in respective row
  16786. indexRow.push( index ++ );
  16787. }
  16788. // now save vertices of the row in our index array
  16789. indexArray.push( indexRow );
  16790. }
  16791. // generate indices
  16792. for ( x = 0; x < radialSegments; x ++ ) {
  16793. for ( y = 0; y < heightSegments; y ++ ) {
  16794. // we use the index array to access the correct indices
  16795. var a = indexArray[ y ][ x ];
  16796. var b = indexArray[ y + 1 ][ x ];
  16797. var c = indexArray[ y + 1 ][ x + 1 ];
  16798. var d = indexArray[ y ][ x + 1 ];
  16799. // faces
  16800. indices.push( a, b, d );
  16801. indices.push( b, c, d );
  16802. // update group counter
  16803. groupCount += 6;
  16804. }
  16805. }
  16806. // add a group to the geometry. this will ensure multi material support
  16807. scope.addGroup( groupStart, groupCount, 0 );
  16808. // calculate new start value for groups
  16809. groupStart += groupCount;
  16810. }
  16811. function generateCap( top ) {
  16812. var x, centerIndexStart, centerIndexEnd;
  16813. var uv = new Vector2();
  16814. var vertex = new Vector3();
  16815. var groupCount = 0;
  16816. var radius = ( top === true ) ? radiusTop : radiusBottom;
  16817. var sign = ( top === true ) ? 1 : - 1;
  16818. // save the index of the first center vertex
  16819. centerIndexStart = index;
  16820. // first we generate the center vertex data of the cap.
  16821. // because the geometry needs one set of uvs per face,
  16822. // we must generate a center vertex per face/segment
  16823. for ( x = 1; x <= radialSegments; x ++ ) {
  16824. // vertex
  16825. vertices.push( 0, halfHeight * sign, 0 );
  16826. // normal
  16827. normals.push( 0, sign, 0 );
  16828. // uv
  16829. uvs.push( 0.5, 0.5 );
  16830. // increase index
  16831. index ++;
  16832. }
  16833. // save the index of the last center vertex
  16834. centerIndexEnd = index;
  16835. // now we generate the surrounding vertices, normals and uvs
  16836. for ( x = 0; x <= radialSegments; x ++ ) {
  16837. var u = x / radialSegments;
  16838. var theta = u * thetaLength + thetaStart;
  16839. var cosTheta = Math.cos( theta );
  16840. var sinTheta = Math.sin( theta );
  16841. // vertex
  16842. vertex.x = radius * sinTheta;
  16843. vertex.y = halfHeight * sign;
  16844. vertex.z = radius * cosTheta;
  16845. vertices.push( vertex.x, vertex.y, vertex.z );
  16846. // normal
  16847. normals.push( 0, sign, 0 );
  16848. // uv
  16849. uv.x = ( cosTheta * 0.5 ) + 0.5;
  16850. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  16851. uvs.push( uv.x, uv.y );
  16852. // increase index
  16853. index ++;
  16854. }
  16855. // generate indices
  16856. for ( x = 0; x < radialSegments; x ++ ) {
  16857. var c = centerIndexStart + x;
  16858. var i = centerIndexEnd + x;
  16859. if ( top === true ) {
  16860. // face top
  16861. indices.push( i, i + 1, c );
  16862. } else {
  16863. // face bottom
  16864. indices.push( i + 1, i, c );
  16865. }
  16866. groupCount += 3;
  16867. }
  16868. // add a group to the geometry. this will ensure multi material support
  16869. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  16870. // calculate new start value for groups
  16871. groupStart += groupCount;
  16872. }
  16873. }
  16874. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16875. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  16876. /**
  16877. * @author abelnation / http://github.com/abelnation
  16878. */
  16879. // ConeGeometry
  16880. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16881. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  16882. this.type = 'ConeGeometry';
  16883. this.parameters = {
  16884. radius: radius,
  16885. height: height,
  16886. radialSegments: radialSegments,
  16887. heightSegments: heightSegments,
  16888. openEnded: openEnded,
  16889. thetaStart: thetaStart,
  16890. thetaLength: thetaLength
  16891. };
  16892. }
  16893. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  16894. ConeGeometry.prototype.constructor = ConeGeometry;
  16895. // ConeBufferGeometry
  16896. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  16897. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  16898. this.type = 'ConeBufferGeometry';
  16899. this.parameters = {
  16900. radius: radius,
  16901. height: height,
  16902. radialSegments: radialSegments,
  16903. heightSegments: heightSegments,
  16904. openEnded: openEnded,
  16905. thetaStart: thetaStart,
  16906. thetaLength: thetaLength
  16907. };
  16908. }
  16909. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  16910. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  16911. /**
  16912. * @author benaadams / https://twitter.com/ben_a_adams
  16913. * @author Mugen87 / https://github.com/Mugen87
  16914. * @author hughes
  16915. */
  16916. // CircleGeometry
  16917. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  16918. Geometry.call( this );
  16919. this.type = 'CircleGeometry';
  16920. this.parameters = {
  16921. radius: radius,
  16922. segments: segments,
  16923. thetaStart: thetaStart,
  16924. thetaLength: thetaLength
  16925. };
  16926. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  16927. this.mergeVertices();
  16928. }
  16929. CircleGeometry.prototype = Object.create( Geometry.prototype );
  16930. CircleGeometry.prototype.constructor = CircleGeometry;
  16931. // CircleBufferGeometry
  16932. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  16933. BufferGeometry.call( this );
  16934. this.type = 'CircleBufferGeometry';
  16935. this.parameters = {
  16936. radius: radius,
  16937. segments: segments,
  16938. thetaStart: thetaStart,
  16939. thetaLength: thetaLength
  16940. };
  16941. radius = radius || 50;
  16942. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  16943. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16944. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  16945. // buffers
  16946. var indices = [];
  16947. var vertices = [];
  16948. var normals = [];
  16949. var uvs = [];
  16950. // helper variables
  16951. var i, s;
  16952. var vertex = new Vector3();
  16953. var uv = new Vector2();
  16954. // center point
  16955. vertices.push( 0, 0, 0 );
  16956. normals.push( 0, 0, 1 );
  16957. uvs.push( 0.5, 0.5 );
  16958. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  16959. var segment = thetaStart + s / segments * thetaLength;
  16960. // vertex
  16961. vertex.x = radius * Math.cos( segment );
  16962. vertex.y = radius * Math.sin( segment );
  16963. vertices.push( vertex.x, vertex.y, vertex.z );
  16964. // normal
  16965. normals.push( 0, 0, 1 );
  16966. // uvs
  16967. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  16968. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  16969. uvs.push( uv.x, uv.y );
  16970. }
  16971. // indices
  16972. for ( i = 1; i <= segments; i ++ ) {
  16973. indices.push( i, i + 1, 0 );
  16974. }
  16975. // build geometry
  16976. this.setIndex( indices );
  16977. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16978. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16979. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16980. }
  16981. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16982. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  16983. var Geometries = Object.freeze({
  16984. WireframeGeometry: WireframeGeometry,
  16985. ParametricGeometry: ParametricGeometry,
  16986. ParametricBufferGeometry: ParametricBufferGeometry,
  16987. TetrahedronGeometry: TetrahedronGeometry,
  16988. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  16989. OctahedronGeometry: OctahedronGeometry,
  16990. OctahedronBufferGeometry: OctahedronBufferGeometry,
  16991. IcosahedronGeometry: IcosahedronGeometry,
  16992. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  16993. DodecahedronGeometry: DodecahedronGeometry,
  16994. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  16995. PolyhedronGeometry: PolyhedronGeometry,
  16996. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  16997. TubeGeometry: TubeGeometry,
  16998. TubeBufferGeometry: TubeBufferGeometry,
  16999. TorusKnotGeometry: TorusKnotGeometry,
  17000. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  17001. TorusGeometry: TorusGeometry,
  17002. TorusBufferGeometry: TorusBufferGeometry,
  17003. TextGeometry: TextGeometry,
  17004. TextBufferGeometry: TextBufferGeometry,
  17005. SphereGeometry: SphereGeometry,
  17006. SphereBufferGeometry: SphereBufferGeometry,
  17007. RingGeometry: RingGeometry,
  17008. RingBufferGeometry: RingBufferGeometry,
  17009. PlaneGeometry: PlaneGeometry,
  17010. PlaneBufferGeometry: PlaneBufferGeometry,
  17011. LatheGeometry: LatheGeometry,
  17012. LatheBufferGeometry: LatheBufferGeometry,
  17013. ShapeGeometry: ShapeGeometry,
  17014. ShapeBufferGeometry: ShapeBufferGeometry,
  17015. ExtrudeGeometry: ExtrudeGeometry,
  17016. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  17017. EdgesGeometry: EdgesGeometry,
  17018. ConeGeometry: ConeGeometry,
  17019. ConeBufferGeometry: ConeBufferGeometry,
  17020. CylinderGeometry: CylinderGeometry,
  17021. CylinderBufferGeometry: CylinderBufferGeometry,
  17022. CircleGeometry: CircleGeometry,
  17023. CircleBufferGeometry: CircleBufferGeometry,
  17024. BoxGeometry: BoxGeometry,
  17025. BoxBufferGeometry: BoxBufferGeometry
  17026. });
  17027. /**
  17028. * @author mrdoob / http://mrdoob.com/
  17029. *
  17030. * parameters = {
  17031. * opacity: <float>
  17032. * }
  17033. */
  17034. function ShadowMaterial( parameters ) {
  17035. ShaderMaterial.call( this, {
  17036. uniforms: UniformsUtils.merge( [
  17037. UniformsLib.lights,
  17038. {
  17039. opacity: { value: 1.0 }
  17040. }
  17041. ] ),
  17042. vertexShader: ShaderChunk[ 'shadow_vert' ],
  17043. fragmentShader: ShaderChunk[ 'shadow_frag' ]
  17044. } );
  17045. this.lights = true;
  17046. this.transparent = true;
  17047. Object.defineProperties( this, {
  17048. opacity: {
  17049. enumerable: true,
  17050. get: function () {
  17051. return this.uniforms.opacity.value;
  17052. },
  17053. set: function ( value ) {
  17054. this.uniforms.opacity.value = value;
  17055. }
  17056. }
  17057. } );
  17058. this.setValues( parameters );
  17059. }
  17060. ShadowMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17061. ShadowMaterial.prototype.constructor = ShadowMaterial;
  17062. ShadowMaterial.prototype.isShadowMaterial = true;
  17063. /**
  17064. * @author mrdoob / http://mrdoob.com/
  17065. */
  17066. function RawShaderMaterial( parameters ) {
  17067. ShaderMaterial.call( this, parameters );
  17068. this.type = 'RawShaderMaterial';
  17069. }
  17070. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17071. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  17072. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  17073. /**
  17074. * @author WestLangley / http://github.com/WestLangley
  17075. *
  17076. * parameters = {
  17077. * color: <hex>,
  17078. * roughness: <float>,
  17079. * metalness: <float>,
  17080. * opacity: <float>,
  17081. *
  17082. * map: new THREE.Texture( <Image> ),
  17083. *
  17084. * lightMap: new THREE.Texture( <Image> ),
  17085. * lightMapIntensity: <float>
  17086. *
  17087. * aoMap: new THREE.Texture( <Image> ),
  17088. * aoMapIntensity: <float>
  17089. *
  17090. * emissive: <hex>,
  17091. * emissiveIntensity: <float>
  17092. * emissiveMap: new THREE.Texture( <Image> ),
  17093. *
  17094. * bumpMap: new THREE.Texture( <Image> ),
  17095. * bumpScale: <float>,
  17096. *
  17097. * normalMap: new THREE.Texture( <Image> ),
  17098. * normalScale: <Vector2>,
  17099. *
  17100. * displacementMap: new THREE.Texture( <Image> ),
  17101. * displacementScale: <float>,
  17102. * displacementBias: <float>,
  17103. *
  17104. * roughnessMap: new THREE.Texture( <Image> ),
  17105. *
  17106. * metalnessMap: new THREE.Texture( <Image> ),
  17107. *
  17108. * alphaMap: new THREE.Texture( <Image> ),
  17109. *
  17110. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  17111. * envMapIntensity: <float>
  17112. *
  17113. * refractionRatio: <float>,
  17114. *
  17115. * wireframe: <boolean>,
  17116. * wireframeLinewidth: <float>,
  17117. *
  17118. * skinning: <bool>,
  17119. * morphTargets: <bool>,
  17120. * morphNormals: <bool>
  17121. * }
  17122. */
  17123. function MeshStandardMaterial( parameters ) {
  17124. Material.call( this );
  17125. this.defines = { 'STANDARD': '' };
  17126. this.type = 'MeshStandardMaterial';
  17127. this.color = new Color( 0xffffff ); // diffuse
  17128. this.roughness = 0.5;
  17129. this.metalness = 0.5;
  17130. this.map = null;
  17131. this.lightMap = null;
  17132. this.lightMapIntensity = 1.0;
  17133. this.aoMap = null;
  17134. this.aoMapIntensity = 1.0;
  17135. this.emissive = new Color( 0x000000 );
  17136. this.emissiveIntensity = 1.0;
  17137. this.emissiveMap = null;
  17138. this.bumpMap = null;
  17139. this.bumpScale = 1;
  17140. this.normalMap = null;
  17141. this.normalScale = new Vector2( 1, 1 );
  17142. this.displacementMap = null;
  17143. this.displacementScale = 1;
  17144. this.displacementBias = 0;
  17145. this.roughnessMap = null;
  17146. this.metalnessMap = null;
  17147. this.alphaMap = null;
  17148. this.envMap = null;
  17149. this.envMapIntensity = 1.0;
  17150. this.refractionRatio = 0.98;
  17151. this.wireframe = false;
  17152. this.wireframeLinewidth = 1;
  17153. this.wireframeLinecap = 'round';
  17154. this.wireframeLinejoin = 'round';
  17155. this.skinning = false;
  17156. this.morphTargets = false;
  17157. this.morphNormals = false;
  17158. this.setValues( parameters );
  17159. }
  17160. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  17161. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  17162. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  17163. MeshStandardMaterial.prototype.copy = function ( source ) {
  17164. Material.prototype.copy.call( this, source );
  17165. this.defines = { 'STANDARD': '' };
  17166. this.color.copy( source.color );
  17167. this.roughness = source.roughness;
  17168. this.metalness = source.metalness;
  17169. this.map = source.map;
  17170. this.lightMap = source.lightMap;
  17171. this.lightMapIntensity = source.lightMapIntensity;
  17172. this.aoMap = source.aoMap;
  17173. this.aoMapIntensity = source.aoMapIntensity;
  17174. this.emissive.copy( source.emissive );
  17175. this.emissiveMap = source.emissiveMap;
  17176. this.emissiveIntensity = source.emissiveIntensity;
  17177. this.bumpMap = source.bumpMap;
  17178. this.bumpScale = source.bumpScale;
  17179. this.normalMap = source.normalMap;
  17180. this.normalScale.copy( source.normalScale );
  17181. this.displacementMap = source.displacementMap;
  17182. this.displacementScale = source.displacementScale;
  17183. this.displacementBias = source.displacementBias;
  17184. this.roughnessMap = source.roughnessMap;
  17185. this.metalnessMap = source.metalnessMap;
  17186. this.alphaMap = source.alphaMap;
  17187. this.envMap = source.envMap;
  17188. this.envMapIntensity = source.envMapIntensity;
  17189. this.refractionRatio = source.refractionRatio;
  17190. this.wireframe = source.wireframe;
  17191. this.wireframeLinewidth = source.wireframeLinewidth;
  17192. this.wireframeLinecap = source.wireframeLinecap;
  17193. this.wireframeLinejoin = source.wireframeLinejoin;
  17194. this.skinning = source.skinning;
  17195. this.morphTargets = source.morphTargets;
  17196. this.morphNormals = source.morphNormals;
  17197. return this;
  17198. };
  17199. /**
  17200. * @author WestLangley / http://github.com/WestLangley
  17201. *
  17202. * parameters = {
  17203. * reflectivity: <float>
  17204. * }
  17205. */
  17206. function MeshPhysicalMaterial( parameters ) {
  17207. MeshStandardMaterial.call( this );
  17208. this.defines = { 'PHYSICAL': '' };
  17209. this.type = 'MeshPhysicalMaterial';
  17210. this.reflectivity = 0.5; // maps to F0 = 0.04
  17211. this.clearCoat = 0.0;
  17212. this.clearCoatRoughness = 0.0;
  17213. this.setValues( parameters );
  17214. }
  17215. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  17216. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  17217. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  17218. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  17219. MeshStandardMaterial.prototype.copy.call( this, source );
  17220. this.defines = { 'PHYSICAL': '' };
  17221. this.reflectivity = source.reflectivity;
  17222. this.clearCoat = source.clearCoat;
  17223. this.clearCoatRoughness = source.clearCoatRoughness;
  17224. return this;
  17225. };
  17226. /**
  17227. * @author mrdoob / http://mrdoob.com/
  17228. * @author alteredq / http://alteredqualia.com/
  17229. *
  17230. * parameters = {
  17231. * color: <hex>,
  17232. * specular: <hex>,
  17233. * shininess: <float>,
  17234. * opacity: <float>,
  17235. *
  17236. * map: new THREE.Texture( <Image> ),
  17237. *
  17238. * lightMap: new THREE.Texture( <Image> ),
  17239. * lightMapIntensity: <float>
  17240. *
  17241. * aoMap: new THREE.Texture( <Image> ),
  17242. * aoMapIntensity: <float>
  17243. *
  17244. * emissive: <hex>,
  17245. * emissiveIntensity: <float>
  17246. * emissiveMap: new THREE.Texture( <Image> ),
  17247. *
  17248. * bumpMap: new THREE.Texture( <Image> ),
  17249. * bumpScale: <float>,
  17250. *
  17251. * normalMap: new THREE.Texture( <Image> ),
  17252. * normalScale: <Vector2>,
  17253. *
  17254. * displacementMap: new THREE.Texture( <Image> ),
  17255. * displacementScale: <float>,
  17256. * displacementBias: <float>,
  17257. *
  17258. * specularMap: new THREE.Texture( <Image> ),
  17259. *
  17260. * alphaMap: new THREE.Texture( <Image> ),
  17261. *
  17262. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  17263. * combine: THREE.Multiply,
  17264. * reflectivity: <float>,
  17265. * refractionRatio: <float>,
  17266. *
  17267. * wireframe: <boolean>,
  17268. * wireframeLinewidth: <float>,
  17269. *
  17270. * skinning: <bool>,
  17271. * morphTargets: <bool>,
  17272. * morphNormals: <bool>
  17273. * }
  17274. */
  17275. function MeshPhongMaterial( parameters ) {
  17276. Material.call( this );
  17277. this.type = 'MeshPhongMaterial';
  17278. this.color = new Color( 0xffffff ); // diffuse
  17279. this.specular = new Color( 0x111111 );
  17280. this.shininess = 30;
  17281. this.map = null;
  17282. this.lightMap = null;
  17283. this.lightMapIntensity = 1.0;
  17284. this.aoMap = null;
  17285. this.aoMapIntensity = 1.0;
  17286. this.emissive = new Color( 0x000000 );
  17287. this.emissiveIntensity = 1.0;
  17288. this.emissiveMap = null;
  17289. this.bumpMap = null;
  17290. this.bumpScale = 1;
  17291. this.normalMap = null;
  17292. this.normalScale = new Vector2( 1, 1 );
  17293. this.displacementMap = null;
  17294. this.displacementScale = 1;
  17295. this.displacementBias = 0;
  17296. this.specularMap = null;
  17297. this.alphaMap = null;
  17298. this.envMap = null;
  17299. this.combine = MultiplyOperation;
  17300. this.reflectivity = 1;
  17301. this.refractionRatio = 0.98;
  17302. this.wireframe = false;
  17303. this.wireframeLinewidth = 1;
  17304. this.wireframeLinecap = 'round';
  17305. this.wireframeLinejoin = 'round';
  17306. this.skinning = false;
  17307. this.morphTargets = false;
  17308. this.morphNormals = false;
  17309. this.setValues( parameters );
  17310. }
  17311. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  17312. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  17313. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  17314. MeshPhongMaterial.prototype.copy = function ( source ) {
  17315. Material.prototype.copy.call( this, source );
  17316. this.color.copy( source.color );
  17317. this.specular.copy( source.specular );
  17318. this.shininess = source.shininess;
  17319. this.map = source.map;
  17320. this.lightMap = source.lightMap;
  17321. this.lightMapIntensity = source.lightMapIntensity;
  17322. this.aoMap = source.aoMap;
  17323. this.aoMapIntensity = source.aoMapIntensity;
  17324. this.emissive.copy( source.emissive );
  17325. this.emissiveMap = source.emissiveMap;
  17326. this.emissiveIntensity = source.emissiveIntensity;
  17327. this.bumpMap = source.bumpMap;
  17328. this.bumpScale = source.bumpScale;
  17329. this.normalMap = source.normalMap;
  17330. this.normalScale.copy( source.normalScale );
  17331. this.displacementMap = source.displacementMap;
  17332. this.displacementScale = source.displacementScale;
  17333. this.displacementBias = source.displacementBias;
  17334. this.specularMap = source.specularMap;
  17335. this.alphaMap = source.alphaMap;
  17336. this.envMap = source.envMap;
  17337. this.combine = source.combine;
  17338. this.reflectivity = source.reflectivity;
  17339. this.refractionRatio = source.refractionRatio;
  17340. this.wireframe = source.wireframe;
  17341. this.wireframeLinewidth = source.wireframeLinewidth;
  17342. this.wireframeLinecap = source.wireframeLinecap;
  17343. this.wireframeLinejoin = source.wireframeLinejoin;
  17344. this.skinning = source.skinning;
  17345. this.morphTargets = source.morphTargets;
  17346. this.morphNormals = source.morphNormals;
  17347. return this;
  17348. };
  17349. /**
  17350. * @author takahirox / http://github.com/takahirox
  17351. *
  17352. * parameters = {
  17353. * gradientMap: new THREE.Texture( <Image> )
  17354. * }
  17355. */
  17356. function MeshToonMaterial( parameters ) {
  17357. MeshPhongMaterial.call( this );
  17358. this.defines = { 'TOON': '' };
  17359. this.type = 'MeshToonMaterial';
  17360. this.gradientMap = null;
  17361. this.setValues( parameters );
  17362. }
  17363. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  17364. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  17365. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  17366. MeshToonMaterial.prototype.copy = function ( source ) {
  17367. MeshPhongMaterial.prototype.copy.call( this, source );
  17368. this.gradientMap = source.gradientMap;
  17369. return this;
  17370. };
  17371. /**
  17372. * @author mrdoob / http://mrdoob.com/
  17373. * @author WestLangley / http://github.com/WestLangley
  17374. *
  17375. * parameters = {
  17376. * opacity: <float>,
  17377. *
  17378. * bumpMap: new THREE.Texture( <Image> ),
  17379. * bumpScale: <float>,
  17380. *
  17381. * normalMap: new THREE.Texture( <Image> ),
  17382. * normalScale: <Vector2>,
  17383. *
  17384. * displacementMap: new THREE.Texture( <Image> ),
  17385. * displacementScale: <float>,
  17386. * displacementBias: <float>,
  17387. *
  17388. * wireframe: <boolean>,
  17389. * wireframeLinewidth: <float>
  17390. *
  17391. * skinning: <bool>,
  17392. * morphTargets: <bool>,
  17393. * morphNormals: <bool>
  17394. * }
  17395. */
  17396. function MeshNormalMaterial( parameters ) {
  17397. Material.call( this, parameters );
  17398. this.type = 'MeshNormalMaterial';
  17399. this.bumpMap = null;
  17400. this.bumpScale = 1;
  17401. this.normalMap = null;
  17402. this.normalScale = new Vector2( 1, 1 );
  17403. this.displacementMap = null;
  17404. this.displacementScale = 1;
  17405. this.displacementBias = 0;
  17406. this.wireframe = false;
  17407. this.wireframeLinewidth = 1;
  17408. this.fog = false;
  17409. this.lights = false;
  17410. this.skinning = false;
  17411. this.morphTargets = false;
  17412. this.morphNormals = false;
  17413. this.setValues( parameters );
  17414. }
  17415. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  17416. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  17417. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  17418. MeshNormalMaterial.prototype.copy = function ( source ) {
  17419. Material.prototype.copy.call( this, source );
  17420. this.bumpMap = source.bumpMap;
  17421. this.bumpScale = source.bumpScale;
  17422. this.normalMap = source.normalMap;
  17423. this.normalScale.copy( source.normalScale );
  17424. this.displacementMap = source.displacementMap;
  17425. this.displacementScale = source.displacementScale;
  17426. this.displacementBias = source.displacementBias;
  17427. this.wireframe = source.wireframe;
  17428. this.wireframeLinewidth = source.wireframeLinewidth;
  17429. this.skinning = source.skinning;
  17430. this.morphTargets = source.morphTargets;
  17431. this.morphNormals = source.morphNormals;
  17432. return this;
  17433. };
  17434. /**
  17435. * @author mrdoob / http://mrdoob.com/
  17436. * @author alteredq / http://alteredqualia.com/
  17437. *
  17438. * parameters = {
  17439. * color: <hex>,
  17440. * opacity: <float>,
  17441. *
  17442. * map: new THREE.Texture( <Image> ),
  17443. *
  17444. * lightMap: new THREE.Texture( <Image> ),
  17445. * lightMapIntensity: <float>
  17446. *
  17447. * aoMap: new THREE.Texture( <Image> ),
  17448. * aoMapIntensity: <float>
  17449. *
  17450. * emissive: <hex>,
  17451. * emissiveIntensity: <float>
  17452. * emissiveMap: new THREE.Texture( <Image> ),
  17453. *
  17454. * specularMap: new THREE.Texture( <Image> ),
  17455. *
  17456. * alphaMap: new THREE.Texture( <Image> ),
  17457. *
  17458. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  17459. * combine: THREE.Multiply,
  17460. * reflectivity: <float>,
  17461. * refractionRatio: <float>,
  17462. *
  17463. * wireframe: <boolean>,
  17464. * wireframeLinewidth: <float>,
  17465. *
  17466. * skinning: <bool>,
  17467. * morphTargets: <bool>,
  17468. * morphNormals: <bool>
  17469. * }
  17470. */
  17471. function MeshLambertMaterial( parameters ) {
  17472. Material.call( this );
  17473. this.type = 'MeshLambertMaterial';
  17474. this.color = new Color( 0xffffff ); // diffuse
  17475. this.map = null;
  17476. this.lightMap = null;
  17477. this.lightMapIntensity = 1.0;
  17478. this.aoMap = null;
  17479. this.aoMapIntensity = 1.0;
  17480. this.emissive = new Color( 0x000000 );
  17481. this.emissiveIntensity = 1.0;
  17482. this.emissiveMap = null;
  17483. this.specularMap = null;
  17484. this.alphaMap = null;
  17485. this.envMap = null;
  17486. this.combine = MultiplyOperation;
  17487. this.reflectivity = 1;
  17488. this.refractionRatio = 0.98;
  17489. this.wireframe = false;
  17490. this.wireframeLinewidth = 1;
  17491. this.wireframeLinecap = 'round';
  17492. this.wireframeLinejoin = 'round';
  17493. this.skinning = false;
  17494. this.morphTargets = false;
  17495. this.morphNormals = false;
  17496. this.setValues( parameters );
  17497. }
  17498. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  17499. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  17500. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  17501. MeshLambertMaterial.prototype.copy = function ( source ) {
  17502. Material.prototype.copy.call( this, source );
  17503. this.color.copy( source.color );
  17504. this.map = source.map;
  17505. this.lightMap = source.lightMap;
  17506. this.lightMapIntensity = source.lightMapIntensity;
  17507. this.aoMap = source.aoMap;
  17508. this.aoMapIntensity = source.aoMapIntensity;
  17509. this.emissive.copy( source.emissive );
  17510. this.emissiveMap = source.emissiveMap;
  17511. this.emissiveIntensity = source.emissiveIntensity;
  17512. this.specularMap = source.specularMap;
  17513. this.alphaMap = source.alphaMap;
  17514. this.envMap = source.envMap;
  17515. this.combine = source.combine;
  17516. this.reflectivity = source.reflectivity;
  17517. this.refractionRatio = source.refractionRatio;
  17518. this.wireframe = source.wireframe;
  17519. this.wireframeLinewidth = source.wireframeLinewidth;
  17520. this.wireframeLinecap = source.wireframeLinecap;
  17521. this.wireframeLinejoin = source.wireframeLinejoin;
  17522. this.skinning = source.skinning;
  17523. this.morphTargets = source.morphTargets;
  17524. this.morphNormals = source.morphNormals;
  17525. return this;
  17526. };
  17527. /**
  17528. * @author alteredq / http://alteredqualia.com/
  17529. *
  17530. * parameters = {
  17531. * color: <hex>,
  17532. * opacity: <float>,
  17533. *
  17534. * linewidth: <float>,
  17535. *
  17536. * scale: <float>,
  17537. * dashSize: <float>,
  17538. * gapSize: <float>
  17539. * }
  17540. */
  17541. function LineDashedMaterial( parameters ) {
  17542. Material.call( this );
  17543. this.type = 'LineDashedMaterial';
  17544. this.color = new Color( 0xffffff );
  17545. this.linewidth = 1;
  17546. this.scale = 1;
  17547. this.dashSize = 3;
  17548. this.gapSize = 1;
  17549. this.lights = false;
  17550. this.setValues( parameters );
  17551. }
  17552. LineDashedMaterial.prototype = Object.create( Material.prototype );
  17553. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  17554. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  17555. LineDashedMaterial.prototype.copy = function ( source ) {
  17556. Material.prototype.copy.call( this, source );
  17557. this.color.copy( source.color );
  17558. this.linewidth = source.linewidth;
  17559. this.scale = source.scale;
  17560. this.dashSize = source.dashSize;
  17561. this.gapSize = source.gapSize;
  17562. return this;
  17563. };
  17564. var Materials = Object.freeze({
  17565. ShadowMaterial: ShadowMaterial,
  17566. SpriteMaterial: SpriteMaterial,
  17567. RawShaderMaterial: RawShaderMaterial,
  17568. ShaderMaterial: ShaderMaterial,
  17569. PointsMaterial: PointsMaterial,
  17570. MeshPhysicalMaterial: MeshPhysicalMaterial,
  17571. MeshStandardMaterial: MeshStandardMaterial,
  17572. MeshPhongMaterial: MeshPhongMaterial,
  17573. MeshToonMaterial: MeshToonMaterial,
  17574. MeshNormalMaterial: MeshNormalMaterial,
  17575. MeshLambertMaterial: MeshLambertMaterial,
  17576. MeshDepthMaterial: MeshDepthMaterial,
  17577. MeshBasicMaterial: MeshBasicMaterial,
  17578. LineDashedMaterial: LineDashedMaterial,
  17579. LineBasicMaterial: LineBasicMaterial,
  17580. Material: Material
  17581. });
  17582. /**
  17583. * @author mrdoob / http://mrdoob.com/
  17584. */
  17585. var Cache = {
  17586. enabled: false,
  17587. files: {},
  17588. add: function ( key, file ) {
  17589. if ( this.enabled === false ) return;
  17590. // console.log( 'THREE.Cache', 'Adding key:', key );
  17591. this.files[ key ] = file;
  17592. },
  17593. get: function ( key ) {
  17594. if ( this.enabled === false ) return;
  17595. // console.log( 'THREE.Cache', 'Checking key:', key );
  17596. return this.files[ key ];
  17597. },
  17598. remove: function ( key ) {
  17599. delete this.files[ key ];
  17600. },
  17601. clear: function () {
  17602. this.files = {};
  17603. }
  17604. };
  17605. /**
  17606. * @author mrdoob / http://mrdoob.com/
  17607. */
  17608. function LoadingManager( onLoad, onProgress, onError ) {
  17609. var scope = this;
  17610. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  17611. this.onStart = undefined;
  17612. this.onLoad = onLoad;
  17613. this.onProgress = onProgress;
  17614. this.onError = onError;
  17615. this.itemStart = function ( url ) {
  17616. itemsTotal ++;
  17617. if ( isLoading === false ) {
  17618. if ( scope.onStart !== undefined ) {
  17619. scope.onStart( url, itemsLoaded, itemsTotal );
  17620. }
  17621. }
  17622. isLoading = true;
  17623. };
  17624. this.itemEnd = function ( url ) {
  17625. itemsLoaded ++;
  17626. if ( scope.onProgress !== undefined ) {
  17627. scope.onProgress( url, itemsLoaded, itemsTotal );
  17628. }
  17629. if ( itemsLoaded === itemsTotal ) {
  17630. isLoading = false;
  17631. if ( scope.onLoad !== undefined ) {
  17632. scope.onLoad();
  17633. }
  17634. }
  17635. };
  17636. this.itemError = function ( url ) {
  17637. if ( scope.onError !== undefined ) {
  17638. scope.onError( url );
  17639. }
  17640. };
  17641. }
  17642. var DefaultLoadingManager = new LoadingManager();
  17643. /**
  17644. * @author mrdoob / http://mrdoob.com/
  17645. */
  17646. function FileLoader( manager ) {
  17647. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17648. }
  17649. Object.assign( FileLoader.prototype, {
  17650. load: function ( url, onLoad, onProgress, onError ) {
  17651. if ( url === undefined ) url = '';
  17652. if ( this.path !== undefined ) url = this.path + url;
  17653. var scope = this;
  17654. var cached = Cache.get( url );
  17655. if ( cached !== undefined ) {
  17656. scope.manager.itemStart( url );
  17657. setTimeout( function () {
  17658. if ( onLoad ) onLoad( cached );
  17659. scope.manager.itemEnd( url );
  17660. }, 0 );
  17661. return cached;
  17662. }
  17663. // Check for data: URI
  17664. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  17665. var dataUriRegexResult = url.match( dataUriRegex );
  17666. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  17667. if ( dataUriRegexResult ) {
  17668. var mimeType = dataUriRegexResult[ 1 ];
  17669. var isBase64 = !! dataUriRegexResult[ 2 ];
  17670. var data = dataUriRegexResult[ 3 ];
  17671. data = window.decodeURIComponent( data );
  17672. if ( isBase64 ) data = window.atob( data );
  17673. try {
  17674. var response;
  17675. var responseType = ( this.responseType || '' ).toLowerCase();
  17676. switch ( responseType ) {
  17677. case 'arraybuffer':
  17678. case 'blob':
  17679. response = new ArrayBuffer( data.length );
  17680. var view = new Uint8Array( response );
  17681. for ( var i = 0; i < data.length; i ++ ) {
  17682. view[ i ] = data.charCodeAt( i );
  17683. }
  17684. if ( responseType === 'blob' ) {
  17685. response = new Blob( [ response ], { type: mimeType } );
  17686. }
  17687. break;
  17688. case 'document':
  17689. var parser = new DOMParser();
  17690. response = parser.parseFromString( data, mimeType );
  17691. break;
  17692. case 'json':
  17693. response = JSON.parse( data );
  17694. break;
  17695. default: // 'text' or other
  17696. response = data;
  17697. break;
  17698. }
  17699. // Wait for next browser tick
  17700. window.setTimeout( function () {
  17701. if ( onLoad ) onLoad( response );
  17702. scope.manager.itemEnd( url );
  17703. }, 0 );
  17704. } catch ( error ) {
  17705. // Wait for next browser tick
  17706. window.setTimeout( function () {
  17707. if ( onError ) onError( error );
  17708. scope.manager.itemEnd( url );
  17709. scope.manager.itemError( url );
  17710. }, 0 );
  17711. }
  17712. } else {
  17713. var request = new XMLHttpRequest();
  17714. request.open( 'GET', url, true );
  17715. request.addEventListener( 'load', function ( event ) {
  17716. var response = event.target.response;
  17717. Cache.add( url, response );
  17718. if ( this.status === 200 ) {
  17719. if ( onLoad ) onLoad( response );
  17720. scope.manager.itemEnd( url );
  17721. } else if ( this.status === 0 ) {
  17722. // Some browsers return HTTP Status 0 when using non-http protocol
  17723. // e.g. 'file://' or 'data://'. Handle as success.
  17724. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  17725. if ( onLoad ) onLoad( response );
  17726. scope.manager.itemEnd( url );
  17727. } else {
  17728. if ( onError ) onError( event );
  17729. scope.manager.itemEnd( url );
  17730. scope.manager.itemError( url );
  17731. }
  17732. }, false );
  17733. if ( onProgress !== undefined ) {
  17734. request.addEventListener( 'progress', function ( event ) {
  17735. onProgress( event );
  17736. }, false );
  17737. }
  17738. request.addEventListener( 'error', function ( event ) {
  17739. if ( onError ) onError( event );
  17740. scope.manager.itemEnd( url );
  17741. scope.manager.itemError( url );
  17742. }, false );
  17743. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  17744. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  17745. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  17746. for ( var header in this.requestHeader ) {
  17747. request.setRequestHeader( header, this.requestHeader[ header ] );
  17748. }
  17749. request.send( null );
  17750. }
  17751. scope.manager.itemStart( url );
  17752. return request;
  17753. },
  17754. setPath: function ( value ) {
  17755. this.path = value;
  17756. return this;
  17757. },
  17758. setResponseType: function ( value ) {
  17759. this.responseType = value;
  17760. return this;
  17761. },
  17762. setWithCredentials: function ( value ) {
  17763. this.withCredentials = value;
  17764. return this;
  17765. },
  17766. setMimeType: function ( value ) {
  17767. this.mimeType = value;
  17768. return this;
  17769. },
  17770. setRequestHeader: function ( value ) {
  17771. this.requestHeader = value;
  17772. return this;
  17773. }
  17774. } );
  17775. /**
  17776. * @author mrdoob / http://mrdoob.com/
  17777. *
  17778. * Abstract Base class to block based textures loader (dds, pvr, ...)
  17779. */
  17780. function CompressedTextureLoader( manager ) {
  17781. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17782. // override in sub classes
  17783. this._parser = null;
  17784. }
  17785. Object.assign( CompressedTextureLoader.prototype, {
  17786. load: function ( url, onLoad, onProgress, onError ) {
  17787. var scope = this;
  17788. var images = [];
  17789. var texture = new CompressedTexture();
  17790. texture.image = images;
  17791. var loader = new FileLoader( this.manager );
  17792. loader.setPath( this.path );
  17793. loader.setResponseType( 'arraybuffer' );
  17794. function loadTexture( i ) {
  17795. loader.load( url[ i ], function ( buffer ) {
  17796. var texDatas = scope._parser( buffer, true );
  17797. images[ i ] = {
  17798. width: texDatas.width,
  17799. height: texDatas.height,
  17800. format: texDatas.format,
  17801. mipmaps: texDatas.mipmaps
  17802. };
  17803. loaded += 1;
  17804. if ( loaded === 6 ) {
  17805. if ( texDatas.mipmapCount === 1 )
  17806. texture.minFilter = LinearFilter;
  17807. texture.format = texDatas.format;
  17808. texture.needsUpdate = true;
  17809. if ( onLoad ) onLoad( texture );
  17810. }
  17811. }, onProgress, onError );
  17812. }
  17813. if ( Array.isArray( url ) ) {
  17814. var loaded = 0;
  17815. for ( var i = 0, il = url.length; i < il; ++ i ) {
  17816. loadTexture( i );
  17817. }
  17818. } else {
  17819. // compressed cubemap texture stored in a single DDS file
  17820. loader.load( url, function ( buffer ) {
  17821. var texDatas = scope._parser( buffer, true );
  17822. if ( texDatas.isCubemap ) {
  17823. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  17824. for ( var f = 0; f < faces; f ++ ) {
  17825. images[ f ] = { mipmaps : [] };
  17826. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  17827. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  17828. images[ f ].format = texDatas.format;
  17829. images[ f ].width = texDatas.width;
  17830. images[ f ].height = texDatas.height;
  17831. }
  17832. }
  17833. } else {
  17834. texture.image.width = texDatas.width;
  17835. texture.image.height = texDatas.height;
  17836. texture.mipmaps = texDatas.mipmaps;
  17837. }
  17838. if ( texDatas.mipmapCount === 1 ) {
  17839. texture.minFilter = LinearFilter;
  17840. }
  17841. texture.format = texDatas.format;
  17842. texture.needsUpdate = true;
  17843. if ( onLoad ) onLoad( texture );
  17844. }, onProgress, onError );
  17845. }
  17846. return texture;
  17847. },
  17848. setPath: function ( value ) {
  17849. this.path = value;
  17850. return this;
  17851. }
  17852. } );
  17853. /**
  17854. * @author Nikos M. / https://github.com/foo123/
  17855. *
  17856. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  17857. */
  17858. function DataTextureLoader( manager ) {
  17859. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17860. // override in sub classes
  17861. this._parser = null;
  17862. }
  17863. Object.assign( DataTextureLoader.prototype, {
  17864. load: function ( url, onLoad, onProgress, onError ) {
  17865. var scope = this;
  17866. var texture = new DataTexture();
  17867. var loader = new FileLoader( this.manager );
  17868. loader.setResponseType( 'arraybuffer' );
  17869. loader.load( url, function ( buffer ) {
  17870. var texData = scope._parser( buffer );
  17871. if ( ! texData ) return;
  17872. if ( undefined !== texData.image ) {
  17873. texture.image = texData.image;
  17874. } else if ( undefined !== texData.data ) {
  17875. texture.image.width = texData.width;
  17876. texture.image.height = texData.height;
  17877. texture.image.data = texData.data;
  17878. }
  17879. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  17880. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  17881. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  17882. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  17883. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  17884. if ( undefined !== texData.format ) {
  17885. texture.format = texData.format;
  17886. }
  17887. if ( undefined !== texData.type ) {
  17888. texture.type = texData.type;
  17889. }
  17890. if ( undefined !== texData.mipmaps ) {
  17891. texture.mipmaps = texData.mipmaps;
  17892. }
  17893. if ( 1 === texData.mipmapCount ) {
  17894. texture.minFilter = LinearFilter;
  17895. }
  17896. texture.needsUpdate = true;
  17897. if ( onLoad ) onLoad( texture, texData );
  17898. }, onProgress, onError );
  17899. return texture;
  17900. }
  17901. } );
  17902. /**
  17903. * @author mrdoob / http://mrdoob.com/
  17904. */
  17905. function ImageLoader( manager ) {
  17906. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17907. }
  17908. Object.assign( ImageLoader.prototype, {
  17909. load: function ( url, onLoad, onProgress, onError ) {
  17910. if ( url === undefined ) url = '';
  17911. if ( this.path !== undefined ) url = this.path + url;
  17912. var scope = this;
  17913. var cached = Cache.get( url );
  17914. if ( cached !== undefined ) {
  17915. scope.manager.itemStart( url );
  17916. setTimeout( function () {
  17917. if ( onLoad ) onLoad( cached );
  17918. scope.manager.itemEnd( url );
  17919. }, 0 );
  17920. return cached;
  17921. }
  17922. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  17923. image.addEventListener( 'load', function () {
  17924. Cache.add( url, this );
  17925. if ( onLoad ) onLoad( this );
  17926. scope.manager.itemEnd( url );
  17927. }, false );
  17928. /*
  17929. image.addEventListener( 'progress', function ( event ) {
  17930. if ( onProgress ) onProgress( event );
  17931. }, false );
  17932. */
  17933. image.addEventListener( 'error', function ( event ) {
  17934. if ( onError ) onError( event );
  17935. scope.manager.itemEnd( url );
  17936. scope.manager.itemError( url );
  17937. }, false );
  17938. if ( url.substr( 0, 5 ) !== 'data:' ) {
  17939. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  17940. }
  17941. scope.manager.itemStart( url );
  17942. image.src = url;
  17943. return image;
  17944. },
  17945. setCrossOrigin: function ( value ) {
  17946. this.crossOrigin = value;
  17947. return this;
  17948. },
  17949. setPath: function ( value ) {
  17950. this.path = value;
  17951. return this;
  17952. }
  17953. } );
  17954. /**
  17955. * @author mrdoob / http://mrdoob.com/
  17956. */
  17957. function CubeTextureLoader( manager ) {
  17958. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17959. }
  17960. Object.assign( CubeTextureLoader.prototype, {
  17961. load: function ( urls, onLoad, onProgress, onError ) {
  17962. var texture = new CubeTexture();
  17963. var loader = new ImageLoader( this.manager );
  17964. loader.setCrossOrigin( this.crossOrigin );
  17965. loader.setPath( this.path );
  17966. var loaded = 0;
  17967. function loadTexture( i ) {
  17968. loader.load( urls[ i ], function ( image ) {
  17969. texture.images[ i ] = image;
  17970. loaded ++;
  17971. if ( loaded === 6 ) {
  17972. texture.needsUpdate = true;
  17973. if ( onLoad ) onLoad( texture );
  17974. }
  17975. }, undefined, onError );
  17976. }
  17977. for ( var i = 0; i < urls.length; ++ i ) {
  17978. loadTexture( i );
  17979. }
  17980. return texture;
  17981. },
  17982. setCrossOrigin: function ( value ) {
  17983. this.crossOrigin = value;
  17984. return this;
  17985. },
  17986. setPath: function ( value ) {
  17987. this.path = value;
  17988. return this;
  17989. }
  17990. } );
  17991. /**
  17992. * @author mrdoob / http://mrdoob.com/
  17993. */
  17994. function TextureLoader( manager ) {
  17995. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  17996. }
  17997. Object.assign( TextureLoader.prototype, {
  17998. load: function ( url, onLoad, onProgress, onError ) {
  17999. var loader = new ImageLoader( this.manager );
  18000. loader.setCrossOrigin( this.crossOrigin );
  18001. loader.setPath( this.path );
  18002. var texture = new Texture();
  18003. texture.image = loader.load( url, function () {
  18004. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  18005. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  18006. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  18007. texture.needsUpdate = true;
  18008. if ( onLoad !== undefined ) {
  18009. onLoad( texture );
  18010. }
  18011. }, onProgress, onError );
  18012. return texture;
  18013. },
  18014. setCrossOrigin: function ( value ) {
  18015. this.crossOrigin = value;
  18016. return this;
  18017. },
  18018. setPath: function ( value ) {
  18019. this.path = value;
  18020. return this;
  18021. }
  18022. } );
  18023. /**
  18024. * @author mrdoob / http://mrdoob.com/
  18025. * @author alteredq / http://alteredqualia.com/
  18026. */
  18027. function Light( color, intensity ) {
  18028. Object3D.call( this );
  18029. this.type = 'Light';
  18030. this.color = new Color( color );
  18031. this.intensity = intensity !== undefined ? intensity : 1;
  18032. this.receiveShadow = undefined;
  18033. }
  18034. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  18035. constructor: Light,
  18036. isLight: true,
  18037. copy: function ( source ) {
  18038. Object3D.prototype.copy.call( this, source );
  18039. this.color.copy( source.color );
  18040. this.intensity = source.intensity;
  18041. return this;
  18042. },
  18043. toJSON: function ( meta ) {
  18044. var data = Object3D.prototype.toJSON.call( this, meta );
  18045. data.object.color = this.color.getHex();
  18046. data.object.intensity = this.intensity;
  18047. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  18048. if ( this.distance !== undefined ) data.object.distance = this.distance;
  18049. if ( this.angle !== undefined ) data.object.angle = this.angle;
  18050. if ( this.decay !== undefined ) data.object.decay = this.decay;
  18051. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  18052. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  18053. return data;
  18054. }
  18055. } );
  18056. /**
  18057. * @author alteredq / http://alteredqualia.com/
  18058. */
  18059. function HemisphereLight( skyColor, groundColor, intensity ) {
  18060. Light.call( this, skyColor, intensity );
  18061. this.type = 'HemisphereLight';
  18062. this.castShadow = undefined;
  18063. this.position.copy( Object3D.DefaultUp );
  18064. this.updateMatrix();
  18065. this.groundColor = new Color( groundColor );
  18066. }
  18067. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18068. constructor: HemisphereLight,
  18069. isHemisphereLight: true,
  18070. copy: function ( source ) {
  18071. Light.prototype.copy.call( this, source );
  18072. this.groundColor.copy( source.groundColor );
  18073. return this;
  18074. }
  18075. } );
  18076. /**
  18077. * @author mrdoob / http://mrdoob.com/
  18078. */
  18079. function LightShadow( camera ) {
  18080. this.camera = camera;
  18081. this.bias = 0;
  18082. this.radius = 1;
  18083. this.mapSize = new Vector2( 512, 512 );
  18084. this.map = null;
  18085. this.matrix = new Matrix4();
  18086. }
  18087. Object.assign( LightShadow.prototype, {
  18088. copy: function ( source ) {
  18089. this.camera = source.camera.clone();
  18090. this.bias = source.bias;
  18091. this.radius = source.radius;
  18092. this.mapSize.copy( source.mapSize );
  18093. return this;
  18094. },
  18095. clone: function () {
  18096. return new this.constructor().copy( this );
  18097. },
  18098. toJSON: function () {
  18099. var object = {};
  18100. if ( this.bias !== 0 ) object.bias = this.bias;
  18101. if ( this.radius !== 1 ) object.radius = this.radius;
  18102. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  18103. object.camera = this.camera.toJSON( false ).object;
  18104. delete object.camera.matrix;
  18105. return object;
  18106. }
  18107. } );
  18108. /**
  18109. * @author mrdoob / http://mrdoob.com/
  18110. */
  18111. function SpotLightShadow() {
  18112. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  18113. }
  18114. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  18115. constructor: SpotLightShadow,
  18116. isSpotLightShadow: true,
  18117. update: function ( light ) {
  18118. var camera = this.camera;
  18119. var fov = _Math.RAD2DEG * 2 * light.angle;
  18120. var aspect = this.mapSize.width / this.mapSize.height;
  18121. var far = light.distance || camera.far;
  18122. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  18123. camera.fov = fov;
  18124. camera.aspect = aspect;
  18125. camera.far = far;
  18126. camera.updateProjectionMatrix();
  18127. }
  18128. }
  18129. } );
  18130. /**
  18131. * @author alteredq / http://alteredqualia.com/
  18132. */
  18133. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  18134. Light.call( this, color, intensity );
  18135. this.type = 'SpotLight';
  18136. this.position.copy( Object3D.DefaultUp );
  18137. this.updateMatrix();
  18138. this.target = new Object3D();
  18139. Object.defineProperty( this, 'power', {
  18140. get: function () {
  18141. // intensity = power per solid angle.
  18142. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18143. return this.intensity * Math.PI;
  18144. },
  18145. set: function ( power ) {
  18146. // intensity = power per solid angle.
  18147. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18148. this.intensity = power / Math.PI;
  18149. }
  18150. } );
  18151. this.distance = ( distance !== undefined ) ? distance : 0;
  18152. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  18153. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  18154. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  18155. this.shadow = new SpotLightShadow();
  18156. }
  18157. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18158. constructor: SpotLight,
  18159. isSpotLight: true,
  18160. copy: function ( source ) {
  18161. Light.prototype.copy.call( this, source );
  18162. this.distance = source.distance;
  18163. this.angle = source.angle;
  18164. this.penumbra = source.penumbra;
  18165. this.decay = source.decay;
  18166. this.target = source.target.clone();
  18167. this.shadow = source.shadow.clone();
  18168. return this;
  18169. }
  18170. } );
  18171. /**
  18172. * @author mrdoob / http://mrdoob.com/
  18173. */
  18174. function PointLight( color, intensity, distance, decay ) {
  18175. Light.call( this, color, intensity );
  18176. this.type = 'PointLight';
  18177. Object.defineProperty( this, 'power', {
  18178. get: function () {
  18179. // intensity = power per solid angle.
  18180. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18181. return this.intensity * 4 * Math.PI;
  18182. },
  18183. set: function ( power ) {
  18184. // intensity = power per solid angle.
  18185. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  18186. this.intensity = power / ( 4 * Math.PI );
  18187. }
  18188. } );
  18189. this.distance = ( distance !== undefined ) ? distance : 0;
  18190. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  18191. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  18192. }
  18193. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18194. constructor: PointLight,
  18195. isPointLight: true,
  18196. copy: function ( source ) {
  18197. Light.prototype.copy.call( this, source );
  18198. this.distance = source.distance;
  18199. this.decay = source.decay;
  18200. this.shadow = source.shadow.clone();
  18201. return this;
  18202. }
  18203. } );
  18204. /**
  18205. * @author mrdoob / http://mrdoob.com/
  18206. */
  18207. function DirectionalLightShadow( ) {
  18208. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  18209. }
  18210. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  18211. constructor: DirectionalLightShadow
  18212. } );
  18213. /**
  18214. * @author mrdoob / http://mrdoob.com/
  18215. * @author alteredq / http://alteredqualia.com/
  18216. */
  18217. function DirectionalLight( color, intensity ) {
  18218. Light.call( this, color, intensity );
  18219. this.type = 'DirectionalLight';
  18220. this.position.copy( Object3D.DefaultUp );
  18221. this.updateMatrix();
  18222. this.target = new Object3D();
  18223. this.shadow = new DirectionalLightShadow();
  18224. }
  18225. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18226. constructor: DirectionalLight,
  18227. isDirectionalLight: true,
  18228. copy: function ( source ) {
  18229. Light.prototype.copy.call( this, source );
  18230. this.target = source.target.clone();
  18231. this.shadow = source.shadow.clone();
  18232. return this;
  18233. }
  18234. } );
  18235. /**
  18236. * @author mrdoob / http://mrdoob.com/
  18237. */
  18238. function AmbientLight( color, intensity ) {
  18239. Light.call( this, color, intensity );
  18240. this.type = 'AmbientLight';
  18241. this.castShadow = undefined;
  18242. }
  18243. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18244. constructor: AmbientLight,
  18245. isAmbientLight: true
  18246. } );
  18247. /**
  18248. * @author abelnation / http://github.com/abelnation
  18249. */
  18250. function RectAreaLight( color, intensity, width, height ) {
  18251. Light.call( this, color, intensity );
  18252. this.type = 'RectAreaLight';
  18253. this.position.set( 0, 1, 0 );
  18254. this.updateMatrix();
  18255. this.width = ( width !== undefined ) ? width : 10;
  18256. this.height = ( height !== undefined ) ? height : 10;
  18257. // TODO (abelnation): distance/decay
  18258. // TODO (abelnation): update method for RectAreaLight to update transform to lookat target
  18259. // TODO (abelnation): shadows
  18260. }
  18261. // TODO (abelnation): RectAreaLight update when light shape is changed
  18262. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  18263. constructor: RectAreaLight,
  18264. isRectAreaLight: true,
  18265. copy: function ( source ) {
  18266. Light.prototype.copy.call( this, source );
  18267. this.width = source.width;
  18268. this.height = source.height;
  18269. return this;
  18270. },
  18271. toJSON: function ( meta ) {
  18272. var data = Light.prototype.toJSON.call( this, meta );
  18273. data.object.width = this.width;
  18274. data.object.height = this.height;
  18275. return data;
  18276. }
  18277. } );
  18278. /**
  18279. * @author tschw
  18280. * @author Ben Houston / http://clara.io/
  18281. * @author David Sarno / http://lighthaus.us/
  18282. */
  18283. var AnimationUtils = {
  18284. // same as Array.prototype.slice, but also works on typed arrays
  18285. arraySlice: function ( array, from, to ) {
  18286. if ( AnimationUtils.isTypedArray( array ) ) {
  18287. // in ios9 array.subarray(from, undefined) will return empty array
  18288. // but array.subarray(from) or array.subarray(from, len) is correct
  18289. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  18290. }
  18291. return array.slice( from, to );
  18292. },
  18293. // converts an array to a specific type
  18294. convertArray: function ( array, type, forceClone ) {
  18295. if ( ! array || // let 'undefined' and 'null' pass
  18296. ! forceClone && array.constructor === type ) return array;
  18297. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  18298. return new type( array ); // create typed array
  18299. }
  18300. return Array.prototype.slice.call( array ); // create Array
  18301. },
  18302. isTypedArray: function ( object ) {
  18303. return ArrayBuffer.isView( object ) &&
  18304. ! ( object instanceof DataView );
  18305. },
  18306. // returns an array by which times and values can be sorted
  18307. getKeyframeOrder: function ( times ) {
  18308. function compareTime( i, j ) {
  18309. return times[ i ] - times[ j ];
  18310. }
  18311. var n = times.length;
  18312. var result = new Array( n );
  18313. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  18314. result.sort( compareTime );
  18315. return result;
  18316. },
  18317. // uses the array previously returned by 'getKeyframeOrder' to sort data
  18318. sortedArray: function ( values, stride, order ) {
  18319. var nValues = values.length;
  18320. var result = new values.constructor( nValues );
  18321. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  18322. var srcOffset = order[ i ] * stride;
  18323. for ( var j = 0; j !== stride; ++ j ) {
  18324. result[ dstOffset ++ ] = values[ srcOffset + j ];
  18325. }
  18326. }
  18327. return result;
  18328. },
  18329. // function for parsing AOS keyframe formats
  18330. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  18331. var i = 1, key = jsonKeys[ 0 ];
  18332. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  18333. key = jsonKeys[ i ++ ];
  18334. }
  18335. if ( key === undefined ) return; // no data
  18336. var value = key[ valuePropertyName ];
  18337. if ( value === undefined ) return; // no data
  18338. if ( Array.isArray( value ) ) {
  18339. do {
  18340. value = key[ valuePropertyName ];
  18341. if ( value !== undefined ) {
  18342. times.push( key.time );
  18343. values.push.apply( values, value ); // push all elements
  18344. }
  18345. key = jsonKeys[ i ++ ];
  18346. } while ( key !== undefined );
  18347. } else if ( value.toArray !== undefined ) {
  18348. // ...assume THREE.Math-ish
  18349. do {
  18350. value = key[ valuePropertyName ];
  18351. if ( value !== undefined ) {
  18352. times.push( key.time );
  18353. value.toArray( values, values.length );
  18354. }
  18355. key = jsonKeys[ i ++ ];
  18356. } while ( key !== undefined );
  18357. } else {
  18358. // otherwise push as-is
  18359. do {
  18360. value = key[ valuePropertyName ];
  18361. if ( value !== undefined ) {
  18362. times.push( key.time );
  18363. values.push( value );
  18364. }
  18365. key = jsonKeys[ i ++ ];
  18366. } while ( key !== undefined );
  18367. }
  18368. }
  18369. };
  18370. /**
  18371. * Abstract base class of interpolants over parametric samples.
  18372. *
  18373. * The parameter domain is one dimensional, typically the time or a path
  18374. * along a curve defined by the data.
  18375. *
  18376. * The sample values can have any dimensionality and derived classes may
  18377. * apply special interpretations to the data.
  18378. *
  18379. * This class provides the interval seek in a Template Method, deferring
  18380. * the actual interpolation to derived classes.
  18381. *
  18382. * Time complexity is O(1) for linear access crossing at most two points
  18383. * and O(log N) for random access, where N is the number of positions.
  18384. *
  18385. * References:
  18386. *
  18387. * http://www.oodesign.com/template-method-pattern.html
  18388. *
  18389. * @author tschw
  18390. */
  18391. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18392. this.parameterPositions = parameterPositions;
  18393. this._cachedIndex = 0;
  18394. this.resultBuffer = resultBuffer !== undefined ?
  18395. resultBuffer : new sampleValues.constructor( sampleSize );
  18396. this.sampleValues = sampleValues;
  18397. this.valueSize = sampleSize;
  18398. }
  18399. Object.assign( Interpolant.prototype, {
  18400. evaluate: function( t ) {
  18401. var pp = this.parameterPositions,
  18402. i1 = this._cachedIndex,
  18403. t1 = pp[ i1 ],
  18404. t0 = pp[ i1 - 1 ];
  18405. validate_interval: {
  18406. seek: {
  18407. var right;
  18408. linear_scan: {
  18409. //- See http://jsperf.com/comparison-to-undefined/3
  18410. //- slower code:
  18411. //-
  18412. //- if ( t >= t1 || t1 === undefined ) {
  18413. forward_scan: if ( ! ( t < t1 ) ) {
  18414. for ( var giveUpAt = i1 + 2; ;) {
  18415. if ( t1 === undefined ) {
  18416. if ( t < t0 ) break forward_scan;
  18417. // after end
  18418. i1 = pp.length;
  18419. this._cachedIndex = i1;
  18420. return this.afterEnd_( i1 - 1, t, t0 );
  18421. }
  18422. if ( i1 === giveUpAt ) break; // this loop
  18423. t0 = t1;
  18424. t1 = pp[ ++ i1 ];
  18425. if ( t < t1 ) {
  18426. // we have arrived at the sought interval
  18427. break seek;
  18428. }
  18429. }
  18430. // prepare binary search on the right side of the index
  18431. right = pp.length;
  18432. break linear_scan;
  18433. }
  18434. //- slower code:
  18435. //- if ( t < t0 || t0 === undefined ) {
  18436. if ( ! ( t >= t0 ) ) {
  18437. // looping?
  18438. var t1global = pp[ 1 ];
  18439. if ( t < t1global ) {
  18440. i1 = 2; // + 1, using the scan for the details
  18441. t0 = t1global;
  18442. }
  18443. // linear reverse scan
  18444. for ( var giveUpAt = i1 - 2; ;) {
  18445. if ( t0 === undefined ) {
  18446. // before start
  18447. this._cachedIndex = 0;
  18448. return this.beforeStart_( 0, t, t1 );
  18449. }
  18450. if ( i1 === giveUpAt ) break; // this loop
  18451. t1 = t0;
  18452. t0 = pp[ -- i1 - 1 ];
  18453. if ( t >= t0 ) {
  18454. // we have arrived at the sought interval
  18455. break seek;
  18456. }
  18457. }
  18458. // prepare binary search on the left side of the index
  18459. right = i1;
  18460. i1 = 0;
  18461. break linear_scan;
  18462. }
  18463. // the interval is valid
  18464. break validate_interval;
  18465. } // linear scan
  18466. // binary search
  18467. while ( i1 < right ) {
  18468. var mid = ( i1 + right ) >>> 1;
  18469. if ( t < pp[ mid ] ) {
  18470. right = mid;
  18471. } else {
  18472. i1 = mid + 1;
  18473. }
  18474. }
  18475. t1 = pp[ i1 ];
  18476. t0 = pp[ i1 - 1 ];
  18477. // check boundary cases, again
  18478. if ( t0 === undefined ) {
  18479. this._cachedIndex = 0;
  18480. return this.beforeStart_( 0, t, t1 );
  18481. }
  18482. if ( t1 === undefined ) {
  18483. i1 = pp.length;
  18484. this._cachedIndex = i1;
  18485. return this.afterEnd_( i1 - 1, t0, t );
  18486. }
  18487. } // seek
  18488. this._cachedIndex = i1;
  18489. this.intervalChanged_( i1, t0, t1 );
  18490. } // validate_interval
  18491. return this.interpolate_( i1, t0, t, t1 );
  18492. },
  18493. settings: null, // optional, subclass-specific settings structure
  18494. // Note: The indirection allows central control of many interpolants.
  18495. // --- Protected interface
  18496. DefaultSettings_: {},
  18497. getSettings_: function() {
  18498. return this.settings || this.DefaultSettings_;
  18499. },
  18500. copySampleValue_: function( index ) {
  18501. // copies a sample value to the result buffer
  18502. var result = this.resultBuffer,
  18503. values = this.sampleValues,
  18504. stride = this.valueSize,
  18505. offset = index * stride;
  18506. for ( var i = 0; i !== stride; ++ i ) {
  18507. result[ i ] = values[ offset + i ];
  18508. }
  18509. return result;
  18510. },
  18511. // Template methods for derived classes:
  18512. interpolate_: function( i1, t0, t, t1 ) {
  18513. throw new Error( "call to abstract method" );
  18514. // implementations shall return this.resultBuffer
  18515. },
  18516. intervalChanged_: function( i1, t0, t1 ) {
  18517. // empty
  18518. }
  18519. } );
  18520. //!\ DECLARE ALIAS AFTER assign prototype !
  18521. Object.assign( Interpolant.prototype, {
  18522. //( 0, t, t0 ), returns this.resultBuffer
  18523. beforeStart_: Interpolant.prototype.copySampleValue_,
  18524. //( N-1, tN-1, t ), returns this.resultBuffer
  18525. afterEnd_: Interpolant.prototype.copySampleValue_,
  18526. } );
  18527. /**
  18528. * Fast and simple cubic spline interpolant.
  18529. *
  18530. * It was derived from a Hermitian construction setting the first derivative
  18531. * at each sample position to the linear slope between neighboring positions
  18532. * over their parameter interval.
  18533. *
  18534. * @author tschw
  18535. */
  18536. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18537. Interpolant.call(
  18538. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18539. this._weightPrev = -0;
  18540. this._offsetPrev = -0;
  18541. this._weightNext = -0;
  18542. this._offsetNext = -0;
  18543. }
  18544. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18545. constructor: CubicInterpolant,
  18546. DefaultSettings_: {
  18547. endingStart: ZeroCurvatureEnding,
  18548. endingEnd: ZeroCurvatureEnding
  18549. },
  18550. intervalChanged_: function( i1, t0, t1 ) {
  18551. var pp = this.parameterPositions,
  18552. iPrev = i1 - 2,
  18553. iNext = i1 + 1,
  18554. tPrev = pp[ iPrev ],
  18555. tNext = pp[ iNext ];
  18556. if ( tPrev === undefined ) {
  18557. switch ( this.getSettings_().endingStart ) {
  18558. case ZeroSlopeEnding:
  18559. // f'(t0) = 0
  18560. iPrev = i1;
  18561. tPrev = 2 * t0 - t1;
  18562. break;
  18563. case WrapAroundEnding:
  18564. // use the other end of the curve
  18565. iPrev = pp.length - 2;
  18566. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  18567. break;
  18568. default: // ZeroCurvatureEnding
  18569. // f''(t0) = 0 a.k.a. Natural Spline
  18570. iPrev = i1;
  18571. tPrev = t1;
  18572. }
  18573. }
  18574. if ( tNext === undefined ) {
  18575. switch ( this.getSettings_().endingEnd ) {
  18576. case ZeroSlopeEnding:
  18577. // f'(tN) = 0
  18578. iNext = i1;
  18579. tNext = 2 * t1 - t0;
  18580. break;
  18581. case WrapAroundEnding:
  18582. // use the other end of the curve
  18583. iNext = 1;
  18584. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  18585. break;
  18586. default: // ZeroCurvatureEnding
  18587. // f''(tN) = 0, a.k.a. Natural Spline
  18588. iNext = i1 - 1;
  18589. tNext = t0;
  18590. }
  18591. }
  18592. var halfDt = ( t1 - t0 ) * 0.5,
  18593. stride = this.valueSize;
  18594. this._weightPrev = halfDt / ( t0 - tPrev );
  18595. this._weightNext = halfDt / ( tNext - t1 );
  18596. this._offsetPrev = iPrev * stride;
  18597. this._offsetNext = iNext * stride;
  18598. },
  18599. interpolate_: function( i1, t0, t, t1 ) {
  18600. var result = this.resultBuffer,
  18601. values = this.sampleValues,
  18602. stride = this.valueSize,
  18603. o1 = i1 * stride, o0 = o1 - stride,
  18604. oP = this._offsetPrev, oN = this._offsetNext,
  18605. wP = this._weightPrev, wN = this._weightNext,
  18606. p = ( t - t0 ) / ( t1 - t0 ),
  18607. pp = p * p,
  18608. ppp = pp * p;
  18609. // evaluate polynomials
  18610. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  18611. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  18612. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  18613. var sN = wN * ppp - wN * pp;
  18614. // combine data linearly
  18615. for ( var i = 0; i !== stride; ++ i ) {
  18616. result[ i ] =
  18617. sP * values[ oP + i ] +
  18618. s0 * values[ o0 + i ] +
  18619. s1 * values[ o1 + i ] +
  18620. sN * values[ oN + i ];
  18621. }
  18622. return result;
  18623. }
  18624. } );
  18625. /**
  18626. * @author tschw
  18627. */
  18628. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18629. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18630. }
  18631. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18632. constructor: LinearInterpolant,
  18633. interpolate_: function( i1, t0, t, t1 ) {
  18634. var result = this.resultBuffer,
  18635. values = this.sampleValues,
  18636. stride = this.valueSize,
  18637. offset1 = i1 * stride,
  18638. offset0 = offset1 - stride,
  18639. weight1 = ( t - t0 ) / ( t1 - t0 ),
  18640. weight0 = 1 - weight1;
  18641. for ( var i = 0; i !== stride; ++ i ) {
  18642. result[ i ] =
  18643. values[ offset0 + i ] * weight0 +
  18644. values[ offset1 + i ] * weight1;
  18645. }
  18646. return result;
  18647. }
  18648. } );
  18649. /**
  18650. *
  18651. * Interpolant that evaluates to the sample value at the position preceeding
  18652. * the parameter.
  18653. *
  18654. * @author tschw
  18655. */
  18656. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18657. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18658. }
  18659. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18660. constructor: DiscreteInterpolant,
  18661. interpolate_: function( i1, t0, t, t1 ) {
  18662. return this.copySampleValue_( i1 - 1 );
  18663. }
  18664. } );
  18665. var KeyframeTrackPrototype;
  18666. KeyframeTrackPrototype = {
  18667. TimeBufferType: Float32Array,
  18668. ValueBufferType: Float32Array,
  18669. DefaultInterpolation: InterpolateLinear,
  18670. InterpolantFactoryMethodDiscrete: function ( result ) {
  18671. return new DiscreteInterpolant(
  18672. this.times, this.values, this.getValueSize(), result );
  18673. },
  18674. InterpolantFactoryMethodLinear: function ( result ) {
  18675. return new LinearInterpolant(
  18676. this.times, this.values, this.getValueSize(), result );
  18677. },
  18678. InterpolantFactoryMethodSmooth: function ( result ) {
  18679. return new CubicInterpolant(
  18680. this.times, this.values, this.getValueSize(), result );
  18681. },
  18682. setInterpolation: function ( interpolation ) {
  18683. var factoryMethod;
  18684. switch ( interpolation ) {
  18685. case InterpolateDiscrete:
  18686. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  18687. break;
  18688. case InterpolateLinear:
  18689. factoryMethod = this.InterpolantFactoryMethodLinear;
  18690. break;
  18691. case InterpolateSmooth:
  18692. factoryMethod = this.InterpolantFactoryMethodSmooth;
  18693. break;
  18694. }
  18695. if ( factoryMethod === undefined ) {
  18696. var message = "unsupported interpolation for " +
  18697. this.ValueTypeName + " keyframe track named " + this.name;
  18698. if ( this.createInterpolant === undefined ) {
  18699. // fall back to default, unless the default itself is messed up
  18700. if ( interpolation !== this.DefaultInterpolation ) {
  18701. this.setInterpolation( this.DefaultInterpolation );
  18702. } else {
  18703. throw new Error( message ); // fatal, in this case
  18704. }
  18705. }
  18706. console.warn( message );
  18707. return;
  18708. }
  18709. this.createInterpolant = factoryMethod;
  18710. },
  18711. getInterpolation: function () {
  18712. switch ( this.createInterpolant ) {
  18713. case this.InterpolantFactoryMethodDiscrete:
  18714. return InterpolateDiscrete;
  18715. case this.InterpolantFactoryMethodLinear:
  18716. return InterpolateLinear;
  18717. case this.InterpolantFactoryMethodSmooth:
  18718. return InterpolateSmooth;
  18719. }
  18720. },
  18721. getValueSize: function () {
  18722. return this.values.length / this.times.length;
  18723. },
  18724. // move all keyframes either forwards or backwards in time
  18725. shift: function ( timeOffset ) {
  18726. if ( timeOffset !== 0.0 ) {
  18727. var times = this.times;
  18728. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  18729. times[ i ] += timeOffset;
  18730. }
  18731. }
  18732. return this;
  18733. },
  18734. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  18735. scale: function ( timeScale ) {
  18736. if ( timeScale !== 1.0 ) {
  18737. var times = this.times;
  18738. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  18739. times[ i ] *= timeScale;
  18740. }
  18741. }
  18742. return this;
  18743. },
  18744. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  18745. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  18746. trim: function ( startTime, endTime ) {
  18747. var times = this.times,
  18748. nKeys = times.length,
  18749. from = 0,
  18750. to = nKeys - 1;
  18751. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  18752. while ( to !== - 1 && times[ to ] > endTime ) -- to;
  18753. ++ to; // inclusive -> exclusive bound
  18754. if ( from !== 0 || to !== nKeys ) {
  18755. // empty tracks are forbidden, so keep at least one keyframe
  18756. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  18757. var stride = this.getValueSize();
  18758. this.times = AnimationUtils.arraySlice( times, from, to );
  18759. this.values = AnimationUtils.
  18760. arraySlice( this.values, from * stride, to * stride );
  18761. }
  18762. return this;
  18763. },
  18764. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  18765. validate: function () {
  18766. var valid = true;
  18767. var valueSize = this.getValueSize();
  18768. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  18769. console.error( "invalid value size in track", this );
  18770. valid = false;
  18771. }
  18772. var times = this.times,
  18773. values = this.values,
  18774. nKeys = times.length;
  18775. if ( nKeys === 0 ) {
  18776. console.error( "track is empty", this );
  18777. valid = false;
  18778. }
  18779. var prevTime = null;
  18780. for ( var i = 0; i !== nKeys; i ++ ) {
  18781. var currTime = times[ i ];
  18782. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  18783. console.error( "time is not a valid number", this, i, currTime );
  18784. valid = false;
  18785. break;
  18786. }
  18787. if ( prevTime !== null && prevTime > currTime ) {
  18788. console.error( "out of order keys", this, i, currTime, prevTime );
  18789. valid = false;
  18790. break;
  18791. }
  18792. prevTime = currTime;
  18793. }
  18794. if ( values !== undefined ) {
  18795. if ( AnimationUtils.isTypedArray( values ) ) {
  18796. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  18797. var value = values[ i ];
  18798. if ( isNaN( value ) ) {
  18799. console.error( "value is not a valid number", this, i, value );
  18800. valid = false;
  18801. break;
  18802. }
  18803. }
  18804. }
  18805. }
  18806. return valid;
  18807. },
  18808. // removes equivalent sequential keys as common in morph target sequences
  18809. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  18810. optimize: function () {
  18811. var times = this.times,
  18812. values = this.values,
  18813. stride = this.getValueSize(),
  18814. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  18815. writeIndex = 1,
  18816. lastIndex = times.length - 1;
  18817. for ( var i = 1; i < lastIndex; ++ i ) {
  18818. var keep = false;
  18819. var time = times[ i ];
  18820. var timeNext = times[ i + 1 ];
  18821. // remove adjacent keyframes scheduled at the same time
  18822. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  18823. if ( ! smoothInterpolation ) {
  18824. // remove unnecessary keyframes same as their neighbors
  18825. var offset = i * stride,
  18826. offsetP = offset - stride,
  18827. offsetN = offset + stride;
  18828. for ( var j = 0; j !== stride; ++ j ) {
  18829. var value = values[ offset + j ];
  18830. if ( value !== values[ offsetP + j ] ||
  18831. value !== values[ offsetN + j ] ) {
  18832. keep = true;
  18833. break;
  18834. }
  18835. }
  18836. } else keep = true;
  18837. }
  18838. // in-place compaction
  18839. if ( keep ) {
  18840. if ( i !== writeIndex ) {
  18841. times[ writeIndex ] = times[ i ];
  18842. var readOffset = i * stride,
  18843. writeOffset = writeIndex * stride;
  18844. for ( var j = 0; j !== stride; ++ j )
  18845. values[ writeOffset + j ] = values[ readOffset + j ];
  18846. }
  18847. ++ writeIndex;
  18848. }
  18849. }
  18850. // flush last keyframe (compaction looks ahead)
  18851. if ( lastIndex > 0 ) {
  18852. times[ writeIndex ] = times[ lastIndex ];
  18853. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j )
  18854. values[ writeOffset + j ] = values[ readOffset + j ];
  18855. ++ writeIndex;
  18856. }
  18857. if ( writeIndex !== times.length ) {
  18858. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  18859. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  18860. }
  18861. return this;
  18862. }
  18863. };
  18864. function KeyframeTrackConstructor( name, times, values, interpolation ) {
  18865. if ( name === undefined ) throw new Error( "track name is undefined" );
  18866. if ( times === undefined || times.length === 0 ) {
  18867. throw new Error( "no keyframes in track named " + name );
  18868. }
  18869. this.name = name;
  18870. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  18871. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  18872. this.setInterpolation( interpolation || this.DefaultInterpolation );
  18873. this.validate();
  18874. this.optimize();
  18875. }
  18876. /**
  18877. *
  18878. * A Track of vectored keyframe values.
  18879. *
  18880. *
  18881. * @author Ben Houston / http://clara.io/
  18882. * @author David Sarno / http://lighthaus.us/
  18883. * @author tschw
  18884. */
  18885. function VectorKeyframeTrack( name, times, values, interpolation ) {
  18886. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18887. }
  18888. VectorKeyframeTrack.prototype =
  18889. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18890. constructor: VectorKeyframeTrack,
  18891. ValueTypeName: 'vector'
  18892. // ValueBufferType is inherited
  18893. // DefaultInterpolation is inherited
  18894. } );
  18895. /**
  18896. * Spherical linear unit quaternion interpolant.
  18897. *
  18898. * @author tschw
  18899. */
  18900. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  18901. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  18902. }
  18903. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  18904. constructor: QuaternionLinearInterpolant,
  18905. interpolate_: function( i1, t0, t, t1 ) {
  18906. var result = this.resultBuffer,
  18907. values = this.sampleValues,
  18908. stride = this.valueSize,
  18909. offset = i1 * stride,
  18910. alpha = ( t - t0 ) / ( t1 - t0 );
  18911. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  18912. Quaternion.slerpFlat( result, 0,
  18913. values, offset - stride, values, offset, alpha );
  18914. }
  18915. return result;
  18916. }
  18917. } );
  18918. /**
  18919. *
  18920. * A Track of quaternion keyframe values.
  18921. *
  18922. * @author Ben Houston / http://clara.io/
  18923. * @author David Sarno / http://lighthaus.us/
  18924. * @author tschw
  18925. */
  18926. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  18927. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18928. }
  18929. QuaternionKeyframeTrack.prototype =
  18930. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18931. constructor: QuaternionKeyframeTrack,
  18932. ValueTypeName: 'quaternion',
  18933. // ValueBufferType is inherited
  18934. DefaultInterpolation: InterpolateLinear,
  18935. InterpolantFactoryMethodLinear: function( result ) {
  18936. return new QuaternionLinearInterpolant(
  18937. this.times, this.values, this.getValueSize(), result );
  18938. },
  18939. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  18940. } );
  18941. /**
  18942. *
  18943. * A Track of numeric keyframe values.
  18944. *
  18945. * @author Ben Houston / http://clara.io/
  18946. * @author David Sarno / http://lighthaus.us/
  18947. * @author tschw
  18948. */
  18949. function NumberKeyframeTrack( name, times, values, interpolation ) {
  18950. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18951. }
  18952. NumberKeyframeTrack.prototype =
  18953. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18954. constructor: NumberKeyframeTrack,
  18955. ValueTypeName: 'number'
  18956. // ValueBufferType is inherited
  18957. // DefaultInterpolation is inherited
  18958. } );
  18959. /**
  18960. *
  18961. * A Track that interpolates Strings
  18962. *
  18963. *
  18964. * @author Ben Houston / http://clara.io/
  18965. * @author David Sarno / http://lighthaus.us/
  18966. * @author tschw
  18967. */
  18968. function StringKeyframeTrack( name, times, values, interpolation ) {
  18969. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  18970. }
  18971. StringKeyframeTrack.prototype =
  18972. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18973. constructor: StringKeyframeTrack,
  18974. ValueTypeName: 'string',
  18975. ValueBufferType: Array,
  18976. DefaultInterpolation: InterpolateDiscrete,
  18977. InterpolantFactoryMethodLinear: undefined,
  18978. InterpolantFactoryMethodSmooth: undefined
  18979. } );
  18980. /**
  18981. *
  18982. * A Track of Boolean keyframe values.
  18983. *
  18984. *
  18985. * @author Ben Houston / http://clara.io/
  18986. * @author David Sarno / http://lighthaus.us/
  18987. * @author tschw
  18988. */
  18989. function BooleanKeyframeTrack( name, times, values ) {
  18990. KeyframeTrackConstructor.call( this, name, times, values );
  18991. }
  18992. BooleanKeyframeTrack.prototype =
  18993. Object.assign( Object.create( KeyframeTrackPrototype ), {
  18994. constructor: BooleanKeyframeTrack,
  18995. ValueTypeName: 'bool',
  18996. ValueBufferType: Array,
  18997. DefaultInterpolation: InterpolateDiscrete,
  18998. InterpolantFactoryMethodLinear: undefined,
  18999. InterpolantFactoryMethodSmooth: undefined
  19000. // Note: Actually this track could have a optimized / compressed
  19001. // representation of a single value and a custom interpolant that
  19002. // computes "firstValue ^ isOdd( index )".
  19003. } );
  19004. /**
  19005. *
  19006. * A Track of keyframe values that represent color.
  19007. *
  19008. *
  19009. * @author Ben Houston / http://clara.io/
  19010. * @author David Sarno / http://lighthaus.us/
  19011. * @author tschw
  19012. */
  19013. function ColorKeyframeTrack( name, times, values, interpolation ) {
  19014. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  19015. }
  19016. ColorKeyframeTrack.prototype =
  19017. Object.assign( Object.create( KeyframeTrackPrototype ), {
  19018. constructor: ColorKeyframeTrack,
  19019. ValueTypeName: 'color'
  19020. // ValueBufferType is inherited
  19021. // DefaultInterpolation is inherited
  19022. // Note: Very basic implementation and nothing special yet.
  19023. // However, this is the place for color space parameterization.
  19024. } );
  19025. /**
  19026. *
  19027. * A timed sequence of keyframes for a specific property.
  19028. *
  19029. *
  19030. * @author Ben Houston / http://clara.io/
  19031. * @author David Sarno / http://lighthaus.us/
  19032. * @author tschw
  19033. */
  19034. function KeyframeTrack( name, times, values, interpolation ) {
  19035. KeyframeTrackConstructor.apply( this, arguments );
  19036. }
  19037. KeyframeTrack.prototype = KeyframeTrackPrototype;
  19038. KeyframeTrackPrototype.constructor = KeyframeTrack;
  19039. // Static methods:
  19040. Object.assign( KeyframeTrack, {
  19041. // Serialization (in static context, because of constructor invocation
  19042. // and automatic invocation of .toJSON):
  19043. parse: function( json ) {
  19044. if( json.type === undefined ) {
  19045. throw new Error( "track type undefined, can not parse" );
  19046. }
  19047. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  19048. if ( json.times === undefined ) {
  19049. var times = [], values = [];
  19050. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  19051. json.times = times;
  19052. json.values = values;
  19053. }
  19054. // derived classes can define a static parse method
  19055. if ( trackType.parse !== undefined ) {
  19056. return trackType.parse( json );
  19057. } else {
  19058. // by default, we asssume a constructor compatible with the base
  19059. return new trackType(
  19060. json.name, json.times, json.values, json.interpolation );
  19061. }
  19062. },
  19063. toJSON: function( track ) {
  19064. var trackType = track.constructor;
  19065. var json;
  19066. // derived classes can define a static toJSON method
  19067. if ( trackType.toJSON !== undefined ) {
  19068. json = trackType.toJSON( track );
  19069. } else {
  19070. // by default, we assume the data can be serialized as-is
  19071. json = {
  19072. 'name': track.name,
  19073. 'times': AnimationUtils.convertArray( track.times, Array ),
  19074. 'values': AnimationUtils.convertArray( track.values, Array )
  19075. };
  19076. var interpolation = track.getInterpolation();
  19077. if ( interpolation !== track.DefaultInterpolation ) {
  19078. json.interpolation = interpolation;
  19079. }
  19080. }
  19081. json.type = track.ValueTypeName; // mandatory
  19082. return json;
  19083. },
  19084. _getTrackTypeForValueTypeName: function( typeName ) {
  19085. switch( typeName.toLowerCase() ) {
  19086. case "scalar":
  19087. case "double":
  19088. case "float":
  19089. case "number":
  19090. case "integer":
  19091. return NumberKeyframeTrack;
  19092. case "vector":
  19093. case "vector2":
  19094. case "vector3":
  19095. case "vector4":
  19096. return VectorKeyframeTrack;
  19097. case "color":
  19098. return ColorKeyframeTrack;
  19099. case "quaternion":
  19100. return QuaternionKeyframeTrack;
  19101. case "bool":
  19102. case "boolean":
  19103. return BooleanKeyframeTrack;
  19104. case "string":
  19105. return StringKeyframeTrack;
  19106. }
  19107. throw new Error( "Unsupported typeName: " + typeName );
  19108. }
  19109. } );
  19110. /**
  19111. *
  19112. * Reusable set of Tracks that represent an animation.
  19113. *
  19114. * @author Ben Houston / http://clara.io/
  19115. * @author David Sarno / http://lighthaus.us/
  19116. */
  19117. function AnimationClip( name, duration, tracks ) {
  19118. this.name = name;
  19119. this.tracks = tracks;
  19120. this.duration = ( duration !== undefined ) ? duration : - 1;
  19121. this.uuid = _Math.generateUUID();
  19122. // this means it should figure out its duration by scanning the tracks
  19123. if ( this.duration < 0 ) {
  19124. this.resetDuration();
  19125. }
  19126. this.optimize();
  19127. }
  19128. Object.assign( AnimationClip, {
  19129. parse: function ( json ) {
  19130. var tracks = [],
  19131. jsonTracks = json.tracks,
  19132. frameTime = 1.0 / ( json.fps || 1.0 );
  19133. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  19134. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  19135. }
  19136. return new AnimationClip( json.name, json.duration, tracks );
  19137. },
  19138. toJSON: function ( clip ) {
  19139. var tracks = [],
  19140. clipTracks = clip.tracks;
  19141. var json = {
  19142. 'name': clip.name,
  19143. 'duration': clip.duration,
  19144. 'tracks': tracks
  19145. };
  19146. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  19147. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  19148. }
  19149. return json;
  19150. },
  19151. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  19152. var numMorphTargets = morphTargetSequence.length;
  19153. var tracks = [];
  19154. for ( var i = 0; i < numMorphTargets; i ++ ) {
  19155. var times = [];
  19156. var values = [];
  19157. times.push(
  19158. ( i + numMorphTargets - 1 ) % numMorphTargets,
  19159. i,
  19160. ( i + 1 ) % numMorphTargets );
  19161. values.push( 0, 1, 0 );
  19162. var order = AnimationUtils.getKeyframeOrder( times );
  19163. times = AnimationUtils.sortedArray( times, 1, order );
  19164. values = AnimationUtils.sortedArray( values, 1, order );
  19165. // if there is a key at the first frame, duplicate it as the
  19166. // last frame as well for perfect loop.
  19167. if ( ! noLoop && times[ 0 ] === 0 ) {
  19168. times.push( numMorphTargets );
  19169. values.push( values[ 0 ] );
  19170. }
  19171. tracks.push(
  19172. new NumberKeyframeTrack(
  19173. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  19174. times, values
  19175. ).scale( 1.0 / fps ) );
  19176. }
  19177. return new AnimationClip( name, - 1, tracks );
  19178. },
  19179. findByName: function ( objectOrClipArray, name ) {
  19180. var clipArray = objectOrClipArray;
  19181. if ( ! Array.isArray( objectOrClipArray ) ) {
  19182. var o = objectOrClipArray;
  19183. clipArray = o.geometry && o.geometry.animations || o.animations;
  19184. }
  19185. for ( var i = 0; i < clipArray.length; i ++ ) {
  19186. if ( clipArray[ i ].name === name ) {
  19187. return clipArray[ i ];
  19188. }
  19189. }
  19190. return null;
  19191. },
  19192. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  19193. var animationToMorphTargets = {};
  19194. // tested with https://regex101.com/ on trick sequences
  19195. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  19196. var pattern = /^([\w-]*?)([\d]+)$/;
  19197. // sort morph target names into animation groups based
  19198. // patterns like Walk_001, Walk_002, Run_001, Run_002
  19199. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  19200. var morphTarget = morphTargets[ i ];
  19201. var parts = morphTarget.name.match( pattern );
  19202. if ( parts && parts.length > 1 ) {
  19203. var name = parts[ 1 ];
  19204. var animationMorphTargets = animationToMorphTargets[ name ];
  19205. if ( ! animationMorphTargets ) {
  19206. animationToMorphTargets[ name ] = animationMorphTargets = [];
  19207. }
  19208. animationMorphTargets.push( morphTarget );
  19209. }
  19210. }
  19211. var clips = [];
  19212. for ( var name in animationToMorphTargets ) {
  19213. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  19214. }
  19215. return clips;
  19216. },
  19217. // parse the animation.hierarchy format
  19218. parseAnimation: function ( animation, bones ) {
  19219. if ( ! animation ) {
  19220. console.error( " no animation in JSONLoader data" );
  19221. return null;
  19222. }
  19223. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  19224. // only return track if there are actually keys.
  19225. if ( animationKeys.length !== 0 ) {
  19226. var times = [];
  19227. var values = [];
  19228. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  19229. // empty keys are filtered out, so check again
  19230. if ( times.length !== 0 ) {
  19231. destTracks.push( new trackType( trackName, times, values ) );
  19232. }
  19233. }
  19234. };
  19235. var tracks = [];
  19236. var clipName = animation.name || 'default';
  19237. // automatic length determination in AnimationClip.
  19238. var duration = animation.length || - 1;
  19239. var fps = animation.fps || 30;
  19240. var hierarchyTracks = animation.hierarchy || [];
  19241. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  19242. var animationKeys = hierarchyTracks[ h ].keys;
  19243. // skip empty tracks
  19244. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  19245. // process morph targets
  19246. if ( animationKeys[ 0 ].morphTargets ) {
  19247. // figure out all morph targets used in this track
  19248. var morphTargetNames = {};
  19249. for ( var k = 0; k < animationKeys.length; k ++ ) {
  19250. if ( animationKeys[ k ].morphTargets ) {
  19251. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  19252. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  19253. }
  19254. }
  19255. }
  19256. // create a track for each morph target with all zero
  19257. // morphTargetInfluences except for the keys in which
  19258. // the morphTarget is named.
  19259. for ( var morphTargetName in morphTargetNames ) {
  19260. var times = [];
  19261. var values = [];
  19262. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  19263. var animationKey = animationKeys[ k ];
  19264. times.push( animationKey.time );
  19265. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  19266. }
  19267. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  19268. }
  19269. duration = morphTargetNames.length * ( fps || 1.0 );
  19270. } else {
  19271. // ...assume skeletal animation
  19272. var boneName = '.bones[' + bones[ h ].name + ']';
  19273. addNonemptyTrack(
  19274. VectorKeyframeTrack, boneName + '.position',
  19275. animationKeys, 'pos', tracks );
  19276. addNonemptyTrack(
  19277. QuaternionKeyframeTrack, boneName + '.quaternion',
  19278. animationKeys, 'rot', tracks );
  19279. addNonemptyTrack(
  19280. VectorKeyframeTrack, boneName + '.scale',
  19281. animationKeys, 'scl', tracks );
  19282. }
  19283. }
  19284. if ( tracks.length === 0 ) {
  19285. return null;
  19286. }
  19287. var clip = new AnimationClip( clipName, duration, tracks );
  19288. return clip;
  19289. }
  19290. } );
  19291. Object.assign( AnimationClip.prototype, {
  19292. resetDuration: function () {
  19293. var tracks = this.tracks, duration = 0;
  19294. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  19295. var track = this.tracks[ i ];
  19296. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  19297. }
  19298. this.duration = duration;
  19299. },
  19300. trim: function () {
  19301. for ( var i = 0; i < this.tracks.length; i ++ ) {
  19302. this.tracks[ i ].trim( 0, this.duration );
  19303. }
  19304. return this;
  19305. },
  19306. optimize: function () {
  19307. for ( var i = 0; i < this.tracks.length; i ++ ) {
  19308. this.tracks[ i ].optimize();
  19309. }
  19310. return this;
  19311. }
  19312. } );
  19313. /**
  19314. * @author mrdoob / http://mrdoob.com/
  19315. */
  19316. function MaterialLoader( manager ) {
  19317. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  19318. this.textures = {};
  19319. }
  19320. Object.assign( MaterialLoader.prototype, {
  19321. load: function ( url, onLoad, onProgress, onError ) {
  19322. var scope = this;
  19323. var loader = new FileLoader( scope.manager );
  19324. loader.load( url, function ( text ) {
  19325. onLoad( scope.parse( JSON.parse( text ) ) );
  19326. }, onProgress, onError );
  19327. },
  19328. setTextures: function ( value ) {
  19329. this.textures = value;
  19330. },
  19331. parse: function ( json ) {
  19332. var textures = this.textures;
  19333. function getTexture( name ) {
  19334. if ( textures[ name ] === undefined ) {
  19335. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  19336. }
  19337. return textures[ name ];
  19338. }
  19339. var material = new Materials[ json.type ]();
  19340. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  19341. if ( json.name !== undefined ) material.name = json.name;
  19342. if ( json.color !== undefined ) material.color.setHex( json.color );
  19343. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  19344. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  19345. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  19346. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  19347. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  19348. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  19349. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  19350. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  19351. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  19352. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  19353. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  19354. if ( json.fog !== undefined ) material.fog = json.fog;
  19355. if ( json.shading !== undefined ) material.shading = json.shading;
  19356. if ( json.blending !== undefined ) material.blending = json.blending;
  19357. if ( json.side !== undefined ) material.side = json.side;
  19358. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  19359. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  19360. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  19361. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  19362. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  19363. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  19364. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  19365. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  19366. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  19367. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  19368. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  19369. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  19370. // for PointsMaterial
  19371. if ( json.size !== undefined ) material.size = json.size;
  19372. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  19373. // maps
  19374. if ( json.map !== undefined ) material.map = getTexture( json.map );
  19375. if ( json.alphaMap !== undefined ) {
  19376. material.alphaMap = getTexture( json.alphaMap );
  19377. material.transparent = true;
  19378. }
  19379. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  19380. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  19381. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  19382. if ( json.normalScale !== undefined ) {
  19383. var normalScale = json.normalScale;
  19384. if ( Array.isArray( normalScale ) === false ) {
  19385. // Blender exporter used to export a scalar. See #7459
  19386. normalScale = [ normalScale, normalScale ];
  19387. }
  19388. material.normalScale = new Vector2().fromArray( normalScale );
  19389. }
  19390. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  19391. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  19392. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  19393. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  19394. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  19395. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  19396. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  19397. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  19398. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  19399. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  19400. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  19401. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  19402. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  19403. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  19404. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  19405. return material;
  19406. }
  19407. } );
  19408. /**
  19409. * @author mrdoob / http://mrdoob.com/
  19410. */
  19411. function BufferGeometryLoader( manager ) {
  19412. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  19413. }
  19414. Object.assign( BufferGeometryLoader.prototype, {
  19415. load: function ( url, onLoad, onProgress, onError ) {
  19416. var scope = this;
  19417. var loader = new FileLoader( scope.manager );
  19418. loader.load( url, function ( text ) {
  19419. onLoad( scope.parse( JSON.parse( text ) ) );
  19420. }, onProgress, onError );
  19421. },
  19422. parse: function ( json ) {
  19423. var geometry = new BufferGeometry();
  19424. var index = json.data.index;
  19425. if ( index !== undefined ) {
  19426. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  19427. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  19428. }
  19429. var attributes = json.data.attributes;
  19430. for ( var key in attributes ) {
  19431. var attribute = attributes[ key ];
  19432. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  19433. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  19434. }
  19435. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  19436. if ( groups !== undefined ) {
  19437. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  19438. var group = groups[ i ];
  19439. geometry.addGroup( group.start, group.count, group.materialIndex );
  19440. }
  19441. }
  19442. var boundingSphere = json.data.boundingSphere;
  19443. if ( boundingSphere !== undefined ) {
  19444. var center = new Vector3();
  19445. if ( boundingSphere.center !== undefined ) {
  19446. center.fromArray( boundingSphere.center );
  19447. }
  19448. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  19449. }
  19450. return geometry;
  19451. }
  19452. } );
  19453. var TYPED_ARRAYS = {
  19454. Int8Array: Int8Array,
  19455. Uint8Array: Uint8Array,
  19456. Uint8ClampedArray: Uint8ClampedArray,
  19457. Int16Array: Int16Array,
  19458. Uint16Array: Uint16Array,
  19459. Int32Array: Int32Array,
  19460. Uint32Array: Uint32Array,
  19461. Float32Array: Float32Array,
  19462. Float64Array: Float64Array
  19463. };
  19464. /**
  19465. * @author alteredq / http://alteredqualia.com/
  19466. */
  19467. function Loader() {
  19468. this.onLoadStart = function () {};
  19469. this.onLoadProgress = function () {};
  19470. this.onLoadComplete = function () {};
  19471. }
  19472. Loader.Handlers = {
  19473. handlers: [],
  19474. add: function ( regex, loader ) {
  19475. this.handlers.push( regex, loader );
  19476. },
  19477. get: function ( file ) {
  19478. var handlers = this.handlers;
  19479. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  19480. var regex = handlers[ i ];
  19481. var loader = handlers[ i + 1 ];
  19482. if ( regex.test( file ) ) {
  19483. return loader;
  19484. }
  19485. }
  19486. return null;
  19487. }
  19488. };
  19489. Object.assign( Loader.prototype, {
  19490. crossOrigin: undefined,
  19491. extractUrlBase: function ( url ) {
  19492. var parts = url.split( '/' );
  19493. if ( parts.length === 1 ) return './';
  19494. parts.pop();
  19495. return parts.join( '/' ) + '/';
  19496. },
  19497. initMaterials: function ( materials, texturePath, crossOrigin ) {
  19498. var array = [];
  19499. for ( var i = 0; i < materials.length; ++ i ) {
  19500. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  19501. }
  19502. return array;
  19503. },
  19504. createMaterial: ( function () {
  19505. var BlendingMode = {
  19506. NoBlending: NoBlending,
  19507. NormalBlending: NormalBlending,
  19508. AdditiveBlending: AdditiveBlending,
  19509. SubtractiveBlending: SubtractiveBlending,
  19510. MultiplyBlending: MultiplyBlending,
  19511. CustomBlending: CustomBlending
  19512. };
  19513. var color = new Color();
  19514. var textureLoader = new TextureLoader();
  19515. var materialLoader = new MaterialLoader();
  19516. return function createMaterial( m, texturePath, crossOrigin ) {
  19517. // convert from old material format
  19518. var textures = {};
  19519. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  19520. var fullPath = texturePath + path;
  19521. var loader = Loader.Handlers.get( fullPath );
  19522. var texture;
  19523. if ( loader !== null ) {
  19524. texture = loader.load( fullPath );
  19525. } else {
  19526. textureLoader.setCrossOrigin( crossOrigin );
  19527. texture = textureLoader.load( fullPath );
  19528. }
  19529. if ( repeat !== undefined ) {
  19530. texture.repeat.fromArray( repeat );
  19531. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  19532. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  19533. }
  19534. if ( offset !== undefined ) {
  19535. texture.offset.fromArray( offset );
  19536. }
  19537. if ( wrap !== undefined ) {
  19538. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  19539. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  19540. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  19541. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  19542. }
  19543. if ( anisotropy !== undefined ) {
  19544. texture.anisotropy = anisotropy;
  19545. }
  19546. var uuid = _Math.generateUUID();
  19547. textures[ uuid ] = texture;
  19548. return uuid;
  19549. }
  19550. //
  19551. var json = {
  19552. uuid: _Math.generateUUID(),
  19553. type: 'MeshLambertMaterial'
  19554. };
  19555. for ( var name in m ) {
  19556. var value = m[ name ];
  19557. switch ( name ) {
  19558. case 'DbgColor':
  19559. case 'DbgIndex':
  19560. case 'opticalDensity':
  19561. case 'illumination':
  19562. break;
  19563. case 'DbgName':
  19564. json.name = value;
  19565. break;
  19566. case 'blending':
  19567. json.blending = BlendingMode[ value ];
  19568. break;
  19569. case 'colorAmbient':
  19570. case 'mapAmbient':
  19571. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  19572. break;
  19573. case 'colorDiffuse':
  19574. json.color = color.fromArray( value ).getHex();
  19575. break;
  19576. case 'colorSpecular':
  19577. json.specular = color.fromArray( value ).getHex();
  19578. break;
  19579. case 'colorEmissive':
  19580. json.emissive = color.fromArray( value ).getHex();
  19581. break;
  19582. case 'specularCoef':
  19583. json.shininess = value;
  19584. break;
  19585. case 'shading':
  19586. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  19587. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  19588. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  19589. break;
  19590. case 'mapDiffuse':
  19591. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  19592. break;
  19593. case 'mapDiffuseRepeat':
  19594. case 'mapDiffuseOffset':
  19595. case 'mapDiffuseWrap':
  19596. case 'mapDiffuseAnisotropy':
  19597. break;
  19598. case 'mapEmissive':
  19599. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  19600. break;
  19601. case 'mapEmissiveRepeat':
  19602. case 'mapEmissiveOffset':
  19603. case 'mapEmissiveWrap':
  19604. case 'mapEmissiveAnisotropy':
  19605. break;
  19606. case 'mapLight':
  19607. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  19608. break;
  19609. case 'mapLightRepeat':
  19610. case 'mapLightOffset':
  19611. case 'mapLightWrap':
  19612. case 'mapLightAnisotropy':
  19613. break;
  19614. case 'mapAO':
  19615. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  19616. break;
  19617. case 'mapAORepeat':
  19618. case 'mapAOOffset':
  19619. case 'mapAOWrap':
  19620. case 'mapAOAnisotropy':
  19621. break;
  19622. case 'mapBump':
  19623. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  19624. break;
  19625. case 'mapBumpScale':
  19626. json.bumpScale = value;
  19627. break;
  19628. case 'mapBumpRepeat':
  19629. case 'mapBumpOffset':
  19630. case 'mapBumpWrap':
  19631. case 'mapBumpAnisotropy':
  19632. break;
  19633. case 'mapNormal':
  19634. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  19635. break;
  19636. case 'mapNormalFactor':
  19637. json.normalScale = [ value, value ];
  19638. break;
  19639. case 'mapNormalRepeat':
  19640. case 'mapNormalOffset':
  19641. case 'mapNormalWrap':
  19642. case 'mapNormalAnisotropy':
  19643. break;
  19644. case 'mapSpecular':
  19645. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  19646. break;
  19647. case 'mapSpecularRepeat':
  19648. case 'mapSpecularOffset':
  19649. case 'mapSpecularWrap':
  19650. case 'mapSpecularAnisotropy':
  19651. break;
  19652. case 'mapMetalness':
  19653. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  19654. break;
  19655. case 'mapMetalnessRepeat':
  19656. case 'mapMetalnessOffset':
  19657. case 'mapMetalnessWrap':
  19658. case 'mapMetalnessAnisotropy':
  19659. break;
  19660. case 'mapRoughness':
  19661. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  19662. break;
  19663. case 'mapRoughnessRepeat':
  19664. case 'mapRoughnessOffset':
  19665. case 'mapRoughnessWrap':
  19666. case 'mapRoughnessAnisotropy':
  19667. break;
  19668. case 'mapAlpha':
  19669. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  19670. break;
  19671. case 'mapAlphaRepeat':
  19672. case 'mapAlphaOffset':
  19673. case 'mapAlphaWrap':
  19674. case 'mapAlphaAnisotropy':
  19675. break;
  19676. case 'flipSided':
  19677. json.side = BackSide;
  19678. break;
  19679. case 'doubleSided':
  19680. json.side = DoubleSide;
  19681. break;
  19682. case 'transparency':
  19683. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  19684. json.opacity = value;
  19685. break;
  19686. case 'depthTest':
  19687. case 'depthWrite':
  19688. case 'colorWrite':
  19689. case 'opacity':
  19690. case 'reflectivity':
  19691. case 'transparent':
  19692. case 'visible':
  19693. case 'wireframe':
  19694. json[ name ] = value;
  19695. break;
  19696. case 'vertexColors':
  19697. if ( value === true ) json.vertexColors = VertexColors;
  19698. if ( value === 'face' ) json.vertexColors = FaceColors;
  19699. break;
  19700. default:
  19701. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  19702. break;
  19703. }
  19704. }
  19705. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  19706. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  19707. if ( json.opacity < 1 ) json.transparent = true;
  19708. materialLoader.setTextures( textures );
  19709. return materialLoader.parse( json );
  19710. };
  19711. } )()
  19712. } );
  19713. /**
  19714. * @author mrdoob / http://mrdoob.com/
  19715. * @author alteredq / http://alteredqualia.com/
  19716. */
  19717. function JSONLoader( manager ) {
  19718. if ( typeof manager === 'boolean' ) {
  19719. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  19720. manager = undefined;
  19721. }
  19722. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  19723. this.withCredentials = false;
  19724. }
  19725. Object.assign( JSONLoader.prototype, {
  19726. load: function ( url, onLoad, onProgress, onError ) {
  19727. var scope = this;
  19728. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : Loader.prototype.extractUrlBase( url );
  19729. var loader = new FileLoader( this.manager );
  19730. loader.setWithCredentials( this.withCredentials );
  19731. loader.load( url, function ( text ) {
  19732. var json = JSON.parse( text );
  19733. var metadata = json.metadata;
  19734. if ( metadata !== undefined ) {
  19735. var type = metadata.type;
  19736. if ( type !== undefined ) {
  19737. if ( type.toLowerCase() === 'object' ) {
  19738. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  19739. return;
  19740. }
  19741. if ( type.toLowerCase() === 'scene' ) {
  19742. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  19743. return;
  19744. }
  19745. }
  19746. }
  19747. var object = scope.parse( json, texturePath );
  19748. onLoad( object.geometry, object.materials );
  19749. }, onProgress, onError );
  19750. },
  19751. setTexturePath: function ( value ) {
  19752. this.texturePath = value;
  19753. },
  19754. parse: ( function () {
  19755. function parseModel( json, geometry ) {
  19756. function isBitSet( value, position ) {
  19757. return value & ( 1 << position );
  19758. }
  19759. var i, j, fi,
  19760. offset, zLength,
  19761. colorIndex, normalIndex, uvIndex, materialIndex,
  19762. type,
  19763. isQuad,
  19764. hasMaterial,
  19765. hasFaceVertexUv,
  19766. hasFaceNormal, hasFaceVertexNormal,
  19767. hasFaceColor, hasFaceVertexColor,
  19768. vertex, face, faceA, faceB, hex, normal,
  19769. uvLayer, uv, u, v,
  19770. faces = json.faces,
  19771. vertices = json.vertices,
  19772. normals = json.normals,
  19773. colors = json.colors,
  19774. scale = json.scale,
  19775. nUvLayers = 0;
  19776. if ( json.uvs !== undefined ) {
  19777. // disregard empty arrays
  19778. for ( i = 0; i < json.uvs.length; i ++ ) {
  19779. if ( json.uvs[ i ].length ) nUvLayers ++;
  19780. }
  19781. for ( i = 0; i < nUvLayers; i ++ ) {
  19782. geometry.faceVertexUvs[ i ] = [];
  19783. }
  19784. }
  19785. offset = 0;
  19786. zLength = vertices.length;
  19787. while ( offset < zLength ) {
  19788. vertex = new Vector3();
  19789. vertex.x = vertices[ offset ++ ] * scale;
  19790. vertex.y = vertices[ offset ++ ] * scale;
  19791. vertex.z = vertices[ offset ++ ] * scale;
  19792. geometry.vertices.push( vertex );
  19793. }
  19794. offset = 0;
  19795. zLength = faces.length;
  19796. while ( offset < zLength ) {
  19797. type = faces[ offset ++ ];
  19798. isQuad = isBitSet( type, 0 );
  19799. hasMaterial = isBitSet( type, 1 );
  19800. hasFaceVertexUv = isBitSet( type, 3 );
  19801. hasFaceNormal = isBitSet( type, 4 );
  19802. hasFaceVertexNormal = isBitSet( type, 5 );
  19803. hasFaceColor = isBitSet( type, 6 );
  19804. hasFaceVertexColor = isBitSet( type, 7 );
  19805. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  19806. if ( isQuad ) {
  19807. faceA = new Face3();
  19808. faceA.a = faces[ offset ];
  19809. faceA.b = faces[ offset + 1 ];
  19810. faceA.c = faces[ offset + 3 ];
  19811. faceB = new Face3();
  19812. faceB.a = faces[ offset + 1 ];
  19813. faceB.b = faces[ offset + 2 ];
  19814. faceB.c = faces[ offset + 3 ];
  19815. offset += 4;
  19816. if ( hasMaterial ) {
  19817. materialIndex = faces[ offset ++ ];
  19818. faceA.materialIndex = materialIndex;
  19819. faceB.materialIndex = materialIndex;
  19820. }
  19821. // to get face <=> uv index correspondence
  19822. fi = geometry.faces.length;
  19823. if ( hasFaceVertexUv ) {
  19824. for ( i = 0; i < nUvLayers; i ++ ) {
  19825. uvLayer = json.uvs[ i ];
  19826. geometry.faceVertexUvs[ i ][ fi ] = [];
  19827. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  19828. for ( j = 0; j < 4; j ++ ) {
  19829. uvIndex = faces[ offset ++ ];
  19830. u = uvLayer[ uvIndex * 2 ];
  19831. v = uvLayer[ uvIndex * 2 + 1 ];
  19832. uv = new Vector2( u, v );
  19833. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  19834. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  19835. }
  19836. }
  19837. }
  19838. if ( hasFaceNormal ) {
  19839. normalIndex = faces[ offset ++ ] * 3;
  19840. faceA.normal.set(
  19841. normals[ normalIndex ++ ],
  19842. normals[ normalIndex ++ ],
  19843. normals[ normalIndex ]
  19844. );
  19845. faceB.normal.copy( faceA.normal );
  19846. }
  19847. if ( hasFaceVertexNormal ) {
  19848. for ( i = 0; i < 4; i ++ ) {
  19849. normalIndex = faces[ offset ++ ] * 3;
  19850. normal = new Vector3(
  19851. normals[ normalIndex ++ ],
  19852. normals[ normalIndex ++ ],
  19853. normals[ normalIndex ]
  19854. );
  19855. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  19856. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  19857. }
  19858. }
  19859. if ( hasFaceColor ) {
  19860. colorIndex = faces[ offset ++ ];
  19861. hex = colors[ colorIndex ];
  19862. faceA.color.setHex( hex );
  19863. faceB.color.setHex( hex );
  19864. }
  19865. if ( hasFaceVertexColor ) {
  19866. for ( i = 0; i < 4; i ++ ) {
  19867. colorIndex = faces[ offset ++ ];
  19868. hex = colors[ colorIndex ];
  19869. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  19870. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  19871. }
  19872. }
  19873. geometry.faces.push( faceA );
  19874. geometry.faces.push( faceB );
  19875. } else {
  19876. face = new Face3();
  19877. face.a = faces[ offset ++ ];
  19878. face.b = faces[ offset ++ ];
  19879. face.c = faces[ offset ++ ];
  19880. if ( hasMaterial ) {
  19881. materialIndex = faces[ offset ++ ];
  19882. face.materialIndex = materialIndex;
  19883. }
  19884. // to get face <=> uv index correspondence
  19885. fi = geometry.faces.length;
  19886. if ( hasFaceVertexUv ) {
  19887. for ( i = 0; i < nUvLayers; i ++ ) {
  19888. uvLayer = json.uvs[ i ];
  19889. geometry.faceVertexUvs[ i ][ fi ] = [];
  19890. for ( j = 0; j < 3; j ++ ) {
  19891. uvIndex = faces[ offset ++ ];
  19892. u = uvLayer[ uvIndex * 2 ];
  19893. v = uvLayer[ uvIndex * 2 + 1 ];
  19894. uv = new Vector2( u, v );
  19895. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  19896. }
  19897. }
  19898. }
  19899. if ( hasFaceNormal ) {
  19900. normalIndex = faces[ offset ++ ] * 3;
  19901. face.normal.set(
  19902. normals[ normalIndex ++ ],
  19903. normals[ normalIndex ++ ],
  19904. normals[ normalIndex ]
  19905. );
  19906. }
  19907. if ( hasFaceVertexNormal ) {
  19908. for ( i = 0; i < 3; i ++ ) {
  19909. normalIndex = faces[ offset ++ ] * 3;
  19910. normal = new Vector3(
  19911. normals[ normalIndex ++ ],
  19912. normals[ normalIndex ++ ],
  19913. normals[ normalIndex ]
  19914. );
  19915. face.vertexNormals.push( normal );
  19916. }
  19917. }
  19918. if ( hasFaceColor ) {
  19919. colorIndex = faces[ offset ++ ];
  19920. face.color.setHex( colors[ colorIndex ] );
  19921. }
  19922. if ( hasFaceVertexColor ) {
  19923. for ( i = 0; i < 3; i ++ ) {
  19924. colorIndex = faces[ offset ++ ];
  19925. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  19926. }
  19927. }
  19928. geometry.faces.push( face );
  19929. }
  19930. }
  19931. }
  19932. function parseSkin( json, geometry ) {
  19933. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  19934. if ( json.skinWeights ) {
  19935. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  19936. var x = json.skinWeights[ i ];
  19937. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  19938. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  19939. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  19940. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  19941. }
  19942. }
  19943. if ( json.skinIndices ) {
  19944. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  19945. var a = json.skinIndices[ i ];
  19946. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  19947. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  19948. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  19949. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  19950. }
  19951. }
  19952. geometry.bones = json.bones;
  19953. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  19954. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  19955. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  19956. }
  19957. }
  19958. function parseMorphing( json, geometry ) {
  19959. var scale = json.scale;
  19960. if ( json.morphTargets !== undefined ) {
  19961. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  19962. geometry.morphTargets[ i ] = {};
  19963. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  19964. geometry.morphTargets[ i ].vertices = [];
  19965. var dstVertices = geometry.morphTargets[ i ].vertices;
  19966. var srcVertices = json.morphTargets[ i ].vertices;
  19967. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  19968. var vertex = new Vector3();
  19969. vertex.x = srcVertices[ v ] * scale;
  19970. vertex.y = srcVertices[ v + 1 ] * scale;
  19971. vertex.z = srcVertices[ v + 2 ] * scale;
  19972. dstVertices.push( vertex );
  19973. }
  19974. }
  19975. }
  19976. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  19977. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  19978. var faces = geometry.faces;
  19979. var morphColors = json.morphColors[ 0 ].colors;
  19980. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19981. faces[ i ].color.fromArray( morphColors, i * 3 );
  19982. }
  19983. }
  19984. }
  19985. function parseAnimations( json, geometry ) {
  19986. var outputAnimations = [];
  19987. // parse old style Bone/Hierarchy animations
  19988. var animations = [];
  19989. if ( json.animation !== undefined ) {
  19990. animations.push( json.animation );
  19991. }
  19992. if ( json.animations !== undefined ) {
  19993. if ( json.animations.length ) {
  19994. animations = animations.concat( json.animations );
  19995. } else {
  19996. animations.push( json.animations );
  19997. }
  19998. }
  19999. for ( var i = 0; i < animations.length; i ++ ) {
  20000. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  20001. if ( clip ) outputAnimations.push( clip );
  20002. }
  20003. // parse implicit morph animations
  20004. if ( geometry.morphTargets ) {
  20005. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  20006. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  20007. outputAnimations = outputAnimations.concat( morphAnimationClips );
  20008. }
  20009. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  20010. }
  20011. return function ( json, texturePath ) {
  20012. if ( json.data !== undefined ) {
  20013. // Geometry 4.0 spec
  20014. json = json.data;
  20015. }
  20016. if ( json.scale !== undefined ) {
  20017. json.scale = 1.0 / json.scale;
  20018. } else {
  20019. json.scale = 1.0;
  20020. }
  20021. var geometry = new Geometry();
  20022. parseModel( json, geometry );
  20023. parseSkin( json, geometry );
  20024. parseMorphing( json, geometry );
  20025. parseAnimations( json, geometry );
  20026. geometry.computeFaceNormals();
  20027. geometry.computeBoundingSphere();
  20028. if ( json.materials === undefined || json.materials.length === 0 ) {
  20029. return { geometry: geometry };
  20030. } else {
  20031. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  20032. return { geometry: geometry, materials: materials };
  20033. }
  20034. };
  20035. } )()
  20036. } );
  20037. /**
  20038. * @author mrdoob / http://mrdoob.com/
  20039. */
  20040. function ObjectLoader( manager ) {
  20041. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20042. this.texturePath = '';
  20043. }
  20044. Object.assign( ObjectLoader.prototype, {
  20045. load: function ( url, onLoad, onProgress, onError ) {
  20046. if ( this.texturePath === '' ) {
  20047. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  20048. }
  20049. var scope = this;
  20050. var loader = new FileLoader( scope.manager );
  20051. loader.load( url, function ( text ) {
  20052. var json = null;
  20053. try {
  20054. json = JSON.parse( text );
  20055. } catch ( error ) {
  20056. if ( onError !== undefined ) onError( error );
  20057. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  20058. return;
  20059. }
  20060. var metadata = json.metadata;
  20061. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  20062. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  20063. return;
  20064. }
  20065. scope.parse( json, onLoad );
  20066. }, onProgress, onError );
  20067. },
  20068. setTexturePath: function ( value ) {
  20069. this.texturePath = value;
  20070. },
  20071. setCrossOrigin: function ( value ) {
  20072. this.crossOrigin = value;
  20073. },
  20074. parse: function ( json, onLoad ) {
  20075. var geometries = this.parseGeometries( json.geometries );
  20076. var images = this.parseImages( json.images, function () {
  20077. if ( onLoad !== undefined ) onLoad( object );
  20078. } );
  20079. var textures = this.parseTextures( json.textures, images );
  20080. var materials = this.parseMaterials( json.materials, textures );
  20081. var object = this.parseObject( json.object, geometries, materials );
  20082. if ( json.animations ) {
  20083. object.animations = this.parseAnimations( json.animations );
  20084. }
  20085. if ( json.images === undefined || json.images.length === 0 ) {
  20086. if ( onLoad !== undefined ) onLoad( object );
  20087. }
  20088. return object;
  20089. },
  20090. parseGeometries: function ( json ) {
  20091. var geometries = {};
  20092. if ( json !== undefined ) {
  20093. var geometryLoader = new JSONLoader();
  20094. var bufferGeometryLoader = new BufferGeometryLoader();
  20095. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20096. var geometry;
  20097. var data = json[ i ];
  20098. switch ( data.type ) {
  20099. case 'PlaneGeometry':
  20100. case 'PlaneBufferGeometry':
  20101. geometry = new Geometries[ data.type ](
  20102. data.width,
  20103. data.height,
  20104. data.widthSegments,
  20105. data.heightSegments
  20106. );
  20107. break;
  20108. case 'BoxGeometry':
  20109. case 'BoxBufferGeometry':
  20110. case 'CubeGeometry': // backwards compatible
  20111. geometry = new Geometries[ data.type ](
  20112. data.width,
  20113. data.height,
  20114. data.depth,
  20115. data.widthSegments,
  20116. data.heightSegments,
  20117. data.depthSegments
  20118. );
  20119. break;
  20120. case 'CircleGeometry':
  20121. case 'CircleBufferGeometry':
  20122. geometry = new Geometries[ data.type ](
  20123. data.radius,
  20124. data.segments,
  20125. data.thetaStart,
  20126. data.thetaLength
  20127. );
  20128. break;
  20129. case 'CylinderGeometry':
  20130. case 'CylinderBufferGeometry':
  20131. geometry = new Geometries[ data.type ](
  20132. data.radiusTop,
  20133. data.radiusBottom,
  20134. data.height,
  20135. data.radialSegments,
  20136. data.heightSegments,
  20137. data.openEnded,
  20138. data.thetaStart,
  20139. data.thetaLength
  20140. );
  20141. break;
  20142. case 'ConeGeometry':
  20143. case 'ConeBufferGeometry':
  20144. geometry = new Geometries[ data.type ](
  20145. data.radius,
  20146. data.height,
  20147. data.radialSegments,
  20148. data.heightSegments,
  20149. data.openEnded,
  20150. data.thetaStart,
  20151. data.thetaLength
  20152. );
  20153. break;
  20154. case 'SphereGeometry':
  20155. case 'SphereBufferGeometry':
  20156. geometry = new Geometries[ data.type ](
  20157. data.radius,
  20158. data.widthSegments,
  20159. data.heightSegments,
  20160. data.phiStart,
  20161. data.phiLength,
  20162. data.thetaStart,
  20163. data.thetaLength
  20164. );
  20165. break;
  20166. case 'DodecahedronGeometry':
  20167. case 'IcosahedronGeometry':
  20168. case 'OctahedronGeometry':
  20169. case 'TetrahedronGeometry':
  20170. geometry = new Geometries[ data.type ](
  20171. data.radius,
  20172. data.detail
  20173. );
  20174. break;
  20175. case 'RingGeometry':
  20176. case 'RingBufferGeometry':
  20177. geometry = new Geometries[ data.type ](
  20178. data.innerRadius,
  20179. data.outerRadius,
  20180. data.thetaSegments,
  20181. data.phiSegments,
  20182. data.thetaStart,
  20183. data.thetaLength
  20184. );
  20185. break;
  20186. case 'TorusGeometry':
  20187. case 'TorusBufferGeometry':
  20188. geometry = new Geometries[ data.type ](
  20189. data.radius,
  20190. data.tube,
  20191. data.radialSegments,
  20192. data.tubularSegments,
  20193. data.arc
  20194. );
  20195. break;
  20196. case 'TorusKnotGeometry':
  20197. case 'TorusKnotBufferGeometry':
  20198. geometry = new Geometries[ data.type ](
  20199. data.radius,
  20200. data.tube,
  20201. data.tubularSegments,
  20202. data.radialSegments,
  20203. data.p,
  20204. data.q
  20205. );
  20206. break;
  20207. case 'LatheGeometry':
  20208. case 'LatheBufferGeometry':
  20209. geometry = new Geometries[ data.type ](
  20210. data.points,
  20211. data.segments,
  20212. data.phiStart,
  20213. data.phiLength
  20214. );
  20215. break;
  20216. case 'BufferGeometry':
  20217. geometry = bufferGeometryLoader.parse( data );
  20218. break;
  20219. case 'Geometry':
  20220. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  20221. break;
  20222. default:
  20223. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  20224. continue;
  20225. }
  20226. geometry.uuid = data.uuid;
  20227. if ( data.name !== undefined ) geometry.name = data.name;
  20228. geometries[ data.uuid ] = geometry;
  20229. }
  20230. }
  20231. return geometries;
  20232. },
  20233. parseMaterials: function ( json, textures ) {
  20234. var materials = {};
  20235. if ( json !== undefined ) {
  20236. var loader = new MaterialLoader();
  20237. loader.setTextures( textures );
  20238. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20239. var data = json[ i ];
  20240. if ( data.type === 'MultiMaterial' ) {
  20241. // Deprecated
  20242. var array = [];
  20243. for ( var j = 0; j < data.materials.length; j ++ ) {
  20244. array.push( loader.parse( data.materials[ j ] ) );
  20245. }
  20246. materials[ data.uuid ] = array;
  20247. } else {
  20248. materials[ data.uuid ] = loader.parse( data );
  20249. }
  20250. }
  20251. }
  20252. return materials;
  20253. },
  20254. parseAnimations: function ( json ) {
  20255. var animations = [];
  20256. for ( var i = 0; i < json.length; i ++ ) {
  20257. var clip = AnimationClip.parse( json[ i ] );
  20258. animations.push( clip );
  20259. }
  20260. return animations;
  20261. },
  20262. parseImages: function ( json, onLoad ) {
  20263. var scope = this;
  20264. var images = {};
  20265. function loadImage( url ) {
  20266. scope.manager.itemStart( url );
  20267. return loader.load( url, function () {
  20268. scope.manager.itemEnd( url );
  20269. }, undefined, function () {
  20270. scope.manager.itemEnd( url );
  20271. scope.manager.itemError( url );
  20272. } );
  20273. }
  20274. if ( json !== undefined && json.length > 0 ) {
  20275. var manager = new LoadingManager( onLoad );
  20276. var loader = new ImageLoader( manager );
  20277. loader.setCrossOrigin( this.crossOrigin );
  20278. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20279. var image = json[ i ];
  20280. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  20281. images[ image.uuid ] = loadImage( path );
  20282. }
  20283. }
  20284. return images;
  20285. },
  20286. parseTextures: function ( json, images ) {
  20287. function parseConstant( value, type ) {
  20288. if ( typeof( value ) === 'number' ) return value;
  20289. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  20290. return type[ value ];
  20291. }
  20292. var textures = {};
  20293. if ( json !== undefined ) {
  20294. for ( var i = 0, l = json.length; i < l; i ++ ) {
  20295. var data = json[ i ];
  20296. if ( data.image === undefined ) {
  20297. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  20298. }
  20299. if ( images[ data.image ] === undefined ) {
  20300. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  20301. }
  20302. var texture = new Texture( images[ data.image ] );
  20303. texture.needsUpdate = true;
  20304. texture.uuid = data.uuid;
  20305. if ( data.name !== undefined ) texture.name = data.name;
  20306. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  20307. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  20308. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  20309. if ( data.wrap !== undefined ) {
  20310. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  20311. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  20312. }
  20313. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  20314. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  20315. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  20316. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  20317. textures[ data.uuid ] = texture;
  20318. }
  20319. }
  20320. return textures;
  20321. },
  20322. parseObject: function () {
  20323. var matrix = new Matrix4();
  20324. return function parseObject( data, geometries, materials ) {
  20325. var object;
  20326. function getGeometry( name ) {
  20327. if ( geometries[ name ] === undefined ) {
  20328. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  20329. }
  20330. return geometries[ name ];
  20331. }
  20332. function getMaterial( name ) {
  20333. if ( name === undefined ) return undefined;
  20334. if ( Array.isArray( name ) ) {
  20335. var array = [];
  20336. for ( var i = 0, l = name.length; i < l; i ++ ) {
  20337. var uuid = name[ i ];
  20338. if ( materials[ uuid ] === undefined ) {
  20339. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  20340. }
  20341. array.push( materials[ uuid ] );
  20342. }
  20343. return array;
  20344. }
  20345. if ( materials[ name ] === undefined ) {
  20346. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  20347. }
  20348. return materials[ name ];
  20349. }
  20350. switch ( data.type ) {
  20351. case 'Scene':
  20352. object = new Scene();
  20353. if ( data.background !== undefined ) {
  20354. if ( Number.isInteger( data.background ) ) {
  20355. object.background = new Color( data.background );
  20356. }
  20357. }
  20358. if ( data.fog !== undefined ) {
  20359. if ( data.fog.type === 'Fog' ) {
  20360. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  20361. } else if ( data.fog.type === 'FogExp2' ) {
  20362. object.fog = new FogExp2( data.fog.color, data.fog.density );
  20363. }
  20364. }
  20365. break;
  20366. case 'PerspectiveCamera':
  20367. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  20368. if ( data.focus !== undefined ) object.focus = data.focus;
  20369. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  20370. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  20371. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  20372. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  20373. break;
  20374. case 'OrthographicCamera':
  20375. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  20376. break;
  20377. case 'AmbientLight':
  20378. object = new AmbientLight( data.color, data.intensity );
  20379. break;
  20380. case 'DirectionalLight':
  20381. object = new DirectionalLight( data.color, data.intensity );
  20382. break;
  20383. case 'PointLight':
  20384. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  20385. break;
  20386. case 'RectAreaLight':
  20387. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  20388. break;
  20389. case 'SpotLight':
  20390. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  20391. break;
  20392. case 'HemisphereLight':
  20393. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  20394. break;
  20395. case 'SkinnedMesh':
  20396. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  20397. case 'Mesh':
  20398. var geometry = getGeometry( data.geometry );
  20399. var material = getMaterial( data.material );
  20400. if ( geometry.bones && geometry.bones.length > 0 ) {
  20401. object = new SkinnedMesh( geometry, material );
  20402. } else {
  20403. object = new Mesh( geometry, material );
  20404. }
  20405. break;
  20406. case 'LOD':
  20407. object = new LOD();
  20408. break;
  20409. case 'Line':
  20410. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  20411. break;
  20412. case 'LineLoop':
  20413. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  20414. break;
  20415. case 'LineSegments':
  20416. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  20417. break;
  20418. case 'PointCloud':
  20419. case 'Points':
  20420. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  20421. break;
  20422. case 'Sprite':
  20423. object = new Sprite( getMaterial( data.material ) );
  20424. break;
  20425. case 'Group':
  20426. object = new Group();
  20427. break;
  20428. default:
  20429. object = new Object3D();
  20430. }
  20431. object.uuid = data.uuid;
  20432. if ( data.name !== undefined ) object.name = data.name;
  20433. if ( data.matrix !== undefined ) {
  20434. matrix.fromArray( data.matrix );
  20435. matrix.decompose( object.position, object.quaternion, object.scale );
  20436. } else {
  20437. if ( data.position !== undefined ) object.position.fromArray( data.position );
  20438. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  20439. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  20440. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  20441. }
  20442. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  20443. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  20444. if ( data.shadow ) {
  20445. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  20446. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  20447. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  20448. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  20449. }
  20450. if ( data.visible !== undefined ) object.visible = data.visible;
  20451. if ( data.userData !== undefined ) object.userData = data.userData;
  20452. if ( data.children !== undefined ) {
  20453. for ( var child in data.children ) {
  20454. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  20455. }
  20456. }
  20457. if ( data.type === 'LOD' ) {
  20458. var levels = data.levels;
  20459. for ( var l = 0; l < levels.length; l ++ ) {
  20460. var level = levels[ l ];
  20461. var child = object.getObjectByProperty( 'uuid', level.object );
  20462. if ( child !== undefined ) {
  20463. object.addLevel( child, level.distance );
  20464. }
  20465. }
  20466. }
  20467. return object;
  20468. };
  20469. }()
  20470. } );
  20471. var TEXTURE_MAPPING = {
  20472. UVMapping: UVMapping,
  20473. CubeReflectionMapping: CubeReflectionMapping,
  20474. CubeRefractionMapping: CubeRefractionMapping,
  20475. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  20476. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  20477. SphericalReflectionMapping: SphericalReflectionMapping,
  20478. CubeUVReflectionMapping: CubeUVReflectionMapping,
  20479. CubeUVRefractionMapping: CubeUVRefractionMapping
  20480. };
  20481. var TEXTURE_WRAPPING = {
  20482. RepeatWrapping: RepeatWrapping,
  20483. ClampToEdgeWrapping: ClampToEdgeWrapping,
  20484. MirroredRepeatWrapping: MirroredRepeatWrapping
  20485. };
  20486. var TEXTURE_FILTER = {
  20487. NearestFilter: NearestFilter,
  20488. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  20489. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  20490. LinearFilter: LinearFilter,
  20491. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  20492. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  20493. };
  20494. /**
  20495. * @author zz85 / http://www.lab4games.net/zz85/blog
  20496. *
  20497. * Bezier Curves formulas obtained from
  20498. * http://en.wikipedia.org/wiki/Bézier_curve
  20499. */
  20500. function CatmullRom( t, p0, p1, p2, p3 ) {
  20501. var v0 = ( p2 - p0 ) * 0.5;
  20502. var v1 = ( p3 - p1 ) * 0.5;
  20503. var t2 = t * t;
  20504. var t3 = t * t2;
  20505. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  20506. }
  20507. //
  20508. function QuadraticBezierP0( t, p ) {
  20509. var k = 1 - t;
  20510. return k * k * p;
  20511. }
  20512. function QuadraticBezierP1( t, p ) {
  20513. return 2 * ( 1 - t ) * t * p;
  20514. }
  20515. function QuadraticBezierP2( t, p ) {
  20516. return t * t * p;
  20517. }
  20518. function QuadraticBezier( t, p0, p1, p2 ) {
  20519. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  20520. QuadraticBezierP2( t, p2 );
  20521. }
  20522. //
  20523. function CubicBezierP0( t, p ) {
  20524. var k = 1 - t;
  20525. return k * k * k * p;
  20526. }
  20527. function CubicBezierP1( t, p ) {
  20528. var k = 1 - t;
  20529. return 3 * k * k * t * p;
  20530. }
  20531. function CubicBezierP2( t, p ) {
  20532. return 3 * ( 1 - t ) * t * t * p;
  20533. }
  20534. function CubicBezierP3( t, p ) {
  20535. return t * t * t * p;
  20536. }
  20537. function CubicBezier( t, p0, p1, p2, p3 ) {
  20538. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  20539. CubicBezierP3( t, p3 );
  20540. }
  20541. /**
  20542. * @author zz85 / http://www.lab4games.net/zz85/blog
  20543. * Extensible curve object
  20544. *
  20545. * Some common of curve methods:
  20546. * .getPoint(t), getTangent(t)
  20547. * .getPointAt(u), getTangentAt(u)
  20548. * .getPoints(), .getSpacedPoints()
  20549. * .getLength()
  20550. * .updateArcLengths()
  20551. *
  20552. * This following curves inherit from THREE.Curve:
  20553. *
  20554. * -- 2D curves --
  20555. * THREE.ArcCurve
  20556. * THREE.CubicBezierCurve
  20557. * THREE.EllipseCurve
  20558. * THREE.LineCurve
  20559. * THREE.QuadraticBezierCurve
  20560. * THREE.SplineCurve
  20561. *
  20562. * -- 3D curves --
  20563. * THREE.CatmullRomCurve3
  20564. * THREE.CubicBezierCurve3
  20565. * THREE.LineCurve3
  20566. * THREE.QuadraticBezierCurve3
  20567. *
  20568. * A series of curves can be represented as a THREE.CurvePath.
  20569. *
  20570. **/
  20571. /**************************************************************
  20572. * Abstract Curve base class
  20573. **************************************************************/
  20574. function Curve() {
  20575. this.arcLengthDivisions = 200;
  20576. }
  20577. Object.assign( Curve.prototype, {
  20578. // Virtual base class method to overwrite and implement in subclasses
  20579. // - t [0 .. 1]
  20580. getPoint: function () {
  20581. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  20582. return null;
  20583. },
  20584. // Get point at relative position in curve according to arc length
  20585. // - u [0 .. 1]
  20586. getPointAt: function ( u ) {
  20587. var t = this.getUtoTmapping( u );
  20588. return this.getPoint( t );
  20589. },
  20590. // Get sequence of points using getPoint( t )
  20591. getPoints: function ( divisions ) {
  20592. if ( divisions === undefined ) divisions = 5;
  20593. var points = [];
  20594. for ( var d = 0; d <= divisions; d ++ ) {
  20595. points.push( this.getPoint( d / divisions ) );
  20596. }
  20597. return points;
  20598. },
  20599. // Get sequence of points using getPointAt( u )
  20600. getSpacedPoints: function ( divisions ) {
  20601. if ( divisions === undefined ) divisions = 5;
  20602. var points = [];
  20603. for ( var d = 0; d <= divisions; d ++ ) {
  20604. points.push( this.getPointAt( d / divisions ) );
  20605. }
  20606. return points;
  20607. },
  20608. // Get total curve arc length
  20609. getLength: function () {
  20610. var lengths = this.getLengths();
  20611. return lengths[ lengths.length - 1 ];
  20612. },
  20613. // Get list of cumulative segment lengths
  20614. getLengths: function ( divisions ) {
  20615. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  20616. if ( this.cacheArcLengths &&
  20617. ( this.cacheArcLengths.length === divisions + 1 ) &&
  20618. ! this.needsUpdate ) {
  20619. return this.cacheArcLengths;
  20620. }
  20621. this.needsUpdate = false;
  20622. var cache = [];
  20623. var current, last = this.getPoint( 0 );
  20624. var p, sum = 0;
  20625. cache.push( 0 );
  20626. for ( p = 1; p <= divisions; p ++ ) {
  20627. current = this.getPoint( p / divisions );
  20628. sum += current.distanceTo( last );
  20629. cache.push( sum );
  20630. last = current;
  20631. }
  20632. this.cacheArcLengths = cache;
  20633. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  20634. },
  20635. updateArcLengths: function () {
  20636. this.needsUpdate = true;
  20637. this.getLengths();
  20638. },
  20639. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20640. getUtoTmapping: function ( u, distance ) {
  20641. var arcLengths = this.getLengths();
  20642. var i = 0, il = arcLengths.length;
  20643. var targetArcLength; // The targeted u distance value to get
  20644. if ( distance ) {
  20645. targetArcLength = distance;
  20646. } else {
  20647. targetArcLength = u * arcLengths[ il - 1 ];
  20648. }
  20649. // binary search for the index with largest value smaller than target u distance
  20650. var low = 0, high = il - 1, comparison;
  20651. while ( low <= high ) {
  20652. 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
  20653. comparison = arcLengths[ i ] - targetArcLength;
  20654. if ( comparison < 0 ) {
  20655. low = i + 1;
  20656. } else if ( comparison > 0 ) {
  20657. high = i - 1;
  20658. } else {
  20659. high = i;
  20660. break;
  20661. // DONE
  20662. }
  20663. }
  20664. i = high;
  20665. if ( arcLengths[ i ] === targetArcLength ) {
  20666. return i / ( il - 1 );
  20667. }
  20668. // we could get finer grain at lengths, or use simple interpolation between two points
  20669. var lengthBefore = arcLengths[ i ];
  20670. var lengthAfter = arcLengths[ i + 1 ];
  20671. var segmentLength = lengthAfter - lengthBefore;
  20672. // determine where we are between the 'before' and 'after' points
  20673. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20674. // add that fractional amount to t
  20675. var t = ( i + segmentFraction ) / ( il - 1 );
  20676. return t;
  20677. },
  20678. // Returns a unit vector tangent at t
  20679. // In case any sub curve does not implement its tangent derivation,
  20680. // 2 points a small delta apart will be used to find its gradient
  20681. // which seems to give a reasonable approximation
  20682. getTangent: function ( t ) {
  20683. var delta = 0.0001;
  20684. var t1 = t - delta;
  20685. var t2 = t + delta;
  20686. // Capping in case of danger
  20687. if ( t1 < 0 ) t1 = 0;
  20688. if ( t2 > 1 ) t2 = 1;
  20689. var pt1 = this.getPoint( t1 );
  20690. var pt2 = this.getPoint( t2 );
  20691. var vec = pt2.clone().sub( pt1 );
  20692. return vec.normalize();
  20693. },
  20694. getTangentAt: function ( u ) {
  20695. var t = this.getUtoTmapping( u );
  20696. return this.getTangent( t );
  20697. },
  20698. computeFrenetFrames: function ( segments, closed ) {
  20699. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20700. var normal = new Vector3();
  20701. var tangents = [];
  20702. var normals = [];
  20703. var binormals = [];
  20704. var vec = new Vector3();
  20705. var mat = new Matrix4();
  20706. var i, u, theta;
  20707. // compute the tangent vectors for each segment on the curve
  20708. for ( i = 0; i <= segments; i ++ ) {
  20709. u = i / segments;
  20710. tangents[ i ] = this.getTangentAt( u );
  20711. tangents[ i ].normalize();
  20712. }
  20713. // select an initial normal vector perpendicular to the first tangent vector,
  20714. // and in the direction of the minimum tangent xyz component
  20715. normals[ 0 ] = new Vector3();
  20716. binormals[ 0 ] = new Vector3();
  20717. var min = Number.MAX_VALUE;
  20718. var tx = Math.abs( tangents[ 0 ].x );
  20719. var ty = Math.abs( tangents[ 0 ].y );
  20720. var tz = Math.abs( tangents[ 0 ].z );
  20721. if ( tx <= min ) {
  20722. min = tx;
  20723. normal.set( 1, 0, 0 );
  20724. }
  20725. if ( ty <= min ) {
  20726. min = ty;
  20727. normal.set( 0, 1, 0 );
  20728. }
  20729. if ( tz <= min ) {
  20730. normal.set( 0, 0, 1 );
  20731. }
  20732. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20733. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20734. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20735. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  20736. for ( i = 1; i <= segments; i ++ ) {
  20737. normals[ i ] = normals[ i - 1 ].clone();
  20738. binormals[ i ] = binormals[ i - 1 ].clone();
  20739. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20740. if ( vec.length() > Number.EPSILON ) {
  20741. vec.normalize();
  20742. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20743. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20744. }
  20745. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20746. }
  20747. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20748. if ( closed === true ) {
  20749. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  20750. theta /= segments;
  20751. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  20752. theta = - theta;
  20753. }
  20754. for ( i = 1; i <= segments; i ++ ) {
  20755. // twist a little...
  20756. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20757. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20758. }
  20759. }
  20760. return {
  20761. tangents: tangents,
  20762. normals: normals,
  20763. binormals: binormals
  20764. };
  20765. }
  20766. } );
  20767. function LineCurve( v1, v2 ) {
  20768. Curve.call( this );
  20769. this.v1 = v1;
  20770. this.v2 = v2;
  20771. }
  20772. LineCurve.prototype = Object.create( Curve.prototype );
  20773. LineCurve.prototype.constructor = LineCurve;
  20774. LineCurve.prototype.isLineCurve = true;
  20775. LineCurve.prototype.getPoint = function ( t ) {
  20776. if ( t === 1 ) {
  20777. return this.v2.clone();
  20778. }
  20779. var point = this.v2.clone().sub( this.v1 );
  20780. point.multiplyScalar( t ).add( this.v1 );
  20781. return point;
  20782. };
  20783. // Line curve is linear, so we can overwrite default getPointAt
  20784. LineCurve.prototype.getPointAt = function ( u ) {
  20785. return this.getPoint( u );
  20786. };
  20787. LineCurve.prototype.getTangent = function ( t ) {
  20788. var tangent = this.v2.clone().sub( this.v1 );
  20789. return tangent.normalize();
  20790. };
  20791. /**
  20792. * @author zz85 / http://www.lab4games.net/zz85/blog
  20793. *
  20794. **/
  20795. /**************************************************************
  20796. * Curved Path - a curve path is simply a array of connected
  20797. * curves, but retains the api of a curve
  20798. **************************************************************/
  20799. function CurvePath() {
  20800. Curve.call( this );
  20801. this.curves = [];
  20802. this.autoClose = false; // Automatically closes the path
  20803. }
  20804. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  20805. constructor: CurvePath,
  20806. add: function ( curve ) {
  20807. this.curves.push( curve );
  20808. },
  20809. closePath: function () {
  20810. // Add a line curve if start and end of lines are not connected
  20811. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20812. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20813. if ( ! startPoint.equals( endPoint ) ) {
  20814. this.curves.push( new LineCurve( endPoint, startPoint ) );
  20815. }
  20816. },
  20817. // To get accurate point with reference to
  20818. // entire path distance at time t,
  20819. // following has to be done:
  20820. // 1. Length of each sub path have to be known
  20821. // 2. Locate and identify type of curve
  20822. // 3. Get t for the curve
  20823. // 4. Return curve.getPointAt(t')
  20824. getPoint: function ( t ) {
  20825. var d = t * this.getLength();
  20826. var curveLengths = this.getCurveLengths();
  20827. var i = 0;
  20828. // To think about boundaries points.
  20829. while ( i < curveLengths.length ) {
  20830. if ( curveLengths[ i ] >= d ) {
  20831. var diff = curveLengths[ i ] - d;
  20832. var curve = this.curves[ i ];
  20833. var segmentLength = curve.getLength();
  20834. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  20835. return curve.getPointAt( u );
  20836. }
  20837. i ++;
  20838. }
  20839. return null;
  20840. // loop where sum != 0, sum > d , sum+1 <d
  20841. },
  20842. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20843. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20844. // getPoint() depends on getLength
  20845. getLength: function () {
  20846. var lens = this.getCurveLengths();
  20847. return lens[ lens.length - 1 ];
  20848. },
  20849. // cacheLengths must be recalculated.
  20850. updateArcLengths: function () {
  20851. this.needsUpdate = true;
  20852. this.cacheLengths = null;
  20853. this.getCurveLengths();
  20854. },
  20855. // Compute lengths and cache them
  20856. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20857. getCurveLengths: function () {
  20858. // We use cache values if curves and cache array are same length
  20859. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20860. return this.cacheLengths;
  20861. }
  20862. // Get length of sub-curve
  20863. // Push sums into cached array
  20864. var lengths = [], sums = 0;
  20865. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20866. sums += this.curves[ i ].getLength();
  20867. lengths.push( sums );
  20868. }
  20869. this.cacheLengths = lengths;
  20870. return lengths;
  20871. },
  20872. getSpacedPoints: function ( divisions ) {
  20873. if ( divisions === undefined ) divisions = 40;
  20874. var points = [];
  20875. for ( var i = 0; i <= divisions; i ++ ) {
  20876. points.push( this.getPoint( i / divisions ) );
  20877. }
  20878. if ( this.autoClose ) {
  20879. points.push( points[ 0 ] );
  20880. }
  20881. return points;
  20882. },
  20883. getPoints: function ( divisions ) {
  20884. divisions = divisions || 12;
  20885. var points = [], last;
  20886. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  20887. var curve = curves[ i ];
  20888. var resolution = (curve && curve.isEllipseCurve) ? divisions * 2
  20889. : (curve && curve.isLineCurve) ? 1
  20890. : (curve && curve.isSplineCurve) ? divisions * curve.points.length
  20891. : divisions;
  20892. var pts = curve.getPoints( resolution );
  20893. for ( var j = 0; j < pts.length; j++ ) {
  20894. var point = pts[ j ];
  20895. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  20896. points.push( point );
  20897. last = point;
  20898. }
  20899. }
  20900. if ( this.autoClose && points.length > 1 && !points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  20901. points.push( points[ 0 ] );
  20902. }
  20903. return points;
  20904. },
  20905. /**************************************************************
  20906. * Create Geometries Helpers
  20907. **************************************************************/
  20908. /// Generate geometry from path points (for Line or Points objects)
  20909. createPointsGeometry: function ( divisions ) {
  20910. var pts = this.getPoints( divisions );
  20911. return this.createGeometry( pts );
  20912. },
  20913. // Generate geometry from equidistant sampling along the path
  20914. createSpacedPointsGeometry: function ( divisions ) {
  20915. var pts = this.getSpacedPoints( divisions );
  20916. return this.createGeometry( pts );
  20917. },
  20918. createGeometry: function ( points ) {
  20919. var geometry = new Geometry();
  20920. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20921. var point = points[ i ];
  20922. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  20923. }
  20924. return geometry;
  20925. }
  20926. } );
  20927. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20928. Curve.call( this );
  20929. this.aX = aX;
  20930. this.aY = aY;
  20931. this.xRadius = xRadius;
  20932. this.yRadius = yRadius;
  20933. this.aStartAngle = aStartAngle;
  20934. this.aEndAngle = aEndAngle;
  20935. this.aClockwise = aClockwise;
  20936. this.aRotation = aRotation || 0;
  20937. }
  20938. EllipseCurve.prototype = Object.create( Curve.prototype );
  20939. EllipseCurve.prototype.constructor = EllipseCurve;
  20940. EllipseCurve.prototype.isEllipseCurve = true;
  20941. EllipseCurve.prototype.getPoint = function ( t ) {
  20942. var twoPi = Math.PI * 2;
  20943. var deltaAngle = this.aEndAngle - this.aStartAngle;
  20944. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  20945. // ensures that deltaAngle is 0 .. 2 PI
  20946. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  20947. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  20948. if ( deltaAngle < Number.EPSILON ) {
  20949. if ( samePoints ) {
  20950. deltaAngle = 0;
  20951. } else {
  20952. deltaAngle = twoPi;
  20953. }
  20954. }
  20955. if ( this.aClockwise === true && ! samePoints ) {
  20956. if ( deltaAngle === twoPi ) {
  20957. deltaAngle = - twoPi;
  20958. } else {
  20959. deltaAngle = deltaAngle - twoPi;
  20960. }
  20961. }
  20962. var angle = this.aStartAngle + t * deltaAngle;
  20963. var x = this.aX + this.xRadius * Math.cos( angle );
  20964. var y = this.aY + this.yRadius * Math.sin( angle );
  20965. if ( this.aRotation !== 0 ) {
  20966. var cos = Math.cos( this.aRotation );
  20967. var sin = Math.sin( this.aRotation );
  20968. var tx = x - this.aX;
  20969. var ty = y - this.aY;
  20970. // Rotate the point about the center of the ellipse.
  20971. x = tx * cos - ty * sin + this.aX;
  20972. y = tx * sin + ty * cos + this.aY;
  20973. }
  20974. return new Vector2( x, y );
  20975. };
  20976. function SplineCurve( points /* array of Vector2 */ ) {
  20977. Curve.call( this );
  20978. this.points = ( points === undefined ) ? [] : points;
  20979. }
  20980. SplineCurve.prototype = Object.create( Curve.prototype );
  20981. SplineCurve.prototype.constructor = SplineCurve;
  20982. SplineCurve.prototype.isSplineCurve = true;
  20983. SplineCurve.prototype.getPoint = function ( t ) {
  20984. var points = this.points;
  20985. var point = ( points.length - 1 ) * t;
  20986. var intPoint = Math.floor( point );
  20987. var weight = point - intPoint;
  20988. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20989. var point1 = points[ intPoint ];
  20990. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20991. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20992. return new Vector2(
  20993. CatmullRom( weight, point0.x, point1.x, point2.x, point3.x ),
  20994. CatmullRom( weight, point0.y, point1.y, point2.y, point3.y )
  20995. );
  20996. };
  20997. function CubicBezierCurve( v0, v1, v2, v3 ) {
  20998. Curve.call( this );
  20999. this.v0 = v0;
  21000. this.v1 = v1;
  21001. this.v2 = v2;
  21002. this.v3 = v3;
  21003. }
  21004. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21005. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21006. CubicBezierCurve.prototype.getPoint = function ( t ) {
  21007. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21008. return new Vector2(
  21009. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21010. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21011. );
  21012. };
  21013. function QuadraticBezierCurve( v0, v1, v2 ) {
  21014. Curve.call( this );
  21015. this.v0 = v0;
  21016. this.v1 = v1;
  21017. this.v2 = v2;
  21018. }
  21019. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21020. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21021. QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21022. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21023. return new Vector2(
  21024. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21025. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21026. );
  21027. };
  21028. var PathPrototype = Object.assign( Object.create( CurvePath.prototype ), {
  21029. fromPoints: function ( vectors ) {
  21030. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  21031. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  21032. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  21033. }
  21034. },
  21035. moveTo: function ( x, y ) {
  21036. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21037. },
  21038. lineTo: function ( x, y ) {
  21039. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  21040. this.curves.push( curve );
  21041. this.currentPoint.set( x, y );
  21042. },
  21043. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21044. var curve = new QuadraticBezierCurve(
  21045. this.currentPoint.clone(),
  21046. new Vector2( aCPx, aCPy ),
  21047. new Vector2( aX, aY )
  21048. );
  21049. this.curves.push( curve );
  21050. this.currentPoint.set( aX, aY );
  21051. },
  21052. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21053. var curve = new CubicBezierCurve(
  21054. this.currentPoint.clone(),
  21055. new Vector2( aCP1x, aCP1y ),
  21056. new Vector2( aCP2x, aCP2y ),
  21057. new Vector2( aX, aY )
  21058. );
  21059. this.curves.push( curve );
  21060. this.currentPoint.set( aX, aY );
  21061. },
  21062. splineThru: function ( pts /*Array of Vector*/ ) {
  21063. var npts = [ this.currentPoint.clone() ].concat( pts );
  21064. var curve = new SplineCurve( npts );
  21065. this.curves.push( curve );
  21066. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21067. },
  21068. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21069. var x0 = this.currentPoint.x;
  21070. var y0 = this.currentPoint.y;
  21071. this.absarc( aX + x0, aY + y0, aRadius,
  21072. aStartAngle, aEndAngle, aClockwise );
  21073. },
  21074. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21075. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21076. },
  21077. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21078. var x0 = this.currentPoint.x;
  21079. var y0 = this.currentPoint.y;
  21080. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21081. },
  21082. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21083. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21084. if ( this.curves.length > 0 ) {
  21085. // if a previous curve is present, attempt to join
  21086. var firstPoint = curve.getPoint( 0 );
  21087. if ( ! firstPoint.equals( this.currentPoint ) ) {
  21088. this.lineTo( firstPoint.x, firstPoint.y );
  21089. }
  21090. }
  21091. this.curves.push( curve );
  21092. var lastPoint = curve.getPoint( 1 );
  21093. this.currentPoint.copy( lastPoint );
  21094. }
  21095. } );
  21096. /**
  21097. * @author zz85 / http://www.lab4games.net/zz85/blog
  21098. * Creates free form 2d path using series of points, lines or curves.
  21099. **/
  21100. function Path( points ) {
  21101. CurvePath.call( this );
  21102. this.currentPoint = new Vector2();
  21103. if ( points ) {
  21104. this.fromPoints( points );
  21105. }
  21106. }
  21107. Path.prototype = PathPrototype;
  21108. PathPrototype.constructor = Path;
  21109. /**
  21110. * @author zz85 / http://www.lab4games.net/zz85/blog
  21111. * Defines a 2d shape plane using paths.
  21112. **/
  21113. // STEP 1 Create a path.
  21114. // STEP 2 Turn path into shape.
  21115. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21116. // STEP 3a - Extract points from each shape, turn to vertices
  21117. // STEP 3b - Triangulate each shape, add faces.
  21118. function Shape() {
  21119. Path.apply( this, arguments );
  21120. this.holes = [];
  21121. }
  21122. Shape.prototype = Object.assign( Object.create( PathPrototype ), {
  21123. constructor: Shape,
  21124. getPointsHoles: function ( divisions ) {
  21125. var holesPts = [];
  21126. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21127. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21128. }
  21129. return holesPts;
  21130. },
  21131. // Get points of shape and holes (keypoints based on segments parameter)
  21132. extractAllPoints: function ( divisions ) {
  21133. return {
  21134. shape: this.getPoints( divisions ),
  21135. holes: this.getPointsHoles( divisions )
  21136. };
  21137. },
  21138. extractPoints: function ( divisions ) {
  21139. return this.extractAllPoints( divisions );
  21140. }
  21141. } );
  21142. /**
  21143. * @author zz85 / http://www.lab4games.net/zz85/blog
  21144. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  21145. **/
  21146. function ShapePath() {
  21147. this.subPaths = [];
  21148. this.currentPath = null;
  21149. }
  21150. Object.assign( ShapePath.prototype, {
  21151. moveTo: function ( x, y ) {
  21152. this.currentPath = new Path();
  21153. this.subPaths.push( this.currentPath );
  21154. this.currentPath.moveTo( x, y );
  21155. },
  21156. lineTo: function ( x, y ) {
  21157. this.currentPath.lineTo( x, y );
  21158. },
  21159. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21160. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21161. },
  21162. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21163. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21164. },
  21165. splineThru: function ( pts ) {
  21166. this.currentPath.splineThru( pts );
  21167. },
  21168. toShapes: function ( isCCW, noHoles ) {
  21169. function toShapesNoHoles( inSubpaths ) {
  21170. var shapes = [];
  21171. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21172. var tmpPath = inSubpaths[ i ];
  21173. var tmpShape = new Shape();
  21174. tmpShape.curves = tmpPath.curves;
  21175. shapes.push( tmpShape );
  21176. }
  21177. return shapes;
  21178. }
  21179. function isPointInsidePolygon( inPt, inPolygon ) {
  21180. var polyLen = inPolygon.length;
  21181. // inPt on polygon contour => immediate success or
  21182. // toggling of inside/outside at every single! intersection point of an edge
  21183. // with the horizontal line through inPt, left of inPt
  21184. // not counting lowerY endpoints of edges and whole edges on that line
  21185. var inside = false;
  21186. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21187. var edgeLowPt = inPolygon[ p ];
  21188. var edgeHighPt = inPolygon[ q ];
  21189. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21190. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21191. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21192. // not parallel
  21193. if ( edgeDy < 0 ) {
  21194. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21195. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21196. }
  21197. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21198. if ( inPt.y === edgeLowPt.y ) {
  21199. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21200. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21201. } else {
  21202. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21203. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21204. if ( perpEdge < 0 ) continue;
  21205. inside = ! inside; // true intersection left of inPt
  21206. }
  21207. } else {
  21208. // parallel or collinear
  21209. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21210. // edge lies on the same horizontal line as inPt
  21211. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21212. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21213. // continue;
  21214. }
  21215. }
  21216. return inside;
  21217. }
  21218. var isClockWise = ShapeUtils.isClockWise;
  21219. var subPaths = this.subPaths;
  21220. if ( subPaths.length === 0 ) return [];
  21221. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21222. var solid, tmpPath, tmpShape, shapes = [];
  21223. if ( subPaths.length === 1 ) {
  21224. tmpPath = subPaths[ 0 ];
  21225. tmpShape = new Shape();
  21226. tmpShape.curves = tmpPath.curves;
  21227. shapes.push( tmpShape );
  21228. return shapes;
  21229. }
  21230. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21231. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21232. // console.log("Holes first", holesFirst);
  21233. var betterShapeHoles = [];
  21234. var newShapes = [];
  21235. var newShapeHoles = [];
  21236. var mainIdx = 0;
  21237. var tmpPoints;
  21238. newShapes[ mainIdx ] = undefined;
  21239. newShapeHoles[ mainIdx ] = [];
  21240. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21241. tmpPath = subPaths[ i ];
  21242. tmpPoints = tmpPath.getPoints();
  21243. solid = isClockWise( tmpPoints );
  21244. solid = isCCW ? ! solid : solid;
  21245. if ( solid ) {
  21246. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21247. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  21248. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21249. if ( holesFirst ) mainIdx ++;
  21250. newShapeHoles[ mainIdx ] = [];
  21251. //console.log('cw', i);
  21252. } else {
  21253. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21254. //console.log('ccw', i);
  21255. }
  21256. }
  21257. // only Holes? -> probably all Shapes with wrong orientation
  21258. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21259. if ( newShapes.length > 1 ) {
  21260. var ambiguous = false;
  21261. var toChange = [];
  21262. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21263. betterShapeHoles[ sIdx ] = [];
  21264. }
  21265. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21266. var sho = newShapeHoles[ sIdx ];
  21267. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21268. var ho = sho[ hIdx ];
  21269. var hole_unassigned = true;
  21270. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21271. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21272. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21273. if ( hole_unassigned ) {
  21274. hole_unassigned = false;
  21275. betterShapeHoles[ s2Idx ].push( ho );
  21276. } else {
  21277. ambiguous = true;
  21278. }
  21279. }
  21280. }
  21281. if ( hole_unassigned ) {
  21282. betterShapeHoles[ sIdx ].push( ho );
  21283. }
  21284. }
  21285. }
  21286. // console.log("ambiguous: ", ambiguous);
  21287. if ( toChange.length > 0 ) {
  21288. // console.log("to change: ", toChange);
  21289. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21290. }
  21291. }
  21292. var tmpHoles;
  21293. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21294. tmpShape = newShapes[ i ].s;
  21295. shapes.push( tmpShape );
  21296. tmpHoles = newShapeHoles[ i ];
  21297. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21298. tmpShape.holes.push( tmpHoles[ j ].h );
  21299. }
  21300. }
  21301. //console.log("shape", shapes);
  21302. return shapes;
  21303. }
  21304. } );
  21305. /**
  21306. * @author zz85 / http://www.lab4games.net/zz85/blog
  21307. * @author mrdoob / http://mrdoob.com/
  21308. */
  21309. function Font( data ) {
  21310. this.data = data;
  21311. }
  21312. Object.assign( Font.prototype, {
  21313. isFont: true,
  21314. generateShapes: function ( text, size, divisions ) {
  21315. function createPaths( text ) {
  21316. var chars = String( text ).split( '' );
  21317. var scale = size / data.resolution;
  21318. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  21319. var offsetX = 0, offsetY = 0;
  21320. var paths = [];
  21321. for ( var i = 0; i < chars.length; i ++ ) {
  21322. var char = chars[ i ];
  21323. if ( char === '\n' ) {
  21324. offsetX = 0;
  21325. offsetY -= line_height;
  21326. } else {
  21327. var ret = createPath( char, scale, offsetX, offsetY );
  21328. offsetX += ret.offsetX;
  21329. paths.push( ret.path );
  21330. }
  21331. }
  21332. return paths;
  21333. }
  21334. function createPath( c, scale, offsetX, offsetY ) {
  21335. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  21336. if ( ! glyph ) return;
  21337. var path = new ShapePath();
  21338. var pts = [];
  21339. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  21340. if ( glyph.o ) {
  21341. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  21342. for ( var i = 0, l = outline.length; i < l; ) {
  21343. var action = outline[ i ++ ];
  21344. switch ( action ) {
  21345. case 'm': // moveTo
  21346. x = outline[ i ++ ] * scale + offsetX;
  21347. y = outline[ i ++ ] * scale + offsetY;
  21348. path.moveTo( x, y );
  21349. break;
  21350. case 'l': // lineTo
  21351. x = outline[ i ++ ] * scale + offsetX;
  21352. y = outline[ i ++ ] * scale + offsetY;
  21353. path.lineTo( x, y );
  21354. break;
  21355. case 'q': // quadraticCurveTo
  21356. cpx = outline[ i ++ ] * scale + offsetX;
  21357. cpy = outline[ i ++ ] * scale + offsetY;
  21358. cpx1 = outline[ i ++ ] * scale + offsetX;
  21359. cpy1 = outline[ i ++ ] * scale + offsetY;
  21360. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  21361. laste = pts[ pts.length - 1 ];
  21362. if ( laste ) {
  21363. cpx0 = laste.x;
  21364. cpy0 = laste.y;
  21365. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21366. var t = i2 / divisions;
  21367. QuadraticBezier( t, cpx0, cpx1, cpx );
  21368. QuadraticBezier( t, cpy0, cpy1, cpy );
  21369. }
  21370. }
  21371. break;
  21372. case 'b': // bezierCurveTo
  21373. cpx = outline[ i ++ ] * scale + offsetX;
  21374. cpy = outline[ i ++ ] * scale + offsetY;
  21375. cpx1 = outline[ i ++ ] * scale + offsetX;
  21376. cpy1 = outline[ i ++ ] * scale + offsetY;
  21377. cpx2 = outline[ i ++ ] * scale + offsetX;
  21378. cpy2 = outline[ i ++ ] * scale + offsetY;
  21379. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  21380. laste = pts[ pts.length - 1 ];
  21381. if ( laste ) {
  21382. cpx0 = laste.x;
  21383. cpy0 = laste.y;
  21384. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21385. var t = i2 / divisions;
  21386. CubicBezier( t, cpx0, cpx1, cpx2, cpx );
  21387. CubicBezier( t, cpy0, cpy1, cpy2, cpy );
  21388. }
  21389. }
  21390. break;
  21391. }
  21392. }
  21393. }
  21394. return { offsetX: glyph.ha * scale, path: path };
  21395. }
  21396. //
  21397. if ( size === undefined ) size = 100;
  21398. if ( divisions === undefined ) divisions = 4;
  21399. var data = this.data;
  21400. var paths = createPaths( text );
  21401. var shapes = [];
  21402. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  21403. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  21404. }
  21405. return shapes;
  21406. }
  21407. } );
  21408. /**
  21409. * @author mrdoob / http://mrdoob.com/
  21410. */
  21411. function FontLoader( manager ) {
  21412. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21413. }
  21414. Object.assign( FontLoader.prototype, {
  21415. load: function ( url, onLoad, onProgress, onError ) {
  21416. var scope = this;
  21417. var loader = new FileLoader( this.manager );
  21418. loader.load( url, function ( text ) {
  21419. var json;
  21420. try {
  21421. json = JSON.parse( text );
  21422. } catch ( e ) {
  21423. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  21424. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  21425. }
  21426. var font = scope.parse( json );
  21427. if ( onLoad ) onLoad( font );
  21428. }, onProgress, onError );
  21429. },
  21430. parse: function ( json ) {
  21431. return new Font( json );
  21432. }
  21433. } );
  21434. var context;
  21435. var AudioContext = {
  21436. getContext: function () {
  21437. if ( context === undefined ) {
  21438. context = new ( window.AudioContext || window.webkitAudioContext )();
  21439. }
  21440. return context;
  21441. },
  21442. setContext: function ( value ) {
  21443. context = value;
  21444. }
  21445. };
  21446. /**
  21447. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  21448. */
  21449. function AudioLoader( manager ) {
  21450. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21451. }
  21452. Object.assign( AudioLoader.prototype, {
  21453. load: function ( url, onLoad, onProgress, onError ) {
  21454. var loader = new FileLoader( this.manager );
  21455. loader.setResponseType( 'arraybuffer' );
  21456. loader.load( url, function ( buffer ) {
  21457. var context = AudioContext.getContext();
  21458. context.decodeAudioData( buffer, function ( audioBuffer ) {
  21459. onLoad( audioBuffer );
  21460. } );
  21461. }, onProgress, onError );
  21462. }
  21463. } );
  21464. /**
  21465. * @author mrdoob / http://mrdoob.com/
  21466. */
  21467. function StereoCamera() {
  21468. this.type = 'StereoCamera';
  21469. this.aspect = 1;
  21470. this.eyeSep = 0.064;
  21471. this.cameraL = new PerspectiveCamera();
  21472. this.cameraL.layers.enable( 1 );
  21473. this.cameraL.matrixAutoUpdate = false;
  21474. this.cameraR = new PerspectiveCamera();
  21475. this.cameraR.layers.enable( 2 );
  21476. this.cameraR.matrixAutoUpdate = false;
  21477. }
  21478. Object.assign( StereoCamera.prototype, {
  21479. update: ( function () {
  21480. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  21481. var eyeRight = new Matrix4();
  21482. var eyeLeft = new Matrix4();
  21483. return function update( camera ) {
  21484. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  21485. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  21486. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  21487. if ( needsUpdate ) {
  21488. instance = this;
  21489. focus = camera.focus;
  21490. fov = camera.fov;
  21491. aspect = camera.aspect * this.aspect;
  21492. near = camera.near;
  21493. far = camera.far;
  21494. zoom = camera.zoom;
  21495. // Off-axis stereoscopic effect based on
  21496. // http://paulbourke.net/stereographics/stereorender/
  21497. var projectionMatrix = camera.projectionMatrix.clone();
  21498. eyeSep = this.eyeSep / 2;
  21499. var eyeSepOnProjection = eyeSep * near / focus;
  21500. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  21501. var xmin, xmax;
  21502. // translate xOffset
  21503. eyeLeft.elements[ 12 ] = - eyeSep;
  21504. eyeRight.elements[ 12 ] = eyeSep;
  21505. // for left eye
  21506. xmin = - ymax * aspect + eyeSepOnProjection;
  21507. xmax = ymax * aspect + eyeSepOnProjection;
  21508. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  21509. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  21510. this.cameraL.projectionMatrix.copy( projectionMatrix );
  21511. // for right eye
  21512. xmin = - ymax * aspect - eyeSepOnProjection;
  21513. xmax = ymax * aspect - eyeSepOnProjection;
  21514. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  21515. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  21516. this.cameraR.projectionMatrix.copy( projectionMatrix );
  21517. }
  21518. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  21519. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  21520. };
  21521. } )()
  21522. } );
  21523. /**
  21524. * Camera for rendering cube maps
  21525. * - renders scene into axis-aligned cube
  21526. *
  21527. * @author alteredq / http://alteredqualia.com/
  21528. */
  21529. function CubeCamera( near, far, cubeResolution ) {
  21530. Object3D.call( this );
  21531. this.type = 'CubeCamera';
  21532. var fov = 90, aspect = 1;
  21533. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  21534. cameraPX.up.set( 0, - 1, 0 );
  21535. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  21536. this.add( cameraPX );
  21537. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  21538. cameraNX.up.set( 0, - 1, 0 );
  21539. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  21540. this.add( cameraNX );
  21541. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  21542. cameraPY.up.set( 0, 0, 1 );
  21543. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  21544. this.add( cameraPY );
  21545. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  21546. cameraNY.up.set( 0, 0, - 1 );
  21547. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  21548. this.add( cameraNY );
  21549. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  21550. cameraPZ.up.set( 0, - 1, 0 );
  21551. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  21552. this.add( cameraPZ );
  21553. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  21554. cameraNZ.up.set( 0, - 1, 0 );
  21555. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  21556. this.add( cameraNZ );
  21557. var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  21558. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  21559. this.renderTarget.texture.name = "CubeCamera";
  21560. this.updateCubeMap = function ( renderer, scene ) {
  21561. if ( this.parent === null ) this.updateMatrixWorld();
  21562. var renderTarget = this.renderTarget;
  21563. var generateMipmaps = renderTarget.texture.generateMipmaps;
  21564. renderTarget.texture.generateMipmaps = false;
  21565. renderTarget.activeCubeFace = 0;
  21566. renderer.render( scene, cameraPX, renderTarget );
  21567. renderTarget.activeCubeFace = 1;
  21568. renderer.render( scene, cameraNX, renderTarget );
  21569. renderTarget.activeCubeFace = 2;
  21570. renderer.render( scene, cameraPY, renderTarget );
  21571. renderTarget.activeCubeFace = 3;
  21572. renderer.render( scene, cameraNY, renderTarget );
  21573. renderTarget.activeCubeFace = 4;
  21574. renderer.render( scene, cameraPZ, renderTarget );
  21575. renderTarget.texture.generateMipmaps = generateMipmaps;
  21576. renderTarget.activeCubeFace = 5;
  21577. renderer.render( scene, cameraNZ, renderTarget );
  21578. renderer.setRenderTarget( null );
  21579. };
  21580. }
  21581. CubeCamera.prototype = Object.create( Object3D.prototype );
  21582. CubeCamera.prototype.constructor = CubeCamera;
  21583. /**
  21584. * @author mrdoob / http://mrdoob.com/
  21585. */
  21586. function ArrayCamera( array ) {
  21587. PerspectiveCamera.call( this );
  21588. this.enabled = false;
  21589. this.cameras = array || [];
  21590. }
  21591. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  21592. constructor: ArrayCamera,
  21593. isArrayCamera: true
  21594. } );
  21595. /**
  21596. * @author mrdoob / http://mrdoob.com/
  21597. */
  21598. function AudioListener() {
  21599. Object3D.call( this );
  21600. this.type = 'AudioListener';
  21601. this.context = AudioContext.getContext();
  21602. this.gain = this.context.createGain();
  21603. this.gain.connect( this.context.destination );
  21604. this.filter = null;
  21605. }
  21606. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  21607. constructor: AudioListener,
  21608. getInput: function () {
  21609. return this.gain;
  21610. },
  21611. removeFilter: function ( ) {
  21612. if ( this.filter !== null ) {
  21613. this.gain.disconnect( this.filter );
  21614. this.filter.disconnect( this.context.destination );
  21615. this.gain.connect( this.context.destination );
  21616. this.filter = null;
  21617. }
  21618. },
  21619. getFilter: function () {
  21620. return this.filter;
  21621. },
  21622. setFilter: function ( value ) {
  21623. if ( this.filter !== null ) {
  21624. this.gain.disconnect( this.filter );
  21625. this.filter.disconnect( this.context.destination );
  21626. } else {
  21627. this.gain.disconnect( this.context.destination );
  21628. }
  21629. this.filter = value;
  21630. this.gain.connect( this.filter );
  21631. this.filter.connect( this.context.destination );
  21632. },
  21633. getMasterVolume: function () {
  21634. return this.gain.gain.value;
  21635. },
  21636. setMasterVolume: function ( value ) {
  21637. this.gain.gain.value = value;
  21638. },
  21639. updateMatrixWorld: ( function () {
  21640. var position = new Vector3();
  21641. var quaternion = new Quaternion();
  21642. var scale = new Vector3();
  21643. var orientation = new Vector3();
  21644. return function updateMatrixWorld( force ) {
  21645. Object3D.prototype.updateMatrixWorld.call( this, force );
  21646. var listener = this.context.listener;
  21647. var up = this.up;
  21648. this.matrixWorld.decompose( position, quaternion, scale );
  21649. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  21650. if ( listener.positionX ) {
  21651. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  21652. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  21653. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  21654. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  21655. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  21656. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  21657. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  21658. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  21659. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  21660. } else {
  21661. listener.setPosition( position.x, position.y, position.z );
  21662. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  21663. }
  21664. };
  21665. } )()
  21666. } );
  21667. /**
  21668. * @author mrdoob / http://mrdoob.com/
  21669. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  21670. */
  21671. function Audio( listener ) {
  21672. Object3D.call( this );
  21673. this.type = 'Audio';
  21674. this.context = listener.context;
  21675. this.gain = this.context.createGain();
  21676. this.gain.connect( listener.getInput() );
  21677. this.autoplay = false;
  21678. this.buffer = null;
  21679. this.loop = false;
  21680. this.startTime = 0;
  21681. this.playbackRate = 1;
  21682. this.isPlaying = false;
  21683. this.hasPlaybackControl = true;
  21684. this.sourceType = 'empty';
  21685. this.filters = [];
  21686. }
  21687. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  21688. constructor: Audio,
  21689. getOutput: function () {
  21690. return this.gain;
  21691. },
  21692. setNodeSource: function ( audioNode ) {
  21693. this.hasPlaybackControl = false;
  21694. this.sourceType = 'audioNode';
  21695. this.source = audioNode;
  21696. this.connect();
  21697. return this;
  21698. },
  21699. setBuffer: function ( audioBuffer ) {
  21700. this.buffer = audioBuffer;
  21701. this.sourceType = 'buffer';
  21702. if ( this.autoplay ) this.play();
  21703. return this;
  21704. },
  21705. play: function () {
  21706. if ( this.isPlaying === true ) {
  21707. console.warn( 'THREE.Audio: Audio is already playing.' );
  21708. return;
  21709. }
  21710. if ( this.hasPlaybackControl === false ) {
  21711. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21712. return;
  21713. }
  21714. var source = this.context.createBufferSource();
  21715. source.buffer = this.buffer;
  21716. source.loop = this.loop;
  21717. source.onended = this.onEnded.bind( this );
  21718. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  21719. source.start( 0, this.startTime );
  21720. this.isPlaying = true;
  21721. this.source = source;
  21722. return this.connect();
  21723. },
  21724. pause: function () {
  21725. if ( this.hasPlaybackControl === false ) {
  21726. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21727. return;
  21728. }
  21729. this.source.stop();
  21730. this.startTime = this.context.currentTime;
  21731. this.isPlaying = false;
  21732. return this;
  21733. },
  21734. stop: function () {
  21735. if ( this.hasPlaybackControl === false ) {
  21736. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21737. return;
  21738. }
  21739. this.source.stop();
  21740. this.startTime = 0;
  21741. this.isPlaying = false;
  21742. return this;
  21743. },
  21744. connect: function () {
  21745. if ( this.filters.length > 0 ) {
  21746. this.source.connect( this.filters[ 0 ] );
  21747. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  21748. this.filters[ i - 1 ].connect( this.filters[ i ] );
  21749. }
  21750. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  21751. } else {
  21752. this.source.connect( this.getOutput() );
  21753. }
  21754. return this;
  21755. },
  21756. disconnect: function () {
  21757. if ( this.filters.length > 0 ) {
  21758. this.source.disconnect( this.filters[ 0 ] );
  21759. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  21760. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  21761. }
  21762. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  21763. } else {
  21764. this.source.disconnect( this.getOutput() );
  21765. }
  21766. return this;
  21767. },
  21768. getFilters: function () {
  21769. return this.filters;
  21770. },
  21771. setFilters: function ( value ) {
  21772. if ( ! value ) value = [];
  21773. if ( this.isPlaying === true ) {
  21774. this.disconnect();
  21775. this.filters = value;
  21776. this.connect();
  21777. } else {
  21778. this.filters = value;
  21779. }
  21780. return this;
  21781. },
  21782. getFilter: function () {
  21783. return this.getFilters()[ 0 ];
  21784. },
  21785. setFilter: function ( filter ) {
  21786. return this.setFilters( filter ? [ filter ] : [] );
  21787. },
  21788. setPlaybackRate: function ( value ) {
  21789. if ( this.hasPlaybackControl === false ) {
  21790. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21791. return;
  21792. }
  21793. this.playbackRate = value;
  21794. if ( this.isPlaying === true ) {
  21795. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  21796. }
  21797. return this;
  21798. },
  21799. getPlaybackRate: function () {
  21800. return this.playbackRate;
  21801. },
  21802. onEnded: function () {
  21803. this.isPlaying = false;
  21804. },
  21805. getLoop: function () {
  21806. if ( this.hasPlaybackControl === false ) {
  21807. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21808. return false;
  21809. }
  21810. return this.loop;
  21811. },
  21812. setLoop: function ( value ) {
  21813. if ( this.hasPlaybackControl === false ) {
  21814. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  21815. return;
  21816. }
  21817. this.loop = value;
  21818. if ( this.isPlaying === true ) {
  21819. this.source.loop = this.loop;
  21820. }
  21821. return this;
  21822. },
  21823. getVolume: function () {
  21824. return this.gain.gain.value;
  21825. },
  21826. setVolume: function ( value ) {
  21827. this.gain.gain.value = value;
  21828. return this;
  21829. }
  21830. } );
  21831. /**
  21832. * @author mrdoob / http://mrdoob.com/
  21833. */
  21834. function PositionalAudio( listener ) {
  21835. Audio.call( this, listener );
  21836. this.panner = this.context.createPanner();
  21837. this.panner.connect( this.gain );
  21838. }
  21839. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  21840. constructor: PositionalAudio,
  21841. getOutput: function () {
  21842. return this.panner;
  21843. },
  21844. getRefDistance: function () {
  21845. return this.panner.refDistance;
  21846. },
  21847. setRefDistance: function ( value ) {
  21848. this.panner.refDistance = value;
  21849. },
  21850. getRolloffFactor: function () {
  21851. return this.panner.rolloffFactor;
  21852. },
  21853. setRolloffFactor: function ( value ) {
  21854. this.panner.rolloffFactor = value;
  21855. },
  21856. getDistanceModel: function () {
  21857. return this.panner.distanceModel;
  21858. },
  21859. setDistanceModel: function ( value ) {
  21860. this.panner.distanceModel = value;
  21861. },
  21862. getMaxDistance: function () {
  21863. return this.panner.maxDistance;
  21864. },
  21865. setMaxDistance: function ( value ) {
  21866. this.panner.maxDistance = value;
  21867. },
  21868. updateMatrixWorld: ( function () {
  21869. var position = new Vector3();
  21870. return function updateMatrixWorld( force ) {
  21871. Object3D.prototype.updateMatrixWorld.call( this, force );
  21872. position.setFromMatrixPosition( this.matrixWorld );
  21873. this.panner.setPosition( position.x, position.y, position.z );
  21874. };
  21875. } )()
  21876. } );
  21877. /**
  21878. * @author mrdoob / http://mrdoob.com/
  21879. */
  21880. function AudioAnalyser( audio, fftSize ) {
  21881. this.analyser = audio.context.createAnalyser();
  21882. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  21883. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  21884. audio.getOutput().connect( this.analyser );
  21885. }
  21886. Object.assign( AudioAnalyser.prototype, {
  21887. getFrequencyData: function () {
  21888. this.analyser.getByteFrequencyData( this.data );
  21889. return this.data;
  21890. },
  21891. getAverageFrequency: function () {
  21892. var value = 0, data = this.getFrequencyData();
  21893. for ( var i = 0; i < data.length; i ++ ) {
  21894. value += data[ i ];
  21895. }
  21896. return value / data.length;
  21897. }
  21898. } );
  21899. /**
  21900. *
  21901. * Buffered scene graph property that allows weighted accumulation.
  21902. *
  21903. *
  21904. * @author Ben Houston / http://clara.io/
  21905. * @author David Sarno / http://lighthaus.us/
  21906. * @author tschw
  21907. */
  21908. function PropertyMixer( binding, typeName, valueSize ) {
  21909. this.binding = binding;
  21910. this.valueSize = valueSize;
  21911. var bufferType = Float64Array,
  21912. mixFunction;
  21913. switch ( typeName ) {
  21914. case 'quaternion':
  21915. mixFunction = this._slerp;
  21916. break;
  21917. case 'string':
  21918. case 'bool':
  21919. bufferType = Array;
  21920. mixFunction = this._select;
  21921. break;
  21922. default:
  21923. mixFunction = this._lerp;
  21924. }
  21925. this.buffer = new bufferType( valueSize * 4 );
  21926. // layout: [ incoming | accu0 | accu1 | orig ]
  21927. //
  21928. // interpolators can use .buffer as their .result
  21929. // the data then goes to 'incoming'
  21930. //
  21931. // 'accu0' and 'accu1' are used frame-interleaved for
  21932. // the cumulative result and are compared to detect
  21933. // changes
  21934. //
  21935. // 'orig' stores the original state of the property
  21936. this._mixBufferRegion = mixFunction;
  21937. this.cumulativeWeight = 0;
  21938. this.useCount = 0;
  21939. this.referenceCount = 0;
  21940. }
  21941. Object.assign( PropertyMixer.prototype, {
  21942. // accumulate data in the 'incoming' region into 'accu<i>'
  21943. accumulate: function ( accuIndex, weight ) {
  21944. // note: happily accumulating nothing when weight = 0, the caller knows
  21945. // the weight and shouldn't have made the call in the first place
  21946. var buffer = this.buffer,
  21947. stride = this.valueSize,
  21948. offset = accuIndex * stride + stride,
  21949. currentWeight = this.cumulativeWeight;
  21950. if ( currentWeight === 0 ) {
  21951. // accuN := incoming * weight
  21952. for ( var i = 0; i !== stride; ++ i ) {
  21953. buffer[ offset + i ] = buffer[ i ];
  21954. }
  21955. currentWeight = weight;
  21956. } else {
  21957. // accuN := accuN + incoming * weight
  21958. currentWeight += weight;
  21959. var mix = weight / currentWeight;
  21960. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  21961. }
  21962. this.cumulativeWeight = currentWeight;
  21963. },
  21964. // apply the state of 'accu<i>' to the binding when accus differ
  21965. apply: function ( accuIndex ) {
  21966. var stride = this.valueSize,
  21967. buffer = this.buffer,
  21968. offset = accuIndex * stride + stride,
  21969. weight = this.cumulativeWeight,
  21970. binding = this.binding;
  21971. this.cumulativeWeight = 0;
  21972. if ( weight < 1 ) {
  21973. // accuN := accuN + original * ( 1 - cumulativeWeight )
  21974. var originalValueOffset = stride * 3;
  21975. this._mixBufferRegion(
  21976. buffer, offset, originalValueOffset, 1 - weight, stride );
  21977. }
  21978. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  21979. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  21980. // value has changed -> update scene graph
  21981. binding.setValue( buffer, offset );
  21982. break;
  21983. }
  21984. }
  21985. },
  21986. // remember the state of the bound property and copy it to both accus
  21987. saveOriginalState: function () {
  21988. var binding = this.binding;
  21989. var buffer = this.buffer,
  21990. stride = this.valueSize,
  21991. originalValueOffset = stride * 3;
  21992. binding.getValue( buffer, originalValueOffset );
  21993. // accu[0..1] := orig -- initially detect changes against the original
  21994. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  21995. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  21996. }
  21997. this.cumulativeWeight = 0;
  21998. },
  21999. // apply the state previously taken via 'saveOriginalState' to the binding
  22000. restoreOriginalState: function () {
  22001. var originalValueOffset = this.valueSize * 3;
  22002. this.binding.setValue( this.buffer, originalValueOffset );
  22003. },
  22004. // mix functions
  22005. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  22006. if ( t >= 0.5 ) {
  22007. for ( var i = 0; i !== stride; ++ i ) {
  22008. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  22009. }
  22010. }
  22011. },
  22012. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  22013. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  22014. },
  22015. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  22016. var s = 1 - t;
  22017. for ( var i = 0; i !== stride; ++ i ) {
  22018. var j = dstOffset + i;
  22019. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  22020. }
  22021. }
  22022. } );
  22023. /**
  22024. *
  22025. * A reference to a real property in the scene graph.
  22026. *
  22027. *
  22028. * @author Ben Houston / http://clara.io/
  22029. * @author David Sarno / http://lighthaus.us/
  22030. * @author tschw
  22031. */
  22032. function Composite( targetGroup, path, optionalParsedPath ) {
  22033. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  22034. this._targetGroup = targetGroup;
  22035. this._bindings = targetGroup.subscribe_( path, parsedPath );
  22036. }
  22037. Object.assign( Composite.prototype, {
  22038. getValue: function ( array, offset ) {
  22039. this.bind(); // bind all binding
  22040. var firstValidIndex = this._targetGroup.nCachedObjects_,
  22041. binding = this._bindings[ firstValidIndex ];
  22042. // and only call .getValue on the first
  22043. if ( binding !== undefined ) binding.getValue( array, offset );
  22044. },
  22045. setValue: function ( array, offset ) {
  22046. var bindings = this._bindings;
  22047. for ( var i = this._targetGroup.nCachedObjects_,
  22048. n = bindings.length; i !== n; ++ i ) {
  22049. bindings[ i ].setValue( array, offset );
  22050. }
  22051. },
  22052. bind: function () {
  22053. var bindings = this._bindings;
  22054. for ( var i = this._targetGroup.nCachedObjects_,
  22055. n = bindings.length; i !== n; ++ i ) {
  22056. bindings[ i ].bind();
  22057. }
  22058. },
  22059. unbind: function () {
  22060. var bindings = this._bindings;
  22061. for ( var i = this._targetGroup.nCachedObjects_,
  22062. n = bindings.length; i !== n; ++ i ) {
  22063. bindings[ i ].unbind();
  22064. }
  22065. }
  22066. } );
  22067. function PropertyBinding( rootNode, path, parsedPath ) {
  22068. this.path = path;
  22069. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  22070. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  22071. this.rootNode = rootNode;
  22072. }
  22073. Object.assign( PropertyBinding, {
  22074. Composite: Composite,
  22075. create: function ( root, path, parsedPath ) {
  22076. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  22077. return new PropertyBinding( root, path, parsedPath );
  22078. } else {
  22079. return new PropertyBinding.Composite( root, path, parsedPath );
  22080. }
  22081. },
  22082. parseTrackName: function () {
  22083. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  22084. // be matched to parse the rest of the track name.
  22085. var directoryRe = /((?:[\w-]+[\/:])*)/;
  22086. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  22087. var nodeRe = /([\w-\.]+)?/;
  22088. // Object on target node, and accessor. Name may contain only word
  22089. // characters. Accessor may contain any character except closing bracket.
  22090. var objectRe = /(?:\.([\w-]+)(?:\[(.+)\])?)?/;
  22091. // Property and accessor. May contain only word characters. Accessor may
  22092. // contain any non-bracket characters.
  22093. var propertyRe = /\.([\w-]+)(?:\[(.+)\])?/;
  22094. var trackRe = new RegExp(''
  22095. + '^'
  22096. + directoryRe.source
  22097. + nodeRe.source
  22098. + objectRe.source
  22099. + propertyRe.source
  22100. + '$'
  22101. );
  22102. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  22103. return function ( trackName ) {
  22104. var matches = trackRe.exec( trackName );
  22105. if ( ! matches ) {
  22106. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  22107. }
  22108. var results = {
  22109. // directoryName: matches[ 1 ], // (tschw) currently unused
  22110. nodeName: matches[ 2 ],
  22111. objectName: matches[ 3 ],
  22112. objectIndex: matches[ 4 ],
  22113. propertyName: matches[ 5 ], // required
  22114. propertyIndex: matches[ 6 ]
  22115. };
  22116. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  22117. if ( lastDot !== undefined && lastDot !== -1 ) {
  22118. var objectName = results.nodeName.substring( lastDot + 1 );
  22119. // Object names must be checked against a whitelist. Otherwise, there
  22120. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  22121. // 'bar' could be the objectName, or part of a nodeName (which can
  22122. // include '.' characters).
  22123. if ( supportedObjectNames.indexOf( objectName ) !== -1 ) {
  22124. results.nodeName = results.nodeName.substring( 0, lastDot );
  22125. results.objectName = objectName;
  22126. }
  22127. }
  22128. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  22129. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  22130. }
  22131. return results;
  22132. };
  22133. }(),
  22134. findNode: function ( root, nodeName ) {
  22135. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  22136. return root;
  22137. }
  22138. // search into skeleton bones.
  22139. if ( root.skeleton ) {
  22140. var searchSkeleton = function ( skeleton ) {
  22141. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  22142. var bone = skeleton.bones[ i ];
  22143. if ( bone.name === nodeName ) {
  22144. return bone;
  22145. }
  22146. }
  22147. return null;
  22148. };
  22149. var bone = searchSkeleton( root.skeleton );
  22150. if ( bone ) {
  22151. return bone;
  22152. }
  22153. }
  22154. // search into node subtree.
  22155. if ( root.children ) {
  22156. var searchNodeSubtree = function ( children ) {
  22157. for ( var i = 0; i < children.length; i ++ ) {
  22158. var childNode = children[ i ];
  22159. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  22160. return childNode;
  22161. }
  22162. var result = searchNodeSubtree( childNode.children );
  22163. if ( result ) return result;
  22164. }
  22165. return null;
  22166. };
  22167. var subTreeNode = searchNodeSubtree( root.children );
  22168. if ( subTreeNode ) {
  22169. return subTreeNode;
  22170. }
  22171. }
  22172. return null;
  22173. }
  22174. } );
  22175. Object.assign( PropertyBinding.prototype, { // prototype, continued
  22176. // these are used to "bind" a nonexistent property
  22177. _getValue_unavailable: function () {},
  22178. _setValue_unavailable: function () {},
  22179. BindingType: {
  22180. Direct: 0,
  22181. EntireArray: 1,
  22182. ArrayElement: 2,
  22183. HasFromToArray: 3
  22184. },
  22185. Versioning: {
  22186. None: 0,
  22187. NeedsUpdate: 1,
  22188. MatrixWorldNeedsUpdate: 2
  22189. },
  22190. GetterByBindingType: [
  22191. function getValue_direct( buffer, offset ) {
  22192. buffer[ offset ] = this.node[ this.propertyName ];
  22193. },
  22194. function getValue_array( buffer, offset ) {
  22195. var source = this.resolvedProperty;
  22196. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  22197. buffer[ offset ++ ] = source[ i ];
  22198. }
  22199. },
  22200. function getValue_arrayElement( buffer, offset ) {
  22201. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  22202. },
  22203. function getValue_toArray( buffer, offset ) {
  22204. this.resolvedProperty.toArray( buffer, offset );
  22205. }
  22206. ],
  22207. SetterByBindingTypeAndVersioning: [
  22208. [
  22209. // Direct
  22210. function setValue_direct( buffer, offset ) {
  22211. this.node[ this.propertyName ] = buffer[ offset ];
  22212. },
  22213. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  22214. this.node[ this.propertyName ] = buffer[ offset ];
  22215. this.targetObject.needsUpdate = true;
  22216. },
  22217. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22218. this.node[ this.propertyName ] = buffer[ offset ];
  22219. this.targetObject.matrixWorldNeedsUpdate = true;
  22220. }
  22221. ], [
  22222. // EntireArray
  22223. function setValue_array( buffer, offset ) {
  22224. var dest = this.resolvedProperty;
  22225. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  22226. dest[ i ] = buffer[ offset ++ ];
  22227. }
  22228. },
  22229. function setValue_array_setNeedsUpdate( buffer, offset ) {
  22230. var dest = this.resolvedProperty;
  22231. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  22232. dest[ i ] = buffer[ offset ++ ];
  22233. }
  22234. this.targetObject.needsUpdate = true;
  22235. },
  22236. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22237. var dest = this.resolvedProperty;
  22238. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  22239. dest[ i ] = buffer[ offset ++ ];
  22240. }
  22241. this.targetObject.matrixWorldNeedsUpdate = true;
  22242. }
  22243. ], [
  22244. // ArrayElement
  22245. function setValue_arrayElement( buffer, offset ) {
  22246. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  22247. },
  22248. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  22249. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  22250. this.targetObject.needsUpdate = true;
  22251. },
  22252. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22253. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  22254. this.targetObject.matrixWorldNeedsUpdate = true;
  22255. }
  22256. ], [
  22257. // HasToFromArray
  22258. function setValue_fromArray( buffer, offset ) {
  22259. this.resolvedProperty.fromArray( buffer, offset );
  22260. },
  22261. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  22262. this.resolvedProperty.fromArray( buffer, offset );
  22263. this.targetObject.needsUpdate = true;
  22264. },
  22265. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  22266. this.resolvedProperty.fromArray( buffer, offset );
  22267. this.targetObject.matrixWorldNeedsUpdate = true;
  22268. }
  22269. ]
  22270. ],
  22271. getValue: function getValue_unbound( targetArray, offset ) {
  22272. this.bind();
  22273. this.getValue( targetArray, offset );
  22274. // Note: This class uses a State pattern on a per-method basis:
  22275. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  22276. // prototype version of these methods with one that represents
  22277. // the bound state. When the property is not found, the methods
  22278. // become no-ops.
  22279. },
  22280. setValue: function getValue_unbound( sourceArray, offset ) {
  22281. this.bind();
  22282. this.setValue( sourceArray, offset );
  22283. },
  22284. // create getter / setter pair for a property in the scene graph
  22285. bind: function () {
  22286. var targetObject = this.node,
  22287. parsedPath = this.parsedPath,
  22288. objectName = parsedPath.objectName,
  22289. propertyName = parsedPath.propertyName,
  22290. propertyIndex = parsedPath.propertyIndex;
  22291. if ( ! targetObject ) {
  22292. targetObject = PropertyBinding.findNode(
  22293. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  22294. this.node = targetObject;
  22295. }
  22296. // set fail state so we can just 'return' on error
  22297. this.getValue = this._getValue_unavailable;
  22298. this.setValue = this._setValue_unavailable;
  22299. // ensure there is a value node
  22300. if ( ! targetObject ) {
  22301. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  22302. return;
  22303. }
  22304. if ( objectName ) {
  22305. var objectIndex = parsedPath.objectIndex;
  22306. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  22307. switch ( objectName ) {
  22308. case 'materials':
  22309. if ( ! targetObject.material ) {
  22310. console.error( ' can not bind to material as node does not have a material', this );
  22311. return;
  22312. }
  22313. if ( ! targetObject.material.materials ) {
  22314. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  22315. return;
  22316. }
  22317. targetObject = targetObject.material.materials;
  22318. break;
  22319. case 'bones':
  22320. if ( ! targetObject.skeleton ) {
  22321. console.error( ' can not bind to bones as node does not have a skeleton', this );
  22322. return;
  22323. }
  22324. // potential future optimization: skip this if propertyIndex is already an integer
  22325. // and convert the integer string to a true integer.
  22326. targetObject = targetObject.skeleton.bones;
  22327. // support resolving morphTarget names into indices.
  22328. for ( var i = 0; i < targetObject.length; i ++ ) {
  22329. if ( targetObject[ i ].name === objectIndex ) {
  22330. objectIndex = i;
  22331. break;
  22332. }
  22333. }
  22334. break;
  22335. default:
  22336. if ( targetObject[ objectName ] === undefined ) {
  22337. console.error( ' can not bind to objectName of node, undefined', this );
  22338. return;
  22339. }
  22340. targetObject = targetObject[ objectName ];
  22341. }
  22342. if ( objectIndex !== undefined ) {
  22343. if ( targetObject[ objectIndex ] === undefined ) {
  22344. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  22345. return;
  22346. }
  22347. targetObject = targetObject[ objectIndex ];
  22348. }
  22349. }
  22350. // resolve property
  22351. var nodeProperty = targetObject[ propertyName ];
  22352. if ( nodeProperty === undefined ) {
  22353. var nodeName = parsedPath.nodeName;
  22354. console.error( " trying to update property for track: " + nodeName +
  22355. '.' + propertyName + " but it wasn't found.", targetObject );
  22356. return;
  22357. }
  22358. // determine versioning scheme
  22359. var versioning = this.Versioning.None;
  22360. if ( targetObject.needsUpdate !== undefined ) { // material
  22361. versioning = this.Versioning.NeedsUpdate;
  22362. this.targetObject = targetObject;
  22363. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  22364. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  22365. this.targetObject = targetObject;
  22366. }
  22367. // determine how the property gets bound
  22368. var bindingType = this.BindingType.Direct;
  22369. if ( propertyIndex !== undefined ) {
  22370. // access a sub element of the property array (only primitives are supported right now)
  22371. if ( propertyName === "morphTargetInfluences" ) {
  22372. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  22373. // support resolving morphTarget names into indices.
  22374. if ( ! targetObject.geometry ) {
  22375. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  22376. return;
  22377. }
  22378. if ( targetObject.geometry.isBufferGeometry ) {
  22379. if ( ! targetObject.geometry.morphAttributes ) {
  22380. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphAttributes', this );
  22381. return;
  22382. }
  22383. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  22384. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  22385. propertyIndex = i;
  22386. break;
  22387. }
  22388. }
  22389. } else {
  22390. if ( ! targetObject.geometry.morphTargets ) {
  22391. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  22392. return;
  22393. }
  22394. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  22395. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  22396. propertyIndex = i;
  22397. break;
  22398. }
  22399. }
  22400. }
  22401. }
  22402. bindingType = this.BindingType.ArrayElement;
  22403. this.resolvedProperty = nodeProperty;
  22404. this.propertyIndex = propertyIndex;
  22405. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  22406. // must use copy for Object3D.Euler/Quaternion
  22407. bindingType = this.BindingType.HasFromToArray;
  22408. this.resolvedProperty = nodeProperty;
  22409. } else if ( Array.isArray( nodeProperty ) ) {
  22410. bindingType = this.BindingType.EntireArray;
  22411. this.resolvedProperty = nodeProperty;
  22412. } else {
  22413. this.propertyName = propertyName;
  22414. }
  22415. // select getter / setter
  22416. this.getValue = this.GetterByBindingType[ bindingType ];
  22417. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  22418. },
  22419. unbind: function () {
  22420. this.node = null;
  22421. // back to the prototype version of getValue / setValue
  22422. // note: avoiding to mutate the shape of 'this' via 'delete'
  22423. this.getValue = this._getValue_unbound;
  22424. this.setValue = this._setValue_unbound;
  22425. }
  22426. } );
  22427. //!\ DECLARE ALIAS AFTER assign prototype !
  22428. Object.assign( PropertyBinding.prototype, {
  22429. // initial state of these methods that calls 'bind'
  22430. _getValue_unbound: PropertyBinding.prototype.getValue,
  22431. _setValue_unbound: PropertyBinding.prototype.setValue,
  22432. } );
  22433. /**
  22434. *
  22435. * A group of objects that receives a shared animation state.
  22436. *
  22437. * Usage:
  22438. *
  22439. * - Add objects you would otherwise pass as 'root' to the
  22440. * constructor or the .clipAction method of AnimationMixer.
  22441. *
  22442. * - Instead pass this object as 'root'.
  22443. *
  22444. * - You can also add and remove objects later when the mixer
  22445. * is running.
  22446. *
  22447. * Note:
  22448. *
  22449. * Objects of this class appear as one object to the mixer,
  22450. * so cache control of the individual objects must be done
  22451. * on the group.
  22452. *
  22453. * Limitation:
  22454. *
  22455. * - The animated properties must be compatible among the
  22456. * all objects in the group.
  22457. *
  22458. * - A single property can either be controlled through a
  22459. * target group or directly, but not both.
  22460. *
  22461. * @author tschw
  22462. */
  22463. function AnimationObjectGroup( var_args ) {
  22464. this.uuid = _Math.generateUUID();
  22465. // cached objects followed by the active ones
  22466. this._objects = Array.prototype.slice.call( arguments );
  22467. this.nCachedObjects_ = 0; // threshold
  22468. // note: read by PropertyBinding.Composite
  22469. var indices = {};
  22470. this._indicesByUUID = indices; // for bookkeeping
  22471. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22472. indices[ arguments[ i ].uuid ] = i;
  22473. }
  22474. this._paths = []; // inside: string
  22475. this._parsedPaths = []; // inside: { we don't care, here }
  22476. this._bindings = []; // inside: Array< PropertyBinding >
  22477. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  22478. var scope = this;
  22479. this.stats = {
  22480. objects: {
  22481. get total() { return scope._objects.length; },
  22482. get inUse() { return this.total - scope.nCachedObjects_; }
  22483. },
  22484. get bindingsPerObject() { return scope._bindings.length; }
  22485. };
  22486. }
  22487. Object.assign( AnimationObjectGroup.prototype, {
  22488. isAnimationObjectGroup: true,
  22489. add: function( var_args ) {
  22490. var objects = this._objects,
  22491. nObjects = objects.length,
  22492. nCachedObjects = this.nCachedObjects_,
  22493. indicesByUUID = this._indicesByUUID,
  22494. paths = this._paths,
  22495. parsedPaths = this._parsedPaths,
  22496. bindings = this._bindings,
  22497. nBindings = bindings.length;
  22498. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22499. var object = arguments[ i ],
  22500. uuid = object.uuid,
  22501. index = indicesByUUID[ uuid ],
  22502. knownObject = undefined;
  22503. if ( index === undefined ) {
  22504. // unknown object -> add it to the ACTIVE region
  22505. index = nObjects ++;
  22506. indicesByUUID[ uuid ] = index;
  22507. objects.push( object );
  22508. // accounting is done, now do the same for all bindings
  22509. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22510. bindings[ j ].push(
  22511. new PropertyBinding(
  22512. object, paths[ j ], parsedPaths[ j ] ) );
  22513. }
  22514. } else if ( index < nCachedObjects ) {
  22515. knownObject = objects[ index ];
  22516. // move existing object to the ACTIVE region
  22517. var firstActiveIndex = -- nCachedObjects,
  22518. lastCachedObject = objects[ firstActiveIndex ];
  22519. indicesByUUID[ lastCachedObject.uuid ] = index;
  22520. objects[ index ] = lastCachedObject;
  22521. indicesByUUID[ uuid ] = firstActiveIndex;
  22522. objects[ firstActiveIndex ] = object;
  22523. // accounting is done, now do the same for all bindings
  22524. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22525. var bindingsForPath = bindings[ j ],
  22526. lastCached = bindingsForPath[ firstActiveIndex ],
  22527. binding = bindingsForPath[ index ];
  22528. bindingsForPath[ index ] = lastCached;
  22529. if ( binding === undefined ) {
  22530. // since we do not bother to create new bindings
  22531. // for objects that are cached, the binding may
  22532. // or may not exist
  22533. binding = new PropertyBinding(
  22534. object, paths[ j ], parsedPaths[ j ] );
  22535. }
  22536. bindingsForPath[ firstActiveIndex ] = binding;
  22537. }
  22538. } else if ( objects[ index ] !== knownObject ) {
  22539. console.error( "Different objects with the same UUID " +
  22540. "detected. Clean the caches or recreate your " +
  22541. "infrastructure when reloading scenes..." );
  22542. } // else the object is already where we want it to be
  22543. } // for arguments
  22544. this.nCachedObjects_ = nCachedObjects;
  22545. },
  22546. remove: function( var_args ) {
  22547. var objects = this._objects,
  22548. nCachedObjects = this.nCachedObjects_,
  22549. indicesByUUID = this._indicesByUUID,
  22550. bindings = this._bindings,
  22551. nBindings = bindings.length;
  22552. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22553. var object = arguments[ i ],
  22554. uuid = object.uuid,
  22555. index = indicesByUUID[ uuid ];
  22556. if ( index !== undefined && index >= nCachedObjects ) {
  22557. // move existing object into the CACHED region
  22558. var lastCachedIndex = nCachedObjects ++,
  22559. firstActiveObject = objects[ lastCachedIndex ];
  22560. indicesByUUID[ firstActiveObject.uuid ] = index;
  22561. objects[ index ] = firstActiveObject;
  22562. indicesByUUID[ uuid ] = lastCachedIndex;
  22563. objects[ lastCachedIndex ] = object;
  22564. // accounting is done, now do the same for all bindings
  22565. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22566. var bindingsForPath = bindings[ j ],
  22567. firstActive = bindingsForPath[ lastCachedIndex ],
  22568. binding = bindingsForPath[ index ];
  22569. bindingsForPath[ index ] = firstActive;
  22570. bindingsForPath[ lastCachedIndex ] = binding;
  22571. }
  22572. }
  22573. } // for arguments
  22574. this.nCachedObjects_ = nCachedObjects;
  22575. },
  22576. // remove & forget
  22577. uncache: function( var_args ) {
  22578. var objects = this._objects,
  22579. nObjects = objects.length,
  22580. nCachedObjects = this.nCachedObjects_,
  22581. indicesByUUID = this._indicesByUUID,
  22582. bindings = this._bindings,
  22583. nBindings = bindings.length;
  22584. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  22585. var object = arguments[ i ],
  22586. uuid = object.uuid,
  22587. index = indicesByUUID[ uuid ];
  22588. if ( index !== undefined ) {
  22589. delete indicesByUUID[ uuid ];
  22590. if ( index < nCachedObjects ) {
  22591. // object is cached, shrink the CACHED region
  22592. var firstActiveIndex = -- nCachedObjects,
  22593. lastCachedObject = objects[ firstActiveIndex ],
  22594. lastIndex = -- nObjects,
  22595. lastObject = objects[ lastIndex ];
  22596. // last cached object takes this object's place
  22597. indicesByUUID[ lastCachedObject.uuid ] = index;
  22598. objects[ index ] = lastCachedObject;
  22599. // last object goes to the activated slot and pop
  22600. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  22601. objects[ firstActiveIndex ] = lastObject;
  22602. objects.pop();
  22603. // accounting is done, now do the same for all bindings
  22604. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22605. var bindingsForPath = bindings[ j ],
  22606. lastCached = bindingsForPath[ firstActiveIndex ],
  22607. last = bindingsForPath[ lastIndex ];
  22608. bindingsForPath[ index ] = lastCached;
  22609. bindingsForPath[ firstActiveIndex ] = last;
  22610. bindingsForPath.pop();
  22611. }
  22612. } else {
  22613. // object is active, just swap with the last and pop
  22614. var lastIndex = -- nObjects,
  22615. lastObject = objects[ lastIndex ];
  22616. indicesByUUID[ lastObject.uuid ] = index;
  22617. objects[ index ] = lastObject;
  22618. objects.pop();
  22619. // accounting is done, now do the same for all bindings
  22620. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  22621. var bindingsForPath = bindings[ j ];
  22622. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  22623. bindingsForPath.pop();
  22624. }
  22625. } // cached or active
  22626. } // if object is known
  22627. } // for arguments
  22628. this.nCachedObjects_ = nCachedObjects;
  22629. },
  22630. // Internal interface used by befriended PropertyBinding.Composite:
  22631. subscribe_: function ( path, parsedPath ) {
  22632. // returns an array of bindings for the given path that is changed
  22633. // according to the contained objects in the group
  22634. var indicesByPath = this._bindingsIndicesByPath,
  22635. index = indicesByPath[ path ],
  22636. bindings = this._bindings;
  22637. if ( index !== undefined ) return bindings[ index ];
  22638. var paths = this._paths,
  22639. parsedPaths = this._parsedPaths,
  22640. objects = this._objects,
  22641. nObjects = objects.length,
  22642. nCachedObjects = this.nCachedObjects_,
  22643. bindingsForPath = new Array( nObjects );
  22644. index = bindings.length;
  22645. indicesByPath[ path ] = index;
  22646. paths.push( path );
  22647. parsedPaths.push( parsedPath );
  22648. bindings.push( bindingsForPath );
  22649. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  22650. var object = objects[ i ];
  22651. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  22652. }
  22653. return bindingsForPath;
  22654. },
  22655. unsubscribe_: function ( path ) {
  22656. // tells the group to forget about a property path and no longer
  22657. // update the array previously obtained with 'subscribe_'
  22658. var indicesByPath = this._bindingsIndicesByPath,
  22659. index = indicesByPath[ path ];
  22660. if ( index !== undefined ) {
  22661. var paths = this._paths,
  22662. parsedPaths = this._parsedPaths,
  22663. bindings = this._bindings,
  22664. lastBindingsIndex = bindings.length - 1,
  22665. lastBindings = bindings[ lastBindingsIndex ],
  22666. lastBindingsPath = path[ lastBindingsIndex ];
  22667. indicesByPath[ lastBindingsPath ] = index;
  22668. bindings[ index ] = lastBindings;
  22669. bindings.pop();
  22670. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  22671. parsedPaths.pop();
  22672. paths[ index ] = paths[ lastBindingsIndex ];
  22673. paths.pop();
  22674. }
  22675. }
  22676. } );
  22677. /**
  22678. *
  22679. * Action provided by AnimationMixer for scheduling clip playback on specific
  22680. * objects.
  22681. *
  22682. * @author Ben Houston / http://clara.io/
  22683. * @author David Sarno / http://lighthaus.us/
  22684. * @author tschw
  22685. *
  22686. */
  22687. function AnimationAction( mixer, clip, localRoot ) {
  22688. this._mixer = mixer;
  22689. this._clip = clip;
  22690. this._localRoot = localRoot || null;
  22691. var tracks = clip.tracks,
  22692. nTracks = tracks.length,
  22693. interpolants = new Array( nTracks );
  22694. var interpolantSettings = {
  22695. endingStart: ZeroCurvatureEnding,
  22696. endingEnd: ZeroCurvatureEnding
  22697. };
  22698. for ( var i = 0; i !== nTracks; ++ i ) {
  22699. var interpolant = tracks[ i ].createInterpolant( null );
  22700. interpolants[ i ] = interpolant;
  22701. interpolant.settings = interpolantSettings;
  22702. }
  22703. this._interpolantSettings = interpolantSettings;
  22704. this._interpolants = interpolants; // bound by the mixer
  22705. // inside: PropertyMixer (managed by the mixer)
  22706. this._propertyBindings = new Array( nTracks );
  22707. this._cacheIndex = null; // for the memory manager
  22708. this._byClipCacheIndex = null; // for the memory manager
  22709. this._timeScaleInterpolant = null;
  22710. this._weightInterpolant = null;
  22711. this.loop = LoopRepeat;
  22712. this._loopCount = -1;
  22713. // global mixer time when the action is to be started
  22714. // it's set back to 'null' upon start of the action
  22715. this._startTime = null;
  22716. // scaled local time of the action
  22717. // gets clamped or wrapped to 0..clip.duration according to loop
  22718. this.time = 0;
  22719. this.timeScale = 1;
  22720. this._effectiveTimeScale = 1;
  22721. this.weight = 1;
  22722. this._effectiveWeight = 1;
  22723. this.repetitions = Infinity; // no. of repetitions when looping
  22724. this.paused = false; // true -> zero effective time scale
  22725. this.enabled = true; // false -> zero effective weight
  22726. this.clampWhenFinished = false; // keep feeding the last frame?
  22727. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  22728. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  22729. }
  22730. Object.assign( AnimationAction.prototype, {
  22731. // State & Scheduling
  22732. play: function() {
  22733. this._mixer._activateAction( this );
  22734. return this;
  22735. },
  22736. stop: function() {
  22737. this._mixer._deactivateAction( this );
  22738. return this.reset();
  22739. },
  22740. reset: function() {
  22741. this.paused = false;
  22742. this.enabled = true;
  22743. this.time = 0; // restart clip
  22744. this._loopCount = -1; // forget previous loops
  22745. this._startTime = null; // forget scheduling
  22746. return this.stopFading().stopWarping();
  22747. },
  22748. isRunning: function() {
  22749. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  22750. this._startTime === null && this._mixer._isActiveAction( this );
  22751. },
  22752. // return true when play has been called
  22753. isScheduled: function() {
  22754. return this._mixer._isActiveAction( this );
  22755. },
  22756. startAt: function( time ) {
  22757. this._startTime = time;
  22758. return this;
  22759. },
  22760. setLoop: function( mode, repetitions ) {
  22761. this.loop = mode;
  22762. this.repetitions = repetitions;
  22763. return this;
  22764. },
  22765. // Weight
  22766. // set the weight stopping any scheduled fading
  22767. // although .enabled = false yields an effective weight of zero, this
  22768. // method does *not* change .enabled, because it would be confusing
  22769. setEffectiveWeight: function( weight ) {
  22770. this.weight = weight;
  22771. // note: same logic as when updated at runtime
  22772. this._effectiveWeight = this.enabled ? weight : 0;
  22773. return this.stopFading();
  22774. },
  22775. // return the weight considering fading and .enabled
  22776. getEffectiveWeight: function() {
  22777. return this._effectiveWeight;
  22778. },
  22779. fadeIn: function( duration ) {
  22780. return this._scheduleFading( duration, 0, 1 );
  22781. },
  22782. fadeOut: function( duration ) {
  22783. return this._scheduleFading( duration, 1, 0 );
  22784. },
  22785. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  22786. fadeOutAction.fadeOut( duration );
  22787. this.fadeIn( duration );
  22788. if( warp ) {
  22789. var fadeInDuration = this._clip.duration,
  22790. fadeOutDuration = fadeOutAction._clip.duration,
  22791. startEndRatio = fadeOutDuration / fadeInDuration,
  22792. endStartRatio = fadeInDuration / fadeOutDuration;
  22793. fadeOutAction.warp( 1.0, startEndRatio, duration );
  22794. this.warp( endStartRatio, 1.0, duration );
  22795. }
  22796. return this;
  22797. },
  22798. crossFadeTo: function( fadeInAction, duration, warp ) {
  22799. return fadeInAction.crossFadeFrom( this, duration, warp );
  22800. },
  22801. stopFading: function() {
  22802. var weightInterpolant = this._weightInterpolant;
  22803. if ( weightInterpolant !== null ) {
  22804. this._weightInterpolant = null;
  22805. this._mixer._takeBackControlInterpolant( weightInterpolant );
  22806. }
  22807. return this;
  22808. },
  22809. // Time Scale Control
  22810. // set the time scale stopping any scheduled warping
  22811. // although .paused = true yields an effective time scale of zero, this
  22812. // method does *not* change .paused, because it would be confusing
  22813. setEffectiveTimeScale: function( timeScale ) {
  22814. this.timeScale = timeScale;
  22815. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  22816. return this.stopWarping();
  22817. },
  22818. // return the time scale considering warping and .paused
  22819. getEffectiveTimeScale: function() {
  22820. return this._effectiveTimeScale;
  22821. },
  22822. setDuration: function( duration ) {
  22823. this.timeScale = this._clip.duration / duration;
  22824. return this.stopWarping();
  22825. },
  22826. syncWith: function( action ) {
  22827. this.time = action.time;
  22828. this.timeScale = action.timeScale;
  22829. return this.stopWarping();
  22830. },
  22831. halt: function( duration ) {
  22832. return this.warp( this._effectiveTimeScale, 0, duration );
  22833. },
  22834. warp: function( startTimeScale, endTimeScale, duration ) {
  22835. var mixer = this._mixer, now = mixer.time,
  22836. interpolant = this._timeScaleInterpolant,
  22837. timeScale = this.timeScale;
  22838. if ( interpolant === null ) {
  22839. interpolant = mixer._lendControlInterpolant();
  22840. this._timeScaleInterpolant = interpolant;
  22841. }
  22842. var times = interpolant.parameterPositions,
  22843. values = interpolant.sampleValues;
  22844. times[ 0 ] = now;
  22845. times[ 1 ] = now + duration;
  22846. values[ 0 ] = startTimeScale / timeScale;
  22847. values[ 1 ] = endTimeScale / timeScale;
  22848. return this;
  22849. },
  22850. stopWarping: function() {
  22851. var timeScaleInterpolant = this._timeScaleInterpolant;
  22852. if ( timeScaleInterpolant !== null ) {
  22853. this._timeScaleInterpolant = null;
  22854. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  22855. }
  22856. return this;
  22857. },
  22858. // Object Accessors
  22859. getMixer: function() {
  22860. return this._mixer;
  22861. },
  22862. getClip: function() {
  22863. return this._clip;
  22864. },
  22865. getRoot: function() {
  22866. return this._localRoot || this._mixer._root;
  22867. },
  22868. // Interna
  22869. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  22870. // called by the mixer
  22871. if ( ! this.enabled ) {
  22872. // call ._updateWeight() to update ._effectiveWeight
  22873. this._updateWeight( time );
  22874. return;
  22875. }
  22876. var startTime = this._startTime;
  22877. if ( startTime !== null ) {
  22878. // check for scheduled start of action
  22879. var timeRunning = ( time - startTime ) * timeDirection;
  22880. if ( timeRunning < 0 || timeDirection === 0 ) {
  22881. return; // yet to come / don't decide when delta = 0
  22882. }
  22883. // start
  22884. this._startTime = null; // unschedule
  22885. deltaTime = timeDirection * timeRunning;
  22886. }
  22887. // apply time scale and advance time
  22888. deltaTime *= this._updateTimeScale( time );
  22889. var clipTime = this._updateTime( deltaTime );
  22890. // note: _updateTime may disable the action resulting in
  22891. // an effective weight of 0
  22892. var weight = this._updateWeight( time );
  22893. if ( weight > 0 ) {
  22894. var interpolants = this._interpolants;
  22895. var propertyMixers = this._propertyBindings;
  22896. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  22897. interpolants[ j ].evaluate( clipTime );
  22898. propertyMixers[ j ].accumulate( accuIndex, weight );
  22899. }
  22900. }
  22901. },
  22902. _updateWeight: function( time ) {
  22903. var weight = 0;
  22904. if ( this.enabled ) {
  22905. weight = this.weight;
  22906. var interpolant = this._weightInterpolant;
  22907. if ( interpolant !== null ) {
  22908. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  22909. weight *= interpolantValue;
  22910. if ( time > interpolant.parameterPositions[ 1 ] ) {
  22911. this.stopFading();
  22912. if ( interpolantValue === 0 ) {
  22913. // faded out, disable
  22914. this.enabled = false;
  22915. }
  22916. }
  22917. }
  22918. }
  22919. this._effectiveWeight = weight;
  22920. return weight;
  22921. },
  22922. _updateTimeScale: function( time ) {
  22923. var timeScale = 0;
  22924. if ( ! this.paused ) {
  22925. timeScale = this.timeScale;
  22926. var interpolant = this._timeScaleInterpolant;
  22927. if ( interpolant !== null ) {
  22928. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  22929. timeScale *= interpolantValue;
  22930. if ( time > interpolant.parameterPositions[ 1 ] ) {
  22931. this.stopWarping();
  22932. if ( timeScale === 0 ) {
  22933. // motion has halted, pause
  22934. this.paused = true;
  22935. } else {
  22936. // warp done - apply final time scale
  22937. this.timeScale = timeScale;
  22938. }
  22939. }
  22940. }
  22941. }
  22942. this._effectiveTimeScale = timeScale;
  22943. return timeScale;
  22944. },
  22945. _updateTime: function( deltaTime ) {
  22946. var time = this.time + deltaTime;
  22947. if ( deltaTime === 0 ) return time;
  22948. var duration = this._clip.duration,
  22949. loop = this.loop,
  22950. loopCount = this._loopCount;
  22951. if ( loop === LoopOnce ) {
  22952. if ( loopCount === -1 ) {
  22953. // just started
  22954. this._loopCount = 0;
  22955. this._setEndings( true, true, false );
  22956. }
  22957. handle_stop: {
  22958. if ( time >= duration ) {
  22959. time = duration;
  22960. } else if ( time < 0 ) {
  22961. time = 0;
  22962. } else break handle_stop;
  22963. if ( this.clampWhenFinished ) this.paused = true;
  22964. else this.enabled = false;
  22965. this._mixer.dispatchEvent( {
  22966. type: 'finished', action: this,
  22967. direction: deltaTime < 0 ? -1 : 1
  22968. } );
  22969. }
  22970. } else { // repetitive Repeat or PingPong
  22971. var pingPong = ( loop === LoopPingPong );
  22972. if ( loopCount === -1 ) {
  22973. // just started
  22974. if ( deltaTime >= 0 ) {
  22975. loopCount = 0;
  22976. this._setEndings(
  22977. true, this.repetitions === 0, pingPong );
  22978. } else {
  22979. // when looping in reverse direction, the initial
  22980. // transition through zero counts as a repetition,
  22981. // so leave loopCount at -1
  22982. this._setEndings(
  22983. this.repetitions === 0, true, pingPong );
  22984. }
  22985. }
  22986. if ( time >= duration || time < 0 ) {
  22987. // wrap around
  22988. var loopDelta = Math.floor( time / duration ); // signed
  22989. time -= duration * loopDelta;
  22990. loopCount += Math.abs( loopDelta );
  22991. var pending = this.repetitions - loopCount;
  22992. if ( pending < 0 ) {
  22993. // have to stop (switch state, clamp time, fire event)
  22994. if ( this.clampWhenFinished ) this.paused = true;
  22995. else this.enabled = false;
  22996. time = deltaTime > 0 ? duration : 0;
  22997. this._mixer.dispatchEvent( {
  22998. type: 'finished', action: this,
  22999. direction: deltaTime > 0 ? 1 : -1
  23000. } );
  23001. } else {
  23002. // keep running
  23003. if ( pending === 0 ) {
  23004. // entering the last round
  23005. var atStart = deltaTime < 0;
  23006. this._setEndings( atStart, ! atStart, pingPong );
  23007. } else {
  23008. this._setEndings( false, false, pingPong );
  23009. }
  23010. this._loopCount = loopCount;
  23011. this._mixer.dispatchEvent( {
  23012. type: 'loop', action: this, loopDelta: loopDelta
  23013. } );
  23014. }
  23015. }
  23016. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  23017. // invert time for the "pong round"
  23018. this.time = time;
  23019. return duration - time;
  23020. }
  23021. }
  23022. this.time = time;
  23023. return time;
  23024. },
  23025. _setEndings: function( atStart, atEnd, pingPong ) {
  23026. var settings = this._interpolantSettings;
  23027. if ( pingPong ) {
  23028. settings.endingStart = ZeroSlopeEnding;
  23029. settings.endingEnd = ZeroSlopeEnding;
  23030. } else {
  23031. // assuming for LoopOnce atStart == atEnd == true
  23032. if ( atStart ) {
  23033. settings.endingStart = this.zeroSlopeAtStart ?
  23034. ZeroSlopeEnding : ZeroCurvatureEnding;
  23035. } else {
  23036. settings.endingStart = WrapAroundEnding;
  23037. }
  23038. if ( atEnd ) {
  23039. settings.endingEnd = this.zeroSlopeAtEnd ?
  23040. ZeroSlopeEnding : ZeroCurvatureEnding;
  23041. } else {
  23042. settings.endingEnd = WrapAroundEnding;
  23043. }
  23044. }
  23045. },
  23046. _scheduleFading: function( duration, weightNow, weightThen ) {
  23047. var mixer = this._mixer, now = mixer.time,
  23048. interpolant = this._weightInterpolant;
  23049. if ( interpolant === null ) {
  23050. interpolant = mixer._lendControlInterpolant();
  23051. this._weightInterpolant = interpolant;
  23052. }
  23053. var times = interpolant.parameterPositions,
  23054. values = interpolant.sampleValues;
  23055. times[ 0 ] = now; values[ 0 ] = weightNow;
  23056. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  23057. return this;
  23058. }
  23059. } );
  23060. /**
  23061. *
  23062. * Player for AnimationClips.
  23063. *
  23064. *
  23065. * @author Ben Houston / http://clara.io/
  23066. * @author David Sarno / http://lighthaus.us/
  23067. * @author tschw
  23068. */
  23069. function AnimationMixer( root ) {
  23070. this._root = root;
  23071. this._initMemoryManager();
  23072. this._accuIndex = 0;
  23073. this.time = 0;
  23074. this.timeScale = 1.0;
  23075. }
  23076. Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, {
  23077. _bindAction: function ( action, prototypeAction ) {
  23078. var root = action._localRoot || this._root,
  23079. tracks = action._clip.tracks,
  23080. nTracks = tracks.length,
  23081. bindings = action._propertyBindings,
  23082. interpolants = action._interpolants,
  23083. rootUuid = root.uuid,
  23084. bindingsByRoot = this._bindingsByRootAndName,
  23085. bindingsByName = bindingsByRoot[ rootUuid ];
  23086. if ( bindingsByName === undefined ) {
  23087. bindingsByName = {};
  23088. bindingsByRoot[ rootUuid ] = bindingsByName;
  23089. }
  23090. for ( var i = 0; i !== nTracks; ++ i ) {
  23091. var track = tracks[ i ],
  23092. trackName = track.name,
  23093. binding = bindingsByName[ trackName ];
  23094. if ( binding !== undefined ) {
  23095. bindings[ i ] = binding;
  23096. } else {
  23097. binding = bindings[ i ];
  23098. if ( binding !== undefined ) {
  23099. // existing binding, make sure the cache knows
  23100. if ( binding._cacheIndex === null ) {
  23101. ++ binding.referenceCount;
  23102. this._addInactiveBinding( binding, rootUuid, trackName );
  23103. }
  23104. continue;
  23105. }
  23106. var path = prototypeAction && prototypeAction.
  23107. _propertyBindings[ i ].binding.parsedPath;
  23108. binding = new PropertyMixer(
  23109. PropertyBinding.create( root, trackName, path ),
  23110. track.ValueTypeName, track.getValueSize() );
  23111. ++ binding.referenceCount;
  23112. this._addInactiveBinding( binding, rootUuid, trackName );
  23113. bindings[ i ] = binding;
  23114. }
  23115. interpolants[ i ].resultBuffer = binding.buffer;
  23116. }
  23117. },
  23118. _activateAction: function ( action ) {
  23119. if ( ! this._isActiveAction( action ) ) {
  23120. if ( action._cacheIndex === null ) {
  23121. // this action has been forgotten by the cache, but the user
  23122. // appears to be still using it -> rebind
  23123. var rootUuid = ( action._localRoot || this._root ).uuid,
  23124. clipUuid = action._clip.uuid,
  23125. actionsForClip = this._actionsByClip[ clipUuid ];
  23126. this._bindAction( action,
  23127. actionsForClip && actionsForClip.knownActions[ 0 ] );
  23128. this._addInactiveAction( action, clipUuid, rootUuid );
  23129. }
  23130. var bindings = action._propertyBindings;
  23131. // increment reference counts / sort out state
  23132. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  23133. var binding = bindings[ i ];
  23134. if ( binding.useCount ++ === 0 ) {
  23135. this._lendBinding( binding );
  23136. binding.saveOriginalState();
  23137. }
  23138. }
  23139. this._lendAction( action );
  23140. }
  23141. },
  23142. _deactivateAction: function ( action ) {
  23143. if ( this._isActiveAction( action ) ) {
  23144. var bindings = action._propertyBindings;
  23145. // decrement reference counts / sort out state
  23146. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  23147. var binding = bindings[ i ];
  23148. if ( -- binding.useCount === 0 ) {
  23149. binding.restoreOriginalState();
  23150. this._takeBackBinding( binding );
  23151. }
  23152. }
  23153. this._takeBackAction( action );
  23154. }
  23155. },
  23156. // Memory manager
  23157. _initMemoryManager: function () {
  23158. this._actions = []; // 'nActiveActions' followed by inactive ones
  23159. this._nActiveActions = 0;
  23160. this._actionsByClip = {};
  23161. // inside:
  23162. // {
  23163. // knownActions: Array< AnimationAction > - used as prototypes
  23164. // actionByRoot: AnimationAction - lookup
  23165. // }
  23166. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  23167. this._nActiveBindings = 0;
  23168. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  23169. this._controlInterpolants = []; // same game as above
  23170. this._nActiveControlInterpolants = 0;
  23171. var scope = this;
  23172. this.stats = {
  23173. actions: {
  23174. get total() { return scope._actions.length; },
  23175. get inUse() { return scope._nActiveActions; }
  23176. },
  23177. bindings: {
  23178. get total() { return scope._bindings.length; },
  23179. get inUse() { return scope._nActiveBindings; }
  23180. },
  23181. controlInterpolants: {
  23182. get total() { return scope._controlInterpolants.length; },
  23183. get inUse() { return scope._nActiveControlInterpolants; }
  23184. }
  23185. };
  23186. },
  23187. // Memory management for AnimationAction objects
  23188. _isActiveAction: function ( action ) {
  23189. var index = action._cacheIndex;
  23190. return index !== null && index < this._nActiveActions;
  23191. },
  23192. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  23193. var actions = this._actions,
  23194. actionsByClip = this._actionsByClip,
  23195. actionsForClip = actionsByClip[ clipUuid ];
  23196. if ( actionsForClip === undefined ) {
  23197. actionsForClip = {
  23198. knownActions: [ action ],
  23199. actionByRoot: {}
  23200. };
  23201. action._byClipCacheIndex = 0;
  23202. actionsByClip[ clipUuid ] = actionsForClip;
  23203. } else {
  23204. var knownActions = actionsForClip.knownActions;
  23205. action._byClipCacheIndex = knownActions.length;
  23206. knownActions.push( action );
  23207. }
  23208. action._cacheIndex = actions.length;
  23209. actions.push( action );
  23210. actionsForClip.actionByRoot[ rootUuid ] = action;
  23211. },
  23212. _removeInactiveAction: function ( action ) {
  23213. var actions = this._actions,
  23214. lastInactiveAction = actions[ actions.length - 1 ],
  23215. cacheIndex = action._cacheIndex;
  23216. lastInactiveAction._cacheIndex = cacheIndex;
  23217. actions[ cacheIndex ] = lastInactiveAction;
  23218. actions.pop();
  23219. action._cacheIndex = null;
  23220. var clipUuid = action._clip.uuid,
  23221. actionsByClip = this._actionsByClip,
  23222. actionsForClip = actionsByClip[ clipUuid ],
  23223. knownActionsForClip = actionsForClip.knownActions,
  23224. lastKnownAction =
  23225. knownActionsForClip[ knownActionsForClip.length - 1 ],
  23226. byClipCacheIndex = action._byClipCacheIndex;
  23227. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  23228. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  23229. knownActionsForClip.pop();
  23230. action._byClipCacheIndex = null;
  23231. var actionByRoot = actionsForClip.actionByRoot,
  23232. rootUuid = ( action._localRoot || this._root ).uuid;
  23233. delete actionByRoot[ rootUuid ];
  23234. if ( knownActionsForClip.length === 0 ) {
  23235. delete actionsByClip[ clipUuid ];
  23236. }
  23237. this._removeInactiveBindingsForAction( action );
  23238. },
  23239. _removeInactiveBindingsForAction: function ( action ) {
  23240. var bindings = action._propertyBindings;
  23241. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  23242. var binding = bindings[ i ];
  23243. if ( -- binding.referenceCount === 0 ) {
  23244. this._removeInactiveBinding( binding );
  23245. }
  23246. }
  23247. },
  23248. _lendAction: function ( action ) {
  23249. // [ active actions | inactive actions ]
  23250. // [ active actions >| inactive actions ]
  23251. // s a
  23252. // <-swap->
  23253. // a s
  23254. var actions = this._actions,
  23255. prevIndex = action._cacheIndex,
  23256. lastActiveIndex = this._nActiveActions ++,
  23257. firstInactiveAction = actions[ lastActiveIndex ];
  23258. action._cacheIndex = lastActiveIndex;
  23259. actions[ lastActiveIndex ] = action;
  23260. firstInactiveAction._cacheIndex = prevIndex;
  23261. actions[ prevIndex ] = firstInactiveAction;
  23262. },
  23263. _takeBackAction: function ( action ) {
  23264. // [ active actions | inactive actions ]
  23265. // [ active actions |< inactive actions ]
  23266. // a s
  23267. // <-swap->
  23268. // s a
  23269. var actions = this._actions,
  23270. prevIndex = action._cacheIndex,
  23271. firstInactiveIndex = -- this._nActiveActions,
  23272. lastActiveAction = actions[ firstInactiveIndex ];
  23273. action._cacheIndex = firstInactiveIndex;
  23274. actions[ firstInactiveIndex ] = action;
  23275. lastActiveAction._cacheIndex = prevIndex;
  23276. actions[ prevIndex ] = lastActiveAction;
  23277. },
  23278. // Memory management for PropertyMixer objects
  23279. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  23280. var bindingsByRoot = this._bindingsByRootAndName,
  23281. bindingByName = bindingsByRoot[ rootUuid ],
  23282. bindings = this._bindings;
  23283. if ( bindingByName === undefined ) {
  23284. bindingByName = {};
  23285. bindingsByRoot[ rootUuid ] = bindingByName;
  23286. }
  23287. bindingByName[ trackName ] = binding;
  23288. binding._cacheIndex = bindings.length;
  23289. bindings.push( binding );
  23290. },
  23291. _removeInactiveBinding: function ( binding ) {
  23292. var bindings = this._bindings,
  23293. propBinding = binding.binding,
  23294. rootUuid = propBinding.rootNode.uuid,
  23295. trackName = propBinding.path,
  23296. bindingsByRoot = this._bindingsByRootAndName,
  23297. bindingByName = bindingsByRoot[ rootUuid ],
  23298. lastInactiveBinding = bindings[ bindings.length - 1 ],
  23299. cacheIndex = binding._cacheIndex;
  23300. lastInactiveBinding._cacheIndex = cacheIndex;
  23301. bindings[ cacheIndex ] = lastInactiveBinding;
  23302. bindings.pop();
  23303. delete bindingByName[ trackName ];
  23304. remove_empty_map: {
  23305. for ( var _ in bindingByName ) break remove_empty_map;
  23306. delete bindingsByRoot[ rootUuid ];
  23307. }
  23308. },
  23309. _lendBinding: function ( binding ) {
  23310. var bindings = this._bindings,
  23311. prevIndex = binding._cacheIndex,
  23312. lastActiveIndex = this._nActiveBindings ++,
  23313. firstInactiveBinding = bindings[ lastActiveIndex ];
  23314. binding._cacheIndex = lastActiveIndex;
  23315. bindings[ lastActiveIndex ] = binding;
  23316. firstInactiveBinding._cacheIndex = prevIndex;
  23317. bindings[ prevIndex ] = firstInactiveBinding;
  23318. },
  23319. _takeBackBinding: function ( binding ) {
  23320. var bindings = this._bindings,
  23321. prevIndex = binding._cacheIndex,
  23322. firstInactiveIndex = -- this._nActiveBindings,
  23323. lastActiveBinding = bindings[ firstInactiveIndex ];
  23324. binding._cacheIndex = firstInactiveIndex;
  23325. bindings[ firstInactiveIndex ] = binding;
  23326. lastActiveBinding._cacheIndex = prevIndex;
  23327. bindings[ prevIndex ] = lastActiveBinding;
  23328. },
  23329. // Memory management of Interpolants for weight and time scale
  23330. _lendControlInterpolant: function () {
  23331. var interpolants = this._controlInterpolants,
  23332. lastActiveIndex = this._nActiveControlInterpolants ++,
  23333. interpolant = interpolants[ lastActiveIndex ];
  23334. if ( interpolant === undefined ) {
  23335. interpolant = new LinearInterpolant(
  23336. new Float32Array( 2 ), new Float32Array( 2 ),
  23337. 1, this._controlInterpolantsResultBuffer );
  23338. interpolant.__cacheIndex = lastActiveIndex;
  23339. interpolants[ lastActiveIndex ] = interpolant;
  23340. }
  23341. return interpolant;
  23342. },
  23343. _takeBackControlInterpolant: function ( interpolant ) {
  23344. var interpolants = this._controlInterpolants,
  23345. prevIndex = interpolant.__cacheIndex,
  23346. firstInactiveIndex = -- this._nActiveControlInterpolants,
  23347. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  23348. interpolant.__cacheIndex = firstInactiveIndex;
  23349. interpolants[ firstInactiveIndex ] = interpolant;
  23350. lastActiveInterpolant.__cacheIndex = prevIndex;
  23351. interpolants[ prevIndex ] = lastActiveInterpolant;
  23352. },
  23353. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  23354. // return an action for a clip optionally using a custom root target
  23355. // object (this method allocates a lot of dynamic memory in case a
  23356. // previously unknown clip/root combination is specified)
  23357. clipAction: function ( clip, optionalRoot ) {
  23358. var root = optionalRoot || this._root,
  23359. rootUuid = root.uuid,
  23360. clipObject = typeof clip === 'string' ?
  23361. AnimationClip.findByName( root, clip ) : clip,
  23362. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  23363. actionsForClip = this._actionsByClip[ clipUuid ],
  23364. prototypeAction = null;
  23365. if ( actionsForClip !== undefined ) {
  23366. var existingAction =
  23367. actionsForClip.actionByRoot[ rootUuid ];
  23368. if ( existingAction !== undefined ) {
  23369. return existingAction;
  23370. }
  23371. // we know the clip, so we don't have to parse all
  23372. // the bindings again but can just copy
  23373. prototypeAction = actionsForClip.knownActions[ 0 ];
  23374. // also, take the clip from the prototype action
  23375. if ( clipObject === null )
  23376. clipObject = prototypeAction._clip;
  23377. }
  23378. // clip must be known when specified via string
  23379. if ( clipObject === null ) return null;
  23380. // allocate all resources required to run it
  23381. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  23382. this._bindAction( newAction, prototypeAction );
  23383. // and make the action known to the memory manager
  23384. this._addInactiveAction( newAction, clipUuid, rootUuid );
  23385. return newAction;
  23386. },
  23387. // get an existing action
  23388. existingAction: function ( clip, optionalRoot ) {
  23389. var root = optionalRoot || this._root,
  23390. rootUuid = root.uuid,
  23391. clipObject = typeof clip === 'string' ?
  23392. AnimationClip.findByName( root, clip ) : clip,
  23393. clipUuid = clipObject ? clipObject.uuid : clip,
  23394. actionsForClip = this._actionsByClip[ clipUuid ];
  23395. if ( actionsForClip !== undefined ) {
  23396. return actionsForClip.actionByRoot[ rootUuid ] || null;
  23397. }
  23398. return null;
  23399. },
  23400. // deactivates all previously scheduled actions
  23401. stopAllAction: function () {
  23402. var actions = this._actions,
  23403. nActions = this._nActiveActions,
  23404. bindings = this._bindings,
  23405. nBindings = this._nActiveBindings;
  23406. this._nActiveActions = 0;
  23407. this._nActiveBindings = 0;
  23408. for ( var i = 0; i !== nActions; ++ i ) {
  23409. actions[ i ].reset();
  23410. }
  23411. for ( var i = 0; i !== nBindings; ++ i ) {
  23412. bindings[ i ].useCount = 0;
  23413. }
  23414. return this;
  23415. },
  23416. // advance the time and update apply the animation
  23417. update: function ( deltaTime ) {
  23418. deltaTime *= this.timeScale;
  23419. var actions = this._actions,
  23420. nActions = this._nActiveActions,
  23421. time = this.time += deltaTime,
  23422. timeDirection = Math.sign( deltaTime ),
  23423. accuIndex = this._accuIndex ^= 1;
  23424. // run active actions
  23425. for ( var i = 0; i !== nActions; ++ i ) {
  23426. var action = actions[ i ];
  23427. action._update( time, deltaTime, timeDirection, accuIndex );
  23428. }
  23429. // update scene graph
  23430. var bindings = this._bindings,
  23431. nBindings = this._nActiveBindings;
  23432. for ( var i = 0; i !== nBindings; ++ i ) {
  23433. bindings[ i ].apply( accuIndex );
  23434. }
  23435. return this;
  23436. },
  23437. // return this mixer's root target object
  23438. getRoot: function () {
  23439. return this._root;
  23440. },
  23441. // free all resources specific to a particular clip
  23442. uncacheClip: function ( clip ) {
  23443. var actions = this._actions,
  23444. clipUuid = clip.uuid,
  23445. actionsByClip = this._actionsByClip,
  23446. actionsForClip = actionsByClip[ clipUuid ];
  23447. if ( actionsForClip !== undefined ) {
  23448. // note: just calling _removeInactiveAction would mess up the
  23449. // iteration state and also require updating the state we can
  23450. // just throw away
  23451. var actionsToRemove = actionsForClip.knownActions;
  23452. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  23453. var action = actionsToRemove[ i ];
  23454. this._deactivateAction( action );
  23455. var cacheIndex = action._cacheIndex,
  23456. lastInactiveAction = actions[ actions.length - 1 ];
  23457. action._cacheIndex = null;
  23458. action._byClipCacheIndex = null;
  23459. lastInactiveAction._cacheIndex = cacheIndex;
  23460. actions[ cacheIndex ] = lastInactiveAction;
  23461. actions.pop();
  23462. this._removeInactiveBindingsForAction( action );
  23463. }
  23464. delete actionsByClip[ clipUuid ];
  23465. }
  23466. },
  23467. // free all resources specific to a particular root target object
  23468. uncacheRoot: function ( root ) {
  23469. var rootUuid = root.uuid,
  23470. actionsByClip = this._actionsByClip;
  23471. for ( var clipUuid in actionsByClip ) {
  23472. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  23473. action = actionByRoot[ rootUuid ];
  23474. if ( action !== undefined ) {
  23475. this._deactivateAction( action );
  23476. this._removeInactiveAction( action );
  23477. }
  23478. }
  23479. var bindingsByRoot = this._bindingsByRootAndName,
  23480. bindingByName = bindingsByRoot[ rootUuid ];
  23481. if ( bindingByName !== undefined ) {
  23482. for ( var trackName in bindingByName ) {
  23483. var binding = bindingByName[ trackName ];
  23484. binding.restoreOriginalState();
  23485. this._removeInactiveBinding( binding );
  23486. }
  23487. }
  23488. },
  23489. // remove a targeted clip from the cache
  23490. uncacheAction: function ( clip, optionalRoot ) {
  23491. var action = this.existingAction( clip, optionalRoot );
  23492. if ( action !== null ) {
  23493. this._deactivateAction( action );
  23494. this._removeInactiveAction( action );
  23495. }
  23496. }
  23497. } );
  23498. /**
  23499. * @author mrdoob / http://mrdoob.com/
  23500. */
  23501. function Uniform( value ) {
  23502. if ( typeof value === 'string' ) {
  23503. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  23504. value = arguments[ 1 ];
  23505. }
  23506. this.value = value;
  23507. }
  23508. Uniform.prototype.clone = function () {
  23509. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  23510. };
  23511. /**
  23512. * @author benaadams / https://twitter.com/ben_a_adams
  23513. */
  23514. function InstancedBufferGeometry() {
  23515. BufferGeometry.call( this );
  23516. this.type = 'InstancedBufferGeometry';
  23517. this.maxInstancedCount = undefined;
  23518. }
  23519. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  23520. constructor: InstancedBufferGeometry,
  23521. isInstancedBufferGeometry: true,
  23522. addGroup: function ( start, count, materialIndex ) {
  23523. this.groups.push( {
  23524. start: start,
  23525. count: count,
  23526. materialIndex: materialIndex
  23527. } );
  23528. },
  23529. copy: function ( source ) {
  23530. var index = source.index;
  23531. if ( index !== null ) {
  23532. this.setIndex( index.clone() );
  23533. }
  23534. var attributes = source.attributes;
  23535. for ( var name in attributes ) {
  23536. var attribute = attributes[ name ];
  23537. this.addAttribute( name, attribute.clone() );
  23538. }
  23539. var groups = source.groups;
  23540. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  23541. var group = groups[ i ];
  23542. this.addGroup( group.start, group.count, group.materialIndex );
  23543. }
  23544. return this;
  23545. }
  23546. } );
  23547. /**
  23548. * @author benaadams / https://twitter.com/ben_a_adams
  23549. */
  23550. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  23551. this.uuid = _Math.generateUUID();
  23552. this.data = interleavedBuffer;
  23553. this.itemSize = itemSize;
  23554. this.offset = offset;
  23555. this.normalized = normalized === true;
  23556. }
  23557. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  23558. count: {
  23559. get: function () {
  23560. return this.data.count;
  23561. }
  23562. },
  23563. array: {
  23564. get: function () {
  23565. return this.data.array;
  23566. }
  23567. }
  23568. } );
  23569. Object.assign( InterleavedBufferAttribute.prototype, {
  23570. isInterleavedBufferAttribute: true,
  23571. setX: function ( index, x ) {
  23572. this.data.array[ index * this.data.stride + this.offset ] = x;
  23573. return this;
  23574. },
  23575. setY: function ( index, y ) {
  23576. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  23577. return this;
  23578. },
  23579. setZ: function ( index, z ) {
  23580. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  23581. return this;
  23582. },
  23583. setW: function ( index, w ) {
  23584. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  23585. return this;
  23586. },
  23587. getX: function ( index ) {
  23588. return this.data.array[ index * this.data.stride + this.offset ];
  23589. },
  23590. getY: function ( index ) {
  23591. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  23592. },
  23593. getZ: function ( index ) {
  23594. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  23595. },
  23596. getW: function ( index ) {
  23597. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  23598. },
  23599. setXY: function ( index, x, y ) {
  23600. index = index * this.data.stride + this.offset;
  23601. this.data.array[ index + 0 ] = x;
  23602. this.data.array[ index + 1 ] = y;
  23603. return this;
  23604. },
  23605. setXYZ: function ( index, x, y, z ) {
  23606. index = index * this.data.stride + this.offset;
  23607. this.data.array[ index + 0 ] = x;
  23608. this.data.array[ index + 1 ] = y;
  23609. this.data.array[ index + 2 ] = z;
  23610. return this;
  23611. },
  23612. setXYZW: function ( index, x, y, z, w ) {
  23613. index = index * this.data.stride + this.offset;
  23614. this.data.array[ index + 0 ] = x;
  23615. this.data.array[ index + 1 ] = y;
  23616. this.data.array[ index + 2 ] = z;
  23617. this.data.array[ index + 3 ] = w;
  23618. return this;
  23619. }
  23620. } );
  23621. /**
  23622. * @author benaadams / https://twitter.com/ben_a_adams
  23623. */
  23624. function InterleavedBuffer( array, stride ) {
  23625. this.uuid = _Math.generateUUID();
  23626. this.array = array;
  23627. this.stride = stride;
  23628. this.count = array !== undefined ? array.length / stride : 0;
  23629. this.dynamic = false;
  23630. this.updateRange = { offset: 0, count: - 1 };
  23631. this.onUploadCallback = function () {};
  23632. this.version = 0;
  23633. }
  23634. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  23635. set: function ( value ) {
  23636. if ( value === true ) this.version ++;
  23637. }
  23638. } );
  23639. Object.assign( InterleavedBuffer.prototype, {
  23640. isInterleavedBuffer: true,
  23641. setArray: function ( array ) {
  23642. if ( Array.isArray( array ) ) {
  23643. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  23644. }
  23645. this.count = array !== undefined ? array.length / this.stride : 0;
  23646. this.array = array;
  23647. },
  23648. setDynamic: function ( value ) {
  23649. this.dynamic = value;
  23650. return this;
  23651. },
  23652. copy: function ( source ) {
  23653. this.array = new source.array.constructor( source.array );
  23654. this.count = source.count;
  23655. this.stride = source.stride;
  23656. this.dynamic = source.dynamic;
  23657. return this;
  23658. },
  23659. copyAt: function ( index1, attribute, index2 ) {
  23660. index1 *= this.stride;
  23661. index2 *= attribute.stride;
  23662. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  23663. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  23664. }
  23665. return this;
  23666. },
  23667. set: function ( value, offset ) {
  23668. if ( offset === undefined ) offset = 0;
  23669. this.array.set( value, offset );
  23670. return this;
  23671. },
  23672. clone: function () {
  23673. return new this.constructor().copy( this );
  23674. },
  23675. onUpload: function ( callback ) {
  23676. this.onUploadCallback = callback;
  23677. return this;
  23678. }
  23679. } );
  23680. /**
  23681. * @author benaadams / https://twitter.com/ben_a_adams
  23682. */
  23683. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  23684. InterleavedBuffer.call( this, array, stride );
  23685. this.meshPerAttribute = meshPerAttribute || 1;
  23686. }
  23687. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  23688. constructor: InstancedInterleavedBuffer,
  23689. isInstancedInterleavedBuffer: true,
  23690. copy: function ( source ) {
  23691. InterleavedBuffer.prototype.copy.call( this, source );
  23692. this.meshPerAttribute = source.meshPerAttribute;
  23693. return this;
  23694. }
  23695. } );
  23696. /**
  23697. * @author benaadams / https://twitter.com/ben_a_adams
  23698. */
  23699. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  23700. BufferAttribute.call( this, array, itemSize );
  23701. this.meshPerAttribute = meshPerAttribute || 1;
  23702. }
  23703. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23704. constructor: InstancedBufferAttribute,
  23705. isInstancedBufferAttribute: true,
  23706. copy: function ( source ) {
  23707. BufferAttribute.prototype.copy.call( this, source );
  23708. this.meshPerAttribute = source.meshPerAttribute;
  23709. return this;
  23710. }
  23711. } );
  23712. /**
  23713. * @author mrdoob / http://mrdoob.com/
  23714. * @author bhouston / http://clara.io/
  23715. * @author stephomi / http://stephaneginier.com/
  23716. */
  23717. function Raycaster( origin, direction, near, far ) {
  23718. this.ray = new Ray( origin, direction );
  23719. // direction is assumed to be normalized (for accurate distance calculations)
  23720. this.near = near || 0;
  23721. this.far = far || Infinity;
  23722. this.params = {
  23723. Mesh: {},
  23724. Line: {},
  23725. LOD: {},
  23726. Points: { threshold: 1 },
  23727. Sprite: {}
  23728. };
  23729. Object.defineProperties( this.params, {
  23730. PointCloud: {
  23731. get: function () {
  23732. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  23733. return this.Points;
  23734. }
  23735. }
  23736. } );
  23737. }
  23738. function ascSort( a, b ) {
  23739. return a.distance - b.distance;
  23740. }
  23741. function intersectObject( object, raycaster, intersects, recursive ) {
  23742. if ( object.visible === false ) return;
  23743. object.raycast( raycaster, intersects );
  23744. if ( recursive === true ) {
  23745. var children = object.children;
  23746. for ( var i = 0, l = children.length; i < l; i ++ ) {
  23747. intersectObject( children[ i ], raycaster, intersects, true );
  23748. }
  23749. }
  23750. }
  23751. Object.assign( Raycaster.prototype, {
  23752. linePrecision: 1,
  23753. set: function ( origin, direction ) {
  23754. // direction is assumed to be normalized (for accurate distance calculations)
  23755. this.ray.set( origin, direction );
  23756. },
  23757. setFromCamera: function ( coords, camera ) {
  23758. if ( ( camera && camera.isPerspectiveCamera ) ) {
  23759. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  23760. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  23761. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  23762. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  23763. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  23764. } else {
  23765. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  23766. }
  23767. },
  23768. intersectObject: function ( object, recursive ) {
  23769. var intersects = [];
  23770. intersectObject( object, this, intersects, recursive );
  23771. intersects.sort( ascSort );
  23772. return intersects;
  23773. },
  23774. intersectObjects: function ( objects, recursive ) {
  23775. var intersects = [];
  23776. if ( Array.isArray( objects ) === false ) {
  23777. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  23778. return intersects;
  23779. }
  23780. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  23781. intersectObject( objects[ i ], this, intersects, recursive );
  23782. }
  23783. intersects.sort( ascSort );
  23784. return intersects;
  23785. }
  23786. } );
  23787. /**
  23788. * @author alteredq / http://alteredqualia.com/
  23789. */
  23790. function Clock( autoStart ) {
  23791. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  23792. this.startTime = 0;
  23793. this.oldTime = 0;
  23794. this.elapsedTime = 0;
  23795. this.running = false;
  23796. }
  23797. Object.assign( Clock.prototype, {
  23798. start: function () {
  23799. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  23800. this.oldTime = this.startTime;
  23801. this.elapsedTime = 0;
  23802. this.running = true;
  23803. },
  23804. stop: function () {
  23805. this.getElapsedTime();
  23806. this.running = false;
  23807. },
  23808. getElapsedTime: function () {
  23809. this.getDelta();
  23810. return this.elapsedTime;
  23811. },
  23812. getDelta: function () {
  23813. var diff = 0;
  23814. if ( this.autoStart && ! this.running ) {
  23815. this.start();
  23816. return 0;
  23817. }
  23818. if ( this.running ) {
  23819. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  23820. diff = ( newTime - this.oldTime ) / 1000;
  23821. this.oldTime = newTime;
  23822. this.elapsedTime += diff;
  23823. }
  23824. return diff;
  23825. }
  23826. } );
  23827. /**
  23828. * @author bhouston / http://clara.io
  23829. * @author WestLangley / http://github.com/WestLangley
  23830. *
  23831. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  23832. *
  23833. * The poles (phi) are at the positive and negative y axis.
  23834. * The equator starts at positive z.
  23835. */
  23836. function Spherical( radius, phi, theta ) {
  23837. this.radius = ( radius !== undefined ) ? radius : 1.0;
  23838. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  23839. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  23840. return this;
  23841. }
  23842. Object.assign( Spherical.prototype, {
  23843. set: function ( radius, phi, theta ) {
  23844. this.radius = radius;
  23845. this.phi = phi;
  23846. this.theta = theta;
  23847. return this;
  23848. },
  23849. clone: function () {
  23850. return new this.constructor().copy( this );
  23851. },
  23852. copy: function ( other ) {
  23853. this.radius = other.radius;
  23854. this.phi = other.phi;
  23855. this.theta = other.theta;
  23856. return this;
  23857. },
  23858. // restrict phi to be betwee EPS and PI-EPS
  23859. makeSafe: function() {
  23860. var EPS = 0.000001;
  23861. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  23862. return this;
  23863. },
  23864. setFromVector3: function( vec3 ) {
  23865. this.radius = vec3.length();
  23866. if ( this.radius === 0 ) {
  23867. this.theta = 0;
  23868. this.phi = 0;
  23869. } else {
  23870. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  23871. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  23872. }
  23873. return this;
  23874. }
  23875. } );
  23876. /**
  23877. * @author Mugen87 / https://github.com/Mugen87
  23878. *
  23879. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  23880. *
  23881. */
  23882. function Cylindrical( radius, theta, y ) {
  23883. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  23884. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  23885. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  23886. return this;
  23887. }
  23888. Object.assign( Cylindrical.prototype, {
  23889. set: function ( radius, theta, y ) {
  23890. this.radius = radius;
  23891. this.theta = theta;
  23892. this.y = y;
  23893. return this;
  23894. },
  23895. clone: function () {
  23896. return new this.constructor().copy( this );
  23897. },
  23898. copy: function ( other ) {
  23899. this.radius = other.radius;
  23900. this.theta = other.theta;
  23901. this.y = other.y;
  23902. return this;
  23903. },
  23904. setFromVector3: function( vec3 ) {
  23905. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  23906. this.theta = Math.atan2( vec3.x, vec3.z );
  23907. this.y = vec3.y;
  23908. return this;
  23909. }
  23910. } );
  23911. /**
  23912. * @author alteredq / http://alteredqualia.com/
  23913. */
  23914. function MorphBlendMesh( geometry, material ) {
  23915. Mesh.call( this, geometry, material );
  23916. this.animationsMap = {};
  23917. this.animationsList = [];
  23918. // prepare default animation
  23919. // (all frames played together in 1 second)
  23920. var numFrames = this.geometry.morphTargets.length;
  23921. var name = "__default";
  23922. var startFrame = 0;
  23923. var endFrame = numFrames - 1;
  23924. var fps = numFrames / 1;
  23925. this.createAnimation( name, startFrame, endFrame, fps );
  23926. this.setAnimationWeight( name, 1 );
  23927. }
  23928. MorphBlendMesh.prototype = Object.create( Mesh.prototype );
  23929. MorphBlendMesh.prototype.constructor = MorphBlendMesh;
  23930. MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  23931. var animation = {
  23932. start: start,
  23933. end: end,
  23934. length: end - start + 1,
  23935. fps: fps,
  23936. duration: ( end - start ) / fps,
  23937. lastFrame: 0,
  23938. currentFrame: 0,
  23939. active: false,
  23940. time: 0,
  23941. direction: 1,
  23942. weight: 1,
  23943. directionBackwards: false,
  23944. mirroredLoop: false
  23945. };
  23946. this.animationsMap[ name ] = animation;
  23947. this.animationsList.push( animation );
  23948. };
  23949. MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  23950. var pattern = /([a-z]+)_?(\d+)/i;
  23951. var firstAnimation, frameRanges = {};
  23952. var geometry = this.geometry;
  23953. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  23954. var morph = geometry.morphTargets[ i ];
  23955. var chunks = morph.name.match( pattern );
  23956. if ( chunks && chunks.length > 1 ) {
  23957. var name = chunks[ 1 ];
  23958. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  23959. var range = frameRanges[ name ];
  23960. if ( i < range.start ) range.start = i;
  23961. if ( i > range.end ) range.end = i;
  23962. if ( ! firstAnimation ) firstAnimation = name;
  23963. }
  23964. }
  23965. for ( var name in frameRanges ) {
  23966. var range = frameRanges[ name ];
  23967. this.createAnimation( name, range.start, range.end, fps );
  23968. }
  23969. this.firstAnimation = firstAnimation;
  23970. };
  23971. MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  23972. var animation = this.animationsMap[ name ];
  23973. if ( animation ) {
  23974. animation.direction = 1;
  23975. animation.directionBackwards = false;
  23976. }
  23977. };
  23978. MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  23979. var animation = this.animationsMap[ name ];
  23980. if ( animation ) {
  23981. animation.direction = - 1;
  23982. animation.directionBackwards = true;
  23983. }
  23984. };
  23985. MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  23986. var animation = this.animationsMap[ name ];
  23987. if ( animation ) {
  23988. animation.fps = fps;
  23989. animation.duration = ( animation.end - animation.start ) / animation.fps;
  23990. }
  23991. };
  23992. MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  23993. var animation = this.animationsMap[ name ];
  23994. if ( animation ) {
  23995. animation.duration = duration;
  23996. animation.fps = ( animation.end - animation.start ) / animation.duration;
  23997. }
  23998. };
  23999. MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24000. var animation = this.animationsMap[ name ];
  24001. if ( animation ) {
  24002. animation.weight = weight;
  24003. }
  24004. };
  24005. MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24006. var animation = this.animationsMap[ name ];
  24007. if ( animation ) {
  24008. animation.time = time;
  24009. }
  24010. };
  24011. MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24012. var time = 0;
  24013. var animation = this.animationsMap[ name ];
  24014. if ( animation ) {
  24015. time = animation.time;
  24016. }
  24017. return time;
  24018. };
  24019. MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24020. var duration = - 1;
  24021. var animation = this.animationsMap[ name ];
  24022. if ( animation ) {
  24023. duration = animation.duration;
  24024. }
  24025. return duration;
  24026. };
  24027. MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24028. var animation = this.animationsMap[ name ];
  24029. if ( animation ) {
  24030. animation.time = 0;
  24031. animation.active = true;
  24032. } else {
  24033. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24034. }
  24035. };
  24036. MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24037. var animation = this.animationsMap[ name ];
  24038. if ( animation ) {
  24039. animation.active = false;
  24040. }
  24041. };
  24042. MorphBlendMesh.prototype.update = function ( delta ) {
  24043. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24044. var animation = this.animationsList[ i ];
  24045. if ( ! animation.active ) continue;
  24046. var frameTime = animation.duration / animation.length;
  24047. animation.time += animation.direction * delta;
  24048. if ( animation.mirroredLoop ) {
  24049. if ( animation.time > animation.duration || animation.time < 0 ) {
  24050. animation.direction *= - 1;
  24051. if ( animation.time > animation.duration ) {
  24052. animation.time = animation.duration;
  24053. animation.directionBackwards = true;
  24054. }
  24055. if ( animation.time < 0 ) {
  24056. animation.time = 0;
  24057. animation.directionBackwards = false;
  24058. }
  24059. }
  24060. } else {
  24061. animation.time = animation.time % animation.duration;
  24062. if ( animation.time < 0 ) animation.time += animation.duration;
  24063. }
  24064. var keyframe = animation.start + _Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24065. var weight = animation.weight;
  24066. if ( keyframe !== animation.currentFrame ) {
  24067. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24068. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24069. this.morphTargetInfluences[ keyframe ] = 0;
  24070. animation.lastFrame = animation.currentFrame;
  24071. animation.currentFrame = keyframe;
  24072. }
  24073. var mix = ( animation.time % frameTime ) / frameTime;
  24074. if ( animation.directionBackwards ) mix = 1 - mix;
  24075. if ( animation.currentFrame !== animation.lastFrame ) {
  24076. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24077. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24078. } else {
  24079. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24080. }
  24081. }
  24082. };
  24083. /**
  24084. * @author alteredq / http://alteredqualia.com/
  24085. */
  24086. function ImmediateRenderObject( material ) {
  24087. Object3D.call( this );
  24088. this.material = material;
  24089. this.render = function ( renderCallback ) {};
  24090. }
  24091. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  24092. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  24093. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  24094. /**
  24095. * @author mrdoob / http://mrdoob.com/
  24096. * @author WestLangley / http://github.com/WestLangley
  24097. */
  24098. function VertexNormalsHelper( object, size, hex, linewidth ) {
  24099. this.object = object;
  24100. this.size = ( size !== undefined ) ? size : 1;
  24101. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24102. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24103. //
  24104. var nNormals = 0;
  24105. var objGeometry = this.object.geometry;
  24106. if ( objGeometry && objGeometry.isGeometry ) {
  24107. nNormals = objGeometry.faces.length * 3;
  24108. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  24109. nNormals = objGeometry.attributes.normal.count;
  24110. }
  24111. //
  24112. var geometry = new BufferGeometry();
  24113. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  24114. geometry.addAttribute( 'position', positions );
  24115. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  24116. //
  24117. this.matrixAutoUpdate = false;
  24118. this.update();
  24119. }
  24120. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  24121. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  24122. VertexNormalsHelper.prototype.update = ( function () {
  24123. var v1 = new Vector3();
  24124. var v2 = new Vector3();
  24125. var normalMatrix = new Matrix3();
  24126. return function update() {
  24127. var keys = [ 'a', 'b', 'c' ];
  24128. this.object.updateMatrixWorld( true );
  24129. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24130. var matrixWorld = this.object.matrixWorld;
  24131. var position = this.geometry.attributes.position;
  24132. //
  24133. var objGeometry = this.object.geometry;
  24134. if ( objGeometry && objGeometry.isGeometry ) {
  24135. var vertices = objGeometry.vertices;
  24136. var faces = objGeometry.faces;
  24137. var idx = 0;
  24138. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24139. var face = faces[ i ];
  24140. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24141. var vertex = vertices[ face[ keys[ j ] ] ];
  24142. var normal = face.vertexNormals[ j ];
  24143. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24144. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24145. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24146. idx = idx + 1;
  24147. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24148. idx = idx + 1;
  24149. }
  24150. }
  24151. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  24152. var objPos = objGeometry.attributes.position;
  24153. var objNorm = objGeometry.attributes.normal;
  24154. var idx = 0;
  24155. // for simplicity, ignore index and drawcalls, and render every normal
  24156. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24157. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24158. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24159. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24160. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24161. idx = idx + 1;
  24162. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24163. idx = idx + 1;
  24164. }
  24165. }
  24166. position.needsUpdate = true;
  24167. };
  24168. }() );
  24169. /**
  24170. * @author alteredq / http://alteredqualia.com/
  24171. * @author mrdoob / http://mrdoob.com/
  24172. * @author WestLangley / http://github.com/WestLangley
  24173. */
  24174. function SpotLightHelper( light ) {
  24175. Object3D.call( this );
  24176. this.light = light;
  24177. this.light.updateMatrixWorld();
  24178. this.matrix = light.matrixWorld;
  24179. this.matrixAutoUpdate = false;
  24180. var geometry = new BufferGeometry();
  24181. var positions = [
  24182. 0, 0, 0, 0, 0, 1,
  24183. 0, 0, 0, 1, 0, 1,
  24184. 0, 0, 0, - 1, 0, 1,
  24185. 0, 0, 0, 0, 1, 1,
  24186. 0, 0, 0, 0, - 1, 1
  24187. ];
  24188. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  24189. var p1 = ( i / l ) * Math.PI * 2;
  24190. var p2 = ( j / l ) * Math.PI * 2;
  24191. positions.push(
  24192. Math.cos( p1 ), Math.sin( p1 ), 1,
  24193. Math.cos( p2 ), Math.sin( p2 ), 1
  24194. );
  24195. }
  24196. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  24197. var material = new LineBasicMaterial( { fog: false } );
  24198. this.cone = new LineSegments( geometry, material );
  24199. this.add( this.cone );
  24200. this.update();
  24201. }
  24202. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  24203. SpotLightHelper.prototype.constructor = SpotLightHelper;
  24204. SpotLightHelper.prototype.dispose = function () {
  24205. this.cone.geometry.dispose();
  24206. this.cone.material.dispose();
  24207. };
  24208. SpotLightHelper.prototype.update = function () {
  24209. var vector = new Vector3();
  24210. var vector2 = new Vector3();
  24211. return function update() {
  24212. var coneLength = this.light.distance ? this.light.distance : 1000;
  24213. var coneWidth = coneLength * Math.tan( this.light.angle );
  24214. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24215. vector.setFromMatrixPosition( this.light.matrixWorld );
  24216. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24217. this.cone.lookAt( vector2.sub( vector ) );
  24218. this.cone.material.color.copy( this.light.color );
  24219. };
  24220. }();
  24221. /**
  24222. * @author Sean Griffin / http://twitter.com/sgrif
  24223. * @author Michael Guerrero / http://realitymeltdown.com
  24224. * @author mrdoob / http://mrdoob.com/
  24225. * @author ikerr / http://verold.com
  24226. * @author Mugen87 / https://github.com/Mugen87
  24227. */
  24228. function SkeletonHelper( object ) {
  24229. this.bones = this.getBoneList( object );
  24230. var geometry = new BufferGeometry();
  24231. var vertices = [];
  24232. var colors = [];
  24233. var color1 = new Color( 0, 0, 1 );
  24234. var color2 = new Color( 0, 1, 0 );
  24235. for ( var i = 0; i < this.bones.length; i ++ ) {
  24236. var bone = this.bones[ i ];
  24237. if ( bone.parent && bone.parent.isBone ) {
  24238. vertices.push( 0, 0, 0 );
  24239. vertices.push( 0, 0, 0 );
  24240. colors.push( color1.r, color1.g, color1.b );
  24241. colors.push( color2.r, color2.g, color2.b );
  24242. }
  24243. }
  24244. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24245. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24246. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24247. LineSegments.call( this, geometry, material );
  24248. this.root = object;
  24249. this.matrix = object.matrixWorld;
  24250. this.matrixAutoUpdate = false;
  24251. this.update();
  24252. }
  24253. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  24254. SkeletonHelper.prototype.constructor = SkeletonHelper;
  24255. SkeletonHelper.prototype.getBoneList = function( object ) {
  24256. var boneList = [];
  24257. if ( object && object.isBone ) {
  24258. boneList.push( object );
  24259. }
  24260. for ( var i = 0; i < object.children.length; i ++ ) {
  24261. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24262. }
  24263. return boneList;
  24264. };
  24265. SkeletonHelper.prototype.update = function () {
  24266. var vector = new Vector3();
  24267. var boneMatrix = new Matrix4();
  24268. var matrixWorldInv = new Matrix4();
  24269. return function update() {
  24270. var geometry = this.geometry;
  24271. var position = geometry.getAttribute( 'position' );
  24272. matrixWorldInv.getInverse( this.root.matrixWorld );
  24273. for ( var i = 0, j = 0; i < this.bones.length; i ++ ) {
  24274. var bone = this.bones[ i ];
  24275. if ( bone.parent && bone.parent.isBone ) {
  24276. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24277. vector.setFromMatrixPosition( boneMatrix );
  24278. position.setXYZ( j, vector.x, vector.y, vector.z );
  24279. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24280. vector.setFromMatrixPosition( boneMatrix );
  24281. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  24282. j += 2;
  24283. }
  24284. }
  24285. geometry.getAttribute( 'position' ).needsUpdate = true;
  24286. };
  24287. }();
  24288. /**
  24289. * @author alteredq / http://alteredqualia.com/
  24290. * @author mrdoob / http://mrdoob.com/
  24291. */
  24292. function PointLightHelper( light, sphereSize ) {
  24293. this.light = light;
  24294. this.light.updateMatrixWorld();
  24295. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  24296. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  24297. material.color.copy( this.light.color );
  24298. Mesh.call( this, geometry, material );
  24299. this.matrix = this.light.matrixWorld;
  24300. this.matrixAutoUpdate = false;
  24301. /*
  24302. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24303. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24304. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24305. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24306. var d = light.distance;
  24307. if ( d === 0.0 ) {
  24308. this.lightDistance.visible = false;
  24309. } else {
  24310. this.lightDistance.scale.set( d, d, d );
  24311. }
  24312. this.add( this.lightDistance );
  24313. */
  24314. }
  24315. PointLightHelper.prototype = Object.create( Mesh.prototype );
  24316. PointLightHelper.prototype.constructor = PointLightHelper;
  24317. PointLightHelper.prototype.dispose = function () {
  24318. this.geometry.dispose();
  24319. this.material.dispose();
  24320. };
  24321. PointLightHelper.prototype.update = function () {
  24322. this.material.color.copy( this.light.color );
  24323. /*
  24324. var d = this.light.distance;
  24325. if ( d === 0.0 ) {
  24326. this.lightDistance.visible = false;
  24327. } else {
  24328. this.lightDistance.visible = true;
  24329. this.lightDistance.scale.set( d, d, d );
  24330. }
  24331. */
  24332. };
  24333. /**
  24334. * @author abelnation / http://github.com/abelnation
  24335. * @author Mugen87 / http://github.com/Mugen87
  24336. * @author WestLangley / http://github.com/WestLangley
  24337. */
  24338. function RectAreaLightHelper( light ) {
  24339. Object3D.call( this );
  24340. this.light = light;
  24341. this.light.updateMatrixWorld();
  24342. this.matrix = light.matrixWorld;
  24343. this.matrixAutoUpdate = false;
  24344. var material = new LineBasicMaterial( { color: light.color } );
  24345. var geometry = new BufferGeometry();
  24346. geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) );
  24347. this.add( new Line( geometry, material ) );
  24348. this.update();
  24349. }
  24350. RectAreaLightHelper.prototype = Object.create( Object3D.prototype );
  24351. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  24352. RectAreaLightHelper.prototype.dispose = function () {
  24353. this.children[ 0 ].geometry.dispose();
  24354. this.children[ 0 ].material.dispose();
  24355. };
  24356. RectAreaLightHelper.prototype.update = function () {
  24357. var line = this.children[ 0 ];
  24358. // update material
  24359. line.material.color.copy( this.light.color );
  24360. // calculate new dimensions of the helper
  24361. var hx = this.light.width * 0.5;
  24362. var hy = this.light.height * 0.5;
  24363. var position = line.geometry.attributes.position;
  24364. var array = position.array;
  24365. // update vertices
  24366. array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0;
  24367. array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0;
  24368. array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0;
  24369. array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0;
  24370. array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0;
  24371. position.needsUpdate = true;
  24372. };
  24373. /**
  24374. * @author alteredq / http://alteredqualia.com/
  24375. * @author mrdoob / http://mrdoob.com/
  24376. * @author Mugen87 / https://github.com/Mugen87
  24377. */
  24378. function HemisphereLightHelper( light, size ) {
  24379. Object3D.call( this );
  24380. this.light = light;
  24381. this.light.updateMatrixWorld();
  24382. this.matrix = light.matrixWorld;
  24383. this.matrixAutoUpdate = false;
  24384. var geometry = new OctahedronBufferGeometry( size );
  24385. geometry.rotateY( Math.PI * 0.5 );
  24386. var material = new MeshBasicMaterial( { vertexColors: VertexColors, wireframe: true } );
  24387. var position = geometry.getAttribute( 'position' );
  24388. var colors = new Float32Array( position.count * 3 );
  24389. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  24390. this.add( new Mesh( geometry, material ) );
  24391. this.update();
  24392. }
  24393. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  24394. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  24395. HemisphereLightHelper.prototype.dispose = function () {
  24396. this.children[ 0 ].geometry.dispose();
  24397. this.children[ 0 ].material.dispose();
  24398. };
  24399. HemisphereLightHelper.prototype.update = function () {
  24400. var vector = new Vector3();
  24401. var color1 = new Color();
  24402. var color2 = new Color();
  24403. return function update() {
  24404. var mesh = this.children[ 0 ];
  24405. var colors = mesh.geometry.getAttribute( 'color' );
  24406. color1.copy( this.light.color );
  24407. color2.copy( this.light.groundColor );
  24408. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  24409. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  24410. colors.setXYZ( i, color.r, color.g, color.b );
  24411. }
  24412. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24413. colors.needsUpdate = true;
  24414. };
  24415. }();
  24416. /**
  24417. * @author mrdoob / http://mrdoob.com/
  24418. */
  24419. function GridHelper( size, divisions, color1, color2 ) {
  24420. size = size || 10;
  24421. divisions = divisions || 10;
  24422. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  24423. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  24424. var center = divisions / 2;
  24425. var step = size / divisions;
  24426. var halfSize = size / 2;
  24427. var vertices = [], colors = [];
  24428. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  24429. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  24430. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  24431. var color = i === center ? color1 : color2;
  24432. color.toArray( colors, j ); j += 3;
  24433. color.toArray( colors, j ); j += 3;
  24434. color.toArray( colors, j ); j += 3;
  24435. color.toArray( colors, j ); j += 3;
  24436. }
  24437. var geometry = new BufferGeometry();
  24438. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24439. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24440. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  24441. LineSegments.call( this, geometry, material );
  24442. }
  24443. GridHelper.prototype = Object.create( LineSegments.prototype );
  24444. GridHelper.prototype.constructor = GridHelper;
  24445. /**
  24446. * @author mrdoob / http://mrdoob.com/
  24447. * @author Mugen87 / http://github.com/Mugen87
  24448. * @author Hectate / http://www.github.com/Hectate
  24449. */
  24450. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  24451. radius = radius || 10;
  24452. radials = radials || 16;
  24453. circles = circles || 8;
  24454. divisions = divisions || 64;
  24455. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  24456. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  24457. var vertices = [];
  24458. var colors = [];
  24459. var x, z;
  24460. var v, i, j, r, color;
  24461. // create the radials
  24462. for ( i = 0; i <= radials; i ++ ) {
  24463. v = ( i / radials ) * ( Math.PI * 2 );
  24464. x = Math.sin( v ) * radius;
  24465. z = Math.cos( v ) * radius;
  24466. vertices.push( 0, 0, 0 );
  24467. vertices.push( x, 0, z );
  24468. color = ( i & 1 ) ? color1 : color2;
  24469. colors.push( color.r, color.g, color.b );
  24470. colors.push( color.r, color.g, color.b );
  24471. }
  24472. // create the circles
  24473. for ( i = 0; i <= circles; i ++ ) {
  24474. color = ( i & 1 ) ? color1 : color2;
  24475. r = radius - ( radius / circles * i );
  24476. for ( j = 0; j < divisions; j ++ ) {
  24477. // first vertex
  24478. v = ( j / 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. // second vertex
  24484. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  24485. x = Math.sin( v ) * r;
  24486. z = Math.cos( v ) * r;
  24487. vertices.push( x, 0, z );
  24488. colors.push( color.r, color.g, color.b );
  24489. }
  24490. }
  24491. var geometry = new BufferGeometry();
  24492. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24493. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24494. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  24495. LineSegments.call( this, geometry, material );
  24496. }
  24497. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  24498. PolarGridHelper.prototype.constructor = PolarGridHelper;
  24499. /**
  24500. * @author mrdoob / http://mrdoob.com/
  24501. * @author WestLangley / http://github.com/WestLangley
  24502. */
  24503. function FaceNormalsHelper( object, size, hex, linewidth ) {
  24504. // FaceNormalsHelper only supports THREE.Geometry
  24505. this.object = object;
  24506. this.size = ( size !== undefined ) ? size : 1;
  24507. var color = ( hex !== undefined ) ? hex : 0xffff00;
  24508. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24509. //
  24510. var nNormals = 0;
  24511. var objGeometry = this.object.geometry;
  24512. if ( objGeometry && objGeometry.isGeometry ) {
  24513. nNormals = objGeometry.faces.length;
  24514. } else {
  24515. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  24516. }
  24517. //
  24518. var geometry = new BufferGeometry();
  24519. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  24520. geometry.addAttribute( 'position', positions );
  24521. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  24522. //
  24523. this.matrixAutoUpdate = false;
  24524. this.update();
  24525. }
  24526. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  24527. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  24528. FaceNormalsHelper.prototype.update = ( function () {
  24529. var v1 = new Vector3();
  24530. var v2 = new Vector3();
  24531. var normalMatrix = new Matrix3();
  24532. return function update() {
  24533. this.object.updateMatrixWorld( true );
  24534. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24535. var matrixWorld = this.object.matrixWorld;
  24536. var position = this.geometry.attributes.position;
  24537. //
  24538. var objGeometry = this.object.geometry;
  24539. var vertices = objGeometry.vertices;
  24540. var faces = objGeometry.faces;
  24541. var idx = 0;
  24542. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24543. var face = faces[ i ];
  24544. var normal = face.normal;
  24545. v1.copy( vertices[ face.a ] )
  24546. .add( vertices[ face.b ] )
  24547. .add( vertices[ face.c ] )
  24548. .divideScalar( 3 )
  24549. .applyMatrix4( matrixWorld );
  24550. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24551. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24552. idx = idx + 1;
  24553. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24554. idx = idx + 1;
  24555. }
  24556. position.needsUpdate = true;
  24557. };
  24558. }() );
  24559. /**
  24560. * @author alteredq / http://alteredqualia.com/
  24561. * @author mrdoob / http://mrdoob.com/
  24562. * @author WestLangley / http://github.com/WestLangley
  24563. */
  24564. function DirectionalLightHelper( light, size ) {
  24565. Object3D.call( this );
  24566. this.light = light;
  24567. this.light.updateMatrixWorld();
  24568. this.matrix = light.matrixWorld;
  24569. this.matrixAutoUpdate = false;
  24570. if ( size === undefined ) size = 1;
  24571. var geometry = new BufferGeometry();
  24572. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  24573. - size, size, 0,
  24574. size, size, 0,
  24575. size, - size, 0,
  24576. - size, - size, 0,
  24577. - size, size, 0
  24578. ], 3 ) );
  24579. var material = new LineBasicMaterial( { fog: false } );
  24580. this.add( new Line( geometry, material ) );
  24581. geometry = new BufferGeometry();
  24582. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  24583. this.add( new Line( geometry, material ));
  24584. this.update();
  24585. }
  24586. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  24587. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  24588. DirectionalLightHelper.prototype.dispose = function () {
  24589. var lightPlane = this.children[ 0 ];
  24590. var targetLine = this.children[ 1 ];
  24591. lightPlane.geometry.dispose();
  24592. lightPlane.material.dispose();
  24593. targetLine.geometry.dispose();
  24594. targetLine.material.dispose();
  24595. };
  24596. DirectionalLightHelper.prototype.update = function () {
  24597. var v1 = new Vector3();
  24598. var v2 = new Vector3();
  24599. var v3 = new Vector3();
  24600. return function update() {
  24601. v1.setFromMatrixPosition( this.light.matrixWorld );
  24602. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  24603. v3.subVectors( v2, v1 );
  24604. var lightPlane = this.children[ 0 ];
  24605. var targetLine = this.children[ 1 ];
  24606. lightPlane.lookAt( v3 );
  24607. lightPlane.material.color.copy( this.light.color );
  24608. targetLine.lookAt( v3 );
  24609. targetLine.scale.z = v3.length();
  24610. };
  24611. }();
  24612. /**
  24613. * @author alteredq / http://alteredqualia.com/
  24614. * @author Mugen87 / https://github.com/Mugen87
  24615. *
  24616. * - shows frustum, line of sight and up of the camera
  24617. * - suitable for fast updates
  24618. * - based on frustum visualization in lightgl.js shadowmap example
  24619. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  24620. */
  24621. function CameraHelper( camera ) {
  24622. var geometry = new BufferGeometry();
  24623. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  24624. var vertices = [];
  24625. var colors = [];
  24626. var pointMap = {};
  24627. // colors
  24628. var colorFrustum = new Color( 0xffaa00 );
  24629. var colorCone = new Color( 0xff0000 );
  24630. var colorUp = new Color( 0x00aaff );
  24631. var colorTarget = new Color( 0xffffff );
  24632. var colorCross = new Color( 0x333333 );
  24633. // near
  24634. addLine( "n1", "n2", colorFrustum );
  24635. addLine( "n2", "n4", colorFrustum );
  24636. addLine( "n4", "n3", colorFrustum );
  24637. addLine( "n3", "n1", colorFrustum );
  24638. // far
  24639. addLine( "f1", "f2", colorFrustum );
  24640. addLine( "f2", "f4", colorFrustum );
  24641. addLine( "f4", "f3", colorFrustum );
  24642. addLine( "f3", "f1", colorFrustum );
  24643. // sides
  24644. addLine( "n1", "f1", colorFrustum );
  24645. addLine( "n2", "f2", colorFrustum );
  24646. addLine( "n3", "f3", colorFrustum );
  24647. addLine( "n4", "f4", colorFrustum );
  24648. // cone
  24649. addLine( "p", "n1", colorCone );
  24650. addLine( "p", "n2", colorCone );
  24651. addLine( "p", "n3", colorCone );
  24652. addLine( "p", "n4", colorCone );
  24653. // up
  24654. addLine( "u1", "u2", colorUp );
  24655. addLine( "u2", "u3", colorUp );
  24656. addLine( "u3", "u1", colorUp );
  24657. // target
  24658. addLine( "c", "t", colorTarget );
  24659. addLine( "p", "c", colorCross );
  24660. // cross
  24661. addLine( "cn1", "cn2", colorCross );
  24662. addLine( "cn3", "cn4", colorCross );
  24663. addLine( "cf1", "cf2", colorCross );
  24664. addLine( "cf3", "cf4", colorCross );
  24665. function addLine( a, b, color ) {
  24666. addPoint( a, color );
  24667. addPoint( b, color );
  24668. }
  24669. function addPoint( id, color ) {
  24670. vertices.push( 0, 0, 0 );
  24671. colors.push( color.r, color.g, color.b );
  24672. if ( pointMap[ id ] === undefined ) {
  24673. pointMap[ id ] = [];
  24674. }
  24675. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  24676. }
  24677. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24678. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24679. LineSegments.call( this, geometry, material );
  24680. this.camera = camera;
  24681. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  24682. this.matrix = camera.matrixWorld;
  24683. this.matrixAutoUpdate = false;
  24684. this.pointMap = pointMap;
  24685. this.update();
  24686. }
  24687. CameraHelper.prototype = Object.create( LineSegments.prototype );
  24688. CameraHelper.prototype.constructor = CameraHelper;
  24689. CameraHelper.prototype.update = function () {
  24690. var geometry, pointMap;
  24691. var vector = new Vector3();
  24692. var camera = new Camera();
  24693. function setPoint( point, x, y, z ) {
  24694. vector.set( x, y, z ).unproject( camera );
  24695. var points = pointMap[ point ];
  24696. if ( points !== undefined ) {
  24697. var position = geometry.getAttribute( 'position' );
  24698. for ( var i = 0, l = points.length; i < l; i ++ ) {
  24699. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  24700. }
  24701. }
  24702. }
  24703. return function update() {
  24704. geometry = this.geometry;
  24705. pointMap = this.pointMap;
  24706. var w = 1, h = 1;
  24707. // we need just camera projection matrix
  24708. // world matrix must be identity
  24709. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  24710. // center / target
  24711. setPoint( "c", 0, 0, - 1 );
  24712. setPoint( "t", 0, 0, 1 );
  24713. // near
  24714. setPoint( "n1", - w, - h, - 1 );
  24715. setPoint( "n2", w, - h, - 1 );
  24716. setPoint( "n3", - w, h, - 1 );
  24717. setPoint( "n4", w, h, - 1 );
  24718. // far
  24719. setPoint( "f1", - w, - h, 1 );
  24720. setPoint( "f2", w, - h, 1 );
  24721. setPoint( "f3", - w, h, 1 );
  24722. setPoint( "f4", w, h, 1 );
  24723. // up
  24724. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  24725. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  24726. setPoint( "u3", 0, h * 2, - 1 );
  24727. // cross
  24728. setPoint( "cf1", - w, 0, 1 );
  24729. setPoint( "cf2", w, 0, 1 );
  24730. setPoint( "cf3", 0, - h, 1 );
  24731. setPoint( "cf4", 0, h, 1 );
  24732. setPoint( "cn1", - w, 0, - 1 );
  24733. setPoint( "cn2", w, 0, - 1 );
  24734. setPoint( "cn3", 0, - h, - 1 );
  24735. setPoint( "cn4", 0, h, - 1 );
  24736. geometry.getAttribute( 'position' ).needsUpdate = true;
  24737. };
  24738. }();
  24739. /**
  24740. * @author mrdoob / http://mrdoob.com/
  24741. * @author Mugen87 / http://github.com/Mugen87
  24742. */
  24743. function BoxHelper( object, color ) {
  24744. this.object = object;
  24745. if ( color === undefined ) color = 0xffff00;
  24746. 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 ] );
  24747. var positions = new Float32Array( 8 * 3 );
  24748. var geometry = new BufferGeometry();
  24749. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  24750. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  24751. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  24752. this.matrixAutoUpdate = false;
  24753. this.update();
  24754. }
  24755. BoxHelper.prototype = Object.create( LineSegments.prototype );
  24756. BoxHelper.prototype.constructor = BoxHelper;
  24757. BoxHelper.prototype.update = ( function () {
  24758. var box = new Box3();
  24759. return function update( object ) {
  24760. if ( object !== undefined ) {
  24761. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  24762. }
  24763. if ( this.object !== undefined ) {
  24764. box.setFromObject( this.object );
  24765. }
  24766. if ( box.isEmpty() ) return;
  24767. var min = box.min;
  24768. var max = box.max;
  24769. /*
  24770. 5____4
  24771. 1/___0/|
  24772. | 6__|_7
  24773. 2/___3/
  24774. 0: max.x, max.y, max.z
  24775. 1: min.x, max.y, max.z
  24776. 2: min.x, min.y, max.z
  24777. 3: max.x, min.y, max.z
  24778. 4: max.x, max.y, min.z
  24779. 5: min.x, max.y, min.z
  24780. 6: min.x, min.y, min.z
  24781. 7: max.x, min.y, min.z
  24782. */
  24783. var position = this.geometry.attributes.position;
  24784. var array = position.array;
  24785. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  24786. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  24787. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  24788. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  24789. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  24790. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  24791. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  24792. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  24793. position.needsUpdate = true;
  24794. this.geometry.computeBoundingSphere();
  24795. };
  24796. } )();
  24797. BoxHelper.prototype.setFromObject = function ( object ) {
  24798. this.object = object;
  24799. this.update();
  24800. return this;
  24801. };
  24802. /**
  24803. * @author WestLangley / http://github.com/WestLangley
  24804. * @author zz85 / http://github.com/zz85
  24805. * @author bhouston / http://clara.io
  24806. *
  24807. * Creates an arrow for visualizing directions
  24808. *
  24809. * Parameters:
  24810. * dir - Vector3
  24811. * origin - Vector3
  24812. * length - Number
  24813. * color - color in hex value
  24814. * headLength - Number
  24815. * headWidth - Number
  24816. */
  24817. var lineGeometry;
  24818. var coneGeometry;
  24819. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  24820. // dir is assumed to be normalized
  24821. Object3D.call( this );
  24822. if ( color === undefined ) color = 0xffff00;
  24823. if ( length === undefined ) length = 1;
  24824. if ( headLength === undefined ) headLength = 0.2 * length;
  24825. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24826. if ( lineGeometry === undefined ) {
  24827. lineGeometry = new BufferGeometry();
  24828. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  24829. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  24830. coneGeometry.translate( 0, - 0.5, 0 );
  24831. }
  24832. this.position.copy( origin );
  24833. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  24834. this.line.matrixAutoUpdate = false;
  24835. this.add( this.line );
  24836. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  24837. this.cone.matrixAutoUpdate = false;
  24838. this.add( this.cone );
  24839. this.setDirection( dir );
  24840. this.setLength( length, headLength, headWidth );
  24841. }
  24842. ArrowHelper.prototype = Object.create( Object3D.prototype );
  24843. ArrowHelper.prototype.constructor = ArrowHelper;
  24844. ArrowHelper.prototype.setDirection = ( function () {
  24845. var axis = new Vector3();
  24846. var radians;
  24847. return function setDirection( dir ) {
  24848. // dir is assumed to be normalized
  24849. if ( dir.y > 0.99999 ) {
  24850. this.quaternion.set( 0, 0, 0, 1 );
  24851. } else if ( dir.y < - 0.99999 ) {
  24852. this.quaternion.set( 1, 0, 0, 0 );
  24853. } else {
  24854. axis.set( dir.z, 0, - dir.x ).normalize();
  24855. radians = Math.acos( dir.y );
  24856. this.quaternion.setFromAxisAngle( axis, radians );
  24857. }
  24858. };
  24859. }() );
  24860. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  24861. if ( headLength === undefined ) headLength = 0.2 * length;
  24862. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24863. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  24864. this.line.updateMatrix();
  24865. this.cone.scale.set( headWidth, headLength, headWidth );
  24866. this.cone.position.y = length;
  24867. this.cone.updateMatrix();
  24868. };
  24869. ArrowHelper.prototype.setColor = function ( color ) {
  24870. this.line.material.color.copy( color );
  24871. this.cone.material.color.copy( color );
  24872. };
  24873. /**
  24874. * @author sroucheray / http://sroucheray.org/
  24875. * @author mrdoob / http://mrdoob.com/
  24876. */
  24877. function AxisHelper( size ) {
  24878. size = size || 1;
  24879. var vertices = [
  24880. 0, 0, 0, size, 0, 0,
  24881. 0, 0, 0, 0, size, 0,
  24882. 0, 0, 0, 0, 0, size
  24883. ];
  24884. var colors = [
  24885. 1, 0, 0, 1, 0.6, 0,
  24886. 0, 1, 0, 0.6, 1, 0,
  24887. 0, 0, 1, 0, 0.6, 1
  24888. ];
  24889. var geometry = new BufferGeometry();
  24890. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  24891. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  24892. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  24893. LineSegments.call( this, geometry, material );
  24894. }
  24895. AxisHelper.prototype = Object.create( LineSegments.prototype );
  24896. AxisHelper.prototype.constructor = AxisHelper;
  24897. /**
  24898. * @author zz85 https://github.com/zz85
  24899. *
  24900. * Centripetal CatmullRom Curve - which is useful for avoiding
  24901. * cusps and self-intersections in non-uniform catmull rom curves.
  24902. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  24903. *
  24904. * curve.type accepts centripetal(default), chordal and catmullrom
  24905. * curve.tension is used for catmullrom which defaults to 0.5
  24906. */
  24907. /*
  24908. Based on an optimized c++ solution in
  24909. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  24910. - http://ideone.com/NoEbVM
  24911. This CubicPoly class could be used for reusing some variables and calculations,
  24912. but for three.js curve use, it could be possible inlined and flatten into a single function call
  24913. which can be placed in CurveUtils.
  24914. */
  24915. function CubicPoly() {
  24916. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  24917. /*
  24918. * Compute coefficients for a cubic polynomial
  24919. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  24920. * such that
  24921. * p(0) = x0, p(1) = x1
  24922. * and
  24923. * p'(0) = t0, p'(1) = t1.
  24924. */
  24925. function init( x0, x1, t0, t1 ) {
  24926. c0 = x0;
  24927. c1 = t0;
  24928. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  24929. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  24930. }
  24931. return {
  24932. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  24933. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  24934. },
  24935. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  24936. // compute tangents when parameterized in [t1,t2]
  24937. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  24938. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  24939. // rescale tangents for parametrization in [0,1]
  24940. t1 *= dt1;
  24941. t2 *= dt1;
  24942. init( x1, x2, t1, t2 );
  24943. },
  24944. calc: function ( t ) {
  24945. var t2 = t * t;
  24946. var t3 = t2 * t;
  24947. return c0 + c1 * t + c2 * t2 + c3 * t3;
  24948. }
  24949. };
  24950. }
  24951. //
  24952. var tmp = new Vector3();
  24953. var px = new CubicPoly();
  24954. var py = new CubicPoly();
  24955. var pz = new CubicPoly();
  24956. function CatmullRomCurve3( p /* array of Vector3 */ ) {
  24957. Curve.call( this );
  24958. this.points = p || [];
  24959. this.closed = false;
  24960. }
  24961. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  24962. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  24963. CatmullRomCurve3.prototype.getPoint = function ( t ) {
  24964. var points = this.points;
  24965. var l = points.length;
  24966. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  24967. var point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  24968. var intPoint = Math.floor( point );
  24969. var weight = point - intPoint;
  24970. if ( this.closed ) {
  24971. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  24972. } else if ( weight === 0 && intPoint === l - 1 ) {
  24973. intPoint = l - 2;
  24974. weight = 1;
  24975. }
  24976. var p0, p1, p2, p3; // 4 points
  24977. if ( this.closed || intPoint > 0 ) {
  24978. p0 = points[ ( intPoint - 1 ) % l ];
  24979. } else {
  24980. // extrapolate first point
  24981. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  24982. p0 = tmp;
  24983. }
  24984. p1 = points[ intPoint % l ];
  24985. p2 = points[ ( intPoint + 1 ) % l ];
  24986. if ( this.closed || intPoint + 2 < l ) {
  24987. p3 = points[ ( intPoint + 2 ) % l ];
  24988. } else {
  24989. // extrapolate last point
  24990. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  24991. p3 = tmp;
  24992. }
  24993. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  24994. // init Centripetal / Chordal Catmull-Rom
  24995. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  24996. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  24997. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  24998. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  24999. // safety check for repeated points
  25000. if ( dt1 < 1e-4 ) dt1 = 1.0;
  25001. if ( dt0 < 1e-4 ) dt0 = dt1;
  25002. if ( dt2 < 1e-4 ) dt2 = dt1;
  25003. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  25004. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  25005. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  25006. } else if ( this.type === 'catmullrom' ) {
  25007. var tension = this.tension !== undefined ? this.tension : 0.5;
  25008. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  25009. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  25010. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  25011. }
  25012. return new Vector3( px.calc( weight ), py.calc( weight ), pz.calc( weight ) );
  25013. };
  25014. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  25015. Curve.call( this );
  25016. this.v0 = v0;
  25017. this.v1 = v1;
  25018. this.v2 = v2;
  25019. this.v3 = v3;
  25020. }
  25021. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  25022. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  25023. CubicBezierCurve3.prototype.getPoint = function ( t ) {
  25024. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  25025. return new Vector3(
  25026. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  25027. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  25028. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  25029. );
  25030. };
  25031. function QuadraticBezierCurve3( v0, v1, v2 ) {
  25032. Curve.call( this );
  25033. this.v0 = v0;
  25034. this.v1 = v1;
  25035. this.v2 = v2;
  25036. }
  25037. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  25038. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  25039. QuadraticBezierCurve3.prototype.getPoint = function ( t ) {
  25040. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  25041. return new Vector3(
  25042. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  25043. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  25044. QuadraticBezier( t, v0.z, v1.z, v2.z )
  25045. );
  25046. };
  25047. function LineCurve3( v1, v2 ) {
  25048. Curve.call( this );
  25049. this.v1 = v1;
  25050. this.v2 = v2;
  25051. }
  25052. LineCurve3.prototype = Object.create( Curve.prototype );
  25053. LineCurve3.prototype.constructor = LineCurve3;
  25054. LineCurve3.prototype.getPoint = function ( t ) {
  25055. if ( t === 1 ) {
  25056. return this.v2.clone();
  25057. }
  25058. var vector = new Vector3();
  25059. vector.subVectors( this.v2, this.v1 ); // diff
  25060. vector.multiplyScalar( t );
  25061. vector.add( this.v1 );
  25062. return vector;
  25063. };
  25064. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  25065. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  25066. }
  25067. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  25068. ArcCurve.prototype.constructor = ArcCurve;
  25069. /**
  25070. * @author alteredq / http://alteredqualia.com/
  25071. */
  25072. var SceneUtils = {
  25073. createMultiMaterialObject: function ( geometry, materials ) {
  25074. var group = new Group();
  25075. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  25076. group.add( new Mesh( geometry, materials[ i ] ) );
  25077. }
  25078. return group;
  25079. },
  25080. detach: function ( child, parent, scene ) {
  25081. child.applyMatrix( parent.matrixWorld );
  25082. parent.remove( child );
  25083. scene.add( child );
  25084. },
  25085. attach: function ( child, scene, parent ) {
  25086. var matrixWorldInverse = new Matrix4();
  25087. matrixWorldInverse.getInverse( parent.matrixWorld );
  25088. child.applyMatrix( matrixWorldInverse );
  25089. scene.remove( child );
  25090. parent.add( child );
  25091. }
  25092. };
  25093. /**
  25094. * @author mrdoob / http://mrdoob.com/
  25095. */
  25096. function Face4( a, b, c, d, normal, color, materialIndex ) {
  25097. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  25098. return new Face3( a, b, c, normal, color, materialIndex );
  25099. }
  25100. var LineStrip = 0;
  25101. var LinePieces = 1;
  25102. function MeshFaceMaterial( materials ) {
  25103. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  25104. return materials;
  25105. }
  25106. function MultiMaterial( materials ) {
  25107. if ( materials === undefined ) materials = [];
  25108. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  25109. materials.isMultiMaterial = true;
  25110. materials.materials = materials;
  25111. materials.clone = function () {
  25112. return materials.slice();
  25113. };
  25114. return materials;
  25115. }
  25116. function PointCloud( geometry, material ) {
  25117. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  25118. return new Points( geometry, material );
  25119. }
  25120. function Particle( material ) {
  25121. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  25122. return new Sprite( material );
  25123. }
  25124. function ParticleSystem( geometry, material ) {
  25125. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  25126. return new Points( geometry, material );
  25127. }
  25128. function PointCloudMaterial( parameters ) {
  25129. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  25130. return new PointsMaterial( parameters );
  25131. }
  25132. function ParticleBasicMaterial( parameters ) {
  25133. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  25134. return new PointsMaterial( parameters );
  25135. }
  25136. function ParticleSystemMaterial( parameters ) {
  25137. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  25138. return new PointsMaterial( parameters );
  25139. }
  25140. function Vertex( x, y, z ) {
  25141. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  25142. return new Vector3( x, y, z );
  25143. }
  25144. //
  25145. function DynamicBufferAttribute( array, itemSize ) {
  25146. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  25147. return new BufferAttribute( array, itemSize ).setDynamic( true );
  25148. }
  25149. function Int8Attribute( array, itemSize ) {
  25150. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  25151. return new Int8BufferAttribute( array, itemSize );
  25152. }
  25153. function Uint8Attribute( array, itemSize ) {
  25154. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  25155. return new Uint8BufferAttribute( array, itemSize );
  25156. }
  25157. function Uint8ClampedAttribute( array, itemSize ) {
  25158. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  25159. return new Uint8ClampedBufferAttribute( array, itemSize );
  25160. }
  25161. function Int16Attribute( array, itemSize ) {
  25162. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  25163. return new Int16BufferAttribute( array, itemSize );
  25164. }
  25165. function Uint16Attribute( array, itemSize ) {
  25166. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  25167. return new Uint16BufferAttribute( array, itemSize );
  25168. }
  25169. function Int32Attribute( array, itemSize ) {
  25170. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  25171. return new Int32BufferAttribute( array, itemSize );
  25172. }
  25173. function Uint32Attribute( array, itemSize ) {
  25174. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  25175. return new Uint32BufferAttribute( array, itemSize );
  25176. }
  25177. function Float32Attribute( array, itemSize ) {
  25178. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  25179. return new Float32BufferAttribute( array, itemSize );
  25180. }
  25181. function Float64Attribute( array, itemSize ) {
  25182. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  25183. return new Float64BufferAttribute( array, itemSize );
  25184. }
  25185. //
  25186. Curve.create = function ( construct, getPoint ) {
  25187. console.log( 'THREE.Curve.create() has been deprecated' );
  25188. construct.prototype = Object.create( Curve.prototype );
  25189. construct.prototype.constructor = construct;
  25190. construct.prototype.getPoint = getPoint;
  25191. return construct;
  25192. };
  25193. //
  25194. function ClosedSplineCurve3( points ) {
  25195. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  25196. CatmullRomCurve3.call( this, points );
  25197. this.type = 'catmullrom';
  25198. this.closed = true;
  25199. }
  25200. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  25201. //
  25202. function SplineCurve3( points ) {
  25203. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  25204. CatmullRomCurve3.call( this, points );
  25205. this.type = 'catmullrom';
  25206. }
  25207. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  25208. //
  25209. function Spline( points ) {
  25210. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  25211. CatmullRomCurve3.call( this, points );
  25212. this.type = 'catmullrom';
  25213. }
  25214. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  25215. Object.assign( Spline.prototype, {
  25216. initFromArray: function ( a ) {
  25217. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  25218. },
  25219. getControlPointsArray: function ( optionalTarget ) {
  25220. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  25221. },
  25222. reparametrizeByArcLength: function ( samplingCoef ) {
  25223. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  25224. }
  25225. } );
  25226. //
  25227. function BoundingBoxHelper( object, color ) {
  25228. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  25229. return new BoxHelper( object, color );
  25230. }
  25231. function EdgesHelper( object, hex ) {
  25232. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  25233. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  25234. }
  25235. GridHelper.prototype.setColors = function () {
  25236. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  25237. };
  25238. function WireframeHelper( object, hex ) {
  25239. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  25240. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  25241. }
  25242. //
  25243. function XHRLoader( manager ) {
  25244. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  25245. return new FileLoader( manager );
  25246. }
  25247. function BinaryTextureLoader( manager ) {
  25248. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  25249. return new DataTextureLoader( manager );
  25250. }
  25251. //
  25252. Object.assign( Box2.prototype, {
  25253. center: function ( optionalTarget ) {
  25254. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  25255. return this.getCenter( optionalTarget );
  25256. },
  25257. empty: function () {
  25258. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  25259. return this.isEmpty();
  25260. },
  25261. isIntersectionBox: function ( box ) {
  25262. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  25263. return this.intersectsBox( box );
  25264. },
  25265. size: function ( optionalTarget ) {
  25266. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  25267. return this.getSize( optionalTarget );
  25268. }
  25269. } );
  25270. Object.assign( Box3.prototype, {
  25271. center: function ( optionalTarget ) {
  25272. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  25273. return this.getCenter( optionalTarget );
  25274. },
  25275. empty: function () {
  25276. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  25277. return this.isEmpty();
  25278. },
  25279. isIntersectionBox: function ( box ) {
  25280. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  25281. return this.intersectsBox( box );
  25282. },
  25283. isIntersectionSphere: function ( sphere ) {
  25284. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  25285. return this.intersectsSphere( sphere );
  25286. },
  25287. size: function ( optionalTarget ) {
  25288. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  25289. return this.getSize( optionalTarget );
  25290. }
  25291. } );
  25292. Line3.prototype.center = function ( optionalTarget ) {
  25293. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  25294. return this.getCenter( optionalTarget );
  25295. };
  25296. _Math.random16 = function () {
  25297. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  25298. return Math.random();
  25299. };
  25300. Object.assign( Matrix3.prototype, {
  25301. flattenToArrayOffset: function ( array, offset ) {
  25302. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  25303. return this.toArray( array, offset );
  25304. },
  25305. multiplyVector3: function ( vector ) {
  25306. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  25307. return vector.applyMatrix3( this );
  25308. },
  25309. multiplyVector3Array: function ( a ) {
  25310. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  25311. return this.applyToVector3Array( a );
  25312. },
  25313. applyToBuffer: function( buffer, offset, length ) {
  25314. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  25315. return this.applyToBufferAttribute( buffer );
  25316. },
  25317. applyToVector3Array: function( array, offset, length ) {
  25318. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  25319. }
  25320. } );
  25321. Object.assign( Matrix4.prototype, {
  25322. extractPosition: function ( m ) {
  25323. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  25324. return this.copyPosition( m );
  25325. },
  25326. flattenToArrayOffset: function ( array, offset ) {
  25327. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  25328. return this.toArray( array, offset );
  25329. },
  25330. getPosition: function () {
  25331. var v1;
  25332. return function getPosition() {
  25333. if ( v1 === undefined ) v1 = new Vector3();
  25334. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  25335. return v1.setFromMatrixColumn( this, 3 );
  25336. };
  25337. }(),
  25338. setRotationFromQuaternion: function ( q ) {
  25339. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  25340. return this.makeRotationFromQuaternion( q );
  25341. },
  25342. multiplyToArray: function () {
  25343. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  25344. },
  25345. multiplyVector3: function ( vector ) {
  25346. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  25347. return vector.applyMatrix4( this );
  25348. },
  25349. multiplyVector4: function ( vector ) {
  25350. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  25351. return vector.applyMatrix4( this );
  25352. },
  25353. multiplyVector3Array: function ( a ) {
  25354. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  25355. return this.applyToVector3Array( a );
  25356. },
  25357. rotateAxis: function ( v ) {
  25358. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  25359. v.transformDirection( this );
  25360. },
  25361. crossVector: function ( vector ) {
  25362. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  25363. return vector.applyMatrix4( this );
  25364. },
  25365. translate: function () {
  25366. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  25367. },
  25368. rotateX: function () {
  25369. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  25370. },
  25371. rotateY: function () {
  25372. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  25373. },
  25374. rotateZ: function () {
  25375. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  25376. },
  25377. rotateByAxis: function () {
  25378. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  25379. },
  25380. applyToBuffer: function( buffer, offset, length ) {
  25381. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  25382. return this.applyToBufferAttribute( buffer );
  25383. },
  25384. applyToVector3Array: function( array, offset, length ) {
  25385. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  25386. },
  25387. makeFrustum: function( left, right, bottom, top, near, far ) {
  25388. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  25389. return this.makePerspective( left, right, top, bottom, near, far );
  25390. }
  25391. } );
  25392. Plane.prototype.isIntersectionLine = function ( line ) {
  25393. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  25394. return this.intersectsLine( line );
  25395. };
  25396. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  25397. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  25398. return vector.applyQuaternion( this );
  25399. };
  25400. Object.assign( Ray.prototype, {
  25401. isIntersectionBox: function ( box ) {
  25402. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  25403. return this.intersectsBox( box );
  25404. },
  25405. isIntersectionPlane: function ( plane ) {
  25406. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  25407. return this.intersectsPlane( plane );
  25408. },
  25409. isIntersectionSphere: function ( sphere ) {
  25410. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  25411. return this.intersectsSphere( sphere );
  25412. }
  25413. } );
  25414. Object.assign( Shape.prototype, {
  25415. extrude: function ( options ) {
  25416. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  25417. return new ExtrudeGeometry( this, options );
  25418. },
  25419. makeGeometry: function ( options ) {
  25420. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  25421. return new ShapeGeometry( this, options );
  25422. }
  25423. } );
  25424. Object.assign( Vector2.prototype, {
  25425. fromAttribute: function ( attribute, index, offset ) {
  25426. console.error( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  25427. return this.fromBufferAttribute( attribute, index, offset );
  25428. }
  25429. } );
  25430. Object.assign( Vector3.prototype, {
  25431. setEulerFromRotationMatrix: function () {
  25432. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  25433. },
  25434. setEulerFromQuaternion: function () {
  25435. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  25436. },
  25437. getPositionFromMatrix: function ( m ) {
  25438. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  25439. return this.setFromMatrixPosition( m );
  25440. },
  25441. getScaleFromMatrix: function ( m ) {
  25442. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  25443. return this.setFromMatrixScale( m );
  25444. },
  25445. getColumnFromMatrix: function ( index, matrix ) {
  25446. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  25447. return this.setFromMatrixColumn( matrix, index );
  25448. },
  25449. applyProjection: function ( m ) {
  25450. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  25451. return this.applyMatrix4( m );
  25452. },
  25453. fromAttribute: function ( attribute, index, offset ) {
  25454. console.error( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  25455. return this.fromBufferAttribute( attribute, index, offset );
  25456. }
  25457. } );
  25458. Object.assign( Vector4.prototype, {
  25459. fromAttribute: function ( attribute, index, offset ) {
  25460. console.error( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  25461. return this.fromBufferAttribute( attribute, index, offset );
  25462. }
  25463. } );
  25464. //
  25465. Geometry.prototype.computeTangents = function () {
  25466. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  25467. };
  25468. Object.assign( Object3D.prototype, {
  25469. getChildByName: function ( name ) {
  25470. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  25471. return this.getObjectByName( name );
  25472. },
  25473. renderDepth: function () {
  25474. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  25475. },
  25476. translate: function ( distance, axis ) {
  25477. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  25478. return this.translateOnAxis( axis, distance );
  25479. }
  25480. } );
  25481. Object.defineProperties( Object3D.prototype, {
  25482. eulerOrder: {
  25483. get: function () {
  25484. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  25485. return this.rotation.order;
  25486. },
  25487. set: function ( value ) {
  25488. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  25489. this.rotation.order = value;
  25490. }
  25491. },
  25492. useQuaternion: {
  25493. get: function () {
  25494. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  25495. },
  25496. set: function () {
  25497. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  25498. }
  25499. }
  25500. } );
  25501. Object.defineProperties( LOD.prototype, {
  25502. objects: {
  25503. get: function () {
  25504. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  25505. return this.levels;
  25506. }
  25507. }
  25508. } );
  25509. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  25510. get: function () {
  25511. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  25512. },
  25513. set: function () {
  25514. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  25515. }
  25516. } );
  25517. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  25518. get: function () {
  25519. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  25520. return this.arcLengthDivisions;
  25521. },
  25522. set: function ( value ) {
  25523. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  25524. this.arcLengthDivisions = value;
  25525. }
  25526. } );
  25527. //
  25528. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  25529. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  25530. "Use .setFocalLength and .filmGauge for a photographic setup." );
  25531. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  25532. this.setFocalLength( focalLength );
  25533. };
  25534. //
  25535. Object.defineProperties( Light.prototype, {
  25536. onlyShadow: {
  25537. set: function () {
  25538. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  25539. }
  25540. },
  25541. shadowCameraFov: {
  25542. set: function ( value ) {
  25543. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  25544. this.shadow.camera.fov = value;
  25545. }
  25546. },
  25547. shadowCameraLeft: {
  25548. set: function ( value ) {
  25549. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  25550. this.shadow.camera.left = value;
  25551. }
  25552. },
  25553. shadowCameraRight: {
  25554. set: function ( value ) {
  25555. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  25556. this.shadow.camera.right = value;
  25557. }
  25558. },
  25559. shadowCameraTop: {
  25560. set: function ( value ) {
  25561. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  25562. this.shadow.camera.top = value;
  25563. }
  25564. },
  25565. shadowCameraBottom: {
  25566. set: function ( value ) {
  25567. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  25568. this.shadow.camera.bottom = value;
  25569. }
  25570. },
  25571. shadowCameraNear: {
  25572. set: function ( value ) {
  25573. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  25574. this.shadow.camera.near = value;
  25575. }
  25576. },
  25577. shadowCameraFar: {
  25578. set: function ( value ) {
  25579. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  25580. this.shadow.camera.far = value;
  25581. }
  25582. },
  25583. shadowCameraVisible: {
  25584. set: function () {
  25585. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  25586. }
  25587. },
  25588. shadowBias: {
  25589. set: function ( value ) {
  25590. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  25591. this.shadow.bias = value;
  25592. }
  25593. },
  25594. shadowDarkness: {
  25595. set: function () {
  25596. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  25597. }
  25598. },
  25599. shadowMapWidth: {
  25600. set: function ( value ) {
  25601. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  25602. this.shadow.mapSize.width = value;
  25603. }
  25604. },
  25605. shadowMapHeight: {
  25606. set: function ( value ) {
  25607. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  25608. this.shadow.mapSize.height = value;
  25609. }
  25610. }
  25611. } );
  25612. //
  25613. Object.defineProperties( BufferAttribute.prototype, {
  25614. length: {
  25615. get: function () {
  25616. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  25617. return this.array.length;
  25618. }
  25619. }
  25620. } );
  25621. Object.assign( BufferGeometry.prototype, {
  25622. addIndex: function ( index ) {
  25623. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  25624. this.setIndex( index );
  25625. },
  25626. addDrawCall: function ( start, count, indexOffset ) {
  25627. if ( indexOffset !== undefined ) {
  25628. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  25629. }
  25630. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  25631. this.addGroup( start, count );
  25632. },
  25633. clearDrawCalls: function () {
  25634. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  25635. this.clearGroups();
  25636. },
  25637. computeTangents: function () {
  25638. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  25639. },
  25640. computeOffsets: function () {
  25641. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  25642. }
  25643. } );
  25644. Object.defineProperties( BufferGeometry.prototype, {
  25645. drawcalls: {
  25646. get: function () {
  25647. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  25648. return this.groups;
  25649. }
  25650. },
  25651. offsets: {
  25652. get: function () {
  25653. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  25654. return this.groups;
  25655. }
  25656. }
  25657. } );
  25658. //
  25659. Object.defineProperties( Uniform.prototype, {
  25660. dynamic: {
  25661. set: function () {
  25662. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  25663. }
  25664. },
  25665. onUpdate: {
  25666. value: function () {
  25667. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  25668. return this;
  25669. }
  25670. }
  25671. } );
  25672. //
  25673. Object.defineProperties( Material.prototype, {
  25674. wrapAround: {
  25675. get: function () {
  25676. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  25677. },
  25678. set: function () {
  25679. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  25680. }
  25681. },
  25682. wrapRGB: {
  25683. get: function () {
  25684. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  25685. return new Color();
  25686. }
  25687. }
  25688. } );
  25689. Object.defineProperties( MeshPhongMaterial.prototype, {
  25690. metal: {
  25691. get: function () {
  25692. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  25693. return false;
  25694. },
  25695. set: function () {
  25696. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  25697. }
  25698. }
  25699. } );
  25700. Object.defineProperties( ShaderMaterial.prototype, {
  25701. derivatives: {
  25702. get: function () {
  25703. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  25704. return this.extensions.derivatives;
  25705. },
  25706. set: function ( value ) {
  25707. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  25708. this.extensions.derivatives = value;
  25709. }
  25710. }
  25711. } );
  25712. //
  25713. Object.assign( WebGLRenderer.prototype, {
  25714. getCurrentRenderTarget: function () {
  25715. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  25716. return this.getRenderTarget();
  25717. },
  25718. supportsFloatTextures: function () {
  25719. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  25720. return this.extensions.get( 'OES_texture_float' );
  25721. },
  25722. supportsHalfFloatTextures: function () {
  25723. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  25724. return this.extensions.get( 'OES_texture_half_float' );
  25725. },
  25726. supportsStandardDerivatives: function () {
  25727. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  25728. return this.extensions.get( 'OES_standard_derivatives' );
  25729. },
  25730. supportsCompressedTextureS3TC: function () {
  25731. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  25732. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  25733. },
  25734. supportsCompressedTexturePVRTC: function () {
  25735. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  25736. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  25737. },
  25738. supportsBlendMinMax: function () {
  25739. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  25740. return this.extensions.get( 'EXT_blend_minmax' );
  25741. },
  25742. supportsVertexTextures: function () {
  25743. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  25744. return this.capabilities.vertexTextures;
  25745. },
  25746. supportsInstancedArrays: function () {
  25747. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  25748. return this.extensions.get( 'ANGLE_instanced_arrays' );
  25749. },
  25750. enableScissorTest: function ( boolean ) {
  25751. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  25752. this.setScissorTest( boolean );
  25753. },
  25754. initMaterial: function () {
  25755. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  25756. },
  25757. addPrePlugin: function () {
  25758. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  25759. },
  25760. addPostPlugin: function () {
  25761. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  25762. },
  25763. updateShadowMap: function () {
  25764. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  25765. }
  25766. } );
  25767. Object.defineProperties( WebGLRenderer.prototype, {
  25768. shadowMapEnabled: {
  25769. get: function () {
  25770. return this.shadowMap.enabled;
  25771. },
  25772. set: function ( value ) {
  25773. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  25774. this.shadowMap.enabled = value;
  25775. }
  25776. },
  25777. shadowMapType: {
  25778. get: function () {
  25779. return this.shadowMap.type;
  25780. },
  25781. set: function ( value ) {
  25782. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  25783. this.shadowMap.type = value;
  25784. }
  25785. },
  25786. shadowMapCullFace: {
  25787. get: function () {
  25788. return this.shadowMap.cullFace;
  25789. },
  25790. set: function ( value ) {
  25791. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  25792. this.shadowMap.cullFace = value;
  25793. }
  25794. }
  25795. } );
  25796. Object.defineProperties( WebGLShadowMap.prototype, {
  25797. cullFace: {
  25798. get: function () {
  25799. return this.renderReverseSided ? CullFaceFront : CullFaceBack;
  25800. },
  25801. set: function ( cullFace ) {
  25802. var value = ( cullFace !== CullFaceBack );
  25803. console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. Set .shadowMap.renderReverseSided to " + value + "." );
  25804. this.renderReverseSided = value;
  25805. }
  25806. }
  25807. } );
  25808. //
  25809. Object.defineProperties( WebGLRenderTarget.prototype, {
  25810. wrapS: {
  25811. get: function () {
  25812. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  25813. return this.texture.wrapS;
  25814. },
  25815. set: function ( value ) {
  25816. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  25817. this.texture.wrapS = value;
  25818. }
  25819. },
  25820. wrapT: {
  25821. get: function () {
  25822. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  25823. return this.texture.wrapT;
  25824. },
  25825. set: function ( value ) {
  25826. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  25827. this.texture.wrapT = value;
  25828. }
  25829. },
  25830. magFilter: {
  25831. get: function () {
  25832. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  25833. return this.texture.magFilter;
  25834. },
  25835. set: function ( value ) {
  25836. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  25837. this.texture.magFilter = value;
  25838. }
  25839. },
  25840. minFilter: {
  25841. get: function () {
  25842. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  25843. return this.texture.minFilter;
  25844. },
  25845. set: function ( value ) {
  25846. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  25847. this.texture.minFilter = value;
  25848. }
  25849. },
  25850. anisotropy: {
  25851. get: function () {
  25852. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  25853. return this.texture.anisotropy;
  25854. },
  25855. set: function ( value ) {
  25856. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  25857. this.texture.anisotropy = value;
  25858. }
  25859. },
  25860. offset: {
  25861. get: function () {
  25862. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  25863. return this.texture.offset;
  25864. },
  25865. set: function ( value ) {
  25866. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  25867. this.texture.offset = value;
  25868. }
  25869. },
  25870. repeat: {
  25871. get: function () {
  25872. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  25873. return this.texture.repeat;
  25874. },
  25875. set: function ( value ) {
  25876. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  25877. this.texture.repeat = value;
  25878. }
  25879. },
  25880. format: {
  25881. get: function () {
  25882. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  25883. return this.texture.format;
  25884. },
  25885. set: function ( value ) {
  25886. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  25887. this.texture.format = value;
  25888. }
  25889. },
  25890. type: {
  25891. get: function () {
  25892. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  25893. return this.texture.type;
  25894. },
  25895. set: function ( value ) {
  25896. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  25897. this.texture.type = value;
  25898. }
  25899. },
  25900. generateMipmaps: {
  25901. get: function () {
  25902. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  25903. return this.texture.generateMipmaps;
  25904. },
  25905. set: function ( value ) {
  25906. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  25907. this.texture.generateMipmaps = value;
  25908. }
  25909. }
  25910. } );
  25911. //
  25912. Audio.prototype.load = function ( file ) {
  25913. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  25914. var scope = this;
  25915. var audioLoader = new AudioLoader();
  25916. audioLoader.load( file, function ( buffer ) {
  25917. scope.setBuffer( buffer );
  25918. } );
  25919. return this;
  25920. };
  25921. AudioAnalyser.prototype.getData = function () {
  25922. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  25923. return this.getFrequencyData();
  25924. };
  25925. //
  25926. var GeometryUtils = {
  25927. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  25928. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  25929. var matrix;
  25930. if ( geometry2.isMesh ) {
  25931. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  25932. matrix = geometry2.matrix;
  25933. geometry2 = geometry2.geometry;
  25934. }
  25935. geometry1.merge( geometry2, matrix, materialIndexOffset );
  25936. },
  25937. center: function ( geometry ) {
  25938. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  25939. return geometry.center();
  25940. }
  25941. };
  25942. var ImageUtils = {
  25943. crossOrigin: undefined,
  25944. loadTexture: function ( url, mapping, onLoad, onError ) {
  25945. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  25946. var loader = new TextureLoader();
  25947. loader.setCrossOrigin( this.crossOrigin );
  25948. var texture = loader.load( url, onLoad, undefined, onError );
  25949. if ( mapping ) texture.mapping = mapping;
  25950. return texture;
  25951. },
  25952. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  25953. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  25954. var loader = new CubeTextureLoader();
  25955. loader.setCrossOrigin( this.crossOrigin );
  25956. var texture = loader.load( urls, onLoad, undefined, onError );
  25957. if ( mapping ) texture.mapping = mapping;
  25958. return texture;
  25959. },
  25960. loadCompressedTexture: function () {
  25961. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  25962. },
  25963. loadCompressedTextureCube: function () {
  25964. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  25965. }
  25966. };
  25967. //
  25968. function Projector() {
  25969. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  25970. this.projectVector = function ( vector, camera ) {
  25971. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  25972. vector.project( camera );
  25973. };
  25974. this.unprojectVector = function ( vector, camera ) {
  25975. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  25976. vector.unproject( camera );
  25977. };
  25978. this.pickingRay = function () {
  25979. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  25980. };
  25981. }
  25982. //
  25983. function CanvasRenderer() {
  25984. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  25985. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  25986. this.clear = function () {};
  25987. this.render = function () {};
  25988. this.setClearColor = function () {};
  25989. this.setSize = function () {};
  25990. }
  25991. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  25992. exports.WebGLRenderTarget = WebGLRenderTarget;
  25993. exports.WebGLRenderer = WebGLRenderer;
  25994. exports.ShaderLib = ShaderLib;
  25995. exports.UniformsLib = UniformsLib;
  25996. exports.UniformsUtils = UniformsUtils;
  25997. exports.ShaderChunk = ShaderChunk;
  25998. exports.FogExp2 = FogExp2;
  25999. exports.Fog = Fog;
  26000. exports.Scene = Scene;
  26001. exports.LensFlare = LensFlare;
  26002. exports.Sprite = Sprite;
  26003. exports.LOD = LOD;
  26004. exports.SkinnedMesh = SkinnedMesh;
  26005. exports.Skeleton = Skeleton;
  26006. exports.Bone = Bone;
  26007. exports.Mesh = Mesh;
  26008. exports.LineSegments = LineSegments;
  26009. exports.LineLoop = LineLoop;
  26010. exports.Line = Line;
  26011. exports.Points = Points;
  26012. exports.Group = Group;
  26013. exports.VideoTexture = VideoTexture;
  26014. exports.DataTexture = DataTexture;
  26015. exports.CompressedTexture = CompressedTexture;
  26016. exports.CubeTexture = CubeTexture;
  26017. exports.CanvasTexture = CanvasTexture;
  26018. exports.DepthTexture = DepthTexture;
  26019. exports.Texture = Texture;
  26020. exports.CompressedTextureLoader = CompressedTextureLoader;
  26021. exports.DataTextureLoader = DataTextureLoader;
  26022. exports.CubeTextureLoader = CubeTextureLoader;
  26023. exports.TextureLoader = TextureLoader;
  26024. exports.ObjectLoader = ObjectLoader;
  26025. exports.MaterialLoader = MaterialLoader;
  26026. exports.BufferGeometryLoader = BufferGeometryLoader;
  26027. exports.DefaultLoadingManager = DefaultLoadingManager;
  26028. exports.LoadingManager = LoadingManager;
  26029. exports.JSONLoader = JSONLoader;
  26030. exports.ImageLoader = ImageLoader;
  26031. exports.FontLoader = FontLoader;
  26032. exports.FileLoader = FileLoader;
  26033. exports.Loader = Loader;
  26034. exports.Cache = Cache;
  26035. exports.AudioLoader = AudioLoader;
  26036. exports.SpotLightShadow = SpotLightShadow;
  26037. exports.SpotLight = SpotLight;
  26038. exports.PointLight = PointLight;
  26039. exports.RectAreaLight = RectAreaLight;
  26040. exports.HemisphereLight = HemisphereLight;
  26041. exports.DirectionalLightShadow = DirectionalLightShadow;
  26042. exports.DirectionalLight = DirectionalLight;
  26043. exports.AmbientLight = AmbientLight;
  26044. exports.LightShadow = LightShadow;
  26045. exports.Light = Light;
  26046. exports.StereoCamera = StereoCamera;
  26047. exports.PerspectiveCamera = PerspectiveCamera;
  26048. exports.OrthographicCamera = OrthographicCamera;
  26049. exports.CubeCamera = CubeCamera;
  26050. exports.ArrayCamera = ArrayCamera;
  26051. exports.Camera = Camera;
  26052. exports.AudioListener = AudioListener;
  26053. exports.PositionalAudio = PositionalAudio;
  26054. exports.AudioContext = AudioContext;
  26055. exports.AudioAnalyser = AudioAnalyser;
  26056. exports.Audio = Audio;
  26057. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  26058. exports.StringKeyframeTrack = StringKeyframeTrack;
  26059. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  26060. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  26061. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  26062. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  26063. exports.PropertyMixer = PropertyMixer;
  26064. exports.PropertyBinding = PropertyBinding;
  26065. exports.KeyframeTrack = KeyframeTrack;
  26066. exports.AnimationUtils = AnimationUtils;
  26067. exports.AnimationObjectGroup = AnimationObjectGroup;
  26068. exports.AnimationMixer = AnimationMixer;
  26069. exports.AnimationClip = AnimationClip;
  26070. exports.Uniform = Uniform;
  26071. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  26072. exports.BufferGeometry = BufferGeometry;
  26073. exports.GeometryIdCount = GeometryIdCount;
  26074. exports.Geometry = Geometry;
  26075. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  26076. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  26077. exports.InterleavedBuffer = InterleavedBuffer;
  26078. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  26079. exports.Face3 = Face3;
  26080. exports.Object3D = Object3D;
  26081. exports.Raycaster = Raycaster;
  26082. exports.Layers = Layers;
  26083. exports.EventDispatcher = EventDispatcher;
  26084. exports.Clock = Clock;
  26085. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  26086. exports.LinearInterpolant = LinearInterpolant;
  26087. exports.DiscreteInterpolant = DiscreteInterpolant;
  26088. exports.CubicInterpolant = CubicInterpolant;
  26089. exports.Interpolant = Interpolant;
  26090. exports.Triangle = Triangle;
  26091. exports.Math = _Math;
  26092. exports.Spherical = Spherical;
  26093. exports.Cylindrical = Cylindrical;
  26094. exports.Plane = Plane;
  26095. exports.Frustum = Frustum;
  26096. exports.Sphere = Sphere;
  26097. exports.Ray = Ray;
  26098. exports.Matrix4 = Matrix4;
  26099. exports.Matrix3 = Matrix3;
  26100. exports.Box3 = Box3;
  26101. exports.Box2 = Box2;
  26102. exports.Line3 = Line3;
  26103. exports.Euler = Euler;
  26104. exports.Vector4 = Vector4;
  26105. exports.Vector3 = Vector3;
  26106. exports.Vector2 = Vector2;
  26107. exports.Quaternion = Quaternion;
  26108. exports.Color = Color;
  26109. exports.MorphBlendMesh = MorphBlendMesh;
  26110. exports.ImmediateRenderObject = ImmediateRenderObject;
  26111. exports.VertexNormalsHelper = VertexNormalsHelper;
  26112. exports.SpotLightHelper = SpotLightHelper;
  26113. exports.SkeletonHelper = SkeletonHelper;
  26114. exports.PointLightHelper = PointLightHelper;
  26115. exports.RectAreaLightHelper = RectAreaLightHelper;
  26116. exports.HemisphereLightHelper = HemisphereLightHelper;
  26117. exports.GridHelper = GridHelper;
  26118. exports.PolarGridHelper = PolarGridHelper;
  26119. exports.FaceNormalsHelper = FaceNormalsHelper;
  26120. exports.DirectionalLightHelper = DirectionalLightHelper;
  26121. exports.CameraHelper = CameraHelper;
  26122. exports.BoxHelper = BoxHelper;
  26123. exports.ArrowHelper = ArrowHelper;
  26124. exports.AxisHelper = AxisHelper;
  26125. exports.CatmullRomCurve3 = CatmullRomCurve3;
  26126. exports.CubicBezierCurve3 = CubicBezierCurve3;
  26127. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  26128. exports.LineCurve3 = LineCurve3;
  26129. exports.ArcCurve = ArcCurve;
  26130. exports.EllipseCurve = EllipseCurve;
  26131. exports.SplineCurve = SplineCurve;
  26132. exports.CubicBezierCurve = CubicBezierCurve;
  26133. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  26134. exports.LineCurve = LineCurve;
  26135. exports.Shape = Shape;
  26136. exports.Path = Path;
  26137. exports.ShapePath = ShapePath;
  26138. exports.Font = Font;
  26139. exports.CurvePath = CurvePath;
  26140. exports.Curve = Curve;
  26141. exports.ShapeUtils = ShapeUtils;
  26142. exports.SceneUtils = SceneUtils;
  26143. exports.WireframeGeometry = WireframeGeometry;
  26144. exports.ParametricGeometry = ParametricGeometry;
  26145. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  26146. exports.TetrahedronGeometry = TetrahedronGeometry;
  26147. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  26148. exports.OctahedronGeometry = OctahedronGeometry;
  26149. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  26150. exports.IcosahedronGeometry = IcosahedronGeometry;
  26151. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  26152. exports.DodecahedronGeometry = DodecahedronGeometry;
  26153. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  26154. exports.PolyhedronGeometry = PolyhedronGeometry;
  26155. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  26156. exports.TubeGeometry = TubeGeometry;
  26157. exports.TubeBufferGeometry = TubeBufferGeometry;
  26158. exports.TorusKnotGeometry = TorusKnotGeometry;
  26159. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  26160. exports.TorusGeometry = TorusGeometry;
  26161. exports.TorusBufferGeometry = TorusBufferGeometry;
  26162. exports.TextGeometry = TextGeometry;
  26163. exports.TextBufferGeometry = TextBufferGeometry;
  26164. exports.SphereGeometry = SphereGeometry;
  26165. exports.SphereBufferGeometry = SphereBufferGeometry;
  26166. exports.RingGeometry = RingGeometry;
  26167. exports.RingBufferGeometry = RingBufferGeometry;
  26168. exports.PlaneGeometry = PlaneGeometry;
  26169. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  26170. exports.LatheGeometry = LatheGeometry;
  26171. exports.LatheBufferGeometry = LatheBufferGeometry;
  26172. exports.ShapeGeometry = ShapeGeometry;
  26173. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  26174. exports.ExtrudeGeometry = ExtrudeGeometry;
  26175. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  26176. exports.EdgesGeometry = EdgesGeometry;
  26177. exports.ConeGeometry = ConeGeometry;
  26178. exports.ConeBufferGeometry = ConeBufferGeometry;
  26179. exports.CylinderGeometry = CylinderGeometry;
  26180. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  26181. exports.CircleGeometry = CircleGeometry;
  26182. exports.CircleBufferGeometry = CircleBufferGeometry;
  26183. exports.BoxGeometry = BoxGeometry;
  26184. exports.BoxBufferGeometry = BoxBufferGeometry;
  26185. exports.ShadowMaterial = ShadowMaterial;
  26186. exports.SpriteMaterial = SpriteMaterial;
  26187. exports.RawShaderMaterial = RawShaderMaterial;
  26188. exports.ShaderMaterial = ShaderMaterial;
  26189. exports.PointsMaterial = PointsMaterial;
  26190. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  26191. exports.MeshStandardMaterial = MeshStandardMaterial;
  26192. exports.MeshPhongMaterial = MeshPhongMaterial;
  26193. exports.MeshToonMaterial = MeshToonMaterial;
  26194. exports.MeshNormalMaterial = MeshNormalMaterial;
  26195. exports.MeshLambertMaterial = MeshLambertMaterial;
  26196. exports.MeshDepthMaterial = MeshDepthMaterial;
  26197. exports.MeshBasicMaterial = MeshBasicMaterial;
  26198. exports.LineDashedMaterial = LineDashedMaterial;
  26199. exports.LineBasicMaterial = LineBasicMaterial;
  26200. exports.Material = Material;
  26201. exports.Float64BufferAttribute = Float64BufferAttribute;
  26202. exports.Float32BufferAttribute = Float32BufferAttribute;
  26203. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  26204. exports.Int32BufferAttribute = Int32BufferAttribute;
  26205. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  26206. exports.Int16BufferAttribute = Int16BufferAttribute;
  26207. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  26208. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  26209. exports.Int8BufferAttribute = Int8BufferAttribute;
  26210. exports.BufferAttribute = BufferAttribute;
  26211. exports.REVISION = REVISION;
  26212. exports.MOUSE = MOUSE;
  26213. exports.CullFaceNone = CullFaceNone;
  26214. exports.CullFaceBack = CullFaceBack;
  26215. exports.CullFaceFront = CullFaceFront;
  26216. exports.CullFaceFrontBack = CullFaceFrontBack;
  26217. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  26218. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  26219. exports.BasicShadowMap = BasicShadowMap;
  26220. exports.PCFShadowMap = PCFShadowMap;
  26221. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  26222. exports.FrontSide = FrontSide;
  26223. exports.BackSide = BackSide;
  26224. exports.DoubleSide = DoubleSide;
  26225. exports.FlatShading = FlatShading;
  26226. exports.SmoothShading = SmoothShading;
  26227. exports.NoColors = NoColors;
  26228. exports.FaceColors = FaceColors;
  26229. exports.VertexColors = VertexColors;
  26230. exports.NoBlending = NoBlending;
  26231. exports.NormalBlending = NormalBlending;
  26232. exports.AdditiveBlending = AdditiveBlending;
  26233. exports.SubtractiveBlending = SubtractiveBlending;
  26234. exports.MultiplyBlending = MultiplyBlending;
  26235. exports.CustomBlending = CustomBlending;
  26236. exports.AddEquation = AddEquation;
  26237. exports.SubtractEquation = SubtractEquation;
  26238. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  26239. exports.MinEquation = MinEquation;
  26240. exports.MaxEquation = MaxEquation;
  26241. exports.ZeroFactor = ZeroFactor;
  26242. exports.OneFactor = OneFactor;
  26243. exports.SrcColorFactor = SrcColorFactor;
  26244. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  26245. exports.SrcAlphaFactor = SrcAlphaFactor;
  26246. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  26247. exports.DstAlphaFactor = DstAlphaFactor;
  26248. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  26249. exports.DstColorFactor = DstColorFactor;
  26250. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  26251. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  26252. exports.NeverDepth = NeverDepth;
  26253. exports.AlwaysDepth = AlwaysDepth;
  26254. exports.LessDepth = LessDepth;
  26255. exports.LessEqualDepth = LessEqualDepth;
  26256. exports.EqualDepth = EqualDepth;
  26257. exports.GreaterEqualDepth = GreaterEqualDepth;
  26258. exports.GreaterDepth = GreaterDepth;
  26259. exports.NotEqualDepth = NotEqualDepth;
  26260. exports.MultiplyOperation = MultiplyOperation;
  26261. exports.MixOperation = MixOperation;
  26262. exports.AddOperation = AddOperation;
  26263. exports.NoToneMapping = NoToneMapping;
  26264. exports.LinearToneMapping = LinearToneMapping;
  26265. exports.ReinhardToneMapping = ReinhardToneMapping;
  26266. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  26267. exports.CineonToneMapping = CineonToneMapping;
  26268. exports.UVMapping = UVMapping;
  26269. exports.CubeReflectionMapping = CubeReflectionMapping;
  26270. exports.CubeRefractionMapping = CubeRefractionMapping;
  26271. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  26272. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  26273. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  26274. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  26275. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  26276. exports.RepeatWrapping = RepeatWrapping;
  26277. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  26278. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  26279. exports.NearestFilter = NearestFilter;
  26280. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  26281. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  26282. exports.LinearFilter = LinearFilter;
  26283. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  26284. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  26285. exports.UnsignedByteType = UnsignedByteType;
  26286. exports.ByteType = ByteType;
  26287. exports.ShortType = ShortType;
  26288. exports.UnsignedShortType = UnsignedShortType;
  26289. exports.IntType = IntType;
  26290. exports.UnsignedIntType = UnsignedIntType;
  26291. exports.FloatType = FloatType;
  26292. exports.HalfFloatType = HalfFloatType;
  26293. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  26294. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  26295. exports.UnsignedShort565Type = UnsignedShort565Type;
  26296. exports.UnsignedInt248Type = UnsignedInt248Type;
  26297. exports.AlphaFormat = AlphaFormat;
  26298. exports.RGBFormat = RGBFormat;
  26299. exports.RGBAFormat = RGBAFormat;
  26300. exports.LuminanceFormat = LuminanceFormat;
  26301. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  26302. exports.RGBEFormat = RGBEFormat;
  26303. exports.DepthFormat = DepthFormat;
  26304. exports.DepthStencilFormat = DepthStencilFormat;
  26305. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  26306. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  26307. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  26308. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  26309. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  26310. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  26311. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  26312. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  26313. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  26314. exports.LoopOnce = LoopOnce;
  26315. exports.LoopRepeat = LoopRepeat;
  26316. exports.LoopPingPong = LoopPingPong;
  26317. exports.InterpolateDiscrete = InterpolateDiscrete;
  26318. exports.InterpolateLinear = InterpolateLinear;
  26319. exports.InterpolateSmooth = InterpolateSmooth;
  26320. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  26321. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  26322. exports.WrapAroundEnding = WrapAroundEnding;
  26323. exports.TrianglesDrawMode = TrianglesDrawMode;
  26324. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  26325. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  26326. exports.LinearEncoding = LinearEncoding;
  26327. exports.sRGBEncoding = sRGBEncoding;
  26328. exports.GammaEncoding = GammaEncoding;
  26329. exports.RGBEEncoding = RGBEEncoding;
  26330. exports.LogLuvEncoding = LogLuvEncoding;
  26331. exports.RGBM7Encoding = RGBM7Encoding;
  26332. exports.RGBM16Encoding = RGBM16Encoding;
  26333. exports.RGBDEncoding = RGBDEncoding;
  26334. exports.BasicDepthPacking = BasicDepthPacking;
  26335. exports.RGBADepthPacking = RGBADepthPacking;
  26336. exports.CubeGeometry = BoxGeometry;
  26337. exports.Face4 = Face4;
  26338. exports.LineStrip = LineStrip;
  26339. exports.LinePieces = LinePieces;
  26340. exports.MeshFaceMaterial = MeshFaceMaterial;
  26341. exports.MultiMaterial = MultiMaterial;
  26342. exports.PointCloud = PointCloud;
  26343. exports.Particle = Particle;
  26344. exports.ParticleSystem = ParticleSystem;
  26345. exports.PointCloudMaterial = PointCloudMaterial;
  26346. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  26347. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  26348. exports.Vertex = Vertex;
  26349. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  26350. exports.Int8Attribute = Int8Attribute;
  26351. exports.Uint8Attribute = Uint8Attribute;
  26352. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  26353. exports.Int16Attribute = Int16Attribute;
  26354. exports.Uint16Attribute = Uint16Attribute;
  26355. exports.Int32Attribute = Int32Attribute;
  26356. exports.Uint32Attribute = Uint32Attribute;
  26357. exports.Float32Attribute = Float32Attribute;
  26358. exports.Float64Attribute = Float64Attribute;
  26359. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  26360. exports.SplineCurve3 = SplineCurve3;
  26361. exports.Spline = Spline;
  26362. exports.BoundingBoxHelper = BoundingBoxHelper;
  26363. exports.EdgesHelper = EdgesHelper;
  26364. exports.WireframeHelper = WireframeHelper;
  26365. exports.XHRLoader = XHRLoader;
  26366. exports.BinaryTextureLoader = BinaryTextureLoader;
  26367. exports.GeometryUtils = GeometryUtils;
  26368. exports.ImageUtils = ImageUtils;
  26369. exports.Projector = Projector;
  26370. exports.CanvasRenderer = CanvasRenderer;
  26371. Object.defineProperty(exports, '__esModule', { value: true });
  26372. })));