three.module.js 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406
  1. // Polyfills
  2. if ( Number.EPSILON === undefined ) {
  3. Number.EPSILON = Math.pow( 2, - 52 );
  4. }
  5. if ( Number.isInteger === undefined ) {
  6. // Missing in IE
  7. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  8. Number.isInteger = function ( value ) {
  9. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  10. };
  11. }
  12. //
  13. if ( Math.sign === undefined ) {
  14. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  15. Math.sign = function ( x ) {
  16. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  17. };
  18. }
  19. if ( 'name' in Function.prototype === false ) {
  20. // Missing in IE
  21. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  22. Object.defineProperty( Function.prototype, 'name', {
  23. get: function () {
  24. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  25. }
  26. } );
  27. }
  28. if ( Object.assign === undefined ) {
  29. // Missing in IE
  30. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  31. ( function () {
  32. Object.assign = function ( target ) {
  33. if ( target === undefined || target === null ) {
  34. throw new TypeError( 'Cannot convert undefined or null to object' );
  35. }
  36. var output = Object( target );
  37. for ( var index = 1; index < arguments.length; index ++ ) {
  38. var source = arguments[ index ];
  39. if ( source !== undefined && source !== null ) {
  40. for ( var nextKey in source ) {
  41. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  42. output[ nextKey ] = source[ nextKey ];
  43. }
  44. }
  45. }
  46. }
  47. return output;
  48. };
  49. } )();
  50. }
  51. /**
  52. * https://github.com/mrdoob/eventdispatcher.js/
  53. */
  54. function EventDispatcher() {}
  55. Object.assign( EventDispatcher.prototype, {
  56. addEventListener: function ( type, listener ) {
  57. if ( this._listeners === undefined ) this._listeners = {};
  58. var listeners = this._listeners;
  59. if ( listeners[ type ] === undefined ) {
  60. listeners[ type ] = [];
  61. }
  62. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  63. listeners[ type ].push( listener );
  64. }
  65. },
  66. hasEventListener: function ( type, listener ) {
  67. if ( this._listeners === undefined ) return false;
  68. var listeners = this._listeners;
  69. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  70. },
  71. removeEventListener: function ( type, listener ) {
  72. if ( this._listeners === undefined ) return;
  73. var listeners = this._listeners;
  74. var listenerArray = listeners[ type ];
  75. if ( listenerArray !== undefined ) {
  76. var index = listenerArray.indexOf( listener );
  77. if ( index !== - 1 ) {
  78. listenerArray.splice( index, 1 );
  79. }
  80. }
  81. },
  82. dispatchEvent: function ( event ) {
  83. if ( this._listeners === undefined ) return;
  84. var listeners = this._listeners;
  85. var listenerArray = listeners[ event.type ];
  86. if ( listenerArray !== undefined ) {
  87. event.target = this;
  88. var array = listenerArray.slice( 0 );
  89. for ( var i = 0, l = array.length; i < l; i ++ ) {
  90. array[ i ].call( this, event );
  91. }
  92. }
  93. }
  94. } );
  95. var REVISION = '93dev';
  96. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  97. var CullFaceNone = 0;
  98. var CullFaceBack = 1;
  99. var CullFaceFront = 2;
  100. var CullFaceFrontBack = 3;
  101. var FrontFaceDirectionCW = 0;
  102. var FrontFaceDirectionCCW = 1;
  103. var BasicShadowMap = 0;
  104. var PCFShadowMap = 1;
  105. var PCFSoftShadowMap = 2;
  106. var FrontSide = 0;
  107. var BackSide = 1;
  108. var DoubleSide = 2;
  109. var FlatShading = 1;
  110. var SmoothShading = 2;
  111. var NoColors = 0;
  112. var FaceColors = 1;
  113. var VertexColors = 2;
  114. var NoBlending = 0;
  115. var NormalBlending = 1;
  116. var AdditiveBlending = 2;
  117. var SubtractiveBlending = 3;
  118. var MultiplyBlending = 4;
  119. var CustomBlending = 5;
  120. var AddEquation = 100;
  121. var SubtractEquation = 101;
  122. var ReverseSubtractEquation = 102;
  123. var MinEquation = 103;
  124. var MaxEquation = 104;
  125. var ZeroFactor = 200;
  126. var OneFactor = 201;
  127. var SrcColorFactor = 202;
  128. var OneMinusSrcColorFactor = 203;
  129. var SrcAlphaFactor = 204;
  130. var OneMinusSrcAlphaFactor = 205;
  131. var DstAlphaFactor = 206;
  132. var OneMinusDstAlphaFactor = 207;
  133. var DstColorFactor = 208;
  134. var OneMinusDstColorFactor = 209;
  135. var SrcAlphaSaturateFactor = 210;
  136. var NeverDepth = 0;
  137. var AlwaysDepth = 1;
  138. var LessDepth = 2;
  139. var LessEqualDepth = 3;
  140. var EqualDepth = 4;
  141. var GreaterEqualDepth = 5;
  142. var GreaterDepth = 6;
  143. var NotEqualDepth = 7;
  144. var MultiplyOperation = 0;
  145. var MixOperation = 1;
  146. var AddOperation = 2;
  147. var NoToneMapping = 0;
  148. var LinearToneMapping = 1;
  149. var ReinhardToneMapping = 2;
  150. var Uncharted2ToneMapping = 3;
  151. var CineonToneMapping = 4;
  152. var UVMapping = 300;
  153. var CubeReflectionMapping = 301;
  154. var CubeRefractionMapping = 302;
  155. var EquirectangularReflectionMapping = 303;
  156. var EquirectangularRefractionMapping = 304;
  157. var SphericalReflectionMapping = 305;
  158. var CubeUVReflectionMapping = 306;
  159. var CubeUVRefractionMapping = 307;
  160. var RepeatWrapping = 1000;
  161. var ClampToEdgeWrapping = 1001;
  162. var MirroredRepeatWrapping = 1002;
  163. var NearestFilter = 1003;
  164. var NearestMipMapNearestFilter = 1004;
  165. var NearestMipMapLinearFilter = 1005;
  166. var LinearFilter = 1006;
  167. var LinearMipMapNearestFilter = 1007;
  168. var LinearMipMapLinearFilter = 1008;
  169. var UnsignedByteType = 1009;
  170. var ByteType = 1010;
  171. var ShortType = 1011;
  172. var UnsignedShortType = 1012;
  173. var IntType = 1013;
  174. var UnsignedIntType = 1014;
  175. var FloatType = 1015;
  176. var HalfFloatType = 1016;
  177. var UnsignedShort4444Type = 1017;
  178. var UnsignedShort5551Type = 1018;
  179. var UnsignedShort565Type = 1019;
  180. var UnsignedInt248Type = 1020;
  181. var AlphaFormat = 1021;
  182. var RGBFormat = 1022;
  183. var RGBAFormat = 1023;
  184. var LuminanceFormat = 1024;
  185. var LuminanceAlphaFormat = 1025;
  186. var RGBEFormat = RGBAFormat;
  187. var DepthFormat = 1026;
  188. var DepthStencilFormat = 1027;
  189. var RGB_S3TC_DXT1_Format = 33776;
  190. var RGBA_S3TC_DXT1_Format = 33777;
  191. var RGBA_S3TC_DXT3_Format = 33778;
  192. var RGBA_S3TC_DXT5_Format = 33779;
  193. var RGB_PVRTC_4BPPV1_Format = 35840;
  194. var RGB_PVRTC_2BPPV1_Format = 35841;
  195. var RGBA_PVRTC_4BPPV1_Format = 35842;
  196. var RGBA_PVRTC_2BPPV1_Format = 35843;
  197. var RGB_ETC1_Format = 36196;
  198. var RGBA_ASTC_4x4_Format = 37808;
  199. var RGBA_ASTC_5x4_Format = 37809;
  200. var RGBA_ASTC_5x5_Format = 37810;
  201. var RGBA_ASTC_6x5_Format = 37811;
  202. var RGBA_ASTC_6x6_Format = 37812;
  203. var RGBA_ASTC_8x5_Format = 37813;
  204. var RGBA_ASTC_8x6_Format = 37814;
  205. var RGBA_ASTC_8x8_Format = 37815;
  206. var RGBA_ASTC_10x5_Format = 37816;
  207. var RGBA_ASTC_10x6_Format = 37817;
  208. var RGBA_ASTC_10x8_Format = 37818;
  209. var RGBA_ASTC_10x10_Format = 37819;
  210. var RGBA_ASTC_12x10_Format = 37820;
  211. var RGBA_ASTC_12x12_Format = 37821;
  212. var LoopOnce = 2200;
  213. var LoopRepeat = 2201;
  214. var LoopPingPong = 2202;
  215. var InterpolateDiscrete = 2300;
  216. var InterpolateLinear = 2301;
  217. var InterpolateSmooth = 2302;
  218. var ZeroCurvatureEnding = 2400;
  219. var ZeroSlopeEnding = 2401;
  220. var WrapAroundEnding = 2402;
  221. var TrianglesDrawMode = 0;
  222. var TriangleStripDrawMode = 1;
  223. var TriangleFanDrawMode = 2;
  224. var LinearEncoding = 3000;
  225. var sRGBEncoding = 3001;
  226. var GammaEncoding = 3007;
  227. var RGBEEncoding = 3002;
  228. var LogLuvEncoding = 3003;
  229. var RGBM7Encoding = 3004;
  230. var RGBM16Encoding = 3005;
  231. var RGBDEncoding = 3006;
  232. var BasicDepthPacking = 3200;
  233. var RGBADepthPacking = 3201;
  234. /**
  235. * @author alteredq / http://alteredqualia.com/
  236. * @author mrdoob / http://mrdoob.com/
  237. */
  238. var _Math = {
  239. DEG2RAD: Math.PI / 180,
  240. RAD2DEG: 180 / Math.PI,
  241. generateUUID: ( function () {
  242. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  243. var lut = [];
  244. for ( var i = 0; i < 256; i ++ ) {
  245. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  246. }
  247. return function generateUUID() {
  248. var d0 = Math.random() * 0xffffffff | 0;
  249. var d1 = Math.random() * 0xffffffff | 0;
  250. var d2 = Math.random() * 0xffffffff | 0;
  251. var d3 = Math.random() * 0xffffffff | 0;
  252. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  253. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  254. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  255. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  256. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  257. return uuid.toUpperCase();
  258. };
  259. } )(),
  260. clamp: function ( value, min, max ) {
  261. return Math.max( min, Math.min( max, value ) );
  262. },
  263. // compute euclidian modulo of m % n
  264. // https://en.wikipedia.org/wiki/Modulo_operation
  265. euclideanModulo: function ( n, m ) {
  266. return ( ( n % m ) + m ) % m;
  267. },
  268. // Linear mapping from range <a1, a2> to range <b1, b2>
  269. mapLinear: function ( x, a1, a2, b1, b2 ) {
  270. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  271. },
  272. // https://en.wikipedia.org/wiki/Linear_interpolation
  273. lerp: function ( x, y, t ) {
  274. return ( 1 - t ) * x + t * y;
  275. },
  276. // http://en.wikipedia.org/wiki/Smoothstep
  277. smoothstep: function ( x, min, max ) {
  278. if ( x <= min ) return 0;
  279. if ( x >= max ) return 1;
  280. x = ( x - min ) / ( max - min );
  281. return x * x * ( 3 - 2 * x );
  282. },
  283. smootherstep: function ( x, min, max ) {
  284. if ( x <= min ) return 0;
  285. if ( x >= max ) return 1;
  286. x = ( x - min ) / ( max - min );
  287. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  288. },
  289. // Random integer from <low, high> interval
  290. randInt: function ( low, high ) {
  291. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  292. },
  293. // Random float from <low, high> interval
  294. randFloat: function ( low, high ) {
  295. return low + Math.random() * ( high - low );
  296. },
  297. // Random float from <-range/2, range/2> interval
  298. randFloatSpread: function ( range ) {
  299. return range * ( 0.5 - Math.random() );
  300. },
  301. degToRad: function ( degrees ) {
  302. return degrees * _Math.DEG2RAD;
  303. },
  304. radToDeg: function ( radians ) {
  305. return radians * _Math.RAD2DEG;
  306. },
  307. isPowerOfTwo: function ( value ) {
  308. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  309. },
  310. ceilPowerOfTwo: function ( value ) {
  311. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  312. },
  313. floorPowerOfTwo: function ( value ) {
  314. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  315. }
  316. };
  317. /**
  318. * @author mrdoob / http://mrdoob.com/
  319. * @author philogb / http://blog.thejit.org/
  320. * @author egraether / http://egraether.com/
  321. * @author zz85 / http://www.lab4games.net/zz85/blog
  322. */
  323. function Vector2( x, y ) {
  324. this.x = x || 0;
  325. this.y = y || 0;
  326. }
  327. Object.defineProperties( Vector2.prototype, {
  328. "width": {
  329. get: function () {
  330. return this.x;
  331. },
  332. set: function ( value ) {
  333. this.x = value;
  334. }
  335. },
  336. "height": {
  337. get: function () {
  338. return this.y;
  339. },
  340. set: function ( value ) {
  341. this.y = value;
  342. }
  343. }
  344. } );
  345. Object.assign( Vector2.prototype, {
  346. isVector2: true,
  347. set: function ( x, y ) {
  348. this.x = x;
  349. this.y = y;
  350. return this;
  351. },
  352. setScalar: function ( scalar ) {
  353. this.x = scalar;
  354. this.y = scalar;
  355. return this;
  356. },
  357. setX: function ( x ) {
  358. this.x = x;
  359. return this;
  360. },
  361. setY: function ( y ) {
  362. this.y = y;
  363. return this;
  364. },
  365. setComponent: function ( index, value ) {
  366. switch ( index ) {
  367. case 0: this.x = value; break;
  368. case 1: this.y = value; break;
  369. default: throw new Error( 'index is out of range: ' + index );
  370. }
  371. return this;
  372. },
  373. getComponent: function ( index ) {
  374. switch ( index ) {
  375. case 0: return this.x;
  376. case 1: return this.y;
  377. default: throw new Error( 'index is out of range: ' + index );
  378. }
  379. },
  380. clone: function () {
  381. return new this.constructor( this.x, this.y );
  382. },
  383. copy: function ( v ) {
  384. this.x = v.x;
  385. this.y = v.y;
  386. return this;
  387. },
  388. add: function ( v, w ) {
  389. if ( w !== undefined ) {
  390. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  391. return this.addVectors( v, w );
  392. }
  393. this.x += v.x;
  394. this.y += v.y;
  395. return this;
  396. },
  397. addScalar: function ( s ) {
  398. this.x += s;
  399. this.y += s;
  400. return this;
  401. },
  402. addVectors: function ( a, b ) {
  403. this.x = a.x + b.x;
  404. this.y = a.y + b.y;
  405. return this;
  406. },
  407. addScaledVector: function ( v, s ) {
  408. this.x += v.x * s;
  409. this.y += v.y * s;
  410. return this;
  411. },
  412. sub: function ( v, w ) {
  413. if ( w !== undefined ) {
  414. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  415. return this.subVectors( v, w );
  416. }
  417. this.x -= v.x;
  418. this.y -= v.y;
  419. return this;
  420. },
  421. subScalar: function ( s ) {
  422. this.x -= s;
  423. this.y -= s;
  424. return this;
  425. },
  426. subVectors: function ( a, b ) {
  427. this.x = a.x - b.x;
  428. this.y = a.y - b.y;
  429. return this;
  430. },
  431. multiply: function ( v ) {
  432. this.x *= v.x;
  433. this.y *= v.y;
  434. return this;
  435. },
  436. multiplyScalar: function ( scalar ) {
  437. this.x *= scalar;
  438. this.y *= scalar;
  439. return this;
  440. },
  441. divide: function ( v ) {
  442. this.x /= v.x;
  443. this.y /= v.y;
  444. return this;
  445. },
  446. divideScalar: function ( scalar ) {
  447. return this.multiplyScalar( 1 / scalar );
  448. },
  449. applyMatrix3: function ( m ) {
  450. var x = this.x, y = this.y;
  451. var e = m.elements;
  452. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  453. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  454. return this;
  455. },
  456. min: function ( v ) {
  457. this.x = Math.min( this.x, v.x );
  458. this.y = Math.min( this.y, v.y );
  459. return this;
  460. },
  461. max: function ( v ) {
  462. this.x = Math.max( this.x, v.x );
  463. this.y = Math.max( this.y, v.y );
  464. return this;
  465. },
  466. clamp: function ( min, max ) {
  467. // assumes min < max, componentwise
  468. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  469. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  470. return this;
  471. },
  472. clampScalar: function () {
  473. var min = new Vector2();
  474. var max = new Vector2();
  475. return function clampScalar( minVal, maxVal ) {
  476. min.set( minVal, minVal );
  477. max.set( maxVal, maxVal );
  478. return this.clamp( min, max );
  479. };
  480. }(),
  481. clampLength: function ( min, max ) {
  482. var length = this.length();
  483. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  484. },
  485. floor: function () {
  486. this.x = Math.floor( this.x );
  487. this.y = Math.floor( this.y );
  488. return this;
  489. },
  490. ceil: function () {
  491. this.x = Math.ceil( this.x );
  492. this.y = Math.ceil( this.y );
  493. return this;
  494. },
  495. round: function () {
  496. this.x = Math.round( this.x );
  497. this.y = Math.round( this.y );
  498. return this;
  499. },
  500. roundToZero: function () {
  501. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  502. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  503. return this;
  504. },
  505. negate: function () {
  506. this.x = - this.x;
  507. this.y = - this.y;
  508. return this;
  509. },
  510. dot: function ( v ) {
  511. return this.x * v.x + this.y * v.y;
  512. },
  513. lengthSq: function () {
  514. return this.x * this.x + this.y * this.y;
  515. },
  516. length: function () {
  517. return Math.sqrt( this.x * this.x + this.y * this.y );
  518. },
  519. manhattanLength: function () {
  520. return Math.abs( this.x ) + Math.abs( this.y );
  521. },
  522. normalize: function () {
  523. return this.divideScalar( this.length() || 1 );
  524. },
  525. angle: function () {
  526. // computes the angle in radians with respect to the positive x-axis
  527. var angle = Math.atan2( this.y, this.x );
  528. if ( angle < 0 ) angle += 2 * Math.PI;
  529. return angle;
  530. },
  531. distanceTo: function ( v ) {
  532. return Math.sqrt( this.distanceToSquared( v ) );
  533. },
  534. distanceToSquared: function ( v ) {
  535. var dx = this.x - v.x, dy = this.y - v.y;
  536. return dx * dx + dy * dy;
  537. },
  538. manhattanDistanceTo: function ( v ) {
  539. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  540. },
  541. setLength: function ( length ) {
  542. return this.normalize().multiplyScalar( length );
  543. },
  544. lerp: function ( v, alpha ) {
  545. this.x += ( v.x - this.x ) * alpha;
  546. this.y += ( v.y - this.y ) * alpha;
  547. return this;
  548. },
  549. lerpVectors: function ( v1, v2, alpha ) {
  550. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  551. },
  552. equals: function ( v ) {
  553. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  554. },
  555. fromArray: function ( array, offset ) {
  556. if ( offset === undefined ) offset = 0;
  557. this.x = array[ offset ];
  558. this.y = array[ offset + 1 ];
  559. return this;
  560. },
  561. toArray: function ( array, offset ) {
  562. if ( array === undefined ) array = [];
  563. if ( offset === undefined ) offset = 0;
  564. array[ offset ] = this.x;
  565. array[ offset + 1 ] = this.y;
  566. return array;
  567. },
  568. fromBufferAttribute: function ( attribute, index, offset ) {
  569. if ( offset !== undefined ) {
  570. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  571. }
  572. this.x = attribute.getX( index );
  573. this.y = attribute.getY( index );
  574. return this;
  575. },
  576. rotateAround: function ( center, angle ) {
  577. var c = Math.cos( angle ), s = Math.sin( angle );
  578. var x = this.x - center.x;
  579. var y = this.y - center.y;
  580. this.x = x * c - y * s + center.x;
  581. this.y = x * s + y * c + center.y;
  582. return this;
  583. }
  584. } );
  585. /**
  586. * @author mrdoob / http://mrdoob.com/
  587. * @author supereggbert / http://www.paulbrunt.co.uk/
  588. * @author philogb / http://blog.thejit.org/
  589. * @author jordi_ros / http://plattsoft.com
  590. * @author D1plo1d / http://github.com/D1plo1d
  591. * @author alteredq / http://alteredqualia.com/
  592. * @author mikael emtinger / http://gomo.se/
  593. * @author timknip / http://www.floorplanner.com/
  594. * @author bhouston / http://clara.io
  595. * @author WestLangley / http://github.com/WestLangley
  596. */
  597. function Matrix4() {
  598. this.elements = [
  599. 1, 0, 0, 0,
  600. 0, 1, 0, 0,
  601. 0, 0, 1, 0,
  602. 0, 0, 0, 1
  603. ];
  604. if ( arguments.length > 0 ) {
  605. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  606. }
  607. }
  608. Object.assign( Matrix4.prototype, {
  609. isMatrix4: true,
  610. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  611. var te = this.elements;
  612. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  613. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  614. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  615. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  616. return this;
  617. },
  618. identity: function () {
  619. this.set(
  620. 1, 0, 0, 0,
  621. 0, 1, 0, 0,
  622. 0, 0, 1, 0,
  623. 0, 0, 0, 1
  624. );
  625. return this;
  626. },
  627. clone: function () {
  628. return new Matrix4().fromArray( this.elements );
  629. },
  630. copy: function ( m ) {
  631. var te = this.elements;
  632. var me = m.elements;
  633. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  634. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  635. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  636. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  637. return this;
  638. },
  639. copyPosition: function ( m ) {
  640. var te = this.elements, me = m.elements;
  641. te[ 12 ] = me[ 12 ];
  642. te[ 13 ] = me[ 13 ];
  643. te[ 14 ] = me[ 14 ];
  644. return this;
  645. },
  646. extractBasis: function ( xAxis, yAxis, zAxis ) {
  647. xAxis.setFromMatrixColumn( this, 0 );
  648. yAxis.setFromMatrixColumn( this, 1 );
  649. zAxis.setFromMatrixColumn( this, 2 );
  650. return this;
  651. },
  652. makeBasis: function ( xAxis, yAxis, zAxis ) {
  653. this.set(
  654. xAxis.x, yAxis.x, zAxis.x, 0,
  655. xAxis.y, yAxis.y, zAxis.y, 0,
  656. xAxis.z, yAxis.z, zAxis.z, 0,
  657. 0, 0, 0, 1
  658. );
  659. return this;
  660. },
  661. extractRotation: function () {
  662. var v1 = new Vector3();
  663. return function extractRotation( m ) {
  664. var te = this.elements;
  665. var me = m.elements;
  666. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  667. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  668. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  669. te[ 0 ] = me[ 0 ] * scaleX;
  670. te[ 1 ] = me[ 1 ] * scaleX;
  671. te[ 2 ] = me[ 2 ] * scaleX;
  672. te[ 4 ] = me[ 4 ] * scaleY;
  673. te[ 5 ] = me[ 5 ] * scaleY;
  674. te[ 6 ] = me[ 6 ] * scaleY;
  675. te[ 8 ] = me[ 8 ] * scaleZ;
  676. te[ 9 ] = me[ 9 ] * scaleZ;
  677. te[ 10 ] = me[ 10 ] * scaleZ;
  678. return this;
  679. };
  680. }(),
  681. makeRotationFromEuler: function ( euler ) {
  682. if ( ! ( euler && euler.isEuler ) ) {
  683. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  684. }
  685. var te = this.elements;
  686. var x = euler.x, y = euler.y, z = euler.z;
  687. var a = Math.cos( x ), b = Math.sin( x );
  688. var c = Math.cos( y ), d = Math.sin( y );
  689. var e = Math.cos( z ), f = Math.sin( z );
  690. if ( euler.order === 'XYZ' ) {
  691. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  692. te[ 0 ] = c * e;
  693. te[ 4 ] = - c * f;
  694. te[ 8 ] = d;
  695. te[ 1 ] = af + be * d;
  696. te[ 5 ] = ae - bf * d;
  697. te[ 9 ] = - b * c;
  698. te[ 2 ] = bf - ae * d;
  699. te[ 6 ] = be + af * d;
  700. te[ 10 ] = a * c;
  701. } else if ( euler.order === 'YXZ' ) {
  702. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  703. te[ 0 ] = ce + df * b;
  704. te[ 4 ] = de * b - cf;
  705. te[ 8 ] = a * d;
  706. te[ 1 ] = a * f;
  707. te[ 5 ] = a * e;
  708. te[ 9 ] = - b;
  709. te[ 2 ] = cf * b - de;
  710. te[ 6 ] = df + ce * b;
  711. te[ 10 ] = a * c;
  712. } else if ( euler.order === 'ZXY' ) {
  713. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  714. te[ 0 ] = ce - df * b;
  715. te[ 4 ] = - a * f;
  716. te[ 8 ] = de + cf * b;
  717. te[ 1 ] = cf + de * b;
  718. te[ 5 ] = a * e;
  719. te[ 9 ] = df - ce * b;
  720. te[ 2 ] = - a * d;
  721. te[ 6 ] = b;
  722. te[ 10 ] = a * c;
  723. } else if ( euler.order === 'ZYX' ) {
  724. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  725. te[ 0 ] = c * e;
  726. te[ 4 ] = be * d - af;
  727. te[ 8 ] = ae * d + bf;
  728. te[ 1 ] = c * f;
  729. te[ 5 ] = bf * d + ae;
  730. te[ 9 ] = af * d - be;
  731. te[ 2 ] = - d;
  732. te[ 6 ] = b * c;
  733. te[ 10 ] = a * c;
  734. } else if ( euler.order === 'YZX' ) {
  735. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  736. te[ 0 ] = c * e;
  737. te[ 4 ] = bd - ac * f;
  738. te[ 8 ] = bc * f + ad;
  739. te[ 1 ] = f;
  740. te[ 5 ] = a * e;
  741. te[ 9 ] = - b * e;
  742. te[ 2 ] = - d * e;
  743. te[ 6 ] = ad * f + bc;
  744. te[ 10 ] = ac - bd * f;
  745. } else if ( euler.order === 'XZY' ) {
  746. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  747. te[ 0 ] = c * e;
  748. te[ 4 ] = - f;
  749. te[ 8 ] = d * e;
  750. te[ 1 ] = ac * f + bd;
  751. te[ 5 ] = a * e;
  752. te[ 9 ] = ad * f - bc;
  753. te[ 2 ] = bc * f - ad;
  754. te[ 6 ] = b * e;
  755. te[ 10 ] = bd * f + ac;
  756. }
  757. // bottom row
  758. te[ 3 ] = 0;
  759. te[ 7 ] = 0;
  760. te[ 11 ] = 0;
  761. // last column
  762. te[ 12 ] = 0;
  763. te[ 13 ] = 0;
  764. te[ 14 ] = 0;
  765. te[ 15 ] = 1;
  766. return this;
  767. },
  768. makeRotationFromQuaternion: function () {
  769. var zero = new Vector3( 0, 0, 0 );
  770. var one = new Vector3( 1, 1, 1 );
  771. return function makeRotationFromQuaternion( q ) {
  772. return this.compose( zero, q, one );
  773. };
  774. }(),
  775. lookAt: function () {
  776. var x = new Vector3();
  777. var y = new Vector3();
  778. var z = new Vector3();
  779. return function lookAt( eye, target, up ) {
  780. var te = this.elements;
  781. z.subVectors( eye, target );
  782. if ( z.lengthSq() === 0 ) {
  783. // eye and target are in the same position
  784. z.z = 1;
  785. }
  786. z.normalize();
  787. x.crossVectors( up, z );
  788. if ( x.lengthSq() === 0 ) {
  789. // up and z are parallel
  790. if ( Math.abs( up.z ) === 1 ) {
  791. z.x += 0.0001;
  792. } else {
  793. z.z += 0.0001;
  794. }
  795. z.normalize();
  796. x.crossVectors( up, z );
  797. }
  798. x.normalize();
  799. y.crossVectors( z, x );
  800. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  801. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  802. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  803. return this;
  804. };
  805. }(),
  806. multiply: function ( m, n ) {
  807. if ( n !== undefined ) {
  808. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  809. return this.multiplyMatrices( m, n );
  810. }
  811. return this.multiplyMatrices( this, m );
  812. },
  813. premultiply: function ( m ) {
  814. return this.multiplyMatrices( m, this );
  815. },
  816. multiplyMatrices: function ( a, b ) {
  817. var ae = a.elements;
  818. var be = b.elements;
  819. var te = this.elements;
  820. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  821. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  822. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  823. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  824. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  825. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  826. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  827. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  828. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  829. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  830. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  831. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  832. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  833. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  834. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  835. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  836. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  837. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  838. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  839. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  840. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  841. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  842. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  843. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  844. return this;
  845. },
  846. multiplyScalar: function ( s ) {
  847. var te = this.elements;
  848. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  849. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  850. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  851. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  852. return this;
  853. },
  854. applyToBufferAttribute: function () {
  855. var v1 = new Vector3();
  856. return function applyToBufferAttribute( attribute ) {
  857. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  858. v1.x = attribute.getX( i );
  859. v1.y = attribute.getY( i );
  860. v1.z = attribute.getZ( i );
  861. v1.applyMatrix4( this );
  862. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  863. }
  864. return attribute;
  865. };
  866. }(),
  867. determinant: function () {
  868. var te = this.elements;
  869. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  870. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  871. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  872. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  873. //TODO: make this more efficient
  874. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  875. return (
  876. n41 * (
  877. + n14 * n23 * n32
  878. - n13 * n24 * n32
  879. - n14 * n22 * n33
  880. + n12 * n24 * n33
  881. + n13 * n22 * n34
  882. - n12 * n23 * n34
  883. ) +
  884. n42 * (
  885. + n11 * n23 * n34
  886. - n11 * n24 * n33
  887. + n14 * n21 * n33
  888. - n13 * n21 * n34
  889. + n13 * n24 * n31
  890. - n14 * n23 * n31
  891. ) +
  892. n43 * (
  893. + n11 * n24 * n32
  894. - n11 * n22 * n34
  895. - n14 * n21 * n32
  896. + n12 * n21 * n34
  897. + n14 * n22 * n31
  898. - n12 * n24 * n31
  899. ) +
  900. n44 * (
  901. - n13 * n22 * n31
  902. - n11 * n23 * n32
  903. + n11 * n22 * n33
  904. + n13 * n21 * n32
  905. - n12 * n21 * n33
  906. + n12 * n23 * n31
  907. )
  908. );
  909. },
  910. transpose: function () {
  911. var te = this.elements;
  912. var tmp;
  913. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  914. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  915. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  916. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  917. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  918. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  919. return this;
  920. },
  921. setPosition: function ( v ) {
  922. var te = this.elements;
  923. te[ 12 ] = v.x;
  924. te[ 13 ] = v.y;
  925. te[ 14 ] = v.z;
  926. return this;
  927. },
  928. getInverse: function ( m, throwOnDegenerate ) {
  929. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  930. var te = this.elements,
  931. me = m.elements,
  932. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  933. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  934. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  935. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  936. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  937. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  938. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  939. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  940. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  941. if ( det === 0 ) {
  942. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  943. if ( throwOnDegenerate === true ) {
  944. throw new Error( msg );
  945. } else {
  946. console.warn( msg );
  947. }
  948. return this.identity();
  949. }
  950. var detInv = 1 / det;
  951. te[ 0 ] = t11 * detInv;
  952. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  953. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  954. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  955. te[ 4 ] = t12 * detInv;
  956. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  957. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  958. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  959. te[ 8 ] = t13 * detInv;
  960. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  961. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  962. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  963. te[ 12 ] = t14 * detInv;
  964. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  965. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  966. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  967. return this;
  968. },
  969. scale: function ( v ) {
  970. var te = this.elements;
  971. var x = v.x, y = v.y, z = v.z;
  972. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  973. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  974. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  975. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  976. return this;
  977. },
  978. getMaxScaleOnAxis: function () {
  979. var te = this.elements;
  980. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  981. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  982. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  983. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  984. },
  985. makeTranslation: function ( x, y, z ) {
  986. this.set(
  987. 1, 0, 0, x,
  988. 0, 1, 0, y,
  989. 0, 0, 1, z,
  990. 0, 0, 0, 1
  991. );
  992. return this;
  993. },
  994. makeRotationX: function ( theta ) {
  995. var c = Math.cos( theta ), s = Math.sin( theta );
  996. this.set(
  997. 1, 0, 0, 0,
  998. 0, c, - s, 0,
  999. 0, s, c, 0,
  1000. 0, 0, 0, 1
  1001. );
  1002. return this;
  1003. },
  1004. makeRotationY: function ( theta ) {
  1005. var c = Math.cos( theta ), s = Math.sin( theta );
  1006. this.set(
  1007. c, 0, s, 0,
  1008. 0, 1, 0, 0,
  1009. - s, 0, c, 0,
  1010. 0, 0, 0, 1
  1011. );
  1012. return this;
  1013. },
  1014. makeRotationZ: function ( theta ) {
  1015. var c = Math.cos( theta ), s = Math.sin( theta );
  1016. this.set(
  1017. c, - s, 0, 0,
  1018. s, c, 0, 0,
  1019. 0, 0, 1, 0,
  1020. 0, 0, 0, 1
  1021. );
  1022. return this;
  1023. },
  1024. makeRotationAxis: function ( axis, angle ) {
  1025. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1026. var c = Math.cos( angle );
  1027. var s = Math.sin( angle );
  1028. var t = 1 - c;
  1029. var x = axis.x, y = axis.y, z = axis.z;
  1030. var tx = t * x, ty = t * y;
  1031. this.set(
  1032. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1033. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1034. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1035. 0, 0, 0, 1
  1036. );
  1037. return this;
  1038. },
  1039. makeScale: function ( x, y, z ) {
  1040. this.set(
  1041. x, 0, 0, 0,
  1042. 0, y, 0, 0,
  1043. 0, 0, z, 0,
  1044. 0, 0, 0, 1
  1045. );
  1046. return this;
  1047. },
  1048. makeShear: function ( x, y, z ) {
  1049. this.set(
  1050. 1, y, z, 0,
  1051. x, 1, z, 0,
  1052. x, y, 1, 0,
  1053. 0, 0, 0, 1
  1054. );
  1055. return this;
  1056. },
  1057. compose: function ( position, quaternion, scale ) {
  1058. var te = this.elements;
  1059. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  1060. var x2 = x + x, y2 = y + y, z2 = z + z;
  1061. var xx = x * x2, xy = x * y2, xz = x * z2;
  1062. var yy = y * y2, yz = y * z2, zz = z * z2;
  1063. var wx = w * x2, wy = w * y2, wz = w * z2;
  1064. var sx = scale.x, sy = scale.y, sz = scale.z;
  1065. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  1066. te[ 1 ] = ( xy + wz ) * sx;
  1067. te[ 2 ] = ( xz - wy ) * sx;
  1068. te[ 3 ] = 0;
  1069. te[ 4 ] = ( xy - wz ) * sy;
  1070. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  1071. te[ 6 ] = ( yz + wx ) * sy;
  1072. te[ 7 ] = 0;
  1073. te[ 8 ] = ( xz + wy ) * sz;
  1074. te[ 9 ] = ( yz - wx ) * sz;
  1075. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  1076. te[ 11 ] = 0;
  1077. te[ 12 ] = position.x;
  1078. te[ 13 ] = position.y;
  1079. te[ 14 ] = position.z;
  1080. te[ 15 ] = 1;
  1081. return this;
  1082. },
  1083. decompose: function () {
  1084. var vector = new Vector3();
  1085. var matrix = new Matrix4();
  1086. return function decompose( position, quaternion, scale ) {
  1087. var te = this.elements;
  1088. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  1089. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  1090. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  1091. // if determine is negative, we need to invert one scale
  1092. var det = this.determinant();
  1093. if ( det < 0 ) sx = - sx;
  1094. position.x = te[ 12 ];
  1095. position.y = te[ 13 ];
  1096. position.z = te[ 14 ];
  1097. // scale the rotation part
  1098. matrix.copy( this );
  1099. var invSX = 1 / sx;
  1100. var invSY = 1 / sy;
  1101. var invSZ = 1 / sz;
  1102. matrix.elements[ 0 ] *= invSX;
  1103. matrix.elements[ 1 ] *= invSX;
  1104. matrix.elements[ 2 ] *= invSX;
  1105. matrix.elements[ 4 ] *= invSY;
  1106. matrix.elements[ 5 ] *= invSY;
  1107. matrix.elements[ 6 ] *= invSY;
  1108. matrix.elements[ 8 ] *= invSZ;
  1109. matrix.elements[ 9 ] *= invSZ;
  1110. matrix.elements[ 10 ] *= invSZ;
  1111. quaternion.setFromRotationMatrix( matrix );
  1112. scale.x = sx;
  1113. scale.y = sy;
  1114. scale.z = sz;
  1115. return this;
  1116. };
  1117. }(),
  1118. makePerspective: function ( left, right, top, bottom, near, far ) {
  1119. if ( far === undefined ) {
  1120. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  1121. }
  1122. var te = this.elements;
  1123. var x = 2 * near / ( right - left );
  1124. var y = 2 * near / ( top - bottom );
  1125. var a = ( right + left ) / ( right - left );
  1126. var b = ( top + bottom ) / ( top - bottom );
  1127. var c = - ( far + near ) / ( far - near );
  1128. var d = - 2 * far * near / ( far - near );
  1129. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  1130. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  1131. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  1132. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  1133. return this;
  1134. },
  1135. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1136. var te = this.elements;
  1137. var w = 1.0 / ( right - left );
  1138. var h = 1.0 / ( top - bottom );
  1139. var p = 1.0 / ( far - near );
  1140. var x = ( right + left ) * w;
  1141. var y = ( top + bottom ) * h;
  1142. var z = ( far + near ) * p;
  1143. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  1144. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  1145. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  1146. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  1147. return this;
  1148. },
  1149. equals: function ( matrix ) {
  1150. var te = this.elements;
  1151. var me = matrix.elements;
  1152. for ( var i = 0; i < 16; i ++ ) {
  1153. if ( te[ i ] !== me[ i ] ) return false;
  1154. }
  1155. return true;
  1156. },
  1157. fromArray: function ( array, offset ) {
  1158. if ( offset === undefined ) offset = 0;
  1159. for ( var i = 0; i < 16; i ++ ) {
  1160. this.elements[ i ] = array[ i + offset ];
  1161. }
  1162. return this;
  1163. },
  1164. toArray: function ( array, offset ) {
  1165. if ( array === undefined ) array = [];
  1166. if ( offset === undefined ) offset = 0;
  1167. var te = this.elements;
  1168. array[ offset ] = te[ 0 ];
  1169. array[ offset + 1 ] = te[ 1 ];
  1170. array[ offset + 2 ] = te[ 2 ];
  1171. array[ offset + 3 ] = te[ 3 ];
  1172. array[ offset + 4 ] = te[ 4 ];
  1173. array[ offset + 5 ] = te[ 5 ];
  1174. array[ offset + 6 ] = te[ 6 ];
  1175. array[ offset + 7 ] = te[ 7 ];
  1176. array[ offset + 8 ] = te[ 8 ];
  1177. array[ offset + 9 ] = te[ 9 ];
  1178. array[ offset + 10 ] = te[ 10 ];
  1179. array[ offset + 11 ] = te[ 11 ];
  1180. array[ offset + 12 ] = te[ 12 ];
  1181. array[ offset + 13 ] = te[ 13 ];
  1182. array[ offset + 14 ] = te[ 14 ];
  1183. array[ offset + 15 ] = te[ 15 ];
  1184. return array;
  1185. }
  1186. } );
  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 ) ) {
  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. // quaternion is assumed to have unit length
  1428. return this.conjugate();
  1429. },
  1430. conjugate: function () {
  1431. this._x *= - 1;
  1432. this._y *= - 1;
  1433. this._z *= - 1;
  1434. this.onChangeCallback();
  1435. return this;
  1436. },
  1437. dot: function ( v ) {
  1438. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1439. },
  1440. lengthSq: function () {
  1441. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1442. },
  1443. length: function () {
  1444. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1445. },
  1446. normalize: function () {
  1447. var l = this.length();
  1448. if ( l === 0 ) {
  1449. this._x = 0;
  1450. this._y = 0;
  1451. this._z = 0;
  1452. this._w = 1;
  1453. } else {
  1454. l = 1 / l;
  1455. this._x = this._x * l;
  1456. this._y = this._y * l;
  1457. this._z = this._z * l;
  1458. this._w = this._w * l;
  1459. }
  1460. this.onChangeCallback();
  1461. return this;
  1462. },
  1463. multiply: function ( q, p ) {
  1464. if ( p !== undefined ) {
  1465. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1466. return this.multiplyQuaternions( q, p );
  1467. }
  1468. return this.multiplyQuaternions( this, q );
  1469. },
  1470. premultiply: function ( q ) {
  1471. return this.multiplyQuaternions( q, this );
  1472. },
  1473. multiplyQuaternions: function ( a, b ) {
  1474. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1475. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1476. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1477. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1478. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1479. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1480. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1481. this.onChangeCallback();
  1482. return this;
  1483. },
  1484. slerp: function ( qb, t ) {
  1485. if ( t === 0 ) return this;
  1486. if ( t === 1 ) return this.copy( qb );
  1487. var x = this._x, y = this._y, z = this._z, w = this._w;
  1488. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1489. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1490. if ( cosHalfTheta < 0 ) {
  1491. this._w = - qb._w;
  1492. this._x = - qb._x;
  1493. this._y = - qb._y;
  1494. this._z = - qb._z;
  1495. cosHalfTheta = - cosHalfTheta;
  1496. } else {
  1497. this.copy( qb );
  1498. }
  1499. if ( cosHalfTheta >= 1.0 ) {
  1500. this._w = w;
  1501. this._x = x;
  1502. this._y = y;
  1503. this._z = z;
  1504. return this;
  1505. }
  1506. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1507. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1508. this._w = 0.5 * ( w + this._w );
  1509. this._x = 0.5 * ( x + this._x );
  1510. this._y = 0.5 * ( y + this._y );
  1511. this._z = 0.5 * ( z + this._z );
  1512. return this;
  1513. }
  1514. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1515. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1516. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1517. this._w = ( w * ratioA + this._w * ratioB );
  1518. this._x = ( x * ratioA + this._x * ratioB );
  1519. this._y = ( y * ratioA + this._y * ratioB );
  1520. this._z = ( z * ratioA + this._z * ratioB );
  1521. this.onChangeCallback();
  1522. return this;
  1523. },
  1524. equals: function ( quaternion ) {
  1525. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1526. },
  1527. fromArray: function ( array, offset ) {
  1528. if ( offset === undefined ) offset = 0;
  1529. this._x = array[ offset ];
  1530. this._y = array[ offset + 1 ];
  1531. this._z = array[ offset + 2 ];
  1532. this._w = array[ offset + 3 ];
  1533. this.onChangeCallback();
  1534. return this;
  1535. },
  1536. toArray: function ( array, offset ) {
  1537. if ( array === undefined ) array = [];
  1538. if ( offset === undefined ) offset = 0;
  1539. array[ offset ] = this._x;
  1540. array[ offset + 1 ] = this._y;
  1541. array[ offset + 2 ] = this._z;
  1542. array[ offset + 3 ] = this._w;
  1543. return array;
  1544. },
  1545. onChange: function ( callback ) {
  1546. this.onChangeCallback = callback;
  1547. return this;
  1548. },
  1549. onChangeCallback: function () {}
  1550. } );
  1551. /**
  1552. * @author mrdoob / http://mrdoob.com/
  1553. * @author kile / http://kile.stravaganza.org/
  1554. * @author philogb / http://blog.thejit.org/
  1555. * @author mikael emtinger / http://gomo.se/
  1556. * @author egraether / http://egraether.com/
  1557. * @author WestLangley / http://github.com/WestLangley
  1558. */
  1559. function Vector3( x, y, z ) {
  1560. this.x = x || 0;
  1561. this.y = y || 0;
  1562. this.z = z || 0;
  1563. }
  1564. Object.assign( Vector3.prototype, {
  1565. isVector3: true,
  1566. set: function ( x, y, z ) {
  1567. this.x = x;
  1568. this.y = y;
  1569. this.z = z;
  1570. return this;
  1571. },
  1572. setScalar: function ( scalar ) {
  1573. this.x = scalar;
  1574. this.y = scalar;
  1575. this.z = scalar;
  1576. return this;
  1577. },
  1578. setX: function ( x ) {
  1579. this.x = x;
  1580. return this;
  1581. },
  1582. setY: function ( y ) {
  1583. this.y = y;
  1584. return this;
  1585. },
  1586. setZ: function ( z ) {
  1587. this.z = z;
  1588. return this;
  1589. },
  1590. setComponent: function ( index, value ) {
  1591. switch ( index ) {
  1592. case 0: this.x = value; break;
  1593. case 1: this.y = value; break;
  1594. case 2: this.z = value; break;
  1595. default: throw new Error( 'index is out of range: ' + index );
  1596. }
  1597. return this;
  1598. },
  1599. getComponent: function ( index ) {
  1600. switch ( index ) {
  1601. case 0: return this.x;
  1602. case 1: return this.y;
  1603. case 2: return this.z;
  1604. default: throw new Error( 'index is out of range: ' + index );
  1605. }
  1606. },
  1607. clone: function () {
  1608. return new this.constructor( this.x, this.y, this.z );
  1609. },
  1610. copy: function ( v ) {
  1611. this.x = v.x;
  1612. this.y = v.y;
  1613. this.z = v.z;
  1614. return this;
  1615. },
  1616. add: function ( v, w ) {
  1617. if ( w !== undefined ) {
  1618. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1619. return this.addVectors( v, w );
  1620. }
  1621. this.x += v.x;
  1622. this.y += v.y;
  1623. this.z += v.z;
  1624. return this;
  1625. },
  1626. addScalar: function ( s ) {
  1627. this.x += s;
  1628. this.y += s;
  1629. this.z += s;
  1630. return this;
  1631. },
  1632. addVectors: function ( a, b ) {
  1633. this.x = a.x + b.x;
  1634. this.y = a.y + b.y;
  1635. this.z = a.z + b.z;
  1636. return this;
  1637. },
  1638. addScaledVector: function ( v, s ) {
  1639. this.x += v.x * s;
  1640. this.y += v.y * s;
  1641. this.z += v.z * s;
  1642. return this;
  1643. },
  1644. sub: function ( v, w ) {
  1645. if ( w !== undefined ) {
  1646. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1647. return this.subVectors( v, w );
  1648. }
  1649. this.x -= v.x;
  1650. this.y -= v.y;
  1651. this.z -= v.z;
  1652. return this;
  1653. },
  1654. subScalar: function ( s ) {
  1655. this.x -= s;
  1656. this.y -= s;
  1657. this.z -= s;
  1658. return this;
  1659. },
  1660. subVectors: function ( a, b ) {
  1661. this.x = a.x - b.x;
  1662. this.y = a.y - b.y;
  1663. this.z = a.z - b.z;
  1664. return this;
  1665. },
  1666. multiply: function ( v, w ) {
  1667. if ( w !== undefined ) {
  1668. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1669. return this.multiplyVectors( v, w );
  1670. }
  1671. this.x *= v.x;
  1672. this.y *= v.y;
  1673. this.z *= v.z;
  1674. return this;
  1675. },
  1676. multiplyScalar: function ( scalar ) {
  1677. this.x *= scalar;
  1678. this.y *= scalar;
  1679. this.z *= scalar;
  1680. return this;
  1681. },
  1682. multiplyVectors: function ( a, b ) {
  1683. this.x = a.x * b.x;
  1684. this.y = a.y * b.y;
  1685. this.z = a.z * b.z;
  1686. return this;
  1687. },
  1688. applyEuler: function () {
  1689. var quaternion = new Quaternion();
  1690. return function applyEuler( euler ) {
  1691. if ( ! ( euler && euler.isEuler ) ) {
  1692. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1693. }
  1694. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1695. };
  1696. }(),
  1697. applyAxisAngle: function () {
  1698. var quaternion = new Quaternion();
  1699. return function applyAxisAngle( axis, angle ) {
  1700. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1701. };
  1702. }(),
  1703. applyMatrix3: function ( m ) {
  1704. var x = this.x, y = this.y, z = this.z;
  1705. var e = m.elements;
  1706. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1707. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1708. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1709. return this;
  1710. },
  1711. applyMatrix4: function ( m ) {
  1712. var x = this.x, y = this.y, z = this.z;
  1713. var e = m.elements;
  1714. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1715. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1716. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1717. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1718. return this;
  1719. },
  1720. applyQuaternion: function ( q ) {
  1721. var x = this.x, y = this.y, z = this.z;
  1722. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1723. // calculate quat * vector
  1724. var ix = qw * x + qy * z - qz * y;
  1725. var iy = qw * y + qz * x - qx * z;
  1726. var iz = qw * z + qx * y - qy * x;
  1727. var iw = - qx * x - qy * y - qz * z;
  1728. // calculate result * inverse quat
  1729. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1730. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1731. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1732. return this;
  1733. },
  1734. project: function () {
  1735. var matrix = new Matrix4();
  1736. return function project( camera ) {
  1737. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1738. return this.applyMatrix4( matrix );
  1739. };
  1740. }(),
  1741. unproject: function () {
  1742. var matrix = new Matrix4();
  1743. return function unproject( camera ) {
  1744. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1745. return this.applyMatrix4( matrix );
  1746. };
  1747. }(),
  1748. transformDirection: function ( m ) {
  1749. // input: THREE.Matrix4 affine matrix
  1750. // vector interpreted as a direction
  1751. var x = this.x, y = this.y, z = this.z;
  1752. var e = m.elements;
  1753. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1754. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1755. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1756. return this.normalize();
  1757. },
  1758. divide: function ( v ) {
  1759. this.x /= v.x;
  1760. this.y /= v.y;
  1761. this.z /= v.z;
  1762. return this;
  1763. },
  1764. divideScalar: function ( scalar ) {
  1765. return this.multiplyScalar( 1 / scalar );
  1766. },
  1767. min: function ( v ) {
  1768. this.x = Math.min( this.x, v.x );
  1769. this.y = Math.min( this.y, v.y );
  1770. this.z = Math.min( this.z, v.z );
  1771. return this;
  1772. },
  1773. max: function ( v ) {
  1774. this.x = Math.max( this.x, v.x );
  1775. this.y = Math.max( this.y, v.y );
  1776. this.z = Math.max( this.z, v.z );
  1777. return this;
  1778. },
  1779. clamp: function ( min, max ) {
  1780. // assumes min < max, componentwise
  1781. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1782. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1783. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1784. return this;
  1785. },
  1786. clampScalar: function () {
  1787. var min = new Vector3();
  1788. var max = new Vector3();
  1789. return function clampScalar( minVal, maxVal ) {
  1790. min.set( minVal, minVal, minVal );
  1791. max.set( maxVal, maxVal, maxVal );
  1792. return this.clamp( min, max );
  1793. };
  1794. }(),
  1795. clampLength: function ( min, max ) {
  1796. var length = this.length();
  1797. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1798. },
  1799. floor: function () {
  1800. this.x = Math.floor( this.x );
  1801. this.y = Math.floor( this.y );
  1802. this.z = Math.floor( this.z );
  1803. return this;
  1804. },
  1805. ceil: function () {
  1806. this.x = Math.ceil( this.x );
  1807. this.y = Math.ceil( this.y );
  1808. this.z = Math.ceil( this.z );
  1809. return this;
  1810. },
  1811. round: function () {
  1812. this.x = Math.round( this.x );
  1813. this.y = Math.round( this.y );
  1814. this.z = Math.round( this.z );
  1815. return this;
  1816. },
  1817. roundToZero: function () {
  1818. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1819. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1820. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1821. return this;
  1822. },
  1823. negate: function () {
  1824. this.x = - this.x;
  1825. this.y = - this.y;
  1826. this.z = - this.z;
  1827. return this;
  1828. },
  1829. dot: function ( v ) {
  1830. return this.x * v.x + this.y * v.y + this.z * v.z;
  1831. },
  1832. // TODO lengthSquared?
  1833. lengthSq: function () {
  1834. return this.x * this.x + this.y * this.y + this.z * this.z;
  1835. },
  1836. length: function () {
  1837. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1838. },
  1839. manhattanLength: function () {
  1840. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1841. },
  1842. normalize: function () {
  1843. return this.divideScalar( this.length() || 1 );
  1844. },
  1845. setLength: function ( length ) {
  1846. return this.normalize().multiplyScalar( length );
  1847. },
  1848. lerp: function ( v, alpha ) {
  1849. this.x += ( v.x - this.x ) * alpha;
  1850. this.y += ( v.y - this.y ) * alpha;
  1851. this.z += ( v.z - this.z ) * alpha;
  1852. return this;
  1853. },
  1854. lerpVectors: function ( v1, v2, alpha ) {
  1855. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1856. },
  1857. cross: function ( v, w ) {
  1858. if ( w !== undefined ) {
  1859. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1860. return this.crossVectors( v, w );
  1861. }
  1862. return this.crossVectors( this, v );
  1863. },
  1864. crossVectors: function ( a, b ) {
  1865. var ax = a.x, ay = a.y, az = a.z;
  1866. var bx = b.x, by = b.y, bz = b.z;
  1867. this.x = ay * bz - az * by;
  1868. this.y = az * bx - ax * bz;
  1869. this.z = ax * by - ay * bx;
  1870. return this;
  1871. },
  1872. projectOnVector: function ( vector ) {
  1873. var scalar = vector.dot( this ) / vector.lengthSq();
  1874. return this.copy( vector ).multiplyScalar( scalar );
  1875. },
  1876. projectOnPlane: function () {
  1877. var v1 = new Vector3();
  1878. return function projectOnPlane( planeNormal ) {
  1879. v1.copy( this ).projectOnVector( planeNormal );
  1880. return this.sub( v1 );
  1881. };
  1882. }(),
  1883. reflect: function () {
  1884. // reflect incident vector off plane orthogonal to normal
  1885. // normal is assumed to have unit length
  1886. var v1 = new Vector3();
  1887. return function reflect( normal ) {
  1888. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1889. };
  1890. }(),
  1891. angleTo: function ( v ) {
  1892. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1893. // clamp, to handle numerical problems
  1894. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1895. },
  1896. distanceTo: function ( v ) {
  1897. return Math.sqrt( this.distanceToSquared( v ) );
  1898. },
  1899. distanceToSquared: function ( v ) {
  1900. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1901. return dx * dx + dy * dy + dz * dz;
  1902. },
  1903. manhattanDistanceTo: function ( v ) {
  1904. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1905. },
  1906. setFromSpherical: function ( s ) {
  1907. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1908. this.x = sinPhiRadius * Math.sin( s.theta );
  1909. this.y = Math.cos( s.phi ) * s.radius;
  1910. this.z = sinPhiRadius * Math.cos( s.theta );
  1911. return this;
  1912. },
  1913. setFromCylindrical: function ( c ) {
  1914. this.x = c.radius * Math.sin( c.theta );
  1915. this.y = c.y;
  1916. this.z = c.radius * Math.cos( c.theta );
  1917. return this;
  1918. },
  1919. setFromMatrixPosition: function ( m ) {
  1920. var e = m.elements;
  1921. this.x = e[ 12 ];
  1922. this.y = e[ 13 ];
  1923. this.z = e[ 14 ];
  1924. return this;
  1925. },
  1926. setFromMatrixScale: function ( m ) {
  1927. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1928. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1929. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1930. this.x = sx;
  1931. this.y = sy;
  1932. this.z = sz;
  1933. return this;
  1934. },
  1935. setFromMatrixColumn: function ( m, index ) {
  1936. return this.fromArray( m.elements, index * 4 );
  1937. },
  1938. equals: function ( v ) {
  1939. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1940. },
  1941. fromArray: function ( array, offset ) {
  1942. if ( offset === undefined ) offset = 0;
  1943. this.x = array[ offset ];
  1944. this.y = array[ offset + 1 ];
  1945. this.z = array[ offset + 2 ];
  1946. return this;
  1947. },
  1948. toArray: function ( array, offset ) {
  1949. if ( array === undefined ) array = [];
  1950. if ( offset === undefined ) offset = 0;
  1951. array[ offset ] = this.x;
  1952. array[ offset + 1 ] = this.y;
  1953. array[ offset + 2 ] = this.z;
  1954. return array;
  1955. },
  1956. fromBufferAttribute: function ( attribute, index, offset ) {
  1957. if ( offset !== undefined ) {
  1958. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1959. }
  1960. this.x = attribute.getX( index );
  1961. this.y = attribute.getY( index );
  1962. this.z = attribute.getZ( index );
  1963. return this;
  1964. }
  1965. } );
  1966. /**
  1967. * @author alteredq / http://alteredqualia.com/
  1968. * @author WestLangley / http://github.com/WestLangley
  1969. * @author bhouston / http://clara.io
  1970. * @author tschw
  1971. */
  1972. function Matrix3() {
  1973. this.elements = [
  1974. 1, 0, 0,
  1975. 0, 1, 0,
  1976. 0, 0, 1
  1977. ];
  1978. if ( arguments.length > 0 ) {
  1979. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1980. }
  1981. }
  1982. Object.assign( Matrix3.prototype, {
  1983. isMatrix3: true,
  1984. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1985. var te = this.elements;
  1986. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1987. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1988. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1989. return this;
  1990. },
  1991. identity: function () {
  1992. this.set(
  1993. 1, 0, 0,
  1994. 0, 1, 0,
  1995. 0, 0, 1
  1996. );
  1997. return this;
  1998. },
  1999. clone: function () {
  2000. return new this.constructor().fromArray( this.elements );
  2001. },
  2002. copy: function ( m ) {
  2003. var te = this.elements;
  2004. var me = m.elements;
  2005. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  2006. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  2007. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  2008. return this;
  2009. },
  2010. setFromMatrix4: function ( m ) {
  2011. var me = m.elements;
  2012. this.set(
  2013. me[ 0 ], me[ 4 ], me[ 8 ],
  2014. me[ 1 ], me[ 5 ], me[ 9 ],
  2015. me[ 2 ], me[ 6 ], me[ 10 ]
  2016. );
  2017. return this;
  2018. },
  2019. applyToBufferAttribute: function () {
  2020. var v1 = new Vector3();
  2021. return function applyToBufferAttribute( attribute ) {
  2022. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2023. v1.x = attribute.getX( i );
  2024. v1.y = attribute.getY( i );
  2025. v1.z = attribute.getZ( i );
  2026. v1.applyMatrix3( this );
  2027. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2028. }
  2029. return attribute;
  2030. };
  2031. }(),
  2032. multiply: function ( m ) {
  2033. return this.multiplyMatrices( this, m );
  2034. },
  2035. premultiply: function ( m ) {
  2036. return this.multiplyMatrices( m, this );
  2037. },
  2038. multiplyMatrices: function ( a, b ) {
  2039. var ae = a.elements;
  2040. var be = b.elements;
  2041. var te = this.elements;
  2042. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  2043. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  2044. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  2045. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  2046. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  2047. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  2048. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  2049. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  2050. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  2051. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  2052. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  2053. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  2054. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  2055. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  2056. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  2057. return this;
  2058. },
  2059. multiplyScalar: function ( s ) {
  2060. var te = this.elements;
  2061. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2062. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2063. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2064. return this;
  2065. },
  2066. determinant: function () {
  2067. var te = this.elements;
  2068. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2069. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2070. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2071. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2072. },
  2073. getInverse: function ( matrix, throwOnDegenerate ) {
  2074. if ( matrix && matrix.isMatrix4 ) {
  2075. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  2076. }
  2077. var me = matrix.elements,
  2078. te = this.elements,
  2079. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2080. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2081. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2082. t11 = n33 * n22 - n32 * n23,
  2083. t12 = n32 * n13 - n33 * n12,
  2084. t13 = n23 * n12 - n22 * n13,
  2085. det = n11 * t11 + n21 * t12 + n31 * t13;
  2086. if ( det === 0 ) {
  2087. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  2088. if ( throwOnDegenerate === true ) {
  2089. throw new Error( msg );
  2090. } else {
  2091. console.warn( msg );
  2092. }
  2093. return this.identity();
  2094. }
  2095. var detInv = 1 / det;
  2096. te[ 0 ] = t11 * detInv;
  2097. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2098. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2099. te[ 3 ] = t12 * detInv;
  2100. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2101. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2102. te[ 6 ] = t13 * detInv;
  2103. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2104. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2105. return this;
  2106. },
  2107. transpose: function () {
  2108. var tmp, m = this.elements;
  2109. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2110. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2111. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2112. return this;
  2113. },
  2114. getNormalMatrix: function ( matrix4 ) {
  2115. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2116. },
  2117. transposeIntoArray: function ( r ) {
  2118. var m = this.elements;
  2119. r[ 0 ] = m[ 0 ];
  2120. r[ 1 ] = m[ 3 ];
  2121. r[ 2 ] = m[ 6 ];
  2122. r[ 3 ] = m[ 1 ];
  2123. r[ 4 ] = m[ 4 ];
  2124. r[ 5 ] = m[ 7 ];
  2125. r[ 6 ] = m[ 2 ];
  2126. r[ 7 ] = m[ 5 ];
  2127. r[ 8 ] = m[ 8 ];
  2128. return this;
  2129. },
  2130. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  2131. var c = Math.cos( rotation );
  2132. var s = Math.sin( rotation );
  2133. this.set(
  2134. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  2135. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  2136. 0, 0, 1
  2137. );
  2138. },
  2139. scale: function ( sx, sy ) {
  2140. var te = this.elements;
  2141. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  2142. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  2143. return this;
  2144. },
  2145. rotate: function ( theta ) {
  2146. var c = Math.cos( theta );
  2147. var s = Math.sin( theta );
  2148. var te = this.elements;
  2149. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  2150. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  2151. te[ 0 ] = c * a11 + s * a21;
  2152. te[ 3 ] = c * a12 + s * a22;
  2153. te[ 6 ] = c * a13 + s * a23;
  2154. te[ 1 ] = - s * a11 + c * a21;
  2155. te[ 4 ] = - s * a12 + c * a22;
  2156. te[ 7 ] = - s * a13 + c * a23;
  2157. return this;
  2158. },
  2159. translate: function ( tx, ty ) {
  2160. var te = this.elements;
  2161. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  2162. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  2163. return this;
  2164. },
  2165. equals: function ( matrix ) {
  2166. var te = this.elements;
  2167. var me = matrix.elements;
  2168. for ( var i = 0; i < 9; i ++ ) {
  2169. if ( te[ i ] !== me[ i ] ) return false;
  2170. }
  2171. return true;
  2172. },
  2173. fromArray: function ( array, offset ) {
  2174. if ( offset === undefined ) offset = 0;
  2175. for ( var i = 0; i < 9; i ++ ) {
  2176. this.elements[ i ] = array[ i + offset ];
  2177. }
  2178. return this;
  2179. },
  2180. toArray: function ( array, offset ) {
  2181. if ( array === undefined ) array = [];
  2182. if ( offset === undefined ) offset = 0;
  2183. var te = this.elements;
  2184. array[ offset ] = te[ 0 ];
  2185. array[ offset + 1 ] = te[ 1 ];
  2186. array[ offset + 2 ] = te[ 2 ];
  2187. array[ offset + 3 ] = te[ 3 ];
  2188. array[ offset + 4 ] = te[ 4 ];
  2189. array[ offset + 5 ] = te[ 5 ];
  2190. array[ offset + 6 ] = te[ 6 ];
  2191. array[ offset + 7 ] = te[ 7 ];
  2192. array[ offset + 8 ] = te[ 8 ];
  2193. return array;
  2194. }
  2195. } );
  2196. /**
  2197. * @author mrdoob / http://mrdoob.com/
  2198. * @author alteredq / http://alteredqualia.com/
  2199. * @author szimek / https://github.com/szimek/
  2200. */
  2201. var textureId = 0;
  2202. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2203. Object.defineProperty( this, 'id', { value: textureId ++ } );
  2204. this.uuid = _Math.generateUUID();
  2205. this.name = '';
  2206. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  2207. this.mipmaps = [];
  2208. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  2209. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  2210. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  2211. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  2212. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  2213. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  2214. this.format = format !== undefined ? format : RGBAFormat;
  2215. this.type = type !== undefined ? type : UnsignedByteType;
  2216. this.offset = new Vector2( 0, 0 );
  2217. this.repeat = new Vector2( 1, 1 );
  2218. this.center = new Vector2( 0, 0 );
  2219. this.rotation = 0;
  2220. this.matrixAutoUpdate = true;
  2221. this.matrix = new Matrix3();
  2222. this.generateMipmaps = true;
  2223. this.premultiplyAlpha = false;
  2224. this.flipY = true;
  2225. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  2226. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  2227. //
  2228. // Also changing the encoding after already used by a Material will not automatically make the Material
  2229. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  2230. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  2231. this.version = 0;
  2232. this.onUpdate = null;
  2233. }
  2234. Texture.DEFAULT_IMAGE = undefined;
  2235. Texture.DEFAULT_MAPPING = UVMapping;
  2236. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2237. constructor: Texture,
  2238. isTexture: true,
  2239. updateMatrix: function () {
  2240. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  2241. },
  2242. clone: function () {
  2243. return new this.constructor().copy( this );
  2244. },
  2245. copy: function ( source ) {
  2246. this.name = source.name;
  2247. this.image = source.image;
  2248. this.mipmaps = source.mipmaps.slice( 0 );
  2249. this.mapping = source.mapping;
  2250. this.wrapS = source.wrapS;
  2251. this.wrapT = source.wrapT;
  2252. this.magFilter = source.magFilter;
  2253. this.minFilter = source.minFilter;
  2254. this.anisotropy = source.anisotropy;
  2255. this.format = source.format;
  2256. this.type = source.type;
  2257. this.offset.copy( source.offset );
  2258. this.repeat.copy( source.repeat );
  2259. this.center.copy( source.center );
  2260. this.rotation = source.rotation;
  2261. this.matrixAutoUpdate = source.matrixAutoUpdate;
  2262. this.matrix.copy( source.matrix );
  2263. this.generateMipmaps = source.generateMipmaps;
  2264. this.premultiplyAlpha = source.premultiplyAlpha;
  2265. this.flipY = source.flipY;
  2266. this.unpackAlignment = source.unpackAlignment;
  2267. this.encoding = source.encoding;
  2268. return this;
  2269. },
  2270. toJSON: function ( meta ) {
  2271. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  2272. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  2273. return meta.textures[ this.uuid ];
  2274. }
  2275. function getDataURL( image ) {
  2276. var canvas;
  2277. if ( image instanceof HTMLCanvasElement ) {
  2278. canvas = image;
  2279. } else {
  2280. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  2281. canvas.width = image.width;
  2282. canvas.height = image.height;
  2283. var context = canvas.getContext( '2d' );
  2284. if ( image instanceof ImageData ) {
  2285. context.putImageData( image, 0, 0 );
  2286. } else {
  2287. context.drawImage( image, 0, 0, image.width, image.height );
  2288. }
  2289. }
  2290. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  2291. return canvas.toDataURL( 'image/jpeg', 0.6 );
  2292. } else {
  2293. return canvas.toDataURL( 'image/png' );
  2294. }
  2295. }
  2296. var output = {
  2297. metadata: {
  2298. version: 4.5,
  2299. type: 'Texture',
  2300. generator: 'Texture.toJSON'
  2301. },
  2302. uuid: this.uuid,
  2303. name: this.name,
  2304. mapping: this.mapping,
  2305. repeat: [ this.repeat.x, this.repeat.y ],
  2306. offset: [ this.offset.x, this.offset.y ],
  2307. center: [ this.center.x, this.center.y ],
  2308. rotation: this.rotation,
  2309. wrap: [ this.wrapS, this.wrapT ],
  2310. format: this.format,
  2311. minFilter: this.minFilter,
  2312. magFilter: this.magFilter,
  2313. anisotropy: this.anisotropy,
  2314. flipY: this.flipY
  2315. };
  2316. if ( this.image !== undefined ) {
  2317. // TODO: Move to THREE.Image
  2318. var image = this.image;
  2319. if ( image.uuid === undefined ) {
  2320. image.uuid = _Math.generateUUID(); // UGH
  2321. }
  2322. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  2323. meta.images[ image.uuid ] = {
  2324. uuid: image.uuid,
  2325. url: getDataURL( image )
  2326. };
  2327. }
  2328. output.image = image.uuid;
  2329. }
  2330. if ( ! isRootObject ) {
  2331. meta.textures[ this.uuid ] = output;
  2332. }
  2333. return output;
  2334. },
  2335. dispose: function () {
  2336. this.dispatchEvent( { type: 'dispose' } );
  2337. },
  2338. transformUv: function ( uv ) {
  2339. if ( this.mapping !== UVMapping ) return;
  2340. uv.applyMatrix3( this.matrix );
  2341. if ( uv.x < 0 || uv.x > 1 ) {
  2342. switch ( this.wrapS ) {
  2343. case RepeatWrapping:
  2344. uv.x = uv.x - Math.floor( uv.x );
  2345. break;
  2346. case ClampToEdgeWrapping:
  2347. uv.x = uv.x < 0 ? 0 : 1;
  2348. break;
  2349. case MirroredRepeatWrapping:
  2350. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  2351. uv.x = Math.ceil( uv.x ) - uv.x;
  2352. } else {
  2353. uv.x = uv.x - Math.floor( uv.x );
  2354. }
  2355. break;
  2356. }
  2357. }
  2358. if ( uv.y < 0 || uv.y > 1 ) {
  2359. switch ( this.wrapT ) {
  2360. case RepeatWrapping:
  2361. uv.y = uv.y - Math.floor( uv.y );
  2362. break;
  2363. case ClampToEdgeWrapping:
  2364. uv.y = uv.y < 0 ? 0 : 1;
  2365. break;
  2366. case MirroredRepeatWrapping:
  2367. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  2368. uv.y = Math.ceil( uv.y ) - uv.y;
  2369. } else {
  2370. uv.y = uv.y - Math.floor( uv.y );
  2371. }
  2372. break;
  2373. }
  2374. }
  2375. if ( this.flipY ) {
  2376. uv.y = 1 - uv.y;
  2377. }
  2378. }
  2379. } );
  2380. Object.defineProperty( Texture.prototype, "needsUpdate", {
  2381. set: function ( value ) {
  2382. if ( value === true ) this.version ++;
  2383. }
  2384. } );
  2385. /**
  2386. * @author supereggbert / http://www.paulbrunt.co.uk/
  2387. * @author philogb / http://blog.thejit.org/
  2388. * @author mikael emtinger / http://gomo.se/
  2389. * @author egraether / http://egraether.com/
  2390. * @author WestLangley / http://github.com/WestLangley
  2391. */
  2392. function Vector4( x, y, z, w ) {
  2393. this.x = x || 0;
  2394. this.y = y || 0;
  2395. this.z = z || 0;
  2396. this.w = ( w !== undefined ) ? w : 1;
  2397. }
  2398. Object.assign( Vector4.prototype, {
  2399. isVector4: true,
  2400. set: function ( x, y, z, w ) {
  2401. this.x = x;
  2402. this.y = y;
  2403. this.z = z;
  2404. this.w = w;
  2405. return this;
  2406. },
  2407. setScalar: function ( scalar ) {
  2408. this.x = scalar;
  2409. this.y = scalar;
  2410. this.z = scalar;
  2411. this.w = scalar;
  2412. return this;
  2413. },
  2414. setX: function ( x ) {
  2415. this.x = x;
  2416. return this;
  2417. },
  2418. setY: function ( y ) {
  2419. this.y = y;
  2420. return this;
  2421. },
  2422. setZ: function ( z ) {
  2423. this.z = z;
  2424. return this;
  2425. },
  2426. setW: function ( w ) {
  2427. this.w = w;
  2428. return this;
  2429. },
  2430. setComponent: function ( index, value ) {
  2431. switch ( index ) {
  2432. case 0: this.x = value; break;
  2433. case 1: this.y = value; break;
  2434. case 2: this.z = value; break;
  2435. case 3: this.w = value; break;
  2436. default: throw new Error( 'index is out of range: ' + index );
  2437. }
  2438. return this;
  2439. },
  2440. getComponent: function ( index ) {
  2441. switch ( index ) {
  2442. case 0: return this.x;
  2443. case 1: return this.y;
  2444. case 2: return this.z;
  2445. case 3: return this.w;
  2446. default: throw new Error( 'index is out of range: ' + index );
  2447. }
  2448. },
  2449. clone: function () {
  2450. return new this.constructor( this.x, this.y, this.z, this.w );
  2451. },
  2452. copy: function ( v ) {
  2453. this.x = v.x;
  2454. this.y = v.y;
  2455. this.z = v.z;
  2456. this.w = ( v.w !== undefined ) ? v.w : 1;
  2457. return this;
  2458. },
  2459. add: function ( v, w ) {
  2460. if ( w !== undefined ) {
  2461. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2462. return this.addVectors( v, w );
  2463. }
  2464. this.x += v.x;
  2465. this.y += v.y;
  2466. this.z += v.z;
  2467. this.w += v.w;
  2468. return this;
  2469. },
  2470. addScalar: function ( s ) {
  2471. this.x += s;
  2472. this.y += s;
  2473. this.z += s;
  2474. this.w += s;
  2475. return this;
  2476. },
  2477. addVectors: function ( a, b ) {
  2478. this.x = a.x + b.x;
  2479. this.y = a.y + b.y;
  2480. this.z = a.z + b.z;
  2481. this.w = a.w + b.w;
  2482. return this;
  2483. },
  2484. addScaledVector: function ( v, s ) {
  2485. this.x += v.x * s;
  2486. this.y += v.y * s;
  2487. this.z += v.z * s;
  2488. this.w += v.w * s;
  2489. return this;
  2490. },
  2491. sub: function ( v, w ) {
  2492. if ( w !== undefined ) {
  2493. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2494. return this.subVectors( v, w );
  2495. }
  2496. this.x -= v.x;
  2497. this.y -= v.y;
  2498. this.z -= v.z;
  2499. this.w -= v.w;
  2500. return this;
  2501. },
  2502. subScalar: function ( s ) {
  2503. this.x -= s;
  2504. this.y -= s;
  2505. this.z -= s;
  2506. this.w -= s;
  2507. return this;
  2508. },
  2509. subVectors: function ( a, b ) {
  2510. this.x = a.x - b.x;
  2511. this.y = a.y - b.y;
  2512. this.z = a.z - b.z;
  2513. this.w = a.w - b.w;
  2514. return this;
  2515. },
  2516. multiplyScalar: function ( scalar ) {
  2517. this.x *= scalar;
  2518. this.y *= scalar;
  2519. this.z *= scalar;
  2520. this.w *= scalar;
  2521. return this;
  2522. },
  2523. applyMatrix4: function ( m ) {
  2524. var x = this.x, y = this.y, z = this.z, w = this.w;
  2525. var e = m.elements;
  2526. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2527. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2528. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2529. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2530. return this;
  2531. },
  2532. divideScalar: function ( scalar ) {
  2533. return this.multiplyScalar( 1 / scalar );
  2534. },
  2535. setAxisAngleFromQuaternion: function ( q ) {
  2536. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2537. // q is assumed to be normalized
  2538. this.w = 2 * Math.acos( q.w );
  2539. var s = Math.sqrt( 1 - q.w * q.w );
  2540. if ( s < 0.0001 ) {
  2541. this.x = 1;
  2542. this.y = 0;
  2543. this.z = 0;
  2544. } else {
  2545. this.x = q.x / s;
  2546. this.y = q.y / s;
  2547. this.z = q.z / s;
  2548. }
  2549. return this;
  2550. },
  2551. setAxisAngleFromRotationMatrix: function ( m ) {
  2552. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2553. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2554. var angle, x, y, z, // variables for result
  2555. epsilon = 0.01, // margin to allow for rounding errors
  2556. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2557. te = m.elements,
  2558. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2559. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2560. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2561. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2562. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2563. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2564. // singularity found
  2565. // first check for identity matrix which must have +1 for all terms
  2566. // in leading diagonal and zero in other terms
  2567. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2568. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2569. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2570. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2571. // this singularity is identity matrix so angle = 0
  2572. this.set( 1, 0, 0, 0 );
  2573. return this; // zero angle, arbitrary axis
  2574. }
  2575. // otherwise this singularity is angle = 180
  2576. angle = Math.PI;
  2577. var xx = ( m11 + 1 ) / 2;
  2578. var yy = ( m22 + 1 ) / 2;
  2579. var zz = ( m33 + 1 ) / 2;
  2580. var xy = ( m12 + m21 ) / 4;
  2581. var xz = ( m13 + m31 ) / 4;
  2582. var yz = ( m23 + m32 ) / 4;
  2583. if ( ( xx > yy ) && ( xx > zz ) ) {
  2584. // m11 is the largest diagonal term
  2585. if ( xx < epsilon ) {
  2586. x = 0;
  2587. y = 0.707106781;
  2588. z = 0.707106781;
  2589. } else {
  2590. x = Math.sqrt( xx );
  2591. y = xy / x;
  2592. z = xz / x;
  2593. }
  2594. } else if ( yy > zz ) {
  2595. // m22 is the largest diagonal term
  2596. if ( yy < epsilon ) {
  2597. x = 0.707106781;
  2598. y = 0;
  2599. z = 0.707106781;
  2600. } else {
  2601. y = Math.sqrt( yy );
  2602. x = xy / y;
  2603. z = yz / y;
  2604. }
  2605. } else {
  2606. // m33 is the largest diagonal term so base result on this
  2607. if ( zz < epsilon ) {
  2608. x = 0.707106781;
  2609. y = 0.707106781;
  2610. z = 0;
  2611. } else {
  2612. z = Math.sqrt( zz );
  2613. x = xz / z;
  2614. y = yz / z;
  2615. }
  2616. }
  2617. this.set( x, y, z, angle );
  2618. return this; // return 180 deg rotation
  2619. }
  2620. // as we have reached here there are no singularities so we can handle normally
  2621. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2622. ( m13 - m31 ) * ( m13 - m31 ) +
  2623. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2624. if ( Math.abs( s ) < 0.001 ) s = 1;
  2625. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2626. // caught by singularity test above, but I've left it in just in case
  2627. this.x = ( m32 - m23 ) / s;
  2628. this.y = ( m13 - m31 ) / s;
  2629. this.z = ( m21 - m12 ) / s;
  2630. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2631. return this;
  2632. },
  2633. min: function ( v ) {
  2634. this.x = Math.min( this.x, v.x );
  2635. this.y = Math.min( this.y, v.y );
  2636. this.z = Math.min( this.z, v.z );
  2637. this.w = Math.min( this.w, v.w );
  2638. return this;
  2639. },
  2640. max: function ( v ) {
  2641. this.x = Math.max( this.x, v.x );
  2642. this.y = Math.max( this.y, v.y );
  2643. this.z = Math.max( this.z, v.z );
  2644. this.w = Math.max( this.w, v.w );
  2645. return this;
  2646. },
  2647. clamp: function ( min, max ) {
  2648. // assumes min < max, componentwise
  2649. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2650. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2651. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2652. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2653. return this;
  2654. },
  2655. clampScalar: function () {
  2656. var min, max;
  2657. return function clampScalar( minVal, maxVal ) {
  2658. if ( min === undefined ) {
  2659. min = new Vector4();
  2660. max = new Vector4();
  2661. }
  2662. min.set( minVal, minVal, minVal, minVal );
  2663. max.set( maxVal, maxVal, maxVal, maxVal );
  2664. return this.clamp( min, max );
  2665. };
  2666. }(),
  2667. clampLength: function ( min, max ) {
  2668. var length = this.length();
  2669. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2670. },
  2671. floor: function () {
  2672. this.x = Math.floor( this.x );
  2673. this.y = Math.floor( this.y );
  2674. this.z = Math.floor( this.z );
  2675. this.w = Math.floor( this.w );
  2676. return this;
  2677. },
  2678. ceil: function () {
  2679. this.x = Math.ceil( this.x );
  2680. this.y = Math.ceil( this.y );
  2681. this.z = Math.ceil( this.z );
  2682. this.w = Math.ceil( this.w );
  2683. return this;
  2684. },
  2685. round: function () {
  2686. this.x = Math.round( this.x );
  2687. this.y = Math.round( this.y );
  2688. this.z = Math.round( this.z );
  2689. this.w = Math.round( this.w );
  2690. return this;
  2691. },
  2692. roundToZero: function () {
  2693. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2694. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2695. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2696. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2697. return this;
  2698. },
  2699. negate: function () {
  2700. this.x = - this.x;
  2701. this.y = - this.y;
  2702. this.z = - this.z;
  2703. this.w = - this.w;
  2704. return this;
  2705. },
  2706. dot: function ( v ) {
  2707. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2708. },
  2709. lengthSq: function () {
  2710. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2711. },
  2712. length: function () {
  2713. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2714. },
  2715. manhattanLength: function () {
  2716. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2717. },
  2718. normalize: function () {
  2719. return this.divideScalar( this.length() || 1 );
  2720. },
  2721. setLength: function ( length ) {
  2722. return this.normalize().multiplyScalar( length );
  2723. },
  2724. lerp: function ( v, alpha ) {
  2725. this.x += ( v.x - this.x ) * alpha;
  2726. this.y += ( v.y - this.y ) * alpha;
  2727. this.z += ( v.z - this.z ) * alpha;
  2728. this.w += ( v.w - this.w ) * alpha;
  2729. return this;
  2730. },
  2731. lerpVectors: function ( v1, v2, alpha ) {
  2732. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2733. },
  2734. equals: function ( v ) {
  2735. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2736. },
  2737. fromArray: function ( array, offset ) {
  2738. if ( offset === undefined ) offset = 0;
  2739. this.x = array[ offset ];
  2740. this.y = array[ offset + 1 ];
  2741. this.z = array[ offset + 2 ];
  2742. this.w = array[ offset + 3 ];
  2743. return this;
  2744. },
  2745. toArray: function ( array, offset ) {
  2746. if ( array === undefined ) array = [];
  2747. if ( offset === undefined ) offset = 0;
  2748. array[ offset ] = this.x;
  2749. array[ offset + 1 ] = this.y;
  2750. array[ offset + 2 ] = this.z;
  2751. array[ offset + 3 ] = this.w;
  2752. return array;
  2753. },
  2754. fromBufferAttribute: function ( attribute, index, offset ) {
  2755. if ( offset !== undefined ) {
  2756. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2757. }
  2758. this.x = attribute.getX( index );
  2759. this.y = attribute.getY( index );
  2760. this.z = attribute.getZ( index );
  2761. this.w = attribute.getW( index );
  2762. return this;
  2763. }
  2764. } );
  2765. /**
  2766. * @author szimek / https://github.com/szimek/
  2767. * @author alteredq / http://alteredqualia.com/
  2768. * @author Marius Kintel / https://github.com/kintel
  2769. */
  2770. /*
  2771. In options, we can specify:
  2772. * Texture parameters for an auto-generated target texture
  2773. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2774. */
  2775. function WebGLRenderTarget( width, height, options ) {
  2776. this.width = width;
  2777. this.height = height;
  2778. this.scissor = new Vector4( 0, 0, width, height );
  2779. this.scissorTest = false;
  2780. this.viewport = new Vector4( 0, 0, width, height );
  2781. options = options || {};
  2782. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  2783. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2784. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : true;
  2785. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2786. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2787. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2788. }
  2789. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2790. constructor: WebGLRenderTarget,
  2791. isWebGLRenderTarget: true,
  2792. setSize: function ( width, height ) {
  2793. if ( this.width !== width || this.height !== height ) {
  2794. this.width = width;
  2795. this.height = height;
  2796. this.dispose();
  2797. }
  2798. this.viewport.set( 0, 0, width, height );
  2799. this.scissor.set( 0, 0, width, height );
  2800. },
  2801. clone: function () {
  2802. return new this.constructor().copy( this );
  2803. },
  2804. copy: function ( source ) {
  2805. this.width = source.width;
  2806. this.height = source.height;
  2807. this.viewport.copy( source.viewport );
  2808. this.texture = source.texture.clone();
  2809. this.depthBuffer = source.depthBuffer;
  2810. this.stencilBuffer = source.stencilBuffer;
  2811. this.depthTexture = source.depthTexture;
  2812. return this;
  2813. },
  2814. dispose: function () {
  2815. this.dispatchEvent( { type: 'dispose' } );
  2816. }
  2817. } );
  2818. /**
  2819. * @author alteredq / http://alteredqualia.com
  2820. */
  2821. function WebGLRenderTargetCube( width, height, options ) {
  2822. WebGLRenderTarget.call( this, width, height, options );
  2823. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  2824. this.activeMipMapLevel = 0;
  2825. }
  2826. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2827. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2828. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2829. /**
  2830. * @author alteredq / http://alteredqualia.com/
  2831. */
  2832. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2833. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2834. this.image = { data: data, width: width, height: height };
  2835. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2836. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2837. this.generateMipmaps = false;
  2838. this.flipY = false;
  2839. this.unpackAlignment = 1;
  2840. }
  2841. DataTexture.prototype = Object.create( Texture.prototype );
  2842. DataTexture.prototype.constructor = DataTexture;
  2843. DataTexture.prototype.isDataTexture = true;
  2844. /**
  2845. * @author bhouston / http://clara.io
  2846. * @author WestLangley / http://github.com/WestLangley
  2847. */
  2848. function Box3( min, max ) {
  2849. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2850. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2851. }
  2852. Object.assign( Box3.prototype, {
  2853. isBox3: true,
  2854. set: function ( min, max ) {
  2855. this.min.copy( min );
  2856. this.max.copy( max );
  2857. return this;
  2858. },
  2859. setFromArray: function ( array ) {
  2860. var minX = + Infinity;
  2861. var minY = + Infinity;
  2862. var minZ = + Infinity;
  2863. var maxX = - Infinity;
  2864. var maxY = - Infinity;
  2865. var maxZ = - Infinity;
  2866. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2867. var x = array[ i ];
  2868. var y = array[ i + 1 ];
  2869. var z = array[ i + 2 ];
  2870. if ( x < minX ) minX = x;
  2871. if ( y < minY ) minY = y;
  2872. if ( z < minZ ) minZ = z;
  2873. if ( x > maxX ) maxX = x;
  2874. if ( y > maxY ) maxY = y;
  2875. if ( z > maxZ ) maxZ = z;
  2876. }
  2877. this.min.set( minX, minY, minZ );
  2878. this.max.set( maxX, maxY, maxZ );
  2879. return this;
  2880. },
  2881. setFromBufferAttribute: function ( attribute ) {
  2882. var minX = + Infinity;
  2883. var minY = + Infinity;
  2884. var minZ = + Infinity;
  2885. var maxX = - Infinity;
  2886. var maxY = - Infinity;
  2887. var maxZ = - Infinity;
  2888. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2889. var x = attribute.getX( i );
  2890. var y = attribute.getY( i );
  2891. var z = attribute.getZ( i );
  2892. if ( x < minX ) minX = x;
  2893. if ( y < minY ) minY = y;
  2894. if ( z < minZ ) minZ = z;
  2895. if ( x > maxX ) maxX = x;
  2896. if ( y > maxY ) maxY = y;
  2897. if ( z > maxZ ) maxZ = z;
  2898. }
  2899. this.min.set( minX, minY, minZ );
  2900. this.max.set( maxX, maxY, maxZ );
  2901. return this;
  2902. },
  2903. setFromPoints: function ( points ) {
  2904. this.makeEmpty();
  2905. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2906. this.expandByPoint( points[ i ] );
  2907. }
  2908. return this;
  2909. },
  2910. setFromCenterAndSize: function () {
  2911. var v1 = new Vector3();
  2912. return function setFromCenterAndSize( center, size ) {
  2913. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2914. this.min.copy( center ).sub( halfSize );
  2915. this.max.copy( center ).add( halfSize );
  2916. return this;
  2917. };
  2918. }(),
  2919. setFromObject: function ( object ) {
  2920. this.makeEmpty();
  2921. return this.expandByObject( object );
  2922. },
  2923. clone: function () {
  2924. return new this.constructor().copy( this );
  2925. },
  2926. copy: function ( box ) {
  2927. this.min.copy( box.min );
  2928. this.max.copy( box.max );
  2929. return this;
  2930. },
  2931. makeEmpty: function () {
  2932. this.min.x = this.min.y = this.min.z = + Infinity;
  2933. this.max.x = this.max.y = this.max.z = - Infinity;
  2934. return this;
  2935. },
  2936. isEmpty: function () {
  2937. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2938. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2939. },
  2940. getCenter: function ( target ) {
  2941. if ( target === undefined ) {
  2942. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2943. target = new Vector3();
  2944. }
  2945. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2946. },
  2947. getSize: function ( target ) {
  2948. if ( target === undefined ) {
  2949. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2950. target = new Vector3();
  2951. }
  2952. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2953. },
  2954. expandByPoint: function ( point ) {
  2955. this.min.min( point );
  2956. this.max.max( point );
  2957. return this;
  2958. },
  2959. expandByVector: function ( vector ) {
  2960. this.min.sub( vector );
  2961. this.max.add( vector );
  2962. return this;
  2963. },
  2964. expandByScalar: function ( scalar ) {
  2965. this.min.addScalar( - scalar );
  2966. this.max.addScalar( scalar );
  2967. return this;
  2968. },
  2969. expandByObject: function () {
  2970. // Computes the world-axis-aligned bounding box of an object (including its children),
  2971. // accounting for both the object's, and children's, world transforms
  2972. var scope, i, l;
  2973. var v1 = new Vector3();
  2974. function traverse( node ) {
  2975. var geometry = node.geometry;
  2976. if ( geometry !== undefined ) {
  2977. if ( geometry.isGeometry ) {
  2978. var vertices = geometry.vertices;
  2979. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  2980. v1.copy( vertices[ i ] );
  2981. v1.applyMatrix4( node.matrixWorld );
  2982. scope.expandByPoint( v1 );
  2983. }
  2984. } else if ( geometry.isBufferGeometry ) {
  2985. var attribute = geometry.attributes.position;
  2986. if ( attribute !== undefined ) {
  2987. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  2988. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  2989. scope.expandByPoint( v1 );
  2990. }
  2991. }
  2992. }
  2993. }
  2994. }
  2995. return function expandByObject( object ) {
  2996. scope = this;
  2997. object.updateMatrixWorld( true );
  2998. object.traverse( traverse );
  2999. return this;
  3000. };
  3001. }(),
  3002. containsPoint: function ( point ) {
  3003. return point.x < this.min.x || point.x > this.max.x ||
  3004. point.y < this.min.y || point.y > this.max.y ||
  3005. point.z < this.min.z || point.z > this.max.z ? false : true;
  3006. },
  3007. containsBox: function ( box ) {
  3008. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3009. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3010. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3011. },
  3012. getParameter: function ( point, target ) {
  3013. // This can potentially have a divide by zero if the box
  3014. // has a size dimension of 0.
  3015. if ( target === undefined ) {
  3016. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3017. target = new Vector3();
  3018. }
  3019. return target.set(
  3020. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3021. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3022. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3023. );
  3024. },
  3025. intersectsBox: function ( box ) {
  3026. // using 6 splitting planes to rule out intersections.
  3027. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3028. box.max.y < this.min.y || box.min.y > this.max.y ||
  3029. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3030. },
  3031. intersectsSphere: ( function () {
  3032. var closestPoint = new Vector3();
  3033. return function intersectsSphere( sphere ) {
  3034. // Find the point on the AABB closest to the sphere center.
  3035. this.clampPoint( sphere.center, closestPoint );
  3036. // If that point is inside the sphere, the AABB and sphere intersect.
  3037. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3038. };
  3039. } )(),
  3040. intersectsPlane: function ( plane ) {
  3041. // We compute the minimum and maximum dot product values. If those values
  3042. // are on the same side (back or front) of the plane, then there is no intersection.
  3043. var min, max;
  3044. if ( plane.normal.x > 0 ) {
  3045. min = plane.normal.x * this.min.x;
  3046. max = plane.normal.x * this.max.x;
  3047. } else {
  3048. min = plane.normal.x * this.max.x;
  3049. max = plane.normal.x * this.min.x;
  3050. }
  3051. if ( plane.normal.y > 0 ) {
  3052. min += plane.normal.y * this.min.y;
  3053. max += plane.normal.y * this.max.y;
  3054. } else {
  3055. min += plane.normal.y * this.max.y;
  3056. max += plane.normal.y * this.min.y;
  3057. }
  3058. if ( plane.normal.z > 0 ) {
  3059. min += plane.normal.z * this.min.z;
  3060. max += plane.normal.z * this.max.z;
  3061. } else {
  3062. min += plane.normal.z * this.max.z;
  3063. max += plane.normal.z * this.min.z;
  3064. }
  3065. return ( min <= plane.constant && max >= plane.constant );
  3066. },
  3067. intersectsTriangle: ( function () {
  3068. // triangle centered vertices
  3069. var v0 = new Vector3();
  3070. var v1 = new Vector3();
  3071. var v2 = new Vector3();
  3072. // triangle edge vectors
  3073. var f0 = new Vector3();
  3074. var f1 = new Vector3();
  3075. var f2 = new Vector3();
  3076. var testAxis = new Vector3();
  3077. var center = new Vector3();
  3078. var extents = new Vector3();
  3079. var triangleNormal = new Vector3();
  3080. function satForAxes( axes ) {
  3081. var i, j;
  3082. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3083. testAxis.fromArray( axes, i );
  3084. // project the aabb onto the seperating axis
  3085. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3086. // project all 3 vertices of the triangle onto the seperating axis
  3087. var p0 = v0.dot( testAxis );
  3088. var p1 = v1.dot( testAxis );
  3089. var p2 = v2.dot( testAxis );
  3090. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3091. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3092. // points of the projected triangle are outside the projected half-length of the aabb
  3093. // the axis is seperating and we can exit
  3094. return false;
  3095. }
  3096. }
  3097. return true;
  3098. }
  3099. return function intersectsTriangle( triangle ) {
  3100. if ( this.isEmpty() ) {
  3101. return false;
  3102. }
  3103. // compute box center and extents
  3104. this.getCenter( center );
  3105. extents.subVectors( this.max, center );
  3106. // translate triangle to aabb origin
  3107. v0.subVectors( triangle.a, center );
  3108. v1.subVectors( triangle.b, center );
  3109. v2.subVectors( triangle.c, center );
  3110. // compute edge vectors for triangle
  3111. f0.subVectors( v1, v0 );
  3112. f1.subVectors( v2, v1 );
  3113. f2.subVectors( v0, v2 );
  3114. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3115. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  3116. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3117. var axes = [
  3118. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3119. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3120. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3121. ];
  3122. if ( ! satForAxes( axes ) ) {
  3123. return false;
  3124. }
  3125. // test 3 face normals from the aabb
  3126. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3127. if ( ! satForAxes( axes ) ) {
  3128. return false;
  3129. }
  3130. // finally testing the face normal of the triangle
  3131. // use already existing triangle edge vectors here
  3132. triangleNormal.crossVectors( f0, f1 );
  3133. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3134. return satForAxes( axes );
  3135. };
  3136. } )(),
  3137. clampPoint: function ( point, target ) {
  3138. if ( target === undefined ) {
  3139. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3140. target = new Vector3();
  3141. }
  3142. return target.copy( point ).clamp( this.min, this.max );
  3143. },
  3144. distanceToPoint: function () {
  3145. var v1 = new Vector3();
  3146. return function distanceToPoint( point ) {
  3147. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3148. return clampedPoint.sub( point ).length();
  3149. };
  3150. }(),
  3151. getBoundingSphere: function () {
  3152. var v1 = new Vector3();
  3153. return function getBoundingSphere( target ) {
  3154. if ( target === undefined ) {
  3155. console.warn( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3156. target = new Sphere();
  3157. }
  3158. this.getCenter( target.center );
  3159. target.radius = this.getSize( v1 ).length() * 0.5;
  3160. return target;
  3161. };
  3162. }(),
  3163. intersect: function ( box ) {
  3164. this.min.max( box.min );
  3165. this.max.min( box.max );
  3166. // 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.
  3167. if ( this.isEmpty() ) this.makeEmpty();
  3168. return this;
  3169. },
  3170. union: function ( box ) {
  3171. this.min.min( box.min );
  3172. this.max.max( box.max );
  3173. return this;
  3174. },
  3175. applyMatrix4: function ( matrix ) {
  3176. // transform of empty box is an empty box.
  3177. if ( this.isEmpty( ) ) return this;
  3178. var m = matrix.elements;
  3179. var xax = m[ 0 ] * this.min.x, xay = m[ 1 ] * this.min.x, xaz = m[ 2 ] * this.min.x;
  3180. var xbx = m[ 0 ] * this.max.x, xby = m[ 1 ] * this.max.x, xbz = m[ 2 ] * this.max.x;
  3181. var yax = m[ 4 ] * this.min.y, yay = m[ 5 ] * this.min.y, yaz = m[ 6 ] * this.min.y;
  3182. var ybx = m[ 4 ] * this.max.y, yby = m[ 5 ] * this.max.y, ybz = m[ 6 ] * this.max.y;
  3183. var zax = m[ 8 ] * this.min.z, zay = m[ 9 ] * this.min.z, zaz = m[ 10 ] * this.min.z;
  3184. var zbx = m[ 8 ] * this.max.z, zby = m[ 9 ] * this.max.z, zbz = m[ 10 ] * this.max.z;
  3185. this.min.x = Math.min( xax, xbx ) + Math.min( yax, ybx ) + Math.min( zax, zbx ) + m[ 12 ];
  3186. this.min.y = Math.min( xay, xby ) + Math.min( yay, yby ) + Math.min( zay, zby ) + m[ 13 ];
  3187. this.min.z = Math.min( xaz, xbz ) + Math.min( yaz, ybz ) + Math.min( zaz, zbz ) + m[ 14 ];
  3188. this.max.x = Math.max( xax, xbx ) + Math.max( yax, ybx ) + Math.max( zax, zbx ) + m[ 12 ];
  3189. this.max.y = Math.max( xay, xby ) + Math.max( yay, yby ) + Math.max( zay, zby ) + m[ 13 ];
  3190. this.max.z = Math.max( xaz, xbz ) + Math.max( yaz, ybz ) + Math.max( zaz, zbz ) + m[ 14 ];
  3191. return this;
  3192. },
  3193. translate: function ( offset ) {
  3194. this.min.add( offset );
  3195. this.max.add( offset );
  3196. return this;
  3197. },
  3198. equals: function ( box ) {
  3199. return box.min.equals( this.min ) && box.max.equals( this.max );
  3200. }
  3201. } );
  3202. /**
  3203. * @author bhouston / http://clara.io
  3204. * @author mrdoob / http://mrdoob.com/
  3205. */
  3206. function Sphere( center, radius ) {
  3207. this.center = ( center !== undefined ) ? center : new Vector3();
  3208. this.radius = ( radius !== undefined ) ? radius : 0;
  3209. }
  3210. Object.assign( Sphere.prototype, {
  3211. set: function ( center, radius ) {
  3212. this.center.copy( center );
  3213. this.radius = radius;
  3214. return this;
  3215. },
  3216. setFromPoints: function () {
  3217. var box = new Box3();
  3218. return function setFromPoints( points, optionalCenter ) {
  3219. var center = this.center;
  3220. if ( optionalCenter !== undefined ) {
  3221. center.copy( optionalCenter );
  3222. } else {
  3223. box.setFromPoints( points ).getCenter( center );
  3224. }
  3225. var maxRadiusSq = 0;
  3226. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3227. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3228. }
  3229. this.radius = Math.sqrt( maxRadiusSq );
  3230. return this;
  3231. };
  3232. }(),
  3233. clone: function () {
  3234. return new this.constructor().copy( this );
  3235. },
  3236. copy: function ( sphere ) {
  3237. this.center.copy( sphere.center );
  3238. this.radius = sphere.radius;
  3239. return this;
  3240. },
  3241. empty: function () {
  3242. return ( this.radius <= 0 );
  3243. },
  3244. containsPoint: function ( point ) {
  3245. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3246. },
  3247. distanceToPoint: function ( point ) {
  3248. return ( point.distanceTo( this.center ) - this.radius );
  3249. },
  3250. intersectsSphere: function ( sphere ) {
  3251. var radiusSum = this.radius + sphere.radius;
  3252. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3253. },
  3254. intersectsBox: function ( box ) {
  3255. return box.intersectsSphere( this );
  3256. },
  3257. intersectsPlane: function ( plane ) {
  3258. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3259. },
  3260. clampPoint: function ( point, target ) {
  3261. var deltaLengthSq = this.center.distanceToSquared( point );
  3262. if ( target === undefined ) {
  3263. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  3264. target = new Vector3();
  3265. }
  3266. target.copy( point );
  3267. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3268. target.sub( this.center ).normalize();
  3269. target.multiplyScalar( this.radius ).add( this.center );
  3270. }
  3271. return target;
  3272. },
  3273. getBoundingBox: function ( target ) {
  3274. if ( target === undefined ) {
  3275. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  3276. target = new Box3();
  3277. }
  3278. target.set( this.center, this.center );
  3279. target.expandByScalar( this.radius );
  3280. return target;
  3281. },
  3282. applyMatrix4: function ( matrix ) {
  3283. this.center.applyMatrix4( matrix );
  3284. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3285. return this;
  3286. },
  3287. translate: function ( offset ) {
  3288. this.center.add( offset );
  3289. return this;
  3290. },
  3291. equals: function ( sphere ) {
  3292. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3293. }
  3294. } );
  3295. /**
  3296. * @author bhouston / http://clara.io
  3297. */
  3298. function Plane( normal, constant ) {
  3299. // normal is assumed to be normalized
  3300. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  3301. this.constant = ( constant !== undefined ) ? constant : 0;
  3302. }
  3303. Object.assign( Plane.prototype, {
  3304. set: function ( normal, constant ) {
  3305. this.normal.copy( normal );
  3306. this.constant = constant;
  3307. return this;
  3308. },
  3309. setComponents: function ( x, y, z, w ) {
  3310. this.normal.set( x, y, z );
  3311. this.constant = w;
  3312. return this;
  3313. },
  3314. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3315. this.normal.copy( normal );
  3316. this.constant = - point.dot( this.normal );
  3317. return this;
  3318. },
  3319. setFromCoplanarPoints: function () {
  3320. var v1 = new Vector3();
  3321. var v2 = new Vector3();
  3322. return function setFromCoplanarPoints( a, b, c ) {
  3323. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3324. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3325. this.setFromNormalAndCoplanarPoint( normal, a );
  3326. return this;
  3327. };
  3328. }(),
  3329. clone: function () {
  3330. return new this.constructor().copy( this );
  3331. },
  3332. copy: function ( plane ) {
  3333. this.normal.copy( plane.normal );
  3334. this.constant = plane.constant;
  3335. return this;
  3336. },
  3337. normalize: function () {
  3338. // Note: will lead to a divide by zero if the plane is invalid.
  3339. var inverseNormalLength = 1.0 / this.normal.length();
  3340. this.normal.multiplyScalar( inverseNormalLength );
  3341. this.constant *= inverseNormalLength;
  3342. return this;
  3343. },
  3344. negate: function () {
  3345. this.constant *= - 1;
  3346. this.normal.negate();
  3347. return this;
  3348. },
  3349. distanceToPoint: function ( point ) {
  3350. return this.normal.dot( point ) + this.constant;
  3351. },
  3352. distanceToSphere: function ( sphere ) {
  3353. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3354. },
  3355. projectPoint: function ( point, target ) {
  3356. if ( target === undefined ) {
  3357. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  3358. target = new Vector3();
  3359. }
  3360. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  3361. },
  3362. intersectLine: function () {
  3363. var v1 = new Vector3();
  3364. return function intersectLine( line, target ) {
  3365. if ( target === undefined ) {
  3366. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  3367. target = new Vector3();
  3368. }
  3369. var direction = line.delta( v1 );
  3370. var denominator = this.normal.dot( direction );
  3371. if ( denominator === 0 ) {
  3372. // line is coplanar, return origin
  3373. if ( this.distanceToPoint( line.start ) === 0 ) {
  3374. return target.copy( line.start );
  3375. }
  3376. // Unsure if this is the correct method to handle this case.
  3377. return undefined;
  3378. }
  3379. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3380. if ( t < 0 || t > 1 ) {
  3381. return undefined;
  3382. }
  3383. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  3384. };
  3385. }(),
  3386. intersectsLine: function ( line ) {
  3387. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3388. var startSign = this.distanceToPoint( line.start );
  3389. var endSign = this.distanceToPoint( line.end );
  3390. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3391. },
  3392. intersectsBox: function ( box ) {
  3393. return box.intersectsPlane( this );
  3394. },
  3395. intersectsSphere: function ( sphere ) {
  3396. return sphere.intersectsPlane( this );
  3397. },
  3398. coplanarPoint: function ( target ) {
  3399. if ( target === undefined ) {
  3400. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  3401. target = new Vector3();
  3402. }
  3403. return target.copy( this.normal ).multiplyScalar( - this.constant );
  3404. },
  3405. applyMatrix4: function () {
  3406. var v1 = new Vector3();
  3407. var m1 = new Matrix3();
  3408. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  3409. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3410. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  3411. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  3412. this.constant = - referencePoint.dot( normal );
  3413. return this;
  3414. };
  3415. }(),
  3416. translate: function ( offset ) {
  3417. this.constant -= offset.dot( this.normal );
  3418. return this;
  3419. },
  3420. equals: function ( plane ) {
  3421. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3422. }
  3423. } );
  3424. /**
  3425. * @author mrdoob / http://mrdoob.com/
  3426. * @author alteredq / http://alteredqualia.com/
  3427. * @author bhouston / http://clara.io
  3428. */
  3429. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  3430. this.planes = [
  3431. ( p0 !== undefined ) ? p0 : new Plane(),
  3432. ( p1 !== undefined ) ? p1 : new Plane(),
  3433. ( p2 !== undefined ) ? p2 : new Plane(),
  3434. ( p3 !== undefined ) ? p3 : new Plane(),
  3435. ( p4 !== undefined ) ? p4 : new Plane(),
  3436. ( p5 !== undefined ) ? p5 : new Plane()
  3437. ];
  3438. }
  3439. Object.assign( Frustum.prototype, {
  3440. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3441. var planes = this.planes;
  3442. planes[ 0 ].copy( p0 );
  3443. planes[ 1 ].copy( p1 );
  3444. planes[ 2 ].copy( p2 );
  3445. planes[ 3 ].copy( p3 );
  3446. planes[ 4 ].copy( p4 );
  3447. planes[ 5 ].copy( p5 );
  3448. return this;
  3449. },
  3450. clone: function () {
  3451. return new this.constructor().copy( this );
  3452. },
  3453. copy: function ( frustum ) {
  3454. var planes = this.planes;
  3455. for ( var i = 0; i < 6; i ++ ) {
  3456. planes[ i ].copy( frustum.planes[ i ] );
  3457. }
  3458. return this;
  3459. },
  3460. setFromMatrix: function ( m ) {
  3461. var planes = this.planes;
  3462. var me = m.elements;
  3463. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3464. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3465. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3466. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3467. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3468. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3469. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3470. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3471. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3472. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3473. return this;
  3474. },
  3475. intersectsObject: function () {
  3476. var sphere = new Sphere();
  3477. return function intersectsObject( object ) {
  3478. var geometry = object.geometry;
  3479. if ( geometry.boundingSphere === null )
  3480. geometry.computeBoundingSphere();
  3481. sphere.copy( geometry.boundingSphere )
  3482. .applyMatrix4( object.matrixWorld );
  3483. return this.intersectsSphere( sphere );
  3484. };
  3485. }(),
  3486. intersectsSprite: function () {
  3487. var sphere = new Sphere();
  3488. return function intersectsSprite( sprite ) {
  3489. sphere.center.set( 0, 0, 0 );
  3490. sphere.radius = 0.7071067811865476;
  3491. sphere.applyMatrix4( sprite.matrixWorld );
  3492. return this.intersectsSphere( sphere );
  3493. };
  3494. }(),
  3495. intersectsSphere: function ( sphere ) {
  3496. var planes = this.planes;
  3497. var center = sphere.center;
  3498. var negRadius = - sphere.radius;
  3499. for ( var i = 0; i < 6; i ++ ) {
  3500. var distance = planes[ i ].distanceToPoint( center );
  3501. if ( distance < negRadius ) {
  3502. return false;
  3503. }
  3504. }
  3505. return true;
  3506. },
  3507. intersectsBox: function () {
  3508. var p1 = new Vector3(),
  3509. p2 = new Vector3();
  3510. return function intersectsBox( box ) {
  3511. var planes = this.planes;
  3512. for ( var i = 0; i < 6; i ++ ) {
  3513. var plane = planes[ i ];
  3514. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3515. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3516. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3517. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3518. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3519. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3520. var d1 = plane.distanceToPoint( p1 );
  3521. var d2 = plane.distanceToPoint( p2 );
  3522. // if both outside plane, no intersection
  3523. if ( d1 < 0 && d2 < 0 ) {
  3524. return false;
  3525. }
  3526. }
  3527. return true;
  3528. };
  3529. }(),
  3530. containsPoint: function ( point ) {
  3531. var planes = this.planes;
  3532. for ( var i = 0; i < 6; i ++ ) {
  3533. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3534. return false;
  3535. }
  3536. }
  3537. return true;
  3538. }
  3539. } );
  3540. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  3541. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif\n";
  3542. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  3543. 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";
  3544. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3545. var begin_vertex = "\nvec3 transformed = vec3( position );\n";
  3546. var beginnormal_vertex = "\nvec3 objectNormal = vec3( normal );\n";
  3547. 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 dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\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";
  3548. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif\n";
  3549. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\tif ( clipped ) discard;\n\t#endif\n#endif\n";
  3550. 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";
  3551. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvarying vec3 vViewPosition;\n#endif\n";
  3552. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n";
  3553. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3554. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif\n";
  3555. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3556. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3557. var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\n";
  3558. 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";
  3559. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n";
  3560. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif\n";
  3561. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  3562. 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";
  3563. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif\n";
  3564. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  3565. 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";
  3566. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\tvec2 sampleUV;\n\t\treflectVec = normalize( reflectVec );\n\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\n\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\tenvColor = envMapTexelToLinear( envColor );\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif\n";
  3567. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n\tuniform float reflectivity;\n\tuniform float envMapIntensity;\n#endif\n#ifdef USE_ENVMAP\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n\t\tvarying vec3 vWorldPosition;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif\n";
  3568. 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";
  3569. 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";
  3570. var fog_vertex = "\n#ifdef USE_FOG\nfogDepth = -mvPosition.z;\n#endif";
  3571. var fog_pars_vertex = "#ifdef USE_FOG\n varying float fogDepth;\n#endif\n";
  3572. 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";
  3573. 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";
  3574. 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";
  3575. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  3576. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3577. 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\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\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";
  3578. var lights_pars_begin = "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\tfloat shadowCameraNear;\n\t\tfloat shadowCameraFar;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif\n";
  3579. var lights_pars_maps = "#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 = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif\n";
  3580. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  3581. 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";
  3582. 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";
  3583. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos - halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos + halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos + halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos - halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\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";
  3584. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearCoatRadiance = vec3( 0.0 );\n#endif\n";
  3585. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), maxMipLevel );\n\t#ifndef STANDARD\n\t\tclearCoatRadiance += getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );\n\t#endif\n#endif\n";
  3586. var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif\n";
  3587. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3588. 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";
  3589. 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";
  3590. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t#else\n\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\tgl_Position.z *= gl_Position.w;\n\t#endif\n#endif\n";
  3591. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif\n";
  3592. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n";
  3593. var map_particle_fragment = "#ifdef USE_MAP\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n";
  3594. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif\n";
  3595. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif\n";
  3596. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3597. 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";
  3598. 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";
  3599. 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";
  3600. var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n#endif\n";
  3601. var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  3602. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy *= normalScale;\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif\n";
  3603. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}\n";
  3604. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  3605. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\n";
  3606. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif\n";
  3607. 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";
  3608. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif\n";
  3609. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3610. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif\n";
  3611. 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";
  3612. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif\n";
  3613. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#endif\n\t#endif\n\treturn shadow;\n}\n";
  3614. 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";
  3615. 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";
  3616. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif\n";
  3617. 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";
  3618. 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";
  3619. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3620. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  3621. var tonemapping_pars_fragment = "#ifndef saturate\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\n";
  3622. 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";
  3623. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\n";
  3624. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  3625. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3626. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3627. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3628. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif\n";
  3629. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\nvoid main() {\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n\tgl_FragColor.a *= opacity;\n}\n";
  3630. 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\tgl_Position.z = gl_Position.w;\n}\n";
  3631. var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - gl_FragCoord.z ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n\t#endif\n}\n";
  3632. var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n}\n";
  3633. var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}\n";
  3634. var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}\n";
  3635. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldPosition );\n\tvec2 sampleUV;\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n}\n";
  3636. 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";
  3637. 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";
  3638. 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";
  3639. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}\n";
  3640. 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";
  3641. 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_begin>\n#include <lights_pars_maps>\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 <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";
  3642. 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_begin>\n#include <lights_pars_maps>\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";
  3643. var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_pars_maps>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  3644. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3645. 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_begin>\n#include <lights_pars_maps>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  3646. 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 <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3647. 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_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}\n";
  3648. 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 <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}\n";
  3649. 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 <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";
  3650. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\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 <fog_vertex>\n}\n";
  3651. var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <fog_fragment>\n}\n";
  3652. var shadow_vert = "#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3653. var ShaderChunk = {
  3654. alphamap_fragment: alphamap_fragment,
  3655. alphamap_pars_fragment: alphamap_pars_fragment,
  3656. alphatest_fragment: alphatest_fragment,
  3657. aomap_fragment: aomap_fragment,
  3658. aomap_pars_fragment: aomap_pars_fragment,
  3659. begin_vertex: begin_vertex,
  3660. beginnormal_vertex: beginnormal_vertex,
  3661. bsdfs: bsdfs,
  3662. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3663. clipping_planes_fragment: clipping_planes_fragment,
  3664. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3665. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3666. clipping_planes_vertex: clipping_planes_vertex,
  3667. color_fragment: color_fragment,
  3668. color_pars_fragment: color_pars_fragment,
  3669. color_pars_vertex: color_pars_vertex,
  3670. color_vertex: color_vertex,
  3671. common: common,
  3672. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3673. defaultnormal_vertex: defaultnormal_vertex,
  3674. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3675. displacementmap_vertex: displacementmap_vertex,
  3676. emissivemap_fragment: emissivemap_fragment,
  3677. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3678. encodings_fragment: encodings_fragment,
  3679. encodings_pars_fragment: encodings_pars_fragment,
  3680. envmap_fragment: envmap_fragment,
  3681. envmap_pars_fragment: envmap_pars_fragment,
  3682. envmap_pars_vertex: envmap_pars_vertex,
  3683. envmap_vertex: envmap_vertex,
  3684. fog_vertex: fog_vertex,
  3685. fog_pars_vertex: fog_pars_vertex,
  3686. fog_fragment: fog_fragment,
  3687. fog_pars_fragment: fog_pars_fragment,
  3688. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3689. lightmap_fragment: lightmap_fragment,
  3690. lightmap_pars_fragment: lightmap_pars_fragment,
  3691. lights_lambert_vertex: lights_lambert_vertex,
  3692. lights_pars_begin: lights_pars_begin,
  3693. lights_pars_maps: lights_pars_maps,
  3694. lights_phong_fragment: lights_phong_fragment,
  3695. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3696. lights_physical_fragment: lights_physical_fragment,
  3697. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3698. lights_fragment_begin: lights_fragment_begin,
  3699. lights_fragment_maps: lights_fragment_maps,
  3700. lights_fragment_end: lights_fragment_end,
  3701. logdepthbuf_fragment: logdepthbuf_fragment,
  3702. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3703. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3704. logdepthbuf_vertex: logdepthbuf_vertex,
  3705. map_fragment: map_fragment,
  3706. map_pars_fragment: map_pars_fragment,
  3707. map_particle_fragment: map_particle_fragment,
  3708. map_particle_pars_fragment: map_particle_pars_fragment,
  3709. metalnessmap_fragment: metalnessmap_fragment,
  3710. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3711. morphnormal_vertex: morphnormal_vertex,
  3712. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3713. morphtarget_vertex: morphtarget_vertex,
  3714. normal_fragment_begin: normal_fragment_begin,
  3715. normal_fragment_maps: normal_fragment_maps,
  3716. normalmap_pars_fragment: normalmap_pars_fragment,
  3717. packing: packing,
  3718. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3719. project_vertex: project_vertex,
  3720. dithering_fragment: dithering_fragment,
  3721. dithering_pars_fragment: dithering_pars_fragment,
  3722. roughnessmap_fragment: roughnessmap_fragment,
  3723. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3724. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3725. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3726. shadowmap_vertex: shadowmap_vertex,
  3727. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3728. skinbase_vertex: skinbase_vertex,
  3729. skinning_pars_vertex: skinning_pars_vertex,
  3730. skinning_vertex: skinning_vertex,
  3731. skinnormal_vertex: skinnormal_vertex,
  3732. specularmap_fragment: specularmap_fragment,
  3733. specularmap_pars_fragment: specularmap_pars_fragment,
  3734. tonemapping_fragment: tonemapping_fragment,
  3735. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3736. uv_pars_fragment: uv_pars_fragment,
  3737. uv_pars_vertex: uv_pars_vertex,
  3738. uv_vertex: uv_vertex,
  3739. uv2_pars_fragment: uv2_pars_fragment,
  3740. uv2_pars_vertex: uv2_pars_vertex,
  3741. uv2_vertex: uv2_vertex,
  3742. worldpos_vertex: worldpos_vertex,
  3743. cube_frag: cube_frag,
  3744. cube_vert: cube_vert,
  3745. depth_frag: depth_frag,
  3746. depth_vert: depth_vert,
  3747. distanceRGBA_frag: distanceRGBA_frag,
  3748. distanceRGBA_vert: distanceRGBA_vert,
  3749. equirect_frag: equirect_frag,
  3750. equirect_vert: equirect_vert,
  3751. linedashed_frag: linedashed_frag,
  3752. linedashed_vert: linedashed_vert,
  3753. meshbasic_frag: meshbasic_frag,
  3754. meshbasic_vert: meshbasic_vert,
  3755. meshlambert_frag: meshlambert_frag,
  3756. meshlambert_vert: meshlambert_vert,
  3757. meshphong_frag: meshphong_frag,
  3758. meshphong_vert: meshphong_vert,
  3759. meshphysical_frag: meshphysical_frag,
  3760. meshphysical_vert: meshphysical_vert,
  3761. normal_frag: normal_frag,
  3762. normal_vert: normal_vert,
  3763. points_frag: points_frag,
  3764. points_vert: points_vert,
  3765. shadow_frag: shadow_frag,
  3766. shadow_vert: shadow_vert
  3767. };
  3768. /**
  3769. * Uniform Utilities
  3770. */
  3771. var UniformsUtils = {
  3772. merge: function ( uniforms ) {
  3773. var merged = {};
  3774. for ( var u = 0; u < uniforms.length; u ++ ) {
  3775. var tmp = this.clone( uniforms[ u ] );
  3776. for ( var p in tmp ) {
  3777. merged[ p ] = tmp[ p ];
  3778. }
  3779. }
  3780. return merged;
  3781. },
  3782. clone: function ( uniforms_src ) {
  3783. var uniforms_dst = {};
  3784. for ( var u in uniforms_src ) {
  3785. uniforms_dst[ u ] = {};
  3786. for ( var p in uniforms_src[ u ] ) {
  3787. var parameter_src = uniforms_src[ u ][ p ];
  3788. if ( parameter_src && ( parameter_src.isColor ||
  3789. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  3790. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  3791. parameter_src.isTexture ) ) {
  3792. uniforms_dst[ u ][ p ] = parameter_src.clone();
  3793. } else if ( Array.isArray( parameter_src ) ) {
  3794. uniforms_dst[ u ][ p ] = parameter_src.slice();
  3795. } else {
  3796. uniforms_dst[ u ][ p ] = parameter_src;
  3797. }
  3798. }
  3799. }
  3800. return uniforms_dst;
  3801. }
  3802. };
  3803. /**
  3804. * @author mrdoob / http://mrdoob.com/
  3805. */
  3806. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3807. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3808. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3809. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3810. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3811. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3812. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3813. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3814. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3815. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3816. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3817. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3818. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3819. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3820. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3821. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3822. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3823. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3824. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3825. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3826. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3827. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3828. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3829. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3830. function Color( r, g, b ) {
  3831. if ( g === undefined && b === undefined ) {
  3832. // r is THREE.Color, hex or string
  3833. return this.set( r );
  3834. }
  3835. return this.setRGB( r, g, b );
  3836. }
  3837. Object.assign( Color.prototype, {
  3838. isColor: true,
  3839. r: 1, g: 1, b: 1,
  3840. set: function ( value ) {
  3841. if ( value && value.isColor ) {
  3842. this.copy( value );
  3843. } else if ( typeof value === 'number' ) {
  3844. this.setHex( value );
  3845. } else if ( typeof value === 'string' ) {
  3846. this.setStyle( value );
  3847. }
  3848. return this;
  3849. },
  3850. setScalar: function ( scalar ) {
  3851. this.r = scalar;
  3852. this.g = scalar;
  3853. this.b = scalar;
  3854. return this;
  3855. },
  3856. setHex: function ( hex ) {
  3857. hex = Math.floor( hex );
  3858. this.r = ( hex >> 16 & 255 ) / 255;
  3859. this.g = ( hex >> 8 & 255 ) / 255;
  3860. this.b = ( hex & 255 ) / 255;
  3861. return this;
  3862. },
  3863. setRGB: function ( r, g, b ) {
  3864. this.r = r;
  3865. this.g = g;
  3866. this.b = b;
  3867. return this;
  3868. },
  3869. setHSL: function () {
  3870. function hue2rgb( p, q, t ) {
  3871. if ( t < 0 ) t += 1;
  3872. if ( t > 1 ) t -= 1;
  3873. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3874. if ( t < 1 / 2 ) return q;
  3875. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3876. return p;
  3877. }
  3878. return function setHSL( h, s, l ) {
  3879. // h,s,l ranges are in 0.0 - 1.0
  3880. h = _Math.euclideanModulo( h, 1 );
  3881. s = _Math.clamp( s, 0, 1 );
  3882. l = _Math.clamp( l, 0, 1 );
  3883. if ( s === 0 ) {
  3884. this.r = this.g = this.b = l;
  3885. } else {
  3886. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3887. var q = ( 2 * l ) - p;
  3888. this.r = hue2rgb( q, p, h + 1 / 3 );
  3889. this.g = hue2rgb( q, p, h );
  3890. this.b = hue2rgb( q, p, h - 1 / 3 );
  3891. }
  3892. return this;
  3893. };
  3894. }(),
  3895. setStyle: function ( style ) {
  3896. function handleAlpha( string ) {
  3897. if ( string === undefined ) return;
  3898. if ( parseFloat( string ) < 1 ) {
  3899. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3900. }
  3901. }
  3902. var m;
  3903. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3904. // rgb / hsl
  3905. var color;
  3906. var name = m[ 1 ];
  3907. var components = m[ 2 ];
  3908. switch ( name ) {
  3909. case 'rgb':
  3910. case 'rgba':
  3911. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3912. // rgb(255,0,0) rgba(255,0,0,0.5)
  3913. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3914. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3915. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3916. handleAlpha( color[ 5 ] );
  3917. return this;
  3918. }
  3919. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3920. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  3921. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  3922. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  3923. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  3924. handleAlpha( color[ 5 ] );
  3925. return this;
  3926. }
  3927. break;
  3928. case 'hsl':
  3929. case 'hsla':
  3930. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3931. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  3932. var h = parseFloat( color[ 1 ] ) / 360;
  3933. var s = parseInt( color[ 2 ], 10 ) / 100;
  3934. var l = parseInt( color[ 3 ], 10 ) / 100;
  3935. handleAlpha( color[ 5 ] );
  3936. return this.setHSL( h, s, l );
  3937. }
  3938. break;
  3939. }
  3940. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  3941. // hex color
  3942. var hex = m[ 1 ];
  3943. var size = hex.length;
  3944. if ( size === 3 ) {
  3945. // #ff0
  3946. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  3947. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  3948. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  3949. return this;
  3950. } else if ( size === 6 ) {
  3951. // #ff0000
  3952. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  3953. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  3954. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  3955. return this;
  3956. }
  3957. }
  3958. if ( style && style.length > 0 ) {
  3959. // color keywords
  3960. var hex = ColorKeywords[ style ];
  3961. if ( hex !== undefined ) {
  3962. // red
  3963. this.setHex( hex );
  3964. } else {
  3965. // unknown color
  3966. console.warn( 'THREE.Color: Unknown color ' + style );
  3967. }
  3968. }
  3969. return this;
  3970. },
  3971. clone: function () {
  3972. return new this.constructor( this.r, this.g, this.b );
  3973. },
  3974. copy: function ( color ) {
  3975. this.r = color.r;
  3976. this.g = color.g;
  3977. this.b = color.b;
  3978. return this;
  3979. },
  3980. copyGammaToLinear: function ( color, gammaFactor ) {
  3981. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3982. this.r = Math.pow( color.r, gammaFactor );
  3983. this.g = Math.pow( color.g, gammaFactor );
  3984. this.b = Math.pow( color.b, gammaFactor );
  3985. return this;
  3986. },
  3987. copyLinearToGamma: function ( color, gammaFactor ) {
  3988. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3989. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  3990. this.r = Math.pow( color.r, safeInverse );
  3991. this.g = Math.pow( color.g, safeInverse );
  3992. this.b = Math.pow( color.b, safeInverse );
  3993. return this;
  3994. },
  3995. convertGammaToLinear: function ( gammaFactor ) {
  3996. this.copyGammaToLinear( this, gammaFactor );
  3997. return this;
  3998. },
  3999. convertLinearToGamma: function ( gammaFactor ) {
  4000. this.copyLinearToGamma( this, gammaFactor );
  4001. return this;
  4002. },
  4003. getHex: function () {
  4004. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4005. },
  4006. getHexString: function () {
  4007. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4008. },
  4009. getHSL: function ( target ) {
  4010. // h,s,l ranges are in 0.0 - 1.0
  4011. if ( target === undefined ) {
  4012. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4013. target = { h: 0, s: 0, l: 0 };
  4014. }
  4015. var r = this.r, g = this.g, b = this.b;
  4016. var max = Math.max( r, g, b );
  4017. var min = Math.min( r, g, b );
  4018. var hue, saturation;
  4019. var lightness = ( min + max ) / 2.0;
  4020. if ( min === max ) {
  4021. hue = 0;
  4022. saturation = 0;
  4023. } else {
  4024. var delta = max - min;
  4025. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4026. switch ( max ) {
  4027. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4028. case g: hue = ( b - r ) / delta + 2; break;
  4029. case b: hue = ( r - g ) / delta + 4; break;
  4030. }
  4031. hue /= 6;
  4032. }
  4033. target.h = hue;
  4034. target.s = saturation;
  4035. target.l = lightness;
  4036. return target;
  4037. },
  4038. getStyle: function () {
  4039. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4040. },
  4041. offsetHSL: function () {
  4042. var hsl = {};
  4043. return function ( h, s, l ) {
  4044. this.getHSL( hsl );
  4045. hsl.h += h; hsl.s += s; hsl.l += l;
  4046. this.setHSL( hsl.h, hsl.s, hsl.l );
  4047. return this;
  4048. };
  4049. }(),
  4050. add: function ( color ) {
  4051. this.r += color.r;
  4052. this.g += color.g;
  4053. this.b += color.b;
  4054. return this;
  4055. },
  4056. addColors: function ( color1, color2 ) {
  4057. this.r = color1.r + color2.r;
  4058. this.g = color1.g + color2.g;
  4059. this.b = color1.b + color2.b;
  4060. return this;
  4061. },
  4062. addScalar: function ( s ) {
  4063. this.r += s;
  4064. this.g += s;
  4065. this.b += s;
  4066. return this;
  4067. },
  4068. sub: function ( color ) {
  4069. this.r = Math.max( 0, this.r - color.r );
  4070. this.g = Math.max( 0, this.g - color.g );
  4071. this.b = Math.max( 0, this.b - color.b );
  4072. return this;
  4073. },
  4074. multiply: function ( color ) {
  4075. this.r *= color.r;
  4076. this.g *= color.g;
  4077. this.b *= color.b;
  4078. return this;
  4079. },
  4080. multiplyScalar: function ( s ) {
  4081. this.r *= s;
  4082. this.g *= s;
  4083. this.b *= s;
  4084. return this;
  4085. },
  4086. lerp: function ( color, alpha ) {
  4087. this.r += ( color.r - this.r ) * alpha;
  4088. this.g += ( color.g - this.g ) * alpha;
  4089. this.b += ( color.b - this.b ) * alpha;
  4090. return this;
  4091. },
  4092. equals: function ( c ) {
  4093. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4094. },
  4095. fromArray: function ( array, offset ) {
  4096. if ( offset === undefined ) offset = 0;
  4097. this.r = array[ offset ];
  4098. this.g = array[ offset + 1 ];
  4099. this.b = array[ offset + 2 ];
  4100. return this;
  4101. },
  4102. toArray: function ( array, offset ) {
  4103. if ( array === undefined ) array = [];
  4104. if ( offset === undefined ) offset = 0;
  4105. array[ offset ] = this.r;
  4106. array[ offset + 1 ] = this.g;
  4107. array[ offset + 2 ] = this.b;
  4108. return array;
  4109. },
  4110. toJSON: function () {
  4111. return this.getHex();
  4112. }
  4113. } );
  4114. /**
  4115. * Uniforms library for shared webgl shaders
  4116. */
  4117. var UniformsLib = {
  4118. common: {
  4119. diffuse: { value: new Color( 0xeeeeee ) },
  4120. opacity: { value: 1.0 },
  4121. map: { value: null },
  4122. uvTransform: { value: new Matrix3() },
  4123. alphaMap: { value: null },
  4124. },
  4125. specularmap: {
  4126. specularMap: { value: null },
  4127. },
  4128. envmap: {
  4129. envMap: { value: null },
  4130. flipEnvMap: { value: - 1 },
  4131. reflectivity: { value: 1.0 },
  4132. refractionRatio: { value: 0.98 },
  4133. maxMipLevel: { value: 0 }
  4134. },
  4135. aomap: {
  4136. aoMap: { value: null },
  4137. aoMapIntensity: { value: 1 }
  4138. },
  4139. lightmap: {
  4140. lightMap: { value: null },
  4141. lightMapIntensity: { value: 1 }
  4142. },
  4143. emissivemap: {
  4144. emissiveMap: { value: null }
  4145. },
  4146. bumpmap: {
  4147. bumpMap: { value: null },
  4148. bumpScale: { value: 1 }
  4149. },
  4150. normalmap: {
  4151. normalMap: { value: null },
  4152. normalScale: { value: new Vector2( 1, 1 ) }
  4153. },
  4154. displacementmap: {
  4155. displacementMap: { value: null },
  4156. displacementScale: { value: 1 },
  4157. displacementBias: { value: 0 }
  4158. },
  4159. roughnessmap: {
  4160. roughnessMap: { value: null }
  4161. },
  4162. metalnessmap: {
  4163. metalnessMap: { value: null }
  4164. },
  4165. gradientmap: {
  4166. gradientMap: { value: null }
  4167. },
  4168. fog: {
  4169. fogDensity: { value: 0.00025 },
  4170. fogNear: { value: 1 },
  4171. fogFar: { value: 2000 },
  4172. fogColor: { value: new Color( 0xffffff ) }
  4173. },
  4174. lights: {
  4175. ambientLightColor: { value: [] },
  4176. directionalLights: { value: [], properties: {
  4177. direction: {},
  4178. color: {},
  4179. shadow: {},
  4180. shadowBias: {},
  4181. shadowRadius: {},
  4182. shadowMapSize: {}
  4183. } },
  4184. directionalShadowMap: { value: [] },
  4185. directionalShadowMatrix: { value: [] },
  4186. spotLights: { value: [], properties: {
  4187. color: {},
  4188. position: {},
  4189. direction: {},
  4190. distance: {},
  4191. coneCos: {},
  4192. penumbraCos: {},
  4193. decay: {},
  4194. shadow: {},
  4195. shadowBias: {},
  4196. shadowRadius: {},
  4197. shadowMapSize: {}
  4198. } },
  4199. spotShadowMap: { value: [] },
  4200. spotShadowMatrix: { value: [] },
  4201. pointLights: { value: [], properties: {
  4202. color: {},
  4203. position: {},
  4204. decay: {},
  4205. distance: {},
  4206. shadow: {},
  4207. shadowBias: {},
  4208. shadowRadius: {},
  4209. shadowMapSize: {},
  4210. shadowCameraNear: {},
  4211. shadowCameraFar: {}
  4212. } },
  4213. pointShadowMap: { value: [] },
  4214. pointShadowMatrix: { value: [] },
  4215. hemisphereLights: { value: [], properties: {
  4216. direction: {},
  4217. skyColor: {},
  4218. groundColor: {}
  4219. } },
  4220. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4221. rectAreaLights: { value: [], properties: {
  4222. color: {},
  4223. position: {},
  4224. width: {},
  4225. height: {}
  4226. } }
  4227. },
  4228. points: {
  4229. diffuse: { value: new Color( 0xeeeeee ) },
  4230. opacity: { value: 1.0 },
  4231. size: { value: 1.0 },
  4232. scale: { value: 1.0 },
  4233. map: { value: null },
  4234. uvTransform: { value: new Matrix3() }
  4235. }
  4236. };
  4237. /**
  4238. * @author alteredq / http://alteredqualia.com/
  4239. * @author mrdoob / http://mrdoob.com/
  4240. * @author mikael emtinger / http://gomo.se/
  4241. */
  4242. var ShaderLib = {
  4243. basic: {
  4244. uniforms: UniformsUtils.merge( [
  4245. UniformsLib.common,
  4246. UniformsLib.specularmap,
  4247. UniformsLib.envmap,
  4248. UniformsLib.aomap,
  4249. UniformsLib.lightmap,
  4250. UniformsLib.fog
  4251. ] ),
  4252. vertexShader: ShaderChunk.meshbasic_vert,
  4253. fragmentShader: ShaderChunk.meshbasic_frag
  4254. },
  4255. lambert: {
  4256. uniforms: UniformsUtils.merge( [
  4257. UniformsLib.common,
  4258. UniformsLib.specularmap,
  4259. UniformsLib.envmap,
  4260. UniformsLib.aomap,
  4261. UniformsLib.lightmap,
  4262. UniformsLib.emissivemap,
  4263. UniformsLib.fog,
  4264. UniformsLib.lights,
  4265. {
  4266. emissive: { value: new Color( 0x000000 ) }
  4267. }
  4268. ] ),
  4269. vertexShader: ShaderChunk.meshlambert_vert,
  4270. fragmentShader: ShaderChunk.meshlambert_frag
  4271. },
  4272. phong: {
  4273. uniforms: UniformsUtils.merge( [
  4274. UniformsLib.common,
  4275. UniformsLib.specularmap,
  4276. UniformsLib.envmap,
  4277. UniformsLib.aomap,
  4278. UniformsLib.lightmap,
  4279. UniformsLib.emissivemap,
  4280. UniformsLib.bumpmap,
  4281. UniformsLib.normalmap,
  4282. UniformsLib.displacementmap,
  4283. UniformsLib.gradientmap,
  4284. UniformsLib.fog,
  4285. UniformsLib.lights,
  4286. {
  4287. emissive: { value: new Color( 0x000000 ) },
  4288. specular: { value: new Color( 0x111111 ) },
  4289. shininess: { value: 30 }
  4290. }
  4291. ] ),
  4292. vertexShader: ShaderChunk.meshphong_vert,
  4293. fragmentShader: ShaderChunk.meshphong_frag
  4294. },
  4295. standard: {
  4296. uniforms: UniformsUtils.merge( [
  4297. UniformsLib.common,
  4298. UniformsLib.envmap,
  4299. UniformsLib.aomap,
  4300. UniformsLib.lightmap,
  4301. UniformsLib.emissivemap,
  4302. UniformsLib.bumpmap,
  4303. UniformsLib.normalmap,
  4304. UniformsLib.displacementmap,
  4305. UniformsLib.roughnessmap,
  4306. UniformsLib.metalnessmap,
  4307. UniformsLib.fog,
  4308. UniformsLib.lights,
  4309. {
  4310. emissive: { value: new Color( 0x000000 ) },
  4311. roughness: { value: 0.5 },
  4312. metalness: { value: 0.5 },
  4313. envMapIntensity: { value: 1 } // temporary
  4314. }
  4315. ] ),
  4316. vertexShader: ShaderChunk.meshphysical_vert,
  4317. fragmentShader: ShaderChunk.meshphysical_frag
  4318. },
  4319. points: {
  4320. uniforms: UniformsUtils.merge( [
  4321. UniformsLib.points,
  4322. UniformsLib.fog
  4323. ] ),
  4324. vertexShader: ShaderChunk.points_vert,
  4325. fragmentShader: ShaderChunk.points_frag
  4326. },
  4327. dashed: {
  4328. uniforms: UniformsUtils.merge( [
  4329. UniformsLib.common,
  4330. UniformsLib.fog,
  4331. {
  4332. scale: { value: 1 },
  4333. dashSize: { value: 1 },
  4334. totalSize: { value: 2 }
  4335. }
  4336. ] ),
  4337. vertexShader: ShaderChunk.linedashed_vert,
  4338. fragmentShader: ShaderChunk.linedashed_frag
  4339. },
  4340. depth: {
  4341. uniforms: UniformsUtils.merge( [
  4342. UniformsLib.common,
  4343. UniformsLib.displacementmap
  4344. ] ),
  4345. vertexShader: ShaderChunk.depth_vert,
  4346. fragmentShader: ShaderChunk.depth_frag
  4347. },
  4348. normal: {
  4349. uniforms: UniformsUtils.merge( [
  4350. UniformsLib.common,
  4351. UniformsLib.bumpmap,
  4352. UniformsLib.normalmap,
  4353. UniformsLib.displacementmap,
  4354. {
  4355. opacity: { value: 1.0 }
  4356. }
  4357. ] ),
  4358. vertexShader: ShaderChunk.normal_vert,
  4359. fragmentShader: ShaderChunk.normal_frag
  4360. },
  4361. /* -------------------------------------------------------------------------
  4362. // Cube map shader
  4363. ------------------------------------------------------------------------- */
  4364. cube: {
  4365. uniforms: {
  4366. tCube: { value: null },
  4367. tFlip: { value: - 1 },
  4368. opacity: { value: 1.0 }
  4369. },
  4370. vertexShader: ShaderChunk.cube_vert,
  4371. fragmentShader: ShaderChunk.cube_frag
  4372. },
  4373. equirect: {
  4374. uniforms: {
  4375. tEquirect: { value: null },
  4376. },
  4377. vertexShader: ShaderChunk.equirect_vert,
  4378. fragmentShader: ShaderChunk.equirect_frag
  4379. },
  4380. distanceRGBA: {
  4381. uniforms: UniformsUtils.merge( [
  4382. UniformsLib.common,
  4383. UniformsLib.displacementmap,
  4384. {
  4385. referencePosition: { value: new Vector3() },
  4386. nearDistance: { value: 1 },
  4387. farDistance: { value: 1000 }
  4388. }
  4389. ] ),
  4390. vertexShader: ShaderChunk.distanceRGBA_vert,
  4391. fragmentShader: ShaderChunk.distanceRGBA_frag
  4392. },
  4393. shadow: {
  4394. uniforms: UniformsUtils.merge( [
  4395. UniformsLib.lights,
  4396. UniformsLib.fog,
  4397. {
  4398. color: { value: new Color( 0x00000 ) },
  4399. opacity: { value: 1.0 }
  4400. },
  4401. ] ),
  4402. vertexShader: ShaderChunk.shadow_vert,
  4403. fragmentShader: ShaderChunk.shadow_frag
  4404. }
  4405. };
  4406. ShaderLib.physical = {
  4407. uniforms: UniformsUtils.merge( [
  4408. ShaderLib.standard.uniforms,
  4409. {
  4410. clearCoat: { value: 0 },
  4411. clearCoatRoughness: { value: 0 }
  4412. }
  4413. ] ),
  4414. vertexShader: ShaderChunk.meshphysical_vert,
  4415. fragmentShader: ShaderChunk.meshphysical_frag
  4416. };
  4417. /**
  4418. * @author mrdoob / http://mrdoob.com/
  4419. */
  4420. function WebGLAnimation() {
  4421. var context = null;
  4422. var isAnimating = false;
  4423. var animationLoop = null;
  4424. function onAnimationFrame( time, frame ) {
  4425. if ( isAnimating === false ) return;
  4426. animationLoop( time, frame );
  4427. context.requestAnimationFrame( onAnimationFrame );
  4428. }
  4429. return {
  4430. start: function () {
  4431. if ( isAnimating === true ) return;
  4432. if ( animationLoop === null ) return;
  4433. context.requestAnimationFrame( onAnimationFrame );
  4434. isAnimating = true;
  4435. },
  4436. stop: function () {
  4437. isAnimating = false;
  4438. },
  4439. setAnimationLoop: function ( callback ) {
  4440. animationLoop = callback;
  4441. },
  4442. setContext: function ( value ) {
  4443. context = value;
  4444. }
  4445. };
  4446. }
  4447. /**
  4448. * @author mrdoob / http://mrdoob.com/
  4449. */
  4450. function WebGLAttributes( gl ) {
  4451. var buffers = new WeakMap();
  4452. function createBuffer( attribute, bufferType ) {
  4453. var array = attribute.array;
  4454. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  4455. var buffer = gl.createBuffer();
  4456. gl.bindBuffer( bufferType, buffer );
  4457. gl.bufferData( bufferType, array, usage );
  4458. attribute.onUploadCallback();
  4459. var type = gl.FLOAT;
  4460. if ( array instanceof Float32Array ) {
  4461. type = gl.FLOAT;
  4462. } else if ( array instanceof Float64Array ) {
  4463. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4464. } else if ( array instanceof Uint16Array ) {
  4465. type = gl.UNSIGNED_SHORT;
  4466. } else if ( array instanceof Int16Array ) {
  4467. type = gl.SHORT;
  4468. } else if ( array instanceof Uint32Array ) {
  4469. type = gl.UNSIGNED_INT;
  4470. } else if ( array instanceof Int32Array ) {
  4471. type = gl.INT;
  4472. } else if ( array instanceof Int8Array ) {
  4473. type = gl.BYTE;
  4474. } else if ( array instanceof Uint8Array ) {
  4475. type = gl.UNSIGNED_BYTE;
  4476. }
  4477. return {
  4478. buffer: buffer,
  4479. type: type,
  4480. bytesPerElement: array.BYTES_PER_ELEMENT,
  4481. version: attribute.version
  4482. };
  4483. }
  4484. function updateBuffer( buffer, attribute, bufferType ) {
  4485. var array = attribute.array;
  4486. var updateRange = attribute.updateRange;
  4487. gl.bindBuffer( bufferType, buffer );
  4488. if ( attribute.dynamic === false ) {
  4489. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  4490. } else if ( updateRange.count === - 1 ) {
  4491. // Not using update ranges
  4492. gl.bufferSubData( bufferType, 0, array );
  4493. } else if ( updateRange.count === 0 ) {
  4494. 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.' );
  4495. } else {
  4496. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4497. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4498. updateRange.count = - 1; // reset range
  4499. }
  4500. }
  4501. //
  4502. function get( attribute ) {
  4503. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4504. return buffers.get( attribute );
  4505. }
  4506. function remove( attribute ) {
  4507. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4508. var data = buffers.get( attribute );
  4509. if ( data ) {
  4510. gl.deleteBuffer( data.buffer );
  4511. buffers.delete( attribute );
  4512. }
  4513. }
  4514. function update( attribute, bufferType ) {
  4515. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4516. var data = buffers.get( attribute );
  4517. if ( data === undefined ) {
  4518. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4519. } else if ( data.version < attribute.version ) {
  4520. updateBuffer( data.buffer, attribute, bufferType );
  4521. data.version = attribute.version;
  4522. }
  4523. }
  4524. return {
  4525. get: get,
  4526. remove: remove,
  4527. update: update
  4528. };
  4529. }
  4530. /**
  4531. * @author mrdoob / http://mrdoob.com/
  4532. * @author WestLangley / http://github.com/WestLangley
  4533. * @author bhouston / http://clara.io
  4534. */
  4535. function Euler( x, y, z, order ) {
  4536. this._x = x || 0;
  4537. this._y = y || 0;
  4538. this._z = z || 0;
  4539. this._order = order || Euler.DefaultOrder;
  4540. }
  4541. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4542. Euler.DefaultOrder = 'XYZ';
  4543. Object.defineProperties( Euler.prototype, {
  4544. x: {
  4545. get: function () {
  4546. return this._x;
  4547. },
  4548. set: function ( value ) {
  4549. this._x = value;
  4550. this.onChangeCallback();
  4551. }
  4552. },
  4553. y: {
  4554. get: function () {
  4555. return this._y;
  4556. },
  4557. set: function ( value ) {
  4558. this._y = value;
  4559. this.onChangeCallback();
  4560. }
  4561. },
  4562. z: {
  4563. get: function () {
  4564. return this._z;
  4565. },
  4566. set: function ( value ) {
  4567. this._z = value;
  4568. this.onChangeCallback();
  4569. }
  4570. },
  4571. order: {
  4572. get: function () {
  4573. return this._order;
  4574. },
  4575. set: function ( value ) {
  4576. this._order = value;
  4577. this.onChangeCallback();
  4578. }
  4579. }
  4580. } );
  4581. Object.assign( Euler.prototype, {
  4582. isEuler: true,
  4583. set: function ( x, y, z, order ) {
  4584. this._x = x;
  4585. this._y = y;
  4586. this._z = z;
  4587. this._order = order || this._order;
  4588. this.onChangeCallback();
  4589. return this;
  4590. },
  4591. clone: function () {
  4592. return new this.constructor( this._x, this._y, this._z, this._order );
  4593. },
  4594. copy: function ( euler ) {
  4595. this._x = euler._x;
  4596. this._y = euler._y;
  4597. this._z = euler._z;
  4598. this._order = euler._order;
  4599. this.onChangeCallback();
  4600. return this;
  4601. },
  4602. setFromRotationMatrix: function ( m, order, update ) {
  4603. var clamp = _Math.clamp;
  4604. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4605. var te = m.elements;
  4606. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4607. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4608. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4609. order = order || this._order;
  4610. if ( order === 'XYZ' ) {
  4611. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4612. if ( Math.abs( m13 ) < 0.99999 ) {
  4613. this._x = Math.atan2( - m23, m33 );
  4614. this._z = Math.atan2( - m12, m11 );
  4615. } else {
  4616. this._x = Math.atan2( m32, m22 );
  4617. this._z = 0;
  4618. }
  4619. } else if ( order === 'YXZ' ) {
  4620. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4621. if ( Math.abs( m23 ) < 0.99999 ) {
  4622. this._y = Math.atan2( m13, m33 );
  4623. this._z = Math.atan2( m21, m22 );
  4624. } else {
  4625. this._y = Math.atan2( - m31, m11 );
  4626. this._z = 0;
  4627. }
  4628. } else if ( order === 'ZXY' ) {
  4629. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4630. if ( Math.abs( m32 ) < 0.99999 ) {
  4631. this._y = Math.atan2( - m31, m33 );
  4632. this._z = Math.atan2( - m12, m22 );
  4633. } else {
  4634. this._y = 0;
  4635. this._z = Math.atan2( m21, m11 );
  4636. }
  4637. } else if ( order === 'ZYX' ) {
  4638. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4639. if ( Math.abs( m31 ) < 0.99999 ) {
  4640. this._x = Math.atan2( m32, m33 );
  4641. this._z = Math.atan2( m21, m11 );
  4642. } else {
  4643. this._x = 0;
  4644. this._z = Math.atan2( - m12, m22 );
  4645. }
  4646. } else if ( order === 'YZX' ) {
  4647. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4648. if ( Math.abs( m21 ) < 0.99999 ) {
  4649. this._x = Math.atan2( - m23, m22 );
  4650. this._y = Math.atan2( - m31, m11 );
  4651. } else {
  4652. this._x = 0;
  4653. this._y = Math.atan2( m13, m33 );
  4654. }
  4655. } else if ( order === 'XZY' ) {
  4656. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4657. if ( Math.abs( m12 ) < 0.99999 ) {
  4658. this._x = Math.atan2( m32, m22 );
  4659. this._y = Math.atan2( m13, m11 );
  4660. } else {
  4661. this._x = Math.atan2( - m23, m33 );
  4662. this._y = 0;
  4663. }
  4664. } else {
  4665. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4666. }
  4667. this._order = order;
  4668. if ( update !== false ) this.onChangeCallback();
  4669. return this;
  4670. },
  4671. setFromQuaternion: function () {
  4672. var matrix = new Matrix4();
  4673. return function setFromQuaternion( q, order, update ) {
  4674. matrix.makeRotationFromQuaternion( q );
  4675. return this.setFromRotationMatrix( matrix, order, update );
  4676. };
  4677. }(),
  4678. setFromVector3: function ( v, order ) {
  4679. return this.set( v.x, v.y, v.z, order || this._order );
  4680. },
  4681. reorder: function () {
  4682. // WARNING: this discards revolution information -bhouston
  4683. var q = new Quaternion();
  4684. return function reorder( newOrder ) {
  4685. q.setFromEuler( this );
  4686. return this.setFromQuaternion( q, newOrder );
  4687. };
  4688. }(),
  4689. equals: function ( euler ) {
  4690. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4691. },
  4692. fromArray: function ( array ) {
  4693. this._x = array[ 0 ];
  4694. this._y = array[ 1 ];
  4695. this._z = array[ 2 ];
  4696. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4697. this.onChangeCallback();
  4698. return this;
  4699. },
  4700. toArray: function ( array, offset ) {
  4701. if ( array === undefined ) array = [];
  4702. if ( offset === undefined ) offset = 0;
  4703. array[ offset ] = this._x;
  4704. array[ offset + 1 ] = this._y;
  4705. array[ offset + 2 ] = this._z;
  4706. array[ offset + 3 ] = this._order;
  4707. return array;
  4708. },
  4709. toVector3: function ( optionalResult ) {
  4710. if ( optionalResult ) {
  4711. return optionalResult.set( this._x, this._y, this._z );
  4712. } else {
  4713. return new Vector3( this._x, this._y, this._z );
  4714. }
  4715. },
  4716. onChange: function ( callback ) {
  4717. this.onChangeCallback = callback;
  4718. return this;
  4719. },
  4720. onChangeCallback: function () {}
  4721. } );
  4722. /**
  4723. * @author mrdoob / http://mrdoob.com/
  4724. */
  4725. function Layers() {
  4726. this.mask = 1 | 0;
  4727. }
  4728. Object.assign( Layers.prototype, {
  4729. set: function ( channel ) {
  4730. this.mask = 1 << channel | 0;
  4731. },
  4732. enable: function ( channel ) {
  4733. this.mask |= 1 << channel | 0;
  4734. },
  4735. toggle: function ( channel ) {
  4736. this.mask ^= 1 << channel | 0;
  4737. },
  4738. disable: function ( channel ) {
  4739. this.mask &= ~ ( 1 << channel | 0 );
  4740. },
  4741. test: function ( layers ) {
  4742. return ( this.mask & layers.mask ) !== 0;
  4743. }
  4744. } );
  4745. /**
  4746. * @author mrdoob / http://mrdoob.com/
  4747. * @author mikael emtinger / http://gomo.se/
  4748. * @author alteredq / http://alteredqualia.com/
  4749. * @author WestLangley / http://github.com/WestLangley
  4750. * @author elephantatwork / www.elephantatwork.ch
  4751. */
  4752. var object3DId = 0;
  4753. function Object3D() {
  4754. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4755. this.uuid = _Math.generateUUID();
  4756. this.name = '';
  4757. this.type = 'Object3D';
  4758. this.parent = null;
  4759. this.children = [];
  4760. this.up = Object3D.DefaultUp.clone();
  4761. var position = new Vector3();
  4762. var rotation = new Euler();
  4763. var quaternion = new Quaternion();
  4764. var scale = new Vector3( 1, 1, 1 );
  4765. function onRotationChange() {
  4766. quaternion.setFromEuler( rotation, false );
  4767. }
  4768. function onQuaternionChange() {
  4769. rotation.setFromQuaternion( quaternion, undefined, false );
  4770. }
  4771. rotation.onChange( onRotationChange );
  4772. quaternion.onChange( onQuaternionChange );
  4773. Object.defineProperties( this, {
  4774. position: {
  4775. enumerable: true,
  4776. value: position
  4777. },
  4778. rotation: {
  4779. enumerable: true,
  4780. value: rotation
  4781. },
  4782. quaternion: {
  4783. enumerable: true,
  4784. value: quaternion
  4785. },
  4786. scale: {
  4787. enumerable: true,
  4788. value: scale
  4789. },
  4790. modelViewMatrix: {
  4791. value: new Matrix4()
  4792. },
  4793. normalMatrix: {
  4794. value: new Matrix3()
  4795. }
  4796. } );
  4797. this.matrix = new Matrix4();
  4798. this.matrixWorld = new Matrix4();
  4799. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4800. this.matrixWorldNeedsUpdate = false;
  4801. this.layers = new Layers();
  4802. this.visible = true;
  4803. this.castShadow = false;
  4804. this.receiveShadow = false;
  4805. this.frustumCulled = true;
  4806. this.renderOrder = 0;
  4807. this.userData = {};
  4808. }
  4809. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  4810. Object3D.DefaultMatrixAutoUpdate = true;
  4811. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  4812. constructor: Object3D,
  4813. isObject3D: true,
  4814. onBeforeRender: function () {},
  4815. onAfterRender: function () {},
  4816. applyMatrix: function ( matrix ) {
  4817. this.matrix.multiplyMatrices( matrix, this.matrix );
  4818. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4819. },
  4820. applyQuaternion: function ( q ) {
  4821. this.quaternion.premultiply( q );
  4822. return this;
  4823. },
  4824. setRotationFromAxisAngle: function ( axis, angle ) {
  4825. // assumes axis is normalized
  4826. this.quaternion.setFromAxisAngle( axis, angle );
  4827. },
  4828. setRotationFromEuler: function ( euler ) {
  4829. this.quaternion.setFromEuler( euler, true );
  4830. },
  4831. setRotationFromMatrix: function ( m ) {
  4832. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4833. this.quaternion.setFromRotationMatrix( m );
  4834. },
  4835. setRotationFromQuaternion: function ( q ) {
  4836. // assumes q is normalized
  4837. this.quaternion.copy( q );
  4838. },
  4839. rotateOnAxis: function () {
  4840. // rotate object on axis in object space
  4841. // axis is assumed to be normalized
  4842. var q1 = new Quaternion();
  4843. return function rotateOnAxis( axis, angle ) {
  4844. q1.setFromAxisAngle( axis, angle );
  4845. this.quaternion.multiply( q1 );
  4846. return this;
  4847. };
  4848. }(),
  4849. rotateOnWorldAxis: function () {
  4850. // rotate object on axis in world space
  4851. // axis is assumed to be normalized
  4852. // method assumes no rotated parent
  4853. var q1 = new Quaternion();
  4854. return function rotateOnWorldAxis( axis, angle ) {
  4855. q1.setFromAxisAngle( axis, angle );
  4856. this.quaternion.premultiply( q1 );
  4857. return this;
  4858. };
  4859. }(),
  4860. rotateX: function () {
  4861. var v1 = new Vector3( 1, 0, 0 );
  4862. return function rotateX( angle ) {
  4863. return this.rotateOnAxis( v1, angle );
  4864. };
  4865. }(),
  4866. rotateY: function () {
  4867. var v1 = new Vector3( 0, 1, 0 );
  4868. return function rotateY( angle ) {
  4869. return this.rotateOnAxis( v1, angle );
  4870. };
  4871. }(),
  4872. rotateZ: function () {
  4873. var v1 = new Vector3( 0, 0, 1 );
  4874. return function rotateZ( angle ) {
  4875. return this.rotateOnAxis( v1, angle );
  4876. };
  4877. }(),
  4878. translateOnAxis: function () {
  4879. // translate object by distance along axis in object space
  4880. // axis is assumed to be normalized
  4881. var v1 = new Vector3();
  4882. return function translateOnAxis( axis, distance ) {
  4883. v1.copy( axis ).applyQuaternion( this.quaternion );
  4884. this.position.add( v1.multiplyScalar( distance ) );
  4885. return this;
  4886. };
  4887. }(),
  4888. translateX: function () {
  4889. var v1 = new Vector3( 1, 0, 0 );
  4890. return function translateX( distance ) {
  4891. return this.translateOnAxis( v1, distance );
  4892. };
  4893. }(),
  4894. translateY: function () {
  4895. var v1 = new Vector3( 0, 1, 0 );
  4896. return function translateY( distance ) {
  4897. return this.translateOnAxis( v1, distance );
  4898. };
  4899. }(),
  4900. translateZ: function () {
  4901. var v1 = new Vector3( 0, 0, 1 );
  4902. return function translateZ( distance ) {
  4903. return this.translateOnAxis( v1, distance );
  4904. };
  4905. }(),
  4906. localToWorld: function ( vector ) {
  4907. return vector.applyMatrix4( this.matrixWorld );
  4908. },
  4909. worldToLocal: function () {
  4910. var m1 = new Matrix4();
  4911. return function worldToLocal( vector ) {
  4912. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4913. };
  4914. }(),
  4915. lookAt: function () {
  4916. // This method does not support objects with rotated and/or translated parent(s)
  4917. var m1 = new Matrix4();
  4918. var vector = new Vector3();
  4919. return function lookAt( x, y, z ) {
  4920. if ( x.isVector3 ) {
  4921. vector.copy( x );
  4922. } else {
  4923. vector.set( x, y, z );
  4924. }
  4925. if ( this.isCamera ) {
  4926. m1.lookAt( this.position, vector, this.up );
  4927. } else {
  4928. m1.lookAt( vector, this.position, this.up );
  4929. }
  4930. this.quaternion.setFromRotationMatrix( m1 );
  4931. };
  4932. }(),
  4933. add: function ( object ) {
  4934. if ( arguments.length > 1 ) {
  4935. for ( var i = 0; i < arguments.length; i ++ ) {
  4936. this.add( arguments[ i ] );
  4937. }
  4938. return this;
  4939. }
  4940. if ( object === this ) {
  4941. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4942. return this;
  4943. }
  4944. if ( ( object && object.isObject3D ) ) {
  4945. if ( object.parent !== null ) {
  4946. object.parent.remove( object );
  4947. }
  4948. object.parent = this;
  4949. object.dispatchEvent( { type: 'added' } );
  4950. this.children.push( object );
  4951. } else {
  4952. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4953. }
  4954. return this;
  4955. },
  4956. remove: function ( object ) {
  4957. if ( arguments.length > 1 ) {
  4958. for ( var i = 0; i < arguments.length; i ++ ) {
  4959. this.remove( arguments[ i ] );
  4960. }
  4961. return this;
  4962. }
  4963. var index = this.children.indexOf( object );
  4964. if ( index !== - 1 ) {
  4965. object.parent = null;
  4966. object.dispatchEvent( { type: 'removed' } );
  4967. this.children.splice( index, 1 );
  4968. }
  4969. return this;
  4970. },
  4971. getObjectById: function ( id ) {
  4972. return this.getObjectByProperty( 'id', id );
  4973. },
  4974. getObjectByName: function ( name ) {
  4975. return this.getObjectByProperty( 'name', name );
  4976. },
  4977. getObjectByProperty: function ( name, value ) {
  4978. if ( this[ name ] === value ) return this;
  4979. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4980. var child = this.children[ i ];
  4981. var object = child.getObjectByProperty( name, value );
  4982. if ( object !== undefined ) {
  4983. return object;
  4984. }
  4985. }
  4986. return undefined;
  4987. },
  4988. getWorldPosition: function ( target ) {
  4989. if ( target === undefined ) {
  4990. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  4991. target = new Vector3();
  4992. }
  4993. this.updateMatrixWorld( true );
  4994. return target.setFromMatrixPosition( this.matrixWorld );
  4995. },
  4996. getWorldQuaternion: function () {
  4997. var position = new Vector3();
  4998. var scale = new Vector3();
  4999. return function getWorldQuaternion( target ) {
  5000. if ( target === undefined ) {
  5001. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5002. target = new Quaternion();
  5003. }
  5004. this.updateMatrixWorld( true );
  5005. this.matrixWorld.decompose( position, target, scale );
  5006. return target;
  5007. };
  5008. }(),
  5009. getWorldScale: function () {
  5010. var position = new Vector3();
  5011. var quaternion = new Quaternion();
  5012. return function getWorldScale( target ) {
  5013. if ( target === undefined ) {
  5014. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5015. target = new Vector3();
  5016. }
  5017. this.updateMatrixWorld( true );
  5018. this.matrixWorld.decompose( position, quaternion, target );
  5019. return target;
  5020. };
  5021. }(),
  5022. getWorldDirection: function () {
  5023. var quaternion = new Quaternion();
  5024. return function getWorldDirection( target ) {
  5025. if ( target === undefined ) {
  5026. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5027. target = new Vector3();
  5028. }
  5029. this.getWorldQuaternion( quaternion );
  5030. return target.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5031. };
  5032. }(),
  5033. raycast: function () {},
  5034. traverse: function ( callback ) {
  5035. callback( this );
  5036. var children = this.children;
  5037. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5038. children[ i ].traverse( callback );
  5039. }
  5040. },
  5041. traverseVisible: function ( callback ) {
  5042. if ( this.visible === false ) return;
  5043. callback( this );
  5044. var children = this.children;
  5045. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5046. children[ i ].traverseVisible( callback );
  5047. }
  5048. },
  5049. traverseAncestors: function ( callback ) {
  5050. var parent = this.parent;
  5051. if ( parent !== null ) {
  5052. callback( parent );
  5053. parent.traverseAncestors( callback );
  5054. }
  5055. },
  5056. updateMatrix: function () {
  5057. this.matrix.compose( this.position, this.quaternion, this.scale );
  5058. this.matrixWorldNeedsUpdate = true;
  5059. },
  5060. updateMatrixWorld: function ( force ) {
  5061. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5062. if ( this.matrixWorldNeedsUpdate || force ) {
  5063. if ( this.parent === null ) {
  5064. this.matrixWorld.copy( this.matrix );
  5065. } else {
  5066. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5067. }
  5068. this.matrixWorldNeedsUpdate = false;
  5069. force = true;
  5070. }
  5071. // update children
  5072. var children = this.children;
  5073. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5074. children[ i ].updateMatrixWorld( force );
  5075. }
  5076. },
  5077. toJSON: function ( meta ) {
  5078. // meta is a string when called from JSON.stringify
  5079. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5080. var output = {};
  5081. // meta is a hash used to collect geometries, materials.
  5082. // not providing it implies that this is the root object
  5083. // being serialized.
  5084. if ( isRootObject ) {
  5085. // initialize meta obj
  5086. meta = {
  5087. geometries: {},
  5088. materials: {},
  5089. textures: {},
  5090. images: {},
  5091. shapes: {}
  5092. };
  5093. output.metadata = {
  5094. version: 4.5,
  5095. type: 'Object',
  5096. generator: 'Object3D.toJSON'
  5097. };
  5098. }
  5099. // standard Object3D serialization
  5100. var object = {};
  5101. object.uuid = this.uuid;
  5102. object.type = this.type;
  5103. if ( this.name !== '' ) object.name = this.name;
  5104. if ( this.castShadow === true ) object.castShadow = true;
  5105. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5106. if ( this.visible === false ) object.visible = false;
  5107. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5108. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5109. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5110. object.matrix = this.matrix.toArray();
  5111. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5112. //
  5113. function serialize( library, element ) {
  5114. if ( library[ element.uuid ] === undefined ) {
  5115. library[ element.uuid ] = element.toJSON( meta );
  5116. }
  5117. return element.uuid;
  5118. }
  5119. if ( this.geometry !== undefined ) {
  5120. object.geometry = serialize( meta.geometries, this.geometry );
  5121. var parameters = this.geometry.parameters;
  5122. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5123. var shapes = parameters.shapes;
  5124. if ( Array.isArray( shapes ) ) {
  5125. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5126. var shape = shapes[ i ];
  5127. serialize( meta.shapes, shape );
  5128. }
  5129. } else {
  5130. serialize( meta.shapes, shapes );
  5131. }
  5132. }
  5133. }
  5134. if ( this.material !== undefined ) {
  5135. if ( Array.isArray( this.material ) ) {
  5136. var uuids = [];
  5137. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5138. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5139. }
  5140. object.material = uuids;
  5141. } else {
  5142. object.material = serialize( meta.materials, this.material );
  5143. }
  5144. }
  5145. //
  5146. if ( this.children.length > 0 ) {
  5147. object.children = [];
  5148. for ( var i = 0; i < this.children.length; i ++ ) {
  5149. object.children.push( this.children[ i ].toJSON( meta ).object );
  5150. }
  5151. }
  5152. if ( isRootObject ) {
  5153. var geometries = extractFromCache( meta.geometries );
  5154. var materials = extractFromCache( meta.materials );
  5155. var textures = extractFromCache( meta.textures );
  5156. var images = extractFromCache( meta.images );
  5157. var shapes = extractFromCache( meta.shapes );
  5158. if ( geometries.length > 0 ) output.geometries = geometries;
  5159. if ( materials.length > 0 ) output.materials = materials;
  5160. if ( textures.length > 0 ) output.textures = textures;
  5161. if ( images.length > 0 ) output.images = images;
  5162. if ( shapes.length > 0 ) output.shapes = shapes;
  5163. }
  5164. output.object = object;
  5165. return output;
  5166. // extract data from the cache hash
  5167. // remove metadata on each item
  5168. // and return as array
  5169. function extractFromCache( cache ) {
  5170. var values = [];
  5171. for ( var key in cache ) {
  5172. var data = cache[ key ];
  5173. delete data.metadata;
  5174. values.push( data );
  5175. }
  5176. return values;
  5177. }
  5178. },
  5179. clone: function ( recursive ) {
  5180. return new this.constructor().copy( this, recursive );
  5181. },
  5182. copy: function ( source, recursive ) {
  5183. if ( recursive === undefined ) recursive = true;
  5184. this.name = source.name;
  5185. this.up.copy( source.up );
  5186. this.position.copy( source.position );
  5187. this.quaternion.copy( source.quaternion );
  5188. this.scale.copy( source.scale );
  5189. this.matrix.copy( source.matrix );
  5190. this.matrixWorld.copy( source.matrixWorld );
  5191. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5192. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5193. this.layers.mask = source.layers.mask;
  5194. this.visible = source.visible;
  5195. this.castShadow = source.castShadow;
  5196. this.receiveShadow = source.receiveShadow;
  5197. this.frustumCulled = source.frustumCulled;
  5198. this.renderOrder = source.renderOrder;
  5199. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5200. if ( recursive === true ) {
  5201. for ( var i = 0; i < source.children.length; i ++ ) {
  5202. var child = source.children[ i ];
  5203. this.add( child.clone() );
  5204. }
  5205. }
  5206. return this;
  5207. }
  5208. } );
  5209. /**
  5210. * @author mrdoob / http://mrdoob.com/
  5211. * @author mikael emtinger / http://gomo.se/
  5212. * @author WestLangley / http://github.com/WestLangley
  5213. */
  5214. function Camera() {
  5215. Object3D.call( this );
  5216. this.type = 'Camera';
  5217. this.matrixWorldInverse = new Matrix4();
  5218. this.projectionMatrix = new Matrix4();
  5219. }
  5220. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  5221. constructor: Camera,
  5222. isCamera: true,
  5223. copy: function ( source, recursive ) {
  5224. Object3D.prototype.copy.call( this, source, recursive );
  5225. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  5226. this.projectionMatrix.copy( source.projectionMatrix );
  5227. return this;
  5228. },
  5229. getWorldDirection: function () {
  5230. var quaternion = new Quaternion();
  5231. return function getWorldDirection( target ) {
  5232. if ( target === undefined ) {
  5233. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  5234. target = new Vector3();
  5235. }
  5236. this.getWorldQuaternion( quaternion );
  5237. return target.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  5238. };
  5239. }(),
  5240. updateMatrixWorld: function ( force ) {
  5241. Object3D.prototype.updateMatrixWorld.call( this, force );
  5242. this.matrixWorldInverse.getInverse( this.matrixWorld );
  5243. },
  5244. clone: function () {
  5245. return new this.constructor().copy( this );
  5246. }
  5247. } );
  5248. /**
  5249. * @author alteredq / http://alteredqualia.com/
  5250. * @author arose / http://github.com/arose
  5251. */
  5252. function OrthographicCamera( left, right, top, bottom, near, far ) {
  5253. Camera.call( this );
  5254. this.type = 'OrthographicCamera';
  5255. this.zoom = 1;
  5256. this.view = null;
  5257. this.left = left;
  5258. this.right = right;
  5259. this.top = top;
  5260. this.bottom = bottom;
  5261. this.near = ( near !== undefined ) ? near : 0.1;
  5262. this.far = ( far !== undefined ) ? far : 2000;
  5263. this.updateProjectionMatrix();
  5264. }
  5265. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  5266. constructor: OrthographicCamera,
  5267. isOrthographicCamera: true,
  5268. copy: function ( source, recursive ) {
  5269. Camera.prototype.copy.call( this, source, recursive );
  5270. this.left = source.left;
  5271. this.right = source.right;
  5272. this.top = source.top;
  5273. this.bottom = source.bottom;
  5274. this.near = source.near;
  5275. this.far = source.far;
  5276. this.zoom = source.zoom;
  5277. this.view = source.view === null ? null : Object.assign( {}, source.view );
  5278. return this;
  5279. },
  5280. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  5281. if ( this.view === null ) {
  5282. this.view = {
  5283. enabled: true,
  5284. fullWidth: 1,
  5285. fullHeight: 1,
  5286. offsetX: 0,
  5287. offsetY: 0,
  5288. width: 1,
  5289. height: 1
  5290. };
  5291. }
  5292. this.view.enabled = true;
  5293. this.view.fullWidth = fullWidth;
  5294. this.view.fullHeight = fullHeight;
  5295. this.view.offsetX = x;
  5296. this.view.offsetY = y;
  5297. this.view.width = width;
  5298. this.view.height = height;
  5299. this.updateProjectionMatrix();
  5300. },
  5301. clearViewOffset: function () {
  5302. if ( this.view !== null ) {
  5303. this.view.enabled = false;
  5304. }
  5305. this.updateProjectionMatrix();
  5306. },
  5307. updateProjectionMatrix: function () {
  5308. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  5309. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  5310. var cx = ( this.right + this.left ) / 2;
  5311. var cy = ( this.top + this.bottom ) / 2;
  5312. var left = cx - dx;
  5313. var right = cx + dx;
  5314. var top = cy + dy;
  5315. var bottom = cy - dy;
  5316. if ( this.view !== null && this.view.enabled ) {
  5317. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  5318. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  5319. var scaleW = ( this.right - this.left ) / this.view.width;
  5320. var scaleH = ( this.top - this.bottom ) / this.view.height;
  5321. left += scaleW * ( this.view.offsetX / zoomW );
  5322. right = left + scaleW * ( this.view.width / zoomW );
  5323. top -= scaleH * ( this.view.offsetY / zoomH );
  5324. bottom = top - scaleH * ( this.view.height / zoomH );
  5325. }
  5326. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  5327. },
  5328. toJSON: function ( meta ) {
  5329. var data = Object3D.prototype.toJSON.call( this, meta );
  5330. data.object.zoom = this.zoom;
  5331. data.object.left = this.left;
  5332. data.object.right = this.right;
  5333. data.object.top = this.top;
  5334. data.object.bottom = this.bottom;
  5335. data.object.near = this.near;
  5336. data.object.far = this.far;
  5337. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  5338. return data;
  5339. }
  5340. } );
  5341. /**
  5342. * @author mrdoob / http://mrdoob.com/
  5343. * @author alteredq / http://alteredqualia.com/
  5344. */
  5345. function Face3( a, b, c, normal, color, materialIndex ) {
  5346. this.a = a;
  5347. this.b = b;
  5348. this.c = c;
  5349. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5350. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5351. this.color = ( color && color.isColor ) ? color : new Color();
  5352. this.vertexColors = Array.isArray( color ) ? color : [];
  5353. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5354. }
  5355. Object.assign( Face3.prototype, {
  5356. clone: function () {
  5357. return new this.constructor().copy( this );
  5358. },
  5359. copy: function ( source ) {
  5360. this.a = source.a;
  5361. this.b = source.b;
  5362. this.c = source.c;
  5363. this.normal.copy( source.normal );
  5364. this.color.copy( source.color );
  5365. this.materialIndex = source.materialIndex;
  5366. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5367. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5368. }
  5369. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5370. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5371. }
  5372. return this;
  5373. }
  5374. } );
  5375. /**
  5376. * @author mrdoob / http://mrdoob.com/
  5377. * @author kile / http://kile.stravaganza.org/
  5378. * @author alteredq / http://alteredqualia.com/
  5379. * @author mikael emtinger / http://gomo.se/
  5380. * @author zz85 / http://www.lab4games.net/zz85/blog
  5381. * @author bhouston / http://clara.io
  5382. */
  5383. var geometryId = 0; // Geometry uses even numbers as Id
  5384. function Geometry() {
  5385. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5386. this.uuid = _Math.generateUUID();
  5387. this.name = '';
  5388. this.type = 'Geometry';
  5389. this.vertices = [];
  5390. this.colors = [];
  5391. this.faces = [];
  5392. this.faceVertexUvs = [[]];
  5393. this.morphTargets = [];
  5394. this.morphNormals = [];
  5395. this.skinWeights = [];
  5396. this.skinIndices = [];
  5397. this.lineDistances = [];
  5398. this.boundingBox = null;
  5399. this.boundingSphere = null;
  5400. // update flags
  5401. this.elementsNeedUpdate = false;
  5402. this.verticesNeedUpdate = false;
  5403. this.uvsNeedUpdate = false;
  5404. this.normalsNeedUpdate = false;
  5405. this.colorsNeedUpdate = false;
  5406. this.lineDistancesNeedUpdate = false;
  5407. this.groupsNeedUpdate = false;
  5408. }
  5409. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5410. constructor: Geometry,
  5411. isGeometry: true,
  5412. applyMatrix: function ( matrix ) {
  5413. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5414. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5415. var vertex = this.vertices[ i ];
  5416. vertex.applyMatrix4( matrix );
  5417. }
  5418. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5419. var face = this.faces[ i ];
  5420. face.normal.applyMatrix3( normalMatrix ).normalize();
  5421. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5422. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5423. }
  5424. }
  5425. if ( this.boundingBox !== null ) {
  5426. this.computeBoundingBox();
  5427. }
  5428. if ( this.boundingSphere !== null ) {
  5429. this.computeBoundingSphere();
  5430. }
  5431. this.verticesNeedUpdate = true;
  5432. this.normalsNeedUpdate = true;
  5433. return this;
  5434. },
  5435. rotateX: function () {
  5436. // rotate geometry around world x-axis
  5437. var m1 = new Matrix4();
  5438. return function rotateX( angle ) {
  5439. m1.makeRotationX( angle );
  5440. this.applyMatrix( m1 );
  5441. return this;
  5442. };
  5443. }(),
  5444. rotateY: function () {
  5445. // rotate geometry around world y-axis
  5446. var m1 = new Matrix4();
  5447. return function rotateY( angle ) {
  5448. m1.makeRotationY( angle );
  5449. this.applyMatrix( m1 );
  5450. return this;
  5451. };
  5452. }(),
  5453. rotateZ: function () {
  5454. // rotate geometry around world z-axis
  5455. var m1 = new Matrix4();
  5456. return function rotateZ( angle ) {
  5457. m1.makeRotationZ( angle );
  5458. this.applyMatrix( m1 );
  5459. return this;
  5460. };
  5461. }(),
  5462. translate: function () {
  5463. // translate geometry
  5464. var m1 = new Matrix4();
  5465. return function translate( x, y, z ) {
  5466. m1.makeTranslation( x, y, z );
  5467. this.applyMatrix( m1 );
  5468. return this;
  5469. };
  5470. }(),
  5471. scale: function () {
  5472. // scale geometry
  5473. var m1 = new Matrix4();
  5474. return function scale( x, y, z ) {
  5475. m1.makeScale( x, y, z );
  5476. this.applyMatrix( m1 );
  5477. return this;
  5478. };
  5479. }(),
  5480. lookAt: function () {
  5481. var obj = new Object3D();
  5482. return function lookAt( vector ) {
  5483. obj.lookAt( vector );
  5484. obj.updateMatrix();
  5485. this.applyMatrix( obj.matrix );
  5486. };
  5487. }(),
  5488. fromBufferGeometry: function ( geometry ) {
  5489. var scope = this;
  5490. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5491. var attributes = geometry.attributes;
  5492. var positions = attributes.position.array;
  5493. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5494. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5495. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5496. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5497. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5498. var tempNormals = [];
  5499. var tempUVs = [];
  5500. var tempUVs2 = [];
  5501. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5502. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5503. if ( normals !== undefined ) {
  5504. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5505. }
  5506. if ( colors !== undefined ) {
  5507. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5508. }
  5509. if ( uvs !== undefined ) {
  5510. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5511. }
  5512. if ( uvs2 !== undefined ) {
  5513. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5514. }
  5515. }
  5516. function addFace( a, b, c, materialIndex ) {
  5517. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5518. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5519. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5520. scope.faces.push( face );
  5521. if ( uvs !== undefined ) {
  5522. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5523. }
  5524. if ( uvs2 !== undefined ) {
  5525. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5526. }
  5527. }
  5528. var groups = geometry.groups;
  5529. if ( groups.length > 0 ) {
  5530. for ( var i = 0; i < groups.length; i ++ ) {
  5531. var group = groups[ i ];
  5532. var start = group.start;
  5533. var count = group.count;
  5534. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5535. if ( indices !== undefined ) {
  5536. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5537. } else {
  5538. addFace( j, j + 1, j + 2, group.materialIndex );
  5539. }
  5540. }
  5541. }
  5542. } else {
  5543. if ( indices !== undefined ) {
  5544. for ( var i = 0; i < indices.length; i += 3 ) {
  5545. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5546. }
  5547. } else {
  5548. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5549. addFace( i, i + 1, i + 2 );
  5550. }
  5551. }
  5552. }
  5553. this.computeFaceNormals();
  5554. if ( geometry.boundingBox !== null ) {
  5555. this.boundingBox = geometry.boundingBox.clone();
  5556. }
  5557. if ( geometry.boundingSphere !== null ) {
  5558. this.boundingSphere = geometry.boundingSphere.clone();
  5559. }
  5560. return this;
  5561. },
  5562. center: function () {
  5563. var offset = new Vector3();
  5564. return function center() {
  5565. this.computeBoundingBox();
  5566. this.boundingBox.getCenter( offset ).negate();
  5567. this.translate( offset.x, offset.y, offset.z );
  5568. return this;
  5569. };
  5570. }(),
  5571. normalize: function () {
  5572. this.computeBoundingSphere();
  5573. var center = this.boundingSphere.center;
  5574. var radius = this.boundingSphere.radius;
  5575. var s = radius === 0 ? 1 : 1.0 / radius;
  5576. var matrix = new Matrix4();
  5577. matrix.set(
  5578. s, 0, 0, - s * center.x,
  5579. 0, s, 0, - s * center.y,
  5580. 0, 0, s, - s * center.z,
  5581. 0, 0, 0, 1
  5582. );
  5583. this.applyMatrix( matrix );
  5584. return this;
  5585. },
  5586. computeFaceNormals: function () {
  5587. var cb = new Vector3(), ab = new Vector3();
  5588. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5589. var face = this.faces[ f ];
  5590. var vA = this.vertices[ face.a ];
  5591. var vB = this.vertices[ face.b ];
  5592. var vC = this.vertices[ face.c ];
  5593. cb.subVectors( vC, vB );
  5594. ab.subVectors( vA, vB );
  5595. cb.cross( ab );
  5596. cb.normalize();
  5597. face.normal.copy( cb );
  5598. }
  5599. },
  5600. computeVertexNormals: function ( areaWeighted ) {
  5601. if ( areaWeighted === undefined ) areaWeighted = true;
  5602. var v, vl, f, fl, face, vertices;
  5603. vertices = new Array( this.vertices.length );
  5604. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5605. vertices[ v ] = new Vector3();
  5606. }
  5607. if ( areaWeighted ) {
  5608. // vertex normals weighted by triangle areas
  5609. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5610. var vA, vB, vC;
  5611. var cb = new Vector3(), ab = new Vector3();
  5612. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5613. face = this.faces[ f ];
  5614. vA = this.vertices[ face.a ];
  5615. vB = this.vertices[ face.b ];
  5616. vC = this.vertices[ face.c ];
  5617. cb.subVectors( vC, vB );
  5618. ab.subVectors( vA, vB );
  5619. cb.cross( ab );
  5620. vertices[ face.a ].add( cb );
  5621. vertices[ face.b ].add( cb );
  5622. vertices[ face.c ].add( cb );
  5623. }
  5624. } else {
  5625. this.computeFaceNormals();
  5626. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5627. face = this.faces[ f ];
  5628. vertices[ face.a ].add( face.normal );
  5629. vertices[ face.b ].add( face.normal );
  5630. vertices[ face.c ].add( face.normal );
  5631. }
  5632. }
  5633. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5634. vertices[ v ].normalize();
  5635. }
  5636. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5637. face = this.faces[ f ];
  5638. var vertexNormals = face.vertexNormals;
  5639. if ( vertexNormals.length === 3 ) {
  5640. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5641. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5642. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5643. } else {
  5644. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5645. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5646. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5647. }
  5648. }
  5649. if ( this.faces.length > 0 ) {
  5650. this.normalsNeedUpdate = true;
  5651. }
  5652. },
  5653. computeFlatVertexNormals: function () {
  5654. var f, fl, face;
  5655. this.computeFaceNormals();
  5656. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5657. face = this.faces[ f ];
  5658. var vertexNormals = face.vertexNormals;
  5659. if ( vertexNormals.length === 3 ) {
  5660. vertexNormals[ 0 ].copy( face.normal );
  5661. vertexNormals[ 1 ].copy( face.normal );
  5662. vertexNormals[ 2 ].copy( face.normal );
  5663. } else {
  5664. vertexNormals[ 0 ] = face.normal.clone();
  5665. vertexNormals[ 1 ] = face.normal.clone();
  5666. vertexNormals[ 2 ] = face.normal.clone();
  5667. }
  5668. }
  5669. if ( this.faces.length > 0 ) {
  5670. this.normalsNeedUpdate = true;
  5671. }
  5672. },
  5673. computeMorphNormals: function () {
  5674. var i, il, f, fl, face;
  5675. // save original normals
  5676. // - create temp variables on first access
  5677. // otherwise just copy (for faster repeated calls)
  5678. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5679. face = this.faces[ f ];
  5680. if ( ! face.__originalFaceNormal ) {
  5681. face.__originalFaceNormal = face.normal.clone();
  5682. } else {
  5683. face.__originalFaceNormal.copy( face.normal );
  5684. }
  5685. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5686. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5687. if ( ! face.__originalVertexNormals[ i ] ) {
  5688. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5689. } else {
  5690. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5691. }
  5692. }
  5693. }
  5694. // use temp geometry to compute face and vertex normals for each morph
  5695. var tmpGeo = new Geometry();
  5696. tmpGeo.faces = this.faces;
  5697. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5698. // create on first access
  5699. if ( ! this.morphNormals[ i ] ) {
  5700. this.morphNormals[ i ] = {};
  5701. this.morphNormals[ i ].faceNormals = [];
  5702. this.morphNormals[ i ].vertexNormals = [];
  5703. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5704. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5705. var faceNormal, vertexNormals;
  5706. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5707. faceNormal = new Vector3();
  5708. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5709. dstNormalsFace.push( faceNormal );
  5710. dstNormalsVertex.push( vertexNormals );
  5711. }
  5712. }
  5713. var morphNormals = this.morphNormals[ i ];
  5714. // set vertices to morph target
  5715. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5716. // compute morph normals
  5717. tmpGeo.computeFaceNormals();
  5718. tmpGeo.computeVertexNormals();
  5719. // store morph normals
  5720. var faceNormal, vertexNormals;
  5721. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5722. face = this.faces[ f ];
  5723. faceNormal = morphNormals.faceNormals[ f ];
  5724. vertexNormals = morphNormals.vertexNormals[ f ];
  5725. faceNormal.copy( face.normal );
  5726. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5727. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5728. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5729. }
  5730. }
  5731. // restore original normals
  5732. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5733. face = this.faces[ f ];
  5734. face.normal = face.__originalFaceNormal;
  5735. face.vertexNormals = face.__originalVertexNormals;
  5736. }
  5737. },
  5738. computeBoundingBox: function () {
  5739. if ( this.boundingBox === null ) {
  5740. this.boundingBox = new Box3();
  5741. }
  5742. this.boundingBox.setFromPoints( this.vertices );
  5743. },
  5744. computeBoundingSphere: function () {
  5745. if ( this.boundingSphere === null ) {
  5746. this.boundingSphere = new Sphere();
  5747. }
  5748. this.boundingSphere.setFromPoints( this.vertices );
  5749. },
  5750. merge: function ( geometry, matrix, materialIndexOffset ) {
  5751. if ( ! ( geometry && geometry.isGeometry ) ) {
  5752. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5753. return;
  5754. }
  5755. var normalMatrix,
  5756. vertexOffset = this.vertices.length,
  5757. vertices1 = this.vertices,
  5758. vertices2 = geometry.vertices,
  5759. faces1 = this.faces,
  5760. faces2 = geometry.faces,
  5761. uvs1 = this.faceVertexUvs[ 0 ],
  5762. uvs2 = geometry.faceVertexUvs[ 0 ],
  5763. colors1 = this.colors,
  5764. colors2 = geometry.colors;
  5765. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5766. if ( matrix !== undefined ) {
  5767. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5768. }
  5769. // vertices
  5770. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5771. var vertex = vertices2[ i ];
  5772. var vertexCopy = vertex.clone();
  5773. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5774. vertices1.push( vertexCopy );
  5775. }
  5776. // colors
  5777. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5778. colors1.push( colors2[ i ].clone() );
  5779. }
  5780. // faces
  5781. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5782. var face = faces2[ i ], faceCopy, normal, color,
  5783. faceVertexNormals = face.vertexNormals,
  5784. faceVertexColors = face.vertexColors;
  5785. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5786. faceCopy.normal.copy( face.normal );
  5787. if ( normalMatrix !== undefined ) {
  5788. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5789. }
  5790. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5791. normal = faceVertexNormals[ j ].clone();
  5792. if ( normalMatrix !== undefined ) {
  5793. normal.applyMatrix3( normalMatrix ).normalize();
  5794. }
  5795. faceCopy.vertexNormals.push( normal );
  5796. }
  5797. faceCopy.color.copy( face.color );
  5798. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5799. color = faceVertexColors[ j ];
  5800. faceCopy.vertexColors.push( color.clone() );
  5801. }
  5802. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5803. faces1.push( faceCopy );
  5804. }
  5805. // uvs
  5806. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5807. var uv = uvs2[ i ], uvCopy = [];
  5808. if ( uv === undefined ) {
  5809. continue;
  5810. }
  5811. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5812. uvCopy.push( uv[ j ].clone() );
  5813. }
  5814. uvs1.push( uvCopy );
  5815. }
  5816. },
  5817. mergeMesh: function ( mesh ) {
  5818. if ( ! ( mesh && mesh.isMesh ) ) {
  5819. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5820. return;
  5821. }
  5822. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5823. this.merge( mesh.geometry, mesh.matrix );
  5824. },
  5825. /*
  5826. * Checks for duplicate vertices with hashmap.
  5827. * Duplicated vertices are removed
  5828. * and faces' vertices are updated.
  5829. */
  5830. mergeVertices: function () {
  5831. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5832. var unique = [], changes = [];
  5833. var v, key;
  5834. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5835. var precision = Math.pow( 10, precisionPoints );
  5836. var i, il, face;
  5837. var indices, j, jl;
  5838. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5839. v = this.vertices[ i ];
  5840. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5841. if ( verticesMap[ key ] === undefined ) {
  5842. verticesMap[ key ] = i;
  5843. unique.push( this.vertices[ i ] );
  5844. changes[ i ] = unique.length - 1;
  5845. } else {
  5846. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5847. changes[ i ] = changes[ verticesMap[ key ] ];
  5848. }
  5849. }
  5850. // if faces are completely degenerate after merging vertices, we
  5851. // have to remove them from the geometry.
  5852. var faceIndicesToRemove = [];
  5853. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5854. face = this.faces[ i ];
  5855. face.a = changes[ face.a ];
  5856. face.b = changes[ face.b ];
  5857. face.c = changes[ face.c ];
  5858. indices = [ face.a, face.b, face.c ];
  5859. // if any duplicate vertices are found in a Face3
  5860. // we have to remove the face as nothing can be saved
  5861. for ( var n = 0; n < 3; n ++ ) {
  5862. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5863. faceIndicesToRemove.push( i );
  5864. break;
  5865. }
  5866. }
  5867. }
  5868. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5869. var idx = faceIndicesToRemove[ i ];
  5870. this.faces.splice( idx, 1 );
  5871. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5872. this.faceVertexUvs[ j ].splice( idx, 1 );
  5873. }
  5874. }
  5875. // Use unique set of vertices
  5876. var diff = this.vertices.length - unique.length;
  5877. this.vertices = unique;
  5878. return diff;
  5879. },
  5880. setFromPoints: function ( points ) {
  5881. this.vertices = [];
  5882. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5883. var point = points[ i ];
  5884. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5885. }
  5886. return this;
  5887. },
  5888. sortFacesByMaterialIndex: function () {
  5889. var faces = this.faces;
  5890. var length = faces.length;
  5891. // tag faces
  5892. for ( var i = 0; i < length; i ++ ) {
  5893. faces[ i ]._id = i;
  5894. }
  5895. // sort faces
  5896. function materialIndexSort( a, b ) {
  5897. return a.materialIndex - b.materialIndex;
  5898. }
  5899. faces.sort( materialIndexSort );
  5900. // sort uvs
  5901. var uvs1 = this.faceVertexUvs[ 0 ];
  5902. var uvs2 = this.faceVertexUvs[ 1 ];
  5903. var newUvs1, newUvs2;
  5904. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5905. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5906. for ( var i = 0; i < length; i ++ ) {
  5907. var id = faces[ i ]._id;
  5908. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5909. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5910. }
  5911. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5912. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5913. },
  5914. toJSON: function () {
  5915. var data = {
  5916. metadata: {
  5917. version: 4.5,
  5918. type: 'Geometry',
  5919. generator: 'Geometry.toJSON'
  5920. }
  5921. };
  5922. // standard Geometry serialization
  5923. data.uuid = this.uuid;
  5924. data.type = this.type;
  5925. if ( this.name !== '' ) data.name = this.name;
  5926. if ( this.parameters !== undefined ) {
  5927. var parameters = this.parameters;
  5928. for ( var key in parameters ) {
  5929. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5930. }
  5931. return data;
  5932. }
  5933. var vertices = [];
  5934. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5935. var vertex = this.vertices[ i ];
  5936. vertices.push( vertex.x, vertex.y, vertex.z );
  5937. }
  5938. var faces = [];
  5939. var normals = [];
  5940. var normalsHash = {};
  5941. var colors = [];
  5942. var colorsHash = {};
  5943. var uvs = [];
  5944. var uvsHash = {};
  5945. for ( var i = 0; i < this.faces.length; i ++ ) {
  5946. var face = this.faces[ i ];
  5947. var hasMaterial = true;
  5948. var hasFaceUv = false; // deprecated
  5949. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5950. var hasFaceNormal = face.normal.length() > 0;
  5951. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5952. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5953. var hasFaceVertexColor = face.vertexColors.length > 0;
  5954. var faceType = 0;
  5955. faceType = setBit( faceType, 0, 0 ); // isQuad
  5956. faceType = setBit( faceType, 1, hasMaterial );
  5957. faceType = setBit( faceType, 2, hasFaceUv );
  5958. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5959. faceType = setBit( faceType, 4, hasFaceNormal );
  5960. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5961. faceType = setBit( faceType, 6, hasFaceColor );
  5962. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5963. faces.push( faceType );
  5964. faces.push( face.a, face.b, face.c );
  5965. faces.push( face.materialIndex );
  5966. if ( hasFaceVertexUv ) {
  5967. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5968. faces.push(
  5969. getUvIndex( faceVertexUvs[ 0 ] ),
  5970. getUvIndex( faceVertexUvs[ 1 ] ),
  5971. getUvIndex( faceVertexUvs[ 2 ] )
  5972. );
  5973. }
  5974. if ( hasFaceNormal ) {
  5975. faces.push( getNormalIndex( face.normal ) );
  5976. }
  5977. if ( hasFaceVertexNormal ) {
  5978. var vertexNormals = face.vertexNormals;
  5979. faces.push(
  5980. getNormalIndex( vertexNormals[ 0 ] ),
  5981. getNormalIndex( vertexNormals[ 1 ] ),
  5982. getNormalIndex( vertexNormals[ 2 ] )
  5983. );
  5984. }
  5985. if ( hasFaceColor ) {
  5986. faces.push( getColorIndex( face.color ) );
  5987. }
  5988. if ( hasFaceVertexColor ) {
  5989. var vertexColors = face.vertexColors;
  5990. faces.push(
  5991. getColorIndex( vertexColors[ 0 ] ),
  5992. getColorIndex( vertexColors[ 1 ] ),
  5993. getColorIndex( vertexColors[ 2 ] )
  5994. );
  5995. }
  5996. }
  5997. function setBit( value, position, enabled ) {
  5998. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5999. }
  6000. function getNormalIndex( normal ) {
  6001. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6002. if ( normalsHash[ hash ] !== undefined ) {
  6003. return normalsHash[ hash ];
  6004. }
  6005. normalsHash[ hash ] = normals.length / 3;
  6006. normals.push( normal.x, normal.y, normal.z );
  6007. return normalsHash[ hash ];
  6008. }
  6009. function getColorIndex( color ) {
  6010. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6011. if ( colorsHash[ hash ] !== undefined ) {
  6012. return colorsHash[ hash ];
  6013. }
  6014. colorsHash[ hash ] = colors.length;
  6015. colors.push( color.getHex() );
  6016. return colorsHash[ hash ];
  6017. }
  6018. function getUvIndex( uv ) {
  6019. var hash = uv.x.toString() + uv.y.toString();
  6020. if ( uvsHash[ hash ] !== undefined ) {
  6021. return uvsHash[ hash ];
  6022. }
  6023. uvsHash[ hash ] = uvs.length / 2;
  6024. uvs.push( uv.x, uv.y );
  6025. return uvsHash[ hash ];
  6026. }
  6027. data.data = {};
  6028. data.data.vertices = vertices;
  6029. data.data.normals = normals;
  6030. if ( colors.length > 0 ) data.data.colors = colors;
  6031. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6032. data.data.faces = faces;
  6033. return data;
  6034. },
  6035. clone: function () {
  6036. /*
  6037. // Handle primitives
  6038. var parameters = this.parameters;
  6039. if ( parameters !== undefined ) {
  6040. var values = [];
  6041. for ( var key in parameters ) {
  6042. values.push( parameters[ key ] );
  6043. }
  6044. var geometry = Object.create( this.constructor.prototype );
  6045. this.constructor.apply( geometry, values );
  6046. return geometry;
  6047. }
  6048. return new this.constructor().copy( this );
  6049. */
  6050. return new Geometry().copy( this );
  6051. },
  6052. copy: function ( source ) {
  6053. var i, il, j, jl, k, kl;
  6054. // reset
  6055. this.vertices = [];
  6056. this.colors = [];
  6057. this.faces = [];
  6058. this.faceVertexUvs = [[]];
  6059. this.morphTargets = [];
  6060. this.morphNormals = [];
  6061. this.skinWeights = [];
  6062. this.skinIndices = [];
  6063. this.lineDistances = [];
  6064. this.boundingBox = null;
  6065. this.boundingSphere = null;
  6066. // name
  6067. this.name = source.name;
  6068. // vertices
  6069. var vertices = source.vertices;
  6070. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6071. this.vertices.push( vertices[ i ].clone() );
  6072. }
  6073. // colors
  6074. var colors = source.colors;
  6075. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6076. this.colors.push( colors[ i ].clone() );
  6077. }
  6078. // faces
  6079. var faces = source.faces;
  6080. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6081. this.faces.push( faces[ i ].clone() );
  6082. }
  6083. // face vertex uvs
  6084. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6085. var faceVertexUvs = source.faceVertexUvs[ i ];
  6086. if ( this.faceVertexUvs[ i ] === undefined ) {
  6087. this.faceVertexUvs[ i ] = [];
  6088. }
  6089. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6090. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6091. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6092. var uv = uvs[ k ];
  6093. uvsCopy.push( uv.clone() );
  6094. }
  6095. this.faceVertexUvs[ i ].push( uvsCopy );
  6096. }
  6097. }
  6098. // morph targets
  6099. var morphTargets = source.morphTargets;
  6100. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6101. var morphTarget = {};
  6102. morphTarget.name = morphTargets[ i ].name;
  6103. // vertices
  6104. if ( morphTargets[ i ].vertices !== undefined ) {
  6105. morphTarget.vertices = [];
  6106. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6107. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6108. }
  6109. }
  6110. // normals
  6111. if ( morphTargets[ i ].normals !== undefined ) {
  6112. morphTarget.normals = [];
  6113. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6114. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6115. }
  6116. }
  6117. this.morphTargets.push( morphTarget );
  6118. }
  6119. // morph normals
  6120. var morphNormals = source.morphNormals;
  6121. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6122. var morphNormal = {};
  6123. // vertex normals
  6124. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6125. morphNormal.vertexNormals = [];
  6126. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6127. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6128. var destVertexNormal = {};
  6129. destVertexNormal.a = srcVertexNormal.a.clone();
  6130. destVertexNormal.b = srcVertexNormal.b.clone();
  6131. destVertexNormal.c = srcVertexNormal.c.clone();
  6132. morphNormal.vertexNormals.push( destVertexNormal );
  6133. }
  6134. }
  6135. // face normals
  6136. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6137. morphNormal.faceNormals = [];
  6138. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6139. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6140. }
  6141. }
  6142. this.morphNormals.push( morphNormal );
  6143. }
  6144. // skin weights
  6145. var skinWeights = source.skinWeights;
  6146. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6147. this.skinWeights.push( skinWeights[ i ].clone() );
  6148. }
  6149. // skin indices
  6150. var skinIndices = source.skinIndices;
  6151. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6152. this.skinIndices.push( skinIndices[ i ].clone() );
  6153. }
  6154. // line distances
  6155. var lineDistances = source.lineDistances;
  6156. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6157. this.lineDistances.push( lineDistances[ i ] );
  6158. }
  6159. // bounding box
  6160. var boundingBox = source.boundingBox;
  6161. if ( boundingBox !== null ) {
  6162. this.boundingBox = boundingBox.clone();
  6163. }
  6164. // bounding sphere
  6165. var boundingSphere = source.boundingSphere;
  6166. if ( boundingSphere !== null ) {
  6167. this.boundingSphere = boundingSphere.clone();
  6168. }
  6169. // update flags
  6170. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6171. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6172. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6173. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6174. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6175. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6176. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6177. return this;
  6178. },
  6179. dispose: function () {
  6180. this.dispatchEvent( { type: 'dispose' } );
  6181. }
  6182. } );
  6183. /**
  6184. * @author mrdoob / http://mrdoob.com/
  6185. */
  6186. function BufferAttribute( array, itemSize, normalized ) {
  6187. if ( Array.isArray( array ) ) {
  6188. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6189. }
  6190. this.name = '';
  6191. this.array = array;
  6192. this.itemSize = itemSize;
  6193. this.count = array !== undefined ? array.length / itemSize : 0;
  6194. this.normalized = normalized === true;
  6195. this.dynamic = false;
  6196. this.updateRange = { offset: 0, count: - 1 };
  6197. this.version = 0;
  6198. }
  6199. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6200. set: function ( value ) {
  6201. if ( value === true ) this.version ++;
  6202. }
  6203. } );
  6204. Object.assign( BufferAttribute.prototype, {
  6205. isBufferAttribute: true,
  6206. onUploadCallback: function () {},
  6207. setArray: function ( array ) {
  6208. if ( Array.isArray( array ) ) {
  6209. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6210. }
  6211. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6212. this.array = array;
  6213. return this;
  6214. },
  6215. setDynamic: function ( value ) {
  6216. this.dynamic = value;
  6217. return this;
  6218. },
  6219. copy: function ( source ) {
  6220. this.name = source.name;
  6221. this.array = new source.array.constructor( source.array );
  6222. this.itemSize = source.itemSize;
  6223. this.count = source.count;
  6224. this.normalized = source.normalized;
  6225. this.dynamic = source.dynamic;
  6226. return this;
  6227. },
  6228. copyAt: function ( index1, attribute, index2 ) {
  6229. index1 *= this.itemSize;
  6230. index2 *= attribute.itemSize;
  6231. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6232. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6233. }
  6234. return this;
  6235. },
  6236. copyArray: function ( array ) {
  6237. this.array.set( array );
  6238. return this;
  6239. },
  6240. copyColorsArray: function ( colors ) {
  6241. var array = this.array, offset = 0;
  6242. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6243. var color = colors[ i ];
  6244. if ( color === undefined ) {
  6245. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6246. color = new Color();
  6247. }
  6248. array[ offset ++ ] = color.r;
  6249. array[ offset ++ ] = color.g;
  6250. array[ offset ++ ] = color.b;
  6251. }
  6252. return this;
  6253. },
  6254. copyVector2sArray: function ( vectors ) {
  6255. var array = this.array, offset = 0;
  6256. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6257. var vector = vectors[ i ];
  6258. if ( vector === undefined ) {
  6259. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6260. vector = new Vector2();
  6261. }
  6262. array[ offset ++ ] = vector.x;
  6263. array[ offset ++ ] = vector.y;
  6264. }
  6265. return this;
  6266. },
  6267. copyVector3sArray: function ( vectors ) {
  6268. var array = this.array, offset = 0;
  6269. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6270. var vector = vectors[ i ];
  6271. if ( vector === undefined ) {
  6272. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6273. vector = new Vector3();
  6274. }
  6275. array[ offset ++ ] = vector.x;
  6276. array[ offset ++ ] = vector.y;
  6277. array[ offset ++ ] = vector.z;
  6278. }
  6279. return this;
  6280. },
  6281. copyVector4sArray: function ( vectors ) {
  6282. var array = this.array, offset = 0;
  6283. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6284. var vector = vectors[ i ];
  6285. if ( vector === undefined ) {
  6286. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6287. vector = new Vector4();
  6288. }
  6289. array[ offset ++ ] = vector.x;
  6290. array[ offset ++ ] = vector.y;
  6291. array[ offset ++ ] = vector.z;
  6292. array[ offset ++ ] = vector.w;
  6293. }
  6294. return this;
  6295. },
  6296. set: function ( value, offset ) {
  6297. if ( offset === undefined ) offset = 0;
  6298. this.array.set( value, offset );
  6299. return this;
  6300. },
  6301. getX: function ( index ) {
  6302. return this.array[ index * this.itemSize ];
  6303. },
  6304. setX: function ( index, x ) {
  6305. this.array[ index * this.itemSize ] = x;
  6306. return this;
  6307. },
  6308. getY: function ( index ) {
  6309. return this.array[ index * this.itemSize + 1 ];
  6310. },
  6311. setY: function ( index, y ) {
  6312. this.array[ index * this.itemSize + 1 ] = y;
  6313. return this;
  6314. },
  6315. getZ: function ( index ) {
  6316. return this.array[ index * this.itemSize + 2 ];
  6317. },
  6318. setZ: function ( index, z ) {
  6319. this.array[ index * this.itemSize + 2 ] = z;
  6320. return this;
  6321. },
  6322. getW: function ( index ) {
  6323. return this.array[ index * this.itemSize + 3 ];
  6324. },
  6325. setW: function ( index, w ) {
  6326. this.array[ index * this.itemSize + 3 ] = w;
  6327. return this;
  6328. },
  6329. setXY: function ( index, x, y ) {
  6330. index *= this.itemSize;
  6331. this.array[ index + 0 ] = x;
  6332. this.array[ index + 1 ] = y;
  6333. return this;
  6334. },
  6335. setXYZ: function ( index, x, y, z ) {
  6336. index *= this.itemSize;
  6337. this.array[ index + 0 ] = x;
  6338. this.array[ index + 1 ] = y;
  6339. this.array[ index + 2 ] = z;
  6340. return this;
  6341. },
  6342. setXYZW: function ( index, x, y, z, w ) {
  6343. index *= this.itemSize;
  6344. this.array[ index + 0 ] = x;
  6345. this.array[ index + 1 ] = y;
  6346. this.array[ index + 2 ] = z;
  6347. this.array[ index + 3 ] = w;
  6348. return this;
  6349. },
  6350. onUpload: function ( callback ) {
  6351. this.onUploadCallback = callback;
  6352. return this;
  6353. },
  6354. clone: function () {
  6355. return new this.constructor( this.array, this.itemSize ).copy( this );
  6356. }
  6357. } );
  6358. //
  6359. function Int8BufferAttribute( array, itemSize, normalized ) {
  6360. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6361. }
  6362. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6363. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6364. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6365. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6366. }
  6367. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6368. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6369. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6370. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6371. }
  6372. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6373. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6374. function Int16BufferAttribute( array, itemSize, normalized ) {
  6375. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6376. }
  6377. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6378. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6379. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6380. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6381. }
  6382. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6383. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6384. function Int32BufferAttribute( array, itemSize, normalized ) {
  6385. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6386. }
  6387. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6388. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6389. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6390. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6391. }
  6392. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6393. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6394. function Float32BufferAttribute( array, itemSize, normalized ) {
  6395. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6396. }
  6397. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6398. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6399. function Float64BufferAttribute( array, itemSize, normalized ) {
  6400. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6401. }
  6402. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6403. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6404. /**
  6405. * @author mrdoob / http://mrdoob.com/
  6406. */
  6407. function DirectGeometry() {
  6408. this.vertices = [];
  6409. this.normals = [];
  6410. this.colors = [];
  6411. this.uvs = [];
  6412. this.uvs2 = [];
  6413. this.groups = [];
  6414. this.morphTargets = {};
  6415. this.skinWeights = [];
  6416. this.skinIndices = [];
  6417. // this.lineDistances = [];
  6418. this.boundingBox = null;
  6419. this.boundingSphere = null;
  6420. // update flags
  6421. this.verticesNeedUpdate = false;
  6422. this.normalsNeedUpdate = false;
  6423. this.colorsNeedUpdate = false;
  6424. this.uvsNeedUpdate = false;
  6425. this.groupsNeedUpdate = false;
  6426. }
  6427. Object.assign( DirectGeometry.prototype, {
  6428. computeGroups: function ( geometry ) {
  6429. var group;
  6430. var groups = [];
  6431. var materialIndex = undefined;
  6432. var faces = geometry.faces;
  6433. for ( var i = 0; i < faces.length; i ++ ) {
  6434. var face = faces[ i ];
  6435. // materials
  6436. if ( face.materialIndex !== materialIndex ) {
  6437. materialIndex = face.materialIndex;
  6438. if ( group !== undefined ) {
  6439. group.count = ( i * 3 ) - group.start;
  6440. groups.push( group );
  6441. }
  6442. group = {
  6443. start: i * 3,
  6444. materialIndex: materialIndex
  6445. };
  6446. }
  6447. }
  6448. if ( group !== undefined ) {
  6449. group.count = ( i * 3 ) - group.start;
  6450. groups.push( group );
  6451. }
  6452. this.groups = groups;
  6453. },
  6454. fromGeometry: function ( geometry ) {
  6455. var faces = geometry.faces;
  6456. var vertices = geometry.vertices;
  6457. var faceVertexUvs = geometry.faceVertexUvs;
  6458. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6459. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6460. // morphs
  6461. var morphTargets = geometry.morphTargets;
  6462. var morphTargetsLength = morphTargets.length;
  6463. var morphTargetsPosition;
  6464. if ( morphTargetsLength > 0 ) {
  6465. morphTargetsPosition = [];
  6466. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6467. morphTargetsPosition[ i ] = [];
  6468. }
  6469. this.morphTargets.position = morphTargetsPosition;
  6470. }
  6471. var morphNormals = geometry.morphNormals;
  6472. var morphNormalsLength = morphNormals.length;
  6473. var morphTargetsNormal;
  6474. if ( morphNormalsLength > 0 ) {
  6475. morphTargetsNormal = [];
  6476. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6477. morphTargetsNormal[ i ] = [];
  6478. }
  6479. this.morphTargets.normal = morphTargetsNormal;
  6480. }
  6481. // skins
  6482. var skinIndices = geometry.skinIndices;
  6483. var skinWeights = geometry.skinWeights;
  6484. var hasSkinIndices = skinIndices.length === vertices.length;
  6485. var hasSkinWeights = skinWeights.length === vertices.length;
  6486. //
  6487. if ( faces.length === 0 ) {
  6488. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6489. }
  6490. for ( var i = 0; i < faces.length; i ++ ) {
  6491. var face = faces[ i ];
  6492. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6493. var vertexNormals = face.vertexNormals;
  6494. if ( vertexNormals.length === 3 ) {
  6495. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6496. } else {
  6497. var normal = face.normal;
  6498. this.normals.push( normal, normal, normal );
  6499. }
  6500. var vertexColors = face.vertexColors;
  6501. if ( vertexColors.length === 3 ) {
  6502. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6503. } else {
  6504. var color = face.color;
  6505. this.colors.push( color, color, color );
  6506. }
  6507. if ( hasFaceVertexUv === true ) {
  6508. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6509. if ( vertexUvs !== undefined ) {
  6510. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6511. } else {
  6512. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6513. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6514. }
  6515. }
  6516. if ( hasFaceVertexUv2 === true ) {
  6517. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6518. if ( vertexUvs !== undefined ) {
  6519. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6520. } else {
  6521. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6522. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6523. }
  6524. }
  6525. // morphs
  6526. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6527. var morphTarget = morphTargets[ j ].vertices;
  6528. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6529. }
  6530. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6531. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6532. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6533. }
  6534. // skins
  6535. if ( hasSkinIndices ) {
  6536. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6537. }
  6538. if ( hasSkinWeights ) {
  6539. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6540. }
  6541. }
  6542. this.computeGroups( geometry );
  6543. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6544. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6545. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6546. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6547. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6548. return this;
  6549. }
  6550. } );
  6551. /**
  6552. * @author mrdoob / http://mrdoob.com/
  6553. */
  6554. function arrayMax( array ) {
  6555. if ( array.length === 0 ) return - Infinity;
  6556. var max = array[ 0 ];
  6557. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6558. if ( array[ i ] > max ) max = array[ i ];
  6559. }
  6560. return max;
  6561. }
  6562. /**
  6563. * @author alteredq / http://alteredqualia.com/
  6564. * @author mrdoob / http://mrdoob.com/
  6565. */
  6566. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6567. function BufferGeometry() {
  6568. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6569. this.uuid = _Math.generateUUID();
  6570. this.name = '';
  6571. this.type = 'BufferGeometry';
  6572. this.index = null;
  6573. this.attributes = {};
  6574. this.morphAttributes = {};
  6575. this.groups = [];
  6576. this.boundingBox = null;
  6577. this.boundingSphere = null;
  6578. this.drawRange = { start: 0, count: Infinity };
  6579. this.userData = {};
  6580. }
  6581. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6582. constructor: BufferGeometry,
  6583. isBufferGeometry: true,
  6584. getIndex: function () {
  6585. return this.index;
  6586. },
  6587. setIndex: function ( index ) {
  6588. if ( Array.isArray( index ) ) {
  6589. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6590. } else {
  6591. this.index = index;
  6592. }
  6593. },
  6594. addAttribute: function ( name, attribute ) {
  6595. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6596. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6597. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6598. }
  6599. if ( name === 'index' ) {
  6600. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6601. this.setIndex( attribute );
  6602. return this;
  6603. }
  6604. this.attributes[ name ] = attribute;
  6605. return this;
  6606. },
  6607. getAttribute: function ( name ) {
  6608. return this.attributes[ name ];
  6609. },
  6610. removeAttribute: function ( name ) {
  6611. delete this.attributes[ name ];
  6612. return this;
  6613. },
  6614. addGroup: function ( start, count, materialIndex ) {
  6615. this.groups.push( {
  6616. start: start,
  6617. count: count,
  6618. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6619. } );
  6620. },
  6621. clearGroups: function () {
  6622. this.groups = [];
  6623. },
  6624. setDrawRange: function ( start, count ) {
  6625. this.drawRange.start = start;
  6626. this.drawRange.count = count;
  6627. },
  6628. applyMatrix: function ( matrix ) {
  6629. var position = this.attributes.position;
  6630. if ( position !== undefined ) {
  6631. matrix.applyToBufferAttribute( position );
  6632. position.needsUpdate = true;
  6633. }
  6634. var normal = this.attributes.normal;
  6635. if ( normal !== undefined ) {
  6636. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6637. normalMatrix.applyToBufferAttribute( normal );
  6638. normal.needsUpdate = true;
  6639. }
  6640. if ( this.boundingBox !== null ) {
  6641. this.computeBoundingBox();
  6642. }
  6643. if ( this.boundingSphere !== null ) {
  6644. this.computeBoundingSphere();
  6645. }
  6646. return this;
  6647. },
  6648. rotateX: function () {
  6649. // rotate geometry around world x-axis
  6650. var m1 = new Matrix4();
  6651. return function rotateX( angle ) {
  6652. m1.makeRotationX( angle );
  6653. this.applyMatrix( m1 );
  6654. return this;
  6655. };
  6656. }(),
  6657. rotateY: function () {
  6658. // rotate geometry around world y-axis
  6659. var m1 = new Matrix4();
  6660. return function rotateY( angle ) {
  6661. m1.makeRotationY( angle );
  6662. this.applyMatrix( m1 );
  6663. return this;
  6664. };
  6665. }(),
  6666. rotateZ: function () {
  6667. // rotate geometry around world z-axis
  6668. var m1 = new Matrix4();
  6669. return function rotateZ( angle ) {
  6670. m1.makeRotationZ( angle );
  6671. this.applyMatrix( m1 );
  6672. return this;
  6673. };
  6674. }(),
  6675. translate: function () {
  6676. // translate geometry
  6677. var m1 = new Matrix4();
  6678. return function translate( x, y, z ) {
  6679. m1.makeTranslation( x, y, z );
  6680. this.applyMatrix( m1 );
  6681. return this;
  6682. };
  6683. }(),
  6684. scale: function () {
  6685. // scale geometry
  6686. var m1 = new Matrix4();
  6687. return function scale( x, y, z ) {
  6688. m1.makeScale( x, y, z );
  6689. this.applyMatrix( m1 );
  6690. return this;
  6691. };
  6692. }(),
  6693. lookAt: function () {
  6694. var obj = new Object3D();
  6695. return function lookAt( vector ) {
  6696. obj.lookAt( vector );
  6697. obj.updateMatrix();
  6698. this.applyMatrix( obj.matrix );
  6699. };
  6700. }(),
  6701. center: function () {
  6702. var offset = new Vector3();
  6703. return function center() {
  6704. this.computeBoundingBox();
  6705. this.boundingBox.getCenter( offset ).negate();
  6706. this.translate( offset.x, offset.y, offset.z );
  6707. return this;
  6708. };
  6709. }(),
  6710. setFromObject: function ( object ) {
  6711. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6712. var geometry = object.geometry;
  6713. if ( object.isPoints || object.isLine ) {
  6714. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6715. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6716. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6717. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6718. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6719. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6720. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6721. }
  6722. if ( geometry.boundingSphere !== null ) {
  6723. this.boundingSphere = geometry.boundingSphere.clone();
  6724. }
  6725. if ( geometry.boundingBox !== null ) {
  6726. this.boundingBox = geometry.boundingBox.clone();
  6727. }
  6728. } else if ( object.isMesh ) {
  6729. if ( geometry && geometry.isGeometry ) {
  6730. this.fromGeometry( geometry );
  6731. }
  6732. }
  6733. return this;
  6734. },
  6735. setFromPoints: function ( points ) {
  6736. var position = [];
  6737. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6738. var point = points[ i ];
  6739. position.push( point.x, point.y, point.z || 0 );
  6740. }
  6741. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6742. return this;
  6743. },
  6744. updateFromObject: function ( object ) {
  6745. var geometry = object.geometry;
  6746. if ( object.isMesh ) {
  6747. var direct = geometry.__directGeometry;
  6748. if ( geometry.elementsNeedUpdate === true ) {
  6749. direct = undefined;
  6750. geometry.elementsNeedUpdate = false;
  6751. }
  6752. if ( direct === undefined ) {
  6753. return this.fromGeometry( geometry );
  6754. }
  6755. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6756. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6757. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6758. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6759. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6760. geometry.verticesNeedUpdate = false;
  6761. geometry.normalsNeedUpdate = false;
  6762. geometry.colorsNeedUpdate = false;
  6763. geometry.uvsNeedUpdate = false;
  6764. geometry.groupsNeedUpdate = false;
  6765. geometry = direct;
  6766. }
  6767. var attribute;
  6768. if ( geometry.verticesNeedUpdate === true ) {
  6769. attribute = this.attributes.position;
  6770. if ( attribute !== undefined ) {
  6771. attribute.copyVector3sArray( geometry.vertices );
  6772. attribute.needsUpdate = true;
  6773. }
  6774. geometry.verticesNeedUpdate = false;
  6775. }
  6776. if ( geometry.normalsNeedUpdate === true ) {
  6777. attribute = this.attributes.normal;
  6778. if ( attribute !== undefined ) {
  6779. attribute.copyVector3sArray( geometry.normals );
  6780. attribute.needsUpdate = true;
  6781. }
  6782. geometry.normalsNeedUpdate = false;
  6783. }
  6784. if ( geometry.colorsNeedUpdate === true ) {
  6785. attribute = this.attributes.color;
  6786. if ( attribute !== undefined ) {
  6787. attribute.copyColorsArray( geometry.colors );
  6788. attribute.needsUpdate = true;
  6789. }
  6790. geometry.colorsNeedUpdate = false;
  6791. }
  6792. if ( geometry.uvsNeedUpdate ) {
  6793. attribute = this.attributes.uv;
  6794. if ( attribute !== undefined ) {
  6795. attribute.copyVector2sArray( geometry.uvs );
  6796. attribute.needsUpdate = true;
  6797. }
  6798. geometry.uvsNeedUpdate = false;
  6799. }
  6800. if ( geometry.lineDistancesNeedUpdate ) {
  6801. attribute = this.attributes.lineDistance;
  6802. if ( attribute !== undefined ) {
  6803. attribute.copyArray( geometry.lineDistances );
  6804. attribute.needsUpdate = true;
  6805. }
  6806. geometry.lineDistancesNeedUpdate = false;
  6807. }
  6808. if ( geometry.groupsNeedUpdate ) {
  6809. geometry.computeGroups( object.geometry );
  6810. this.groups = geometry.groups;
  6811. geometry.groupsNeedUpdate = false;
  6812. }
  6813. return this;
  6814. },
  6815. fromGeometry: function ( geometry ) {
  6816. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6817. return this.fromDirectGeometry( geometry.__directGeometry );
  6818. },
  6819. fromDirectGeometry: function ( geometry ) {
  6820. var positions = new Float32Array( geometry.vertices.length * 3 );
  6821. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6822. if ( geometry.normals.length > 0 ) {
  6823. var normals = new Float32Array( geometry.normals.length * 3 );
  6824. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6825. }
  6826. if ( geometry.colors.length > 0 ) {
  6827. var colors = new Float32Array( geometry.colors.length * 3 );
  6828. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6829. }
  6830. if ( geometry.uvs.length > 0 ) {
  6831. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6832. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6833. }
  6834. if ( geometry.uvs2.length > 0 ) {
  6835. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6836. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6837. }
  6838. // groups
  6839. this.groups = geometry.groups;
  6840. // morphs
  6841. for ( var name in geometry.morphTargets ) {
  6842. var array = [];
  6843. var morphTargets = geometry.morphTargets[ name ];
  6844. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6845. var morphTarget = morphTargets[ i ];
  6846. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  6847. array.push( attribute.copyVector3sArray( morphTarget ) );
  6848. }
  6849. this.morphAttributes[ name ] = array;
  6850. }
  6851. // skinning
  6852. if ( geometry.skinIndices.length > 0 ) {
  6853. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6854. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6855. }
  6856. if ( geometry.skinWeights.length > 0 ) {
  6857. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6858. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6859. }
  6860. //
  6861. if ( geometry.boundingSphere !== null ) {
  6862. this.boundingSphere = geometry.boundingSphere.clone();
  6863. }
  6864. if ( geometry.boundingBox !== null ) {
  6865. this.boundingBox = geometry.boundingBox.clone();
  6866. }
  6867. return this;
  6868. },
  6869. computeBoundingBox: function () {
  6870. if ( this.boundingBox === null ) {
  6871. this.boundingBox = new Box3();
  6872. }
  6873. var position = this.attributes.position;
  6874. if ( position !== undefined ) {
  6875. this.boundingBox.setFromBufferAttribute( position );
  6876. } else {
  6877. this.boundingBox.makeEmpty();
  6878. }
  6879. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6880. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6881. }
  6882. },
  6883. computeBoundingSphere: function () {
  6884. var box = new Box3();
  6885. var vector = new Vector3();
  6886. return function computeBoundingSphere() {
  6887. if ( this.boundingSphere === null ) {
  6888. this.boundingSphere = new Sphere();
  6889. }
  6890. var position = this.attributes.position;
  6891. if ( position ) {
  6892. var center = this.boundingSphere.center;
  6893. box.setFromBufferAttribute( position );
  6894. box.getCenter( center );
  6895. // hoping to find a boundingSphere with a radius smaller than the
  6896. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6897. var maxRadiusSq = 0;
  6898. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6899. vector.x = position.getX( i );
  6900. vector.y = position.getY( i );
  6901. vector.z = position.getZ( i );
  6902. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6903. }
  6904. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6905. if ( isNaN( this.boundingSphere.radius ) ) {
  6906. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6907. }
  6908. }
  6909. };
  6910. }(),
  6911. computeFaceNormals: function () {
  6912. // backwards compatibility
  6913. },
  6914. computeVertexNormals: function () {
  6915. var index = this.index;
  6916. var attributes = this.attributes;
  6917. var groups = this.groups;
  6918. if ( attributes.position ) {
  6919. var positions = attributes.position.array;
  6920. if ( attributes.normal === undefined ) {
  6921. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6922. } else {
  6923. // reset existing normals to zero
  6924. var array = attributes.normal.array;
  6925. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6926. array[ i ] = 0;
  6927. }
  6928. }
  6929. var normals = attributes.normal.array;
  6930. var vA, vB, vC;
  6931. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6932. var cb = new Vector3(), ab = new Vector3();
  6933. // indexed elements
  6934. if ( index ) {
  6935. var indices = index.array;
  6936. if ( groups.length === 0 ) {
  6937. this.addGroup( 0, indices.length );
  6938. }
  6939. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6940. var group = groups[ j ];
  6941. var start = group.start;
  6942. var count = group.count;
  6943. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6944. vA = indices[ i + 0 ] * 3;
  6945. vB = indices[ i + 1 ] * 3;
  6946. vC = indices[ i + 2 ] * 3;
  6947. pA.fromArray( positions, vA );
  6948. pB.fromArray( positions, vB );
  6949. pC.fromArray( positions, vC );
  6950. cb.subVectors( pC, pB );
  6951. ab.subVectors( pA, pB );
  6952. cb.cross( ab );
  6953. normals[ vA ] += cb.x;
  6954. normals[ vA + 1 ] += cb.y;
  6955. normals[ vA + 2 ] += cb.z;
  6956. normals[ vB ] += cb.x;
  6957. normals[ vB + 1 ] += cb.y;
  6958. normals[ vB + 2 ] += cb.z;
  6959. normals[ vC ] += cb.x;
  6960. normals[ vC + 1 ] += cb.y;
  6961. normals[ vC + 2 ] += cb.z;
  6962. }
  6963. }
  6964. } else {
  6965. // non-indexed elements (unconnected triangle soup)
  6966. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6967. pA.fromArray( positions, i );
  6968. pB.fromArray( positions, i + 3 );
  6969. pC.fromArray( positions, i + 6 );
  6970. cb.subVectors( pC, pB );
  6971. ab.subVectors( pA, pB );
  6972. cb.cross( ab );
  6973. normals[ i ] = cb.x;
  6974. normals[ i + 1 ] = cb.y;
  6975. normals[ i + 2 ] = cb.z;
  6976. normals[ i + 3 ] = cb.x;
  6977. normals[ i + 4 ] = cb.y;
  6978. normals[ i + 5 ] = cb.z;
  6979. normals[ i + 6 ] = cb.x;
  6980. normals[ i + 7 ] = cb.y;
  6981. normals[ i + 8 ] = cb.z;
  6982. }
  6983. }
  6984. this.normalizeNormals();
  6985. attributes.normal.needsUpdate = true;
  6986. }
  6987. },
  6988. merge: function ( geometry, offset ) {
  6989. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6990. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6991. return;
  6992. }
  6993. if ( offset === undefined ) {
  6994. offset = 0;
  6995. console.warn(
  6996. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6997. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6998. );
  6999. }
  7000. var attributes = this.attributes;
  7001. for ( var key in attributes ) {
  7002. if ( geometry.attributes[ key ] === undefined ) continue;
  7003. var attribute1 = attributes[ key ];
  7004. var attributeArray1 = attribute1.array;
  7005. var attribute2 = geometry.attributes[ key ];
  7006. var attributeArray2 = attribute2.array;
  7007. var attributeSize = attribute2.itemSize;
  7008. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7009. attributeArray1[ j ] = attributeArray2[ i ];
  7010. }
  7011. }
  7012. return this;
  7013. },
  7014. normalizeNormals: function () {
  7015. var vector = new Vector3();
  7016. return function normalizeNormals() {
  7017. var normals = this.attributes.normal;
  7018. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7019. vector.x = normals.getX( i );
  7020. vector.y = normals.getY( i );
  7021. vector.z = normals.getZ( i );
  7022. vector.normalize();
  7023. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7024. }
  7025. };
  7026. }(),
  7027. toNonIndexed: function () {
  7028. if ( this.index === null ) {
  7029. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7030. return this;
  7031. }
  7032. var geometry2 = new BufferGeometry();
  7033. var indices = this.index.array;
  7034. var attributes = this.attributes;
  7035. for ( var name in attributes ) {
  7036. var attribute = attributes[ name ];
  7037. var array = attribute.array;
  7038. var itemSize = attribute.itemSize;
  7039. var array2 = new array.constructor( indices.length * itemSize );
  7040. var index = 0, index2 = 0;
  7041. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7042. index = indices[ i ] * itemSize;
  7043. for ( var j = 0; j < itemSize; j ++ ) {
  7044. array2[ index2 ++ ] = array[ index ++ ];
  7045. }
  7046. }
  7047. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  7048. }
  7049. var groups = this.groups;
  7050. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7051. var group = groups[ i ];
  7052. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7053. }
  7054. return geometry2;
  7055. },
  7056. toJSON: function () {
  7057. var data = {
  7058. metadata: {
  7059. version: 4.5,
  7060. type: 'BufferGeometry',
  7061. generator: 'BufferGeometry.toJSON'
  7062. }
  7063. };
  7064. // standard BufferGeometry serialization
  7065. data.uuid = this.uuid;
  7066. data.type = this.type;
  7067. if ( this.name !== '' ) data.name = this.name;
  7068. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7069. if ( this.parameters !== undefined ) {
  7070. var parameters = this.parameters;
  7071. for ( var key in parameters ) {
  7072. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7073. }
  7074. return data;
  7075. }
  7076. data.data = { attributes: {} };
  7077. var index = this.index;
  7078. if ( index !== null ) {
  7079. var array = Array.prototype.slice.call( index.array );
  7080. data.data.index = {
  7081. type: index.array.constructor.name,
  7082. array: array
  7083. };
  7084. }
  7085. var attributes = this.attributes;
  7086. for ( var key in attributes ) {
  7087. var attribute = attributes[ key ];
  7088. var array = Array.prototype.slice.call( attribute.array );
  7089. data.data.attributes[ key ] = {
  7090. itemSize: attribute.itemSize,
  7091. type: attribute.array.constructor.name,
  7092. array: array,
  7093. normalized: attribute.normalized
  7094. };
  7095. }
  7096. var groups = this.groups;
  7097. if ( groups.length > 0 ) {
  7098. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7099. }
  7100. var boundingSphere = this.boundingSphere;
  7101. if ( boundingSphere !== null ) {
  7102. data.data.boundingSphere = {
  7103. center: boundingSphere.center.toArray(),
  7104. radius: boundingSphere.radius
  7105. };
  7106. }
  7107. return data;
  7108. },
  7109. clone: function () {
  7110. /*
  7111. // Handle primitives
  7112. var parameters = this.parameters;
  7113. if ( parameters !== undefined ) {
  7114. var values = [];
  7115. for ( var key in parameters ) {
  7116. values.push( parameters[ key ] );
  7117. }
  7118. var geometry = Object.create( this.constructor.prototype );
  7119. this.constructor.apply( geometry, values );
  7120. return geometry;
  7121. }
  7122. return new this.constructor().copy( this );
  7123. */
  7124. return new BufferGeometry().copy( this );
  7125. },
  7126. copy: function ( source ) {
  7127. var name, i, l;
  7128. // reset
  7129. this.index = null;
  7130. this.attributes = {};
  7131. this.morphAttributes = {};
  7132. this.groups = [];
  7133. this.boundingBox = null;
  7134. this.boundingSphere = null;
  7135. // name
  7136. this.name = source.name;
  7137. // index
  7138. var index = source.index;
  7139. if ( index !== null ) {
  7140. this.setIndex( index.clone() );
  7141. }
  7142. // attributes
  7143. var attributes = source.attributes;
  7144. for ( name in attributes ) {
  7145. var attribute = attributes[ name ];
  7146. this.addAttribute( name, attribute.clone() );
  7147. }
  7148. // morph attributes
  7149. var morphAttributes = source.morphAttributes;
  7150. for ( name in morphAttributes ) {
  7151. var array = [];
  7152. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7153. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7154. array.push( morphAttribute[ i ].clone() );
  7155. }
  7156. this.morphAttributes[ name ] = array;
  7157. }
  7158. // groups
  7159. var groups = source.groups;
  7160. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7161. var group = groups[ i ];
  7162. this.addGroup( group.start, group.count, group.materialIndex );
  7163. }
  7164. // bounding box
  7165. var boundingBox = source.boundingBox;
  7166. if ( boundingBox !== null ) {
  7167. this.boundingBox = boundingBox.clone();
  7168. }
  7169. // bounding sphere
  7170. var boundingSphere = source.boundingSphere;
  7171. if ( boundingSphere !== null ) {
  7172. this.boundingSphere = boundingSphere.clone();
  7173. }
  7174. // draw range
  7175. this.drawRange.start = source.drawRange.start;
  7176. this.drawRange.count = source.drawRange.count;
  7177. // user data
  7178. this.userData = source.userData;
  7179. return this;
  7180. },
  7181. dispose: function () {
  7182. this.dispatchEvent( { type: 'dispose' } );
  7183. }
  7184. } );
  7185. /**
  7186. * @author mrdoob / http://mrdoob.com/
  7187. * @author Mugen87 / https://github.com/Mugen87
  7188. */
  7189. // BoxGeometry
  7190. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7191. Geometry.call( this );
  7192. this.type = 'BoxGeometry';
  7193. this.parameters = {
  7194. width: width,
  7195. height: height,
  7196. depth: depth,
  7197. widthSegments: widthSegments,
  7198. heightSegments: heightSegments,
  7199. depthSegments: depthSegments
  7200. };
  7201. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7202. this.mergeVertices();
  7203. }
  7204. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7205. BoxGeometry.prototype.constructor = BoxGeometry;
  7206. // BoxBufferGeometry
  7207. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7208. BufferGeometry.call( this );
  7209. this.type = 'BoxBufferGeometry';
  7210. this.parameters = {
  7211. width: width,
  7212. height: height,
  7213. depth: depth,
  7214. widthSegments: widthSegments,
  7215. heightSegments: heightSegments,
  7216. depthSegments: depthSegments
  7217. };
  7218. var scope = this;
  7219. width = width || 1;
  7220. height = height || 1;
  7221. depth = depth || 1;
  7222. // segments
  7223. widthSegments = Math.floor( widthSegments ) || 1;
  7224. heightSegments = Math.floor( heightSegments ) || 1;
  7225. depthSegments = Math.floor( depthSegments ) || 1;
  7226. // buffers
  7227. var indices = [];
  7228. var vertices = [];
  7229. var normals = [];
  7230. var uvs = [];
  7231. // helper variables
  7232. var numberOfVertices = 0;
  7233. var groupStart = 0;
  7234. // build each side of the box geometry
  7235. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7236. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7237. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7238. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7239. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7240. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7241. // build geometry
  7242. this.setIndex( indices );
  7243. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7244. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7245. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7246. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7247. var segmentWidth = width / gridX;
  7248. var segmentHeight = height / gridY;
  7249. var widthHalf = width / 2;
  7250. var heightHalf = height / 2;
  7251. var depthHalf = depth / 2;
  7252. var gridX1 = gridX + 1;
  7253. var gridY1 = gridY + 1;
  7254. var vertexCounter = 0;
  7255. var groupCount = 0;
  7256. var ix, iy;
  7257. var vector = new Vector3();
  7258. // generate vertices, normals and uvs
  7259. for ( iy = 0; iy < gridY1; iy ++ ) {
  7260. var y = iy * segmentHeight - heightHalf;
  7261. for ( ix = 0; ix < gridX1; ix ++ ) {
  7262. var x = ix * segmentWidth - widthHalf;
  7263. // set values to correct vector component
  7264. vector[ u ] = x * udir;
  7265. vector[ v ] = y * vdir;
  7266. vector[ w ] = depthHalf;
  7267. // now apply vector to vertex buffer
  7268. vertices.push( vector.x, vector.y, vector.z );
  7269. // set values to correct vector component
  7270. vector[ u ] = 0;
  7271. vector[ v ] = 0;
  7272. vector[ w ] = depth > 0 ? 1 : - 1;
  7273. // now apply vector to normal buffer
  7274. normals.push( vector.x, vector.y, vector.z );
  7275. // uvs
  7276. uvs.push( ix / gridX );
  7277. uvs.push( 1 - ( iy / gridY ) );
  7278. // counters
  7279. vertexCounter += 1;
  7280. }
  7281. }
  7282. // indices
  7283. // 1. you need three indices to draw a single face
  7284. // 2. a single segment consists of two faces
  7285. // 3. so we need to generate six (2*3) indices per segment
  7286. for ( iy = 0; iy < gridY; iy ++ ) {
  7287. for ( ix = 0; ix < gridX; ix ++ ) {
  7288. var a = numberOfVertices + ix + gridX1 * iy;
  7289. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7290. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7291. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7292. // faces
  7293. indices.push( a, b, d );
  7294. indices.push( b, c, d );
  7295. // increase counter
  7296. groupCount += 6;
  7297. }
  7298. }
  7299. // add a group to the geometry. this will ensure multi material support
  7300. scope.addGroup( groupStart, groupCount, materialIndex );
  7301. // calculate new start value for groups
  7302. groupStart += groupCount;
  7303. // update total number of vertices
  7304. numberOfVertices += vertexCounter;
  7305. }
  7306. }
  7307. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7308. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7309. /**
  7310. * @author mrdoob / http://mrdoob.com/
  7311. * @author Mugen87 / https://github.com/Mugen87
  7312. */
  7313. // PlaneGeometry
  7314. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7315. Geometry.call( this );
  7316. this.type = 'PlaneGeometry';
  7317. this.parameters = {
  7318. width: width,
  7319. height: height,
  7320. widthSegments: widthSegments,
  7321. heightSegments: heightSegments
  7322. };
  7323. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7324. this.mergeVertices();
  7325. }
  7326. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7327. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7328. // PlaneBufferGeometry
  7329. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7330. BufferGeometry.call( this );
  7331. this.type = 'PlaneBufferGeometry';
  7332. this.parameters = {
  7333. width: width,
  7334. height: height,
  7335. widthSegments: widthSegments,
  7336. heightSegments: heightSegments
  7337. };
  7338. width = width || 1;
  7339. height = height || 1;
  7340. var width_half = width / 2;
  7341. var height_half = height / 2;
  7342. var gridX = Math.floor( widthSegments ) || 1;
  7343. var gridY = Math.floor( heightSegments ) || 1;
  7344. var gridX1 = gridX + 1;
  7345. var gridY1 = gridY + 1;
  7346. var segment_width = width / gridX;
  7347. var segment_height = height / gridY;
  7348. var ix, iy;
  7349. // buffers
  7350. var indices = [];
  7351. var vertices = [];
  7352. var normals = [];
  7353. var uvs = [];
  7354. // generate vertices, normals and uvs
  7355. for ( iy = 0; iy < gridY1; iy ++ ) {
  7356. var y = iy * segment_height - height_half;
  7357. for ( ix = 0; ix < gridX1; ix ++ ) {
  7358. var x = ix * segment_width - width_half;
  7359. vertices.push( x, - y, 0 );
  7360. normals.push( 0, 0, 1 );
  7361. uvs.push( ix / gridX );
  7362. uvs.push( 1 - ( iy / gridY ) );
  7363. }
  7364. }
  7365. // indices
  7366. for ( iy = 0; iy < gridY; iy ++ ) {
  7367. for ( ix = 0; ix < gridX; ix ++ ) {
  7368. var a = ix + gridX1 * iy;
  7369. var b = ix + gridX1 * ( iy + 1 );
  7370. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7371. var d = ( ix + 1 ) + gridX1 * iy;
  7372. // faces
  7373. indices.push( a, b, d );
  7374. indices.push( b, c, d );
  7375. }
  7376. }
  7377. // build geometry
  7378. this.setIndex( indices );
  7379. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7380. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7381. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7382. }
  7383. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7384. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7385. /**
  7386. * @author mrdoob / http://mrdoob.com/
  7387. * @author alteredq / http://alteredqualia.com/
  7388. */
  7389. var materialId = 0;
  7390. function Material() {
  7391. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7392. this.uuid = _Math.generateUUID();
  7393. this.name = '';
  7394. this.type = 'Material';
  7395. this.fog = true;
  7396. this.lights = true;
  7397. this.blending = NormalBlending;
  7398. this.side = FrontSide;
  7399. this.flatShading = false;
  7400. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7401. this.opacity = 1;
  7402. this.transparent = false;
  7403. this.blendSrc = SrcAlphaFactor;
  7404. this.blendDst = OneMinusSrcAlphaFactor;
  7405. this.blendEquation = AddEquation;
  7406. this.blendSrcAlpha = null;
  7407. this.blendDstAlpha = null;
  7408. this.blendEquationAlpha = null;
  7409. this.depthFunc = LessEqualDepth;
  7410. this.depthTest = true;
  7411. this.depthWrite = true;
  7412. this.clippingPlanes = null;
  7413. this.clipIntersection = false;
  7414. this.clipShadows = false;
  7415. this.shadowSide = null;
  7416. this.colorWrite = true;
  7417. this.precision = null; // override the renderer's default precision for this material
  7418. this.polygonOffset = false;
  7419. this.polygonOffsetFactor = 0;
  7420. this.polygonOffsetUnits = 0;
  7421. this.dithering = false;
  7422. this.alphaTest = 0;
  7423. this.premultipliedAlpha = false;
  7424. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  7425. this.visible = true;
  7426. this.userData = {};
  7427. this.needsUpdate = true;
  7428. }
  7429. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7430. constructor: Material,
  7431. isMaterial: true,
  7432. onBeforeCompile: function () {},
  7433. setValues: function ( values ) {
  7434. if ( values === undefined ) return;
  7435. for ( var key in values ) {
  7436. var newValue = values[ key ];
  7437. if ( newValue === undefined ) {
  7438. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7439. continue;
  7440. }
  7441. // for backward compatability if shading is set in the constructor
  7442. if ( key === 'shading' ) {
  7443. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7444. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7445. continue;
  7446. }
  7447. var currentValue = this[ key ];
  7448. if ( currentValue === undefined ) {
  7449. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7450. continue;
  7451. }
  7452. if ( currentValue && currentValue.isColor ) {
  7453. currentValue.set( newValue );
  7454. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7455. currentValue.copy( newValue );
  7456. } else if ( key === 'overdraw' ) {
  7457. // ensure overdraw is backwards-compatible with legacy boolean type
  7458. this[ key ] = Number( newValue );
  7459. } else {
  7460. this[ key ] = newValue;
  7461. }
  7462. }
  7463. },
  7464. toJSON: function ( meta ) {
  7465. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7466. if ( isRoot ) {
  7467. meta = {
  7468. textures: {},
  7469. images: {}
  7470. };
  7471. }
  7472. var data = {
  7473. metadata: {
  7474. version: 4.5,
  7475. type: 'Material',
  7476. generator: 'Material.toJSON'
  7477. }
  7478. };
  7479. // standard Material serialization
  7480. data.uuid = this.uuid;
  7481. data.type = this.type;
  7482. if ( this.name !== '' ) data.name = this.name;
  7483. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7484. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7485. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7486. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7487. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7488. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7489. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7490. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7491. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7492. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7493. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7494. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7495. if ( this.aoMap && this.aoMap.isTexture ) {
  7496. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7497. data.aoMapIntensity = this.aoMapIntensity;
  7498. }
  7499. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7500. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7501. data.bumpScale = this.bumpScale;
  7502. }
  7503. if ( this.normalMap && this.normalMap.isTexture ) {
  7504. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7505. data.normalScale = this.normalScale.toArray();
  7506. }
  7507. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7508. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7509. data.displacementScale = this.displacementScale;
  7510. data.displacementBias = this.displacementBias;
  7511. }
  7512. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7513. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7514. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7515. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7516. if ( this.envMap && this.envMap.isTexture ) {
  7517. data.envMap = this.envMap.toJSON( meta ).uuid;
  7518. data.reflectivity = this.reflectivity; // Scale behind envMap
  7519. }
  7520. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7521. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7522. }
  7523. if ( this.size !== undefined ) data.size = this.size;
  7524. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7525. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7526. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7527. if ( this.side !== FrontSide ) data.side = this.side;
  7528. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7529. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7530. if ( this.transparent === true ) data.transparent = this.transparent;
  7531. data.depthFunc = this.depthFunc;
  7532. data.depthTest = this.depthTest;
  7533. data.depthWrite = this.depthWrite;
  7534. // rotation (SpriteMaterial)
  7535. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7536. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7537. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7538. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7539. if ( this.scale !== undefined ) data.scale = this.scale;
  7540. if ( this.dithering === true ) data.dithering = true;
  7541. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7542. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7543. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7544. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7545. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7546. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7547. if ( this.morphTargets === true ) data.morphTargets = true;
  7548. if ( this.skinning === true ) data.skinning = true;
  7549. if ( this.visible === false ) data.visible = false;
  7550. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7551. // TODO: Copied from Object3D.toJSON
  7552. function extractFromCache( cache ) {
  7553. var values = [];
  7554. for ( var key in cache ) {
  7555. var data = cache[ key ];
  7556. delete data.metadata;
  7557. values.push( data );
  7558. }
  7559. return values;
  7560. }
  7561. if ( isRoot ) {
  7562. var textures = extractFromCache( meta.textures );
  7563. var images = extractFromCache( meta.images );
  7564. if ( textures.length > 0 ) data.textures = textures;
  7565. if ( images.length > 0 ) data.images = images;
  7566. }
  7567. return data;
  7568. },
  7569. clone: function () {
  7570. return new this.constructor().copy( this );
  7571. },
  7572. copy: function ( source ) {
  7573. this.name = source.name;
  7574. this.fog = source.fog;
  7575. this.lights = source.lights;
  7576. this.blending = source.blending;
  7577. this.side = source.side;
  7578. this.flatShading = source.flatShading;
  7579. this.vertexColors = source.vertexColors;
  7580. this.opacity = source.opacity;
  7581. this.transparent = source.transparent;
  7582. this.blendSrc = source.blendSrc;
  7583. this.blendDst = source.blendDst;
  7584. this.blendEquation = source.blendEquation;
  7585. this.blendSrcAlpha = source.blendSrcAlpha;
  7586. this.blendDstAlpha = source.blendDstAlpha;
  7587. this.blendEquationAlpha = source.blendEquationAlpha;
  7588. this.depthFunc = source.depthFunc;
  7589. this.depthTest = source.depthTest;
  7590. this.depthWrite = source.depthWrite;
  7591. this.colorWrite = source.colorWrite;
  7592. this.precision = source.precision;
  7593. this.polygonOffset = source.polygonOffset;
  7594. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7595. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7596. this.dithering = source.dithering;
  7597. this.alphaTest = source.alphaTest;
  7598. this.premultipliedAlpha = source.premultipliedAlpha;
  7599. this.overdraw = source.overdraw;
  7600. this.visible = source.visible;
  7601. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7602. this.clipShadows = source.clipShadows;
  7603. this.clipIntersection = source.clipIntersection;
  7604. var srcPlanes = source.clippingPlanes,
  7605. dstPlanes = null;
  7606. if ( srcPlanes !== null ) {
  7607. var n = srcPlanes.length;
  7608. dstPlanes = new Array( n );
  7609. for ( var i = 0; i !== n; ++ i )
  7610. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7611. }
  7612. this.clippingPlanes = dstPlanes;
  7613. this.shadowSide = source.shadowSide;
  7614. return this;
  7615. },
  7616. dispose: function () {
  7617. this.dispatchEvent( { type: 'dispose' } );
  7618. }
  7619. } );
  7620. /**
  7621. * @author mrdoob / http://mrdoob.com/
  7622. * @author alteredq / http://alteredqualia.com/
  7623. *
  7624. * parameters = {
  7625. * color: <hex>,
  7626. * opacity: <float>,
  7627. * map: new THREE.Texture( <Image> ),
  7628. *
  7629. * lightMap: new THREE.Texture( <Image> ),
  7630. * lightMapIntensity: <float>
  7631. *
  7632. * aoMap: new THREE.Texture( <Image> ),
  7633. * aoMapIntensity: <float>
  7634. *
  7635. * specularMap: new THREE.Texture( <Image> ),
  7636. *
  7637. * alphaMap: new THREE.Texture( <Image> ),
  7638. *
  7639. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  7640. * combine: THREE.Multiply,
  7641. * reflectivity: <float>,
  7642. * refractionRatio: <float>,
  7643. *
  7644. * depthTest: <bool>,
  7645. * depthWrite: <bool>,
  7646. *
  7647. * wireframe: <boolean>,
  7648. * wireframeLinewidth: <float>,
  7649. *
  7650. * skinning: <bool>,
  7651. * morphTargets: <bool>
  7652. * }
  7653. */
  7654. function MeshBasicMaterial( parameters ) {
  7655. Material.call( this );
  7656. this.type = 'MeshBasicMaterial';
  7657. this.color = new Color( 0xffffff ); // emissive
  7658. this.map = null;
  7659. this.lightMap = null;
  7660. this.lightMapIntensity = 1.0;
  7661. this.aoMap = null;
  7662. this.aoMapIntensity = 1.0;
  7663. this.specularMap = null;
  7664. this.alphaMap = null;
  7665. this.envMap = null;
  7666. this.combine = MultiplyOperation;
  7667. this.reflectivity = 1;
  7668. this.refractionRatio = 0.98;
  7669. this.wireframe = false;
  7670. this.wireframeLinewidth = 1;
  7671. this.wireframeLinecap = 'round';
  7672. this.wireframeLinejoin = 'round';
  7673. this.skinning = false;
  7674. this.morphTargets = false;
  7675. this.lights = false;
  7676. this.setValues( parameters );
  7677. }
  7678. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  7679. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  7680. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  7681. MeshBasicMaterial.prototype.copy = function ( source ) {
  7682. Material.prototype.copy.call( this, source );
  7683. this.color.copy( source.color );
  7684. this.map = source.map;
  7685. this.lightMap = source.lightMap;
  7686. this.lightMapIntensity = source.lightMapIntensity;
  7687. this.aoMap = source.aoMap;
  7688. this.aoMapIntensity = source.aoMapIntensity;
  7689. this.specularMap = source.specularMap;
  7690. this.alphaMap = source.alphaMap;
  7691. this.envMap = source.envMap;
  7692. this.combine = source.combine;
  7693. this.reflectivity = source.reflectivity;
  7694. this.refractionRatio = source.refractionRatio;
  7695. this.wireframe = source.wireframe;
  7696. this.wireframeLinewidth = source.wireframeLinewidth;
  7697. this.wireframeLinecap = source.wireframeLinecap;
  7698. this.wireframeLinejoin = source.wireframeLinejoin;
  7699. this.skinning = source.skinning;
  7700. this.morphTargets = source.morphTargets;
  7701. return this;
  7702. };
  7703. /**
  7704. * @author alteredq / http://alteredqualia.com/
  7705. *
  7706. * parameters = {
  7707. * defines: { "label" : "value" },
  7708. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7709. *
  7710. * fragmentShader: <string>,
  7711. * vertexShader: <string>,
  7712. *
  7713. * wireframe: <boolean>,
  7714. * wireframeLinewidth: <float>,
  7715. *
  7716. * lights: <bool>,
  7717. *
  7718. * skinning: <bool>,
  7719. * morphTargets: <bool>,
  7720. * morphNormals: <bool>
  7721. * }
  7722. */
  7723. function ShaderMaterial( parameters ) {
  7724. Material.call( this );
  7725. this.type = 'ShaderMaterial';
  7726. this.defines = {};
  7727. this.uniforms = {};
  7728. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  7729. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  7730. this.linewidth = 1;
  7731. this.wireframe = false;
  7732. this.wireframeLinewidth = 1;
  7733. this.fog = false; // set to use scene fog
  7734. this.lights = false; // set to use scene lights
  7735. this.clipping = false; // set to use user-defined clipping planes
  7736. this.skinning = false; // set to use skinning attribute streams
  7737. this.morphTargets = false; // set to use morph targets
  7738. this.morphNormals = false; // set to use morph normals
  7739. this.extensions = {
  7740. derivatives: false, // set to use derivatives
  7741. fragDepth: false, // set to use fragment depth values
  7742. drawBuffers: false, // set to use draw buffers
  7743. shaderTextureLOD: false // set to use shader texture LOD
  7744. };
  7745. // When rendered geometry doesn't include these attributes but the material does,
  7746. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7747. this.defaultAttributeValues = {
  7748. 'color': [ 1, 1, 1 ],
  7749. 'uv': [ 0, 0 ],
  7750. 'uv2': [ 0, 0 ]
  7751. };
  7752. this.index0AttributeName = undefined;
  7753. this.uniformsNeedUpdate = false;
  7754. if ( parameters !== undefined ) {
  7755. if ( parameters.attributes !== undefined ) {
  7756. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7757. }
  7758. this.setValues( parameters );
  7759. }
  7760. }
  7761. ShaderMaterial.prototype = Object.create( Material.prototype );
  7762. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7763. ShaderMaterial.prototype.isShaderMaterial = true;
  7764. ShaderMaterial.prototype.copy = function ( source ) {
  7765. Material.prototype.copy.call( this, source );
  7766. this.fragmentShader = source.fragmentShader;
  7767. this.vertexShader = source.vertexShader;
  7768. this.uniforms = UniformsUtils.clone( source.uniforms );
  7769. this.defines = Object.assign( {}, source.defines );
  7770. this.wireframe = source.wireframe;
  7771. this.wireframeLinewidth = source.wireframeLinewidth;
  7772. this.lights = source.lights;
  7773. this.clipping = source.clipping;
  7774. this.skinning = source.skinning;
  7775. this.morphTargets = source.morphTargets;
  7776. this.morphNormals = source.morphNormals;
  7777. this.extensions = source.extensions;
  7778. return this;
  7779. };
  7780. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7781. var data = Material.prototype.toJSON.call( this, meta );
  7782. data.uniforms = this.uniforms;
  7783. data.vertexShader = this.vertexShader;
  7784. data.fragmentShader = this.fragmentShader;
  7785. return data;
  7786. };
  7787. /**
  7788. * @author bhouston / http://clara.io
  7789. */
  7790. function Ray( origin, direction ) {
  7791. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7792. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7793. }
  7794. Object.assign( Ray.prototype, {
  7795. set: function ( origin, direction ) {
  7796. this.origin.copy( origin );
  7797. this.direction.copy( direction );
  7798. return this;
  7799. },
  7800. clone: function () {
  7801. return new this.constructor().copy( this );
  7802. },
  7803. copy: function ( ray ) {
  7804. this.origin.copy( ray.origin );
  7805. this.direction.copy( ray.direction );
  7806. return this;
  7807. },
  7808. at: function ( t, target ) {
  7809. if ( target === undefined ) {
  7810. console.warn( 'THREE.Ray: .at() target is now required' );
  7811. target = new Vector3();
  7812. }
  7813. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7814. },
  7815. lookAt: function ( v ) {
  7816. this.direction.copy( v ).sub( this.origin ).normalize();
  7817. return this;
  7818. },
  7819. recast: function () {
  7820. var v1 = new Vector3();
  7821. return function recast( t ) {
  7822. this.origin.copy( this.at( t, v1 ) );
  7823. return this;
  7824. };
  7825. }(),
  7826. closestPointToPoint: function ( point, target ) {
  7827. if ( target === undefined ) {
  7828. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7829. target = new Vector3();
  7830. }
  7831. target.subVectors( point, this.origin );
  7832. var directionDistance = target.dot( this.direction );
  7833. if ( directionDistance < 0 ) {
  7834. return target.copy( this.origin );
  7835. }
  7836. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7837. },
  7838. distanceToPoint: function ( point ) {
  7839. return Math.sqrt( this.distanceSqToPoint( point ) );
  7840. },
  7841. distanceSqToPoint: function () {
  7842. var v1 = new Vector3();
  7843. return function distanceSqToPoint( point ) {
  7844. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7845. // point behind the ray
  7846. if ( directionDistance < 0 ) {
  7847. return this.origin.distanceToSquared( point );
  7848. }
  7849. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7850. return v1.distanceToSquared( point );
  7851. };
  7852. }(),
  7853. distanceSqToSegment: function () {
  7854. var segCenter = new Vector3();
  7855. var segDir = new Vector3();
  7856. var diff = new Vector3();
  7857. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7858. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7859. // It returns the min distance between the ray and the segment
  7860. // defined by v0 and v1
  7861. // It can also set two optional targets :
  7862. // - The closest point on the ray
  7863. // - The closest point on the segment
  7864. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7865. segDir.copy( v1 ).sub( v0 ).normalize();
  7866. diff.copy( this.origin ).sub( segCenter );
  7867. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7868. var a01 = - this.direction.dot( segDir );
  7869. var b0 = diff.dot( this.direction );
  7870. var b1 = - diff.dot( segDir );
  7871. var c = diff.lengthSq();
  7872. var det = Math.abs( 1 - a01 * a01 );
  7873. var s0, s1, sqrDist, extDet;
  7874. if ( det > 0 ) {
  7875. // The ray and segment are not parallel.
  7876. s0 = a01 * b1 - b0;
  7877. s1 = a01 * b0 - b1;
  7878. extDet = segExtent * det;
  7879. if ( s0 >= 0 ) {
  7880. if ( s1 >= - extDet ) {
  7881. if ( s1 <= extDet ) {
  7882. // region 0
  7883. // Minimum at interior points of ray and segment.
  7884. var invDet = 1 / det;
  7885. s0 *= invDet;
  7886. s1 *= invDet;
  7887. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  7888. } else {
  7889. // region 1
  7890. s1 = segExtent;
  7891. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7892. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7893. }
  7894. } else {
  7895. // region 5
  7896. s1 = - segExtent;
  7897. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7898. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7899. }
  7900. } else {
  7901. if ( s1 <= - extDet ) {
  7902. // region 4
  7903. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  7904. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7905. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7906. } else if ( s1 <= extDet ) {
  7907. // region 3
  7908. s0 = 0;
  7909. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7910. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  7911. } else {
  7912. // region 2
  7913. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  7914. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7915. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7916. }
  7917. }
  7918. } else {
  7919. // Ray and segment are parallel.
  7920. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  7921. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7922. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7923. }
  7924. if ( optionalPointOnRay ) {
  7925. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  7926. }
  7927. if ( optionalPointOnSegment ) {
  7928. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  7929. }
  7930. return sqrDist;
  7931. };
  7932. }(),
  7933. intersectSphere: function () {
  7934. var v1 = new Vector3();
  7935. return function intersectSphere( sphere, target ) {
  7936. v1.subVectors( sphere.center, this.origin );
  7937. var tca = v1.dot( this.direction );
  7938. var d2 = v1.dot( v1 ) - tca * tca;
  7939. var radius2 = sphere.radius * sphere.radius;
  7940. if ( d2 > radius2 ) return null;
  7941. var thc = Math.sqrt( radius2 - d2 );
  7942. // t0 = first intersect point - entrance on front of sphere
  7943. var t0 = tca - thc;
  7944. // t1 = second intersect point - exit point on back of sphere
  7945. var t1 = tca + thc;
  7946. // test to see if both t0 and t1 are behind the ray - if so, return null
  7947. if ( t0 < 0 && t1 < 0 ) return null;
  7948. // test to see if t0 is behind the ray:
  7949. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  7950. // in order to always return an intersect point that is in front of the ray.
  7951. if ( t0 < 0 ) return this.at( t1, target );
  7952. // else t0 is in front of the ray, so return the first collision point scaled by t0
  7953. return this.at( t0, target );
  7954. };
  7955. }(),
  7956. intersectsSphere: function ( sphere ) {
  7957. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  7958. },
  7959. distanceToPlane: function ( plane ) {
  7960. var denominator = plane.normal.dot( this.direction );
  7961. if ( denominator === 0 ) {
  7962. // line is coplanar, return origin
  7963. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  7964. return 0;
  7965. }
  7966. // Null is preferable to undefined since undefined means.... it is undefined
  7967. return null;
  7968. }
  7969. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  7970. // Return if the ray never intersects the plane
  7971. return t >= 0 ? t : null;
  7972. },
  7973. intersectPlane: function ( plane, target ) {
  7974. var t = this.distanceToPlane( plane );
  7975. if ( t === null ) {
  7976. return null;
  7977. }
  7978. return this.at( t, target );
  7979. },
  7980. intersectsPlane: function ( plane ) {
  7981. // check if the ray lies on the plane first
  7982. var distToPoint = plane.distanceToPoint( this.origin );
  7983. if ( distToPoint === 0 ) {
  7984. return true;
  7985. }
  7986. var denominator = plane.normal.dot( this.direction );
  7987. if ( denominator * distToPoint < 0 ) {
  7988. return true;
  7989. }
  7990. // ray origin is behind the plane (and is pointing behind it)
  7991. return false;
  7992. },
  7993. intersectBox: function ( box, target ) {
  7994. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  7995. var invdirx = 1 / this.direction.x,
  7996. invdiry = 1 / this.direction.y,
  7997. invdirz = 1 / this.direction.z;
  7998. var origin = this.origin;
  7999. if ( invdirx >= 0 ) {
  8000. tmin = ( box.min.x - origin.x ) * invdirx;
  8001. tmax = ( box.max.x - origin.x ) * invdirx;
  8002. } else {
  8003. tmin = ( box.max.x - origin.x ) * invdirx;
  8004. tmax = ( box.min.x - origin.x ) * invdirx;
  8005. }
  8006. if ( invdiry >= 0 ) {
  8007. tymin = ( box.min.y - origin.y ) * invdiry;
  8008. tymax = ( box.max.y - origin.y ) * invdiry;
  8009. } else {
  8010. tymin = ( box.max.y - origin.y ) * invdiry;
  8011. tymax = ( box.min.y - origin.y ) * invdiry;
  8012. }
  8013. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8014. // These lines also handle the case where tmin or tmax is NaN
  8015. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8016. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8017. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8018. if ( invdirz >= 0 ) {
  8019. tzmin = ( box.min.z - origin.z ) * invdirz;
  8020. tzmax = ( box.max.z - origin.z ) * invdirz;
  8021. } else {
  8022. tzmin = ( box.max.z - origin.z ) * invdirz;
  8023. tzmax = ( box.min.z - origin.z ) * invdirz;
  8024. }
  8025. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8026. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8027. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8028. //return point closest to the ray (positive side)
  8029. if ( tmax < 0 ) return null;
  8030. return this.at( tmin >= 0 ? tmin : tmax, target );
  8031. },
  8032. intersectsBox: ( function () {
  8033. var v = new Vector3();
  8034. return function intersectsBox( box ) {
  8035. return this.intersectBox( box, v ) !== null;
  8036. };
  8037. } )(),
  8038. intersectTriangle: function () {
  8039. // Compute the offset origin, edges, and normal.
  8040. var diff = new Vector3();
  8041. var edge1 = new Vector3();
  8042. var edge2 = new Vector3();
  8043. var normal = new Vector3();
  8044. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8045. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8046. edge1.subVectors( b, a );
  8047. edge2.subVectors( c, a );
  8048. normal.crossVectors( edge1, edge2 );
  8049. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8050. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8051. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8052. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8053. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8054. var DdN = this.direction.dot( normal );
  8055. var sign;
  8056. if ( DdN > 0 ) {
  8057. if ( backfaceCulling ) return null;
  8058. sign = 1;
  8059. } else if ( DdN < 0 ) {
  8060. sign = - 1;
  8061. DdN = - DdN;
  8062. } else {
  8063. return null;
  8064. }
  8065. diff.subVectors( this.origin, a );
  8066. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8067. // b1 < 0, no intersection
  8068. if ( DdQxE2 < 0 ) {
  8069. return null;
  8070. }
  8071. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8072. // b2 < 0, no intersection
  8073. if ( DdE1xQ < 0 ) {
  8074. return null;
  8075. }
  8076. // b1+b2 > 1, no intersection
  8077. if ( DdQxE2 + DdE1xQ > DdN ) {
  8078. return null;
  8079. }
  8080. // Line intersects triangle, check if ray does.
  8081. var QdN = - sign * diff.dot( normal );
  8082. // t < 0, no intersection
  8083. if ( QdN < 0 ) {
  8084. return null;
  8085. }
  8086. // Ray intersects triangle.
  8087. return this.at( QdN / DdN, target );
  8088. };
  8089. }(),
  8090. applyMatrix4: function ( matrix4 ) {
  8091. this.origin.applyMatrix4( matrix4 );
  8092. this.direction.transformDirection( matrix4 );
  8093. return this;
  8094. },
  8095. equals: function ( ray ) {
  8096. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8097. }
  8098. } );
  8099. /**
  8100. * @author bhouston / http://clara.io
  8101. */
  8102. function Line3( start, end ) {
  8103. this.start = ( start !== undefined ) ? start : new Vector3();
  8104. this.end = ( end !== undefined ) ? end : new Vector3();
  8105. }
  8106. Object.assign( Line3.prototype, {
  8107. set: function ( start, end ) {
  8108. this.start.copy( start );
  8109. this.end.copy( end );
  8110. return this;
  8111. },
  8112. clone: function () {
  8113. return new this.constructor().copy( this );
  8114. },
  8115. copy: function ( line ) {
  8116. this.start.copy( line.start );
  8117. this.end.copy( line.end );
  8118. return this;
  8119. },
  8120. getCenter: function ( target ) {
  8121. if ( target === undefined ) {
  8122. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  8123. target = new Vector3();
  8124. }
  8125. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  8126. },
  8127. delta: function ( target ) {
  8128. if ( target === undefined ) {
  8129. console.warn( 'THREE.Line3: .delta() target is now required' );
  8130. target = new Vector3();
  8131. }
  8132. return target.subVectors( this.end, this.start );
  8133. },
  8134. distanceSq: function () {
  8135. return this.start.distanceToSquared( this.end );
  8136. },
  8137. distance: function () {
  8138. return this.start.distanceTo( this.end );
  8139. },
  8140. at: function ( t, target ) {
  8141. if ( target === undefined ) {
  8142. console.warn( 'THREE.Line3: .at() target is now required' );
  8143. target = new Vector3();
  8144. }
  8145. return this.delta( target ).multiplyScalar( t ).add( this.start );
  8146. },
  8147. closestPointToPointParameter: function () {
  8148. var startP = new Vector3();
  8149. var startEnd = new Vector3();
  8150. return function closestPointToPointParameter( point, clampToLine ) {
  8151. startP.subVectors( point, this.start );
  8152. startEnd.subVectors( this.end, this.start );
  8153. var startEnd2 = startEnd.dot( startEnd );
  8154. var startEnd_startP = startEnd.dot( startP );
  8155. var t = startEnd_startP / startEnd2;
  8156. if ( clampToLine ) {
  8157. t = _Math.clamp( t, 0, 1 );
  8158. }
  8159. return t;
  8160. };
  8161. }(),
  8162. closestPointToPoint: function ( point, clampToLine, target ) {
  8163. var t = this.closestPointToPointParameter( point, clampToLine );
  8164. if ( target === undefined ) {
  8165. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  8166. target = new Vector3();
  8167. }
  8168. return this.delta( target ).multiplyScalar( t ).add( this.start );
  8169. },
  8170. applyMatrix4: function ( matrix ) {
  8171. this.start.applyMatrix4( matrix );
  8172. this.end.applyMatrix4( matrix );
  8173. return this;
  8174. },
  8175. equals: function ( line ) {
  8176. return line.start.equals( this.start ) && line.end.equals( this.end );
  8177. }
  8178. } );
  8179. /**
  8180. * @author bhouston / http://clara.io
  8181. * @author mrdoob / http://mrdoob.com/
  8182. */
  8183. function Triangle( a, b, c ) {
  8184. this.a = ( a !== undefined ) ? a : new Vector3();
  8185. this.b = ( b !== undefined ) ? b : new Vector3();
  8186. this.c = ( c !== undefined ) ? c : new Vector3();
  8187. }
  8188. Object.assign( Triangle, {
  8189. getNormal: function () {
  8190. var v0 = new Vector3();
  8191. return function getNormal( a, b, c, target ) {
  8192. if ( target === undefined ) {
  8193. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8194. target = new Vector3();
  8195. }
  8196. target.subVectors( c, b );
  8197. v0.subVectors( a, b );
  8198. target.cross( v0 );
  8199. var targetLengthSq = target.lengthSq();
  8200. if ( targetLengthSq > 0 ) {
  8201. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8202. }
  8203. return target.set( 0, 0, 0 );
  8204. };
  8205. }(),
  8206. // static/instance method to calculate barycentric coordinates
  8207. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8208. getBarycoord: function () {
  8209. var v0 = new Vector3();
  8210. var v1 = new Vector3();
  8211. var v2 = new Vector3();
  8212. return function getBarycoord( point, a, b, c, target ) {
  8213. v0.subVectors( c, a );
  8214. v1.subVectors( b, a );
  8215. v2.subVectors( point, a );
  8216. var dot00 = v0.dot( v0 );
  8217. var dot01 = v0.dot( v1 );
  8218. var dot02 = v0.dot( v2 );
  8219. var dot11 = v1.dot( v1 );
  8220. var dot12 = v1.dot( v2 );
  8221. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8222. if ( target === undefined ) {
  8223. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8224. target = new Vector3();
  8225. }
  8226. // collinear or singular triangle
  8227. if ( denom === 0 ) {
  8228. // arbitrary location outside of triangle?
  8229. // not sure if this is the best idea, maybe should be returning undefined
  8230. return target.set( - 2, - 1, - 1 );
  8231. }
  8232. var invDenom = 1 / denom;
  8233. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8234. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8235. // barycentric coordinates must always sum to 1
  8236. return target.set( 1 - u - v, v, u );
  8237. };
  8238. }(),
  8239. containsPoint: function () {
  8240. var v1 = new Vector3();
  8241. return function containsPoint( point, a, b, c ) {
  8242. Triangle.getBarycoord( point, a, b, c, v1 );
  8243. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8244. };
  8245. }()
  8246. } );
  8247. Object.assign( Triangle.prototype, {
  8248. set: function ( a, b, c ) {
  8249. this.a.copy( a );
  8250. this.b.copy( b );
  8251. this.c.copy( c );
  8252. return this;
  8253. },
  8254. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8255. this.a.copy( points[ i0 ] );
  8256. this.b.copy( points[ i1 ] );
  8257. this.c.copy( points[ i2 ] );
  8258. return this;
  8259. },
  8260. clone: function () {
  8261. return new this.constructor().copy( this );
  8262. },
  8263. copy: function ( triangle ) {
  8264. this.a.copy( triangle.a );
  8265. this.b.copy( triangle.b );
  8266. this.c.copy( triangle.c );
  8267. return this;
  8268. },
  8269. getArea: function () {
  8270. var v0 = new Vector3();
  8271. var v1 = new Vector3();
  8272. return function getArea() {
  8273. v0.subVectors( this.c, this.b );
  8274. v1.subVectors( this.a, this.b );
  8275. return v0.cross( v1 ).length() * 0.5;
  8276. };
  8277. }(),
  8278. getMidpoint: function ( target ) {
  8279. if ( target === undefined ) {
  8280. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8281. target = new Vector3();
  8282. }
  8283. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8284. },
  8285. getNormal: function ( target ) {
  8286. return Triangle.getNormal( this.a, this.b, this.c, target );
  8287. },
  8288. getPlane: function ( target ) {
  8289. if ( target === undefined ) {
  8290. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8291. target = new Vector3();
  8292. }
  8293. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8294. },
  8295. getBarycoord: function ( point, target ) {
  8296. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8297. },
  8298. containsPoint: function ( point ) {
  8299. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8300. },
  8301. intersectsBox: function ( box ) {
  8302. return box.intersectsTriangle( this );
  8303. },
  8304. closestPointToPoint: function () {
  8305. var plane = new Plane();
  8306. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  8307. var projectedPoint = new Vector3();
  8308. var closestPoint = new Vector3();
  8309. return function closestPointToPoint( point, target ) {
  8310. if ( target === undefined ) {
  8311. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8312. target = new Vector3();
  8313. }
  8314. var minDistance = Infinity;
  8315. // project the point onto the plane of the triangle
  8316. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  8317. plane.projectPoint( point, projectedPoint );
  8318. // check if the projection lies within the triangle
  8319. if ( this.containsPoint( projectedPoint ) === true ) {
  8320. // if so, this is the closest point
  8321. target.copy( projectedPoint );
  8322. } else {
  8323. // if not, the point falls outside the triangle. the target is the closest point to the triangle's edges or vertices
  8324. edgeList[ 0 ].set( this.a, this.b );
  8325. edgeList[ 1 ].set( this.b, this.c );
  8326. edgeList[ 2 ].set( this.c, this.a );
  8327. for ( var i = 0; i < edgeList.length; i ++ ) {
  8328. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  8329. var distance = projectedPoint.distanceToSquared( closestPoint );
  8330. if ( distance < minDistance ) {
  8331. minDistance = distance;
  8332. target.copy( closestPoint );
  8333. }
  8334. }
  8335. }
  8336. return target;
  8337. };
  8338. }(),
  8339. equals: function ( triangle ) {
  8340. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8341. }
  8342. } );
  8343. /**
  8344. * @author mrdoob / http://mrdoob.com/
  8345. * @author alteredq / http://alteredqualia.com/
  8346. * @author mikael emtinger / http://gomo.se/
  8347. * @author jonobr1 / http://jonobr1.com/
  8348. */
  8349. function Mesh( geometry, material ) {
  8350. Object3D.call( this );
  8351. this.type = 'Mesh';
  8352. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8353. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8354. this.drawMode = TrianglesDrawMode;
  8355. this.updateMorphTargets();
  8356. }
  8357. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8358. constructor: Mesh,
  8359. isMesh: true,
  8360. setDrawMode: function ( value ) {
  8361. this.drawMode = value;
  8362. },
  8363. copy: function ( source ) {
  8364. Object3D.prototype.copy.call( this, source );
  8365. this.drawMode = source.drawMode;
  8366. if ( source.morphTargetInfluences !== undefined ) {
  8367. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8368. }
  8369. if ( source.morphTargetDictionary !== undefined ) {
  8370. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8371. }
  8372. return this;
  8373. },
  8374. updateMorphTargets: function () {
  8375. var geometry = this.geometry;
  8376. var m, ml, name;
  8377. if ( geometry.isBufferGeometry ) {
  8378. var morphAttributes = geometry.morphAttributes;
  8379. var keys = Object.keys( morphAttributes );
  8380. if ( keys.length > 0 ) {
  8381. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8382. if ( morphAttribute !== undefined ) {
  8383. this.morphTargetInfluences = [];
  8384. this.morphTargetDictionary = {};
  8385. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8386. name = morphAttribute[ m ].name || String( m );
  8387. this.morphTargetInfluences.push( 0 );
  8388. this.morphTargetDictionary[ name ] = m;
  8389. }
  8390. }
  8391. }
  8392. } else {
  8393. var morphTargets = geometry.morphTargets;
  8394. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8395. this.morphTargetInfluences = [];
  8396. this.morphTargetDictionary = {};
  8397. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  8398. name = morphTargets[ m ].name || String( m );
  8399. this.morphTargetInfluences.push( 0 );
  8400. this.morphTargetDictionary[ name ] = m;
  8401. }
  8402. }
  8403. }
  8404. },
  8405. raycast: ( function () {
  8406. var inverseMatrix = new Matrix4();
  8407. var ray = new Ray();
  8408. var sphere = new Sphere();
  8409. var vA = new Vector3();
  8410. var vB = new Vector3();
  8411. var vC = new Vector3();
  8412. var tempA = new Vector3();
  8413. var tempB = new Vector3();
  8414. var tempC = new Vector3();
  8415. var uvA = new Vector2();
  8416. var uvB = new Vector2();
  8417. var uvC = new Vector2();
  8418. var barycoord = new Vector3();
  8419. var intersectionPoint = new Vector3();
  8420. var intersectionPointWorld = new Vector3();
  8421. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  8422. Triangle.getBarycoord( point, p1, p2, p3, barycoord );
  8423. uv1.multiplyScalar( barycoord.x );
  8424. uv2.multiplyScalar( barycoord.y );
  8425. uv3.multiplyScalar( barycoord.z );
  8426. uv1.add( uv2 ).add( uv3 );
  8427. return uv1.clone();
  8428. }
  8429. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8430. var intersect;
  8431. if ( material.side === BackSide ) {
  8432. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8433. } else {
  8434. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8435. }
  8436. if ( intersect === null ) return null;
  8437. intersectionPointWorld.copy( point );
  8438. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8439. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8440. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8441. return {
  8442. distance: distance,
  8443. point: intersectionPointWorld.clone(),
  8444. object: object
  8445. };
  8446. }
  8447. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  8448. vA.fromBufferAttribute( position, a );
  8449. vB.fromBufferAttribute( position, b );
  8450. vC.fromBufferAttribute( position, c );
  8451. var intersection = checkIntersection( object, object.material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8452. if ( intersection ) {
  8453. if ( uv ) {
  8454. uvA.fromBufferAttribute( uv, a );
  8455. uvB.fromBufferAttribute( uv, b );
  8456. uvC.fromBufferAttribute( uv, c );
  8457. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  8458. }
  8459. var face = new Face3( a, b, c );
  8460. Triangle.getNormal( vA, vB, vC, face.normal );
  8461. intersection.face = face;
  8462. }
  8463. return intersection;
  8464. }
  8465. return function raycast( raycaster, intersects ) {
  8466. var geometry = this.geometry;
  8467. var material = this.material;
  8468. var matrixWorld = this.matrixWorld;
  8469. if ( material === undefined ) return;
  8470. // Checking boundingSphere distance to ray
  8471. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8472. sphere.copy( geometry.boundingSphere );
  8473. sphere.applyMatrix4( matrixWorld );
  8474. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8475. //
  8476. inverseMatrix.getInverse( matrixWorld );
  8477. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8478. // Check boundingBox before continuing
  8479. if ( geometry.boundingBox !== null ) {
  8480. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8481. }
  8482. var intersection;
  8483. if ( geometry.isBufferGeometry ) {
  8484. var a, b, c;
  8485. var index = geometry.index;
  8486. var position = geometry.attributes.position;
  8487. var uv = geometry.attributes.uv;
  8488. var i, l;
  8489. if ( index !== null ) {
  8490. // indexed buffer geometry
  8491. for ( i = 0, l = index.count; i < l; i += 3 ) {
  8492. a = index.getX( i );
  8493. b = index.getX( i + 1 );
  8494. c = index.getX( i + 2 );
  8495. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  8496. if ( intersection ) {
  8497. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8498. intersects.push( intersection );
  8499. }
  8500. }
  8501. } else if ( position !== undefined ) {
  8502. // non-indexed buffer geometry
  8503. for ( i = 0, l = position.count; i < l; i += 3 ) {
  8504. a = i;
  8505. b = i + 1;
  8506. c = i + 2;
  8507. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  8508. if ( intersection ) {
  8509. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8510. intersects.push( intersection );
  8511. }
  8512. }
  8513. }
  8514. } else if ( geometry.isGeometry ) {
  8515. var fvA, fvB, fvC;
  8516. var isMultiMaterial = Array.isArray( material );
  8517. var vertices = geometry.vertices;
  8518. var faces = geometry.faces;
  8519. var uvs;
  8520. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8521. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8522. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8523. var face = faces[ f ];
  8524. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8525. if ( faceMaterial === undefined ) continue;
  8526. fvA = vertices[ face.a ];
  8527. fvB = vertices[ face.b ];
  8528. fvC = vertices[ face.c ];
  8529. if ( faceMaterial.morphTargets === true ) {
  8530. var morphTargets = geometry.morphTargets;
  8531. var morphInfluences = this.morphTargetInfluences;
  8532. vA.set( 0, 0, 0 );
  8533. vB.set( 0, 0, 0 );
  8534. vC.set( 0, 0, 0 );
  8535. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  8536. var influence = morphInfluences[ t ];
  8537. if ( influence === 0 ) continue;
  8538. var targets = morphTargets[ t ].vertices;
  8539. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  8540. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  8541. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  8542. }
  8543. vA.add( fvA );
  8544. vB.add( fvB );
  8545. vC.add( fvC );
  8546. fvA = vA;
  8547. fvB = vB;
  8548. fvC = vC;
  8549. }
  8550. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8551. if ( intersection ) {
  8552. if ( uvs && uvs[ f ] ) {
  8553. var uvs_f = uvs[ f ];
  8554. uvA.copy( uvs_f[ 0 ] );
  8555. uvB.copy( uvs_f[ 1 ] );
  8556. uvC.copy( uvs_f[ 2 ] );
  8557. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  8558. }
  8559. intersection.face = face;
  8560. intersection.faceIndex = f;
  8561. intersects.push( intersection );
  8562. }
  8563. }
  8564. }
  8565. };
  8566. }() ),
  8567. clone: function () {
  8568. return new this.constructor( this.geometry, this.material ).copy( this );
  8569. }
  8570. } );
  8571. /**
  8572. * @author mrdoob / http://mrdoob.com/
  8573. */
  8574. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8575. var clearColor = new Color( 0x000000 );
  8576. var clearAlpha = 0;
  8577. var planeCamera, planeMesh;
  8578. var boxMesh;
  8579. function render( renderList, scene, camera, forceClear ) {
  8580. var background = scene.background;
  8581. if ( background === null ) {
  8582. setClear( clearColor, clearAlpha );
  8583. } else if ( background && background.isColor ) {
  8584. setClear( background, 1 );
  8585. forceClear = true;
  8586. }
  8587. if ( renderer.autoClear || forceClear ) {
  8588. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8589. }
  8590. if ( background && background.isCubeTexture ) {
  8591. if ( boxMesh === undefined ) {
  8592. boxMesh = new Mesh(
  8593. new BoxBufferGeometry( 1, 1, 1 ),
  8594. new ShaderMaterial( {
  8595. uniforms: ShaderLib.cube.uniforms,
  8596. vertexShader: ShaderLib.cube.vertexShader,
  8597. fragmentShader: ShaderLib.cube.fragmentShader,
  8598. side: BackSide,
  8599. depthTest: true,
  8600. depthWrite: false,
  8601. fog: false
  8602. } )
  8603. );
  8604. boxMesh.geometry.removeAttribute( 'normal' );
  8605. boxMesh.geometry.removeAttribute( 'uv' );
  8606. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8607. this.matrixWorld.copyPosition( camera.matrixWorld );
  8608. };
  8609. objects.update( boxMesh );
  8610. }
  8611. boxMesh.material.uniforms.tCube.value = background;
  8612. renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
  8613. } else if ( background && background.isTexture ) {
  8614. if ( planeCamera === undefined ) {
  8615. planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  8616. planeMesh = new Mesh(
  8617. new PlaneBufferGeometry( 2, 2 ),
  8618. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  8619. );
  8620. objects.update( planeMesh );
  8621. }
  8622. planeMesh.material.map = background;
  8623. // TODO Push this to renderList
  8624. renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
  8625. }
  8626. }
  8627. function setClear( color, alpha ) {
  8628. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8629. }
  8630. return {
  8631. getClearColor: function () {
  8632. return clearColor;
  8633. },
  8634. setClearColor: function ( color, alpha ) {
  8635. clearColor.set( color );
  8636. clearAlpha = alpha !== undefined ? alpha : 1;
  8637. setClear( clearColor, clearAlpha );
  8638. },
  8639. getClearAlpha: function () {
  8640. return clearAlpha;
  8641. },
  8642. setClearAlpha: function ( alpha ) {
  8643. clearAlpha = alpha;
  8644. setClear( clearColor, clearAlpha );
  8645. },
  8646. render: render
  8647. };
  8648. }
  8649. /**
  8650. * @author mrdoob / http://mrdoob.com/
  8651. */
  8652. function WebGLBufferRenderer( gl, extensions, info ) {
  8653. var mode;
  8654. function setMode( value ) {
  8655. mode = value;
  8656. }
  8657. function render( start, count ) {
  8658. gl.drawArrays( mode, start, count );
  8659. info.update( count, mode );
  8660. }
  8661. function renderInstances( geometry, start, count ) {
  8662. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  8663. if ( extension === null ) {
  8664. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8665. return;
  8666. }
  8667. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  8668. info.update( count, mode, geometry.maxInstancedCount );
  8669. }
  8670. //
  8671. this.setMode = setMode;
  8672. this.render = render;
  8673. this.renderInstances = renderInstances;
  8674. }
  8675. /**
  8676. * @author mrdoob / http://mrdoob.com/
  8677. */
  8678. function WebGLCapabilities( gl, extensions, parameters ) {
  8679. var maxAnisotropy;
  8680. function getMaxAnisotropy() {
  8681. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8682. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8683. if ( extension !== null ) {
  8684. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8685. } else {
  8686. maxAnisotropy = 0;
  8687. }
  8688. return maxAnisotropy;
  8689. }
  8690. function getMaxPrecision( precision ) {
  8691. if ( precision === 'highp' ) {
  8692. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  8693. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  8694. return 'highp';
  8695. }
  8696. precision = 'mediump';
  8697. }
  8698. if ( precision === 'mediump' ) {
  8699. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  8700. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  8701. return 'mediump';
  8702. }
  8703. }
  8704. return 'lowp';
  8705. }
  8706. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8707. var maxPrecision = getMaxPrecision( precision );
  8708. if ( maxPrecision !== precision ) {
  8709. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8710. precision = maxPrecision;
  8711. }
  8712. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8713. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  8714. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  8715. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  8716. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  8717. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  8718. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  8719. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  8720. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  8721. var vertexTextures = maxVertexTextures > 0;
  8722. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  8723. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8724. return {
  8725. getMaxAnisotropy: getMaxAnisotropy,
  8726. getMaxPrecision: getMaxPrecision,
  8727. precision: precision,
  8728. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8729. maxTextures: maxTextures,
  8730. maxVertexTextures: maxVertexTextures,
  8731. maxTextureSize: maxTextureSize,
  8732. maxCubemapSize: maxCubemapSize,
  8733. maxAttributes: maxAttributes,
  8734. maxVertexUniforms: maxVertexUniforms,
  8735. maxVaryings: maxVaryings,
  8736. maxFragmentUniforms: maxFragmentUniforms,
  8737. vertexTextures: vertexTextures,
  8738. floatFragmentTextures: floatFragmentTextures,
  8739. floatVertexTextures: floatVertexTextures
  8740. };
  8741. }
  8742. /**
  8743. * @author tschw
  8744. */
  8745. function WebGLClipping() {
  8746. var scope = this,
  8747. globalState = null,
  8748. numGlobalPlanes = 0,
  8749. localClippingEnabled = false,
  8750. renderingShadows = false,
  8751. plane = new Plane(),
  8752. viewNormalMatrix = new Matrix3(),
  8753. uniform = { value: null, needsUpdate: false };
  8754. this.uniform = uniform;
  8755. this.numPlanes = 0;
  8756. this.numIntersection = 0;
  8757. this.init = function ( planes, enableLocalClipping, camera ) {
  8758. var enabled =
  8759. planes.length !== 0 ||
  8760. enableLocalClipping ||
  8761. // enable state of previous frame - the clipping code has to
  8762. // run another frame in order to reset the state:
  8763. numGlobalPlanes !== 0 ||
  8764. localClippingEnabled;
  8765. localClippingEnabled = enableLocalClipping;
  8766. globalState = projectPlanes( planes, camera, 0 );
  8767. numGlobalPlanes = planes.length;
  8768. return enabled;
  8769. };
  8770. this.beginShadows = function () {
  8771. renderingShadows = true;
  8772. projectPlanes( null );
  8773. };
  8774. this.endShadows = function () {
  8775. renderingShadows = false;
  8776. resetGlobalState();
  8777. };
  8778. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  8779. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8780. // there's no local clipping
  8781. if ( renderingShadows ) {
  8782. // there's no global clipping
  8783. projectPlanes( null );
  8784. } else {
  8785. resetGlobalState();
  8786. }
  8787. } else {
  8788. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8789. lGlobal = nGlobal * 4,
  8790. dstArray = cache.clippingState || null;
  8791. uniform.value = dstArray; // ensure unique state
  8792. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  8793. for ( var i = 0; i !== lGlobal; ++ i ) {
  8794. dstArray[ i ] = globalState[ i ];
  8795. }
  8796. cache.clippingState = dstArray;
  8797. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8798. this.numPlanes += nGlobal;
  8799. }
  8800. };
  8801. function resetGlobalState() {
  8802. if ( uniform.value !== globalState ) {
  8803. uniform.value = globalState;
  8804. uniform.needsUpdate = numGlobalPlanes > 0;
  8805. }
  8806. scope.numPlanes = numGlobalPlanes;
  8807. scope.numIntersection = 0;
  8808. }
  8809. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8810. var nPlanes = planes !== null ? planes.length : 0,
  8811. dstArray = null;
  8812. if ( nPlanes !== 0 ) {
  8813. dstArray = uniform.value;
  8814. if ( skipTransform !== true || dstArray === null ) {
  8815. var flatSize = dstOffset + nPlanes * 4,
  8816. viewMatrix = camera.matrixWorldInverse;
  8817. viewNormalMatrix.getNormalMatrix( viewMatrix );
  8818. if ( dstArray === null || dstArray.length < flatSize ) {
  8819. dstArray = new Float32Array( flatSize );
  8820. }
  8821. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  8822. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  8823. plane.normal.toArray( dstArray, i4 );
  8824. dstArray[ i4 + 3 ] = plane.constant;
  8825. }
  8826. }
  8827. uniform.value = dstArray;
  8828. uniform.needsUpdate = true;
  8829. }
  8830. scope.numPlanes = nPlanes;
  8831. return dstArray;
  8832. }
  8833. }
  8834. /**
  8835. * @author mrdoob / http://mrdoob.com/
  8836. */
  8837. function WebGLExtensions( gl ) {
  8838. var extensions = {};
  8839. return {
  8840. get: function ( name ) {
  8841. if ( extensions[ name ] !== undefined ) {
  8842. return extensions[ name ];
  8843. }
  8844. var extension;
  8845. switch ( name ) {
  8846. case 'WEBGL_depth_texture':
  8847. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  8848. break;
  8849. case 'EXT_texture_filter_anisotropic':
  8850. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  8851. break;
  8852. case 'WEBGL_compressed_texture_s3tc':
  8853. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  8854. break;
  8855. case 'WEBGL_compressed_texture_pvrtc':
  8856. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  8857. break;
  8858. default:
  8859. extension = gl.getExtension( name );
  8860. }
  8861. if ( extension === null ) {
  8862. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  8863. }
  8864. extensions[ name ] = extension;
  8865. return extension;
  8866. }
  8867. };
  8868. }
  8869. /**
  8870. * @author mrdoob / http://mrdoob.com/
  8871. */
  8872. function WebGLGeometries( gl, attributes, info ) {
  8873. var geometries = {};
  8874. var wireframeAttributes = {};
  8875. function onGeometryDispose( event ) {
  8876. var geometry = event.target;
  8877. var buffergeometry = geometries[ geometry.id ];
  8878. if ( buffergeometry.index !== null ) {
  8879. attributes.remove( buffergeometry.index );
  8880. }
  8881. for ( var name in buffergeometry.attributes ) {
  8882. attributes.remove( buffergeometry.attributes[ name ] );
  8883. }
  8884. geometry.removeEventListener( 'dispose', onGeometryDispose );
  8885. delete geometries[ geometry.id ];
  8886. // TODO Remove duplicate code
  8887. var attribute = wireframeAttributes[ geometry.id ];
  8888. if ( attribute ) {
  8889. attributes.remove( attribute );
  8890. delete wireframeAttributes[ geometry.id ];
  8891. }
  8892. attribute = wireframeAttributes[ buffergeometry.id ];
  8893. if ( attribute ) {
  8894. attributes.remove( attribute );
  8895. delete wireframeAttributes[ buffergeometry.id ];
  8896. }
  8897. //
  8898. info.memory.geometries --;
  8899. }
  8900. function get( object, geometry ) {
  8901. var buffergeometry = geometries[ geometry.id ];
  8902. if ( buffergeometry ) return buffergeometry;
  8903. geometry.addEventListener( 'dispose', onGeometryDispose );
  8904. if ( geometry.isBufferGeometry ) {
  8905. buffergeometry = geometry;
  8906. } else if ( geometry.isGeometry ) {
  8907. if ( geometry._bufferGeometry === undefined ) {
  8908. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  8909. }
  8910. buffergeometry = geometry._bufferGeometry;
  8911. }
  8912. geometries[ geometry.id ] = buffergeometry;
  8913. info.memory.geometries ++;
  8914. return buffergeometry;
  8915. }
  8916. function update( geometry ) {
  8917. var index = geometry.index;
  8918. var geometryAttributes = geometry.attributes;
  8919. if ( index !== null ) {
  8920. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  8921. }
  8922. for ( var name in geometryAttributes ) {
  8923. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  8924. }
  8925. // morph targets
  8926. var morphAttributes = geometry.morphAttributes;
  8927. for ( var name in morphAttributes ) {
  8928. var array = morphAttributes[ name ];
  8929. for ( var i = 0, l = array.length; i < l; i ++ ) {
  8930. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  8931. }
  8932. }
  8933. }
  8934. function getWireframeAttribute( geometry ) {
  8935. var attribute = wireframeAttributes[ geometry.id ];
  8936. if ( attribute ) return attribute;
  8937. var indices = [];
  8938. var geometryIndex = geometry.index;
  8939. var geometryAttributes = geometry.attributes;
  8940. // console.time( 'wireframe' );
  8941. if ( geometryIndex !== null ) {
  8942. var array = geometryIndex.array;
  8943. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  8944. var a = array[ i + 0 ];
  8945. var b = array[ i + 1 ];
  8946. var c = array[ i + 2 ];
  8947. indices.push( a, b, b, c, c, a );
  8948. }
  8949. } else {
  8950. var array = geometryAttributes.position.array;
  8951. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  8952. var a = i + 0;
  8953. var b = i + 1;
  8954. var c = i + 2;
  8955. indices.push( a, b, b, c, c, a );
  8956. }
  8957. }
  8958. // console.timeEnd( 'wireframe' );
  8959. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  8960. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  8961. wireframeAttributes[ geometry.id ] = attribute;
  8962. return attribute;
  8963. }
  8964. return {
  8965. get: get,
  8966. update: update,
  8967. getWireframeAttribute: getWireframeAttribute
  8968. };
  8969. }
  8970. /**
  8971. * @author mrdoob / http://mrdoob.com/
  8972. */
  8973. function WebGLIndexedBufferRenderer( gl, extensions, info ) {
  8974. var mode;
  8975. function setMode( value ) {
  8976. mode = value;
  8977. }
  8978. var type, bytesPerElement;
  8979. function setIndex( value ) {
  8980. type = value.type;
  8981. bytesPerElement = value.bytesPerElement;
  8982. }
  8983. function render( start, count ) {
  8984. gl.drawElements( mode, count, type, start * bytesPerElement );
  8985. info.update( count, mode );
  8986. }
  8987. function renderInstances( geometry, start, count ) {
  8988. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  8989. if ( extension === null ) {
  8990. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8991. return;
  8992. }
  8993. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  8994. info.update( count, mode, geometry.maxInstancedCount );
  8995. }
  8996. //
  8997. this.setMode = setMode;
  8998. this.setIndex = setIndex;
  8999. this.render = render;
  9000. this.renderInstances = renderInstances;
  9001. }
  9002. /**
  9003. * @author Mugen87 / https://github.com/Mugen87
  9004. */
  9005. function WebGLInfo( gl ) {
  9006. var memory = {
  9007. geometries: 0,
  9008. textures: 0
  9009. };
  9010. var render = {
  9011. frame: 0,
  9012. calls: 0,
  9013. triangles: 0,
  9014. points: 0,
  9015. lines: 0
  9016. };
  9017. function update( count, mode, instanceCount ) {
  9018. instanceCount = instanceCount || 1;
  9019. render.calls ++;
  9020. switch ( mode ) {
  9021. case gl.TRIANGLES:
  9022. render.triangles += instanceCount * ( count / 3 );
  9023. break;
  9024. case gl.TRIANGLE_STRIP:
  9025. case gl.TRIANGLE_FAN:
  9026. render.triangles += instanceCount * ( count - 2 );
  9027. break;
  9028. case gl.LINES:
  9029. render.lines += instanceCount * ( count / 2 );
  9030. break;
  9031. case gl.LINE_STRIP:
  9032. render.lines += instanceCount * ( count - 1 );
  9033. break;
  9034. case gl.LINE_LOOP:
  9035. render.lines += instanceCount * count;
  9036. break;
  9037. case gl.POINTS:
  9038. render.points += instanceCount * count;
  9039. break;
  9040. default:
  9041. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9042. break;
  9043. }
  9044. }
  9045. function reset() {
  9046. render.frame ++;
  9047. render.calls = 0;
  9048. render.triangles = 0;
  9049. render.points = 0;
  9050. render.lines = 0;
  9051. }
  9052. return {
  9053. memory: memory,
  9054. render: render,
  9055. programs: null,
  9056. autoReset: true,
  9057. reset: reset,
  9058. update: update
  9059. };
  9060. }
  9061. /**
  9062. * @author mrdoob / http://mrdoob.com/
  9063. */
  9064. function absNumericalSort( a, b ) {
  9065. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9066. }
  9067. function WebGLMorphtargets( gl ) {
  9068. var influencesList = {};
  9069. var morphInfluences = new Float32Array( 8 );
  9070. function update( object, geometry, material, program ) {
  9071. var objectInfluences = object.morphTargetInfluences;
  9072. var length = objectInfluences.length;
  9073. var influences = influencesList[ geometry.id ];
  9074. if ( influences === undefined ) {
  9075. // initialise list
  9076. influences = [];
  9077. for ( var i = 0; i < length; i ++ ) {
  9078. influences[ i ] = [ i, 0 ];
  9079. }
  9080. influencesList[ geometry.id ] = influences;
  9081. }
  9082. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9083. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9084. // Remove current morphAttributes
  9085. for ( var i = 0; i < length; i ++ ) {
  9086. var influence = influences[ i ];
  9087. if ( influence[ 1 ] !== 0 ) {
  9088. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9089. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9090. }
  9091. }
  9092. // Collect influences
  9093. for ( var i = 0; i < length; i ++ ) {
  9094. var influence = influences[ i ];
  9095. influence[ 0 ] = i;
  9096. influence[ 1 ] = objectInfluences[ i ];
  9097. }
  9098. influences.sort( absNumericalSort );
  9099. // Add morphAttributes
  9100. for ( var i = 0; i < 8; i ++ ) {
  9101. var influence = influences[ i ];
  9102. if ( influence ) {
  9103. var index = influence[ 0 ];
  9104. var value = influence[ 1 ];
  9105. if ( value ) {
  9106. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9107. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9108. morphInfluences[ i ] = value;
  9109. continue;
  9110. }
  9111. }
  9112. morphInfluences[ i ] = 0;
  9113. }
  9114. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9115. }
  9116. return {
  9117. update: update
  9118. };
  9119. }
  9120. /**
  9121. * @author mrdoob / http://mrdoob.com/
  9122. */
  9123. function WebGLObjects( geometries, info ) {
  9124. var updateList = {};
  9125. function update( object ) {
  9126. var frame = info.render.frame;
  9127. var geometry = object.geometry;
  9128. var buffergeometry = geometries.get( object, geometry );
  9129. // Update once per frame
  9130. if ( updateList[ buffergeometry.id ] !== frame ) {
  9131. if ( geometry.isGeometry ) {
  9132. buffergeometry.updateFromObject( object );
  9133. }
  9134. geometries.update( buffergeometry );
  9135. updateList[ buffergeometry.id ] = frame;
  9136. }
  9137. return buffergeometry;
  9138. }
  9139. function dispose() {
  9140. updateList = {};
  9141. }
  9142. return {
  9143. update: update,
  9144. dispose: dispose
  9145. };
  9146. }
  9147. /**
  9148. * @author mrdoob / http://mrdoob.com/
  9149. */
  9150. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9151. images = images !== undefined ? images : [];
  9152. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9153. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9154. this.flipY = false;
  9155. }
  9156. CubeTexture.prototype = Object.create( Texture.prototype );
  9157. CubeTexture.prototype.constructor = CubeTexture;
  9158. CubeTexture.prototype.isCubeTexture = true;
  9159. Object.defineProperty( CubeTexture.prototype, 'images', {
  9160. get: function () {
  9161. return this.image;
  9162. },
  9163. set: function ( value ) {
  9164. this.image = value;
  9165. }
  9166. } );
  9167. /**
  9168. * @author tschw
  9169. *
  9170. * Uniforms of a program.
  9171. * Those form a tree structure with a special top-level container for the root,
  9172. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  9173. *
  9174. *
  9175. * Properties of inner nodes including the top-level container:
  9176. *
  9177. * .seq - array of nested uniforms
  9178. * .map - nested uniforms by name
  9179. *
  9180. *
  9181. * Methods of all nodes except the top-level container:
  9182. *
  9183. * .setValue( gl, value, [renderer] )
  9184. *
  9185. * uploads a uniform value(s)
  9186. * the 'renderer' parameter is needed for sampler uniforms
  9187. *
  9188. *
  9189. * Static methods of the top-level container (renderer factorizations):
  9190. *
  9191. * .upload( gl, seq, values, renderer )
  9192. *
  9193. * sets uniforms in 'seq' to 'values[id].value'
  9194. *
  9195. * .seqWithValue( seq, values ) : filteredSeq
  9196. *
  9197. * filters 'seq' entries with corresponding entry in values
  9198. *
  9199. *
  9200. * Methods of the top-level container (renderer factorizations):
  9201. *
  9202. * .setValue( gl, name, value )
  9203. *
  9204. * sets uniform with name 'name' to 'value'
  9205. *
  9206. * .set( gl, obj, prop )
  9207. *
  9208. * sets uniform from object and property with same name than uniform
  9209. *
  9210. * .setOptional( gl, obj, prop )
  9211. *
  9212. * like .set for an optional property of the object
  9213. *
  9214. */
  9215. var emptyTexture = new Texture();
  9216. var emptyCubeTexture = new CubeTexture();
  9217. // --- Base for inner nodes (including the root) ---
  9218. function UniformContainer() {
  9219. this.seq = [];
  9220. this.map = {};
  9221. }
  9222. // --- Utilities ---
  9223. // Array Caches (provide typed arrays for temporary by size)
  9224. var arrayCacheF32 = [];
  9225. var arrayCacheI32 = [];
  9226. // Float32Array caches used for uploading Matrix uniforms
  9227. var mat4array = new Float32Array( 16 );
  9228. var mat3array = new Float32Array( 9 );
  9229. var mat2array = new Float32Array( 4 );
  9230. // Flattening for arrays of vectors and matrices
  9231. function flatten( array, nBlocks, blockSize ) {
  9232. var firstElem = array[ 0 ];
  9233. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9234. // unoptimized: ! isNaN( firstElem )
  9235. // see http://jacksondunstan.com/articles/983
  9236. var n = nBlocks * blockSize,
  9237. r = arrayCacheF32[ n ];
  9238. if ( r === undefined ) {
  9239. r = new Float32Array( n );
  9240. arrayCacheF32[ n ] = r;
  9241. }
  9242. if ( nBlocks !== 0 ) {
  9243. firstElem.toArray( r, 0 );
  9244. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9245. offset += blockSize;
  9246. array[ i ].toArray( r, offset );
  9247. }
  9248. }
  9249. return r;
  9250. }
  9251. function arraysEqual( a, b ) {
  9252. if ( a.length !== b.length ) return false;
  9253. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9254. if ( a[ i ] !== b[ i ] ) return false;
  9255. }
  9256. return true;
  9257. }
  9258. function copyArray( a, b ) {
  9259. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9260. a[ i ] = b[ i ];
  9261. }
  9262. }
  9263. // Texture unit allocation
  9264. function allocTexUnits( renderer, n ) {
  9265. var r = arrayCacheI32[ n ];
  9266. if ( r === undefined ) {
  9267. r = new Int32Array( n );
  9268. arrayCacheI32[ n ] = r;
  9269. }
  9270. for ( var i = 0; i !== n; ++ i )
  9271. r[ i ] = renderer.allocTextureUnit();
  9272. return r;
  9273. }
  9274. // --- Setters ---
  9275. // Note: Defining these methods externally, because they come in a bunch
  9276. // and this way their names minify.
  9277. // Single scalar
  9278. function setValue1f( gl, v ) {
  9279. var cache = this.cache;
  9280. if ( cache[ 0 ] === v ) return;
  9281. gl.uniform1f( this.addr, v );
  9282. cache[ 0 ] = v;
  9283. }
  9284. function setValue1i( gl, v ) {
  9285. var cache = this.cache;
  9286. if ( cache[ 0 ] === v ) return;
  9287. gl.uniform1i( this.addr, v );
  9288. cache[ 0 ] = v;
  9289. }
  9290. // Single float vector (from flat array or THREE.VectorN)
  9291. function setValue2fv( gl, v ) {
  9292. var cache = this.cache;
  9293. if ( v.x !== undefined ) {
  9294. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9295. gl.uniform2f( this.addr, v.x, v.y );
  9296. cache[ 0 ] = v.x;
  9297. cache[ 1 ] = v.y;
  9298. }
  9299. } else {
  9300. if ( arraysEqual( cache, v ) ) return;
  9301. gl.uniform2fv( this.addr, v );
  9302. copyArray( cache, v );
  9303. }
  9304. }
  9305. function setValue3fv( gl, v ) {
  9306. var cache = this.cache;
  9307. if ( v.x !== undefined ) {
  9308. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9309. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9310. cache[ 0 ] = v.x;
  9311. cache[ 1 ] = v.y;
  9312. cache[ 2 ] = v.z;
  9313. }
  9314. } else if ( v.r !== undefined ) {
  9315. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9316. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9317. cache[ 0 ] = v.r;
  9318. cache[ 1 ] = v.g;
  9319. cache[ 2 ] = v.b;
  9320. }
  9321. } else {
  9322. if ( arraysEqual( cache, v ) ) return;
  9323. gl.uniform3fv( this.addr, v );
  9324. copyArray( cache, v );
  9325. }
  9326. }
  9327. function setValue4fv( gl, v ) {
  9328. var cache = this.cache;
  9329. if ( v.x !== undefined ) {
  9330. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9331. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9332. cache[ 0 ] = v.x;
  9333. cache[ 1 ] = v.y;
  9334. cache[ 2 ] = v.z;
  9335. cache[ 3 ] = v.w;
  9336. }
  9337. } else {
  9338. if ( arraysEqual( cache, v ) ) return;
  9339. gl.uniform4fv( this.addr, v );
  9340. copyArray( cache, v );
  9341. }
  9342. }
  9343. // Single matrix (from flat array or MatrixN)
  9344. function setValue2fm( gl, v ) {
  9345. var cache = this.cache;
  9346. var elements = v.elements;
  9347. if ( elements === undefined ) {
  9348. if ( arraysEqual( cache, v ) ) return;
  9349. gl.uniformMatrix2fv( this.addr, false, v );
  9350. copyArray( cache, v );
  9351. } else {
  9352. if ( arraysEqual( cache, elements ) ) return;
  9353. mat2array.set( elements );
  9354. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9355. copyArray( cache, elements );
  9356. }
  9357. }
  9358. function setValue3fm( gl, v ) {
  9359. var cache = this.cache;
  9360. var elements = v.elements;
  9361. if ( elements === undefined ) {
  9362. if ( arraysEqual( cache, v ) ) return;
  9363. gl.uniformMatrix3fv( this.addr, false, v );
  9364. copyArray( cache, v );
  9365. } else {
  9366. if ( arraysEqual( cache, elements ) ) return;
  9367. mat3array.set( elements );
  9368. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9369. copyArray( cache, elements );
  9370. }
  9371. }
  9372. function setValue4fm( gl, v ) {
  9373. var cache = this.cache;
  9374. var elements = v.elements;
  9375. if ( elements === undefined ) {
  9376. if ( arraysEqual( cache, v ) ) return;
  9377. gl.uniformMatrix4fv( this.addr, false, v );
  9378. copyArray( cache, v );
  9379. } else {
  9380. if ( arraysEqual( cache, elements ) ) return;
  9381. mat4array.set( elements );
  9382. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9383. copyArray( cache, elements );
  9384. }
  9385. }
  9386. // Single texture (2D / Cube)
  9387. function setValueT1( gl, v, renderer ) {
  9388. var cache = this.cache;
  9389. var unit = renderer.allocTextureUnit();
  9390. if ( cache[ 0 ] !== unit ) {
  9391. gl.uniform1i( this.addr, unit );
  9392. cache[ 0 ] = unit;
  9393. }
  9394. renderer.setTexture2D( v || emptyTexture, unit );
  9395. }
  9396. function setValueT6( gl, v, renderer ) {
  9397. var cache = this.cache;
  9398. var unit = renderer.allocTextureUnit();
  9399. if ( cache[ 0 ] !== unit ) {
  9400. gl.uniform1i( this.addr, unit );
  9401. cache[ 0 ] = unit;
  9402. }
  9403. renderer.setTextureCube( v || emptyCubeTexture, unit );
  9404. }
  9405. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9406. function setValue2iv( gl, v ) {
  9407. var cache = this.cache;
  9408. if ( arraysEqual( cache, v ) ) return;
  9409. gl.uniform2iv( this.addr, v );
  9410. copyArray( cache, v );
  9411. }
  9412. function setValue3iv( gl, v ) {
  9413. var cache = this.cache;
  9414. if ( arraysEqual( cache, v ) ) return;
  9415. gl.uniform3iv( this.addr, v );
  9416. copyArray( cache, v );
  9417. }
  9418. function setValue4iv( gl, v ) {
  9419. var cache = this.cache;
  9420. if ( arraysEqual( cache, v ) ) return;
  9421. gl.uniform4iv( this.addr, v );
  9422. copyArray( cache, v );
  9423. }
  9424. // Helper to pick the right setter for the singular case
  9425. function getSingularSetter( type ) {
  9426. switch ( type ) {
  9427. case 0x1406: return setValue1f; // FLOAT
  9428. case 0x8b50: return setValue2fv; // _VEC2
  9429. case 0x8b51: return setValue3fv; // _VEC3
  9430. case 0x8b52: return setValue4fv; // _VEC4
  9431. case 0x8b5a: return setValue2fm; // _MAT2
  9432. case 0x8b5b: return setValue3fm; // _MAT3
  9433. case 0x8b5c: return setValue4fm; // _MAT4
  9434. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9435. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9436. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9437. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9438. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9439. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9440. }
  9441. }
  9442. // Array of scalars
  9443. function setValue1fv( gl, v ) {
  9444. var cache = this.cache;
  9445. if ( arraysEqual( cache, v ) ) return;
  9446. gl.uniform1fv( this.addr, v );
  9447. copyArray( cache, v );
  9448. }
  9449. function setValue1iv( gl, v ) {
  9450. var cache = this.cache;
  9451. if ( arraysEqual( cache, v ) ) return;
  9452. gl.uniform1iv( this.addr, v );
  9453. copyArray( cache, v );
  9454. }
  9455. // Array of vectors (flat or from THREE classes)
  9456. function setValueV2a( gl, v ) {
  9457. var cache = this.cache;
  9458. var data = flatten( v, this.size, 2 );
  9459. if ( arraysEqual( cache, data ) ) return;
  9460. gl.uniform2fv( this.addr, data );
  9461. this.updateCache( data );
  9462. }
  9463. function setValueV3a( gl, v ) {
  9464. var cache = this.cache;
  9465. var data = flatten( v, this.size, 3 );
  9466. if ( arraysEqual( cache, data ) ) return;
  9467. gl.uniform3fv( this.addr, data );
  9468. this.updateCache( data );
  9469. }
  9470. function setValueV4a( gl, v ) {
  9471. var cache = this.cache;
  9472. var data = flatten( v, this.size, 4 );
  9473. if ( arraysEqual( cache, data ) ) return;
  9474. gl.uniform4fv( this.addr, data );
  9475. this.updateCache( data );
  9476. }
  9477. // Array of matrices (flat or from THREE clases)
  9478. function setValueM2a( gl, v ) {
  9479. var cache = this.cache;
  9480. var data = flatten( v, this.size, 4 );
  9481. if ( arraysEqual( cache, data ) ) return;
  9482. gl.uniformMatrix2fv( this.addr, false, data );
  9483. this.updateCache( data );
  9484. }
  9485. function setValueM3a( gl, v ) {
  9486. var cache = this.cache;
  9487. var data = flatten( v, this.size, 9 );
  9488. if ( arraysEqual( cache, data ) ) return;
  9489. gl.uniformMatrix3fv( this.addr, false, data );
  9490. this.updateCache( data );
  9491. }
  9492. function setValueM4a( gl, v ) {
  9493. var cache = this.cache;
  9494. var data = flatten( v, this.size, 16 );
  9495. if ( arraysEqual( cache, data ) ) return;
  9496. gl.uniformMatrix4fv( this.addr, false, data );
  9497. this.updateCache( data );
  9498. }
  9499. // Array of textures (2D / Cube)
  9500. function setValueT1a( gl, v, renderer ) {
  9501. var cache = this.cache;
  9502. var n = v.length;
  9503. var units = allocTexUnits( renderer, n );
  9504. if ( arraysEqual( cache, units ) === false ) {
  9505. gl.uniform1iv( this.addr, units );
  9506. copyArray( cache, units );
  9507. }
  9508. for ( var i = 0; i !== n; ++ i ) {
  9509. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9510. }
  9511. }
  9512. function setValueT6a( gl, v, renderer ) {
  9513. var cache = this.cache;
  9514. var n = v.length;
  9515. var units = allocTexUnits( renderer, n );
  9516. if ( arraysEqual( cache, units ) === false ) {
  9517. gl.uniform1iv( this.addr, units );
  9518. copyArray( cache, units );
  9519. }
  9520. for ( var i = 0; i !== n; ++ i ) {
  9521. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9522. }
  9523. }
  9524. // Helper to pick the right setter for a pure (bottom-level) array
  9525. function getPureArraySetter( type ) {
  9526. switch ( type ) {
  9527. case 0x1406: return setValue1fv; // FLOAT
  9528. case 0x8b50: return setValueV2a; // _VEC2
  9529. case 0x8b51: return setValueV3a; // _VEC3
  9530. case 0x8b52: return setValueV4a; // _VEC4
  9531. case 0x8b5a: return setValueM2a; // _MAT2
  9532. case 0x8b5b: return setValueM3a; // _MAT3
  9533. case 0x8b5c: return setValueM4a; // _MAT4
  9534. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9535. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9536. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9537. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9538. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9539. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9540. }
  9541. }
  9542. // --- Uniform Classes ---
  9543. function SingleUniform( id, activeInfo, addr ) {
  9544. this.id = id;
  9545. this.addr = addr;
  9546. this.cache = [];
  9547. this.setValue = getSingularSetter( activeInfo.type );
  9548. // this.path = activeInfo.name; // DEBUG
  9549. }
  9550. function PureArrayUniform( id, activeInfo, addr ) {
  9551. this.id = id;
  9552. this.addr = addr;
  9553. this.cache = [];
  9554. this.size = activeInfo.size;
  9555. this.setValue = getPureArraySetter( activeInfo.type );
  9556. // this.path = activeInfo.name; // DEBUG
  9557. }
  9558. PureArrayUniform.prototype.updateCache = function ( data ) {
  9559. var cache = this.cache;
  9560. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9561. this.cache = new Float32Array( data.length );
  9562. }
  9563. copyArray( cache, data );
  9564. };
  9565. function StructuredUniform( id ) {
  9566. this.id = id;
  9567. UniformContainer.call( this ); // mix-in
  9568. }
  9569. StructuredUniform.prototype.setValue = function ( gl, value ) {
  9570. // Note: Don't need an extra 'renderer' parameter, since samplers
  9571. // are not allowed in structured uniforms.
  9572. var seq = this.seq;
  9573. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9574. var u = seq[ i ];
  9575. u.setValue( gl, value[ u.id ] );
  9576. }
  9577. };
  9578. // --- Top-level ---
  9579. // Parser - builds up the property tree from the path strings
  9580. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9581. // extracts
  9582. // - the identifier (member name or array index)
  9583. // - followed by an optional right bracket (found when array index)
  9584. // - followed by an optional left bracket or dot (type of subscript)
  9585. //
  9586. // Note: These portions can be read in a non-overlapping fashion and
  9587. // allow straightforward parsing of the hierarchy that WebGL encodes
  9588. // in the uniform names.
  9589. function addUniform( container, uniformObject ) {
  9590. container.seq.push( uniformObject );
  9591. container.map[ uniformObject.id ] = uniformObject;
  9592. }
  9593. function parseUniform( activeInfo, addr, container ) {
  9594. var path = activeInfo.name,
  9595. pathLength = path.length;
  9596. // reset RegExp object, because of the early exit of a previous run
  9597. RePathPart.lastIndex = 0;
  9598. while ( true ) {
  9599. var match = RePathPart.exec( path ),
  9600. matchEnd = RePathPart.lastIndex,
  9601. id = match[ 1 ],
  9602. idIsIndex = match[ 2 ] === ']',
  9603. subscript = match[ 3 ];
  9604. if ( idIsIndex ) id = id | 0; // convert to integer
  9605. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9606. // bare name or "pure" bottom-level array "[0]" suffix
  9607. addUniform( container, subscript === undefined ?
  9608. new SingleUniform( id, activeInfo, addr ) :
  9609. new PureArrayUniform( id, activeInfo, addr ) );
  9610. break;
  9611. } else {
  9612. // step into inner node / create it in case it doesn't exist
  9613. var map = container.map, next = map[ id ];
  9614. if ( next === undefined ) {
  9615. next = new StructuredUniform( id );
  9616. addUniform( container, next );
  9617. }
  9618. container = next;
  9619. }
  9620. }
  9621. }
  9622. // Root Container
  9623. function WebGLUniforms( gl, program, renderer ) {
  9624. UniformContainer.call( this );
  9625. this.renderer = renderer;
  9626. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  9627. for ( var i = 0; i < n; ++ i ) {
  9628. var info = gl.getActiveUniform( program, i ),
  9629. addr = gl.getUniformLocation( program, info.name );
  9630. parseUniform( info, addr, this );
  9631. }
  9632. }
  9633. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  9634. var u = this.map[ name ];
  9635. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  9636. };
  9637. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9638. var v = object[ name ];
  9639. if ( v !== undefined ) this.setValue( gl, name, v );
  9640. };
  9641. // Static interface
  9642. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  9643. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9644. var u = seq[ i ],
  9645. v = values[ u.id ];
  9646. if ( v.needsUpdate !== false ) {
  9647. // note: always updating when .needsUpdate is undefined
  9648. u.setValue( gl, v.value, renderer );
  9649. }
  9650. }
  9651. };
  9652. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9653. var r = [];
  9654. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9655. var u = seq[ i ];
  9656. if ( u.id in values ) r.push( u );
  9657. }
  9658. return r;
  9659. };
  9660. /**
  9661. * @author mrdoob / http://mrdoob.com/
  9662. */
  9663. function addLineNumbers( string ) {
  9664. var lines = string.split( '\n' );
  9665. for ( var i = 0; i < lines.length; i ++ ) {
  9666. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9667. }
  9668. return lines.join( '\n' );
  9669. }
  9670. function WebGLShader( gl, type, string ) {
  9671. var shader = gl.createShader( type );
  9672. gl.shaderSource( shader, string );
  9673. gl.compileShader( shader );
  9674. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  9675. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9676. }
  9677. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9678. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9679. }
  9680. // --enable-privileged-webgl-extension
  9681. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9682. return shader;
  9683. }
  9684. /**
  9685. * @author mrdoob / http://mrdoob.com/
  9686. */
  9687. var programIdCount = 0;
  9688. function getEncodingComponents( encoding ) {
  9689. switch ( encoding ) {
  9690. case LinearEncoding:
  9691. return [ 'Linear', '( value )' ];
  9692. case sRGBEncoding:
  9693. return [ 'sRGB', '( value )' ];
  9694. case RGBEEncoding:
  9695. return [ 'RGBE', '( value )' ];
  9696. case RGBM7Encoding:
  9697. return [ 'RGBM', '( value, 7.0 )' ];
  9698. case RGBM16Encoding:
  9699. return [ 'RGBM', '( value, 16.0 )' ];
  9700. case RGBDEncoding:
  9701. return [ 'RGBD', '( value, 256.0 )' ];
  9702. case GammaEncoding:
  9703. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9704. default:
  9705. throw new Error( 'unsupported encoding: ' + encoding );
  9706. }
  9707. }
  9708. function getTexelDecodingFunction( functionName, encoding ) {
  9709. var components = getEncodingComponents( encoding );
  9710. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9711. }
  9712. function getTexelEncodingFunction( functionName, encoding ) {
  9713. var components = getEncodingComponents( encoding );
  9714. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9715. }
  9716. function getToneMappingFunction( functionName, toneMapping ) {
  9717. var toneMappingName;
  9718. switch ( toneMapping ) {
  9719. case LinearToneMapping:
  9720. toneMappingName = 'Linear';
  9721. break;
  9722. case ReinhardToneMapping:
  9723. toneMappingName = 'Reinhard';
  9724. break;
  9725. case Uncharted2ToneMapping:
  9726. toneMappingName = 'Uncharted2';
  9727. break;
  9728. case CineonToneMapping:
  9729. toneMappingName = 'OptimizedCineon';
  9730. break;
  9731. default:
  9732. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  9733. }
  9734. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  9735. }
  9736. function generateExtensions( extensions, parameters, rendererExtensions ) {
  9737. extensions = extensions || {};
  9738. var chunks = [
  9739. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  9740. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  9741. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  9742. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  9743. ];
  9744. return chunks.filter( filterEmptyLine ).join( '\n' );
  9745. }
  9746. function generateDefines( defines ) {
  9747. var chunks = [];
  9748. for ( var name in defines ) {
  9749. var value = defines[ name ];
  9750. if ( value === false ) continue;
  9751. chunks.push( '#define ' + name + ' ' + value );
  9752. }
  9753. return chunks.join( '\n' );
  9754. }
  9755. function fetchAttributeLocations( gl, program ) {
  9756. var attributes = {};
  9757. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  9758. for ( var i = 0; i < n; i ++ ) {
  9759. var info = gl.getActiveAttrib( program, i );
  9760. var name = info.name;
  9761. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  9762. attributes[ name ] = gl.getAttribLocation( program, name );
  9763. }
  9764. return attributes;
  9765. }
  9766. function filterEmptyLine( string ) {
  9767. return string !== '';
  9768. }
  9769. function replaceLightNums( string, parameters ) {
  9770. return string
  9771. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  9772. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  9773. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  9774. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  9775. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  9776. }
  9777. function replaceClippingPlaneNums( string, parameters ) {
  9778. return string
  9779. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  9780. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  9781. }
  9782. function parseIncludes( string ) {
  9783. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  9784. function replace( match, include ) {
  9785. var replace = ShaderChunk[ include ];
  9786. if ( replace === undefined ) {
  9787. throw new Error( 'Can not resolve #include <' + include + '>' );
  9788. }
  9789. return parseIncludes( replace );
  9790. }
  9791. return string.replace( pattern, replace );
  9792. }
  9793. function unrollLoops( string ) {
  9794. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  9795. function replace( match, start, end, snippet ) {
  9796. var unroll = '';
  9797. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  9798. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  9799. }
  9800. return unroll;
  9801. }
  9802. return string.replace( pattern, replace );
  9803. }
  9804. function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
  9805. var gl = renderer.context;
  9806. var defines = material.defines;
  9807. var vertexShader = shader.vertexShader;
  9808. var fragmentShader = shader.fragmentShader;
  9809. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  9810. if ( parameters.shadowMapType === PCFShadowMap ) {
  9811. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  9812. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  9813. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  9814. }
  9815. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9816. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  9817. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  9818. if ( parameters.envMap ) {
  9819. switch ( material.envMap.mapping ) {
  9820. case CubeReflectionMapping:
  9821. case CubeRefractionMapping:
  9822. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9823. break;
  9824. case CubeUVReflectionMapping:
  9825. case CubeUVRefractionMapping:
  9826. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  9827. break;
  9828. case EquirectangularReflectionMapping:
  9829. case EquirectangularRefractionMapping:
  9830. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  9831. break;
  9832. case SphericalReflectionMapping:
  9833. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  9834. break;
  9835. }
  9836. switch ( material.envMap.mapping ) {
  9837. case CubeRefractionMapping:
  9838. case EquirectangularRefractionMapping:
  9839. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  9840. break;
  9841. }
  9842. switch ( material.combine ) {
  9843. case MultiplyOperation:
  9844. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  9845. break;
  9846. case MixOperation:
  9847. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  9848. break;
  9849. case AddOperation:
  9850. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  9851. break;
  9852. }
  9853. }
  9854. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  9855. // console.log( 'building new program ' );
  9856. //
  9857. var customExtensions = generateExtensions( material.extensions, parameters, extensions );
  9858. var customDefines = generateDefines( defines );
  9859. //
  9860. var program = gl.createProgram();
  9861. var prefixVertex, prefixFragment;
  9862. if ( material.isRawShaderMaterial ) {
  9863. prefixVertex = [
  9864. customDefines
  9865. ].filter( filterEmptyLine ).join( '\n' );
  9866. if ( prefixVertex.length > 0 ) {
  9867. prefixVertex += '\n';
  9868. }
  9869. prefixFragment = [
  9870. customExtensions,
  9871. customDefines
  9872. ].filter( filterEmptyLine ).join( '\n' );
  9873. if ( prefixFragment.length > 0 ) {
  9874. prefixFragment += '\n';
  9875. }
  9876. } else {
  9877. prefixVertex = [
  9878. 'precision ' + parameters.precision + ' float;',
  9879. 'precision ' + parameters.precision + ' int;',
  9880. '#define SHADER_NAME ' + shader.name,
  9881. customDefines,
  9882. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  9883. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  9884. '#define MAX_BONES ' + parameters.maxBones,
  9885. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  9886. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  9887. parameters.map ? '#define USE_MAP' : '',
  9888. parameters.envMap ? '#define USE_ENVMAP' : '',
  9889. parameters.envMap ? '#define ' + envMapModeDefine : '',
  9890. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  9891. parameters.aoMap ? '#define USE_AOMAP' : '',
  9892. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  9893. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  9894. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  9895. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  9896. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  9897. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  9898. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  9899. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  9900. parameters.vertexColors ? '#define USE_COLOR' : '',
  9901. parameters.flatShading ? '#define FLAT_SHADED' : '',
  9902. parameters.skinning ? '#define USE_SKINNING' : '',
  9903. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  9904. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  9905. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  9906. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  9907. parameters.flipSided ? '#define FLIP_SIDED' : '',
  9908. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  9909. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  9910. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  9911. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  9912. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  9913. 'uniform mat4 modelMatrix;',
  9914. 'uniform mat4 modelViewMatrix;',
  9915. 'uniform mat4 projectionMatrix;',
  9916. 'uniform mat4 viewMatrix;',
  9917. 'uniform mat3 normalMatrix;',
  9918. 'uniform vec3 cameraPosition;',
  9919. 'attribute vec3 position;',
  9920. 'attribute vec3 normal;',
  9921. 'attribute vec2 uv;',
  9922. '#ifdef USE_COLOR',
  9923. ' attribute vec3 color;',
  9924. '#endif',
  9925. '#ifdef USE_MORPHTARGETS',
  9926. ' attribute vec3 morphTarget0;',
  9927. ' attribute vec3 morphTarget1;',
  9928. ' attribute vec3 morphTarget2;',
  9929. ' attribute vec3 morphTarget3;',
  9930. ' #ifdef USE_MORPHNORMALS',
  9931. ' attribute vec3 morphNormal0;',
  9932. ' attribute vec3 morphNormal1;',
  9933. ' attribute vec3 morphNormal2;',
  9934. ' attribute vec3 morphNormal3;',
  9935. ' #else',
  9936. ' attribute vec3 morphTarget4;',
  9937. ' attribute vec3 morphTarget5;',
  9938. ' attribute vec3 morphTarget6;',
  9939. ' attribute vec3 morphTarget7;',
  9940. ' #endif',
  9941. '#endif',
  9942. '#ifdef USE_SKINNING',
  9943. ' attribute vec4 skinIndex;',
  9944. ' attribute vec4 skinWeight;',
  9945. '#endif',
  9946. '\n'
  9947. ].filter( filterEmptyLine ).join( '\n' );
  9948. prefixFragment = [
  9949. customExtensions,
  9950. 'precision ' + parameters.precision + ' float;',
  9951. 'precision ' + parameters.precision + ' int;',
  9952. '#define SHADER_NAME ' + shader.name,
  9953. customDefines,
  9954. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  9955. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  9956. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  9957. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  9958. parameters.map ? '#define USE_MAP' : '',
  9959. parameters.envMap ? '#define USE_ENVMAP' : '',
  9960. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  9961. parameters.envMap ? '#define ' + envMapModeDefine : '',
  9962. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  9963. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  9964. parameters.aoMap ? '#define USE_AOMAP' : '',
  9965. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  9966. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  9967. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  9968. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  9969. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  9970. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  9971. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  9972. parameters.vertexColors ? '#define USE_COLOR' : '',
  9973. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  9974. parameters.flatShading ? '#define FLAT_SHADED' : '',
  9975. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  9976. parameters.flipSided ? '#define FLIP_SIDED' : '',
  9977. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  9978. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  9979. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  9980. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  9981. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  9982. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  9983. parameters.envMap && extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  9984. 'uniform mat4 viewMatrix;',
  9985. 'uniform vec3 cameraPosition;',
  9986. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  9987. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  9988. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  9989. parameters.dithering ? '#define DITHERING' : '',
  9990. ( 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
  9991. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  9992. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  9993. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  9994. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  9995. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  9996. '\n'
  9997. ].filter( filterEmptyLine ).join( '\n' );
  9998. }
  9999. vertexShader = parseIncludes( vertexShader );
  10000. vertexShader = replaceLightNums( vertexShader, parameters );
  10001. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10002. fragmentShader = parseIncludes( fragmentShader );
  10003. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10004. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10005. vertexShader = unrollLoops( vertexShader );
  10006. fragmentShader = unrollLoops( fragmentShader );
  10007. var vertexGlsl = prefixVertex + vertexShader;
  10008. var fragmentGlsl = prefixFragment + fragmentShader;
  10009. // console.log( '*VERTEX*', vertexGlsl );
  10010. // console.log( '*FRAGMENT*', fragmentGlsl );
  10011. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  10012. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  10013. gl.attachShader( program, glVertexShader );
  10014. gl.attachShader( program, glFragmentShader );
  10015. // Force a particular attribute to index 0.
  10016. if ( material.index0AttributeName !== undefined ) {
  10017. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10018. } else if ( parameters.morphTargets === true ) {
  10019. // programs with morphTargets displace position out of attribute 0
  10020. gl.bindAttribLocation( program, 0, 'position' );
  10021. }
  10022. gl.linkProgram( program );
  10023. var programLog = gl.getProgramInfoLog( program ).trim();
  10024. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10025. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10026. var runnable = true;
  10027. var haveDiagnostics = true;
  10028. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10029. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10030. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  10031. runnable = false;
  10032. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10033. } else if ( programLog !== '' ) {
  10034. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10035. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10036. haveDiagnostics = false;
  10037. }
  10038. if ( haveDiagnostics ) {
  10039. this.diagnostics = {
  10040. runnable: runnable,
  10041. material: material,
  10042. programLog: programLog,
  10043. vertexShader: {
  10044. log: vertexLog,
  10045. prefix: prefixVertex
  10046. },
  10047. fragmentShader: {
  10048. log: fragmentLog,
  10049. prefix: prefixFragment
  10050. }
  10051. };
  10052. }
  10053. // clean up
  10054. gl.deleteShader( glVertexShader );
  10055. gl.deleteShader( glFragmentShader );
  10056. // set up caching for uniform locations
  10057. var cachedUniforms;
  10058. this.getUniforms = function () {
  10059. if ( cachedUniforms === undefined ) {
  10060. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  10061. }
  10062. return cachedUniforms;
  10063. };
  10064. // set up caching for attribute locations
  10065. var cachedAttributes;
  10066. this.getAttributes = function () {
  10067. if ( cachedAttributes === undefined ) {
  10068. cachedAttributes = fetchAttributeLocations( gl, program );
  10069. }
  10070. return cachedAttributes;
  10071. };
  10072. // free resource
  10073. this.destroy = function () {
  10074. gl.deleteProgram( program );
  10075. this.program = undefined;
  10076. };
  10077. // DEPRECATED
  10078. Object.defineProperties( this, {
  10079. uniforms: {
  10080. get: function () {
  10081. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10082. return this.getUniforms();
  10083. }
  10084. },
  10085. attributes: {
  10086. get: function () {
  10087. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10088. return this.getAttributes();
  10089. }
  10090. }
  10091. } );
  10092. //
  10093. this.name = shader.name;
  10094. this.id = programIdCount ++;
  10095. this.code = code;
  10096. this.usedTimes = 1;
  10097. this.program = program;
  10098. this.vertexShader = glVertexShader;
  10099. this.fragmentShader = glFragmentShader;
  10100. return this;
  10101. }
  10102. /**
  10103. * @author mrdoob / http://mrdoob.com/
  10104. */
  10105. function WebGLPrograms( renderer, extensions, capabilities ) {
  10106. var programs = [];
  10107. var shaderIDs = {
  10108. MeshDepthMaterial: 'depth',
  10109. MeshDistanceMaterial: 'distanceRGBA',
  10110. MeshNormalMaterial: 'normal',
  10111. MeshBasicMaterial: 'basic',
  10112. MeshLambertMaterial: 'lambert',
  10113. MeshPhongMaterial: 'phong',
  10114. MeshToonMaterial: 'phong',
  10115. MeshStandardMaterial: 'physical',
  10116. MeshPhysicalMaterial: 'physical',
  10117. LineBasicMaterial: 'basic',
  10118. LineDashedMaterial: 'dashed',
  10119. PointsMaterial: 'points',
  10120. ShadowMaterial: 'shadow'
  10121. };
  10122. var parameterNames = [
  10123. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10124. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  10125. "roughnessMap", "metalnessMap", "gradientMap",
  10126. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  10127. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10128. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10129. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10130. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10131. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10132. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10133. ];
  10134. function allocateBones( object ) {
  10135. var skeleton = object.skeleton;
  10136. var bones = skeleton.bones;
  10137. if ( capabilities.floatVertexTextures ) {
  10138. return 1024;
  10139. } else {
  10140. // default for when object is not specified
  10141. // ( for example when prebuilding shader to be used with multiple objects )
  10142. //
  10143. // - leave some extra space for other uniforms
  10144. // - limit here is ANGLE's 254 max uniform vectors
  10145. // (up to 54 should be safe)
  10146. var nVertexUniforms = capabilities.maxVertexUniforms;
  10147. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10148. var maxBones = Math.min( nVertexMatrices, bones.length );
  10149. if ( maxBones < bones.length ) {
  10150. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10151. return 0;
  10152. }
  10153. return maxBones;
  10154. }
  10155. }
  10156. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10157. var encoding;
  10158. if ( ! map ) {
  10159. encoding = LinearEncoding;
  10160. } else if ( map.isTexture ) {
  10161. encoding = map.encoding;
  10162. } else if ( map.isWebGLRenderTarget ) {
  10163. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10164. encoding = map.texture.encoding;
  10165. }
  10166. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10167. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10168. encoding = GammaEncoding;
  10169. }
  10170. return encoding;
  10171. }
  10172. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10173. var shaderID = shaderIDs[ material.type ];
  10174. // heuristics to create shader parameters according to lights in the scene
  10175. // (not to blow over maxLights budget)
  10176. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10177. var precision = capabilities.precision;
  10178. if ( material.precision !== null ) {
  10179. precision = capabilities.getMaxPrecision( material.precision );
  10180. if ( precision !== material.precision ) {
  10181. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10182. }
  10183. }
  10184. var currentRenderTarget = renderer.getRenderTarget();
  10185. var parameters = {
  10186. shaderID: shaderID,
  10187. precision: precision,
  10188. supportsVertexTextures: capabilities.vertexTextures,
  10189. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10190. map: !! material.map,
  10191. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10192. envMap: !! material.envMap,
  10193. envMapMode: material.envMap && material.envMap.mapping,
  10194. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10195. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10196. lightMap: !! material.lightMap,
  10197. aoMap: !! material.aoMap,
  10198. emissiveMap: !! material.emissiveMap,
  10199. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10200. bumpMap: !! material.bumpMap,
  10201. normalMap: !! material.normalMap,
  10202. displacementMap: !! material.displacementMap,
  10203. roughnessMap: !! material.roughnessMap,
  10204. metalnessMap: !! material.metalnessMap,
  10205. specularMap: !! material.specularMap,
  10206. alphaMap: !! material.alphaMap,
  10207. gradientMap: !! material.gradientMap,
  10208. combine: material.combine,
  10209. vertexColors: material.vertexColors,
  10210. fog: !! fog,
  10211. useFog: material.fog,
  10212. fogExp: ( fog && fog.isFogExp2 ),
  10213. flatShading: material.flatShading,
  10214. sizeAttenuation: material.sizeAttenuation,
  10215. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10216. skinning: material.skinning && maxBones > 0,
  10217. maxBones: maxBones,
  10218. useVertexTexture: capabilities.floatVertexTextures,
  10219. morphTargets: material.morphTargets,
  10220. morphNormals: material.morphNormals,
  10221. maxMorphTargets: renderer.maxMorphTargets,
  10222. maxMorphNormals: renderer.maxMorphNormals,
  10223. numDirLights: lights.directional.length,
  10224. numPointLights: lights.point.length,
  10225. numSpotLights: lights.spot.length,
  10226. numRectAreaLights: lights.rectArea.length,
  10227. numHemiLights: lights.hemi.length,
  10228. numClippingPlanes: nClipPlanes,
  10229. numClipIntersection: nClipIntersection,
  10230. dithering: material.dithering,
  10231. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10232. shadowMapType: renderer.shadowMap.type,
  10233. toneMapping: renderer.toneMapping,
  10234. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10235. premultipliedAlpha: material.premultipliedAlpha,
  10236. alphaTest: material.alphaTest,
  10237. doubleSided: material.side === DoubleSide,
  10238. flipSided: material.side === BackSide,
  10239. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10240. };
  10241. return parameters;
  10242. };
  10243. this.getProgramCode = function ( material, parameters ) {
  10244. var array = [];
  10245. if ( parameters.shaderID ) {
  10246. array.push( parameters.shaderID );
  10247. } else {
  10248. array.push( material.fragmentShader );
  10249. array.push( material.vertexShader );
  10250. }
  10251. if ( material.defines !== undefined ) {
  10252. for ( var name in material.defines ) {
  10253. array.push( name );
  10254. array.push( material.defines[ name ] );
  10255. }
  10256. }
  10257. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10258. array.push( parameters[ parameterNames[ i ] ] );
  10259. }
  10260. array.push( material.onBeforeCompile.toString() );
  10261. array.push( renderer.gammaOutput );
  10262. return array.join();
  10263. };
  10264. this.acquireProgram = function ( material, shader, parameters, code ) {
  10265. var program;
  10266. // Check if code has been already compiled
  10267. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10268. var programInfo = programs[ p ];
  10269. if ( programInfo.code === code ) {
  10270. program = programInfo;
  10271. ++ program.usedTimes;
  10272. break;
  10273. }
  10274. }
  10275. if ( program === undefined ) {
  10276. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
  10277. programs.push( program );
  10278. }
  10279. return program;
  10280. };
  10281. this.releaseProgram = function ( program ) {
  10282. if ( -- program.usedTimes === 0 ) {
  10283. // Remove from unordered set
  10284. var i = programs.indexOf( program );
  10285. programs[ i ] = programs[ programs.length - 1 ];
  10286. programs.pop();
  10287. // Free WebGL resources
  10288. program.destroy();
  10289. }
  10290. };
  10291. // Exposed for resource monitoring & error feedback via renderer.info:
  10292. this.programs = programs;
  10293. }
  10294. /**
  10295. * @author fordacious / fordacious.github.io
  10296. */
  10297. function WebGLProperties() {
  10298. var properties = new WeakMap();
  10299. function get( object ) {
  10300. var map = properties.get( object );
  10301. if ( map === undefined ) {
  10302. map = {};
  10303. properties.set( object, map );
  10304. }
  10305. return map;
  10306. }
  10307. function remove( object ) {
  10308. properties.delete( object );
  10309. }
  10310. function update( object, key, value ) {
  10311. properties.get( object )[ key ] = value;
  10312. }
  10313. function dispose() {
  10314. properties = new WeakMap();
  10315. }
  10316. return {
  10317. get: get,
  10318. remove: remove,
  10319. update: update,
  10320. dispose: dispose
  10321. };
  10322. }
  10323. /**
  10324. * @author mrdoob / http://mrdoob.com/
  10325. */
  10326. function painterSortStable( a, b ) {
  10327. if ( a.renderOrder !== b.renderOrder ) {
  10328. return a.renderOrder - b.renderOrder;
  10329. } else if ( a.program && b.program && a.program !== b.program ) {
  10330. return a.program.id - b.program.id;
  10331. } else if ( a.material.id !== b.material.id ) {
  10332. return a.material.id - b.material.id;
  10333. } else if ( a.z !== b.z ) {
  10334. return a.z - b.z;
  10335. } else {
  10336. return a.id - b.id;
  10337. }
  10338. }
  10339. function reversePainterSortStable( a, b ) {
  10340. if ( a.renderOrder !== b.renderOrder ) {
  10341. return a.renderOrder - b.renderOrder;
  10342. } if ( a.z !== b.z ) {
  10343. return b.z - a.z;
  10344. } else {
  10345. return a.id - b.id;
  10346. }
  10347. }
  10348. function WebGLRenderList() {
  10349. var renderItems = [];
  10350. var renderItemsIndex = 0;
  10351. var opaque = [];
  10352. var transparent = [];
  10353. function init() {
  10354. renderItemsIndex = 0;
  10355. opaque.length = 0;
  10356. transparent.length = 0;
  10357. }
  10358. function push( object, geometry, material, z, group ) {
  10359. var renderItem = renderItems[ renderItemsIndex ];
  10360. if ( renderItem === undefined ) {
  10361. renderItem = {
  10362. id: object.id,
  10363. object: object,
  10364. geometry: geometry,
  10365. material: material,
  10366. program: material.program,
  10367. renderOrder: object.renderOrder,
  10368. z: z,
  10369. group: group
  10370. };
  10371. renderItems[ renderItemsIndex ] = renderItem;
  10372. } else {
  10373. renderItem.id = object.id;
  10374. renderItem.object = object;
  10375. renderItem.geometry = geometry;
  10376. renderItem.material = material;
  10377. renderItem.program = material.program;
  10378. renderItem.renderOrder = object.renderOrder;
  10379. renderItem.z = z;
  10380. renderItem.group = group;
  10381. }
  10382. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10383. renderItemsIndex ++;
  10384. }
  10385. function sort() {
  10386. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10387. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10388. }
  10389. return {
  10390. opaque: opaque,
  10391. transparent: transparent,
  10392. init: init,
  10393. push: push,
  10394. sort: sort
  10395. };
  10396. }
  10397. function WebGLRenderLists() {
  10398. var lists = {};
  10399. function get( scene, camera ) {
  10400. var hash = scene.id + ',' + camera.id;
  10401. var list = lists[ hash ];
  10402. if ( list === undefined ) {
  10403. // console.log( 'THREE.WebGLRenderLists:', hash );
  10404. list = new WebGLRenderList();
  10405. lists[ hash ] = list;
  10406. }
  10407. return list;
  10408. }
  10409. function dispose() {
  10410. lists = {};
  10411. }
  10412. return {
  10413. get: get,
  10414. dispose: dispose
  10415. };
  10416. }
  10417. /**
  10418. * @author mrdoob / http://mrdoob.com/
  10419. */
  10420. function UniformsCache() {
  10421. var lights = {};
  10422. return {
  10423. get: function ( light ) {
  10424. if ( lights[ light.id ] !== undefined ) {
  10425. return lights[ light.id ];
  10426. }
  10427. var uniforms;
  10428. switch ( light.type ) {
  10429. case 'DirectionalLight':
  10430. uniforms = {
  10431. direction: new Vector3(),
  10432. color: new Color(),
  10433. shadow: false,
  10434. shadowBias: 0,
  10435. shadowRadius: 1,
  10436. shadowMapSize: new Vector2()
  10437. };
  10438. break;
  10439. case 'SpotLight':
  10440. uniforms = {
  10441. position: new Vector3(),
  10442. direction: new Vector3(),
  10443. color: new Color(),
  10444. distance: 0,
  10445. coneCos: 0,
  10446. penumbraCos: 0,
  10447. decay: 0,
  10448. shadow: false,
  10449. shadowBias: 0,
  10450. shadowRadius: 1,
  10451. shadowMapSize: new Vector2()
  10452. };
  10453. break;
  10454. case 'PointLight':
  10455. uniforms = {
  10456. position: new Vector3(),
  10457. color: new Color(),
  10458. distance: 0,
  10459. decay: 0,
  10460. shadow: false,
  10461. shadowBias: 0,
  10462. shadowRadius: 1,
  10463. shadowMapSize: new Vector2(),
  10464. shadowCameraNear: 1,
  10465. shadowCameraFar: 1000
  10466. };
  10467. break;
  10468. case 'HemisphereLight':
  10469. uniforms = {
  10470. direction: new Vector3(),
  10471. skyColor: new Color(),
  10472. groundColor: new Color()
  10473. };
  10474. break;
  10475. case 'RectAreaLight':
  10476. uniforms = {
  10477. color: new Color(),
  10478. position: new Vector3(),
  10479. halfWidth: new Vector3(),
  10480. halfHeight: new Vector3()
  10481. // TODO (abelnation): set RectAreaLight shadow uniforms
  10482. };
  10483. break;
  10484. }
  10485. lights[ light.id ] = uniforms;
  10486. return uniforms;
  10487. }
  10488. };
  10489. }
  10490. var count = 0;
  10491. function WebGLLights() {
  10492. var cache = new UniformsCache();
  10493. var state = {
  10494. id: count ++,
  10495. hash: '',
  10496. ambient: [ 0, 0, 0 ],
  10497. directional: [],
  10498. directionalShadowMap: [],
  10499. directionalShadowMatrix: [],
  10500. spot: [],
  10501. spotShadowMap: [],
  10502. spotShadowMatrix: [],
  10503. rectArea: [],
  10504. point: [],
  10505. pointShadowMap: [],
  10506. pointShadowMatrix: [],
  10507. hemi: []
  10508. };
  10509. var vector3 = new Vector3();
  10510. var matrix4 = new Matrix4();
  10511. var matrix42 = new Matrix4();
  10512. function setup( lights, shadows, camera ) {
  10513. var r = 0, g = 0, b = 0;
  10514. var directionalLength = 0;
  10515. var pointLength = 0;
  10516. var spotLength = 0;
  10517. var rectAreaLength = 0;
  10518. var hemiLength = 0;
  10519. var viewMatrix = camera.matrixWorldInverse;
  10520. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10521. var light = lights[ i ];
  10522. var color = light.color;
  10523. var intensity = light.intensity;
  10524. var distance = light.distance;
  10525. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10526. if ( light.isAmbientLight ) {
  10527. r += color.r * intensity;
  10528. g += color.g * intensity;
  10529. b += color.b * intensity;
  10530. } else if ( light.isDirectionalLight ) {
  10531. var uniforms = cache.get( light );
  10532. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10533. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10534. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10535. uniforms.direction.sub( vector3 );
  10536. uniforms.direction.transformDirection( viewMatrix );
  10537. uniforms.shadow = light.castShadow;
  10538. if ( light.castShadow ) {
  10539. var shadow = light.shadow;
  10540. uniforms.shadowBias = shadow.bias;
  10541. uniforms.shadowRadius = shadow.radius;
  10542. uniforms.shadowMapSize = shadow.mapSize;
  10543. }
  10544. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10545. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10546. state.directional[ directionalLength ] = uniforms;
  10547. directionalLength ++;
  10548. } else if ( light.isSpotLight ) {
  10549. var uniforms = cache.get( light );
  10550. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10551. uniforms.position.applyMatrix4( viewMatrix );
  10552. uniforms.color.copy( color ).multiplyScalar( intensity );
  10553. uniforms.distance = distance;
  10554. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10555. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10556. uniforms.direction.sub( vector3 );
  10557. uniforms.direction.transformDirection( viewMatrix );
  10558. uniforms.coneCos = Math.cos( light.angle );
  10559. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10560. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  10561. uniforms.shadow = light.castShadow;
  10562. if ( light.castShadow ) {
  10563. var shadow = light.shadow;
  10564. uniforms.shadowBias = shadow.bias;
  10565. uniforms.shadowRadius = shadow.radius;
  10566. uniforms.shadowMapSize = shadow.mapSize;
  10567. }
  10568. state.spotShadowMap[ spotLength ] = shadowMap;
  10569. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10570. state.spot[ spotLength ] = uniforms;
  10571. spotLength ++;
  10572. } else if ( light.isRectAreaLight ) {
  10573. var uniforms = cache.get( light );
  10574. // (a) intensity is the total visible light emitted
  10575. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10576. // (b) intensity is the brightness of the light
  10577. uniforms.color.copy( color ).multiplyScalar( intensity );
  10578. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10579. uniforms.position.applyMatrix4( viewMatrix );
  10580. // extract local rotation of light to derive width/height half vectors
  10581. matrix42.identity();
  10582. matrix4.copy( light.matrixWorld );
  10583. matrix4.premultiply( viewMatrix );
  10584. matrix42.extractRotation( matrix4 );
  10585. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  10586. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  10587. uniforms.halfWidth.applyMatrix4( matrix42 );
  10588. uniforms.halfHeight.applyMatrix4( matrix42 );
  10589. // TODO (abelnation): RectAreaLight distance?
  10590. // uniforms.distance = distance;
  10591. state.rectArea[ rectAreaLength ] = uniforms;
  10592. rectAreaLength ++;
  10593. } else if ( light.isPointLight ) {
  10594. var uniforms = cache.get( light );
  10595. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10596. uniforms.position.applyMatrix4( viewMatrix );
  10597. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10598. uniforms.distance = light.distance;
  10599. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  10600. uniforms.shadow = light.castShadow;
  10601. if ( light.castShadow ) {
  10602. var shadow = light.shadow;
  10603. uniforms.shadowBias = shadow.bias;
  10604. uniforms.shadowRadius = shadow.radius;
  10605. uniforms.shadowMapSize = shadow.mapSize;
  10606. uniforms.shadowCameraNear = shadow.camera.near;
  10607. uniforms.shadowCameraFar = shadow.camera.far;
  10608. }
  10609. state.pointShadowMap[ pointLength ] = shadowMap;
  10610. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  10611. state.point[ pointLength ] = uniforms;
  10612. pointLength ++;
  10613. } else if ( light.isHemisphereLight ) {
  10614. var uniforms = cache.get( light );
  10615. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10616. uniforms.direction.transformDirection( viewMatrix );
  10617. uniforms.direction.normalize();
  10618. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  10619. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  10620. state.hemi[ hemiLength ] = uniforms;
  10621. hemiLength ++;
  10622. }
  10623. }
  10624. state.ambient[ 0 ] = r;
  10625. state.ambient[ 1 ] = g;
  10626. state.ambient[ 2 ] = b;
  10627. state.directional.length = directionalLength;
  10628. state.spot.length = spotLength;
  10629. state.rectArea.length = rectAreaLength;
  10630. state.point.length = pointLength;
  10631. state.hemi.length = hemiLength;
  10632. state.hash = state.id + ',' + directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length;
  10633. }
  10634. return {
  10635. setup: setup,
  10636. state: state
  10637. };
  10638. }
  10639. /**
  10640. * @author Mugen87 / https://github.com/Mugen87
  10641. */
  10642. function WebGLRenderState() {
  10643. var lights = new WebGLLights();
  10644. var lightsArray = [];
  10645. var shadowsArray = [];
  10646. var spritesArray = [];
  10647. function init() {
  10648. lightsArray.length = 0;
  10649. shadowsArray.length = 0;
  10650. spritesArray.length = 0;
  10651. }
  10652. function pushLight( light ) {
  10653. lightsArray.push( light );
  10654. }
  10655. function pushShadow( shadowLight ) {
  10656. shadowsArray.push( shadowLight );
  10657. }
  10658. function pushSprite( shadowLight ) {
  10659. spritesArray.push( shadowLight );
  10660. }
  10661. function setupLights( camera ) {
  10662. lights.setup( lightsArray, shadowsArray, camera );
  10663. }
  10664. var state = {
  10665. lightsArray: lightsArray,
  10666. shadowsArray: shadowsArray,
  10667. spritesArray: spritesArray,
  10668. lights: lights
  10669. };
  10670. return {
  10671. init: init,
  10672. state: state,
  10673. setupLights: setupLights,
  10674. pushLight: pushLight,
  10675. pushShadow: pushShadow,
  10676. pushSprite: pushSprite
  10677. };
  10678. }
  10679. function WebGLRenderStates() {
  10680. var renderStates = {};
  10681. function get( scene, camera ) {
  10682. var hash = scene.id + ',' + camera.id;
  10683. var renderState = renderStates[ hash ];
  10684. if ( renderState === undefined ) {
  10685. renderState = new WebGLRenderState();
  10686. renderStates[ hash ] = renderState;
  10687. }
  10688. return renderState;
  10689. }
  10690. function dispose() {
  10691. renderStates = {};
  10692. }
  10693. return {
  10694. get: get,
  10695. dispose: dispose
  10696. };
  10697. }
  10698. /**
  10699. * @author mrdoob / http://mrdoob.com/
  10700. * @author alteredq / http://alteredqualia.com/
  10701. * @author bhouston / https://clara.io
  10702. * @author WestLangley / http://github.com/WestLangley
  10703. *
  10704. * parameters = {
  10705. *
  10706. * opacity: <float>,
  10707. *
  10708. * map: new THREE.Texture( <Image> ),
  10709. *
  10710. * alphaMap: new THREE.Texture( <Image> ),
  10711. *
  10712. * displacementMap: new THREE.Texture( <Image> ),
  10713. * displacementScale: <float>,
  10714. * displacementBias: <float>,
  10715. *
  10716. * wireframe: <boolean>,
  10717. * wireframeLinewidth: <float>
  10718. * }
  10719. */
  10720. function MeshDepthMaterial( parameters ) {
  10721. Material.call( this );
  10722. this.type = 'MeshDepthMaterial';
  10723. this.depthPacking = BasicDepthPacking;
  10724. this.skinning = false;
  10725. this.morphTargets = false;
  10726. this.map = null;
  10727. this.alphaMap = null;
  10728. this.displacementMap = null;
  10729. this.displacementScale = 1;
  10730. this.displacementBias = 0;
  10731. this.wireframe = false;
  10732. this.wireframeLinewidth = 1;
  10733. this.fog = false;
  10734. this.lights = false;
  10735. this.setValues( parameters );
  10736. }
  10737. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  10738. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  10739. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  10740. MeshDepthMaterial.prototype.copy = function ( source ) {
  10741. Material.prototype.copy.call( this, source );
  10742. this.depthPacking = source.depthPacking;
  10743. this.skinning = source.skinning;
  10744. this.morphTargets = source.morphTargets;
  10745. this.map = source.map;
  10746. this.alphaMap = source.alphaMap;
  10747. this.displacementMap = source.displacementMap;
  10748. this.displacementScale = source.displacementScale;
  10749. this.displacementBias = source.displacementBias;
  10750. this.wireframe = source.wireframe;
  10751. this.wireframeLinewidth = source.wireframeLinewidth;
  10752. return this;
  10753. };
  10754. /**
  10755. * @author WestLangley / http://github.com/WestLangley
  10756. *
  10757. * parameters = {
  10758. *
  10759. * referencePosition: <float>,
  10760. * nearDistance: <float>,
  10761. * farDistance: <float>,
  10762. *
  10763. * skinning: <bool>,
  10764. * morphTargets: <bool>,
  10765. *
  10766. * map: new THREE.Texture( <Image> ),
  10767. *
  10768. * alphaMap: new THREE.Texture( <Image> ),
  10769. *
  10770. * displacementMap: new THREE.Texture( <Image> ),
  10771. * displacementScale: <float>,
  10772. * displacementBias: <float>
  10773. *
  10774. * }
  10775. */
  10776. function MeshDistanceMaterial( parameters ) {
  10777. Material.call( this );
  10778. this.type = 'MeshDistanceMaterial';
  10779. this.referencePosition = new Vector3();
  10780. this.nearDistance = 1;
  10781. this.farDistance = 1000;
  10782. this.skinning = false;
  10783. this.morphTargets = false;
  10784. this.map = null;
  10785. this.alphaMap = null;
  10786. this.displacementMap = null;
  10787. this.displacementScale = 1;
  10788. this.displacementBias = 0;
  10789. this.fog = false;
  10790. this.lights = false;
  10791. this.setValues( parameters );
  10792. }
  10793. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  10794. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  10795. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  10796. MeshDistanceMaterial.prototype.copy = function ( source ) {
  10797. Material.prototype.copy.call( this, source );
  10798. this.referencePosition.copy( source.referencePosition );
  10799. this.nearDistance = source.nearDistance;
  10800. this.farDistance = source.farDistance;
  10801. this.skinning = source.skinning;
  10802. this.morphTargets = source.morphTargets;
  10803. this.map = source.map;
  10804. this.alphaMap = source.alphaMap;
  10805. this.displacementMap = source.displacementMap;
  10806. this.displacementScale = source.displacementScale;
  10807. this.displacementBias = source.displacementBias;
  10808. return this;
  10809. };
  10810. /**
  10811. * @author alteredq / http://alteredqualia.com/
  10812. * @author mrdoob / http://mrdoob.com/
  10813. */
  10814. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  10815. var _frustum = new Frustum(),
  10816. _projScreenMatrix = new Matrix4(),
  10817. _shadowMapSize = new Vector2(),
  10818. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  10819. _lookTarget = new Vector3(),
  10820. _lightPositionWorld = new Vector3(),
  10821. _MorphingFlag = 1,
  10822. _SkinningFlag = 2,
  10823. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  10824. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  10825. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  10826. _materialCache = {};
  10827. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  10828. var cubeDirections = [
  10829. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  10830. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  10831. ];
  10832. var cubeUps = [
  10833. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  10834. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  10835. ];
  10836. var cube2DViewPorts = [
  10837. new Vector4(), new Vector4(), new Vector4(),
  10838. new Vector4(), new Vector4(), new Vector4()
  10839. ];
  10840. // init
  10841. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  10842. var useMorphing = ( i & _MorphingFlag ) !== 0;
  10843. var useSkinning = ( i & _SkinningFlag ) !== 0;
  10844. var depthMaterial = new MeshDepthMaterial( {
  10845. depthPacking: RGBADepthPacking,
  10846. morphTargets: useMorphing,
  10847. skinning: useSkinning
  10848. } );
  10849. _depthMaterials[ i ] = depthMaterial;
  10850. //
  10851. var distanceMaterial = new MeshDistanceMaterial( {
  10852. morphTargets: useMorphing,
  10853. skinning: useSkinning
  10854. } );
  10855. _distanceMaterials[ i ] = distanceMaterial;
  10856. }
  10857. //
  10858. var scope = this;
  10859. this.enabled = false;
  10860. this.autoUpdate = true;
  10861. this.needsUpdate = false;
  10862. this.type = PCFShadowMap;
  10863. this.render = function ( lights, scene, camera ) {
  10864. if ( scope.enabled === false ) return;
  10865. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  10866. if ( lights.length === 0 ) return;
  10867. // TODO Clean up (needed in case of contextlost)
  10868. var _gl = _renderer.context;
  10869. var _state = _renderer.state;
  10870. // Set GL state for depth map.
  10871. _state.disable( _gl.BLEND );
  10872. _state.buffers.color.setClear( 1, 1, 1, 1 );
  10873. _state.buffers.depth.setTest( true );
  10874. _state.setScissorTest( false );
  10875. // render depth map
  10876. var faceCount;
  10877. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  10878. var light = lights[ i ];
  10879. var shadow = light.shadow;
  10880. var isPointLight = light && light.isPointLight;
  10881. if ( shadow === undefined ) {
  10882. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  10883. continue;
  10884. }
  10885. var shadowCamera = shadow.camera;
  10886. _shadowMapSize.copy( shadow.mapSize );
  10887. _shadowMapSize.min( _maxShadowMapSize );
  10888. if ( isPointLight ) {
  10889. var vpWidth = _shadowMapSize.x;
  10890. var vpHeight = _shadowMapSize.y;
  10891. // These viewports map a cube-map onto a 2D texture with the
  10892. // following orientation:
  10893. //
  10894. // xzXZ
  10895. // y Y
  10896. //
  10897. // X - Positive x direction
  10898. // x - Negative x direction
  10899. // Y - Positive y direction
  10900. // y - Negative y direction
  10901. // Z - Positive z direction
  10902. // z - Negative z direction
  10903. // positive X
  10904. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  10905. // negative X
  10906. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  10907. // positive Z
  10908. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  10909. // negative Z
  10910. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  10911. // positive Y
  10912. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  10913. // negative Y
  10914. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  10915. _shadowMapSize.x *= 4.0;
  10916. _shadowMapSize.y *= 2.0;
  10917. }
  10918. if ( shadow.map === null ) {
  10919. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  10920. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  10921. shadow.map.texture.name = light.name + ".shadowMap";
  10922. shadowCamera.updateProjectionMatrix();
  10923. }
  10924. if ( shadow.isSpotLightShadow ) {
  10925. shadow.update( light );
  10926. }
  10927. var shadowMap = shadow.map;
  10928. var shadowMatrix = shadow.matrix;
  10929. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  10930. shadowCamera.position.copy( _lightPositionWorld );
  10931. if ( isPointLight ) {
  10932. faceCount = 6;
  10933. // for point lights we set the shadow matrix to be a translation-only matrix
  10934. // equal to inverse of the light's position
  10935. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  10936. } else {
  10937. faceCount = 1;
  10938. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  10939. shadowCamera.lookAt( _lookTarget );
  10940. shadowCamera.updateMatrixWorld();
  10941. // compute shadow matrix
  10942. shadowMatrix.set(
  10943. 0.5, 0.0, 0.0, 0.5,
  10944. 0.0, 0.5, 0.0, 0.5,
  10945. 0.0, 0.0, 0.5, 0.5,
  10946. 0.0, 0.0, 0.0, 1.0
  10947. );
  10948. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  10949. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  10950. }
  10951. _renderer.setRenderTarget( shadowMap );
  10952. _renderer.clear();
  10953. // render shadow map for each cube face (if omni-directional) or
  10954. // run a single pass if not
  10955. for ( var face = 0; face < faceCount; face ++ ) {
  10956. if ( isPointLight ) {
  10957. _lookTarget.copy( shadowCamera.position );
  10958. _lookTarget.add( cubeDirections[ face ] );
  10959. shadowCamera.up.copy( cubeUps[ face ] );
  10960. shadowCamera.lookAt( _lookTarget );
  10961. shadowCamera.updateMatrixWorld();
  10962. var vpDimensions = cube2DViewPorts[ face ];
  10963. _state.viewport( vpDimensions );
  10964. }
  10965. // update camera matrices and frustum
  10966. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  10967. _frustum.setFromMatrix( _projScreenMatrix );
  10968. // set object matrices & frustum culling
  10969. renderObject( scene, camera, shadowCamera, isPointLight );
  10970. }
  10971. }
  10972. scope.needsUpdate = false;
  10973. };
  10974. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  10975. var geometry = object.geometry;
  10976. var result = null;
  10977. var materialVariants = _depthMaterials;
  10978. var customMaterial = object.customDepthMaterial;
  10979. if ( isPointLight ) {
  10980. materialVariants = _distanceMaterials;
  10981. customMaterial = object.customDistanceMaterial;
  10982. }
  10983. if ( ! customMaterial ) {
  10984. var useMorphing = false;
  10985. if ( material.morphTargets ) {
  10986. if ( geometry && geometry.isBufferGeometry ) {
  10987. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  10988. } else if ( geometry && geometry.isGeometry ) {
  10989. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  10990. }
  10991. }
  10992. if ( object.isSkinnedMesh && material.skinning === false ) {
  10993. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  10994. }
  10995. var useSkinning = object.isSkinnedMesh && material.skinning;
  10996. var variantIndex = 0;
  10997. if ( useMorphing ) variantIndex |= _MorphingFlag;
  10998. if ( useSkinning ) variantIndex |= _SkinningFlag;
  10999. result = materialVariants[ variantIndex ];
  11000. } else {
  11001. result = customMaterial;
  11002. }
  11003. if ( _renderer.localClippingEnabled &&
  11004. material.clipShadows === true &&
  11005. material.clippingPlanes.length !== 0 ) {
  11006. // in this case we need a unique material instance reflecting the
  11007. // appropriate state
  11008. var keyA = result.uuid, keyB = material.uuid;
  11009. var materialsForVariant = _materialCache[ keyA ];
  11010. if ( materialsForVariant === undefined ) {
  11011. materialsForVariant = {};
  11012. _materialCache[ keyA ] = materialsForVariant;
  11013. }
  11014. var cachedMaterial = materialsForVariant[ keyB ];
  11015. if ( cachedMaterial === undefined ) {
  11016. cachedMaterial = result.clone();
  11017. materialsForVariant[ keyB ] = cachedMaterial;
  11018. }
  11019. result = cachedMaterial;
  11020. }
  11021. result.visible = material.visible;
  11022. result.wireframe = material.wireframe;
  11023. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11024. result.clipShadows = material.clipShadows;
  11025. result.clippingPlanes = material.clippingPlanes;
  11026. result.clipIntersection = material.clipIntersection;
  11027. result.wireframeLinewidth = material.wireframeLinewidth;
  11028. result.linewidth = material.linewidth;
  11029. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11030. result.referencePosition.copy( lightPositionWorld );
  11031. result.nearDistance = shadowCameraNear;
  11032. result.farDistance = shadowCameraFar;
  11033. }
  11034. return result;
  11035. }
  11036. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11037. if ( object.visible === false ) return;
  11038. var visible = object.layers.test( camera.layers );
  11039. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11040. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11041. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11042. var geometry = _objects.update( object );
  11043. var material = object.material;
  11044. if ( Array.isArray( material ) ) {
  11045. var groups = geometry.groups;
  11046. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11047. var group = groups[ k ];
  11048. var groupMaterial = material[ group.materialIndex ];
  11049. if ( groupMaterial && groupMaterial.visible ) {
  11050. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11051. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11052. }
  11053. }
  11054. } else if ( material.visible ) {
  11055. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11056. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11057. }
  11058. }
  11059. }
  11060. var children = object.children;
  11061. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11062. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11063. }
  11064. }
  11065. }
  11066. /**
  11067. * @author mrdoob / http://mrdoob.com/
  11068. */
  11069. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  11070. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  11071. this.needsUpdate = true;
  11072. }
  11073. CanvasTexture.prototype = Object.create( Texture.prototype );
  11074. CanvasTexture.prototype.constructor = CanvasTexture;
  11075. CanvasTexture.prototype.isCanvasTexture = true;
  11076. /**
  11077. * @author mikael emtinger / http://gomo.se/
  11078. * @author alteredq / http://alteredqualia.com/
  11079. */
  11080. function WebGLSpriteRenderer( renderer, gl, state, textures, capabilities ) {
  11081. var vertexBuffer, elementBuffer;
  11082. var program, attributes, uniforms;
  11083. var texture;
  11084. // decompose matrixWorld
  11085. var spritePosition = new Vector3();
  11086. var spriteRotation = new Quaternion();
  11087. var spriteScale = new Vector3();
  11088. function init() {
  11089. var vertices = new Float32Array( [
  11090. - 0.5, - 0.5, 0, 0,
  11091. 0.5, - 0.5, 1, 0,
  11092. 0.5, 0.5, 1, 1,
  11093. - 0.5, 0.5, 0, 1
  11094. ] );
  11095. var faces = new Uint16Array( [
  11096. 0, 1, 2,
  11097. 0, 2, 3
  11098. ] );
  11099. vertexBuffer = gl.createBuffer();
  11100. elementBuffer = gl.createBuffer();
  11101. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  11102. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  11103. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  11104. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  11105. program = createProgram();
  11106. attributes = {
  11107. position: gl.getAttribLocation( program, 'position' ),
  11108. uv: gl.getAttribLocation( program, 'uv' )
  11109. };
  11110. uniforms = {
  11111. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  11112. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  11113. rotation: gl.getUniformLocation( program, 'rotation' ),
  11114. center: gl.getUniformLocation( program, 'center' ),
  11115. scale: gl.getUniformLocation( program, 'scale' ),
  11116. color: gl.getUniformLocation( program, 'color' ),
  11117. map: gl.getUniformLocation( program, 'map' ),
  11118. opacity: gl.getUniformLocation( program, 'opacity' ),
  11119. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  11120. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  11121. fogType: gl.getUniformLocation( program, 'fogType' ),
  11122. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  11123. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  11124. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  11125. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  11126. fogDepth: gl.getUniformLocation( program, 'fogDepth' ),
  11127. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  11128. };
  11129. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11130. canvas.width = 8;
  11131. canvas.height = 8;
  11132. var context = canvas.getContext( '2d' );
  11133. context.fillStyle = 'white';
  11134. context.fillRect( 0, 0, 8, 8 );
  11135. texture = new CanvasTexture( canvas );
  11136. }
  11137. this.render = function ( sprites, scene, camera ) {
  11138. if ( sprites.length === 0 ) return;
  11139. // setup gl
  11140. if ( program === undefined ) {
  11141. init();
  11142. }
  11143. state.useProgram( program );
  11144. state.initAttributes();
  11145. state.enableAttribute( attributes.position );
  11146. state.enableAttribute( attributes.uv );
  11147. state.disableUnusedAttributes();
  11148. state.disable( gl.CULL_FACE );
  11149. state.enable( gl.BLEND );
  11150. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  11151. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  11152. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  11153. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  11154. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  11155. state.activeTexture( gl.TEXTURE0 );
  11156. gl.uniform1i( uniforms.map, 0 );
  11157. var oldFogType = 0;
  11158. var sceneFogType = 0;
  11159. var fog = scene.fog;
  11160. if ( fog ) {
  11161. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  11162. if ( fog.isFog ) {
  11163. gl.uniform1f( uniforms.fogNear, fog.near );
  11164. gl.uniform1f( uniforms.fogFar, fog.far );
  11165. gl.uniform1i( uniforms.fogType, 1 );
  11166. oldFogType = 1;
  11167. sceneFogType = 1;
  11168. } else if ( fog.isFogExp2 ) {
  11169. gl.uniform1f( uniforms.fogDensity, fog.density );
  11170. gl.uniform1i( uniforms.fogType, 2 );
  11171. oldFogType = 2;
  11172. sceneFogType = 2;
  11173. }
  11174. } else {
  11175. gl.uniform1i( uniforms.fogType, 0 );
  11176. oldFogType = 0;
  11177. sceneFogType = 0;
  11178. }
  11179. // update positions and sort
  11180. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  11181. var sprite = sprites[ i ];
  11182. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  11183. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  11184. }
  11185. sprites.sort( painterSortStable );
  11186. // render all sprites
  11187. var scale = [];
  11188. var center = [];
  11189. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  11190. var sprite = sprites[ i ];
  11191. var material = sprite.material;
  11192. if ( material.visible === false ) continue;
  11193. sprite.onBeforeRender( renderer, scene, camera, undefined, material, undefined );
  11194. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  11195. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  11196. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  11197. scale[ 0 ] = spriteScale.x;
  11198. scale[ 1 ] = spriteScale.y;
  11199. center[ 0 ] = sprite.center.x - 0.5;
  11200. center[ 1 ] = sprite.center.y - 0.5;
  11201. var fogType = 0;
  11202. if ( scene.fog && material.fog ) {
  11203. fogType = sceneFogType;
  11204. }
  11205. if ( oldFogType !== fogType ) {
  11206. gl.uniform1i( uniforms.fogType, fogType );
  11207. oldFogType = fogType;
  11208. }
  11209. if ( material.map !== null ) {
  11210. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  11211. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  11212. } else {
  11213. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  11214. gl.uniform2f( uniforms.uvScale, 1, 1 );
  11215. }
  11216. gl.uniform1f( uniforms.opacity, material.opacity );
  11217. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  11218. gl.uniform1f( uniforms.rotation, material.rotation );
  11219. gl.uniform2fv( uniforms.center, center );
  11220. gl.uniform2fv( uniforms.scale, scale );
  11221. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11222. state.buffers.depth.setTest( material.depthTest );
  11223. state.buffers.depth.setMask( material.depthWrite );
  11224. state.buffers.color.setMask( material.colorWrite );
  11225. textures.setTexture2D( material.map || texture, 0 );
  11226. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  11227. sprite.onAfterRender( renderer, scene, camera, undefined, material, undefined );
  11228. }
  11229. // restore gl
  11230. state.enable( gl.CULL_FACE );
  11231. state.reset();
  11232. };
  11233. function createProgram() {
  11234. var program = gl.createProgram();
  11235. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  11236. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  11237. gl.shaderSource( vertexShader, [
  11238. 'precision ' + capabilities.precision + ' float;',
  11239. '#define SHADER_NAME ' + 'SpriteMaterial',
  11240. 'uniform mat4 modelViewMatrix;',
  11241. 'uniform mat4 projectionMatrix;',
  11242. 'uniform float rotation;',
  11243. 'uniform vec2 center;',
  11244. 'uniform vec2 scale;',
  11245. 'uniform vec2 uvOffset;',
  11246. 'uniform vec2 uvScale;',
  11247. 'attribute vec2 position;',
  11248. 'attribute vec2 uv;',
  11249. 'varying vec2 vUV;',
  11250. 'varying float fogDepth;',
  11251. 'void main() {',
  11252. ' vUV = uvOffset + uv * uvScale;',
  11253. ' vec2 alignedPosition = ( position - center ) * scale;',
  11254. ' vec2 rotatedPosition;',
  11255. ' rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  11256. ' rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  11257. ' vec4 mvPosition;',
  11258. ' mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  11259. ' mvPosition.xy += rotatedPosition;',
  11260. ' gl_Position = projectionMatrix * mvPosition;',
  11261. ' fogDepth = - mvPosition.z;',
  11262. '}'
  11263. ].join( '\n' ) );
  11264. gl.shaderSource( fragmentShader, [
  11265. 'precision ' + capabilities.precision + ' float;',
  11266. '#define SHADER_NAME ' + 'SpriteMaterial',
  11267. 'uniform vec3 color;',
  11268. 'uniform sampler2D map;',
  11269. 'uniform float opacity;',
  11270. 'uniform int fogType;',
  11271. 'uniform vec3 fogColor;',
  11272. 'uniform float fogDensity;',
  11273. 'uniform float fogNear;',
  11274. 'uniform float fogFar;',
  11275. 'uniform float alphaTest;',
  11276. 'varying vec2 vUV;',
  11277. 'varying float fogDepth;',
  11278. 'void main() {',
  11279. ' vec4 texture = texture2D( map, vUV );',
  11280. ' gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  11281. ' if ( gl_FragColor.a < alphaTest ) discard;',
  11282. ' if ( fogType > 0 ) {',
  11283. ' float fogFactor = 0.0;',
  11284. ' if ( fogType == 1 ) {',
  11285. ' fogFactor = smoothstep( fogNear, fogFar, fogDepth );',
  11286. ' } else {',
  11287. ' const float LOG2 = 1.442695;',
  11288. ' fogFactor = exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 );',
  11289. ' fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  11290. ' }',
  11291. ' gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );',
  11292. ' }',
  11293. '}'
  11294. ].join( '\n' ) );
  11295. gl.compileShader( vertexShader );
  11296. gl.compileShader( fragmentShader );
  11297. gl.attachShader( program, vertexShader );
  11298. gl.attachShader( program, fragmentShader );
  11299. gl.linkProgram( program );
  11300. return program;
  11301. }
  11302. function painterSortStable( a, b ) {
  11303. if ( a.renderOrder !== b.renderOrder ) {
  11304. return a.renderOrder - b.renderOrder;
  11305. } else if ( a.z !== b.z ) {
  11306. return b.z - a.z;
  11307. } else {
  11308. return b.id - a.id;
  11309. }
  11310. }
  11311. }
  11312. /**
  11313. * @author mrdoob / http://mrdoob.com/
  11314. */
  11315. function WebGLState( gl, extensions, utils ) {
  11316. function ColorBuffer() {
  11317. var locked = false;
  11318. var color = new Vector4();
  11319. var currentColorMask = null;
  11320. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11321. return {
  11322. setMask: function ( colorMask ) {
  11323. if ( currentColorMask !== colorMask && ! locked ) {
  11324. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11325. currentColorMask = colorMask;
  11326. }
  11327. },
  11328. setLocked: function ( lock ) {
  11329. locked = lock;
  11330. },
  11331. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11332. if ( premultipliedAlpha === true ) {
  11333. r *= a; g *= a; b *= a;
  11334. }
  11335. color.set( r, g, b, a );
  11336. if ( currentColorClear.equals( color ) === false ) {
  11337. gl.clearColor( r, g, b, a );
  11338. currentColorClear.copy( color );
  11339. }
  11340. },
  11341. reset: function () {
  11342. locked = false;
  11343. currentColorMask = null;
  11344. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11345. }
  11346. };
  11347. }
  11348. function DepthBuffer() {
  11349. var locked = false;
  11350. var currentDepthMask = null;
  11351. var currentDepthFunc = null;
  11352. var currentDepthClear = null;
  11353. return {
  11354. setTest: function ( depthTest ) {
  11355. if ( depthTest ) {
  11356. enable( gl.DEPTH_TEST );
  11357. } else {
  11358. disable( gl.DEPTH_TEST );
  11359. }
  11360. },
  11361. setMask: function ( depthMask ) {
  11362. if ( currentDepthMask !== depthMask && ! locked ) {
  11363. gl.depthMask( depthMask );
  11364. currentDepthMask = depthMask;
  11365. }
  11366. },
  11367. setFunc: function ( depthFunc ) {
  11368. if ( currentDepthFunc !== depthFunc ) {
  11369. if ( depthFunc ) {
  11370. switch ( depthFunc ) {
  11371. case NeverDepth:
  11372. gl.depthFunc( gl.NEVER );
  11373. break;
  11374. case AlwaysDepth:
  11375. gl.depthFunc( gl.ALWAYS );
  11376. break;
  11377. case LessDepth:
  11378. gl.depthFunc( gl.LESS );
  11379. break;
  11380. case LessEqualDepth:
  11381. gl.depthFunc( gl.LEQUAL );
  11382. break;
  11383. case EqualDepth:
  11384. gl.depthFunc( gl.EQUAL );
  11385. break;
  11386. case GreaterEqualDepth:
  11387. gl.depthFunc( gl.GEQUAL );
  11388. break;
  11389. case GreaterDepth:
  11390. gl.depthFunc( gl.GREATER );
  11391. break;
  11392. case NotEqualDepth:
  11393. gl.depthFunc( gl.NOTEQUAL );
  11394. break;
  11395. default:
  11396. gl.depthFunc( gl.LEQUAL );
  11397. }
  11398. } else {
  11399. gl.depthFunc( gl.LEQUAL );
  11400. }
  11401. currentDepthFunc = depthFunc;
  11402. }
  11403. },
  11404. setLocked: function ( lock ) {
  11405. locked = lock;
  11406. },
  11407. setClear: function ( depth ) {
  11408. if ( currentDepthClear !== depth ) {
  11409. gl.clearDepth( depth );
  11410. currentDepthClear = depth;
  11411. }
  11412. },
  11413. reset: function () {
  11414. locked = false;
  11415. currentDepthMask = null;
  11416. currentDepthFunc = null;
  11417. currentDepthClear = null;
  11418. }
  11419. };
  11420. }
  11421. function StencilBuffer() {
  11422. var locked = false;
  11423. var currentStencilMask = null;
  11424. var currentStencilFunc = null;
  11425. var currentStencilRef = null;
  11426. var currentStencilFuncMask = null;
  11427. var currentStencilFail = null;
  11428. var currentStencilZFail = null;
  11429. var currentStencilZPass = null;
  11430. var currentStencilClear = null;
  11431. return {
  11432. setTest: function ( stencilTest ) {
  11433. if ( stencilTest ) {
  11434. enable( gl.STENCIL_TEST );
  11435. } else {
  11436. disable( gl.STENCIL_TEST );
  11437. }
  11438. },
  11439. setMask: function ( stencilMask ) {
  11440. if ( currentStencilMask !== stencilMask && ! locked ) {
  11441. gl.stencilMask( stencilMask );
  11442. currentStencilMask = stencilMask;
  11443. }
  11444. },
  11445. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11446. if ( currentStencilFunc !== stencilFunc ||
  11447. currentStencilRef !== stencilRef ||
  11448. currentStencilFuncMask !== stencilMask ) {
  11449. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11450. currentStencilFunc = stencilFunc;
  11451. currentStencilRef = stencilRef;
  11452. currentStencilFuncMask = stencilMask;
  11453. }
  11454. },
  11455. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11456. if ( currentStencilFail !== stencilFail ||
  11457. currentStencilZFail !== stencilZFail ||
  11458. currentStencilZPass !== stencilZPass ) {
  11459. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11460. currentStencilFail = stencilFail;
  11461. currentStencilZFail = stencilZFail;
  11462. currentStencilZPass = stencilZPass;
  11463. }
  11464. },
  11465. setLocked: function ( lock ) {
  11466. locked = lock;
  11467. },
  11468. setClear: function ( stencil ) {
  11469. if ( currentStencilClear !== stencil ) {
  11470. gl.clearStencil( stencil );
  11471. currentStencilClear = stencil;
  11472. }
  11473. },
  11474. reset: function () {
  11475. locked = false;
  11476. currentStencilMask = null;
  11477. currentStencilFunc = null;
  11478. currentStencilRef = null;
  11479. currentStencilFuncMask = null;
  11480. currentStencilFail = null;
  11481. currentStencilZFail = null;
  11482. currentStencilZPass = null;
  11483. currentStencilClear = null;
  11484. }
  11485. };
  11486. }
  11487. //
  11488. var colorBuffer = new ColorBuffer();
  11489. var depthBuffer = new DepthBuffer();
  11490. var stencilBuffer = new StencilBuffer();
  11491. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11492. var newAttributes = new Uint8Array( maxVertexAttributes );
  11493. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11494. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11495. var capabilities = {};
  11496. var compressedTextureFormats = null;
  11497. var currentProgram = null;
  11498. var currentBlending = null;
  11499. var currentBlendEquation = null;
  11500. var currentBlendSrc = null;
  11501. var currentBlendDst = null;
  11502. var currentBlendEquationAlpha = null;
  11503. var currentBlendSrcAlpha = null;
  11504. var currentBlendDstAlpha = null;
  11505. var currentPremultipledAlpha = false;
  11506. var currentFlipSided = null;
  11507. var currentCullFace = null;
  11508. var currentLineWidth = null;
  11509. var currentPolygonOffsetFactor = null;
  11510. var currentPolygonOffsetUnits = null;
  11511. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  11512. var lineWidthAvailable = false;
  11513. var version = 0;
  11514. var glVersion = gl.getParameter( gl.VERSION );
  11515. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11516. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11517. lineWidthAvailable = ( version >= 1.0 );
  11518. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11519. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11520. lineWidthAvailable = ( version >= 2.0 );
  11521. }
  11522. var currentTextureSlot = null;
  11523. var currentBoundTextures = {};
  11524. var currentScissor = new Vector4();
  11525. var currentViewport = new Vector4();
  11526. function createTexture( type, target, count ) {
  11527. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11528. var texture = gl.createTexture();
  11529. gl.bindTexture( type, texture );
  11530. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  11531. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  11532. for ( var i = 0; i < count; i ++ ) {
  11533. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  11534. }
  11535. return texture;
  11536. }
  11537. var emptyTextures = {};
  11538. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  11539. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  11540. // init
  11541. colorBuffer.setClear( 0, 0, 0, 1 );
  11542. depthBuffer.setClear( 1 );
  11543. stencilBuffer.setClear( 0 );
  11544. enable( gl.DEPTH_TEST );
  11545. depthBuffer.setFunc( LessEqualDepth );
  11546. setFlipSided( false );
  11547. setCullFace( CullFaceBack );
  11548. enable( gl.CULL_FACE );
  11549. enable( gl.BLEND );
  11550. setBlending( NormalBlending );
  11551. //
  11552. function initAttributes() {
  11553. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11554. newAttributes[ i ] = 0;
  11555. }
  11556. }
  11557. function enableAttribute( attribute ) {
  11558. enableAttributeAndDivisor( attribute, 0 );
  11559. }
  11560. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11561. newAttributes[ attribute ] = 1;
  11562. if ( enabledAttributes[ attribute ] === 0 ) {
  11563. gl.enableVertexAttribArray( attribute );
  11564. enabledAttributes[ attribute ] = 1;
  11565. }
  11566. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11567. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11568. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  11569. attributeDivisors[ attribute ] = meshPerAttribute;
  11570. }
  11571. }
  11572. function disableUnusedAttributes() {
  11573. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11574. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11575. gl.disableVertexAttribArray( i );
  11576. enabledAttributes[ i ] = 0;
  11577. }
  11578. }
  11579. }
  11580. function enable( id ) {
  11581. if ( capabilities[ id ] !== true ) {
  11582. gl.enable( id );
  11583. capabilities[ id ] = true;
  11584. }
  11585. }
  11586. function disable( id ) {
  11587. if ( capabilities[ id ] !== false ) {
  11588. gl.disable( id );
  11589. capabilities[ id ] = false;
  11590. }
  11591. }
  11592. function getCompressedTextureFormats() {
  11593. if ( compressedTextureFormats === null ) {
  11594. compressedTextureFormats = [];
  11595. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11596. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11597. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11598. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11599. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  11600. for ( var i = 0; i < formats.length; i ++ ) {
  11601. compressedTextureFormats.push( formats[ i ] );
  11602. }
  11603. }
  11604. }
  11605. return compressedTextureFormats;
  11606. }
  11607. function useProgram( program ) {
  11608. if ( currentProgram !== program ) {
  11609. gl.useProgram( program );
  11610. currentProgram = program;
  11611. return true;
  11612. }
  11613. return false;
  11614. }
  11615. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11616. if ( blending !== NoBlending ) {
  11617. enable( gl.BLEND );
  11618. } else {
  11619. disable( gl.BLEND );
  11620. }
  11621. if ( blending !== CustomBlending ) {
  11622. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11623. switch ( blending ) {
  11624. case AdditiveBlending:
  11625. if ( premultipliedAlpha ) {
  11626. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11627. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  11628. } else {
  11629. gl.blendEquation( gl.FUNC_ADD );
  11630. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  11631. }
  11632. break;
  11633. case SubtractiveBlending:
  11634. if ( premultipliedAlpha ) {
  11635. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11636. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  11637. } else {
  11638. gl.blendEquation( gl.FUNC_ADD );
  11639. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  11640. }
  11641. break;
  11642. case MultiplyBlending:
  11643. if ( premultipliedAlpha ) {
  11644. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11645. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  11646. } else {
  11647. gl.blendEquation( gl.FUNC_ADD );
  11648. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  11649. }
  11650. break;
  11651. default:
  11652. if ( premultipliedAlpha ) {
  11653. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11654. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11655. } else {
  11656. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11657. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11658. }
  11659. }
  11660. }
  11661. currentBlendEquation = null;
  11662. currentBlendSrc = null;
  11663. currentBlendDst = null;
  11664. currentBlendEquationAlpha = null;
  11665. currentBlendSrcAlpha = null;
  11666. currentBlendDstAlpha = null;
  11667. } else {
  11668. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11669. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11670. blendDstAlpha = blendDstAlpha || blendDst;
  11671. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11672. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11673. currentBlendEquation = blendEquation;
  11674. currentBlendEquationAlpha = blendEquationAlpha;
  11675. }
  11676. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11677. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11678. currentBlendSrc = blendSrc;
  11679. currentBlendDst = blendDst;
  11680. currentBlendSrcAlpha = blendSrcAlpha;
  11681. currentBlendDstAlpha = blendDstAlpha;
  11682. }
  11683. }
  11684. currentBlending = blending;
  11685. currentPremultipledAlpha = premultipliedAlpha;
  11686. }
  11687. function setMaterial( material, frontFaceCW ) {
  11688. material.side === DoubleSide
  11689. ? disable( gl.CULL_FACE )
  11690. : enable( gl.CULL_FACE );
  11691. var flipSided = ( material.side === BackSide );
  11692. if ( frontFaceCW ) flipSided = ! flipSided;
  11693. setFlipSided( flipSided );
  11694. material.transparent === true
  11695. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  11696. : setBlending( NoBlending );
  11697. depthBuffer.setFunc( material.depthFunc );
  11698. depthBuffer.setTest( material.depthTest );
  11699. depthBuffer.setMask( material.depthWrite );
  11700. colorBuffer.setMask( material.colorWrite );
  11701. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11702. }
  11703. //
  11704. function setFlipSided( flipSided ) {
  11705. if ( currentFlipSided !== flipSided ) {
  11706. if ( flipSided ) {
  11707. gl.frontFace( gl.CW );
  11708. } else {
  11709. gl.frontFace( gl.CCW );
  11710. }
  11711. currentFlipSided = flipSided;
  11712. }
  11713. }
  11714. function setCullFace( cullFace ) {
  11715. if ( cullFace !== CullFaceNone ) {
  11716. enable( gl.CULL_FACE );
  11717. if ( cullFace !== currentCullFace ) {
  11718. if ( cullFace === CullFaceBack ) {
  11719. gl.cullFace( gl.BACK );
  11720. } else if ( cullFace === CullFaceFront ) {
  11721. gl.cullFace( gl.FRONT );
  11722. } else {
  11723. gl.cullFace( gl.FRONT_AND_BACK );
  11724. }
  11725. }
  11726. } else {
  11727. disable( gl.CULL_FACE );
  11728. }
  11729. currentCullFace = cullFace;
  11730. }
  11731. function setLineWidth( width ) {
  11732. if ( width !== currentLineWidth ) {
  11733. if ( lineWidthAvailable ) gl.lineWidth( width );
  11734. currentLineWidth = width;
  11735. }
  11736. }
  11737. function setPolygonOffset( polygonOffset, factor, units ) {
  11738. if ( polygonOffset ) {
  11739. enable( gl.POLYGON_OFFSET_FILL );
  11740. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11741. gl.polygonOffset( factor, units );
  11742. currentPolygonOffsetFactor = factor;
  11743. currentPolygonOffsetUnits = units;
  11744. }
  11745. } else {
  11746. disable( gl.POLYGON_OFFSET_FILL );
  11747. }
  11748. }
  11749. function setScissorTest( scissorTest ) {
  11750. if ( scissorTest ) {
  11751. enable( gl.SCISSOR_TEST );
  11752. } else {
  11753. disable( gl.SCISSOR_TEST );
  11754. }
  11755. }
  11756. // texture
  11757. function activeTexture( webglSlot ) {
  11758. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  11759. if ( currentTextureSlot !== webglSlot ) {
  11760. gl.activeTexture( webglSlot );
  11761. currentTextureSlot = webglSlot;
  11762. }
  11763. }
  11764. function bindTexture( webglType, webglTexture ) {
  11765. if ( currentTextureSlot === null ) {
  11766. activeTexture();
  11767. }
  11768. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11769. if ( boundTexture === undefined ) {
  11770. boundTexture = { type: undefined, texture: undefined };
  11771. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11772. }
  11773. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11774. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11775. boundTexture.type = webglType;
  11776. boundTexture.texture = webglTexture;
  11777. }
  11778. }
  11779. function compressedTexImage2D() {
  11780. try {
  11781. gl.compressedTexImage2D.apply( gl, arguments );
  11782. } catch ( error ) {
  11783. console.error( 'THREE.WebGLState:', error );
  11784. }
  11785. }
  11786. function texImage2D() {
  11787. try {
  11788. gl.texImage2D.apply( gl, arguments );
  11789. } catch ( error ) {
  11790. console.error( 'THREE.WebGLState:', error );
  11791. }
  11792. }
  11793. //
  11794. function scissor( scissor ) {
  11795. if ( currentScissor.equals( scissor ) === false ) {
  11796. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11797. currentScissor.copy( scissor );
  11798. }
  11799. }
  11800. function viewport( viewport ) {
  11801. if ( currentViewport.equals( viewport ) === false ) {
  11802. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11803. currentViewport.copy( viewport );
  11804. }
  11805. }
  11806. //
  11807. function reset() {
  11808. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11809. if ( enabledAttributes[ i ] === 1 ) {
  11810. gl.disableVertexAttribArray( i );
  11811. enabledAttributes[ i ] = 0;
  11812. }
  11813. }
  11814. capabilities = {};
  11815. compressedTextureFormats = null;
  11816. currentTextureSlot = null;
  11817. currentBoundTextures = {};
  11818. currentProgram = null;
  11819. currentBlending = null;
  11820. currentFlipSided = null;
  11821. currentCullFace = null;
  11822. colorBuffer.reset();
  11823. depthBuffer.reset();
  11824. stencilBuffer.reset();
  11825. }
  11826. return {
  11827. buffers: {
  11828. color: colorBuffer,
  11829. depth: depthBuffer,
  11830. stencil: stencilBuffer
  11831. },
  11832. initAttributes: initAttributes,
  11833. enableAttribute: enableAttribute,
  11834. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11835. disableUnusedAttributes: disableUnusedAttributes,
  11836. enable: enable,
  11837. disable: disable,
  11838. getCompressedTextureFormats: getCompressedTextureFormats,
  11839. useProgram: useProgram,
  11840. setBlending: setBlending,
  11841. setMaterial: setMaterial,
  11842. setFlipSided: setFlipSided,
  11843. setCullFace: setCullFace,
  11844. setLineWidth: setLineWidth,
  11845. setPolygonOffset: setPolygonOffset,
  11846. setScissorTest: setScissorTest,
  11847. activeTexture: activeTexture,
  11848. bindTexture: bindTexture,
  11849. compressedTexImage2D: compressedTexImage2D,
  11850. texImage2D: texImage2D,
  11851. scissor: scissor,
  11852. viewport: viewport,
  11853. reset: reset
  11854. };
  11855. }
  11856. /**
  11857. * @author mrdoob / http://mrdoob.com/
  11858. */
  11859. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  11860. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext ); /* global WebGL2RenderingContext */
  11861. var _videoTextures = {};
  11862. var _canvas;
  11863. //
  11864. function clampToMaxSize( image, maxSize ) {
  11865. if ( image.width > maxSize || image.height > maxSize ) {
  11866. if ( 'data' in image ) {
  11867. console.warn( 'THREE.WebGLRenderer: image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  11868. return;
  11869. }
  11870. // Warning: Scaling through the canvas will only work with images that use
  11871. // premultiplied alpha.
  11872. var scale = maxSize / Math.max( image.width, image.height );
  11873. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11874. canvas.width = Math.floor( image.width * scale );
  11875. canvas.height = Math.floor( image.height * scale );
  11876. var context = canvas.getContext( '2d' );
  11877. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  11878. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  11879. return canvas;
  11880. }
  11881. return image;
  11882. }
  11883. function isPowerOfTwo( image ) {
  11884. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  11885. }
  11886. function makePowerOfTwo( image ) {
  11887. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  11888. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11889. _canvas.width = _Math.floorPowerOfTwo( image.width );
  11890. _canvas.height = _Math.floorPowerOfTwo( image.height );
  11891. var context = _canvas.getContext( '2d' );
  11892. context.drawImage( image, 0, 0, _canvas.width, _canvas.height );
  11893. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + _canvas.width + 'x' + _canvas.height, image );
  11894. return _canvas;
  11895. }
  11896. return image;
  11897. }
  11898. function textureNeedsPowerOfTwo( texture ) {
  11899. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  11900. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  11901. }
  11902. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  11903. return texture.generateMipmaps && isPowerOfTwo &&
  11904. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  11905. }
  11906. function generateMipmap( target, texture, width, height ) {
  11907. _gl.generateMipmap( target );
  11908. var textureProperties = properties.get( texture );
  11909. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  11910. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  11911. }
  11912. // Fallback filters for non-power-of-2 textures
  11913. function filterFallback( f ) {
  11914. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  11915. return _gl.NEAREST;
  11916. }
  11917. return _gl.LINEAR;
  11918. }
  11919. //
  11920. function onTextureDispose( event ) {
  11921. var texture = event.target;
  11922. texture.removeEventListener( 'dispose', onTextureDispose );
  11923. deallocateTexture( texture );
  11924. if ( texture.isVideoTexture ) {
  11925. delete _videoTextures[ texture.id ];
  11926. }
  11927. info.memory.textures --;
  11928. }
  11929. function onRenderTargetDispose( event ) {
  11930. var renderTarget = event.target;
  11931. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11932. deallocateRenderTarget( renderTarget );
  11933. info.memory.textures --;
  11934. }
  11935. //
  11936. function deallocateTexture( texture ) {
  11937. var textureProperties = properties.get( texture );
  11938. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11939. // cube texture
  11940. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11941. } else {
  11942. // 2D texture
  11943. if ( textureProperties.__webglInit === undefined ) return;
  11944. _gl.deleteTexture( textureProperties.__webglTexture );
  11945. }
  11946. // remove all webgl properties
  11947. properties.remove( texture );
  11948. }
  11949. function deallocateRenderTarget( renderTarget ) {
  11950. var renderTargetProperties = properties.get( renderTarget );
  11951. var textureProperties = properties.get( renderTarget.texture );
  11952. if ( ! renderTarget ) return;
  11953. if ( textureProperties.__webglTexture !== undefined ) {
  11954. _gl.deleteTexture( textureProperties.__webglTexture );
  11955. }
  11956. if ( renderTarget.depthTexture ) {
  11957. renderTarget.depthTexture.dispose();
  11958. }
  11959. if ( renderTarget.isWebGLRenderTargetCube ) {
  11960. for ( var i = 0; i < 6; i ++ ) {
  11961. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  11962. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  11963. }
  11964. } else {
  11965. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  11966. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  11967. }
  11968. properties.remove( renderTarget.texture );
  11969. properties.remove( renderTarget );
  11970. }
  11971. //
  11972. function setTexture2D( texture, slot ) {
  11973. var textureProperties = properties.get( texture );
  11974. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  11975. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  11976. var image = texture.image;
  11977. if ( image === undefined ) {
  11978. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  11979. } else if ( image.complete === false ) {
  11980. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  11981. } else {
  11982. uploadTexture( textureProperties, texture, slot );
  11983. return;
  11984. }
  11985. }
  11986. state.activeTexture( _gl.TEXTURE0 + slot );
  11987. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  11988. }
  11989. function setTextureCube( texture, slot ) {
  11990. var textureProperties = properties.get( texture );
  11991. if ( texture.image.length === 6 ) {
  11992. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  11993. if ( ! textureProperties.__image__webglTextureCube ) {
  11994. texture.addEventListener( 'dispose', onTextureDispose );
  11995. textureProperties.__image__webglTextureCube = _gl.createTexture();
  11996. info.memory.textures ++;
  11997. }
  11998. state.activeTexture( _gl.TEXTURE0 + slot );
  11999. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  12000. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  12001. var isCompressed = ( texture && texture.isCompressedTexture );
  12002. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12003. var cubeImage = [];
  12004. for ( var i = 0; i < 6; i ++ ) {
  12005. if ( ! isCompressed && ! isDataTexture ) {
  12006. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  12007. } else {
  12008. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12009. }
  12010. }
  12011. var image = cubeImage[ 0 ],
  12012. isPowerOfTwoImage = isPowerOfTwo( image ),
  12013. glFormat = utils.convert( texture.format ),
  12014. glType = utils.convert( texture.type );
  12015. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  12016. for ( var i = 0; i < 6; i ++ ) {
  12017. if ( ! isCompressed ) {
  12018. if ( isDataTexture ) {
  12019. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12020. } else {
  12021. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  12022. }
  12023. } else {
  12024. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12025. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12026. mipmap = mipmaps[ j ];
  12027. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12028. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12029. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12030. } else {
  12031. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12032. }
  12033. } else {
  12034. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12035. }
  12036. }
  12037. }
  12038. }
  12039. if ( ! isCompressed ) {
  12040. textureProperties.__maxMipLevel = 0;
  12041. } else {
  12042. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12043. }
  12044. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  12045. // We assume images for cube map have the same size.
  12046. generateMipmap( _gl.TEXTURE_CUBE_MAP, texture, image.width, image.height );
  12047. }
  12048. textureProperties.__version = texture.version;
  12049. if ( texture.onUpdate ) texture.onUpdate( texture );
  12050. } else {
  12051. state.activeTexture( _gl.TEXTURE0 + slot );
  12052. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  12053. }
  12054. }
  12055. }
  12056. function setTextureCubeDynamic( texture, slot ) {
  12057. state.activeTexture( _gl.TEXTURE0 + slot );
  12058. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  12059. }
  12060. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  12061. var extension;
  12062. if ( isPowerOfTwoImage ) {
  12063. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
  12064. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
  12065. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
  12066. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
  12067. } else {
  12068. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  12069. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  12070. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12071. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  12072. }
  12073. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  12074. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  12075. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12076. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  12077. }
  12078. }
  12079. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12080. if ( extension ) {
  12081. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12082. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  12083. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12084. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12085. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12086. }
  12087. }
  12088. }
  12089. function uploadTexture( textureProperties, texture, slot ) {
  12090. if ( textureProperties.__webglInit === undefined ) {
  12091. textureProperties.__webglInit = true;
  12092. texture.addEventListener( 'dispose', onTextureDispose );
  12093. textureProperties.__webglTexture = _gl.createTexture();
  12094. info.memory.textures ++;
  12095. }
  12096. state.activeTexture( _gl.TEXTURE0 + slot );
  12097. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  12098. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  12099. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  12100. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  12101. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  12102. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  12103. image = makePowerOfTwo( image );
  12104. }
  12105. var isPowerOfTwoImage = isPowerOfTwo( image ),
  12106. glFormat = utils.convert( texture.format ),
  12107. glType = utils.convert( texture.type );
  12108. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  12109. var mipmap, mipmaps = texture.mipmaps;
  12110. if ( texture.isDepthTexture ) {
  12111. // populate depth texture with dummy data
  12112. var internalFormat = _gl.DEPTH_COMPONENT;
  12113. if ( texture.type === FloatType ) {
  12114. if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12115. internalFormat = _gl.DEPTH_COMPONENT32F;
  12116. } else if ( _isWebGL2 ) {
  12117. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12118. internalFormat = _gl.DEPTH_COMPONENT16;
  12119. }
  12120. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  12121. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12122. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12123. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12124. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12125. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12126. texture.type = UnsignedShortType;
  12127. glType = utils.convert( texture.type );
  12128. }
  12129. }
  12130. // Depth stencil textures need the DEPTH_STENCIL internal format
  12131. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12132. if ( texture.format === DepthStencilFormat ) {
  12133. internalFormat = _gl.DEPTH_STENCIL;
  12134. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12135. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12136. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12137. if ( texture.type !== UnsignedInt248Type ) {
  12138. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12139. texture.type = UnsignedInt248Type;
  12140. glType = utils.convert( texture.type );
  12141. }
  12142. }
  12143. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  12144. } else if ( texture.isDataTexture ) {
  12145. // use manually created mipmaps if available
  12146. // if there are no manual mipmaps
  12147. // set 0 level mipmap and then use GL to generate other mipmap levels
  12148. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12149. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12150. mipmap = mipmaps[ i ];
  12151. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12152. }
  12153. texture.generateMipmaps = false;
  12154. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12155. } else {
  12156. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12157. textureProperties.__maxMipLevel = 0;
  12158. }
  12159. } else if ( texture.isCompressedTexture ) {
  12160. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12161. mipmap = mipmaps[ i ];
  12162. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12163. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12164. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12165. } else {
  12166. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12167. }
  12168. } else {
  12169. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12170. }
  12171. }
  12172. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12173. } else {
  12174. // regular Texture (image, video, canvas)
  12175. // use manually created mipmaps if available
  12176. // if there are no manual mipmaps
  12177. // set 0 level mipmap and then use GL to generate other mipmap levels
  12178. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12179. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12180. mipmap = mipmaps[ i ];
  12181. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  12182. }
  12183. texture.generateMipmaps = false;
  12184. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12185. } else {
  12186. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  12187. textureProperties.__maxMipLevel = 0;
  12188. }
  12189. }
  12190. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  12191. generateMipmap( _gl.TEXTURE_2D, texture, image.width, image.height );
  12192. }
  12193. textureProperties.__version = texture.version;
  12194. if ( texture.onUpdate ) texture.onUpdate( texture );
  12195. }
  12196. // Render targets
  12197. // Setup storage for target texture and bind it to correct framebuffer
  12198. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12199. var glFormat = utils.convert( renderTarget.texture.format );
  12200. var glType = utils.convert( renderTarget.texture.type );
  12201. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12202. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  12203. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12204. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  12205. }
  12206. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12207. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  12208. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  12209. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12210. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  12211. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  12212. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12213. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  12214. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  12215. } else {
  12216. // FIXME: We don't support !depth !stencil
  12217. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  12218. }
  12219. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  12220. }
  12221. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12222. function setupDepthTexture( framebuffer, renderTarget ) {
  12223. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12224. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12225. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  12226. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12227. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12228. }
  12229. // upload an empty depth texture with framebuffer size
  12230. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12231. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12232. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12233. renderTarget.depthTexture.image.width = renderTarget.width;
  12234. renderTarget.depthTexture.image.height = renderTarget.height;
  12235. renderTarget.depthTexture.needsUpdate = true;
  12236. }
  12237. setTexture2D( renderTarget.depthTexture, 0 );
  12238. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12239. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12240. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  12241. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12242. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  12243. } else {
  12244. throw new Error( 'Unknown depthTexture format' );
  12245. }
  12246. }
  12247. // Setup GL resources for a non-texture depth buffer
  12248. function setupDepthRenderbuffer( renderTarget ) {
  12249. var renderTargetProperties = properties.get( renderTarget );
  12250. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12251. if ( renderTarget.depthTexture ) {
  12252. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12253. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12254. } else {
  12255. if ( isCube ) {
  12256. renderTargetProperties.__webglDepthbuffer = [];
  12257. for ( var i = 0; i < 6; i ++ ) {
  12258. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  12259. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12260. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12261. }
  12262. } else {
  12263. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  12264. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12265. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12266. }
  12267. }
  12268. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  12269. }
  12270. // Set up GL resources for the render target
  12271. function setupRenderTarget( renderTarget ) {
  12272. var renderTargetProperties = properties.get( renderTarget );
  12273. var textureProperties = properties.get( renderTarget.texture );
  12274. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12275. textureProperties.__webglTexture = _gl.createTexture();
  12276. info.memory.textures ++;
  12277. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12278. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12279. // Setup framebuffer
  12280. if ( isCube ) {
  12281. renderTargetProperties.__webglFramebuffer = [];
  12282. for ( var i = 0; i < 6; i ++ ) {
  12283. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12284. }
  12285. } else {
  12286. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12287. }
  12288. // Setup color buffer
  12289. if ( isCube ) {
  12290. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  12291. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  12292. for ( var i = 0; i < 6; i ++ ) {
  12293. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  12294. }
  12295. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12296. generateMipmap( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, renderTarget.width, renderTarget.height );
  12297. }
  12298. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  12299. } else {
  12300. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  12301. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  12302. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  12303. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12304. generateMipmap( _gl.TEXTURE_2D, renderTarget.texture, renderTarget.width, renderTarget.height );
  12305. }
  12306. state.bindTexture( _gl.TEXTURE_2D, null );
  12307. }
  12308. // Setup depth and stencil buffers
  12309. if ( renderTarget.depthBuffer ) {
  12310. setupDepthRenderbuffer( renderTarget );
  12311. }
  12312. }
  12313. function updateRenderTargetMipmap( renderTarget ) {
  12314. var texture = renderTarget.texture;
  12315. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12316. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  12317. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  12318. var webglTexture = properties.get( texture ).__webglTexture;
  12319. state.bindTexture( target, webglTexture );
  12320. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12321. state.bindTexture( target, null );
  12322. }
  12323. }
  12324. function updateVideoTexture( texture ) {
  12325. var id = texture.id;
  12326. var frame = info.render.frame;
  12327. // Check the last frame we updated the VideoTexture
  12328. if ( _videoTextures[ id ] !== frame ) {
  12329. _videoTextures[ id ] = frame;
  12330. texture.update();
  12331. }
  12332. }
  12333. this.setTexture2D = setTexture2D;
  12334. this.setTextureCube = setTextureCube;
  12335. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12336. this.setupRenderTarget = setupRenderTarget;
  12337. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12338. }
  12339. /**
  12340. * @author thespite / http://www.twitter.com/thespite
  12341. */
  12342. function WebGLUtils( gl, extensions ) {
  12343. function convert( p ) {
  12344. var extension;
  12345. if ( p === RepeatWrapping ) return gl.REPEAT;
  12346. if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
  12347. if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
  12348. if ( p === NearestFilter ) return gl.NEAREST;
  12349. if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
  12350. if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
  12351. if ( p === LinearFilter ) return gl.LINEAR;
  12352. if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
  12353. if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
  12354. if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
  12355. if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
  12356. if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
  12357. if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5;
  12358. if ( p === ByteType ) return gl.BYTE;
  12359. if ( p === ShortType ) return gl.SHORT;
  12360. if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;
  12361. if ( p === IntType ) return gl.INT;
  12362. if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;
  12363. if ( p === FloatType ) return gl.FLOAT;
  12364. if ( p === HalfFloatType ) {
  12365. extension = extensions.get( 'OES_texture_half_float' );
  12366. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12367. }
  12368. if ( p === AlphaFormat ) return gl.ALPHA;
  12369. if ( p === RGBFormat ) return gl.RGB;
  12370. if ( p === RGBAFormat ) return gl.RGBA;
  12371. if ( p === LuminanceFormat ) return gl.LUMINANCE;
  12372. if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
  12373. if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;
  12374. if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
  12375. if ( p === AddEquation ) return gl.FUNC_ADD;
  12376. if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
  12377. if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
  12378. if ( p === ZeroFactor ) return gl.ZERO;
  12379. if ( p === OneFactor ) return gl.ONE;
  12380. if ( p === SrcColorFactor ) return gl.SRC_COLOR;
  12381. if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
  12382. if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
  12383. if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
  12384. if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
  12385. if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
  12386. if ( p === DstColorFactor ) return gl.DST_COLOR;
  12387. if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
  12388. if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
  12389. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12390. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12391. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12392. if ( extension !== null ) {
  12393. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12394. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12395. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12396. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12397. }
  12398. }
  12399. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12400. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12401. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12402. if ( extension !== null ) {
  12403. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12404. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12405. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12406. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12407. }
  12408. }
  12409. if ( p === RGB_ETC1_Format ) {
  12410. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12411. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12412. }
  12413. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12414. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12415. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12416. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12417. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12418. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12419. if ( extension !== null ) {
  12420. return p;
  12421. }
  12422. }
  12423. if ( p === MinEquation || p === MaxEquation ) {
  12424. extension = extensions.get( 'EXT_blend_minmax' );
  12425. if ( extension !== null ) {
  12426. if ( p === MinEquation ) return extension.MIN_EXT;
  12427. if ( p === MaxEquation ) return extension.MAX_EXT;
  12428. }
  12429. }
  12430. if ( p === UnsignedInt248Type ) {
  12431. extension = extensions.get( 'WEBGL_depth_texture' );
  12432. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12433. }
  12434. return 0;
  12435. }
  12436. return { convert: convert };
  12437. }
  12438. /**
  12439. * @author mrdoob / http://mrdoob.com/
  12440. * @author greggman / http://games.greggman.com/
  12441. * @author zz85 / http://www.lab4games.net/zz85/blog
  12442. * @author tschw
  12443. */
  12444. function PerspectiveCamera( fov, aspect, near, far ) {
  12445. Camera.call( this );
  12446. this.type = 'PerspectiveCamera';
  12447. this.fov = fov !== undefined ? fov : 50;
  12448. this.zoom = 1;
  12449. this.near = near !== undefined ? near : 0.1;
  12450. this.far = far !== undefined ? far : 2000;
  12451. this.focus = 10;
  12452. this.aspect = aspect !== undefined ? aspect : 1;
  12453. this.view = null;
  12454. this.filmGauge = 35; // width of the film (default in millimeters)
  12455. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12456. this.updateProjectionMatrix();
  12457. }
  12458. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12459. constructor: PerspectiveCamera,
  12460. isPerspectiveCamera: true,
  12461. copy: function ( source, recursive ) {
  12462. Camera.prototype.copy.call( this, source, recursive );
  12463. this.fov = source.fov;
  12464. this.zoom = source.zoom;
  12465. this.near = source.near;
  12466. this.far = source.far;
  12467. this.focus = source.focus;
  12468. this.aspect = source.aspect;
  12469. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12470. this.filmGauge = source.filmGauge;
  12471. this.filmOffset = source.filmOffset;
  12472. return this;
  12473. },
  12474. /**
  12475. * Sets the FOV by focal length in respect to the current .filmGauge.
  12476. *
  12477. * The default film gauge is 35, so that the focal length can be specified for
  12478. * a 35mm (full frame) camera.
  12479. *
  12480. * Values for focal length and film gauge must have the same unit.
  12481. */
  12482. setFocalLength: function ( focalLength ) {
  12483. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12484. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12485. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12486. this.updateProjectionMatrix();
  12487. },
  12488. /**
  12489. * Calculates the focal length from the current .fov and .filmGauge.
  12490. */
  12491. getFocalLength: function () {
  12492. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12493. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12494. },
  12495. getEffectiveFOV: function () {
  12496. return _Math.RAD2DEG * 2 * Math.atan(
  12497. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12498. },
  12499. getFilmWidth: function () {
  12500. // film not completely covered in portrait format (aspect < 1)
  12501. return this.filmGauge * Math.min( this.aspect, 1 );
  12502. },
  12503. getFilmHeight: function () {
  12504. // film not completely covered in landscape format (aspect > 1)
  12505. return this.filmGauge / Math.max( this.aspect, 1 );
  12506. },
  12507. /**
  12508. * Sets an offset in a larger frustum. This is useful for multi-window or
  12509. * multi-monitor/multi-machine setups.
  12510. *
  12511. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12512. * the monitors are in grid like this
  12513. *
  12514. * +---+---+---+
  12515. * | A | B | C |
  12516. * +---+---+---+
  12517. * | D | E | F |
  12518. * +---+---+---+
  12519. *
  12520. * then for each monitor you would call it like this
  12521. *
  12522. * var w = 1920;
  12523. * var h = 1080;
  12524. * var fullWidth = w * 3;
  12525. * var fullHeight = h * 2;
  12526. *
  12527. * --A--
  12528. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12529. * --B--
  12530. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12531. * --C--
  12532. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12533. * --D--
  12534. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12535. * --E--
  12536. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12537. * --F--
  12538. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12539. *
  12540. * Note there is no reason monitors have to be the same size or in a grid.
  12541. */
  12542. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12543. this.aspect = fullWidth / fullHeight;
  12544. if ( this.view === null ) {
  12545. this.view = {
  12546. enabled: true,
  12547. fullWidth: 1,
  12548. fullHeight: 1,
  12549. offsetX: 0,
  12550. offsetY: 0,
  12551. width: 1,
  12552. height: 1
  12553. };
  12554. }
  12555. this.view.enabled = true;
  12556. this.view.fullWidth = fullWidth;
  12557. this.view.fullHeight = fullHeight;
  12558. this.view.offsetX = x;
  12559. this.view.offsetY = y;
  12560. this.view.width = width;
  12561. this.view.height = height;
  12562. this.updateProjectionMatrix();
  12563. },
  12564. clearViewOffset: function () {
  12565. if ( this.view !== null ) {
  12566. this.view.enabled = false;
  12567. }
  12568. this.updateProjectionMatrix();
  12569. },
  12570. updateProjectionMatrix: function () {
  12571. var near = this.near,
  12572. top = near * Math.tan(
  12573. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  12574. height = 2 * top,
  12575. width = this.aspect * height,
  12576. left = - 0.5 * width,
  12577. view = this.view;
  12578. if ( this.view !== null && this.view.enabled ) {
  12579. var fullWidth = view.fullWidth,
  12580. fullHeight = view.fullHeight;
  12581. left += view.offsetX * width / fullWidth;
  12582. top -= view.offsetY * height / fullHeight;
  12583. width *= view.width / fullWidth;
  12584. height *= view.height / fullHeight;
  12585. }
  12586. var skew = this.filmOffset;
  12587. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  12588. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  12589. },
  12590. toJSON: function ( meta ) {
  12591. var data = Object3D.prototype.toJSON.call( this, meta );
  12592. data.object.fov = this.fov;
  12593. data.object.zoom = this.zoom;
  12594. data.object.near = this.near;
  12595. data.object.far = this.far;
  12596. data.object.focus = this.focus;
  12597. data.object.aspect = this.aspect;
  12598. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  12599. data.object.filmGauge = this.filmGauge;
  12600. data.object.filmOffset = this.filmOffset;
  12601. return data;
  12602. }
  12603. } );
  12604. /**
  12605. * @author mrdoob / http://mrdoob.com/
  12606. */
  12607. function ArrayCamera( array ) {
  12608. PerspectiveCamera.call( this );
  12609. this.cameras = array || [];
  12610. }
  12611. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  12612. constructor: ArrayCamera,
  12613. isArrayCamera: true
  12614. } );
  12615. /**
  12616. * @author mrdoob / http://mrdoob.com/
  12617. */
  12618. function WebVRManager( renderer ) {
  12619. var scope = this;
  12620. var device = null;
  12621. var frameData = null;
  12622. var poseTarget = null;
  12623. var standingMatrix = new Matrix4();
  12624. var standingMatrixInverse = new Matrix4();
  12625. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  12626. frameData = new window.VRFrameData();
  12627. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  12628. }
  12629. var matrixWorldInverse = new Matrix4();
  12630. var tempQuaternion = new Quaternion();
  12631. var tempPosition = new Vector3();
  12632. var cameraL = new PerspectiveCamera();
  12633. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  12634. cameraL.layers.enable( 1 );
  12635. var cameraR = new PerspectiveCamera();
  12636. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  12637. cameraR.layers.enable( 2 );
  12638. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  12639. cameraVR.layers.enable( 1 );
  12640. cameraVR.layers.enable( 2 );
  12641. //
  12642. function isPresenting() {
  12643. return device !== null && device.isPresenting === true;
  12644. }
  12645. var currentSize, currentPixelRatio;
  12646. function onVRDisplayPresentChange() {
  12647. if ( isPresenting() ) {
  12648. var eyeParameters = device.getEyeParameters( 'left' );
  12649. var renderWidth = eyeParameters.renderWidth;
  12650. var renderHeight = eyeParameters.renderHeight;
  12651. currentPixelRatio = renderer.getPixelRatio();
  12652. currentSize = renderer.getSize();
  12653. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  12654. animation.start();
  12655. } else if ( scope.enabled ) {
  12656. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  12657. animation.stop();
  12658. }
  12659. }
  12660. //
  12661. this.enabled = false;
  12662. this.userHeight = 1.6;
  12663. this.getDevice = function () {
  12664. return device;
  12665. };
  12666. this.setDevice = function ( value ) {
  12667. if ( value !== undefined ) device = value;
  12668. animation.setContext( value );
  12669. };
  12670. this.setPoseTarget = function ( object ) {
  12671. if ( object !== undefined ) poseTarget = object;
  12672. };
  12673. this.getCamera = function ( camera ) {
  12674. if ( device === null ) return camera;
  12675. device.depthNear = camera.near;
  12676. device.depthFar = camera.far;
  12677. device.getFrameData( frameData );
  12678. //
  12679. var stageParameters = device.stageParameters;
  12680. if ( stageParameters ) {
  12681. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  12682. } else {
  12683. standingMatrix.makeTranslation( 0, scope.userHeight, 0 );
  12684. }
  12685. var pose = frameData.pose;
  12686. var poseObject = poseTarget !== null ? poseTarget : camera;
  12687. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  12688. poseObject.matrix.copy( standingMatrix );
  12689. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  12690. if ( pose.orientation !== null ) {
  12691. tempQuaternion.fromArray( pose.orientation );
  12692. poseObject.quaternion.multiply( tempQuaternion );
  12693. }
  12694. if ( pose.position !== null ) {
  12695. tempQuaternion.setFromRotationMatrix( standingMatrix );
  12696. tempPosition.fromArray( pose.position );
  12697. tempPosition.applyQuaternion( tempQuaternion );
  12698. poseObject.position.add( tempPosition );
  12699. }
  12700. poseObject.updateMatrixWorld();
  12701. if ( device.isPresenting === false ) return camera;
  12702. //
  12703. cameraL.near = camera.near;
  12704. cameraR.near = camera.near;
  12705. cameraL.far = camera.far;
  12706. cameraR.far = camera.far;
  12707. cameraVR.matrixWorld.copy( camera.matrixWorld );
  12708. cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
  12709. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  12710. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  12711. // TODO (mrdoob) Double check this code
  12712. standingMatrixInverse.getInverse( standingMatrix );
  12713. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  12714. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  12715. var parent = poseObject.parent;
  12716. if ( parent !== null ) {
  12717. matrixWorldInverse.getInverse( parent.matrixWorld );
  12718. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  12719. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  12720. }
  12721. // envMap and Mirror needs camera.matrixWorld
  12722. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  12723. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  12724. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  12725. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  12726. // HACK (mrdoob)
  12727. // https://github.com/w3c/webvr/issues/203
  12728. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  12729. //
  12730. var layers = device.getLayers();
  12731. if ( layers.length ) {
  12732. var layer = layers[ 0 ];
  12733. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  12734. cameraL.bounds.fromArray( layer.leftBounds );
  12735. }
  12736. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  12737. cameraR.bounds.fromArray( layer.rightBounds );
  12738. }
  12739. }
  12740. return cameraVR;
  12741. };
  12742. this.getStandingMatrix = function () {
  12743. return standingMatrix;
  12744. };
  12745. this.isPresenting = isPresenting;
  12746. // Animation Loop
  12747. var animation = new WebGLAnimation();
  12748. this.setAnimationLoop = function ( callback ) {
  12749. animation.setAnimationLoop( callback );
  12750. };
  12751. this.submitFrame = function () {
  12752. if ( isPresenting() ) device.submitFrame();
  12753. };
  12754. this.dispose = function () {
  12755. if ( typeof window !== 'undefined' ) {
  12756. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  12757. }
  12758. };
  12759. }
  12760. /**
  12761. * @author mrdoob / http://mrdoob.com/
  12762. */
  12763. function WebXRManager( renderer ) {
  12764. var gl = renderer.context;
  12765. var device = null;
  12766. var session = null;
  12767. var frameOfRef = null;
  12768. var pose = null;
  12769. function isPresenting() {
  12770. return session !== null && frameOfRef !== null;
  12771. }
  12772. //
  12773. var cameraL = new PerspectiveCamera();
  12774. cameraL.layers.enable( 1 );
  12775. cameraL.viewport = new Vector4();
  12776. var cameraR = new PerspectiveCamera();
  12777. cameraR.layers.enable( 2 );
  12778. cameraR.viewport = new Vector4();
  12779. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  12780. cameraVR.layers.enable( 1 );
  12781. cameraVR.layers.enable( 2 );
  12782. //
  12783. this.enabled = false;
  12784. this.getDevice = function () {
  12785. return device;
  12786. };
  12787. this.setDevice = function ( value ) {
  12788. if ( value !== undefined ) device = value;
  12789. gl.setCompatibleXRDevice( value );
  12790. };
  12791. //
  12792. this.setSession = function ( value ) {
  12793. session = value;
  12794. if ( session !== null ) {
  12795. session.addEventListener( 'end', function () {
  12796. renderer.setFramebuffer( null );
  12797. animation.stop();
  12798. } );
  12799. session.baseLayer = new XRWebGLLayer( session, gl );
  12800. session.requestFrameOfReference( 'stage' ).then( function ( value ) {
  12801. frameOfRef = value;
  12802. renderer.setFramebuffer( session.baseLayer.framebuffer );
  12803. animation.setContext( session );
  12804. animation.start();
  12805. } );
  12806. }
  12807. };
  12808. function updateCamera( camera, parent ) {
  12809. if ( parent === null ) {
  12810. camera.matrixWorld.copy( camera.matrix );
  12811. } else {
  12812. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  12813. }
  12814. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12815. }
  12816. this.getCamera = function ( camera ) {
  12817. if ( isPresenting() ) {
  12818. var parent = camera.parent;
  12819. var cameras = cameraVR.cameras;
  12820. // apply camera.parent to cameraVR
  12821. updateCamera( cameraVR, parent );
  12822. for ( var i = 0; i < cameras.length; i ++ ) {
  12823. updateCamera( cameras[ i ], parent );
  12824. }
  12825. // update camera and its children
  12826. camera.matrixWorld.copy( cameraVR.matrixWorld );
  12827. var children = camera.children;
  12828. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12829. children[ i ].updateMatrixWorld( true );
  12830. }
  12831. return cameraVR;
  12832. }
  12833. return camera;
  12834. };
  12835. this.isPresenting = isPresenting;
  12836. // Animation Loop
  12837. var onAnimationFrameCallback = null;
  12838. function onAnimationFrame( time, frame ) {
  12839. pose = frame.getDevicePose( frameOfRef );
  12840. var layer = session.baseLayer;
  12841. var views = frame.views;
  12842. for ( var i = 0; i < views.length; i ++ ) {
  12843. var view = views[ i ];
  12844. var viewport = layer.getViewport( view );
  12845. var viewMatrix = pose.getViewMatrix( view );
  12846. var camera = cameraVR.cameras[ i ];
  12847. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  12848. camera.projectionMatrix.fromArray( view.projectionMatrix );
  12849. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  12850. if ( i === 0 ) {
  12851. cameraVR.matrix.copy( camera.matrix );
  12852. // HACK (mrdoob)
  12853. // https://github.com/w3c/webvr/issues/203
  12854. cameraVR.projectionMatrix.copy( camera.projectionMatrix );
  12855. }
  12856. }
  12857. if ( onAnimationFrameCallback ) onAnimationFrameCallback();
  12858. }
  12859. var animation = new WebGLAnimation();
  12860. animation.setAnimationLoop( onAnimationFrame );
  12861. this.setAnimationLoop = function ( callback ) {
  12862. onAnimationFrameCallback = callback;
  12863. };
  12864. // DEPRECATED
  12865. this.getStandingMatrix = function () {
  12866. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  12867. return new THREE.Matrix4();
  12868. };
  12869. this.submitFrame = function () {};
  12870. }
  12871. /**
  12872. * @author supereggbert / http://www.paulbrunt.co.uk/
  12873. * @author mrdoob / http://mrdoob.com/
  12874. * @author alteredq / http://alteredqualia.com/
  12875. * @author szimek / https://github.com/szimek/
  12876. * @author tschw
  12877. */
  12878. function WebGLRenderer( parameters ) {
  12879. console.log( 'THREE.WebGLRenderer', REVISION );
  12880. parameters = parameters || {};
  12881. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  12882. _context = parameters.context !== undefined ? parameters.context : null,
  12883. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12884. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12885. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12886. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12887. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12888. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12889. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  12890. var currentRenderList = null;
  12891. var currentRenderState = null;
  12892. // public properties
  12893. this.domElement = _canvas;
  12894. this.context = null;
  12895. // clearing
  12896. this.autoClear = true;
  12897. this.autoClearColor = true;
  12898. this.autoClearDepth = true;
  12899. this.autoClearStencil = true;
  12900. // scene graph
  12901. this.sortObjects = true;
  12902. // user-defined clipping
  12903. this.clippingPlanes = [];
  12904. this.localClippingEnabled = false;
  12905. // physically based shading
  12906. this.gammaFactor = 2.0; // for backwards compatibility
  12907. this.gammaInput = false;
  12908. this.gammaOutput = false;
  12909. // physical lights
  12910. this.physicallyCorrectLights = false;
  12911. // tone mapping
  12912. this.toneMapping = LinearToneMapping;
  12913. this.toneMappingExposure = 1.0;
  12914. this.toneMappingWhitePoint = 1.0;
  12915. // morphs
  12916. this.maxMorphTargets = 8;
  12917. this.maxMorphNormals = 4;
  12918. // internal properties
  12919. var _this = this,
  12920. _isContextLost = false,
  12921. // internal state cache
  12922. _framebuffer = null,
  12923. _currentRenderTarget = null,
  12924. _currentFramebuffer = null,
  12925. _currentMaterialId = - 1,
  12926. _currentGeometryProgram = '',
  12927. _currentCamera = null,
  12928. _currentArrayCamera = null,
  12929. _currentViewport = new Vector4(),
  12930. _currentScissor = new Vector4(),
  12931. _currentScissorTest = null,
  12932. //
  12933. _usedTextureUnits = 0,
  12934. //
  12935. _width = _canvas.width,
  12936. _height = _canvas.height,
  12937. _pixelRatio = 1,
  12938. _viewport = new Vector4( 0, 0, _width, _height ),
  12939. _scissor = new Vector4( 0, 0, _width, _height ),
  12940. _scissorTest = false,
  12941. // frustum
  12942. _frustum = new Frustum(),
  12943. // clipping
  12944. _clipping = new WebGLClipping(),
  12945. _clippingEnabled = false,
  12946. _localClippingEnabled = false,
  12947. // camera matrices cache
  12948. _projScreenMatrix = new Matrix4(),
  12949. _vector3 = new Vector3();
  12950. function getTargetPixelRatio() {
  12951. return _currentRenderTarget === null ? _pixelRatio : 1;
  12952. }
  12953. // initialize
  12954. var _gl;
  12955. try {
  12956. var contextAttributes = {
  12957. alpha: _alpha,
  12958. depth: _depth,
  12959. stencil: _stencil,
  12960. antialias: _antialias,
  12961. premultipliedAlpha: _premultipliedAlpha,
  12962. preserveDrawingBuffer: _preserveDrawingBuffer,
  12963. powerPreference: _powerPreference
  12964. };
  12965. // event listeners must be registered before WebGL context is created, see #12753
  12966. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12967. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  12968. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  12969. if ( _gl === null ) {
  12970. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12971. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  12972. } else {
  12973. throw new Error( 'Error creating WebGL context.' );
  12974. }
  12975. }
  12976. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  12977. if ( _gl.getShaderPrecisionFormat === undefined ) {
  12978. _gl.getShaderPrecisionFormat = function () {
  12979. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  12980. };
  12981. }
  12982. } catch ( error ) {
  12983. console.error( 'THREE.WebGLRenderer: ' + error.message );
  12984. }
  12985. var extensions, capabilities, state, info;
  12986. var properties, textures, attributes, geometries, objects;
  12987. var programCache, renderLists, renderStates;
  12988. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  12989. var spriteRenderer;
  12990. var utils;
  12991. function initGLContext() {
  12992. extensions = new WebGLExtensions( _gl );
  12993. extensions.get( 'WEBGL_depth_texture' );
  12994. extensions.get( 'OES_texture_float' );
  12995. extensions.get( 'OES_texture_float_linear' );
  12996. extensions.get( 'OES_texture_half_float' );
  12997. extensions.get( 'OES_texture_half_float_linear' );
  12998. extensions.get( 'OES_standard_derivatives' );
  12999. extensions.get( 'OES_element_index_uint' );
  13000. extensions.get( 'ANGLE_instanced_arrays' );
  13001. utils = new WebGLUtils( _gl, extensions );
  13002. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13003. state = new WebGLState( _gl, extensions, utils );
  13004. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13005. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13006. info = new WebGLInfo( _gl );
  13007. properties = new WebGLProperties();
  13008. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13009. attributes = new WebGLAttributes( _gl );
  13010. geometries = new WebGLGeometries( _gl, attributes, info );
  13011. objects = new WebGLObjects( geometries, info );
  13012. morphtargets = new WebGLMorphtargets( _gl );
  13013. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13014. renderLists = new WebGLRenderLists();
  13015. renderStates = new WebGLRenderStates();
  13016. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13017. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info );
  13018. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info );
  13019. spriteRenderer = new WebGLSpriteRenderer( _this, _gl, state, textures, capabilities );
  13020. info.programs = programCache.programs;
  13021. _this.context = _gl;
  13022. _this.capabilities = capabilities;
  13023. _this.extensions = extensions;
  13024. _this.properties = properties;
  13025. _this.renderLists = renderLists;
  13026. _this.state = state;
  13027. _this.info = info;
  13028. }
  13029. initGLContext();
  13030. // vr
  13031. var vr = ( 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13032. this.vr = vr;
  13033. // shadow map
  13034. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13035. this.shadowMap = shadowMap;
  13036. // API
  13037. this.getContext = function () {
  13038. return _gl;
  13039. };
  13040. this.getContextAttributes = function () {
  13041. return _gl.getContextAttributes();
  13042. };
  13043. this.forceContextLoss = function () {
  13044. var extension = extensions.get( 'WEBGL_lose_context' );
  13045. if ( extension ) extension.loseContext();
  13046. };
  13047. this.forceContextRestore = function () {
  13048. var extension = extensions.get( 'WEBGL_lose_context' );
  13049. if ( extension ) extension.restoreContext();
  13050. };
  13051. this.getPixelRatio = function () {
  13052. return _pixelRatio;
  13053. };
  13054. this.setPixelRatio = function ( value ) {
  13055. if ( value === undefined ) return;
  13056. _pixelRatio = value;
  13057. this.setSize( _width, _height, false );
  13058. };
  13059. this.getSize = function () {
  13060. return {
  13061. width: _width,
  13062. height: _height
  13063. };
  13064. };
  13065. this.setSize = function ( width, height, updateStyle ) {
  13066. if ( vr.isPresenting() ) {
  13067. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13068. return;
  13069. }
  13070. _width = width;
  13071. _height = height;
  13072. _canvas.width = width * _pixelRatio;
  13073. _canvas.height = height * _pixelRatio;
  13074. if ( updateStyle !== false ) {
  13075. _canvas.style.width = width + 'px';
  13076. _canvas.style.height = height + 'px';
  13077. }
  13078. this.setViewport( 0, 0, width, height );
  13079. };
  13080. this.getDrawingBufferSize = function () {
  13081. return {
  13082. width: _width * _pixelRatio,
  13083. height: _height * _pixelRatio
  13084. };
  13085. };
  13086. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13087. _width = width;
  13088. _height = height;
  13089. _pixelRatio = pixelRatio;
  13090. _canvas.width = width * pixelRatio;
  13091. _canvas.height = height * pixelRatio;
  13092. this.setViewport( 0, 0, width, height );
  13093. };
  13094. this.getCurrentViewport = function () {
  13095. return _currentViewport;
  13096. };
  13097. this.setViewport = function ( x, y, width, height ) {
  13098. _viewport.set( x, _height - y - height, width, height );
  13099. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13100. };
  13101. this.setScissor = function ( x, y, width, height ) {
  13102. _scissor.set( x, _height - y - height, width, height );
  13103. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13104. };
  13105. this.setScissorTest = function ( boolean ) {
  13106. state.setScissorTest( _scissorTest = boolean );
  13107. };
  13108. // Clearing
  13109. this.getClearColor = function () {
  13110. return background.getClearColor();
  13111. };
  13112. this.setClearColor = function () {
  13113. background.setClearColor.apply( background, arguments );
  13114. };
  13115. this.getClearAlpha = function () {
  13116. return background.getClearAlpha();
  13117. };
  13118. this.setClearAlpha = function () {
  13119. background.setClearAlpha.apply( background, arguments );
  13120. };
  13121. this.clear = function ( color, depth, stencil ) {
  13122. var bits = 0;
  13123. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  13124. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  13125. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  13126. _gl.clear( bits );
  13127. };
  13128. this.clearColor = function () {
  13129. this.clear( true, false, false );
  13130. };
  13131. this.clearDepth = function () {
  13132. this.clear( false, true, false );
  13133. };
  13134. this.clearStencil = function () {
  13135. this.clear( false, false, true );
  13136. };
  13137. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  13138. this.setRenderTarget( renderTarget );
  13139. this.clear( color, depth, stencil );
  13140. };
  13141. //
  13142. this.dispose = function () {
  13143. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13144. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13145. renderLists.dispose();
  13146. renderStates.dispose();
  13147. properties.dispose();
  13148. objects.dispose();
  13149. vr.dispose();
  13150. animation.stop();
  13151. };
  13152. // Events
  13153. function onContextLost( event ) {
  13154. event.preventDefault();
  13155. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13156. _isContextLost = true;
  13157. }
  13158. function onContextRestore( /* event */ ) {
  13159. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13160. _isContextLost = false;
  13161. initGLContext();
  13162. }
  13163. function onMaterialDispose( event ) {
  13164. var material = event.target;
  13165. material.removeEventListener( 'dispose', onMaterialDispose );
  13166. deallocateMaterial( material );
  13167. }
  13168. // Buffer deallocation
  13169. function deallocateMaterial( material ) {
  13170. releaseMaterialProgramReference( material );
  13171. properties.remove( material );
  13172. }
  13173. function releaseMaterialProgramReference( material ) {
  13174. var programInfo = properties.get( material ).program;
  13175. material.program = undefined;
  13176. if ( programInfo !== undefined ) {
  13177. programCache.releaseProgram( programInfo );
  13178. }
  13179. }
  13180. // Buffer rendering
  13181. function renderObjectImmediate( object, program, material ) {
  13182. object.render( function ( object ) {
  13183. _this.renderBufferImmediate( object, program, material );
  13184. } );
  13185. }
  13186. this.renderBufferImmediate = function ( object, program, material ) {
  13187. state.initAttributes();
  13188. var buffers = properties.get( object );
  13189. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13190. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13191. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13192. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13193. var programAttributes = program.getAttributes();
  13194. if ( object.hasPositions ) {
  13195. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  13196. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  13197. state.enableAttribute( programAttributes.position );
  13198. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  13199. }
  13200. if ( object.hasNormals ) {
  13201. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  13202. if ( ! material.isMeshPhongMaterial &&
  13203. ! material.isMeshStandardMaterial &&
  13204. ! material.isMeshNormalMaterial &&
  13205. material.flatShading === true ) {
  13206. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  13207. var array = object.normalArray;
  13208. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  13209. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  13210. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  13211. array[ i + 0 ] = nx;
  13212. array[ i + 1 ] = ny;
  13213. array[ i + 2 ] = nz;
  13214. array[ i + 3 ] = nx;
  13215. array[ i + 4 ] = ny;
  13216. array[ i + 5 ] = nz;
  13217. array[ i + 6 ] = nx;
  13218. array[ i + 7 ] = ny;
  13219. array[ i + 8 ] = nz;
  13220. }
  13221. }
  13222. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  13223. state.enableAttribute( programAttributes.normal );
  13224. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  13225. }
  13226. if ( object.hasUvs && material.map ) {
  13227. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  13228. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  13229. state.enableAttribute( programAttributes.uv );
  13230. _gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  13231. }
  13232. if ( object.hasColors && material.vertexColors !== NoColors ) {
  13233. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  13234. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  13235. state.enableAttribute( programAttributes.color );
  13236. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  13237. }
  13238. state.disableUnusedAttributes();
  13239. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  13240. object.count = 0;
  13241. };
  13242. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13243. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13244. state.setMaterial( material, frontFaceCW );
  13245. var program = setProgram( camera, fog, material, object );
  13246. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  13247. var updateBuffers = false;
  13248. if ( geometryProgram !== _currentGeometryProgram ) {
  13249. _currentGeometryProgram = geometryProgram;
  13250. updateBuffers = true;
  13251. }
  13252. if ( object.morphTargetInfluences ) {
  13253. morphtargets.update( object, geometry, material, program );
  13254. updateBuffers = true;
  13255. }
  13256. //
  13257. var index = geometry.index;
  13258. var position = geometry.attributes.position;
  13259. var rangeFactor = 1;
  13260. if ( material.wireframe === true ) {
  13261. index = geometries.getWireframeAttribute( geometry );
  13262. rangeFactor = 2;
  13263. }
  13264. var attribute;
  13265. var renderer = bufferRenderer;
  13266. if ( index !== null ) {
  13267. attribute = attributes.get( index );
  13268. renderer = indexedBufferRenderer;
  13269. renderer.setIndex( attribute );
  13270. }
  13271. if ( updateBuffers ) {
  13272. setupVertexAttributes( material, program, geometry );
  13273. if ( index !== null ) {
  13274. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  13275. }
  13276. }
  13277. //
  13278. var dataCount = Infinity;
  13279. if ( index !== null ) {
  13280. dataCount = index.count;
  13281. } else if ( position !== undefined ) {
  13282. dataCount = position.count;
  13283. }
  13284. var rangeStart = geometry.drawRange.start * rangeFactor;
  13285. var rangeCount = geometry.drawRange.count * rangeFactor;
  13286. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13287. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13288. var drawStart = Math.max( rangeStart, groupStart );
  13289. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13290. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13291. if ( drawCount === 0 ) return;
  13292. //
  13293. if ( object.isMesh ) {
  13294. if ( material.wireframe === true ) {
  13295. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13296. renderer.setMode( _gl.LINES );
  13297. } else {
  13298. switch ( object.drawMode ) {
  13299. case TrianglesDrawMode:
  13300. renderer.setMode( _gl.TRIANGLES );
  13301. break;
  13302. case TriangleStripDrawMode:
  13303. renderer.setMode( _gl.TRIANGLE_STRIP );
  13304. break;
  13305. case TriangleFanDrawMode:
  13306. renderer.setMode( _gl.TRIANGLE_FAN );
  13307. break;
  13308. }
  13309. }
  13310. } else if ( object.isLine ) {
  13311. var lineWidth = material.linewidth;
  13312. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13313. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13314. if ( object.isLineSegments ) {
  13315. renderer.setMode( _gl.LINES );
  13316. } else if ( object.isLineLoop ) {
  13317. renderer.setMode( _gl.LINE_LOOP );
  13318. } else {
  13319. renderer.setMode( _gl.LINE_STRIP );
  13320. }
  13321. } else if ( object.isPoints ) {
  13322. renderer.setMode( _gl.POINTS );
  13323. }
  13324. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13325. if ( geometry.maxInstancedCount > 0 ) {
  13326. renderer.renderInstances( geometry, drawStart, drawCount );
  13327. }
  13328. } else {
  13329. renderer.render( drawStart, drawCount );
  13330. }
  13331. };
  13332. function setupVertexAttributes( material, program, geometry ) {
  13333. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13334. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13335. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13336. return;
  13337. }
  13338. }
  13339. state.initAttributes();
  13340. var geometryAttributes = geometry.attributes;
  13341. var programAttributes = program.getAttributes();
  13342. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13343. for ( var name in programAttributes ) {
  13344. var programAttribute = programAttributes[ name ];
  13345. if ( programAttribute >= 0 ) {
  13346. var geometryAttribute = geometryAttributes[ name ];
  13347. if ( geometryAttribute !== undefined ) {
  13348. var normalized = geometryAttribute.normalized;
  13349. var size = geometryAttribute.itemSize;
  13350. var attribute = attributes.get( geometryAttribute );
  13351. // TODO Attribute may not be available on context restore
  13352. if ( attribute === undefined ) continue;
  13353. var buffer = attribute.buffer;
  13354. var type = attribute.type;
  13355. var bytesPerElement = attribute.bytesPerElement;
  13356. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13357. var data = geometryAttribute.data;
  13358. var stride = data.stride;
  13359. var offset = geometryAttribute.offset;
  13360. if ( data && data.isInstancedInterleavedBuffer ) {
  13361. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13362. if ( geometry.maxInstancedCount === undefined ) {
  13363. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13364. }
  13365. } else {
  13366. state.enableAttribute( programAttribute );
  13367. }
  13368. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13369. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  13370. } else {
  13371. if ( geometryAttribute.isInstancedBufferAttribute ) {
  13372. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  13373. if ( geometry.maxInstancedCount === undefined ) {
  13374. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13375. }
  13376. } else {
  13377. state.enableAttribute( programAttribute );
  13378. }
  13379. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13380. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  13381. }
  13382. } else if ( materialDefaultAttributeValues !== undefined ) {
  13383. var value = materialDefaultAttributeValues[ name ];
  13384. if ( value !== undefined ) {
  13385. switch ( value.length ) {
  13386. case 2:
  13387. _gl.vertexAttrib2fv( programAttribute, value );
  13388. break;
  13389. case 3:
  13390. _gl.vertexAttrib3fv( programAttribute, value );
  13391. break;
  13392. case 4:
  13393. _gl.vertexAttrib4fv( programAttribute, value );
  13394. break;
  13395. default:
  13396. _gl.vertexAttrib1fv( programAttribute, value );
  13397. }
  13398. }
  13399. }
  13400. }
  13401. }
  13402. state.disableUnusedAttributes();
  13403. }
  13404. // Compile
  13405. this.compile = function ( scene, camera ) {
  13406. currentRenderState = renderStates.get( scene, camera );
  13407. currentRenderState.init();
  13408. scene.traverse( function ( object ) {
  13409. if ( object.isLight ) {
  13410. currentRenderState.pushLight( object );
  13411. if ( object.castShadow ) {
  13412. currentRenderState.pushShadow( object );
  13413. }
  13414. }
  13415. } );
  13416. currentRenderState.setupLights( camera );
  13417. scene.traverse( function ( object ) {
  13418. if ( object.material ) {
  13419. if ( Array.isArray( object.material ) ) {
  13420. for ( var i = 0; i < object.material.length; i ++ ) {
  13421. initMaterial( object.material[ i ], scene.fog, object );
  13422. }
  13423. } else {
  13424. initMaterial( object.material, scene.fog, object );
  13425. }
  13426. }
  13427. } );
  13428. };
  13429. // Animation Loop
  13430. var onAnimationFrameCallback = null;
  13431. function onAnimationFrame() {
  13432. if ( vr.isPresenting() ) return;
  13433. if ( onAnimationFrameCallback ) onAnimationFrameCallback();
  13434. }
  13435. var animation = new WebGLAnimation();
  13436. animation.setAnimationLoop( onAnimationFrame );
  13437. animation.setContext( window );
  13438. this.setAnimationLoop = function ( callback ) {
  13439. onAnimationFrameCallback = callback;
  13440. vr.setAnimationLoop( callback );
  13441. animation.start();
  13442. };
  13443. // Rendering
  13444. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13445. if ( ! ( camera && camera.isCamera ) ) {
  13446. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13447. return;
  13448. }
  13449. if ( _isContextLost ) return;
  13450. // reset caching for this frame
  13451. _currentGeometryProgram = '';
  13452. _currentMaterialId = - 1;
  13453. _currentCamera = null;
  13454. // update scene graph
  13455. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13456. // update camera matrices and frustum
  13457. if ( camera.parent === null ) camera.updateMatrixWorld();
  13458. if ( vr.enabled ) {
  13459. camera = vr.getCamera( camera );
  13460. }
  13461. //
  13462. currentRenderState = renderStates.get( scene, camera );
  13463. currentRenderState.init();
  13464. scene.onBeforeRender( _this, scene, camera, renderTarget );
  13465. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13466. _frustum.setFromMatrix( _projScreenMatrix );
  13467. _localClippingEnabled = this.localClippingEnabled;
  13468. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  13469. currentRenderList = renderLists.get( scene, camera );
  13470. currentRenderList.init();
  13471. projectObject( scene, camera, _this.sortObjects );
  13472. if ( _this.sortObjects === true ) {
  13473. currentRenderList.sort();
  13474. }
  13475. //
  13476. if ( _clippingEnabled ) _clipping.beginShadows();
  13477. var shadowsArray = currentRenderState.state.shadowsArray;
  13478. shadowMap.render( shadowsArray, scene, camera );
  13479. currentRenderState.setupLights( camera );
  13480. if ( _clippingEnabled ) _clipping.endShadows();
  13481. //
  13482. if ( this.info.autoReset ) this.info.reset();
  13483. if ( renderTarget === undefined ) {
  13484. renderTarget = null;
  13485. }
  13486. this.setRenderTarget( renderTarget );
  13487. //
  13488. background.render( currentRenderList, scene, camera, forceClear );
  13489. // render scene
  13490. var opaqueObjects = currentRenderList.opaque;
  13491. var transparentObjects = currentRenderList.transparent;
  13492. if ( scene.overrideMaterial ) {
  13493. var overrideMaterial = scene.overrideMaterial;
  13494. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  13495. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  13496. } else {
  13497. // opaque pass (front-to-back order)
  13498. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  13499. // transparent pass (back-to-front order)
  13500. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  13501. }
  13502. // custom renderers
  13503. var spritesArray = currentRenderState.state.spritesArray;
  13504. spriteRenderer.render( spritesArray, scene, camera );
  13505. // Generate mipmap if we're using any kind of mipmap filtering
  13506. if ( renderTarget ) {
  13507. textures.updateRenderTargetMipmap( renderTarget );
  13508. }
  13509. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13510. state.buffers.depth.setTest( true );
  13511. state.buffers.depth.setMask( true );
  13512. state.buffers.color.setMask( true );
  13513. state.setPolygonOffset( false );
  13514. scene.onAfterRender( _this, scene, camera );
  13515. if ( vr.enabled ) {
  13516. vr.submitFrame();
  13517. }
  13518. // _gl.finish();
  13519. currentRenderList = null;
  13520. currentRenderState = null;
  13521. };
  13522. /*
  13523. // TODO Duplicated code (Frustum)
  13524. var _sphere = new Sphere();
  13525. function isObjectViewable( object ) {
  13526. var geometry = object.geometry;
  13527. if ( geometry.boundingSphere === null )
  13528. geometry.computeBoundingSphere();
  13529. _sphere.copy( geometry.boundingSphere ).
  13530. applyMatrix4( object.matrixWorld );
  13531. return isSphereViewable( _sphere );
  13532. }
  13533. function isSpriteViewable( sprite ) {
  13534. _sphere.center.set( 0, 0, 0 );
  13535. _sphere.radius = 0.7071067811865476;
  13536. _sphere.applyMatrix4( sprite.matrixWorld );
  13537. return isSphereViewable( _sphere );
  13538. }
  13539. function isSphereViewable( sphere ) {
  13540. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  13541. var numPlanes = _clipping.numPlanes;
  13542. if ( numPlanes === 0 ) return true;
  13543. var planes = _this.clippingPlanes,
  13544. center = sphere.center,
  13545. negRad = - sphere.radius,
  13546. i = 0;
  13547. do {
  13548. // out when deeper than radius in the negative halfspace
  13549. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  13550. } while ( ++ i !== numPlanes );
  13551. return true;
  13552. }
  13553. */
  13554. function projectObject( object, camera, sortObjects ) {
  13555. if ( object.visible === false ) return;
  13556. var visible = object.layers.test( camera.layers );
  13557. if ( visible ) {
  13558. if ( object.isLight ) {
  13559. currentRenderState.pushLight( object );
  13560. if ( object.castShadow ) {
  13561. currentRenderState.pushShadow( object );
  13562. }
  13563. } else if ( object.isSprite ) {
  13564. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  13565. currentRenderState.pushSprite( object );
  13566. }
  13567. } else if ( object.isImmediateRenderObject ) {
  13568. if ( sortObjects ) {
  13569. _vector3.setFromMatrixPosition( object.matrixWorld )
  13570. .applyMatrix4( _projScreenMatrix );
  13571. }
  13572. currentRenderList.push( object, null, object.material, _vector3.z, null );
  13573. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  13574. if ( object.isSkinnedMesh ) {
  13575. object.skeleton.update();
  13576. }
  13577. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  13578. if ( sortObjects ) {
  13579. _vector3.setFromMatrixPosition( object.matrixWorld )
  13580. .applyMatrix4( _projScreenMatrix );
  13581. }
  13582. var geometry = objects.update( object );
  13583. var material = object.material;
  13584. if ( Array.isArray( material ) ) {
  13585. var groups = geometry.groups;
  13586. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13587. var group = groups[ i ];
  13588. var groupMaterial = material[ group.materialIndex ];
  13589. if ( groupMaterial && groupMaterial.visible ) {
  13590. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  13591. }
  13592. }
  13593. } else if ( material.visible ) {
  13594. currentRenderList.push( object, geometry, material, _vector3.z, null );
  13595. }
  13596. }
  13597. }
  13598. }
  13599. var children = object.children;
  13600. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13601. projectObject( children[ i ], camera, sortObjects );
  13602. }
  13603. }
  13604. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  13605. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13606. var renderItem = renderList[ i ];
  13607. var object = renderItem.object;
  13608. var geometry = renderItem.geometry;
  13609. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13610. var group = renderItem.group;
  13611. if ( camera.isArrayCamera ) {
  13612. _currentArrayCamera = camera;
  13613. var cameras = camera.cameras;
  13614. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  13615. var camera2 = cameras[ j ];
  13616. if ( object.layers.test( camera2.layers ) ) {
  13617. if ( 'viewport' in camera2 ) { // XR
  13618. state.viewport( _currentViewport.copy( camera2.viewport ) );
  13619. } else {
  13620. var bounds = camera2.bounds;
  13621. var x = bounds.x * _width;
  13622. var y = bounds.y * _height;
  13623. var width = bounds.z * _width;
  13624. var height = bounds.w * _height;
  13625. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  13626. }
  13627. renderObject( object, scene, camera2, geometry, material, group );
  13628. }
  13629. }
  13630. } else {
  13631. _currentArrayCamera = null;
  13632. renderObject( object, scene, camera, geometry, material, group );
  13633. }
  13634. }
  13635. }
  13636. function renderObject( object, scene, camera, geometry, material, group ) {
  13637. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  13638. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13639. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13640. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13641. if ( object.isImmediateRenderObject ) {
  13642. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13643. state.setMaterial( material, frontFaceCW );
  13644. var program = setProgram( camera, scene.fog, material, object );
  13645. _currentGeometryProgram = '';
  13646. renderObjectImmediate( object, program, material );
  13647. } else {
  13648. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  13649. }
  13650. object.onAfterRender( _this, scene, camera, geometry, material, group );
  13651. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13652. }
  13653. function initMaterial( material, fog, object ) {
  13654. var materialProperties = properties.get( material );
  13655. var lights = currentRenderState.state.lights;
  13656. var shadowsArray = currentRenderState.state.shadowsArray;
  13657. var parameters = programCache.getParameters(
  13658. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  13659. var code = programCache.getProgramCode( material, parameters );
  13660. var program = materialProperties.program;
  13661. var programChange = true;
  13662. if ( program === undefined ) {
  13663. // new material
  13664. material.addEventListener( 'dispose', onMaterialDispose );
  13665. } else if ( program.code !== code ) {
  13666. // changed glsl or parameters
  13667. releaseMaterialProgramReference( material );
  13668. } else if ( materialProperties.lightsHash !== lights.state.hash ) {
  13669. properties.update( material, 'lightsHash', lights.state.hash );
  13670. programChange = false;
  13671. } else if ( parameters.shaderID !== undefined ) {
  13672. // same glsl and uniform list
  13673. return;
  13674. } else {
  13675. // only rebuild uniform list
  13676. programChange = false;
  13677. }
  13678. if ( programChange ) {
  13679. if ( parameters.shaderID ) {
  13680. var shader = ShaderLib[ parameters.shaderID ];
  13681. materialProperties.shader = {
  13682. name: material.type,
  13683. uniforms: UniformsUtils.clone( shader.uniforms ),
  13684. vertexShader: shader.vertexShader,
  13685. fragmentShader: shader.fragmentShader
  13686. };
  13687. } else {
  13688. materialProperties.shader = {
  13689. name: material.type,
  13690. uniforms: material.uniforms,
  13691. vertexShader: material.vertexShader,
  13692. fragmentShader: material.fragmentShader
  13693. };
  13694. }
  13695. material.onBeforeCompile( materialProperties.shader, _this );
  13696. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  13697. materialProperties.program = program;
  13698. material.program = program;
  13699. }
  13700. var programAttributes = program.getAttributes();
  13701. if ( material.morphTargets ) {
  13702. material.numSupportedMorphTargets = 0;
  13703. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13704. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  13705. material.numSupportedMorphTargets ++;
  13706. }
  13707. }
  13708. }
  13709. if ( material.morphNormals ) {
  13710. material.numSupportedMorphNormals = 0;
  13711. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  13712. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  13713. material.numSupportedMorphNormals ++;
  13714. }
  13715. }
  13716. }
  13717. var uniforms = materialProperties.shader.uniforms;
  13718. if ( ! material.isShaderMaterial &&
  13719. ! material.isRawShaderMaterial ||
  13720. material.clipping === true ) {
  13721. materialProperties.numClippingPlanes = _clipping.numPlanes;
  13722. materialProperties.numIntersection = _clipping.numIntersection;
  13723. uniforms.clippingPlanes = _clipping.uniform;
  13724. }
  13725. materialProperties.fog = fog;
  13726. // store the light setup it was created for
  13727. materialProperties.lightsHash = lights.state.hash;
  13728. if ( material.lights ) {
  13729. // wire up the material to this renderer's lighting state
  13730. uniforms.ambientLightColor.value = lights.state.ambient;
  13731. uniforms.directionalLights.value = lights.state.directional;
  13732. uniforms.spotLights.value = lights.state.spot;
  13733. uniforms.rectAreaLights.value = lights.state.rectArea;
  13734. uniforms.pointLights.value = lights.state.point;
  13735. uniforms.hemisphereLights.value = lights.state.hemi;
  13736. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  13737. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  13738. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  13739. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  13740. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  13741. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  13742. // TODO (abelnation): add area lights shadow info to uniforms
  13743. }
  13744. var progUniforms = materialProperties.program.getUniforms(),
  13745. uniformsList =
  13746. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  13747. materialProperties.uniformsList = uniformsList;
  13748. }
  13749. function setProgram( camera, fog, material, object ) {
  13750. _usedTextureUnits = 0;
  13751. var materialProperties = properties.get( material );
  13752. var lights = currentRenderState.state.lights;
  13753. if ( _clippingEnabled ) {
  13754. if ( _localClippingEnabled || camera !== _currentCamera ) {
  13755. var useCache =
  13756. camera === _currentCamera &&
  13757. material.id === _currentMaterialId;
  13758. // we might want to call this function with some ClippingGroup
  13759. // object instead of the material, once it becomes feasible
  13760. // (#8465, #8379)
  13761. _clipping.setState(
  13762. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  13763. camera, materialProperties, useCache );
  13764. }
  13765. }
  13766. if ( material.needsUpdate === false ) {
  13767. if ( materialProperties.program === undefined ) {
  13768. material.needsUpdate = true;
  13769. } else if ( material.fog && materialProperties.fog !== fog ) {
  13770. material.needsUpdate = true;
  13771. } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
  13772. material.needsUpdate = true;
  13773. } else if ( materialProperties.numClippingPlanes !== undefined &&
  13774. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  13775. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  13776. material.needsUpdate = true;
  13777. }
  13778. }
  13779. if ( material.needsUpdate ) {
  13780. initMaterial( material, fog, object );
  13781. material.needsUpdate = false;
  13782. }
  13783. var refreshProgram = false;
  13784. var refreshMaterial = false;
  13785. var refreshLights = false;
  13786. var program = materialProperties.program,
  13787. p_uniforms = program.getUniforms(),
  13788. m_uniforms = materialProperties.shader.uniforms;
  13789. if ( state.useProgram( program.program ) ) {
  13790. refreshProgram = true;
  13791. refreshMaterial = true;
  13792. refreshLights = true;
  13793. }
  13794. if ( material.id !== _currentMaterialId ) {
  13795. _currentMaterialId = material.id;
  13796. refreshMaterial = true;
  13797. }
  13798. if ( refreshProgram || camera !== _currentCamera ) {
  13799. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  13800. if ( capabilities.logarithmicDepthBuffer ) {
  13801. p_uniforms.setValue( _gl, 'logDepthBufFC',
  13802. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13803. }
  13804. // Avoid unneeded uniform updates per ArrayCamera's sub-camera
  13805. if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
  13806. _currentCamera = ( _currentArrayCamera || camera );
  13807. // lighting uniforms depend on the camera so enforce an update
  13808. // now, in case this material supports lights - or later, when
  13809. // the next material that does gets activated:
  13810. refreshMaterial = true; // set to true on material change
  13811. refreshLights = true; // remains set until update done
  13812. }
  13813. // load material specific uniforms
  13814. // (shader material also gets them for the sake of genericity)
  13815. if ( material.isShaderMaterial ||
  13816. material.isMeshPhongMaterial ||
  13817. material.isMeshStandardMaterial ||
  13818. material.envMap ) {
  13819. var uCamPos = p_uniforms.map.cameraPosition;
  13820. if ( uCamPos !== undefined ) {
  13821. uCamPos.setValue( _gl,
  13822. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  13823. }
  13824. }
  13825. if ( material.isMeshPhongMaterial ||
  13826. material.isMeshLambertMaterial ||
  13827. material.isMeshBasicMaterial ||
  13828. material.isMeshStandardMaterial ||
  13829. material.isShaderMaterial ||
  13830. material.skinning ) {
  13831. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  13832. }
  13833. }
  13834. // skinning uniforms must be set even if material didn't change
  13835. // auto-setting of texture unit for bone texture must go before other textures
  13836. // not sure why, but otherwise weird things happen
  13837. if ( material.skinning ) {
  13838. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  13839. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  13840. var skeleton = object.skeleton;
  13841. if ( skeleton ) {
  13842. var bones = skeleton.bones;
  13843. if ( capabilities.floatVertexTextures ) {
  13844. if ( skeleton.boneTexture === undefined ) {
  13845. // layout (1 matrix = 4 pixels)
  13846. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13847. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13848. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13849. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13850. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13851. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  13852. size = _Math.ceilPowerOfTwo( size );
  13853. size = Math.max( size, 4 );
  13854. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  13855. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  13856. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  13857. boneTexture.needsUpdate = true;
  13858. skeleton.boneMatrices = boneMatrices;
  13859. skeleton.boneTexture = boneTexture;
  13860. skeleton.boneTextureSize = size;
  13861. }
  13862. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  13863. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  13864. } else {
  13865. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  13866. }
  13867. }
  13868. }
  13869. if ( refreshMaterial ) {
  13870. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  13871. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  13872. if ( material.lights ) {
  13873. // the current material requires lighting info
  13874. // note: all lighting uniforms are always set correctly
  13875. // they simply reference the renderer's state for their
  13876. // values
  13877. //
  13878. // use the current material's .needsUpdate flags to set
  13879. // the GL state when required
  13880. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  13881. }
  13882. // refresh uniforms common to several materials
  13883. if ( fog && material.fog ) {
  13884. refreshUniformsFog( m_uniforms, fog );
  13885. }
  13886. if ( material.isMeshBasicMaterial ) {
  13887. refreshUniformsCommon( m_uniforms, material );
  13888. } else if ( material.isMeshLambertMaterial ) {
  13889. refreshUniformsCommon( m_uniforms, material );
  13890. refreshUniformsLambert( m_uniforms, material );
  13891. } else if ( material.isMeshPhongMaterial ) {
  13892. refreshUniformsCommon( m_uniforms, material );
  13893. if ( material.isMeshToonMaterial ) {
  13894. refreshUniformsToon( m_uniforms, material );
  13895. } else {
  13896. refreshUniformsPhong( m_uniforms, material );
  13897. }
  13898. } else if ( material.isMeshStandardMaterial ) {
  13899. refreshUniformsCommon( m_uniforms, material );
  13900. if ( material.isMeshPhysicalMaterial ) {
  13901. refreshUniformsPhysical( m_uniforms, material );
  13902. } else {
  13903. refreshUniformsStandard( m_uniforms, material );
  13904. }
  13905. } else if ( material.isMeshDepthMaterial ) {
  13906. refreshUniformsCommon( m_uniforms, material );
  13907. refreshUniformsDepth( m_uniforms, material );
  13908. } else if ( material.isMeshDistanceMaterial ) {
  13909. refreshUniformsCommon( m_uniforms, material );
  13910. refreshUniformsDistance( m_uniforms, material );
  13911. } else if ( material.isMeshNormalMaterial ) {
  13912. refreshUniformsCommon( m_uniforms, material );
  13913. refreshUniformsNormal( m_uniforms, material );
  13914. } else if ( material.isLineBasicMaterial ) {
  13915. refreshUniformsLine( m_uniforms, material );
  13916. if ( material.isLineDashedMaterial ) {
  13917. refreshUniformsDash( m_uniforms, material );
  13918. }
  13919. } else if ( material.isPointsMaterial ) {
  13920. refreshUniformsPoints( m_uniforms, material );
  13921. } else if ( material.isShadowMaterial ) {
  13922. m_uniforms.color.value = material.color;
  13923. m_uniforms.opacity.value = material.opacity;
  13924. }
  13925. // RectAreaLight Texture
  13926. // TODO (mrdoob): Find a nicer implementation
  13927. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  13928. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  13929. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  13930. }
  13931. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  13932. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  13933. material.uniformsNeedUpdate = false;
  13934. }
  13935. // common matrices
  13936. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  13937. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  13938. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  13939. return program;
  13940. }
  13941. // Uniforms (refresh uniforms objects)
  13942. function refreshUniformsCommon( uniforms, material ) {
  13943. uniforms.opacity.value = material.opacity;
  13944. if ( material.color ) {
  13945. uniforms.diffuse.value = material.color;
  13946. }
  13947. if ( material.emissive ) {
  13948. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  13949. }
  13950. if ( material.map ) {
  13951. uniforms.map.value = material.map;
  13952. }
  13953. if ( material.alphaMap ) {
  13954. uniforms.alphaMap.value = material.alphaMap;
  13955. }
  13956. if ( material.specularMap ) {
  13957. uniforms.specularMap.value = material.specularMap;
  13958. }
  13959. if ( material.envMap ) {
  13960. uniforms.envMap.value = material.envMap;
  13961. // don't flip CubeTexture envMaps, flip everything else:
  13962. // WebGLRenderTargetCube will be flipped for backwards compatibility
  13963. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  13964. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  13965. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  13966. uniforms.reflectivity.value = material.reflectivity;
  13967. uniforms.refractionRatio.value = material.refractionRatio;
  13968. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  13969. }
  13970. if ( material.lightMap ) {
  13971. uniforms.lightMap.value = material.lightMap;
  13972. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13973. }
  13974. if ( material.aoMap ) {
  13975. uniforms.aoMap.value = material.aoMap;
  13976. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13977. }
  13978. // uv repeat and offset setting priorities
  13979. // 1. color map
  13980. // 2. specular map
  13981. // 3. normal map
  13982. // 4. bump map
  13983. // 5. alpha map
  13984. // 6. emissive map
  13985. var uvScaleMap;
  13986. if ( material.map ) {
  13987. uvScaleMap = material.map;
  13988. } else if ( material.specularMap ) {
  13989. uvScaleMap = material.specularMap;
  13990. } else if ( material.displacementMap ) {
  13991. uvScaleMap = material.displacementMap;
  13992. } else if ( material.normalMap ) {
  13993. uvScaleMap = material.normalMap;
  13994. } else if ( material.bumpMap ) {
  13995. uvScaleMap = material.bumpMap;
  13996. } else if ( material.roughnessMap ) {
  13997. uvScaleMap = material.roughnessMap;
  13998. } else if ( material.metalnessMap ) {
  13999. uvScaleMap = material.metalnessMap;
  14000. } else if ( material.alphaMap ) {
  14001. uvScaleMap = material.alphaMap;
  14002. } else if ( material.emissiveMap ) {
  14003. uvScaleMap = material.emissiveMap;
  14004. }
  14005. if ( uvScaleMap !== undefined ) {
  14006. // backwards compatibility
  14007. if ( uvScaleMap.isWebGLRenderTarget ) {
  14008. uvScaleMap = uvScaleMap.texture;
  14009. }
  14010. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14011. uvScaleMap.updateMatrix();
  14012. }
  14013. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14014. }
  14015. }
  14016. function refreshUniformsLine( uniforms, material ) {
  14017. uniforms.diffuse.value = material.color;
  14018. uniforms.opacity.value = material.opacity;
  14019. }
  14020. function refreshUniformsDash( uniforms, material ) {
  14021. uniforms.dashSize.value = material.dashSize;
  14022. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14023. uniforms.scale.value = material.scale;
  14024. }
  14025. function refreshUniformsPoints( uniforms, material ) {
  14026. uniforms.diffuse.value = material.color;
  14027. uniforms.opacity.value = material.opacity;
  14028. uniforms.size.value = material.size * _pixelRatio;
  14029. uniforms.scale.value = _height * 0.5;
  14030. uniforms.map.value = material.map;
  14031. if ( material.map !== null ) {
  14032. if ( material.map.matrixAutoUpdate === true ) {
  14033. material.map.updateMatrix();
  14034. }
  14035. uniforms.uvTransform.value.copy( material.map.matrix );
  14036. }
  14037. }
  14038. function refreshUniformsFog( uniforms, fog ) {
  14039. uniforms.fogColor.value = fog.color;
  14040. if ( fog.isFog ) {
  14041. uniforms.fogNear.value = fog.near;
  14042. uniforms.fogFar.value = fog.far;
  14043. } else if ( fog.isFogExp2 ) {
  14044. uniforms.fogDensity.value = fog.density;
  14045. }
  14046. }
  14047. function refreshUniformsLambert( uniforms, material ) {
  14048. if ( material.emissiveMap ) {
  14049. uniforms.emissiveMap.value = material.emissiveMap;
  14050. }
  14051. }
  14052. function refreshUniformsPhong( uniforms, material ) {
  14053. uniforms.specular.value = material.specular;
  14054. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14055. if ( material.emissiveMap ) {
  14056. uniforms.emissiveMap.value = material.emissiveMap;
  14057. }
  14058. if ( material.bumpMap ) {
  14059. uniforms.bumpMap.value = material.bumpMap;
  14060. uniforms.bumpScale.value = material.bumpScale;
  14061. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14062. }
  14063. if ( material.normalMap ) {
  14064. uniforms.normalMap.value = material.normalMap;
  14065. uniforms.normalScale.value.copy( material.normalScale );
  14066. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14067. }
  14068. if ( material.displacementMap ) {
  14069. uniforms.displacementMap.value = material.displacementMap;
  14070. uniforms.displacementScale.value = material.displacementScale;
  14071. uniforms.displacementBias.value = material.displacementBias;
  14072. }
  14073. }
  14074. function refreshUniformsToon( uniforms, material ) {
  14075. refreshUniformsPhong( uniforms, material );
  14076. if ( material.gradientMap ) {
  14077. uniforms.gradientMap.value = material.gradientMap;
  14078. }
  14079. }
  14080. function refreshUniformsStandard( uniforms, material ) {
  14081. uniforms.roughness.value = material.roughness;
  14082. uniforms.metalness.value = material.metalness;
  14083. if ( material.roughnessMap ) {
  14084. uniforms.roughnessMap.value = material.roughnessMap;
  14085. }
  14086. if ( material.metalnessMap ) {
  14087. uniforms.metalnessMap.value = material.metalnessMap;
  14088. }
  14089. if ( material.emissiveMap ) {
  14090. uniforms.emissiveMap.value = material.emissiveMap;
  14091. }
  14092. if ( material.bumpMap ) {
  14093. uniforms.bumpMap.value = material.bumpMap;
  14094. uniforms.bumpScale.value = material.bumpScale;
  14095. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14096. }
  14097. if ( material.normalMap ) {
  14098. uniforms.normalMap.value = material.normalMap;
  14099. uniforms.normalScale.value.copy( material.normalScale );
  14100. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14101. }
  14102. if ( material.displacementMap ) {
  14103. uniforms.displacementMap.value = material.displacementMap;
  14104. uniforms.displacementScale.value = material.displacementScale;
  14105. uniforms.displacementBias.value = material.displacementBias;
  14106. }
  14107. if ( material.envMap ) {
  14108. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14109. uniforms.envMapIntensity.value = material.envMapIntensity;
  14110. }
  14111. }
  14112. function refreshUniformsPhysical( uniforms, material ) {
  14113. uniforms.clearCoat.value = material.clearCoat;
  14114. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14115. refreshUniformsStandard( uniforms, material );
  14116. }
  14117. function refreshUniformsDepth( uniforms, material ) {
  14118. if ( material.displacementMap ) {
  14119. uniforms.displacementMap.value = material.displacementMap;
  14120. uniforms.displacementScale.value = material.displacementScale;
  14121. uniforms.displacementBias.value = material.displacementBias;
  14122. }
  14123. }
  14124. function refreshUniformsDistance( uniforms, material ) {
  14125. if ( material.displacementMap ) {
  14126. uniforms.displacementMap.value = material.displacementMap;
  14127. uniforms.displacementScale.value = material.displacementScale;
  14128. uniforms.displacementBias.value = material.displacementBias;
  14129. }
  14130. uniforms.referencePosition.value.copy( material.referencePosition );
  14131. uniforms.nearDistance.value = material.nearDistance;
  14132. uniforms.farDistance.value = material.farDistance;
  14133. }
  14134. function refreshUniformsNormal( uniforms, material ) {
  14135. if ( material.bumpMap ) {
  14136. uniforms.bumpMap.value = material.bumpMap;
  14137. uniforms.bumpScale.value = material.bumpScale;
  14138. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14139. }
  14140. if ( material.normalMap ) {
  14141. uniforms.normalMap.value = material.normalMap;
  14142. uniforms.normalScale.value.copy( material.normalScale );
  14143. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14144. }
  14145. if ( material.displacementMap ) {
  14146. uniforms.displacementMap.value = material.displacementMap;
  14147. uniforms.displacementScale.value = material.displacementScale;
  14148. uniforms.displacementBias.value = material.displacementBias;
  14149. }
  14150. }
  14151. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14152. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14153. uniforms.ambientLightColor.needsUpdate = value;
  14154. uniforms.directionalLights.needsUpdate = value;
  14155. uniforms.pointLights.needsUpdate = value;
  14156. uniforms.spotLights.needsUpdate = value;
  14157. uniforms.rectAreaLights.needsUpdate = value;
  14158. uniforms.hemisphereLights.needsUpdate = value;
  14159. }
  14160. // Textures
  14161. function allocTextureUnit() {
  14162. var textureUnit = _usedTextureUnits;
  14163. if ( textureUnit >= capabilities.maxTextures ) {
  14164. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  14165. }
  14166. _usedTextureUnits += 1;
  14167. return textureUnit;
  14168. }
  14169. this.allocTextureUnit = allocTextureUnit;
  14170. // this.setTexture2D = setTexture2D;
  14171. this.setTexture2D = ( function () {
  14172. var warned = false;
  14173. // backwards compatibility: peel texture.texture
  14174. return function setTexture2D( texture, slot ) {
  14175. if ( texture && texture.isWebGLRenderTarget ) {
  14176. if ( ! warned ) {
  14177. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  14178. warned = true;
  14179. }
  14180. texture = texture.texture;
  14181. }
  14182. textures.setTexture2D( texture, slot );
  14183. };
  14184. }() );
  14185. this.setTexture = ( function () {
  14186. var warned = false;
  14187. return function setTexture( texture, slot ) {
  14188. if ( ! warned ) {
  14189. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  14190. warned = true;
  14191. }
  14192. textures.setTexture2D( texture, slot );
  14193. };
  14194. }() );
  14195. this.setTextureCube = ( function () {
  14196. var warned = false;
  14197. return function setTextureCube( texture, slot ) {
  14198. // backwards compatibility: peel texture.texture
  14199. if ( texture && texture.isWebGLRenderTargetCube ) {
  14200. if ( ! warned ) {
  14201. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  14202. warned = true;
  14203. }
  14204. texture = texture.texture;
  14205. }
  14206. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  14207. // TODO: unify these code paths
  14208. if ( ( texture && texture.isCubeTexture ) ||
  14209. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14210. // CompressedTexture can have Array in image :/
  14211. // this function alone should take care of cube textures
  14212. textures.setTextureCube( texture, slot );
  14213. } else {
  14214. // assumed: texture property of THREE.WebGLRenderTargetCube
  14215. textures.setTextureCubeDynamic( texture, slot );
  14216. }
  14217. };
  14218. }() );
  14219. //
  14220. this.setFramebuffer = function ( value ) {
  14221. _framebuffer = value;
  14222. };
  14223. this.getRenderTarget = function () {
  14224. return _currentRenderTarget;
  14225. };
  14226. this.setRenderTarget = function ( renderTarget ) {
  14227. _currentRenderTarget = renderTarget;
  14228. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14229. textures.setupRenderTarget( renderTarget );
  14230. }
  14231. var framebuffer = _framebuffer;
  14232. var isCube = false;
  14233. if ( renderTarget ) {
  14234. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14235. if ( renderTarget.isWebGLRenderTargetCube ) {
  14236. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  14237. isCube = true;
  14238. } else {
  14239. framebuffer = __webglFramebuffer;
  14240. }
  14241. _currentViewport.copy( renderTarget.viewport );
  14242. _currentScissor.copy( renderTarget.scissor );
  14243. _currentScissorTest = renderTarget.scissorTest;
  14244. } else {
  14245. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14246. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14247. _currentScissorTest = _scissorTest;
  14248. }
  14249. if ( _currentFramebuffer !== framebuffer ) {
  14250. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14251. _currentFramebuffer = framebuffer;
  14252. }
  14253. state.viewport( _currentViewport );
  14254. state.scissor( _currentScissor );
  14255. state.setScissorTest( _currentScissorTest );
  14256. if ( isCube ) {
  14257. var textureProperties = properties.get( renderTarget.texture );
  14258. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  14259. }
  14260. };
  14261. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14262. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14263. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14264. return;
  14265. }
  14266. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14267. if ( framebuffer ) {
  14268. var restore = false;
  14269. if ( framebuffer !== _currentFramebuffer ) {
  14270. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14271. restore = true;
  14272. }
  14273. try {
  14274. var texture = renderTarget.texture;
  14275. var textureFormat = texture.format;
  14276. var textureType = texture.type;
  14277. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14278. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14279. return;
  14280. }
  14281. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14282. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14283. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  14284. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14285. return;
  14286. }
  14287. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14288. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14289. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14290. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14291. }
  14292. } else {
  14293. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14294. }
  14295. } finally {
  14296. if ( restore ) {
  14297. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14298. }
  14299. }
  14300. }
  14301. };
  14302. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14303. var width = texture.image.width;
  14304. var height = texture.image.height;
  14305. var glFormat = utils.convert( texture.format );
  14306. this.setTexture2D( texture, 0 );
  14307. _gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14308. };
  14309. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14310. var width = srcTexture.image.width;
  14311. var height = srcTexture.image.height;
  14312. var glFormat = utils.convert( dstTexture.format );
  14313. var glType = utils.convert( dstTexture.type );
  14314. this.setTexture2D( dstTexture, 0 );
  14315. if ( srcTexture.isDataTexture ) {
  14316. _gl.texSubImage2D( _gl.TEXTURE_2D, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14317. } else {
  14318. _gl.texSubImage2D( _gl.TEXTURE_2D, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14319. }
  14320. };
  14321. }
  14322. /**
  14323. * @author mrdoob / http://mrdoob.com/
  14324. * @author alteredq / http://alteredqualia.com/
  14325. */
  14326. function FogExp2( color, density ) {
  14327. this.name = '';
  14328. this.color = new Color( color );
  14329. this.density = ( density !== undefined ) ? density : 0.00025;
  14330. }
  14331. FogExp2.prototype.isFogExp2 = true;
  14332. FogExp2.prototype.clone = function () {
  14333. return new FogExp2( this.color, this.density );
  14334. };
  14335. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  14336. return {
  14337. type: 'FogExp2',
  14338. color: this.color.getHex(),
  14339. density: this.density
  14340. };
  14341. };
  14342. /**
  14343. * @author mrdoob / http://mrdoob.com/
  14344. * @author alteredq / http://alteredqualia.com/
  14345. */
  14346. function Fog( color, near, far ) {
  14347. this.name = '';
  14348. this.color = new Color( color );
  14349. this.near = ( near !== undefined ) ? near : 1;
  14350. this.far = ( far !== undefined ) ? far : 1000;
  14351. }
  14352. Fog.prototype.isFog = true;
  14353. Fog.prototype.clone = function () {
  14354. return new Fog( this.color, this.near, this.far );
  14355. };
  14356. Fog.prototype.toJSON = function ( /* meta */ ) {
  14357. return {
  14358. type: 'Fog',
  14359. color: this.color.getHex(),
  14360. near: this.near,
  14361. far: this.far
  14362. };
  14363. };
  14364. /**
  14365. * @author mrdoob / http://mrdoob.com/
  14366. */
  14367. function Scene() {
  14368. Object3D.call( this );
  14369. this.type = 'Scene';
  14370. this.background = null;
  14371. this.fog = null;
  14372. this.overrideMaterial = null;
  14373. this.autoUpdate = true; // checked by the renderer
  14374. }
  14375. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14376. constructor: Scene,
  14377. copy: function ( source, recursive ) {
  14378. Object3D.prototype.copy.call( this, source, recursive );
  14379. if ( source.background !== null ) this.background = source.background.clone();
  14380. if ( source.fog !== null ) this.fog = source.fog.clone();
  14381. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14382. this.autoUpdate = source.autoUpdate;
  14383. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14384. return this;
  14385. },
  14386. toJSON: function ( meta ) {
  14387. var data = Object3D.prototype.toJSON.call( this, meta );
  14388. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  14389. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  14390. return data;
  14391. }
  14392. } );
  14393. /**
  14394. * @author alteredq / http://alteredqualia.com/
  14395. *
  14396. * parameters = {
  14397. * color: <hex>,
  14398. * opacity: <float>,
  14399. * map: new THREE.Texture( <Image> ),
  14400. *
  14401. * uvOffset: new THREE.Vector2(),
  14402. * uvScale: new THREE.Vector2()
  14403. * }
  14404. */
  14405. function SpriteMaterial( parameters ) {
  14406. Material.call( this );
  14407. this.type = 'SpriteMaterial';
  14408. this.color = new Color( 0xffffff );
  14409. this.map = null;
  14410. this.rotation = 0;
  14411. this.fog = false;
  14412. this.lights = false;
  14413. this.setValues( parameters );
  14414. }
  14415. SpriteMaterial.prototype = Object.create( Material.prototype );
  14416. SpriteMaterial.prototype.constructor = SpriteMaterial;
  14417. SpriteMaterial.prototype.isSpriteMaterial = true;
  14418. SpriteMaterial.prototype.copy = function ( source ) {
  14419. Material.prototype.copy.call( this, source );
  14420. this.color.copy( source.color );
  14421. this.map = source.map;
  14422. this.rotation = source.rotation;
  14423. return this;
  14424. };
  14425. /**
  14426. * @author mikael emtinger / http://gomo.se/
  14427. * @author alteredq / http://alteredqualia.com/
  14428. */
  14429. function Sprite( material ) {
  14430. Object3D.call( this );
  14431. this.type = 'Sprite';
  14432. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  14433. this.center = new Vector2( 0.5, 0.5 );
  14434. }
  14435. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14436. constructor: Sprite,
  14437. isSprite: true,
  14438. raycast: ( function () {
  14439. var intersectPoint = new Vector3();
  14440. var worldPosition = new Vector3();
  14441. var worldScale = new Vector3();
  14442. return function raycast( raycaster, intersects ) {
  14443. worldPosition.setFromMatrixPosition( this.matrixWorld );
  14444. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  14445. worldScale.setFromMatrixScale( this.matrixWorld );
  14446. var guessSizeSq = worldScale.x * worldScale.y / 4;
  14447. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  14448. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14449. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14450. intersects.push( {
  14451. distance: distance,
  14452. point: intersectPoint.clone(),
  14453. face: null,
  14454. object: this
  14455. } );
  14456. };
  14457. }() ),
  14458. clone: function () {
  14459. return new this.constructor( this.material ).copy( this );
  14460. },
  14461. copy: function ( source ) {
  14462. Object3D.prototype.copy.call( this, source );
  14463. if ( source.center !== undefined ) this.center.copy( source.center );
  14464. return this;
  14465. }
  14466. } );
  14467. /**
  14468. * @author mikael emtinger / http://gomo.se/
  14469. * @author alteredq / http://alteredqualia.com/
  14470. * @author mrdoob / http://mrdoob.com/
  14471. */
  14472. function LOD() {
  14473. Object3D.call( this );
  14474. this.type = 'LOD';
  14475. Object.defineProperties( this, {
  14476. levels: {
  14477. enumerable: true,
  14478. value: []
  14479. }
  14480. } );
  14481. }
  14482. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14483. constructor: LOD,
  14484. copy: function ( source ) {
  14485. Object3D.prototype.copy.call( this, source, false );
  14486. var levels = source.levels;
  14487. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14488. var level = levels[ i ];
  14489. this.addLevel( level.object.clone(), level.distance );
  14490. }
  14491. return this;
  14492. },
  14493. addLevel: function ( object, distance ) {
  14494. if ( distance === undefined ) distance = 0;
  14495. distance = Math.abs( distance );
  14496. var levels = this.levels;
  14497. for ( var l = 0; l < levels.length; l ++ ) {
  14498. if ( distance < levels[ l ].distance ) {
  14499. break;
  14500. }
  14501. }
  14502. levels.splice( l, 0, { distance: distance, object: object } );
  14503. this.add( object );
  14504. },
  14505. getObjectForDistance: function ( distance ) {
  14506. var levels = this.levels;
  14507. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14508. if ( distance < levels[ i ].distance ) {
  14509. break;
  14510. }
  14511. }
  14512. return levels[ i - 1 ].object;
  14513. },
  14514. raycast: ( function () {
  14515. var matrixPosition = new Vector3();
  14516. return function raycast( raycaster, intersects ) {
  14517. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  14518. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  14519. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  14520. };
  14521. }() ),
  14522. update: function () {
  14523. var v1 = new Vector3();
  14524. var v2 = new Vector3();
  14525. return function update( camera ) {
  14526. var levels = this.levels;
  14527. if ( levels.length > 1 ) {
  14528. v1.setFromMatrixPosition( camera.matrixWorld );
  14529. v2.setFromMatrixPosition( this.matrixWorld );
  14530. var distance = v1.distanceTo( v2 );
  14531. levels[ 0 ].object.visible = true;
  14532. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14533. if ( distance >= levels[ i ].distance ) {
  14534. levels[ i - 1 ].object.visible = false;
  14535. levels[ i ].object.visible = true;
  14536. } else {
  14537. break;
  14538. }
  14539. }
  14540. for ( ; i < l; i ++ ) {
  14541. levels[ i ].object.visible = false;
  14542. }
  14543. }
  14544. };
  14545. }(),
  14546. toJSON: function ( meta ) {
  14547. var data = Object3D.prototype.toJSON.call( this, meta );
  14548. data.object.levels = [];
  14549. var levels = this.levels;
  14550. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14551. var level = levels[ i ];
  14552. data.object.levels.push( {
  14553. object: level.object.uuid,
  14554. distance: level.distance
  14555. } );
  14556. }
  14557. return data;
  14558. }
  14559. } );
  14560. /**
  14561. * @author mikael emtinger / http://gomo.se/
  14562. * @author alteredq / http://alteredqualia.com/
  14563. * @author michael guerrero / http://realitymeltdown.com
  14564. * @author ikerr / http://verold.com
  14565. */
  14566. function Skeleton( bones, boneInverses ) {
  14567. // copy the bone array
  14568. bones = bones || [];
  14569. this.bones = bones.slice( 0 );
  14570. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  14571. // use the supplied bone inverses or calculate the inverses
  14572. if ( boneInverses === undefined ) {
  14573. this.calculateInverses();
  14574. } else {
  14575. if ( this.bones.length === boneInverses.length ) {
  14576. this.boneInverses = boneInverses.slice( 0 );
  14577. } else {
  14578. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  14579. this.boneInverses = [];
  14580. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14581. this.boneInverses.push( new Matrix4() );
  14582. }
  14583. }
  14584. }
  14585. }
  14586. Object.assign( Skeleton.prototype, {
  14587. calculateInverses: function () {
  14588. this.boneInverses = [];
  14589. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14590. var inverse = new Matrix4();
  14591. if ( this.bones[ i ] ) {
  14592. inverse.getInverse( this.bones[ i ].matrixWorld );
  14593. }
  14594. this.boneInverses.push( inverse );
  14595. }
  14596. },
  14597. pose: function () {
  14598. var bone, i, il;
  14599. // recover the bind-time world matrices
  14600. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14601. bone = this.bones[ i ];
  14602. if ( bone ) {
  14603. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  14604. }
  14605. }
  14606. // compute the local matrices, positions, rotations and scales
  14607. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14608. bone = this.bones[ i ];
  14609. if ( bone ) {
  14610. if ( bone.parent && bone.parent.isBone ) {
  14611. bone.matrix.getInverse( bone.parent.matrixWorld );
  14612. bone.matrix.multiply( bone.matrixWorld );
  14613. } else {
  14614. bone.matrix.copy( bone.matrixWorld );
  14615. }
  14616. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  14617. }
  14618. }
  14619. },
  14620. update: ( function () {
  14621. var offsetMatrix = new Matrix4();
  14622. var identityMatrix = new Matrix4();
  14623. return function update() {
  14624. var bones = this.bones;
  14625. var boneInverses = this.boneInverses;
  14626. var boneMatrices = this.boneMatrices;
  14627. var boneTexture = this.boneTexture;
  14628. // flatten bone matrices to array
  14629. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  14630. // compute the offset between the current and the original transform
  14631. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  14632. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  14633. offsetMatrix.toArray( boneMatrices, i * 16 );
  14634. }
  14635. if ( boneTexture !== undefined ) {
  14636. boneTexture.needsUpdate = true;
  14637. }
  14638. };
  14639. } )(),
  14640. clone: function () {
  14641. return new Skeleton( this.bones, this.boneInverses );
  14642. },
  14643. getBoneByName: function ( name ) {
  14644. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14645. var bone = this.bones[ i ];
  14646. if ( bone.name === name ) {
  14647. return bone;
  14648. }
  14649. }
  14650. return undefined;
  14651. }
  14652. } );
  14653. /**
  14654. * @author mikael emtinger / http://gomo.se/
  14655. * @author alteredq / http://alteredqualia.com/
  14656. * @author ikerr / http://verold.com
  14657. */
  14658. function Bone() {
  14659. Object3D.call( this );
  14660. this.type = 'Bone';
  14661. }
  14662. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14663. constructor: Bone,
  14664. isBone: true
  14665. } );
  14666. /**
  14667. * @author mikael emtinger / http://gomo.se/
  14668. * @author alteredq / http://alteredqualia.com/
  14669. * @author ikerr / http://verold.com
  14670. */
  14671. function SkinnedMesh( geometry, material ) {
  14672. Mesh.call( this, geometry, material );
  14673. this.type = 'SkinnedMesh';
  14674. this.bindMode = 'attached';
  14675. this.bindMatrix = new Matrix4();
  14676. this.bindMatrixInverse = new Matrix4();
  14677. var bones = this.initBones();
  14678. var skeleton = new Skeleton( bones );
  14679. this.bind( skeleton, this.matrixWorld );
  14680. this.normalizeSkinWeights();
  14681. }
  14682. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  14683. constructor: SkinnedMesh,
  14684. isSkinnedMesh: true,
  14685. initBones: function () {
  14686. var bones = [], bone, gbone;
  14687. var i, il;
  14688. if ( this.geometry && this.geometry.bones !== undefined ) {
  14689. // first, create array of 'Bone' objects from geometry data
  14690. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14691. gbone = this.geometry.bones[ i ];
  14692. // create new 'Bone' object
  14693. bone = new Bone();
  14694. bones.push( bone );
  14695. // apply values
  14696. bone.name = gbone.name;
  14697. bone.position.fromArray( gbone.pos );
  14698. bone.quaternion.fromArray( gbone.rotq );
  14699. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  14700. }
  14701. // second, create bone hierarchy
  14702. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14703. gbone = this.geometry.bones[ i ];
  14704. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  14705. // subsequent bones in the hierarchy
  14706. bones[ gbone.parent ].add( bones[ i ] );
  14707. } else {
  14708. // topmost bone, immediate child of the skinned mesh
  14709. this.add( bones[ i ] );
  14710. }
  14711. }
  14712. }
  14713. // now the bones are part of the scene graph and children of the skinned mesh.
  14714. // let's update the corresponding matrices
  14715. this.updateMatrixWorld( true );
  14716. return bones;
  14717. },
  14718. bind: function ( skeleton, bindMatrix ) {
  14719. this.skeleton = skeleton;
  14720. if ( bindMatrix === undefined ) {
  14721. this.updateMatrixWorld( true );
  14722. this.skeleton.calculateInverses();
  14723. bindMatrix = this.matrixWorld;
  14724. }
  14725. this.bindMatrix.copy( bindMatrix );
  14726. this.bindMatrixInverse.getInverse( bindMatrix );
  14727. },
  14728. pose: function () {
  14729. this.skeleton.pose();
  14730. },
  14731. normalizeSkinWeights: function () {
  14732. var scale, i;
  14733. if ( this.geometry && this.geometry.isGeometry ) {
  14734. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  14735. var sw = this.geometry.skinWeights[ i ];
  14736. scale = 1.0 / sw.manhattanLength();
  14737. if ( scale !== Infinity ) {
  14738. sw.multiplyScalar( scale );
  14739. } else {
  14740. sw.set( 1, 0, 0, 0 ); // do something reasonable
  14741. }
  14742. }
  14743. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  14744. var vec = new Vector4();
  14745. var skinWeight = this.geometry.attributes.skinWeight;
  14746. for ( i = 0; i < skinWeight.count; i ++ ) {
  14747. vec.x = skinWeight.getX( i );
  14748. vec.y = skinWeight.getY( i );
  14749. vec.z = skinWeight.getZ( i );
  14750. vec.w = skinWeight.getW( i );
  14751. scale = 1.0 / vec.manhattanLength();
  14752. if ( scale !== Infinity ) {
  14753. vec.multiplyScalar( scale );
  14754. } else {
  14755. vec.set( 1, 0, 0, 0 ); // do something reasonable
  14756. }
  14757. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  14758. }
  14759. }
  14760. },
  14761. updateMatrixWorld: function ( force ) {
  14762. Mesh.prototype.updateMatrixWorld.call( this, force );
  14763. if ( this.bindMode === 'attached' ) {
  14764. this.bindMatrixInverse.getInverse( this.matrixWorld );
  14765. } else if ( this.bindMode === 'detached' ) {
  14766. this.bindMatrixInverse.getInverse( this.bindMatrix );
  14767. } else {
  14768. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  14769. }
  14770. },
  14771. clone: function () {
  14772. return new this.constructor( this.geometry, this.material ).copy( this );
  14773. }
  14774. } );
  14775. /**
  14776. * @author mrdoob / http://mrdoob.com/
  14777. * @author alteredq / http://alteredqualia.com/
  14778. *
  14779. * parameters = {
  14780. * color: <hex>,
  14781. * opacity: <float>,
  14782. *
  14783. * linewidth: <float>,
  14784. * linecap: "round",
  14785. * linejoin: "round"
  14786. * }
  14787. */
  14788. function LineBasicMaterial( parameters ) {
  14789. Material.call( this );
  14790. this.type = 'LineBasicMaterial';
  14791. this.color = new Color( 0xffffff );
  14792. this.linewidth = 1;
  14793. this.linecap = 'round';
  14794. this.linejoin = 'round';
  14795. this.lights = false;
  14796. this.setValues( parameters );
  14797. }
  14798. LineBasicMaterial.prototype = Object.create( Material.prototype );
  14799. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  14800. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  14801. LineBasicMaterial.prototype.copy = function ( source ) {
  14802. Material.prototype.copy.call( this, source );
  14803. this.color.copy( source.color );
  14804. this.linewidth = source.linewidth;
  14805. this.linecap = source.linecap;
  14806. this.linejoin = source.linejoin;
  14807. return this;
  14808. };
  14809. /**
  14810. * @author mrdoob / http://mrdoob.com/
  14811. */
  14812. function Line( geometry, material, mode ) {
  14813. if ( mode === 1 ) {
  14814. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14815. return new LineSegments( geometry, material );
  14816. }
  14817. Object3D.call( this );
  14818. this.type = 'Line';
  14819. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14820. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14821. }
  14822. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14823. constructor: Line,
  14824. isLine: true,
  14825. computeLineDistances: ( function () {
  14826. var start = new Vector3();
  14827. var end = new Vector3();
  14828. return function computeLineDistances() {
  14829. var geometry = this.geometry;
  14830. if ( geometry.isBufferGeometry ) {
  14831. // we assume non-indexed geometry
  14832. if ( geometry.index === null ) {
  14833. var positionAttribute = geometry.attributes.position;
  14834. var lineDistances = [ 0 ];
  14835. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  14836. start.fromBufferAttribute( positionAttribute, i - 1 );
  14837. end.fromBufferAttribute( positionAttribute, i );
  14838. lineDistances[ i ] = lineDistances[ i - 1 ];
  14839. lineDistances[ i ] += start.distanceTo( end );
  14840. }
  14841. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  14842. } else {
  14843. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  14844. }
  14845. } else if ( geometry.isGeometry ) {
  14846. var vertices = geometry.vertices;
  14847. var lineDistances = geometry.lineDistances;
  14848. lineDistances[ 0 ] = 0;
  14849. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  14850. lineDistances[ i ] = lineDistances[ i - 1 ];
  14851. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  14852. }
  14853. }
  14854. return this;
  14855. };
  14856. }() ),
  14857. raycast: ( function () {
  14858. var inverseMatrix = new Matrix4();
  14859. var ray = new Ray();
  14860. var sphere = new Sphere();
  14861. return function raycast( raycaster, intersects ) {
  14862. var precision = raycaster.linePrecision;
  14863. var precisionSq = precision * precision;
  14864. var geometry = this.geometry;
  14865. var matrixWorld = this.matrixWorld;
  14866. // Checking boundingSphere distance to ray
  14867. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14868. sphere.copy( geometry.boundingSphere );
  14869. sphere.applyMatrix4( matrixWorld );
  14870. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14871. //
  14872. inverseMatrix.getInverse( matrixWorld );
  14873. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14874. var vStart = new Vector3();
  14875. var vEnd = new Vector3();
  14876. var interSegment = new Vector3();
  14877. var interRay = new Vector3();
  14878. var step = ( this && this.isLineSegments ) ? 2 : 1;
  14879. if ( geometry.isBufferGeometry ) {
  14880. var index = geometry.index;
  14881. var attributes = geometry.attributes;
  14882. var positions = attributes.position.array;
  14883. if ( index !== null ) {
  14884. var indices = index.array;
  14885. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14886. var a = indices[ i ];
  14887. var b = indices[ i + 1 ];
  14888. vStart.fromArray( positions, a * 3 );
  14889. vEnd.fromArray( positions, b * 3 );
  14890. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14891. if ( distSq > precisionSq ) continue;
  14892. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14893. var distance = raycaster.ray.origin.distanceTo( interRay );
  14894. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14895. intersects.push( {
  14896. distance: distance,
  14897. // What do we want? intersection point on the ray or on the segment??
  14898. // point: raycaster.ray.at( distance ),
  14899. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14900. index: i,
  14901. face: null,
  14902. faceIndex: null,
  14903. object: this
  14904. } );
  14905. }
  14906. } else {
  14907. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14908. vStart.fromArray( positions, 3 * i );
  14909. vEnd.fromArray( positions, 3 * i + 3 );
  14910. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14911. if ( distSq > precisionSq ) continue;
  14912. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14913. var distance = raycaster.ray.origin.distanceTo( interRay );
  14914. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14915. intersects.push( {
  14916. distance: distance,
  14917. // What do we want? intersection point on the ray or on the segment??
  14918. // point: raycaster.ray.at( distance ),
  14919. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14920. index: i,
  14921. face: null,
  14922. faceIndex: null,
  14923. object: this
  14924. } );
  14925. }
  14926. }
  14927. } else if ( geometry.isGeometry ) {
  14928. var vertices = geometry.vertices;
  14929. var nbVertices = vertices.length;
  14930. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14931. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14932. if ( distSq > precisionSq ) continue;
  14933. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14934. var distance = raycaster.ray.origin.distanceTo( interRay );
  14935. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14936. intersects.push( {
  14937. distance: distance,
  14938. // What do we want? intersection point on the ray or on the segment??
  14939. // point: raycaster.ray.at( distance ),
  14940. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14941. index: i,
  14942. face: null,
  14943. faceIndex: null,
  14944. object: this
  14945. } );
  14946. }
  14947. }
  14948. };
  14949. }() ),
  14950. clone: function () {
  14951. return new this.constructor( this.geometry, this.material ).copy( this );
  14952. }
  14953. } );
  14954. /**
  14955. * @author mrdoob / http://mrdoob.com/
  14956. */
  14957. function LineSegments( geometry, material ) {
  14958. Line.call( this, geometry, material );
  14959. this.type = 'LineSegments';
  14960. }
  14961. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14962. constructor: LineSegments,
  14963. isLineSegments: true,
  14964. computeLineDistances: ( function () {
  14965. var start = new Vector3();
  14966. var end = new Vector3();
  14967. return function computeLineDistances() {
  14968. var geometry = this.geometry;
  14969. if ( geometry.isBufferGeometry ) {
  14970. // we assume non-indexed geometry
  14971. if ( geometry.index === null ) {
  14972. var positionAttribute = geometry.attributes.position;
  14973. var lineDistances = [];
  14974. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  14975. start.fromBufferAttribute( positionAttribute, i );
  14976. end.fromBufferAttribute( positionAttribute, i + 1 );
  14977. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  14978. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  14979. }
  14980. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  14981. } else {
  14982. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  14983. }
  14984. } else if ( geometry.isGeometry ) {
  14985. var vertices = geometry.vertices;
  14986. var lineDistances = geometry.lineDistances;
  14987. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  14988. start.copy( vertices[ i ] );
  14989. end.copy( vertices[ i + 1 ] );
  14990. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  14991. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  14992. }
  14993. }
  14994. return this;
  14995. };
  14996. }() )
  14997. } );
  14998. /**
  14999. * @author mgreter / http://github.com/mgreter
  15000. */
  15001. function LineLoop( geometry, material ) {
  15002. Line.call( this, geometry, material );
  15003. this.type = 'LineLoop';
  15004. }
  15005. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15006. constructor: LineLoop,
  15007. isLineLoop: true,
  15008. } );
  15009. /**
  15010. * @author mrdoob / http://mrdoob.com/
  15011. * @author alteredq / http://alteredqualia.com/
  15012. *
  15013. * parameters = {
  15014. * color: <hex>,
  15015. * opacity: <float>,
  15016. * map: new THREE.Texture( <Image> ),
  15017. *
  15018. * size: <float>,
  15019. * sizeAttenuation: <bool>
  15020. *
  15021. * morphTargets: <bool>
  15022. * }
  15023. */
  15024. function PointsMaterial( parameters ) {
  15025. Material.call( this );
  15026. this.type = 'PointsMaterial';
  15027. this.color = new Color( 0xffffff );
  15028. this.map = null;
  15029. this.size = 1;
  15030. this.sizeAttenuation = true;
  15031. this.morphTargets = false;
  15032. this.lights = false;
  15033. this.setValues( parameters );
  15034. }
  15035. PointsMaterial.prototype = Object.create( Material.prototype );
  15036. PointsMaterial.prototype.constructor = PointsMaterial;
  15037. PointsMaterial.prototype.isPointsMaterial = true;
  15038. PointsMaterial.prototype.copy = function ( source ) {
  15039. Material.prototype.copy.call( this, source );
  15040. this.color.copy( source.color );
  15041. this.map = source.map;
  15042. this.size = source.size;
  15043. this.sizeAttenuation = source.sizeAttenuation;
  15044. this.morphTargets = source.morphTargets;
  15045. return this;
  15046. };
  15047. /**
  15048. * @author alteredq / http://alteredqualia.com/
  15049. */
  15050. function Points( geometry, material ) {
  15051. Object3D.call( this );
  15052. this.type = 'Points';
  15053. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15054. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15055. }
  15056. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15057. constructor: Points,
  15058. isPoints: true,
  15059. raycast: ( function () {
  15060. var inverseMatrix = new Matrix4();
  15061. var ray = new Ray();
  15062. var sphere = new Sphere();
  15063. return function raycast( raycaster, intersects ) {
  15064. var object = this;
  15065. var geometry = this.geometry;
  15066. var matrixWorld = this.matrixWorld;
  15067. var threshold = raycaster.params.Points.threshold;
  15068. // Checking boundingSphere distance to ray
  15069. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15070. sphere.copy( geometry.boundingSphere );
  15071. sphere.applyMatrix4( matrixWorld );
  15072. sphere.radius += threshold;
  15073. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15074. //
  15075. inverseMatrix.getInverse( matrixWorld );
  15076. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15077. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15078. var localThresholdSq = localThreshold * localThreshold;
  15079. var position = new Vector3();
  15080. var intersectPoint = new Vector3();
  15081. function testPoint( point, index ) {
  15082. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15083. if ( rayPointDistanceSq < localThresholdSq ) {
  15084. ray.closestPointToPoint( point, intersectPoint );
  15085. intersectPoint.applyMatrix4( matrixWorld );
  15086. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15087. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15088. intersects.push( {
  15089. distance: distance,
  15090. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15091. point: intersectPoint.clone(),
  15092. index: index,
  15093. face: null,
  15094. object: object
  15095. } );
  15096. }
  15097. }
  15098. if ( geometry.isBufferGeometry ) {
  15099. var index = geometry.index;
  15100. var attributes = geometry.attributes;
  15101. var positions = attributes.position.array;
  15102. if ( index !== null ) {
  15103. var indices = index.array;
  15104. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15105. var a = indices[ i ];
  15106. position.fromArray( positions, a * 3 );
  15107. testPoint( position, a );
  15108. }
  15109. } else {
  15110. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15111. position.fromArray( positions, i * 3 );
  15112. testPoint( position, i );
  15113. }
  15114. }
  15115. } else {
  15116. var vertices = geometry.vertices;
  15117. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15118. testPoint( vertices[ i ], i );
  15119. }
  15120. }
  15121. };
  15122. }() ),
  15123. clone: function () {
  15124. return new this.constructor( this.geometry, this.material ).copy( this );
  15125. }
  15126. } );
  15127. /**
  15128. * @author mrdoob / http://mrdoob.com/
  15129. */
  15130. function Group() {
  15131. Object3D.call( this );
  15132. this.type = 'Group';
  15133. }
  15134. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15135. constructor: Group,
  15136. isGroup: true
  15137. } );
  15138. /**
  15139. * @author mrdoob / http://mrdoob.com/
  15140. */
  15141. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15142. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15143. this.generateMipmaps = false;
  15144. }
  15145. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15146. constructor: VideoTexture,
  15147. isVideoTexture: true,
  15148. update: function () {
  15149. var video = this.image;
  15150. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15151. this.needsUpdate = true;
  15152. }
  15153. }
  15154. } );
  15155. /**
  15156. * @author alteredq / http://alteredqualia.com/
  15157. */
  15158. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15159. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15160. this.image = { width: width, height: height };
  15161. this.mipmaps = mipmaps;
  15162. // no flipping for cube textures
  15163. // (also flipping doesn't work for compressed textures )
  15164. this.flipY = false;
  15165. // can't generate mipmaps for compressed textures
  15166. // mips must be embedded in DDS files
  15167. this.generateMipmaps = false;
  15168. }
  15169. CompressedTexture.prototype = Object.create( Texture.prototype );
  15170. CompressedTexture.prototype.constructor = CompressedTexture;
  15171. CompressedTexture.prototype.isCompressedTexture = true;
  15172. /**
  15173. * @author Matt DesLauriers / @mattdesl
  15174. * @author atix / arthursilber.de
  15175. */
  15176. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15177. format = format !== undefined ? format : DepthFormat;
  15178. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15179. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15180. }
  15181. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15182. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15183. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15184. this.image = { width: width, height: height };
  15185. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  15186. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  15187. this.flipY = false;
  15188. this.generateMipmaps = false;
  15189. }
  15190. DepthTexture.prototype = Object.create( Texture.prototype );
  15191. DepthTexture.prototype.constructor = DepthTexture;
  15192. DepthTexture.prototype.isDepthTexture = true;
  15193. /**
  15194. * @author mrdoob / http://mrdoob.com/
  15195. * @author Mugen87 / https://github.com/Mugen87
  15196. */
  15197. function WireframeGeometry( geometry ) {
  15198. BufferGeometry.call( this );
  15199. this.type = 'WireframeGeometry';
  15200. // buffer
  15201. var vertices = [];
  15202. // helper variables
  15203. var i, j, l, o, ol;
  15204. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  15205. var key, keys = [ 'a', 'b', 'c' ];
  15206. var vertex;
  15207. // different logic for Geometry and BufferGeometry
  15208. if ( geometry && geometry.isGeometry ) {
  15209. // create a data structure that contains all edges without duplicates
  15210. var faces = geometry.faces;
  15211. for ( i = 0, l = faces.length; i < l; i ++ ) {
  15212. var face = faces[ i ];
  15213. for ( j = 0; j < 3; j ++ ) {
  15214. edge1 = face[ keys[ j ] ];
  15215. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  15216. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15217. edge[ 1 ] = Math.max( edge1, edge2 );
  15218. key = edge[ 0 ] + ',' + edge[ 1 ];
  15219. if ( edges[ key ] === undefined ) {
  15220. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15221. }
  15222. }
  15223. }
  15224. // generate vertices
  15225. for ( key in edges ) {
  15226. e = edges[ key ];
  15227. vertex = geometry.vertices[ e.index1 ];
  15228. vertices.push( vertex.x, vertex.y, vertex.z );
  15229. vertex = geometry.vertices[ e.index2 ];
  15230. vertices.push( vertex.x, vertex.y, vertex.z );
  15231. }
  15232. } else if ( geometry && geometry.isBufferGeometry ) {
  15233. var position, indices, groups;
  15234. var group, start, count;
  15235. var index1, index2;
  15236. vertex = new Vector3();
  15237. if ( geometry.index !== null ) {
  15238. // indexed BufferGeometry
  15239. position = geometry.attributes.position;
  15240. indices = geometry.index;
  15241. groups = geometry.groups;
  15242. if ( groups.length === 0 ) {
  15243. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  15244. }
  15245. // create a data structure that contains all eges without duplicates
  15246. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  15247. group = groups[ o ];
  15248. start = group.start;
  15249. count = group.count;
  15250. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  15251. for ( j = 0; j < 3; j ++ ) {
  15252. edge1 = indices.getX( i + j );
  15253. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  15254. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15255. edge[ 1 ] = Math.max( edge1, edge2 );
  15256. key = edge[ 0 ] + ',' + edge[ 1 ];
  15257. if ( edges[ key ] === undefined ) {
  15258. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15259. }
  15260. }
  15261. }
  15262. }
  15263. // generate vertices
  15264. for ( key in edges ) {
  15265. e = edges[ key ];
  15266. vertex.fromBufferAttribute( position, e.index1 );
  15267. vertices.push( vertex.x, vertex.y, vertex.z );
  15268. vertex.fromBufferAttribute( position, e.index2 );
  15269. vertices.push( vertex.x, vertex.y, vertex.z );
  15270. }
  15271. } else {
  15272. // non-indexed BufferGeometry
  15273. position = geometry.attributes.position;
  15274. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  15275. for ( j = 0; j < 3; j ++ ) {
  15276. // three edges per triangle, an edge is represented as (index1, index2)
  15277. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  15278. index1 = 3 * i + j;
  15279. vertex.fromBufferAttribute( position, index1 );
  15280. vertices.push( vertex.x, vertex.y, vertex.z );
  15281. index2 = 3 * i + ( ( j + 1 ) % 3 );
  15282. vertex.fromBufferAttribute( position, index2 );
  15283. vertices.push( vertex.x, vertex.y, vertex.z );
  15284. }
  15285. }
  15286. }
  15287. }
  15288. // build geometry
  15289. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15290. }
  15291. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  15292. WireframeGeometry.prototype.constructor = WireframeGeometry;
  15293. /**
  15294. * @author zz85 / https://github.com/zz85
  15295. * @author Mugen87 / https://github.com/Mugen87
  15296. *
  15297. * Parametric Surfaces Geometry
  15298. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  15299. */
  15300. // ParametricGeometry
  15301. function ParametricGeometry( func, slices, stacks ) {
  15302. Geometry.call( this );
  15303. this.type = 'ParametricGeometry';
  15304. this.parameters = {
  15305. func: func,
  15306. slices: slices,
  15307. stacks: stacks
  15308. };
  15309. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  15310. this.mergeVertices();
  15311. }
  15312. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  15313. ParametricGeometry.prototype.constructor = ParametricGeometry;
  15314. // ParametricBufferGeometry
  15315. function ParametricBufferGeometry( func, slices, stacks ) {
  15316. BufferGeometry.call( this );
  15317. this.type = 'ParametricBufferGeometry';
  15318. this.parameters = {
  15319. func: func,
  15320. slices: slices,
  15321. stacks: stacks
  15322. };
  15323. // buffers
  15324. var indices = [];
  15325. var vertices = [];
  15326. var normals = [];
  15327. var uvs = [];
  15328. var EPS = 0.00001;
  15329. var normal = new Vector3();
  15330. var p0 = new Vector3(), p1 = new Vector3();
  15331. var pu = new Vector3(), pv = new Vector3();
  15332. var i, j;
  15333. if ( func.length < 3 ) {
  15334. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  15335. }
  15336. // generate vertices, normals and uvs
  15337. var sliceCount = slices + 1;
  15338. for ( i = 0; i <= stacks; i ++ ) {
  15339. var v = i / stacks;
  15340. for ( j = 0; j <= slices; j ++ ) {
  15341. var u = j / slices;
  15342. // vertex
  15343. func( u, v, p0 );
  15344. vertices.push( p0.x, p0.y, p0.z );
  15345. // normal
  15346. // approximate tangent vectors via finite differences
  15347. if ( u - EPS >= 0 ) {
  15348. func( u - EPS, v, p1 );
  15349. pu.subVectors( p0, p1 );
  15350. } else {
  15351. func( u + EPS, v, p1 );
  15352. pu.subVectors( p1, p0 );
  15353. }
  15354. if ( v - EPS >= 0 ) {
  15355. func( u, v - EPS, p1 );
  15356. pv.subVectors( p0, p1 );
  15357. } else {
  15358. func( u, v + EPS, p1 );
  15359. pv.subVectors( p1, p0 );
  15360. }
  15361. // cross product of tangent vectors returns surface normal
  15362. normal.crossVectors( pu, pv ).normalize();
  15363. normals.push( normal.x, normal.y, normal.z );
  15364. // uv
  15365. uvs.push( u, v );
  15366. }
  15367. }
  15368. // generate indices
  15369. for ( i = 0; i < stacks; i ++ ) {
  15370. for ( j = 0; j < slices; j ++ ) {
  15371. var a = i * sliceCount + j;
  15372. var b = i * sliceCount + j + 1;
  15373. var c = ( i + 1 ) * sliceCount + j + 1;
  15374. var d = ( i + 1 ) * sliceCount + j;
  15375. // faces one and two
  15376. indices.push( a, b, d );
  15377. indices.push( b, c, d );
  15378. }
  15379. }
  15380. // build geometry
  15381. this.setIndex( indices );
  15382. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15383. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15384. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15385. }
  15386. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15387. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  15388. /**
  15389. * @author clockworkgeek / https://github.com/clockworkgeek
  15390. * @author timothypratley / https://github.com/timothypratley
  15391. * @author WestLangley / http://github.com/WestLangley
  15392. * @author Mugen87 / https://github.com/Mugen87
  15393. */
  15394. // PolyhedronGeometry
  15395. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  15396. Geometry.call( this );
  15397. this.type = 'PolyhedronGeometry';
  15398. this.parameters = {
  15399. vertices: vertices,
  15400. indices: indices,
  15401. radius: radius,
  15402. detail: detail
  15403. };
  15404. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  15405. this.mergeVertices();
  15406. }
  15407. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  15408. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  15409. // PolyhedronBufferGeometry
  15410. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  15411. BufferGeometry.call( this );
  15412. this.type = 'PolyhedronBufferGeometry';
  15413. this.parameters = {
  15414. vertices: vertices,
  15415. indices: indices,
  15416. radius: radius,
  15417. detail: detail
  15418. };
  15419. radius = radius || 1;
  15420. detail = detail || 0;
  15421. // default buffer data
  15422. var vertexBuffer = [];
  15423. var uvBuffer = [];
  15424. // the subdivision creates the vertex buffer data
  15425. subdivide( detail );
  15426. // all vertices should lie on a conceptual sphere with a given radius
  15427. appplyRadius( radius );
  15428. // finally, create the uv data
  15429. generateUVs();
  15430. // build non-indexed geometry
  15431. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  15432. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  15433. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  15434. if ( detail === 0 ) {
  15435. this.computeVertexNormals(); // flat normals
  15436. } else {
  15437. this.normalizeNormals(); // smooth normals
  15438. }
  15439. // helper functions
  15440. function subdivide( detail ) {
  15441. var a = new Vector3();
  15442. var b = new Vector3();
  15443. var c = new Vector3();
  15444. // iterate over all faces and apply a subdivison with the given detail value
  15445. for ( var i = 0; i < indices.length; i += 3 ) {
  15446. // get the vertices of the face
  15447. getVertexByIndex( indices[ i + 0 ], a );
  15448. getVertexByIndex( indices[ i + 1 ], b );
  15449. getVertexByIndex( indices[ i + 2 ], c );
  15450. // perform subdivision
  15451. subdivideFace( a, b, c, detail );
  15452. }
  15453. }
  15454. function subdivideFace( a, b, c, detail ) {
  15455. var cols = Math.pow( 2, detail );
  15456. // we use this multidimensional array as a data structure for creating the subdivision
  15457. var v = [];
  15458. var i, j;
  15459. // construct all of the vertices for this subdivision
  15460. for ( i = 0; i <= cols; i ++ ) {
  15461. v[ i ] = [];
  15462. var aj = a.clone().lerp( c, i / cols );
  15463. var bj = b.clone().lerp( c, i / cols );
  15464. var rows = cols - i;
  15465. for ( j = 0; j <= rows; j ++ ) {
  15466. if ( j === 0 && i === cols ) {
  15467. v[ i ][ j ] = aj;
  15468. } else {
  15469. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  15470. }
  15471. }
  15472. }
  15473. // construct all of the faces
  15474. for ( i = 0; i < cols; i ++ ) {
  15475. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  15476. var k = Math.floor( j / 2 );
  15477. if ( j % 2 === 0 ) {
  15478. pushVertex( v[ i ][ k + 1 ] );
  15479. pushVertex( v[ i + 1 ][ k ] );
  15480. pushVertex( v[ i ][ k ] );
  15481. } else {
  15482. pushVertex( v[ i ][ k + 1 ] );
  15483. pushVertex( v[ i + 1 ][ k + 1 ] );
  15484. pushVertex( v[ i + 1 ][ k ] );
  15485. }
  15486. }
  15487. }
  15488. }
  15489. function appplyRadius( radius ) {
  15490. var vertex = new Vector3();
  15491. // iterate over the entire buffer and apply the radius to each vertex
  15492. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15493. vertex.x = vertexBuffer[ i + 0 ];
  15494. vertex.y = vertexBuffer[ i + 1 ];
  15495. vertex.z = vertexBuffer[ i + 2 ];
  15496. vertex.normalize().multiplyScalar( radius );
  15497. vertexBuffer[ i + 0 ] = vertex.x;
  15498. vertexBuffer[ i + 1 ] = vertex.y;
  15499. vertexBuffer[ i + 2 ] = vertex.z;
  15500. }
  15501. }
  15502. function generateUVs() {
  15503. var vertex = new Vector3();
  15504. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15505. vertex.x = vertexBuffer[ i + 0 ];
  15506. vertex.y = vertexBuffer[ i + 1 ];
  15507. vertex.z = vertexBuffer[ i + 2 ];
  15508. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  15509. var v = inclination( vertex ) / Math.PI + 0.5;
  15510. uvBuffer.push( u, 1 - v );
  15511. }
  15512. correctUVs();
  15513. correctSeam();
  15514. }
  15515. function correctSeam() {
  15516. // handle case when face straddles the seam, see #3269
  15517. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  15518. // uv data of a single face
  15519. var x0 = uvBuffer[ i + 0 ];
  15520. var x1 = uvBuffer[ i + 2 ];
  15521. var x2 = uvBuffer[ i + 4 ];
  15522. var max = Math.max( x0, x1, x2 );
  15523. var min = Math.min( x0, x1, x2 );
  15524. // 0.9 is somewhat arbitrary
  15525. if ( max > 0.9 && min < 0.1 ) {
  15526. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  15527. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  15528. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  15529. }
  15530. }
  15531. }
  15532. function pushVertex( vertex ) {
  15533. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  15534. }
  15535. function getVertexByIndex( index, vertex ) {
  15536. var stride = index * 3;
  15537. vertex.x = vertices[ stride + 0 ];
  15538. vertex.y = vertices[ stride + 1 ];
  15539. vertex.z = vertices[ stride + 2 ];
  15540. }
  15541. function correctUVs() {
  15542. var a = new Vector3();
  15543. var b = new Vector3();
  15544. var c = new Vector3();
  15545. var centroid = new Vector3();
  15546. var uvA = new Vector2();
  15547. var uvB = new Vector2();
  15548. var uvC = new Vector2();
  15549. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  15550. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  15551. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  15552. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  15553. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  15554. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  15555. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  15556. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  15557. var azi = azimuth( centroid );
  15558. correctUV( uvA, j + 0, a, azi );
  15559. correctUV( uvB, j + 2, b, azi );
  15560. correctUV( uvC, j + 4, c, azi );
  15561. }
  15562. }
  15563. function correctUV( uv, stride, vector, azimuth ) {
  15564. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  15565. uvBuffer[ stride ] = uv.x - 1;
  15566. }
  15567. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  15568. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  15569. }
  15570. }
  15571. // Angle around the Y axis, counter-clockwise when looking from above.
  15572. function azimuth( vector ) {
  15573. return Math.atan2( vector.z, - vector.x );
  15574. }
  15575. // Angle above the XZ plane.
  15576. function inclination( vector ) {
  15577. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  15578. }
  15579. }
  15580. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15581. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  15582. /**
  15583. * @author timothypratley / https://github.com/timothypratley
  15584. * @author Mugen87 / https://github.com/Mugen87
  15585. */
  15586. // TetrahedronGeometry
  15587. function TetrahedronGeometry( radius, detail ) {
  15588. Geometry.call( this );
  15589. this.type = 'TetrahedronGeometry';
  15590. this.parameters = {
  15591. radius: radius,
  15592. detail: detail
  15593. };
  15594. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  15595. this.mergeVertices();
  15596. }
  15597. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  15598. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  15599. // TetrahedronBufferGeometry
  15600. function TetrahedronBufferGeometry( radius, detail ) {
  15601. var vertices = [
  15602. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  15603. ];
  15604. var indices = [
  15605. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  15606. ];
  15607. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15608. this.type = 'TetrahedronBufferGeometry';
  15609. this.parameters = {
  15610. radius: radius,
  15611. detail: detail
  15612. };
  15613. }
  15614. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15615. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  15616. /**
  15617. * @author timothypratley / https://github.com/timothypratley
  15618. * @author Mugen87 / https://github.com/Mugen87
  15619. */
  15620. // OctahedronGeometry
  15621. function OctahedronGeometry( radius, detail ) {
  15622. Geometry.call( this );
  15623. this.type = 'OctahedronGeometry';
  15624. this.parameters = {
  15625. radius: radius,
  15626. detail: detail
  15627. };
  15628. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  15629. this.mergeVertices();
  15630. }
  15631. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  15632. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  15633. // OctahedronBufferGeometry
  15634. function OctahedronBufferGeometry( radius, detail ) {
  15635. var vertices = [
  15636. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  15637. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  15638. ];
  15639. var indices = [
  15640. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  15641. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  15642. 1, 3, 4, 1, 4, 2
  15643. ];
  15644. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15645. this.type = 'OctahedronBufferGeometry';
  15646. this.parameters = {
  15647. radius: radius,
  15648. detail: detail
  15649. };
  15650. }
  15651. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15652. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  15653. /**
  15654. * @author timothypratley / https://github.com/timothypratley
  15655. * @author Mugen87 / https://github.com/Mugen87
  15656. */
  15657. // IcosahedronGeometry
  15658. function IcosahedronGeometry( radius, detail ) {
  15659. Geometry.call( this );
  15660. this.type = 'IcosahedronGeometry';
  15661. this.parameters = {
  15662. radius: radius,
  15663. detail: detail
  15664. };
  15665. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  15666. this.mergeVertices();
  15667. }
  15668. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  15669. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  15670. // IcosahedronBufferGeometry
  15671. function IcosahedronBufferGeometry( radius, detail ) {
  15672. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15673. var vertices = [
  15674. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  15675. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  15676. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  15677. ];
  15678. var indices = [
  15679. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  15680. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  15681. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  15682. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  15683. ];
  15684. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15685. this.type = 'IcosahedronBufferGeometry';
  15686. this.parameters = {
  15687. radius: radius,
  15688. detail: detail
  15689. };
  15690. }
  15691. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15692. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  15693. /**
  15694. * @author Abe Pazos / https://hamoid.com
  15695. * @author Mugen87 / https://github.com/Mugen87
  15696. */
  15697. // DodecahedronGeometry
  15698. function DodecahedronGeometry( radius, detail ) {
  15699. Geometry.call( this );
  15700. this.type = 'DodecahedronGeometry';
  15701. this.parameters = {
  15702. radius: radius,
  15703. detail: detail
  15704. };
  15705. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  15706. this.mergeVertices();
  15707. }
  15708. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  15709. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  15710. // DodecahedronBufferGeometry
  15711. function DodecahedronBufferGeometry( radius, detail ) {
  15712. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15713. var r = 1 / t;
  15714. var vertices = [
  15715. // (±1, ±1, ±1)
  15716. - 1, - 1, - 1, - 1, - 1, 1,
  15717. - 1, 1, - 1, - 1, 1, 1,
  15718. 1, - 1, - 1, 1, - 1, 1,
  15719. 1, 1, - 1, 1, 1, 1,
  15720. // (0, ±1/φ, ±φ)
  15721. 0, - r, - t, 0, - r, t,
  15722. 0, r, - t, 0, r, t,
  15723. // (±1/φ, ±φ, 0)
  15724. - r, - t, 0, - r, t, 0,
  15725. r, - t, 0, r, t, 0,
  15726. // (±φ, 0, ±1/φ)
  15727. - t, 0, - r, t, 0, - r,
  15728. - t, 0, r, t, 0, r
  15729. ];
  15730. var indices = [
  15731. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  15732. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  15733. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  15734. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  15735. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  15736. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  15737. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  15738. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  15739. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  15740. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  15741. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  15742. 1, 12, 14, 1, 14, 5, 1, 5, 9
  15743. ];
  15744. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15745. this.type = 'DodecahedronBufferGeometry';
  15746. this.parameters = {
  15747. radius: radius,
  15748. detail: detail
  15749. };
  15750. }
  15751. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15752. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  15753. /**
  15754. * @author oosmoxiecode / https://github.com/oosmoxiecode
  15755. * @author WestLangley / https://github.com/WestLangley
  15756. * @author zz85 / https://github.com/zz85
  15757. * @author miningold / https://github.com/miningold
  15758. * @author jonobr1 / https://github.com/jonobr1
  15759. * @author Mugen87 / https://github.com/Mugen87
  15760. *
  15761. */
  15762. // TubeGeometry
  15763. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  15764. Geometry.call( this );
  15765. this.type = 'TubeGeometry';
  15766. this.parameters = {
  15767. path: path,
  15768. tubularSegments: tubularSegments,
  15769. radius: radius,
  15770. radialSegments: radialSegments,
  15771. closed: closed
  15772. };
  15773. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  15774. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  15775. // expose internals
  15776. this.tangents = bufferGeometry.tangents;
  15777. this.normals = bufferGeometry.normals;
  15778. this.binormals = bufferGeometry.binormals;
  15779. // create geometry
  15780. this.fromBufferGeometry( bufferGeometry );
  15781. this.mergeVertices();
  15782. }
  15783. TubeGeometry.prototype = Object.create( Geometry.prototype );
  15784. TubeGeometry.prototype.constructor = TubeGeometry;
  15785. // TubeBufferGeometry
  15786. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  15787. BufferGeometry.call( this );
  15788. this.type = 'TubeBufferGeometry';
  15789. this.parameters = {
  15790. path: path,
  15791. tubularSegments: tubularSegments,
  15792. radius: radius,
  15793. radialSegments: radialSegments,
  15794. closed: closed
  15795. };
  15796. tubularSegments = tubularSegments || 64;
  15797. radius = radius || 1;
  15798. radialSegments = radialSegments || 8;
  15799. closed = closed || false;
  15800. var frames = path.computeFrenetFrames( tubularSegments, closed );
  15801. // expose internals
  15802. this.tangents = frames.tangents;
  15803. this.normals = frames.normals;
  15804. this.binormals = frames.binormals;
  15805. // helper variables
  15806. var vertex = new Vector3();
  15807. var normal = new Vector3();
  15808. var uv = new Vector2();
  15809. var P = new Vector3();
  15810. var i, j;
  15811. // buffer
  15812. var vertices = [];
  15813. var normals = [];
  15814. var uvs = [];
  15815. var indices = [];
  15816. // create buffer data
  15817. generateBufferData();
  15818. // build geometry
  15819. this.setIndex( indices );
  15820. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15821. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15822. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15823. // functions
  15824. function generateBufferData() {
  15825. for ( i = 0; i < tubularSegments; i ++ ) {
  15826. generateSegment( i );
  15827. }
  15828. // if the geometry is not closed, generate the last row of vertices and normals
  15829. // at the regular position on the given path
  15830. //
  15831. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  15832. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  15833. // uvs are generated in a separate function.
  15834. // this makes it easy compute correct values for closed geometries
  15835. generateUVs();
  15836. // finally create faces
  15837. generateIndices();
  15838. }
  15839. function generateSegment( i ) {
  15840. // we use getPointAt to sample evenly distributed points from the given path
  15841. P = path.getPointAt( i / tubularSegments, P );
  15842. // retrieve corresponding normal and binormal
  15843. var N = frames.normals[ i ];
  15844. var B = frames.binormals[ i ];
  15845. // generate normals and vertices for the current segment
  15846. for ( j = 0; j <= radialSegments; j ++ ) {
  15847. var v = j / radialSegments * Math.PI * 2;
  15848. var sin = Math.sin( v );
  15849. var cos = - Math.cos( v );
  15850. // normal
  15851. normal.x = ( cos * N.x + sin * B.x );
  15852. normal.y = ( cos * N.y + sin * B.y );
  15853. normal.z = ( cos * N.z + sin * B.z );
  15854. normal.normalize();
  15855. normals.push( normal.x, normal.y, normal.z );
  15856. // vertex
  15857. vertex.x = P.x + radius * normal.x;
  15858. vertex.y = P.y + radius * normal.y;
  15859. vertex.z = P.z + radius * normal.z;
  15860. vertices.push( vertex.x, vertex.y, vertex.z );
  15861. }
  15862. }
  15863. function generateIndices() {
  15864. for ( j = 1; j <= tubularSegments; j ++ ) {
  15865. for ( i = 1; i <= radialSegments; i ++ ) {
  15866. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15867. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15868. var c = ( radialSegments + 1 ) * j + i;
  15869. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15870. // faces
  15871. indices.push( a, b, d );
  15872. indices.push( b, c, d );
  15873. }
  15874. }
  15875. }
  15876. function generateUVs() {
  15877. for ( i = 0; i <= tubularSegments; i ++ ) {
  15878. for ( j = 0; j <= radialSegments; j ++ ) {
  15879. uv.x = i / tubularSegments;
  15880. uv.y = j / radialSegments;
  15881. uvs.push( uv.x, uv.y );
  15882. }
  15883. }
  15884. }
  15885. }
  15886. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15887. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  15888. /**
  15889. * @author oosmoxiecode
  15890. * @author Mugen87 / https://github.com/Mugen87
  15891. *
  15892. * based on http://www.blackpawn.com/texts/pqtorus/
  15893. */
  15894. // TorusKnotGeometry
  15895. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  15896. Geometry.call( this );
  15897. this.type = 'TorusKnotGeometry';
  15898. this.parameters = {
  15899. radius: radius,
  15900. tube: tube,
  15901. tubularSegments: tubularSegments,
  15902. radialSegments: radialSegments,
  15903. p: p,
  15904. q: q
  15905. };
  15906. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  15907. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  15908. this.mergeVertices();
  15909. }
  15910. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  15911. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  15912. // TorusKnotBufferGeometry
  15913. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  15914. BufferGeometry.call( this );
  15915. this.type = 'TorusKnotBufferGeometry';
  15916. this.parameters = {
  15917. radius: radius,
  15918. tube: tube,
  15919. tubularSegments: tubularSegments,
  15920. radialSegments: radialSegments,
  15921. p: p,
  15922. q: q
  15923. };
  15924. radius = radius || 1;
  15925. tube = tube || 0.4;
  15926. tubularSegments = Math.floor( tubularSegments ) || 64;
  15927. radialSegments = Math.floor( radialSegments ) || 8;
  15928. p = p || 2;
  15929. q = q || 3;
  15930. // buffers
  15931. var indices = [];
  15932. var vertices = [];
  15933. var normals = [];
  15934. var uvs = [];
  15935. // helper variables
  15936. var i, j;
  15937. var vertex = new Vector3();
  15938. var normal = new Vector3();
  15939. var P1 = new Vector3();
  15940. var P2 = new Vector3();
  15941. var B = new Vector3();
  15942. var T = new Vector3();
  15943. var N = new Vector3();
  15944. // generate vertices, normals and uvs
  15945. for ( i = 0; i <= tubularSegments; ++ i ) {
  15946. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  15947. var u = i / tubularSegments * p * Math.PI * 2;
  15948. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  15949. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  15950. calculatePositionOnCurve( u, p, q, radius, P1 );
  15951. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  15952. // calculate orthonormal basis
  15953. T.subVectors( P2, P1 );
  15954. N.addVectors( P2, P1 );
  15955. B.crossVectors( T, N );
  15956. N.crossVectors( B, T );
  15957. // normalize B, N. T can be ignored, we don't use it
  15958. B.normalize();
  15959. N.normalize();
  15960. for ( j = 0; j <= radialSegments; ++ j ) {
  15961. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  15962. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  15963. var v = j / radialSegments * Math.PI * 2;
  15964. var cx = - tube * Math.cos( v );
  15965. var cy = tube * Math.sin( v );
  15966. // now calculate the final vertex position.
  15967. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  15968. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  15969. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  15970. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  15971. vertices.push( vertex.x, vertex.y, vertex.z );
  15972. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  15973. normal.subVectors( vertex, P1 ).normalize();
  15974. normals.push( normal.x, normal.y, normal.z );
  15975. // uv
  15976. uvs.push( i / tubularSegments );
  15977. uvs.push( j / radialSegments );
  15978. }
  15979. }
  15980. // generate indices
  15981. for ( j = 1; j <= tubularSegments; j ++ ) {
  15982. for ( i = 1; i <= radialSegments; i ++ ) {
  15983. // indices
  15984. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15985. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15986. var c = ( radialSegments + 1 ) * j + i;
  15987. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15988. // faces
  15989. indices.push( a, b, d );
  15990. indices.push( b, c, d );
  15991. }
  15992. }
  15993. // build geometry
  15994. this.setIndex( indices );
  15995. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15996. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15997. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15998. // this function calculates the current position on the torus curve
  15999. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16000. var cu = Math.cos( u );
  16001. var su = Math.sin( u );
  16002. var quOverP = q / p * u;
  16003. var cs = Math.cos( quOverP );
  16004. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16005. position.y = radius * ( 2 + cs ) * su * 0.5;
  16006. position.z = radius * Math.sin( quOverP ) * 0.5;
  16007. }
  16008. }
  16009. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16010. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16011. /**
  16012. * @author oosmoxiecode
  16013. * @author mrdoob / http://mrdoob.com/
  16014. * @author Mugen87 / https://github.com/Mugen87
  16015. */
  16016. // TorusGeometry
  16017. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16018. Geometry.call( this );
  16019. this.type = 'TorusGeometry';
  16020. this.parameters = {
  16021. radius: radius,
  16022. tube: tube,
  16023. radialSegments: radialSegments,
  16024. tubularSegments: tubularSegments,
  16025. arc: arc
  16026. };
  16027. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16028. this.mergeVertices();
  16029. }
  16030. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16031. TorusGeometry.prototype.constructor = TorusGeometry;
  16032. // TorusBufferGeometry
  16033. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16034. BufferGeometry.call( this );
  16035. this.type = 'TorusBufferGeometry';
  16036. this.parameters = {
  16037. radius: radius,
  16038. tube: tube,
  16039. radialSegments: radialSegments,
  16040. tubularSegments: tubularSegments,
  16041. arc: arc
  16042. };
  16043. radius = radius || 1;
  16044. tube = tube || 0.4;
  16045. radialSegments = Math.floor( radialSegments ) || 8;
  16046. tubularSegments = Math.floor( tubularSegments ) || 6;
  16047. arc = arc || Math.PI * 2;
  16048. // buffers
  16049. var indices = [];
  16050. var vertices = [];
  16051. var normals = [];
  16052. var uvs = [];
  16053. // helper variables
  16054. var center = new Vector3();
  16055. var vertex = new Vector3();
  16056. var normal = new Vector3();
  16057. var j, i;
  16058. // generate vertices, normals and uvs
  16059. for ( j = 0; j <= radialSegments; j ++ ) {
  16060. for ( i = 0; i <= tubularSegments; i ++ ) {
  16061. var u = i / tubularSegments * arc;
  16062. var v = j / radialSegments * Math.PI * 2;
  16063. // vertex
  16064. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16065. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16066. vertex.z = tube * Math.sin( v );
  16067. vertices.push( vertex.x, vertex.y, vertex.z );
  16068. // normal
  16069. center.x = radius * Math.cos( u );
  16070. center.y = radius * Math.sin( u );
  16071. normal.subVectors( vertex, center ).normalize();
  16072. normals.push( normal.x, normal.y, normal.z );
  16073. // uv
  16074. uvs.push( i / tubularSegments );
  16075. uvs.push( j / radialSegments );
  16076. }
  16077. }
  16078. // generate indices
  16079. for ( j = 1; j <= radialSegments; j ++ ) {
  16080. for ( i = 1; i <= tubularSegments; i ++ ) {
  16081. // indices
  16082. var a = ( tubularSegments + 1 ) * j + i - 1;
  16083. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16084. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16085. var d = ( tubularSegments + 1 ) * j + i;
  16086. // faces
  16087. indices.push( a, b, d );
  16088. indices.push( b, c, d );
  16089. }
  16090. }
  16091. // build geometry
  16092. this.setIndex( indices );
  16093. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16094. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16095. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16096. }
  16097. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16098. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16099. /**
  16100. * @author Mugen87 / https://github.com/Mugen87
  16101. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16102. */
  16103. var Earcut = {
  16104. triangulate: function ( data, holeIndices, dim ) {
  16105. dim = dim || 2;
  16106. var hasHoles = holeIndices && holeIndices.length,
  16107. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16108. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16109. triangles = [];
  16110. if ( ! outerNode ) return triangles;
  16111. var minX, minY, maxX, maxY, x, y, invSize;
  16112. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16113. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16114. if ( data.length > 80 * dim ) {
  16115. minX = maxX = data[ 0 ];
  16116. minY = maxY = data[ 1 ];
  16117. for ( var i = dim; i < outerLen; i += dim ) {
  16118. x = data[ i ];
  16119. y = data[ i + 1 ];
  16120. if ( x < minX ) minX = x;
  16121. if ( y < minY ) minY = y;
  16122. if ( x > maxX ) maxX = x;
  16123. if ( y > maxY ) maxY = y;
  16124. }
  16125. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16126. invSize = Math.max( maxX - minX, maxY - minY );
  16127. invSize = invSize !== 0 ? 1 / invSize : 0;
  16128. }
  16129. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16130. return triangles;
  16131. }
  16132. };
  16133. // create a circular doubly linked list from polygon points in the specified winding order
  16134. function linkedList( data, start, end, dim, clockwise ) {
  16135. var i, last;
  16136. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16137. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16138. } else {
  16139. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16140. }
  16141. if ( last && equals( last, last.next ) ) {
  16142. removeNode( last );
  16143. last = last.next;
  16144. }
  16145. return last;
  16146. }
  16147. // eliminate colinear or duplicate points
  16148. function filterPoints( start, end ) {
  16149. if ( ! start ) return start;
  16150. if ( ! end ) end = start;
  16151. var p = start, again;
  16152. do {
  16153. again = false;
  16154. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16155. removeNode( p );
  16156. p = end = p.prev;
  16157. if ( p === p.next ) break;
  16158. again = true;
  16159. } else {
  16160. p = p.next;
  16161. }
  16162. } while ( again || p !== end );
  16163. return end;
  16164. }
  16165. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16166. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16167. if ( ! ear ) return;
  16168. // interlink polygon nodes in z-order
  16169. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16170. var stop = ear, prev, next;
  16171. // iterate through ears, slicing them one by one
  16172. while ( ear.prev !== ear.next ) {
  16173. prev = ear.prev;
  16174. next = ear.next;
  16175. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16176. // cut off the triangle
  16177. triangles.push( prev.i / dim );
  16178. triangles.push( ear.i / dim );
  16179. triangles.push( next.i / dim );
  16180. removeNode( ear );
  16181. // skipping the next vertice leads to less sliver triangles
  16182. ear = next.next;
  16183. stop = next.next;
  16184. continue;
  16185. }
  16186. ear = next;
  16187. // if we looped through the whole remaining polygon and can't find any more ears
  16188. if ( ear === stop ) {
  16189. // try filtering points and slicing again
  16190. if ( ! pass ) {
  16191. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16192. // if this didn't work, try curing all small self-intersections locally
  16193. } else if ( pass === 1 ) {
  16194. ear = cureLocalIntersections( ear, triangles, dim );
  16195. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16196. // as a last resort, try splitting the remaining polygon into two
  16197. } else if ( pass === 2 ) {
  16198. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16199. }
  16200. break;
  16201. }
  16202. }
  16203. }
  16204. // check whether a polygon node forms a valid ear with adjacent nodes
  16205. function isEar( ear ) {
  16206. var a = ear.prev,
  16207. b = ear,
  16208. c = ear.next;
  16209. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16210. // now make sure we don't have other points inside the potential ear
  16211. var p = ear.next.next;
  16212. while ( p !== ear.prev ) {
  16213. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) {
  16214. return false;
  16215. }
  16216. p = p.next;
  16217. }
  16218. return true;
  16219. }
  16220. function isEarHashed( ear, minX, minY, invSize ) {
  16221. var a = ear.prev,
  16222. b = ear,
  16223. c = ear.next;
  16224. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16225. // triangle bbox; min & max are calculated like this for speed
  16226. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  16227. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  16228. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  16229. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  16230. // z-order range for the current triangle bbox;
  16231. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  16232. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  16233. // first look for points inside the triangle in increasing z-order
  16234. var p = ear.nextZ;
  16235. while ( p && p.z <= maxZ ) {
  16236. if ( p !== ear.prev && p !== ear.next &&
  16237. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16238. area( p.prev, p, p.next ) >= 0 ) return false;
  16239. p = p.nextZ;
  16240. }
  16241. // then look for points in decreasing z-order
  16242. p = ear.prevZ;
  16243. while ( p && p.z >= minZ ) {
  16244. if ( p !== ear.prev && p !== ear.next &&
  16245. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16246. area( p.prev, p, p.next ) >= 0 ) return false;
  16247. p = p.prevZ;
  16248. }
  16249. return true;
  16250. }
  16251. // go through all polygon nodes and cure small local self-intersections
  16252. function cureLocalIntersections( start, triangles, dim ) {
  16253. var p = start;
  16254. do {
  16255. var a = p.prev, b = p.next.next;
  16256. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  16257. triangles.push( a.i / dim );
  16258. triangles.push( p.i / dim );
  16259. triangles.push( b.i / dim );
  16260. // remove two nodes involved
  16261. removeNode( p );
  16262. removeNode( p.next );
  16263. p = start = b;
  16264. }
  16265. p = p.next;
  16266. } while ( p !== start );
  16267. return p;
  16268. }
  16269. // try splitting polygon into two and triangulate them independently
  16270. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  16271. // look for a valid diagonal that divides the polygon into two
  16272. var a = start;
  16273. do {
  16274. var b = a.next.next;
  16275. while ( b !== a.prev ) {
  16276. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  16277. // split the polygon in two by the diagonal
  16278. var c = splitPolygon( a, b );
  16279. // filter colinear points around the cuts
  16280. a = filterPoints( a, a.next );
  16281. c = filterPoints( c, c.next );
  16282. // run earcut on each half
  16283. earcutLinked( a, triangles, dim, minX, minY, invSize );
  16284. earcutLinked( c, triangles, dim, minX, minY, invSize );
  16285. return;
  16286. }
  16287. b = b.next;
  16288. }
  16289. a = a.next;
  16290. } while ( a !== start );
  16291. }
  16292. // link every hole into the outer loop, producing a single-ring polygon without holes
  16293. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  16294. var queue = [], i, len, start, end, list;
  16295. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  16296. start = holeIndices[ i ] * dim;
  16297. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  16298. list = linkedList( data, start, end, dim, false );
  16299. if ( list === list.next ) list.steiner = true;
  16300. queue.push( getLeftmost( list ) );
  16301. }
  16302. queue.sort( compareX );
  16303. // process holes from left to right
  16304. for ( i = 0; i < queue.length; i ++ ) {
  16305. eliminateHole( queue[ i ], outerNode );
  16306. outerNode = filterPoints( outerNode, outerNode.next );
  16307. }
  16308. return outerNode;
  16309. }
  16310. function compareX( a, b ) {
  16311. return a.x - b.x;
  16312. }
  16313. // find a bridge between vertices that connects hole with an outer ring and and link it
  16314. function eliminateHole( hole, outerNode ) {
  16315. outerNode = findHoleBridge( hole, outerNode );
  16316. if ( outerNode ) {
  16317. var b = splitPolygon( outerNode, hole );
  16318. filterPoints( b, b.next );
  16319. }
  16320. }
  16321. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  16322. function findHoleBridge( hole, outerNode ) {
  16323. var p = outerNode,
  16324. hx = hole.x,
  16325. hy = hole.y,
  16326. qx = - Infinity,
  16327. m;
  16328. // find a segment intersected by a ray from the hole's leftmost point to the left;
  16329. // segment's endpoint with lesser x will be potential connection point
  16330. do {
  16331. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  16332. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  16333. if ( x <= hx && x > qx ) {
  16334. qx = x;
  16335. if ( x === hx ) {
  16336. if ( hy === p.y ) return p;
  16337. if ( hy === p.next.y ) return p.next;
  16338. }
  16339. m = p.x < p.next.x ? p : p.next;
  16340. }
  16341. }
  16342. p = p.next;
  16343. } while ( p !== outerNode );
  16344. if ( ! m ) return null;
  16345. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  16346. // look for points inside the triangle of hole point, segment intersection and endpoint;
  16347. // if there are no points found, we have a valid connection;
  16348. // otherwise choose the point of the minimum angle with the ray as connection point
  16349. var stop = m,
  16350. mx = m.x,
  16351. my = m.y,
  16352. tanMin = Infinity,
  16353. tan;
  16354. p = m.next;
  16355. while ( p !== stop ) {
  16356. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  16357. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  16358. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  16359. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  16360. m = p;
  16361. tanMin = tan;
  16362. }
  16363. }
  16364. p = p.next;
  16365. }
  16366. return m;
  16367. }
  16368. // interlink polygon nodes in z-order
  16369. function indexCurve( start, minX, minY, invSize ) {
  16370. var p = start;
  16371. do {
  16372. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  16373. p.prevZ = p.prev;
  16374. p.nextZ = p.next;
  16375. p = p.next;
  16376. } while ( p !== start );
  16377. p.prevZ.nextZ = null;
  16378. p.prevZ = null;
  16379. sortLinked( p );
  16380. }
  16381. // Simon Tatham's linked list merge sort algorithm
  16382. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  16383. function sortLinked( list ) {
  16384. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  16385. do {
  16386. p = list;
  16387. list = null;
  16388. tail = null;
  16389. numMerges = 0;
  16390. while ( p ) {
  16391. numMerges ++;
  16392. q = p;
  16393. pSize = 0;
  16394. for ( i = 0; i < inSize; i ++ ) {
  16395. pSize ++;
  16396. q = q.nextZ;
  16397. if ( ! q ) break;
  16398. }
  16399. qSize = inSize;
  16400. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  16401. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  16402. e = p;
  16403. p = p.nextZ;
  16404. pSize --;
  16405. } else {
  16406. e = q;
  16407. q = q.nextZ;
  16408. qSize --;
  16409. }
  16410. if ( tail ) tail.nextZ = e;
  16411. else list = e;
  16412. e.prevZ = tail;
  16413. tail = e;
  16414. }
  16415. p = q;
  16416. }
  16417. tail.nextZ = null;
  16418. inSize *= 2;
  16419. } while ( numMerges > 1 );
  16420. return list;
  16421. }
  16422. // z-order of a point given coords and inverse of the longer side of data bbox
  16423. function zOrder( x, y, minX, minY, invSize ) {
  16424. // coords are transformed into non-negative 15-bit integer range
  16425. x = 32767 * ( x - minX ) * invSize;
  16426. y = 32767 * ( y - minY ) * invSize;
  16427. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  16428. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  16429. x = ( x | ( x << 2 ) ) & 0x33333333;
  16430. x = ( x | ( x << 1 ) ) & 0x55555555;
  16431. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  16432. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  16433. y = ( y | ( y << 2 ) ) & 0x33333333;
  16434. y = ( y | ( y << 1 ) ) & 0x55555555;
  16435. return x | ( y << 1 );
  16436. }
  16437. // find the leftmost node of a polygon ring
  16438. function getLeftmost( start ) {
  16439. var p = start, leftmost = start;
  16440. do {
  16441. if ( p.x < leftmost.x ) leftmost = p;
  16442. p = p.next;
  16443. } while ( p !== start );
  16444. return leftmost;
  16445. }
  16446. // check if a point lies within a convex triangle
  16447. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  16448. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  16449. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  16450. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  16451. }
  16452. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  16453. function isValidDiagonal( a, b ) {
  16454. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  16455. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  16456. }
  16457. // signed area of a triangle
  16458. function area( p, q, r ) {
  16459. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  16460. }
  16461. // check if two points are equal
  16462. function equals( p1, p2 ) {
  16463. return p1.x === p2.x && p1.y === p2.y;
  16464. }
  16465. // check if two segments intersect
  16466. function intersects( p1, q1, p2, q2 ) {
  16467. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  16468. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  16469. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  16470. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  16471. }
  16472. // check if a polygon diagonal intersects any polygon segments
  16473. function intersectsPolygon( a, b ) {
  16474. var p = a;
  16475. do {
  16476. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  16477. intersects( p, p.next, a, b ) ) {
  16478. return true;
  16479. }
  16480. p = p.next;
  16481. } while ( p !== a );
  16482. return false;
  16483. }
  16484. // check if a polygon diagonal is locally inside the polygon
  16485. function locallyInside( a, b ) {
  16486. return area( a.prev, a, a.next ) < 0 ?
  16487. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  16488. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  16489. }
  16490. // check if the middle point of a polygon diagonal is inside the polygon
  16491. function middleInside( a, b ) {
  16492. var p = a,
  16493. inside = false,
  16494. px = ( a.x + b.x ) / 2,
  16495. py = ( a.y + b.y ) / 2;
  16496. do {
  16497. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  16498. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  16499. inside = ! inside;
  16500. }
  16501. p = p.next;
  16502. } while ( p !== a );
  16503. return inside;
  16504. }
  16505. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  16506. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  16507. function splitPolygon( a, b ) {
  16508. var a2 = new Node( a.i, a.x, a.y ),
  16509. b2 = new Node( b.i, b.x, b.y ),
  16510. an = a.next,
  16511. bp = b.prev;
  16512. a.next = b;
  16513. b.prev = a;
  16514. a2.next = an;
  16515. an.prev = a2;
  16516. b2.next = a2;
  16517. a2.prev = b2;
  16518. bp.next = b2;
  16519. b2.prev = bp;
  16520. return b2;
  16521. }
  16522. // create a node and optionally link it with previous one (in a circular doubly linked list)
  16523. function insertNode( i, x, y, last ) {
  16524. var p = new Node( i, x, y );
  16525. if ( ! last ) {
  16526. p.prev = p;
  16527. p.next = p;
  16528. } else {
  16529. p.next = last.next;
  16530. p.prev = last;
  16531. last.next.prev = p;
  16532. last.next = p;
  16533. }
  16534. return p;
  16535. }
  16536. function removeNode( p ) {
  16537. p.next.prev = p.prev;
  16538. p.prev.next = p.next;
  16539. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  16540. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  16541. }
  16542. function Node( i, x, y ) {
  16543. // vertice index in coordinates array
  16544. this.i = i;
  16545. // vertex coordinates
  16546. this.x = x;
  16547. this.y = y;
  16548. // previous and next vertice nodes in a polygon ring
  16549. this.prev = null;
  16550. this.next = null;
  16551. // z-order curve value
  16552. this.z = null;
  16553. // previous and next nodes in z-order
  16554. this.prevZ = null;
  16555. this.nextZ = null;
  16556. // indicates whether this is a steiner point
  16557. this.steiner = false;
  16558. }
  16559. function signedArea( data, start, end, dim ) {
  16560. var sum = 0;
  16561. for ( var i = start, j = end - dim; i < end; i += dim ) {
  16562. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  16563. j = i;
  16564. }
  16565. return sum;
  16566. }
  16567. /**
  16568. * @author zz85 / http://www.lab4games.net/zz85/blog
  16569. */
  16570. var ShapeUtils = {
  16571. // calculate area of the contour polygon
  16572. area: function ( contour ) {
  16573. var n = contour.length;
  16574. var a = 0.0;
  16575. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16576. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16577. }
  16578. return a * 0.5;
  16579. },
  16580. isClockWise: function ( pts ) {
  16581. return ShapeUtils.area( pts ) < 0;
  16582. },
  16583. triangulateShape: function ( contour, holes ) {
  16584. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  16585. var holeIndices = []; // array of hole indices
  16586. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  16587. removeDupEndPts( contour );
  16588. addContour( vertices, contour );
  16589. //
  16590. var holeIndex = contour.length;
  16591. holes.forEach( removeDupEndPts );
  16592. for ( var i = 0; i < holes.length; i ++ ) {
  16593. holeIndices.push( holeIndex );
  16594. holeIndex += holes[ i ].length;
  16595. addContour( vertices, holes[ i ] );
  16596. }
  16597. //
  16598. var triangles = Earcut.triangulate( vertices, holeIndices );
  16599. //
  16600. for ( var i = 0; i < triangles.length; i += 3 ) {
  16601. faces.push( triangles.slice( i, i + 3 ) );
  16602. }
  16603. return faces;
  16604. }
  16605. };
  16606. function removeDupEndPts( points ) {
  16607. var l = points.length;
  16608. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  16609. points.pop();
  16610. }
  16611. }
  16612. function addContour( vertices, contour ) {
  16613. for ( var i = 0; i < contour.length; i ++ ) {
  16614. vertices.push( contour[ i ].x );
  16615. vertices.push( contour[ i ].y );
  16616. }
  16617. }
  16618. /**
  16619. * @author zz85 / http://www.lab4games.net/zz85/blog
  16620. *
  16621. * Creates extruded geometry from a path shape.
  16622. *
  16623. * parameters = {
  16624. *
  16625. * curveSegments: <int>, // number of points on the curves
  16626. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  16627. * depth: <float>, // Depth to extrude the shape
  16628. *
  16629. * bevelEnabled: <bool>, // turn on bevel
  16630. * bevelThickness: <float>, // how deep into the original shape bevel goes
  16631. * bevelSize: <float>, // how far from shape outline is bevel
  16632. * bevelSegments: <int>, // number of bevel layers
  16633. *
  16634. * extrudePath: <THREE.Curve> // curve to extrude shape along
  16635. *
  16636. * UVGenerator: <Object> // object that provides UV generator functions
  16637. *
  16638. * }
  16639. */
  16640. // ExtrudeGeometry
  16641. function ExtrudeGeometry( shapes, options ) {
  16642. Geometry.call( this );
  16643. this.type = 'ExtrudeGeometry';
  16644. this.parameters = {
  16645. shapes: shapes,
  16646. options: options
  16647. };
  16648. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  16649. this.mergeVertices();
  16650. }
  16651. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  16652. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  16653. // ExtrudeBufferGeometry
  16654. function ExtrudeBufferGeometry( shapes, options ) {
  16655. BufferGeometry.call( this );
  16656. this.type = 'ExtrudeBufferGeometry';
  16657. this.parameters = {
  16658. shapes: shapes,
  16659. options: options
  16660. };
  16661. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  16662. var scope = this;
  16663. var verticesArray = [];
  16664. var uvArray = [];
  16665. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  16666. var shape = shapes[ i ];
  16667. addShape( shape );
  16668. }
  16669. // build geometry
  16670. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  16671. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  16672. this.computeVertexNormals();
  16673. // functions
  16674. function addShape( shape ) {
  16675. var placeholder = [];
  16676. // options
  16677. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  16678. var steps = options.steps !== undefined ? options.steps : 1;
  16679. var depth = options.depth !== undefined ? options.depth : 100;
  16680. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  16681. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  16682. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  16683. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  16684. var extrudePath = options.extrudePath;
  16685. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  16686. // deprecated options
  16687. if ( options.amount !== undefined ) {
  16688. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  16689. depth = options.amount;
  16690. }
  16691. //
  16692. var extrudePts, extrudeByPath = false;
  16693. var splineTube, binormal, normal, position2;
  16694. if ( extrudePath ) {
  16695. extrudePts = extrudePath.getSpacedPoints( steps );
  16696. extrudeByPath = true;
  16697. bevelEnabled = false; // bevels not supported for path extrusion
  16698. // SETUP TNB variables
  16699. // TODO1 - have a .isClosed in spline?
  16700. splineTube = extrudePath.computeFrenetFrames( steps, false );
  16701. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  16702. binormal = new Vector3();
  16703. normal = new Vector3();
  16704. position2 = new Vector3();
  16705. }
  16706. // Safeguards if bevels are not enabled
  16707. if ( ! bevelEnabled ) {
  16708. bevelSegments = 0;
  16709. bevelThickness = 0;
  16710. bevelSize = 0;
  16711. }
  16712. // Variables initialization
  16713. var ahole, h, hl; // looping of holes
  16714. var shapePoints = shape.extractPoints( curveSegments );
  16715. var vertices = shapePoints.shape;
  16716. var holes = shapePoints.holes;
  16717. var reverse = ! ShapeUtils.isClockWise( vertices );
  16718. if ( reverse ) {
  16719. vertices = vertices.reverse();
  16720. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  16721. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16722. ahole = holes[ h ];
  16723. if ( ShapeUtils.isClockWise( ahole ) ) {
  16724. holes[ h ] = ahole.reverse();
  16725. }
  16726. }
  16727. }
  16728. var faces = ShapeUtils.triangulateShape( vertices, holes );
  16729. /* Vertices */
  16730. var contour = vertices; // vertices has all points but contour has only points of circumference
  16731. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16732. ahole = holes[ h ];
  16733. vertices = vertices.concat( ahole );
  16734. }
  16735. function scalePt2( pt, vec, size ) {
  16736. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  16737. return vec.clone().multiplyScalar( size ).add( pt );
  16738. }
  16739. var b, bs, t, z,
  16740. vert, vlen = vertices.length,
  16741. face, flen = faces.length;
  16742. // Find directions for point movement
  16743. function getBevelVec( inPt, inPrev, inNext ) {
  16744. // computes for inPt the corresponding point inPt' on a new contour
  16745. // shifted by 1 unit (length of normalized vector) to the left
  16746. // if we walk along contour clockwise, this new contour is outside the old one
  16747. //
  16748. // inPt' is the intersection of the two lines parallel to the two
  16749. // adjacent edges of inPt at a distance of 1 unit on the left side.
  16750. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  16751. // good reading for geometry algorithms (here: line-line intersection)
  16752. // http://geomalgorithms.com/a05-_intersect-1.html
  16753. var v_prev_x = inPt.x - inPrev.x,
  16754. v_prev_y = inPt.y - inPrev.y;
  16755. var v_next_x = inNext.x - inPt.x,
  16756. v_next_y = inNext.y - inPt.y;
  16757. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  16758. // check for collinear edges
  16759. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16760. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  16761. // not collinear
  16762. // length of vectors for normalizing
  16763. var v_prev_len = Math.sqrt( v_prev_lensq );
  16764. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  16765. // shift adjacent points by unit vectors to the left
  16766. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  16767. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  16768. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  16769. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  16770. // scaling factor for v_prev to intersection point
  16771. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  16772. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  16773. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16774. // vector from inPt to intersection point
  16775. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  16776. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  16777. // Don't normalize!, otherwise sharp corners become ugly
  16778. // but prevent crazy spikes
  16779. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  16780. if ( v_trans_lensq <= 2 ) {
  16781. return new Vector2( v_trans_x, v_trans_y );
  16782. } else {
  16783. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  16784. }
  16785. } else {
  16786. // handle special case of collinear edges
  16787. var direction_eq = false; // assumes: opposite
  16788. if ( v_prev_x > Number.EPSILON ) {
  16789. if ( v_next_x > Number.EPSILON ) {
  16790. direction_eq = true;
  16791. }
  16792. } else {
  16793. if ( v_prev_x < - Number.EPSILON ) {
  16794. if ( v_next_x < - Number.EPSILON ) {
  16795. direction_eq = true;
  16796. }
  16797. } else {
  16798. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  16799. direction_eq = true;
  16800. }
  16801. }
  16802. }
  16803. if ( direction_eq ) {
  16804. // console.log("Warning: lines are a straight sequence");
  16805. v_trans_x = - v_prev_y;
  16806. v_trans_y = v_prev_x;
  16807. shrink_by = Math.sqrt( v_prev_lensq );
  16808. } else {
  16809. // console.log("Warning: lines are a straight spike");
  16810. v_trans_x = v_prev_x;
  16811. v_trans_y = v_prev_y;
  16812. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  16813. }
  16814. }
  16815. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  16816. }
  16817. var contourMovements = [];
  16818. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16819. if ( j === il ) j = 0;
  16820. if ( k === il ) k = 0;
  16821. // (j)---(i)---(k)
  16822. // console.log('i,j,k', i, j , k)
  16823. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  16824. }
  16825. var holesMovements = [],
  16826. oneHoleMovements, verticesMovements = contourMovements.concat();
  16827. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16828. ahole = holes[ h ];
  16829. oneHoleMovements = [];
  16830. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16831. if ( j === il ) j = 0;
  16832. if ( k === il ) k = 0;
  16833. // (j)---(i)---(k)
  16834. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  16835. }
  16836. holesMovements.push( oneHoleMovements );
  16837. verticesMovements = verticesMovements.concat( oneHoleMovements );
  16838. }
  16839. // Loop bevelSegments, 1 for the front, 1 for the back
  16840. for ( b = 0; b < bevelSegments; b ++ ) {
  16841. //for ( b = bevelSegments; b > 0; b -- ) {
  16842. t = b / bevelSegments;
  16843. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16844. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16845. // contract shape
  16846. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16847. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16848. v( vert.x, vert.y, - z );
  16849. }
  16850. // expand holes
  16851. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16852. ahole = holes[ h ];
  16853. oneHoleMovements = holesMovements[ h ];
  16854. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16855. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16856. v( vert.x, vert.y, - z );
  16857. }
  16858. }
  16859. }
  16860. bs = bevelSize;
  16861. // Back facing vertices
  16862. for ( i = 0; i < vlen; i ++ ) {
  16863. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16864. if ( ! extrudeByPath ) {
  16865. v( vert.x, vert.y, 0 );
  16866. } else {
  16867. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  16868. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  16869. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  16870. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  16871. v( position2.x, position2.y, position2.z );
  16872. }
  16873. }
  16874. // Add stepped vertices...
  16875. // Including front facing vertices
  16876. var s;
  16877. for ( s = 1; s <= steps; s ++ ) {
  16878. for ( i = 0; i < vlen; i ++ ) {
  16879. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16880. if ( ! extrudeByPath ) {
  16881. v( vert.x, vert.y, depth / steps * s );
  16882. } else {
  16883. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  16884. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  16885. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  16886. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  16887. v( position2.x, position2.y, position2.z );
  16888. }
  16889. }
  16890. }
  16891. // Add bevel segments planes
  16892. //for ( b = 1; b <= bevelSegments; b ++ ) {
  16893. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  16894. t = b / bevelSegments;
  16895. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16896. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16897. // contract shape
  16898. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16899. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16900. v( vert.x, vert.y, depth + z );
  16901. }
  16902. // expand holes
  16903. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16904. ahole = holes[ h ];
  16905. oneHoleMovements = holesMovements[ h ];
  16906. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16907. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16908. if ( ! extrudeByPath ) {
  16909. v( vert.x, vert.y, depth + z );
  16910. } else {
  16911. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  16912. }
  16913. }
  16914. }
  16915. }
  16916. /* Faces */
  16917. // Top and bottom faces
  16918. buildLidFaces();
  16919. // Sides faces
  16920. buildSideFaces();
  16921. ///// Internal functions
  16922. function buildLidFaces() {
  16923. var start = verticesArray.length / 3;
  16924. if ( bevelEnabled ) {
  16925. var layer = 0; // steps + 1
  16926. var offset = vlen * layer;
  16927. // Bottom faces
  16928. for ( i = 0; i < flen; i ++ ) {
  16929. face = faces[ i ];
  16930. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  16931. }
  16932. layer = steps + bevelSegments * 2;
  16933. offset = vlen * layer;
  16934. // Top faces
  16935. for ( i = 0; i < flen; i ++ ) {
  16936. face = faces[ i ];
  16937. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  16938. }
  16939. } else {
  16940. // Bottom faces
  16941. for ( i = 0; i < flen; i ++ ) {
  16942. face = faces[ i ];
  16943. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  16944. }
  16945. // Top faces
  16946. for ( i = 0; i < flen; i ++ ) {
  16947. face = faces[ i ];
  16948. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  16949. }
  16950. }
  16951. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  16952. }
  16953. // Create faces for the z-sides of the shape
  16954. function buildSideFaces() {
  16955. var start = verticesArray.length / 3;
  16956. var layeroffset = 0;
  16957. sidewalls( contour, layeroffset );
  16958. layeroffset += contour.length;
  16959. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16960. ahole = holes[ h ];
  16961. sidewalls( ahole, layeroffset );
  16962. //, true
  16963. layeroffset += ahole.length;
  16964. }
  16965. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  16966. }
  16967. function sidewalls( contour, layeroffset ) {
  16968. var j, k;
  16969. i = contour.length;
  16970. while ( -- i >= 0 ) {
  16971. j = i;
  16972. k = i - 1;
  16973. if ( k < 0 ) k = contour.length - 1;
  16974. //console.log('b', i,j, i-1, k,vertices.length);
  16975. var s = 0,
  16976. sl = steps + bevelSegments * 2;
  16977. for ( s = 0; s < sl; s ++ ) {
  16978. var slen1 = vlen * s;
  16979. var slen2 = vlen * ( s + 1 );
  16980. var a = layeroffset + j + slen1,
  16981. b = layeroffset + k + slen1,
  16982. c = layeroffset + k + slen2,
  16983. d = layeroffset + j + slen2;
  16984. f4( a, b, c, d );
  16985. }
  16986. }
  16987. }
  16988. function v( x, y, z ) {
  16989. placeholder.push( x );
  16990. placeholder.push( y );
  16991. placeholder.push( z );
  16992. }
  16993. function f3( a, b, c ) {
  16994. addVertex( a );
  16995. addVertex( b );
  16996. addVertex( c );
  16997. var nextIndex = verticesArray.length / 3;
  16998. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16999. addUV( uvs[ 0 ] );
  17000. addUV( uvs[ 1 ] );
  17001. addUV( uvs[ 2 ] );
  17002. }
  17003. function f4( a, b, c, d ) {
  17004. addVertex( a );
  17005. addVertex( b );
  17006. addVertex( d );
  17007. addVertex( b );
  17008. addVertex( c );
  17009. addVertex( d );
  17010. var nextIndex = verticesArray.length / 3;
  17011. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17012. addUV( uvs[ 0 ] );
  17013. addUV( uvs[ 1 ] );
  17014. addUV( uvs[ 3 ] );
  17015. addUV( uvs[ 1 ] );
  17016. addUV( uvs[ 2 ] );
  17017. addUV( uvs[ 3 ] );
  17018. }
  17019. function addVertex( index ) {
  17020. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17021. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17022. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17023. }
  17024. function addUV( vector2 ) {
  17025. uvArray.push( vector2.x );
  17026. uvArray.push( vector2.y );
  17027. }
  17028. }
  17029. }
  17030. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17031. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17032. var WorldUVGenerator = {
  17033. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17034. var a_x = vertices[ indexA * 3 ];
  17035. var a_y = vertices[ indexA * 3 + 1 ];
  17036. var b_x = vertices[ indexB * 3 ];
  17037. var b_y = vertices[ indexB * 3 + 1 ];
  17038. var c_x = vertices[ indexC * 3 ];
  17039. var c_y = vertices[ indexC * 3 + 1 ];
  17040. return [
  17041. new Vector2( a_x, a_y ),
  17042. new Vector2( b_x, b_y ),
  17043. new Vector2( c_x, c_y )
  17044. ];
  17045. },
  17046. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17047. var a_x = vertices[ indexA * 3 ];
  17048. var a_y = vertices[ indexA * 3 + 1 ];
  17049. var a_z = vertices[ indexA * 3 + 2 ];
  17050. var b_x = vertices[ indexB * 3 ];
  17051. var b_y = vertices[ indexB * 3 + 1 ];
  17052. var b_z = vertices[ indexB * 3 + 2 ];
  17053. var c_x = vertices[ indexC * 3 ];
  17054. var c_y = vertices[ indexC * 3 + 1 ];
  17055. var c_z = vertices[ indexC * 3 + 2 ];
  17056. var d_x = vertices[ indexD * 3 ];
  17057. var d_y = vertices[ indexD * 3 + 1 ];
  17058. var d_z = vertices[ indexD * 3 + 2 ];
  17059. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17060. return [
  17061. new Vector2( a_x, 1 - a_z ),
  17062. new Vector2( b_x, 1 - b_z ),
  17063. new Vector2( c_x, 1 - c_z ),
  17064. new Vector2( d_x, 1 - d_z )
  17065. ];
  17066. } else {
  17067. return [
  17068. new Vector2( a_y, 1 - a_z ),
  17069. new Vector2( b_y, 1 - b_z ),
  17070. new Vector2( c_y, 1 - c_z ),
  17071. new Vector2( d_y, 1 - d_z )
  17072. ];
  17073. }
  17074. }
  17075. };
  17076. /**
  17077. * @author zz85 / http://www.lab4games.net/zz85/blog
  17078. * @author alteredq / http://alteredqualia.com/
  17079. *
  17080. * Text = 3D Text
  17081. *
  17082. * parameters = {
  17083. * font: <THREE.Font>, // font
  17084. *
  17085. * size: <float>, // size of the text
  17086. * height: <float>, // thickness to extrude text
  17087. * curveSegments: <int>, // number of points on the curves
  17088. *
  17089. * bevelEnabled: <bool>, // turn on bevel
  17090. * bevelThickness: <float>, // how deep into text bevel goes
  17091. * bevelSize: <float> // how far from text outline is bevel
  17092. * }
  17093. */
  17094. // TextGeometry
  17095. function TextGeometry( text, parameters ) {
  17096. Geometry.call( this );
  17097. this.type = 'TextGeometry';
  17098. this.parameters = {
  17099. text: text,
  17100. parameters: parameters
  17101. };
  17102. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17103. this.mergeVertices();
  17104. }
  17105. TextGeometry.prototype = Object.create( Geometry.prototype );
  17106. TextGeometry.prototype.constructor = TextGeometry;
  17107. // TextBufferGeometry
  17108. function TextBufferGeometry( text, parameters ) {
  17109. parameters = parameters || {};
  17110. var font = parameters.font;
  17111. if ( ! ( font && font.isFont ) ) {
  17112. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17113. return new Geometry();
  17114. }
  17115. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  17116. // translate parameters to ExtrudeGeometry API
  17117. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17118. // defaults
  17119. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17120. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17121. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17122. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17123. this.type = 'TextBufferGeometry';
  17124. }
  17125. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17126. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17127. /**
  17128. * @author mrdoob / http://mrdoob.com/
  17129. * @author benaadams / https://twitter.com/ben_a_adams
  17130. * @author Mugen87 / https://github.com/Mugen87
  17131. */
  17132. // SphereGeometry
  17133. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17134. Geometry.call( this );
  17135. this.type = 'SphereGeometry';
  17136. this.parameters = {
  17137. radius: radius,
  17138. widthSegments: widthSegments,
  17139. heightSegments: heightSegments,
  17140. phiStart: phiStart,
  17141. phiLength: phiLength,
  17142. thetaStart: thetaStart,
  17143. thetaLength: thetaLength
  17144. };
  17145. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17146. this.mergeVertices();
  17147. }
  17148. SphereGeometry.prototype = Object.create( Geometry.prototype );
  17149. SphereGeometry.prototype.constructor = SphereGeometry;
  17150. // SphereBufferGeometry
  17151. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17152. BufferGeometry.call( this );
  17153. this.type = 'SphereBufferGeometry';
  17154. this.parameters = {
  17155. radius: radius,
  17156. widthSegments: widthSegments,
  17157. heightSegments: heightSegments,
  17158. phiStart: phiStart,
  17159. phiLength: phiLength,
  17160. thetaStart: thetaStart,
  17161. thetaLength: thetaLength
  17162. };
  17163. radius = radius || 1;
  17164. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17165. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17166. phiStart = phiStart !== undefined ? phiStart : 0;
  17167. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  17168. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17169. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  17170. var thetaEnd = thetaStart + thetaLength;
  17171. var ix, iy;
  17172. var index = 0;
  17173. var grid = [];
  17174. var vertex = new Vector3();
  17175. var normal = new Vector3();
  17176. // buffers
  17177. var indices = [];
  17178. var vertices = [];
  17179. var normals = [];
  17180. var uvs = [];
  17181. // generate vertices, normals and uvs
  17182. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  17183. var verticesRow = [];
  17184. var v = iy / heightSegments;
  17185. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  17186. var u = ix / widthSegments;
  17187. // vertex
  17188. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17189. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  17190. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17191. vertices.push( vertex.x, vertex.y, vertex.z );
  17192. // normal
  17193. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  17194. normals.push( normal.x, normal.y, normal.z );
  17195. // uv
  17196. uvs.push( u, 1 - v );
  17197. verticesRow.push( index ++ );
  17198. }
  17199. grid.push( verticesRow );
  17200. }
  17201. // indices
  17202. for ( iy = 0; iy < heightSegments; iy ++ ) {
  17203. for ( ix = 0; ix < widthSegments; ix ++ ) {
  17204. var a = grid[ iy ][ ix + 1 ];
  17205. var b = grid[ iy ][ ix ];
  17206. var c = grid[ iy + 1 ][ ix ];
  17207. var d = grid[ iy + 1 ][ ix + 1 ];
  17208. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  17209. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  17210. }
  17211. }
  17212. // build geometry
  17213. this.setIndex( indices );
  17214. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17215. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17216. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17217. }
  17218. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17219. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  17220. /**
  17221. * @author Kaleb Murphy
  17222. * @author Mugen87 / https://github.com/Mugen87
  17223. */
  17224. // RingGeometry
  17225. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17226. Geometry.call( this );
  17227. this.type = 'RingGeometry';
  17228. this.parameters = {
  17229. innerRadius: innerRadius,
  17230. outerRadius: outerRadius,
  17231. thetaSegments: thetaSegments,
  17232. phiSegments: phiSegments,
  17233. thetaStart: thetaStart,
  17234. thetaLength: thetaLength
  17235. };
  17236. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  17237. this.mergeVertices();
  17238. }
  17239. RingGeometry.prototype = Object.create( Geometry.prototype );
  17240. RingGeometry.prototype.constructor = RingGeometry;
  17241. // RingBufferGeometry
  17242. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17243. BufferGeometry.call( this );
  17244. this.type = 'RingBufferGeometry';
  17245. this.parameters = {
  17246. innerRadius: innerRadius,
  17247. outerRadius: outerRadius,
  17248. thetaSegments: thetaSegments,
  17249. phiSegments: phiSegments,
  17250. thetaStart: thetaStart,
  17251. thetaLength: thetaLength
  17252. };
  17253. innerRadius = innerRadius || 0.5;
  17254. outerRadius = outerRadius || 1;
  17255. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17256. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17257. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  17258. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  17259. // buffers
  17260. var indices = [];
  17261. var vertices = [];
  17262. var normals = [];
  17263. var uvs = [];
  17264. // some helper variables
  17265. var segment;
  17266. var radius = innerRadius;
  17267. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  17268. var vertex = new Vector3();
  17269. var uv = new Vector2();
  17270. var j, i;
  17271. // generate vertices, normals and uvs
  17272. for ( j = 0; j <= phiSegments; j ++ ) {
  17273. for ( i = 0; i <= thetaSegments; i ++ ) {
  17274. // values are generate from the inside of the ring to the outside
  17275. segment = thetaStart + i / thetaSegments * thetaLength;
  17276. // vertex
  17277. vertex.x = radius * Math.cos( segment );
  17278. vertex.y = radius * Math.sin( segment );
  17279. vertices.push( vertex.x, vertex.y, vertex.z );
  17280. // normal
  17281. normals.push( 0, 0, 1 );
  17282. // uv
  17283. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  17284. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  17285. uvs.push( uv.x, uv.y );
  17286. }
  17287. // increase the radius for next row of vertices
  17288. radius += radiusStep;
  17289. }
  17290. // indices
  17291. for ( j = 0; j < phiSegments; j ++ ) {
  17292. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  17293. for ( i = 0; i < thetaSegments; i ++ ) {
  17294. segment = i + thetaSegmentLevel;
  17295. var a = segment;
  17296. var b = segment + thetaSegments + 1;
  17297. var c = segment + thetaSegments + 2;
  17298. var d = segment + 1;
  17299. // faces
  17300. indices.push( a, b, d );
  17301. indices.push( b, c, d );
  17302. }
  17303. }
  17304. // build geometry
  17305. this.setIndex( indices );
  17306. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17307. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17308. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17309. }
  17310. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17311. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  17312. /**
  17313. * @author astrodud / http://astrodud.isgreat.org/
  17314. * @author zz85 / https://github.com/zz85
  17315. * @author bhouston / http://clara.io
  17316. * @author Mugen87 / https://github.com/Mugen87
  17317. */
  17318. // LatheGeometry
  17319. function LatheGeometry( points, segments, phiStart, phiLength ) {
  17320. Geometry.call( this );
  17321. this.type = 'LatheGeometry';
  17322. this.parameters = {
  17323. points: points,
  17324. segments: segments,
  17325. phiStart: phiStart,
  17326. phiLength: phiLength
  17327. };
  17328. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  17329. this.mergeVertices();
  17330. }
  17331. LatheGeometry.prototype = Object.create( Geometry.prototype );
  17332. LatheGeometry.prototype.constructor = LatheGeometry;
  17333. // LatheBufferGeometry
  17334. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  17335. BufferGeometry.call( this );
  17336. this.type = 'LatheBufferGeometry';
  17337. this.parameters = {
  17338. points: points,
  17339. segments: segments,
  17340. phiStart: phiStart,
  17341. phiLength: phiLength
  17342. };
  17343. segments = Math.floor( segments ) || 12;
  17344. phiStart = phiStart || 0;
  17345. phiLength = phiLength || Math.PI * 2;
  17346. // clamp phiLength so it's in range of [ 0, 2PI ]
  17347. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  17348. // buffers
  17349. var indices = [];
  17350. var vertices = [];
  17351. var uvs = [];
  17352. // helper variables
  17353. var base;
  17354. var inverseSegments = 1.0 / segments;
  17355. var vertex = new Vector3();
  17356. var uv = new Vector2();
  17357. var i, j;
  17358. // generate vertices and uvs
  17359. for ( i = 0; i <= segments; i ++ ) {
  17360. var phi = phiStart + i * inverseSegments * phiLength;
  17361. var sin = Math.sin( phi );
  17362. var cos = Math.cos( phi );
  17363. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  17364. // vertex
  17365. vertex.x = points[ j ].x * sin;
  17366. vertex.y = points[ j ].y;
  17367. vertex.z = points[ j ].x * cos;
  17368. vertices.push( vertex.x, vertex.y, vertex.z );
  17369. // uv
  17370. uv.x = i / segments;
  17371. uv.y = j / ( points.length - 1 );
  17372. uvs.push( uv.x, uv.y );
  17373. }
  17374. }
  17375. // indices
  17376. for ( i = 0; i < segments; i ++ ) {
  17377. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  17378. base = j + i * points.length;
  17379. var a = base;
  17380. var b = base + points.length;
  17381. var c = base + points.length + 1;
  17382. var d = base + 1;
  17383. // faces
  17384. indices.push( a, b, d );
  17385. indices.push( b, c, d );
  17386. }
  17387. }
  17388. // build geometry
  17389. this.setIndex( indices );
  17390. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17391. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17392. // generate normals
  17393. this.computeVertexNormals();
  17394. // if the geometry is closed, we need to average the normals along the seam.
  17395. // because the corresponding vertices are identical (but still have different UVs).
  17396. if ( phiLength === Math.PI * 2 ) {
  17397. var normals = this.attributes.normal.array;
  17398. var n1 = new Vector3();
  17399. var n2 = new Vector3();
  17400. var n = new Vector3();
  17401. // this is the buffer offset for the last line of vertices
  17402. base = segments * points.length * 3;
  17403. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  17404. // select the normal of the vertex in the first line
  17405. n1.x = normals[ j + 0 ];
  17406. n1.y = normals[ j + 1 ];
  17407. n1.z = normals[ j + 2 ];
  17408. // select the normal of the vertex in the last line
  17409. n2.x = normals[ base + j + 0 ];
  17410. n2.y = normals[ base + j + 1 ];
  17411. n2.z = normals[ base + j + 2 ];
  17412. // average normals
  17413. n.addVectors( n1, n2 ).normalize();
  17414. // assign the new values to both normals
  17415. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  17416. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  17417. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  17418. }
  17419. }
  17420. }
  17421. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17422. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  17423. /**
  17424. * @author jonobr1 / http://jonobr1.com
  17425. * @author Mugen87 / https://github.com/Mugen87
  17426. */
  17427. // ShapeGeometry
  17428. function ShapeGeometry( shapes, curveSegments ) {
  17429. Geometry.call( this );
  17430. this.type = 'ShapeGeometry';
  17431. if ( typeof curveSegments === 'object' ) {
  17432. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  17433. curveSegments = curveSegments.curveSegments;
  17434. }
  17435. this.parameters = {
  17436. shapes: shapes,
  17437. curveSegments: curveSegments
  17438. };
  17439. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  17440. this.mergeVertices();
  17441. }
  17442. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  17443. ShapeGeometry.prototype.constructor = ShapeGeometry;
  17444. ShapeGeometry.prototype.toJSON = function () {
  17445. var data = Geometry.prototype.toJSON.call( this );
  17446. var shapes = this.parameters.shapes;
  17447. return toJSON( shapes, data );
  17448. };
  17449. // ShapeBufferGeometry
  17450. function ShapeBufferGeometry( shapes, curveSegments ) {
  17451. BufferGeometry.call( this );
  17452. this.type = 'ShapeBufferGeometry';
  17453. this.parameters = {
  17454. shapes: shapes,
  17455. curveSegments: curveSegments
  17456. };
  17457. curveSegments = curveSegments || 12;
  17458. // buffers
  17459. var indices = [];
  17460. var vertices = [];
  17461. var normals = [];
  17462. var uvs = [];
  17463. // helper variables
  17464. var groupStart = 0;
  17465. var groupCount = 0;
  17466. // allow single and array values for "shapes" parameter
  17467. if ( Array.isArray( shapes ) === false ) {
  17468. addShape( shapes );
  17469. } else {
  17470. for ( var i = 0; i < shapes.length; i ++ ) {
  17471. addShape( shapes[ i ] );
  17472. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  17473. groupStart += groupCount;
  17474. groupCount = 0;
  17475. }
  17476. }
  17477. // build geometry
  17478. this.setIndex( indices );
  17479. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17480. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17481. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17482. // helper functions
  17483. function addShape( shape ) {
  17484. var i, l, shapeHole;
  17485. var indexOffset = vertices.length / 3;
  17486. var points = shape.extractPoints( curveSegments );
  17487. var shapeVertices = points.shape;
  17488. var shapeHoles = points.holes;
  17489. // check direction of vertices
  17490. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  17491. shapeVertices = shapeVertices.reverse();
  17492. // also check if holes are in the opposite direction
  17493. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17494. shapeHole = shapeHoles[ i ];
  17495. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  17496. shapeHoles[ i ] = shapeHole.reverse();
  17497. }
  17498. }
  17499. }
  17500. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  17501. // join vertices of inner and outer paths to a single array
  17502. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17503. shapeHole = shapeHoles[ i ];
  17504. shapeVertices = shapeVertices.concat( shapeHole );
  17505. }
  17506. // vertices, normals, uvs
  17507. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  17508. var vertex = shapeVertices[ i ];
  17509. vertices.push( vertex.x, vertex.y, 0 );
  17510. normals.push( 0, 0, 1 );
  17511. uvs.push( vertex.x, vertex.y ); // world uvs
  17512. }
  17513. // incides
  17514. for ( i = 0, l = faces.length; i < l; i ++ ) {
  17515. var face = faces[ i ];
  17516. var a = face[ 0 ] + indexOffset;
  17517. var b = face[ 1 ] + indexOffset;
  17518. var c = face[ 2 ] + indexOffset;
  17519. indices.push( a, b, c );
  17520. groupCount += 3;
  17521. }
  17522. }
  17523. }
  17524. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17525. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  17526. ShapeBufferGeometry.prototype.toJSON = function () {
  17527. var data = BufferGeometry.prototype.toJSON.call( this );
  17528. var shapes = this.parameters.shapes;
  17529. return toJSON( shapes, data );
  17530. };
  17531. //
  17532. function toJSON( shapes, data ) {
  17533. data.shapes = [];
  17534. if ( Array.isArray( shapes ) ) {
  17535. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17536. var shape = shapes[ i ];
  17537. data.shapes.push( shape.uuid );
  17538. }
  17539. } else {
  17540. data.shapes.push( shapes.uuid );
  17541. }
  17542. return data;
  17543. }
  17544. /**
  17545. * @author WestLangley / http://github.com/WestLangley
  17546. * @author Mugen87 / https://github.com/Mugen87
  17547. */
  17548. function EdgesGeometry( geometry, thresholdAngle ) {
  17549. BufferGeometry.call( this );
  17550. this.type = 'EdgesGeometry';
  17551. this.parameters = {
  17552. thresholdAngle: thresholdAngle
  17553. };
  17554. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  17555. // buffer
  17556. var vertices = [];
  17557. // helper variables
  17558. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  17559. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  17560. var key, keys = [ 'a', 'b', 'c' ];
  17561. // prepare source geometry
  17562. var geometry2;
  17563. if ( geometry.isBufferGeometry ) {
  17564. geometry2 = new Geometry();
  17565. geometry2.fromBufferGeometry( geometry );
  17566. } else {
  17567. geometry2 = geometry.clone();
  17568. }
  17569. geometry2.mergeVertices();
  17570. geometry2.computeFaceNormals();
  17571. var sourceVertices = geometry2.vertices;
  17572. var faces = geometry2.faces;
  17573. // now create a data structure where each entry represents an edge with its adjoining faces
  17574. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  17575. var face = faces[ i ];
  17576. for ( var j = 0; j < 3; j ++ ) {
  17577. edge1 = face[ keys[ j ] ];
  17578. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  17579. edge[ 0 ] = Math.min( edge1, edge2 );
  17580. edge[ 1 ] = Math.max( edge1, edge2 );
  17581. key = edge[ 0 ] + ',' + edge[ 1 ];
  17582. if ( edges[ key ] === undefined ) {
  17583. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  17584. } else {
  17585. edges[ key ].face2 = i;
  17586. }
  17587. }
  17588. }
  17589. // generate vertices
  17590. for ( key in edges ) {
  17591. var e = edges[ key ];
  17592. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  17593. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  17594. var vertex = sourceVertices[ e.index1 ];
  17595. vertices.push( vertex.x, vertex.y, vertex.z );
  17596. vertex = sourceVertices[ e.index2 ];
  17597. vertices.push( vertex.x, vertex.y, vertex.z );
  17598. }
  17599. }
  17600. // build geometry
  17601. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17602. }
  17603. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  17604. EdgesGeometry.prototype.constructor = EdgesGeometry;
  17605. /**
  17606. * @author mrdoob / http://mrdoob.com/
  17607. * @author Mugen87 / https://github.com/Mugen87
  17608. */
  17609. // CylinderGeometry
  17610. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17611. Geometry.call( this );
  17612. this.type = 'CylinderGeometry';
  17613. this.parameters = {
  17614. radiusTop: radiusTop,
  17615. radiusBottom: radiusBottom,
  17616. height: height,
  17617. radialSegments: radialSegments,
  17618. heightSegments: heightSegments,
  17619. openEnded: openEnded,
  17620. thetaStart: thetaStart,
  17621. thetaLength: thetaLength
  17622. };
  17623. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  17624. this.mergeVertices();
  17625. }
  17626. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  17627. CylinderGeometry.prototype.constructor = CylinderGeometry;
  17628. // CylinderBufferGeometry
  17629. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17630. BufferGeometry.call( this );
  17631. this.type = 'CylinderBufferGeometry';
  17632. this.parameters = {
  17633. radiusTop: radiusTop,
  17634. radiusBottom: radiusBottom,
  17635. height: height,
  17636. radialSegments: radialSegments,
  17637. heightSegments: heightSegments,
  17638. openEnded: openEnded,
  17639. thetaStart: thetaStart,
  17640. thetaLength: thetaLength
  17641. };
  17642. var scope = this;
  17643. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17644. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17645. height = height || 1;
  17646. radialSegments = Math.floor( radialSegments ) || 8;
  17647. heightSegments = Math.floor( heightSegments ) || 1;
  17648. openEnded = openEnded !== undefined ? openEnded : false;
  17649. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17650. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17651. // buffers
  17652. var indices = [];
  17653. var vertices = [];
  17654. var normals = [];
  17655. var uvs = [];
  17656. // helper variables
  17657. var index = 0;
  17658. var indexArray = [];
  17659. var halfHeight = height / 2;
  17660. var groupStart = 0;
  17661. // generate geometry
  17662. generateTorso();
  17663. if ( openEnded === false ) {
  17664. if ( radiusTop > 0 ) generateCap( true );
  17665. if ( radiusBottom > 0 ) generateCap( false );
  17666. }
  17667. // build geometry
  17668. this.setIndex( indices );
  17669. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17670. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17671. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17672. function generateTorso() {
  17673. var x, y;
  17674. var normal = new Vector3();
  17675. var vertex = new Vector3();
  17676. var groupCount = 0;
  17677. // this will be used to calculate the normal
  17678. var slope = ( radiusBottom - radiusTop ) / height;
  17679. // generate vertices, normals and uvs
  17680. for ( y = 0; y <= heightSegments; y ++ ) {
  17681. var indexRow = [];
  17682. var v = y / heightSegments;
  17683. // calculate the radius of the current row
  17684. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  17685. for ( x = 0; x <= radialSegments; x ++ ) {
  17686. var u = x / radialSegments;
  17687. var theta = u * thetaLength + thetaStart;
  17688. var sinTheta = Math.sin( theta );
  17689. var cosTheta = Math.cos( theta );
  17690. // vertex
  17691. vertex.x = radius * sinTheta;
  17692. vertex.y = - v * height + halfHeight;
  17693. vertex.z = radius * cosTheta;
  17694. vertices.push( vertex.x, vertex.y, vertex.z );
  17695. // normal
  17696. normal.set( sinTheta, slope, cosTheta ).normalize();
  17697. normals.push( normal.x, normal.y, normal.z );
  17698. // uv
  17699. uvs.push( u, 1 - v );
  17700. // save index of vertex in respective row
  17701. indexRow.push( index ++ );
  17702. }
  17703. // now save vertices of the row in our index array
  17704. indexArray.push( indexRow );
  17705. }
  17706. // generate indices
  17707. for ( x = 0; x < radialSegments; x ++ ) {
  17708. for ( y = 0; y < heightSegments; y ++ ) {
  17709. // we use the index array to access the correct indices
  17710. var a = indexArray[ y ][ x ];
  17711. var b = indexArray[ y + 1 ][ x ];
  17712. var c = indexArray[ y + 1 ][ x + 1 ];
  17713. var d = indexArray[ y ][ x + 1 ];
  17714. // faces
  17715. indices.push( a, b, d );
  17716. indices.push( b, c, d );
  17717. // update group counter
  17718. groupCount += 6;
  17719. }
  17720. }
  17721. // add a group to the geometry. this will ensure multi material support
  17722. scope.addGroup( groupStart, groupCount, 0 );
  17723. // calculate new start value for groups
  17724. groupStart += groupCount;
  17725. }
  17726. function generateCap( top ) {
  17727. var x, centerIndexStart, centerIndexEnd;
  17728. var uv = new Vector2();
  17729. var vertex = new Vector3();
  17730. var groupCount = 0;
  17731. var radius = ( top === true ) ? radiusTop : radiusBottom;
  17732. var sign = ( top === true ) ? 1 : - 1;
  17733. // save the index of the first center vertex
  17734. centerIndexStart = index;
  17735. // first we generate the center vertex data of the cap.
  17736. // because the geometry needs one set of uvs per face,
  17737. // we must generate a center vertex per face/segment
  17738. for ( x = 1; x <= radialSegments; x ++ ) {
  17739. // vertex
  17740. vertices.push( 0, halfHeight * sign, 0 );
  17741. // normal
  17742. normals.push( 0, sign, 0 );
  17743. // uv
  17744. uvs.push( 0.5, 0.5 );
  17745. // increase index
  17746. index ++;
  17747. }
  17748. // save the index of the last center vertex
  17749. centerIndexEnd = index;
  17750. // now we generate the surrounding vertices, normals and uvs
  17751. for ( x = 0; x <= radialSegments; x ++ ) {
  17752. var u = x / radialSegments;
  17753. var theta = u * thetaLength + thetaStart;
  17754. var cosTheta = Math.cos( theta );
  17755. var sinTheta = Math.sin( theta );
  17756. // vertex
  17757. vertex.x = radius * sinTheta;
  17758. vertex.y = halfHeight * sign;
  17759. vertex.z = radius * cosTheta;
  17760. vertices.push( vertex.x, vertex.y, vertex.z );
  17761. // normal
  17762. normals.push( 0, sign, 0 );
  17763. // uv
  17764. uv.x = ( cosTheta * 0.5 ) + 0.5;
  17765. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  17766. uvs.push( uv.x, uv.y );
  17767. // increase index
  17768. index ++;
  17769. }
  17770. // generate indices
  17771. for ( x = 0; x < radialSegments; x ++ ) {
  17772. var c = centerIndexStart + x;
  17773. var i = centerIndexEnd + x;
  17774. if ( top === true ) {
  17775. // face top
  17776. indices.push( i, i + 1, c );
  17777. } else {
  17778. // face bottom
  17779. indices.push( i + 1, i, c );
  17780. }
  17781. groupCount += 3;
  17782. }
  17783. // add a group to the geometry. this will ensure multi material support
  17784. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  17785. // calculate new start value for groups
  17786. groupStart += groupCount;
  17787. }
  17788. }
  17789. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17790. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  17791. /**
  17792. * @author abelnation / http://github.com/abelnation
  17793. */
  17794. // ConeGeometry
  17795. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17796. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17797. this.type = 'ConeGeometry';
  17798. this.parameters = {
  17799. radius: radius,
  17800. height: height,
  17801. radialSegments: radialSegments,
  17802. heightSegments: heightSegments,
  17803. openEnded: openEnded,
  17804. thetaStart: thetaStart,
  17805. thetaLength: thetaLength
  17806. };
  17807. }
  17808. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  17809. ConeGeometry.prototype.constructor = ConeGeometry;
  17810. // ConeBufferGeometry
  17811. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17812. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17813. this.type = 'ConeBufferGeometry';
  17814. this.parameters = {
  17815. radius: radius,
  17816. height: height,
  17817. radialSegments: radialSegments,
  17818. heightSegments: heightSegments,
  17819. openEnded: openEnded,
  17820. thetaStart: thetaStart,
  17821. thetaLength: thetaLength
  17822. };
  17823. }
  17824. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  17825. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  17826. /**
  17827. * @author benaadams / https://twitter.com/ben_a_adams
  17828. * @author Mugen87 / https://github.com/Mugen87
  17829. * @author hughes
  17830. */
  17831. // CircleGeometry
  17832. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  17833. Geometry.call( this );
  17834. this.type = 'CircleGeometry';
  17835. this.parameters = {
  17836. radius: radius,
  17837. segments: segments,
  17838. thetaStart: thetaStart,
  17839. thetaLength: thetaLength
  17840. };
  17841. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  17842. this.mergeVertices();
  17843. }
  17844. CircleGeometry.prototype = Object.create( Geometry.prototype );
  17845. CircleGeometry.prototype.constructor = CircleGeometry;
  17846. // CircleBufferGeometry
  17847. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  17848. BufferGeometry.call( this );
  17849. this.type = 'CircleBufferGeometry';
  17850. this.parameters = {
  17851. radius: radius,
  17852. segments: segments,
  17853. thetaStart: thetaStart,
  17854. thetaLength: thetaLength
  17855. };
  17856. radius = radius || 1;
  17857. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  17858. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17859. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17860. // buffers
  17861. var indices = [];
  17862. var vertices = [];
  17863. var normals = [];
  17864. var uvs = [];
  17865. // helper variables
  17866. var i, s;
  17867. var vertex = new Vector3();
  17868. var uv = new Vector2();
  17869. // center point
  17870. vertices.push( 0, 0, 0 );
  17871. normals.push( 0, 0, 1 );
  17872. uvs.push( 0.5, 0.5 );
  17873. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  17874. var segment = thetaStart + s / segments * thetaLength;
  17875. // vertex
  17876. vertex.x = radius * Math.cos( segment );
  17877. vertex.y = radius * Math.sin( segment );
  17878. vertices.push( vertex.x, vertex.y, vertex.z );
  17879. // normal
  17880. normals.push( 0, 0, 1 );
  17881. // uvs
  17882. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  17883. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  17884. uvs.push( uv.x, uv.y );
  17885. }
  17886. // indices
  17887. for ( i = 1; i <= segments; i ++ ) {
  17888. indices.push( i, i + 1, 0 );
  17889. }
  17890. // build geometry
  17891. this.setIndex( indices );
  17892. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17893. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17894. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17895. }
  17896. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17897. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  17898. var Geometries = Object.freeze({
  17899. WireframeGeometry: WireframeGeometry,
  17900. ParametricGeometry: ParametricGeometry,
  17901. ParametricBufferGeometry: ParametricBufferGeometry,
  17902. TetrahedronGeometry: TetrahedronGeometry,
  17903. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  17904. OctahedronGeometry: OctahedronGeometry,
  17905. OctahedronBufferGeometry: OctahedronBufferGeometry,
  17906. IcosahedronGeometry: IcosahedronGeometry,
  17907. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  17908. DodecahedronGeometry: DodecahedronGeometry,
  17909. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  17910. PolyhedronGeometry: PolyhedronGeometry,
  17911. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  17912. TubeGeometry: TubeGeometry,
  17913. TubeBufferGeometry: TubeBufferGeometry,
  17914. TorusKnotGeometry: TorusKnotGeometry,
  17915. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  17916. TorusGeometry: TorusGeometry,
  17917. TorusBufferGeometry: TorusBufferGeometry,
  17918. TextGeometry: TextGeometry,
  17919. TextBufferGeometry: TextBufferGeometry,
  17920. SphereGeometry: SphereGeometry,
  17921. SphereBufferGeometry: SphereBufferGeometry,
  17922. RingGeometry: RingGeometry,
  17923. RingBufferGeometry: RingBufferGeometry,
  17924. PlaneGeometry: PlaneGeometry,
  17925. PlaneBufferGeometry: PlaneBufferGeometry,
  17926. LatheGeometry: LatheGeometry,
  17927. LatheBufferGeometry: LatheBufferGeometry,
  17928. ShapeGeometry: ShapeGeometry,
  17929. ShapeBufferGeometry: ShapeBufferGeometry,
  17930. ExtrudeGeometry: ExtrudeGeometry,
  17931. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  17932. EdgesGeometry: EdgesGeometry,
  17933. ConeGeometry: ConeGeometry,
  17934. ConeBufferGeometry: ConeBufferGeometry,
  17935. CylinderGeometry: CylinderGeometry,
  17936. CylinderBufferGeometry: CylinderBufferGeometry,
  17937. CircleGeometry: CircleGeometry,
  17938. CircleBufferGeometry: CircleBufferGeometry,
  17939. BoxGeometry: BoxGeometry,
  17940. BoxBufferGeometry: BoxBufferGeometry
  17941. });
  17942. /**
  17943. * @author mrdoob / http://mrdoob.com/
  17944. *
  17945. * parameters = {
  17946. * color: <THREE.Color>
  17947. * }
  17948. */
  17949. function ShadowMaterial( parameters ) {
  17950. Material.call( this );
  17951. this.type = 'ShadowMaterial';
  17952. this.color = new Color( 0x000000 );
  17953. this.transparent = true;
  17954. this.setValues( parameters );
  17955. }
  17956. ShadowMaterial.prototype = Object.create( Material.prototype );
  17957. ShadowMaterial.prototype.constructor = ShadowMaterial;
  17958. ShadowMaterial.prototype.isShadowMaterial = true;
  17959. ShadowMaterial.prototype.copy = function ( source ) {
  17960. Material.prototype.copy.call( this, source );
  17961. this.color.copy( source.color );
  17962. return this;
  17963. };
  17964. /**
  17965. * @author mrdoob / http://mrdoob.com/
  17966. */
  17967. function RawShaderMaterial( parameters ) {
  17968. ShaderMaterial.call( this, parameters );
  17969. this.type = 'RawShaderMaterial';
  17970. }
  17971. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17972. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  17973. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  17974. /**
  17975. * @author WestLangley / http://github.com/WestLangley
  17976. *
  17977. * parameters = {
  17978. * color: <hex>,
  17979. * roughness: <float>,
  17980. * metalness: <float>,
  17981. * opacity: <float>,
  17982. *
  17983. * map: new THREE.Texture( <Image> ),
  17984. *
  17985. * lightMap: new THREE.Texture( <Image> ),
  17986. * lightMapIntensity: <float>
  17987. *
  17988. * aoMap: new THREE.Texture( <Image> ),
  17989. * aoMapIntensity: <float>
  17990. *
  17991. * emissive: <hex>,
  17992. * emissiveIntensity: <float>
  17993. * emissiveMap: new THREE.Texture( <Image> ),
  17994. *
  17995. * bumpMap: new THREE.Texture( <Image> ),
  17996. * bumpScale: <float>,
  17997. *
  17998. * normalMap: new THREE.Texture( <Image> ),
  17999. * normalScale: <Vector2>,
  18000. *
  18001. * displacementMap: new THREE.Texture( <Image> ),
  18002. * displacementScale: <float>,
  18003. * displacementBias: <float>,
  18004. *
  18005. * roughnessMap: new THREE.Texture( <Image> ),
  18006. *
  18007. * metalnessMap: new THREE.Texture( <Image> ),
  18008. *
  18009. * alphaMap: new THREE.Texture( <Image> ),
  18010. *
  18011. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18012. * envMapIntensity: <float>
  18013. *
  18014. * refractionRatio: <float>,
  18015. *
  18016. * wireframe: <boolean>,
  18017. * wireframeLinewidth: <float>,
  18018. *
  18019. * skinning: <bool>,
  18020. * morphTargets: <bool>,
  18021. * morphNormals: <bool>
  18022. * }
  18023. */
  18024. function MeshStandardMaterial( parameters ) {
  18025. Material.call( this );
  18026. this.defines = { 'STANDARD': '' };
  18027. this.type = 'MeshStandardMaterial';
  18028. this.color = new Color( 0xffffff ); // diffuse
  18029. this.roughness = 0.5;
  18030. this.metalness = 0.5;
  18031. this.map = null;
  18032. this.lightMap = null;
  18033. this.lightMapIntensity = 1.0;
  18034. this.aoMap = null;
  18035. this.aoMapIntensity = 1.0;
  18036. this.emissive = new Color( 0x000000 );
  18037. this.emissiveIntensity = 1.0;
  18038. this.emissiveMap = null;
  18039. this.bumpMap = null;
  18040. this.bumpScale = 1;
  18041. this.normalMap = null;
  18042. this.normalScale = new Vector2( 1, 1 );
  18043. this.displacementMap = null;
  18044. this.displacementScale = 1;
  18045. this.displacementBias = 0;
  18046. this.roughnessMap = null;
  18047. this.metalnessMap = null;
  18048. this.alphaMap = null;
  18049. this.envMap = null;
  18050. this.envMapIntensity = 1.0;
  18051. this.refractionRatio = 0.98;
  18052. this.wireframe = false;
  18053. this.wireframeLinewidth = 1;
  18054. this.wireframeLinecap = 'round';
  18055. this.wireframeLinejoin = 'round';
  18056. this.skinning = false;
  18057. this.morphTargets = false;
  18058. this.morphNormals = false;
  18059. this.setValues( parameters );
  18060. }
  18061. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18062. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18063. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18064. MeshStandardMaterial.prototype.copy = function ( source ) {
  18065. Material.prototype.copy.call( this, source );
  18066. this.defines = { 'STANDARD': '' };
  18067. this.color.copy( source.color );
  18068. this.roughness = source.roughness;
  18069. this.metalness = source.metalness;
  18070. this.map = source.map;
  18071. this.lightMap = source.lightMap;
  18072. this.lightMapIntensity = source.lightMapIntensity;
  18073. this.aoMap = source.aoMap;
  18074. this.aoMapIntensity = source.aoMapIntensity;
  18075. this.emissive.copy( source.emissive );
  18076. this.emissiveMap = source.emissiveMap;
  18077. this.emissiveIntensity = source.emissiveIntensity;
  18078. this.bumpMap = source.bumpMap;
  18079. this.bumpScale = source.bumpScale;
  18080. this.normalMap = source.normalMap;
  18081. this.normalScale.copy( source.normalScale );
  18082. this.displacementMap = source.displacementMap;
  18083. this.displacementScale = source.displacementScale;
  18084. this.displacementBias = source.displacementBias;
  18085. this.roughnessMap = source.roughnessMap;
  18086. this.metalnessMap = source.metalnessMap;
  18087. this.alphaMap = source.alphaMap;
  18088. this.envMap = source.envMap;
  18089. this.envMapIntensity = source.envMapIntensity;
  18090. this.refractionRatio = source.refractionRatio;
  18091. this.wireframe = source.wireframe;
  18092. this.wireframeLinewidth = source.wireframeLinewidth;
  18093. this.wireframeLinecap = source.wireframeLinecap;
  18094. this.wireframeLinejoin = source.wireframeLinejoin;
  18095. this.skinning = source.skinning;
  18096. this.morphTargets = source.morphTargets;
  18097. this.morphNormals = source.morphNormals;
  18098. return this;
  18099. };
  18100. /**
  18101. * @author WestLangley / http://github.com/WestLangley
  18102. *
  18103. * parameters = {
  18104. * reflectivity: <float>
  18105. * }
  18106. */
  18107. function MeshPhysicalMaterial( parameters ) {
  18108. MeshStandardMaterial.call( this );
  18109. this.defines = { 'PHYSICAL': '' };
  18110. this.type = 'MeshPhysicalMaterial';
  18111. this.reflectivity = 0.5; // maps to F0 = 0.04
  18112. this.clearCoat = 0.0;
  18113. this.clearCoatRoughness = 0.0;
  18114. this.setValues( parameters );
  18115. }
  18116. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18117. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18118. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18119. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18120. MeshStandardMaterial.prototype.copy.call( this, source );
  18121. this.defines = { 'PHYSICAL': '' };
  18122. this.reflectivity = source.reflectivity;
  18123. this.clearCoat = source.clearCoat;
  18124. this.clearCoatRoughness = source.clearCoatRoughness;
  18125. return this;
  18126. };
  18127. /**
  18128. * @author mrdoob / http://mrdoob.com/
  18129. * @author alteredq / http://alteredqualia.com/
  18130. *
  18131. * parameters = {
  18132. * color: <hex>,
  18133. * specular: <hex>,
  18134. * shininess: <float>,
  18135. * opacity: <float>,
  18136. *
  18137. * map: new THREE.Texture( <Image> ),
  18138. *
  18139. * lightMap: new THREE.Texture( <Image> ),
  18140. * lightMapIntensity: <float>
  18141. *
  18142. * aoMap: new THREE.Texture( <Image> ),
  18143. * aoMapIntensity: <float>
  18144. *
  18145. * emissive: <hex>,
  18146. * emissiveIntensity: <float>
  18147. * emissiveMap: new THREE.Texture( <Image> ),
  18148. *
  18149. * bumpMap: new THREE.Texture( <Image> ),
  18150. * bumpScale: <float>,
  18151. *
  18152. * normalMap: new THREE.Texture( <Image> ),
  18153. * normalScale: <Vector2>,
  18154. *
  18155. * displacementMap: new THREE.Texture( <Image> ),
  18156. * displacementScale: <float>,
  18157. * displacementBias: <float>,
  18158. *
  18159. * specularMap: new THREE.Texture( <Image> ),
  18160. *
  18161. * alphaMap: new THREE.Texture( <Image> ),
  18162. *
  18163. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18164. * combine: THREE.Multiply,
  18165. * reflectivity: <float>,
  18166. * refractionRatio: <float>,
  18167. *
  18168. * wireframe: <boolean>,
  18169. * wireframeLinewidth: <float>,
  18170. *
  18171. * skinning: <bool>,
  18172. * morphTargets: <bool>,
  18173. * morphNormals: <bool>
  18174. * }
  18175. */
  18176. function MeshPhongMaterial( parameters ) {
  18177. Material.call( this );
  18178. this.type = 'MeshPhongMaterial';
  18179. this.color = new Color( 0xffffff ); // diffuse
  18180. this.specular = new Color( 0x111111 );
  18181. this.shininess = 30;
  18182. this.map = null;
  18183. this.lightMap = null;
  18184. this.lightMapIntensity = 1.0;
  18185. this.aoMap = null;
  18186. this.aoMapIntensity = 1.0;
  18187. this.emissive = new Color( 0x000000 );
  18188. this.emissiveIntensity = 1.0;
  18189. this.emissiveMap = null;
  18190. this.bumpMap = null;
  18191. this.bumpScale = 1;
  18192. this.normalMap = null;
  18193. this.normalScale = new Vector2( 1, 1 );
  18194. this.displacementMap = null;
  18195. this.displacementScale = 1;
  18196. this.displacementBias = 0;
  18197. this.specularMap = null;
  18198. this.alphaMap = null;
  18199. this.envMap = null;
  18200. this.combine = MultiplyOperation;
  18201. this.reflectivity = 1;
  18202. this.refractionRatio = 0.98;
  18203. this.wireframe = false;
  18204. this.wireframeLinewidth = 1;
  18205. this.wireframeLinecap = 'round';
  18206. this.wireframeLinejoin = 'round';
  18207. this.skinning = false;
  18208. this.morphTargets = false;
  18209. this.morphNormals = false;
  18210. this.setValues( parameters );
  18211. }
  18212. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  18213. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  18214. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  18215. MeshPhongMaterial.prototype.copy = function ( source ) {
  18216. Material.prototype.copy.call( this, source );
  18217. this.color.copy( source.color );
  18218. this.specular.copy( source.specular );
  18219. this.shininess = source.shininess;
  18220. this.map = source.map;
  18221. this.lightMap = source.lightMap;
  18222. this.lightMapIntensity = source.lightMapIntensity;
  18223. this.aoMap = source.aoMap;
  18224. this.aoMapIntensity = source.aoMapIntensity;
  18225. this.emissive.copy( source.emissive );
  18226. this.emissiveMap = source.emissiveMap;
  18227. this.emissiveIntensity = source.emissiveIntensity;
  18228. this.bumpMap = source.bumpMap;
  18229. this.bumpScale = source.bumpScale;
  18230. this.normalMap = source.normalMap;
  18231. this.normalScale.copy( source.normalScale );
  18232. this.displacementMap = source.displacementMap;
  18233. this.displacementScale = source.displacementScale;
  18234. this.displacementBias = source.displacementBias;
  18235. this.specularMap = source.specularMap;
  18236. this.alphaMap = source.alphaMap;
  18237. this.envMap = source.envMap;
  18238. this.combine = source.combine;
  18239. this.reflectivity = source.reflectivity;
  18240. this.refractionRatio = source.refractionRatio;
  18241. this.wireframe = source.wireframe;
  18242. this.wireframeLinewidth = source.wireframeLinewidth;
  18243. this.wireframeLinecap = source.wireframeLinecap;
  18244. this.wireframeLinejoin = source.wireframeLinejoin;
  18245. this.skinning = source.skinning;
  18246. this.morphTargets = source.morphTargets;
  18247. this.morphNormals = source.morphNormals;
  18248. return this;
  18249. };
  18250. /**
  18251. * @author takahirox / http://github.com/takahirox
  18252. *
  18253. * parameters = {
  18254. * gradientMap: new THREE.Texture( <Image> )
  18255. * }
  18256. */
  18257. function MeshToonMaterial( parameters ) {
  18258. MeshPhongMaterial.call( this );
  18259. this.defines = { 'TOON': '' };
  18260. this.type = 'MeshToonMaterial';
  18261. this.gradientMap = null;
  18262. this.setValues( parameters );
  18263. }
  18264. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  18265. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  18266. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  18267. MeshToonMaterial.prototype.copy = function ( source ) {
  18268. MeshPhongMaterial.prototype.copy.call( this, source );
  18269. this.gradientMap = source.gradientMap;
  18270. return this;
  18271. };
  18272. /**
  18273. * @author mrdoob / http://mrdoob.com/
  18274. * @author WestLangley / http://github.com/WestLangley
  18275. *
  18276. * parameters = {
  18277. * opacity: <float>,
  18278. *
  18279. * bumpMap: new THREE.Texture( <Image> ),
  18280. * bumpScale: <float>,
  18281. *
  18282. * normalMap: new THREE.Texture( <Image> ),
  18283. * normalScale: <Vector2>,
  18284. *
  18285. * displacementMap: new THREE.Texture( <Image> ),
  18286. * displacementScale: <float>,
  18287. * displacementBias: <float>,
  18288. *
  18289. * wireframe: <boolean>,
  18290. * wireframeLinewidth: <float>
  18291. *
  18292. * skinning: <bool>,
  18293. * morphTargets: <bool>,
  18294. * morphNormals: <bool>
  18295. * }
  18296. */
  18297. function MeshNormalMaterial( parameters ) {
  18298. Material.call( this );
  18299. this.type = 'MeshNormalMaterial';
  18300. this.bumpMap = null;
  18301. this.bumpScale = 1;
  18302. this.normalMap = null;
  18303. this.normalScale = new Vector2( 1, 1 );
  18304. this.displacementMap = null;
  18305. this.displacementScale = 1;
  18306. this.displacementBias = 0;
  18307. this.wireframe = false;
  18308. this.wireframeLinewidth = 1;
  18309. this.fog = false;
  18310. this.lights = false;
  18311. this.skinning = false;
  18312. this.morphTargets = false;
  18313. this.morphNormals = false;
  18314. this.setValues( parameters );
  18315. }
  18316. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  18317. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  18318. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  18319. MeshNormalMaterial.prototype.copy = function ( source ) {
  18320. Material.prototype.copy.call( this, source );
  18321. this.bumpMap = source.bumpMap;
  18322. this.bumpScale = source.bumpScale;
  18323. this.normalMap = source.normalMap;
  18324. this.normalScale.copy( source.normalScale );
  18325. this.displacementMap = source.displacementMap;
  18326. this.displacementScale = source.displacementScale;
  18327. this.displacementBias = source.displacementBias;
  18328. this.wireframe = source.wireframe;
  18329. this.wireframeLinewidth = source.wireframeLinewidth;
  18330. this.skinning = source.skinning;
  18331. this.morphTargets = source.morphTargets;
  18332. this.morphNormals = source.morphNormals;
  18333. return this;
  18334. };
  18335. /**
  18336. * @author mrdoob / http://mrdoob.com/
  18337. * @author alteredq / http://alteredqualia.com/
  18338. *
  18339. * parameters = {
  18340. * color: <hex>,
  18341. * opacity: <float>,
  18342. *
  18343. * map: new THREE.Texture( <Image> ),
  18344. *
  18345. * lightMap: new THREE.Texture( <Image> ),
  18346. * lightMapIntensity: <float>
  18347. *
  18348. * aoMap: new THREE.Texture( <Image> ),
  18349. * aoMapIntensity: <float>
  18350. *
  18351. * emissive: <hex>,
  18352. * emissiveIntensity: <float>
  18353. * emissiveMap: new THREE.Texture( <Image> ),
  18354. *
  18355. * specularMap: new THREE.Texture( <Image> ),
  18356. *
  18357. * alphaMap: new THREE.Texture( <Image> ),
  18358. *
  18359. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18360. * combine: THREE.Multiply,
  18361. * reflectivity: <float>,
  18362. * refractionRatio: <float>,
  18363. *
  18364. * wireframe: <boolean>,
  18365. * wireframeLinewidth: <float>,
  18366. *
  18367. * skinning: <bool>,
  18368. * morphTargets: <bool>,
  18369. * morphNormals: <bool>
  18370. * }
  18371. */
  18372. function MeshLambertMaterial( parameters ) {
  18373. Material.call( this );
  18374. this.type = 'MeshLambertMaterial';
  18375. this.color = new Color( 0xffffff ); // diffuse
  18376. this.map = null;
  18377. this.lightMap = null;
  18378. this.lightMapIntensity = 1.0;
  18379. this.aoMap = null;
  18380. this.aoMapIntensity = 1.0;
  18381. this.emissive = new Color( 0x000000 );
  18382. this.emissiveIntensity = 1.0;
  18383. this.emissiveMap = null;
  18384. this.specularMap = null;
  18385. this.alphaMap = null;
  18386. this.envMap = null;
  18387. this.combine = MultiplyOperation;
  18388. this.reflectivity = 1;
  18389. this.refractionRatio = 0.98;
  18390. this.wireframe = false;
  18391. this.wireframeLinewidth = 1;
  18392. this.wireframeLinecap = 'round';
  18393. this.wireframeLinejoin = 'round';
  18394. this.skinning = false;
  18395. this.morphTargets = false;
  18396. this.morphNormals = false;
  18397. this.setValues( parameters );
  18398. }
  18399. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  18400. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  18401. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  18402. MeshLambertMaterial.prototype.copy = function ( source ) {
  18403. Material.prototype.copy.call( this, source );
  18404. this.color.copy( source.color );
  18405. this.map = source.map;
  18406. this.lightMap = source.lightMap;
  18407. this.lightMapIntensity = source.lightMapIntensity;
  18408. this.aoMap = source.aoMap;
  18409. this.aoMapIntensity = source.aoMapIntensity;
  18410. this.emissive.copy( source.emissive );
  18411. this.emissiveMap = source.emissiveMap;
  18412. this.emissiveIntensity = source.emissiveIntensity;
  18413. this.specularMap = source.specularMap;
  18414. this.alphaMap = source.alphaMap;
  18415. this.envMap = source.envMap;
  18416. this.combine = source.combine;
  18417. this.reflectivity = source.reflectivity;
  18418. this.refractionRatio = source.refractionRatio;
  18419. this.wireframe = source.wireframe;
  18420. this.wireframeLinewidth = source.wireframeLinewidth;
  18421. this.wireframeLinecap = source.wireframeLinecap;
  18422. this.wireframeLinejoin = source.wireframeLinejoin;
  18423. this.skinning = source.skinning;
  18424. this.morphTargets = source.morphTargets;
  18425. this.morphNormals = source.morphNormals;
  18426. return this;
  18427. };
  18428. /**
  18429. * @author alteredq / http://alteredqualia.com/
  18430. *
  18431. * parameters = {
  18432. * color: <hex>,
  18433. * opacity: <float>,
  18434. *
  18435. * linewidth: <float>,
  18436. *
  18437. * scale: <float>,
  18438. * dashSize: <float>,
  18439. * gapSize: <float>
  18440. * }
  18441. */
  18442. function LineDashedMaterial( parameters ) {
  18443. LineBasicMaterial.call( this );
  18444. this.type = 'LineDashedMaterial';
  18445. this.scale = 1;
  18446. this.dashSize = 3;
  18447. this.gapSize = 1;
  18448. this.setValues( parameters );
  18449. }
  18450. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  18451. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  18452. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  18453. LineDashedMaterial.prototype.copy = function ( source ) {
  18454. LineBasicMaterial.prototype.copy.call( this, source );
  18455. this.scale = source.scale;
  18456. this.dashSize = source.dashSize;
  18457. this.gapSize = source.gapSize;
  18458. return this;
  18459. };
  18460. var Materials = Object.freeze({
  18461. ShadowMaterial: ShadowMaterial,
  18462. SpriteMaterial: SpriteMaterial,
  18463. RawShaderMaterial: RawShaderMaterial,
  18464. ShaderMaterial: ShaderMaterial,
  18465. PointsMaterial: PointsMaterial,
  18466. MeshPhysicalMaterial: MeshPhysicalMaterial,
  18467. MeshStandardMaterial: MeshStandardMaterial,
  18468. MeshPhongMaterial: MeshPhongMaterial,
  18469. MeshToonMaterial: MeshToonMaterial,
  18470. MeshNormalMaterial: MeshNormalMaterial,
  18471. MeshLambertMaterial: MeshLambertMaterial,
  18472. MeshDepthMaterial: MeshDepthMaterial,
  18473. MeshDistanceMaterial: MeshDistanceMaterial,
  18474. MeshBasicMaterial: MeshBasicMaterial,
  18475. LineDashedMaterial: LineDashedMaterial,
  18476. LineBasicMaterial: LineBasicMaterial,
  18477. Material: Material
  18478. });
  18479. /**
  18480. * @author mrdoob / http://mrdoob.com/
  18481. */
  18482. var Cache = {
  18483. enabled: false,
  18484. files: {},
  18485. add: function ( key, file ) {
  18486. if ( this.enabled === false ) return;
  18487. // console.log( 'THREE.Cache', 'Adding key:', key );
  18488. this.files[ key ] = file;
  18489. },
  18490. get: function ( key ) {
  18491. if ( this.enabled === false ) return;
  18492. // console.log( 'THREE.Cache', 'Checking key:', key );
  18493. return this.files[ key ];
  18494. },
  18495. remove: function ( key ) {
  18496. delete this.files[ key ];
  18497. },
  18498. clear: function () {
  18499. this.files = {};
  18500. }
  18501. };
  18502. /**
  18503. * @author mrdoob / http://mrdoob.com/
  18504. */
  18505. function LoadingManager( onLoad, onProgress, onError ) {
  18506. var scope = this;
  18507. var isLoading = false;
  18508. var itemsLoaded = 0;
  18509. var itemsTotal = 0;
  18510. var urlModifier = undefined;
  18511. this.onStart = undefined;
  18512. this.onLoad = onLoad;
  18513. this.onProgress = onProgress;
  18514. this.onError = onError;
  18515. this.itemStart = function ( url ) {
  18516. itemsTotal ++;
  18517. if ( isLoading === false ) {
  18518. if ( scope.onStart !== undefined ) {
  18519. scope.onStart( url, itemsLoaded, itemsTotal );
  18520. }
  18521. }
  18522. isLoading = true;
  18523. };
  18524. this.itemEnd = function ( url ) {
  18525. itemsLoaded ++;
  18526. if ( scope.onProgress !== undefined ) {
  18527. scope.onProgress( url, itemsLoaded, itemsTotal );
  18528. }
  18529. if ( itemsLoaded === itemsTotal ) {
  18530. isLoading = false;
  18531. if ( scope.onLoad !== undefined ) {
  18532. scope.onLoad();
  18533. }
  18534. }
  18535. };
  18536. this.itemError = function ( url ) {
  18537. if ( scope.onError !== undefined ) {
  18538. scope.onError( url );
  18539. }
  18540. };
  18541. this.resolveURL = function ( url ) {
  18542. if ( urlModifier ) {
  18543. return urlModifier( url );
  18544. }
  18545. return url;
  18546. };
  18547. this.setURLModifier = function ( transform ) {
  18548. urlModifier = transform;
  18549. return this;
  18550. };
  18551. }
  18552. var DefaultLoadingManager = new LoadingManager();
  18553. /**
  18554. * @author mrdoob / http://mrdoob.com/
  18555. */
  18556. var loading = {};
  18557. function FileLoader( manager ) {
  18558. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18559. }
  18560. Object.assign( FileLoader.prototype, {
  18561. load: function ( url, onLoad, onProgress, onError ) {
  18562. if ( url === undefined ) url = '';
  18563. if ( this.path !== undefined ) url = this.path + url;
  18564. url = this.manager.resolveURL( url );
  18565. var scope = this;
  18566. var cached = Cache.get( url );
  18567. if ( cached !== undefined ) {
  18568. scope.manager.itemStart( url );
  18569. setTimeout( function () {
  18570. if ( onLoad ) onLoad( cached );
  18571. scope.manager.itemEnd( url );
  18572. }, 0 );
  18573. return cached;
  18574. }
  18575. // Check if request is duplicate
  18576. if ( loading[ url ] !== undefined ) {
  18577. loading[ url ].push( {
  18578. onLoad: onLoad,
  18579. onProgress: onProgress,
  18580. onError: onError
  18581. } );
  18582. return;
  18583. }
  18584. // Check for data: URI
  18585. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  18586. var dataUriRegexResult = url.match( dataUriRegex );
  18587. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  18588. if ( dataUriRegexResult ) {
  18589. var mimeType = dataUriRegexResult[ 1 ];
  18590. var isBase64 = !! dataUriRegexResult[ 2 ];
  18591. var data = dataUriRegexResult[ 3 ];
  18592. data = window.decodeURIComponent( data );
  18593. if ( isBase64 ) data = window.atob( data );
  18594. try {
  18595. var response;
  18596. var responseType = ( this.responseType || '' ).toLowerCase();
  18597. switch ( responseType ) {
  18598. case 'arraybuffer':
  18599. case 'blob':
  18600. var view = new Uint8Array( data.length );
  18601. for ( var i = 0; i < data.length; i ++ ) {
  18602. view[ i ] = data.charCodeAt( i );
  18603. }
  18604. if ( responseType === 'blob' ) {
  18605. response = new Blob( [ view.buffer ], { type: mimeType } );
  18606. } else {
  18607. response = view.buffer;
  18608. }
  18609. break;
  18610. case 'document':
  18611. var parser = new DOMParser();
  18612. response = parser.parseFromString( data, mimeType );
  18613. break;
  18614. case 'json':
  18615. response = JSON.parse( data );
  18616. break;
  18617. default: // 'text' or other
  18618. response = data;
  18619. break;
  18620. }
  18621. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18622. window.setTimeout( function () {
  18623. if ( onLoad ) onLoad( response );
  18624. scope.manager.itemEnd( url );
  18625. }, 0 );
  18626. } catch ( error ) {
  18627. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18628. window.setTimeout( function () {
  18629. if ( onError ) onError( error );
  18630. scope.manager.itemEnd( url );
  18631. scope.manager.itemError( url );
  18632. }, 0 );
  18633. }
  18634. } else {
  18635. // Initialise array for duplicate requests
  18636. loading[ url ] = [];
  18637. loading[ url ].push( {
  18638. onLoad: onLoad,
  18639. onProgress: onProgress,
  18640. onError: onError
  18641. } );
  18642. var request = new XMLHttpRequest();
  18643. request.open( 'GET', url, true );
  18644. request.addEventListener( 'load', function ( event ) {
  18645. var response = this.response;
  18646. Cache.add( url, response );
  18647. var callbacks = loading[ url ];
  18648. delete loading[ url ];
  18649. if ( this.status === 200 || this.status === 0 ) {
  18650. // Some browsers return HTTP Status 0 when using non-http protocol
  18651. // e.g. 'file://' or 'data://'. Handle as success.
  18652. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  18653. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18654. var callback = callbacks[ i ];
  18655. if ( callback.onLoad ) callback.onLoad( response );
  18656. }
  18657. scope.manager.itemEnd( url );
  18658. } else {
  18659. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18660. var callback = callbacks[ i ];
  18661. if ( callback.onError ) callback.onError( event );
  18662. }
  18663. scope.manager.itemEnd( url );
  18664. scope.manager.itemError( url );
  18665. }
  18666. }, false );
  18667. request.addEventListener( 'progress', function ( event ) {
  18668. var callbacks = loading[ url ];
  18669. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18670. var callback = callbacks[ i ];
  18671. if ( callback.onProgress ) callback.onProgress( event );
  18672. }
  18673. }, false );
  18674. request.addEventListener( 'error', function ( event ) {
  18675. var callbacks = loading[ url ];
  18676. delete loading[ url ];
  18677. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18678. var callback = callbacks[ i ];
  18679. if ( callback.onError ) callback.onError( event );
  18680. }
  18681. scope.manager.itemEnd( url );
  18682. scope.manager.itemError( url );
  18683. }, false );
  18684. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  18685. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  18686. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  18687. for ( var header in this.requestHeader ) {
  18688. request.setRequestHeader( header, this.requestHeader[ header ] );
  18689. }
  18690. request.send( null );
  18691. }
  18692. scope.manager.itemStart( url );
  18693. return request;
  18694. },
  18695. setPath: function ( value ) {
  18696. this.path = value;
  18697. return this;
  18698. },
  18699. setResponseType: function ( value ) {
  18700. this.responseType = value;
  18701. return this;
  18702. },
  18703. setWithCredentials: function ( value ) {
  18704. this.withCredentials = value;
  18705. return this;
  18706. },
  18707. setMimeType: function ( value ) {
  18708. this.mimeType = value;
  18709. return this;
  18710. },
  18711. setRequestHeader: function ( value ) {
  18712. this.requestHeader = value;
  18713. return this;
  18714. }
  18715. } );
  18716. /**
  18717. * @author mrdoob / http://mrdoob.com/
  18718. *
  18719. * Abstract Base class to block based textures loader (dds, pvr, ...)
  18720. */
  18721. function CompressedTextureLoader( manager ) {
  18722. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18723. // override in sub classes
  18724. this._parser = null;
  18725. }
  18726. Object.assign( CompressedTextureLoader.prototype, {
  18727. load: function ( url, onLoad, onProgress, onError ) {
  18728. var scope = this;
  18729. var images = [];
  18730. var texture = new CompressedTexture();
  18731. texture.image = images;
  18732. var loader = new FileLoader( this.manager );
  18733. loader.setPath( this.path );
  18734. loader.setResponseType( 'arraybuffer' );
  18735. function loadTexture( i ) {
  18736. loader.load( url[ i ], function ( buffer ) {
  18737. var texDatas = scope._parser( buffer, true );
  18738. images[ i ] = {
  18739. width: texDatas.width,
  18740. height: texDatas.height,
  18741. format: texDatas.format,
  18742. mipmaps: texDatas.mipmaps
  18743. };
  18744. loaded += 1;
  18745. if ( loaded === 6 ) {
  18746. if ( texDatas.mipmapCount === 1 )
  18747. texture.minFilter = LinearFilter;
  18748. texture.format = texDatas.format;
  18749. texture.needsUpdate = true;
  18750. if ( onLoad ) onLoad( texture );
  18751. }
  18752. }, onProgress, onError );
  18753. }
  18754. if ( Array.isArray( url ) ) {
  18755. var loaded = 0;
  18756. for ( var i = 0, il = url.length; i < il; ++ i ) {
  18757. loadTexture( i );
  18758. }
  18759. } else {
  18760. // compressed cubemap texture stored in a single DDS file
  18761. loader.load( url, function ( buffer ) {
  18762. var texDatas = scope._parser( buffer, true );
  18763. if ( texDatas.isCubemap ) {
  18764. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  18765. for ( var f = 0; f < faces; f ++ ) {
  18766. images[ f ] = { mipmaps: [] };
  18767. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  18768. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  18769. images[ f ].format = texDatas.format;
  18770. images[ f ].width = texDatas.width;
  18771. images[ f ].height = texDatas.height;
  18772. }
  18773. }
  18774. } else {
  18775. texture.image.width = texDatas.width;
  18776. texture.image.height = texDatas.height;
  18777. texture.mipmaps = texDatas.mipmaps;
  18778. }
  18779. if ( texDatas.mipmapCount === 1 ) {
  18780. texture.minFilter = LinearFilter;
  18781. }
  18782. texture.format = texDatas.format;
  18783. texture.needsUpdate = true;
  18784. if ( onLoad ) onLoad( texture );
  18785. }, onProgress, onError );
  18786. }
  18787. return texture;
  18788. },
  18789. setPath: function ( value ) {
  18790. this.path = value;
  18791. return this;
  18792. }
  18793. } );
  18794. /**
  18795. * @author Nikos M. / https://github.com/foo123/
  18796. *
  18797. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  18798. */
  18799. function DataTextureLoader( manager ) {
  18800. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18801. // override in sub classes
  18802. this._parser = null;
  18803. }
  18804. Object.assign( DataTextureLoader.prototype, {
  18805. load: function ( url, onLoad, onProgress, onError ) {
  18806. var scope = this;
  18807. var texture = new DataTexture();
  18808. var loader = new FileLoader( this.manager );
  18809. loader.setResponseType( 'arraybuffer' );
  18810. loader.load( url, function ( buffer ) {
  18811. var texData = scope._parser( buffer );
  18812. if ( ! texData ) return;
  18813. if ( undefined !== texData.image ) {
  18814. texture.image = texData.image;
  18815. } else if ( undefined !== texData.data ) {
  18816. texture.image.width = texData.width;
  18817. texture.image.height = texData.height;
  18818. texture.image.data = texData.data;
  18819. }
  18820. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  18821. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  18822. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  18823. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  18824. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  18825. if ( undefined !== texData.format ) {
  18826. texture.format = texData.format;
  18827. }
  18828. if ( undefined !== texData.type ) {
  18829. texture.type = texData.type;
  18830. }
  18831. if ( undefined !== texData.mipmaps ) {
  18832. texture.mipmaps = texData.mipmaps;
  18833. }
  18834. if ( 1 === texData.mipmapCount ) {
  18835. texture.minFilter = LinearFilter;
  18836. }
  18837. texture.needsUpdate = true;
  18838. if ( onLoad ) onLoad( texture, texData );
  18839. }, onProgress, onError );
  18840. return texture;
  18841. }
  18842. } );
  18843. /**
  18844. * @author mrdoob / http://mrdoob.com/
  18845. */
  18846. function ImageLoader( manager ) {
  18847. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18848. }
  18849. Object.assign( ImageLoader.prototype, {
  18850. crossOrigin: 'Anonymous',
  18851. load: function ( url, onLoad, onProgress, onError ) {
  18852. if ( url === undefined ) url = '';
  18853. if ( this.path !== undefined ) url = this.path + url;
  18854. url = this.manager.resolveURL( url );
  18855. var scope = this;
  18856. var cached = Cache.get( url );
  18857. if ( cached !== undefined ) {
  18858. scope.manager.itemStart( url );
  18859. setTimeout( function () {
  18860. if ( onLoad ) onLoad( cached );
  18861. scope.manager.itemEnd( url );
  18862. }, 0 );
  18863. return cached;
  18864. }
  18865. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  18866. function onImageLoad() {
  18867. image.removeEventListener( 'load', onImageLoad, false );
  18868. image.removeEventListener( 'error', onImageError, false );
  18869. Cache.add( url, this );
  18870. if ( onLoad ) onLoad( this );
  18871. scope.manager.itemEnd( url );
  18872. }
  18873. function onImageError( event ) {
  18874. image.removeEventListener( 'load', onImageLoad, false );
  18875. image.removeEventListener( 'error', onImageError, false );
  18876. if ( onError ) onError( event );
  18877. scope.manager.itemEnd( url );
  18878. scope.manager.itemError( url );
  18879. }
  18880. image.addEventListener( 'load', onImageLoad, false );
  18881. image.addEventListener( 'error', onImageError, false );
  18882. if ( url.substr( 0, 5 ) !== 'data:' ) {
  18883. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  18884. }
  18885. scope.manager.itemStart( url );
  18886. image.src = url;
  18887. return image;
  18888. },
  18889. setCrossOrigin: function ( value ) {
  18890. this.crossOrigin = value;
  18891. return this;
  18892. },
  18893. setPath: function ( value ) {
  18894. this.path = value;
  18895. return this;
  18896. }
  18897. } );
  18898. /**
  18899. * @author mrdoob / http://mrdoob.com/
  18900. */
  18901. function CubeTextureLoader( manager ) {
  18902. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18903. }
  18904. Object.assign( CubeTextureLoader.prototype, {
  18905. crossOrigin: 'Anonymous',
  18906. load: function ( urls, onLoad, onProgress, onError ) {
  18907. var texture = new CubeTexture();
  18908. var loader = new ImageLoader( this.manager );
  18909. loader.setCrossOrigin( this.crossOrigin );
  18910. loader.setPath( this.path );
  18911. var loaded = 0;
  18912. function loadTexture( i ) {
  18913. loader.load( urls[ i ], function ( image ) {
  18914. texture.images[ i ] = image;
  18915. loaded ++;
  18916. if ( loaded === 6 ) {
  18917. texture.needsUpdate = true;
  18918. if ( onLoad ) onLoad( texture );
  18919. }
  18920. }, undefined, onError );
  18921. }
  18922. for ( var i = 0; i < urls.length; ++ i ) {
  18923. loadTexture( i );
  18924. }
  18925. return texture;
  18926. },
  18927. setCrossOrigin: function ( value ) {
  18928. this.crossOrigin = value;
  18929. return this;
  18930. },
  18931. setPath: function ( value ) {
  18932. this.path = value;
  18933. return this;
  18934. }
  18935. } );
  18936. /**
  18937. * @author mrdoob / http://mrdoob.com/
  18938. */
  18939. function TextureLoader( manager ) {
  18940. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18941. }
  18942. Object.assign( TextureLoader.prototype, {
  18943. crossOrigin: 'Anonymous',
  18944. load: function ( url, onLoad, onProgress, onError ) {
  18945. var texture = new Texture();
  18946. var loader = new ImageLoader( this.manager );
  18947. loader.setCrossOrigin( this.crossOrigin );
  18948. loader.setPath( this.path );
  18949. loader.load( url, function ( image ) {
  18950. texture.image = image;
  18951. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  18952. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  18953. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  18954. texture.needsUpdate = true;
  18955. if ( onLoad !== undefined ) {
  18956. onLoad( texture );
  18957. }
  18958. }, onProgress, onError );
  18959. return texture;
  18960. },
  18961. setCrossOrigin: function ( value ) {
  18962. this.crossOrigin = value;
  18963. return this;
  18964. },
  18965. setPath: function ( value ) {
  18966. this.path = value;
  18967. return this;
  18968. }
  18969. } );
  18970. /**
  18971. * @author zz85 / http://www.lab4games.net/zz85/blog
  18972. * Extensible curve object
  18973. *
  18974. * Some common of curve methods:
  18975. * .getPoint( t, optionalTarget ), .getTangent( t )
  18976. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  18977. * .getPoints(), .getSpacedPoints()
  18978. * .getLength()
  18979. * .updateArcLengths()
  18980. *
  18981. * This following curves inherit from THREE.Curve:
  18982. *
  18983. * -- 2D curves --
  18984. * THREE.ArcCurve
  18985. * THREE.CubicBezierCurve
  18986. * THREE.EllipseCurve
  18987. * THREE.LineCurve
  18988. * THREE.QuadraticBezierCurve
  18989. * THREE.SplineCurve
  18990. *
  18991. * -- 3D curves --
  18992. * THREE.CatmullRomCurve3
  18993. * THREE.CubicBezierCurve3
  18994. * THREE.LineCurve3
  18995. * THREE.QuadraticBezierCurve3
  18996. *
  18997. * A series of curves can be represented as a THREE.CurvePath.
  18998. *
  18999. **/
  19000. /**************************************************************
  19001. * Abstract Curve base class
  19002. **************************************************************/
  19003. function Curve() {
  19004. this.type = 'Curve';
  19005. this.arcLengthDivisions = 200;
  19006. }
  19007. Object.assign( Curve.prototype, {
  19008. // Virtual base class method to overwrite and implement in subclasses
  19009. // - t [0 .. 1]
  19010. getPoint: function ( /* t, optionalTarget */ ) {
  19011. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  19012. return null;
  19013. },
  19014. // Get point at relative position in curve according to arc length
  19015. // - u [0 .. 1]
  19016. getPointAt: function ( u, optionalTarget ) {
  19017. var t = this.getUtoTmapping( u );
  19018. return this.getPoint( t, optionalTarget );
  19019. },
  19020. // Get sequence of points using getPoint( t )
  19021. getPoints: function ( divisions ) {
  19022. if ( divisions === undefined ) divisions = 5;
  19023. var points = [];
  19024. for ( var d = 0; d <= divisions; d ++ ) {
  19025. points.push( this.getPoint( d / divisions ) );
  19026. }
  19027. return points;
  19028. },
  19029. // Get sequence of points using getPointAt( u )
  19030. getSpacedPoints: function ( divisions ) {
  19031. if ( divisions === undefined ) divisions = 5;
  19032. var points = [];
  19033. for ( var d = 0; d <= divisions; d ++ ) {
  19034. points.push( this.getPointAt( d / divisions ) );
  19035. }
  19036. return points;
  19037. },
  19038. // Get total curve arc length
  19039. getLength: function () {
  19040. var lengths = this.getLengths();
  19041. return lengths[ lengths.length - 1 ];
  19042. },
  19043. // Get list of cumulative segment lengths
  19044. getLengths: function ( divisions ) {
  19045. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  19046. if ( this.cacheArcLengths &&
  19047. ( this.cacheArcLengths.length === divisions + 1 ) &&
  19048. ! this.needsUpdate ) {
  19049. return this.cacheArcLengths;
  19050. }
  19051. this.needsUpdate = false;
  19052. var cache = [];
  19053. var current, last = this.getPoint( 0 );
  19054. var p, sum = 0;
  19055. cache.push( 0 );
  19056. for ( p = 1; p <= divisions; p ++ ) {
  19057. current = this.getPoint( p / divisions );
  19058. sum += current.distanceTo( last );
  19059. cache.push( sum );
  19060. last = current;
  19061. }
  19062. this.cacheArcLengths = cache;
  19063. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  19064. },
  19065. updateArcLengths: function () {
  19066. this.needsUpdate = true;
  19067. this.getLengths();
  19068. },
  19069. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  19070. getUtoTmapping: function ( u, distance ) {
  19071. var arcLengths = this.getLengths();
  19072. var i = 0, il = arcLengths.length;
  19073. var targetArcLength; // The targeted u distance value to get
  19074. if ( distance ) {
  19075. targetArcLength = distance;
  19076. } else {
  19077. targetArcLength = u * arcLengths[ il - 1 ];
  19078. }
  19079. // binary search for the index with largest value smaller than target u distance
  19080. var low = 0, high = il - 1, comparison;
  19081. while ( low <= high ) {
  19082. 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
  19083. comparison = arcLengths[ i ] - targetArcLength;
  19084. if ( comparison < 0 ) {
  19085. low = i + 1;
  19086. } else if ( comparison > 0 ) {
  19087. high = i - 1;
  19088. } else {
  19089. high = i;
  19090. break;
  19091. // DONE
  19092. }
  19093. }
  19094. i = high;
  19095. if ( arcLengths[ i ] === targetArcLength ) {
  19096. return i / ( il - 1 );
  19097. }
  19098. // we could get finer grain at lengths, or use simple interpolation between two points
  19099. var lengthBefore = arcLengths[ i ];
  19100. var lengthAfter = arcLengths[ i + 1 ];
  19101. var segmentLength = lengthAfter - lengthBefore;
  19102. // determine where we are between the 'before' and 'after' points
  19103. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  19104. // add that fractional amount to t
  19105. var t = ( i + segmentFraction ) / ( il - 1 );
  19106. return t;
  19107. },
  19108. // Returns a unit vector tangent at t
  19109. // In case any sub curve does not implement its tangent derivation,
  19110. // 2 points a small delta apart will be used to find its gradient
  19111. // which seems to give a reasonable approximation
  19112. getTangent: function ( t ) {
  19113. var delta = 0.0001;
  19114. var t1 = t - delta;
  19115. var t2 = t + delta;
  19116. // Capping in case of danger
  19117. if ( t1 < 0 ) t1 = 0;
  19118. if ( t2 > 1 ) t2 = 1;
  19119. var pt1 = this.getPoint( t1 );
  19120. var pt2 = this.getPoint( t2 );
  19121. var vec = pt2.clone().sub( pt1 );
  19122. return vec.normalize();
  19123. },
  19124. getTangentAt: function ( u ) {
  19125. var t = this.getUtoTmapping( u );
  19126. return this.getTangent( t );
  19127. },
  19128. computeFrenetFrames: function ( segments, closed ) {
  19129. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19130. var normal = new Vector3();
  19131. var tangents = [];
  19132. var normals = [];
  19133. var binormals = [];
  19134. var vec = new Vector3();
  19135. var mat = new Matrix4();
  19136. var i, u, theta;
  19137. // compute the tangent vectors for each segment on the curve
  19138. for ( i = 0; i <= segments; i ++ ) {
  19139. u = i / segments;
  19140. tangents[ i ] = this.getTangentAt( u );
  19141. tangents[ i ].normalize();
  19142. }
  19143. // select an initial normal vector perpendicular to the first tangent vector,
  19144. // and in the direction of the minimum tangent xyz component
  19145. normals[ 0 ] = new Vector3();
  19146. binormals[ 0 ] = new Vector3();
  19147. var min = Number.MAX_VALUE;
  19148. var tx = Math.abs( tangents[ 0 ].x );
  19149. var ty = Math.abs( tangents[ 0 ].y );
  19150. var tz = Math.abs( tangents[ 0 ].z );
  19151. if ( tx <= min ) {
  19152. min = tx;
  19153. normal.set( 1, 0, 0 );
  19154. }
  19155. if ( ty <= min ) {
  19156. min = ty;
  19157. normal.set( 0, 1, 0 );
  19158. }
  19159. if ( tz <= min ) {
  19160. normal.set( 0, 0, 1 );
  19161. }
  19162. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  19163. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  19164. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  19165. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  19166. for ( i = 1; i <= segments; i ++ ) {
  19167. normals[ i ] = normals[ i - 1 ].clone();
  19168. binormals[ i ] = binormals[ i - 1 ].clone();
  19169. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  19170. if ( vec.length() > Number.EPSILON ) {
  19171. vec.normalize();
  19172. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  19173. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  19174. }
  19175. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19176. }
  19177. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  19178. if ( closed === true ) {
  19179. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  19180. theta /= segments;
  19181. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  19182. theta = - theta;
  19183. }
  19184. for ( i = 1; i <= segments; i ++ ) {
  19185. // twist a little...
  19186. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  19187. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19188. }
  19189. }
  19190. return {
  19191. tangents: tangents,
  19192. normals: normals,
  19193. binormals: binormals
  19194. };
  19195. },
  19196. clone: function () {
  19197. return new this.constructor().copy( this );
  19198. },
  19199. copy: function ( source ) {
  19200. this.arcLengthDivisions = source.arcLengthDivisions;
  19201. return this;
  19202. },
  19203. toJSON: function () {
  19204. var data = {
  19205. metadata: {
  19206. version: 4.5,
  19207. type: 'Curve',
  19208. generator: 'Curve.toJSON'
  19209. }
  19210. };
  19211. data.arcLengthDivisions = this.arcLengthDivisions;
  19212. data.type = this.type;
  19213. return data;
  19214. },
  19215. fromJSON: function ( json ) {
  19216. this.arcLengthDivisions = json.arcLengthDivisions;
  19217. return this;
  19218. }
  19219. } );
  19220. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  19221. Curve.call( this );
  19222. this.type = 'EllipseCurve';
  19223. this.aX = aX || 0;
  19224. this.aY = aY || 0;
  19225. this.xRadius = xRadius || 1;
  19226. this.yRadius = yRadius || 1;
  19227. this.aStartAngle = aStartAngle || 0;
  19228. this.aEndAngle = aEndAngle || 2 * Math.PI;
  19229. this.aClockwise = aClockwise || false;
  19230. this.aRotation = aRotation || 0;
  19231. }
  19232. EllipseCurve.prototype = Object.create( Curve.prototype );
  19233. EllipseCurve.prototype.constructor = EllipseCurve;
  19234. EllipseCurve.prototype.isEllipseCurve = true;
  19235. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19236. var point = optionalTarget || new Vector2();
  19237. var twoPi = Math.PI * 2;
  19238. var deltaAngle = this.aEndAngle - this.aStartAngle;
  19239. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  19240. // ensures that deltaAngle is 0 .. 2 PI
  19241. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  19242. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  19243. if ( deltaAngle < Number.EPSILON ) {
  19244. if ( samePoints ) {
  19245. deltaAngle = 0;
  19246. } else {
  19247. deltaAngle = twoPi;
  19248. }
  19249. }
  19250. if ( this.aClockwise === true && ! samePoints ) {
  19251. if ( deltaAngle === twoPi ) {
  19252. deltaAngle = - twoPi;
  19253. } else {
  19254. deltaAngle = deltaAngle - twoPi;
  19255. }
  19256. }
  19257. var angle = this.aStartAngle + t * deltaAngle;
  19258. var x = this.aX + this.xRadius * Math.cos( angle );
  19259. var y = this.aY + this.yRadius * Math.sin( angle );
  19260. if ( this.aRotation !== 0 ) {
  19261. var cos = Math.cos( this.aRotation );
  19262. var sin = Math.sin( this.aRotation );
  19263. var tx = x - this.aX;
  19264. var ty = y - this.aY;
  19265. // Rotate the point about the center of the ellipse.
  19266. x = tx * cos - ty * sin + this.aX;
  19267. y = tx * sin + ty * cos + this.aY;
  19268. }
  19269. return point.set( x, y );
  19270. };
  19271. EllipseCurve.prototype.copy = function ( source ) {
  19272. Curve.prototype.copy.call( this, source );
  19273. this.aX = source.aX;
  19274. this.aY = source.aY;
  19275. this.xRadius = source.xRadius;
  19276. this.yRadius = source.yRadius;
  19277. this.aStartAngle = source.aStartAngle;
  19278. this.aEndAngle = source.aEndAngle;
  19279. this.aClockwise = source.aClockwise;
  19280. this.aRotation = source.aRotation;
  19281. return this;
  19282. };
  19283. EllipseCurve.prototype.toJSON = function () {
  19284. var data = Curve.prototype.toJSON.call( this );
  19285. data.aX = this.aX;
  19286. data.aY = this.aY;
  19287. data.xRadius = this.xRadius;
  19288. data.yRadius = this.yRadius;
  19289. data.aStartAngle = this.aStartAngle;
  19290. data.aEndAngle = this.aEndAngle;
  19291. data.aClockwise = this.aClockwise;
  19292. data.aRotation = this.aRotation;
  19293. return data;
  19294. };
  19295. EllipseCurve.prototype.fromJSON = function ( json ) {
  19296. Curve.prototype.fromJSON.call( this, json );
  19297. this.aX = json.aX;
  19298. this.aY = json.aY;
  19299. this.xRadius = json.xRadius;
  19300. this.yRadius = json.yRadius;
  19301. this.aStartAngle = json.aStartAngle;
  19302. this.aEndAngle = json.aEndAngle;
  19303. this.aClockwise = json.aClockwise;
  19304. this.aRotation = json.aRotation;
  19305. return this;
  19306. };
  19307. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  19308. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  19309. this.type = 'ArcCurve';
  19310. }
  19311. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  19312. ArcCurve.prototype.constructor = ArcCurve;
  19313. ArcCurve.prototype.isArcCurve = true;
  19314. /**
  19315. * @author zz85 https://github.com/zz85
  19316. *
  19317. * Centripetal CatmullRom Curve - which is useful for avoiding
  19318. * cusps and self-intersections in non-uniform catmull rom curves.
  19319. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  19320. *
  19321. * curve.type accepts centripetal(default), chordal and catmullrom
  19322. * curve.tension is used for catmullrom which defaults to 0.5
  19323. */
  19324. /*
  19325. Based on an optimized c++ solution in
  19326. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  19327. - http://ideone.com/NoEbVM
  19328. This CubicPoly class could be used for reusing some variables and calculations,
  19329. but for three.js curve use, it could be possible inlined and flatten into a single function call
  19330. which can be placed in CurveUtils.
  19331. */
  19332. function CubicPoly() {
  19333. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  19334. /*
  19335. * Compute coefficients for a cubic polynomial
  19336. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  19337. * such that
  19338. * p(0) = x0, p(1) = x1
  19339. * and
  19340. * p'(0) = t0, p'(1) = t1.
  19341. */
  19342. function init( x0, x1, t0, t1 ) {
  19343. c0 = x0;
  19344. c1 = t0;
  19345. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  19346. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  19347. }
  19348. return {
  19349. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  19350. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  19351. },
  19352. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  19353. // compute tangents when parameterized in [t1,t2]
  19354. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  19355. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  19356. // rescale tangents for parametrization in [0,1]
  19357. t1 *= dt1;
  19358. t2 *= dt1;
  19359. init( x1, x2, t1, t2 );
  19360. },
  19361. calc: function ( t ) {
  19362. var t2 = t * t;
  19363. var t3 = t2 * t;
  19364. return c0 + c1 * t + c2 * t2 + c3 * t3;
  19365. }
  19366. };
  19367. }
  19368. //
  19369. var tmp = new Vector3();
  19370. var px = new CubicPoly();
  19371. var py = new CubicPoly();
  19372. var pz = new CubicPoly();
  19373. function CatmullRomCurve3( points, closed, curveType, tension ) {
  19374. Curve.call( this );
  19375. this.type = 'CatmullRomCurve3';
  19376. this.points = points || [];
  19377. this.closed = closed || false;
  19378. this.curveType = curveType || 'centripetal';
  19379. this.tension = tension || 0.5;
  19380. }
  19381. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  19382. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  19383. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  19384. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19385. var point = optionalTarget || new Vector3();
  19386. var points = this.points;
  19387. var l = points.length;
  19388. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  19389. var intPoint = Math.floor( p );
  19390. var weight = p - intPoint;
  19391. if ( this.closed ) {
  19392. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  19393. } else if ( weight === 0 && intPoint === l - 1 ) {
  19394. intPoint = l - 2;
  19395. weight = 1;
  19396. }
  19397. var p0, p1, p2, p3; // 4 points
  19398. if ( this.closed || intPoint > 0 ) {
  19399. p0 = points[ ( intPoint - 1 ) % l ];
  19400. } else {
  19401. // extrapolate first point
  19402. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  19403. p0 = tmp;
  19404. }
  19405. p1 = points[ intPoint % l ];
  19406. p2 = points[ ( intPoint + 1 ) % l ];
  19407. if ( this.closed || intPoint + 2 < l ) {
  19408. p3 = points[ ( intPoint + 2 ) % l ];
  19409. } else {
  19410. // extrapolate last point
  19411. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  19412. p3 = tmp;
  19413. }
  19414. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  19415. // init Centripetal / Chordal Catmull-Rom
  19416. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  19417. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  19418. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  19419. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  19420. // safety check for repeated points
  19421. if ( dt1 < 1e-4 ) dt1 = 1.0;
  19422. if ( dt0 < 1e-4 ) dt0 = dt1;
  19423. if ( dt2 < 1e-4 ) dt2 = dt1;
  19424. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  19425. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  19426. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  19427. } else if ( this.curveType === 'catmullrom' ) {
  19428. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  19429. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  19430. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  19431. }
  19432. point.set(
  19433. px.calc( weight ),
  19434. py.calc( weight ),
  19435. pz.calc( weight )
  19436. );
  19437. return point;
  19438. };
  19439. CatmullRomCurve3.prototype.copy = function ( source ) {
  19440. Curve.prototype.copy.call( this, source );
  19441. this.points = [];
  19442. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19443. var point = source.points[ i ];
  19444. this.points.push( point.clone() );
  19445. }
  19446. this.closed = source.closed;
  19447. this.curveType = source.curveType;
  19448. this.tension = source.tension;
  19449. return this;
  19450. };
  19451. CatmullRomCurve3.prototype.toJSON = function () {
  19452. var data = Curve.prototype.toJSON.call( this );
  19453. data.points = [];
  19454. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  19455. var point = this.points[ i ];
  19456. data.points.push( point.toArray() );
  19457. }
  19458. data.closed = this.closed;
  19459. data.curveType = this.curveType;
  19460. data.tension = this.tension;
  19461. return data;
  19462. };
  19463. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  19464. Curve.prototype.fromJSON.call( this, json );
  19465. this.points = [];
  19466. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  19467. var point = json.points[ i ];
  19468. this.points.push( new Vector3().fromArray( point ) );
  19469. }
  19470. this.closed = json.closed;
  19471. this.curveType = json.curveType;
  19472. this.tension = json.tension;
  19473. return this;
  19474. };
  19475. /**
  19476. * @author zz85 / http://www.lab4games.net/zz85/blog
  19477. *
  19478. * Bezier Curves formulas obtained from
  19479. * http://en.wikipedia.org/wiki/Bézier_curve
  19480. */
  19481. function CatmullRom( t, p0, p1, p2, p3 ) {
  19482. var v0 = ( p2 - p0 ) * 0.5;
  19483. var v1 = ( p3 - p1 ) * 0.5;
  19484. var t2 = t * t;
  19485. var t3 = t * t2;
  19486. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19487. }
  19488. //
  19489. function QuadraticBezierP0( t, p ) {
  19490. var k = 1 - t;
  19491. return k * k * p;
  19492. }
  19493. function QuadraticBezierP1( t, p ) {
  19494. return 2 * ( 1 - t ) * t * p;
  19495. }
  19496. function QuadraticBezierP2( t, p ) {
  19497. return t * t * p;
  19498. }
  19499. function QuadraticBezier( t, p0, p1, p2 ) {
  19500. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  19501. QuadraticBezierP2( t, p2 );
  19502. }
  19503. //
  19504. function CubicBezierP0( t, p ) {
  19505. var k = 1 - t;
  19506. return k * k * k * p;
  19507. }
  19508. function CubicBezierP1( t, p ) {
  19509. var k = 1 - t;
  19510. return 3 * k * k * t * p;
  19511. }
  19512. function CubicBezierP2( t, p ) {
  19513. return 3 * ( 1 - t ) * t * t * p;
  19514. }
  19515. function CubicBezierP3( t, p ) {
  19516. return t * t * t * p;
  19517. }
  19518. function CubicBezier( t, p0, p1, p2, p3 ) {
  19519. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  19520. CubicBezierP3( t, p3 );
  19521. }
  19522. function CubicBezierCurve( v0, v1, v2, v3 ) {
  19523. Curve.call( this );
  19524. this.type = 'CubicBezierCurve';
  19525. this.v0 = v0 || new Vector2();
  19526. this.v1 = v1 || new Vector2();
  19527. this.v2 = v2 || new Vector2();
  19528. this.v3 = v3 || new Vector2();
  19529. }
  19530. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  19531. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  19532. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  19533. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19534. var point = optionalTarget || new Vector2();
  19535. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19536. point.set(
  19537. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19538. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  19539. );
  19540. return point;
  19541. };
  19542. CubicBezierCurve.prototype.copy = function ( source ) {
  19543. Curve.prototype.copy.call( this, source );
  19544. this.v0.copy( source.v0 );
  19545. this.v1.copy( source.v1 );
  19546. this.v2.copy( source.v2 );
  19547. this.v3.copy( source.v3 );
  19548. return this;
  19549. };
  19550. CubicBezierCurve.prototype.toJSON = function () {
  19551. var data = Curve.prototype.toJSON.call( this );
  19552. data.v0 = this.v0.toArray();
  19553. data.v1 = this.v1.toArray();
  19554. data.v2 = this.v2.toArray();
  19555. data.v3 = this.v3.toArray();
  19556. return data;
  19557. };
  19558. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  19559. Curve.prototype.fromJSON.call( this, json );
  19560. this.v0.fromArray( json.v0 );
  19561. this.v1.fromArray( json.v1 );
  19562. this.v2.fromArray( json.v2 );
  19563. this.v3.fromArray( json.v3 );
  19564. return this;
  19565. };
  19566. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  19567. Curve.call( this );
  19568. this.type = 'CubicBezierCurve3';
  19569. this.v0 = v0 || new Vector3();
  19570. this.v1 = v1 || new Vector3();
  19571. this.v2 = v2 || new Vector3();
  19572. this.v3 = v3 || new Vector3();
  19573. }
  19574. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  19575. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  19576. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  19577. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19578. var point = optionalTarget || new Vector3();
  19579. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19580. point.set(
  19581. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19582. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  19583. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  19584. );
  19585. return point;
  19586. };
  19587. CubicBezierCurve3.prototype.copy = function ( source ) {
  19588. Curve.prototype.copy.call( this, source );
  19589. this.v0.copy( source.v0 );
  19590. this.v1.copy( source.v1 );
  19591. this.v2.copy( source.v2 );
  19592. this.v3.copy( source.v3 );
  19593. return this;
  19594. };
  19595. CubicBezierCurve3.prototype.toJSON = function () {
  19596. var data = Curve.prototype.toJSON.call( this );
  19597. data.v0 = this.v0.toArray();
  19598. data.v1 = this.v1.toArray();
  19599. data.v2 = this.v2.toArray();
  19600. data.v3 = this.v3.toArray();
  19601. return data;
  19602. };
  19603. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  19604. Curve.prototype.fromJSON.call( this, json );
  19605. this.v0.fromArray( json.v0 );
  19606. this.v1.fromArray( json.v1 );
  19607. this.v2.fromArray( json.v2 );
  19608. this.v3.fromArray( json.v3 );
  19609. return this;
  19610. };
  19611. function LineCurve( v1, v2 ) {
  19612. Curve.call( this );
  19613. this.type = 'LineCurve';
  19614. this.v1 = v1 || new Vector2();
  19615. this.v2 = v2 || new Vector2();
  19616. }
  19617. LineCurve.prototype = Object.create( Curve.prototype );
  19618. LineCurve.prototype.constructor = LineCurve;
  19619. LineCurve.prototype.isLineCurve = true;
  19620. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19621. var point = optionalTarget || new Vector2();
  19622. if ( t === 1 ) {
  19623. point.copy( this.v2 );
  19624. } else {
  19625. point.copy( this.v2 ).sub( this.v1 );
  19626. point.multiplyScalar( t ).add( this.v1 );
  19627. }
  19628. return point;
  19629. };
  19630. // Line curve is linear, so we can overwrite default getPointAt
  19631. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  19632. return this.getPoint( u, optionalTarget );
  19633. };
  19634. LineCurve.prototype.getTangent = function ( /* t */ ) {
  19635. var tangent = this.v2.clone().sub( this.v1 );
  19636. return tangent.normalize();
  19637. };
  19638. LineCurve.prototype.copy = function ( source ) {
  19639. Curve.prototype.copy.call( this, source );
  19640. this.v1.copy( source.v1 );
  19641. this.v2.copy( source.v2 );
  19642. return this;
  19643. };
  19644. LineCurve.prototype.toJSON = function () {
  19645. var data = Curve.prototype.toJSON.call( this );
  19646. data.v1 = this.v1.toArray();
  19647. data.v2 = this.v2.toArray();
  19648. return data;
  19649. };
  19650. LineCurve.prototype.fromJSON = function ( json ) {
  19651. Curve.prototype.fromJSON.call( this, json );
  19652. this.v1.fromArray( json.v1 );
  19653. this.v2.fromArray( json.v2 );
  19654. return this;
  19655. };
  19656. function LineCurve3( v1, v2 ) {
  19657. Curve.call( this );
  19658. this.type = 'LineCurve3';
  19659. this.v1 = v1 || new Vector3();
  19660. this.v2 = v2 || new Vector3();
  19661. }
  19662. LineCurve3.prototype = Object.create( Curve.prototype );
  19663. LineCurve3.prototype.constructor = LineCurve3;
  19664. LineCurve3.prototype.isLineCurve3 = true;
  19665. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19666. var point = optionalTarget || new Vector3();
  19667. if ( t === 1 ) {
  19668. point.copy( this.v2 );
  19669. } else {
  19670. point.copy( this.v2 ).sub( this.v1 );
  19671. point.multiplyScalar( t ).add( this.v1 );
  19672. }
  19673. return point;
  19674. };
  19675. // Line curve is linear, so we can overwrite default getPointAt
  19676. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  19677. return this.getPoint( u, optionalTarget );
  19678. };
  19679. LineCurve3.prototype.copy = function ( source ) {
  19680. Curve.prototype.copy.call( this, source );
  19681. this.v1.copy( source.v1 );
  19682. this.v2.copy( source.v2 );
  19683. return this;
  19684. };
  19685. LineCurve3.prototype.toJSON = function () {
  19686. var data = Curve.prototype.toJSON.call( this );
  19687. data.v1 = this.v1.toArray();
  19688. data.v2 = this.v2.toArray();
  19689. return data;
  19690. };
  19691. LineCurve3.prototype.fromJSON = function ( json ) {
  19692. Curve.prototype.fromJSON.call( this, json );
  19693. this.v1.fromArray( json.v1 );
  19694. this.v2.fromArray( json.v2 );
  19695. return this;
  19696. };
  19697. function QuadraticBezierCurve( v0, v1, v2 ) {
  19698. Curve.call( this );
  19699. this.type = 'QuadraticBezierCurve';
  19700. this.v0 = v0 || new Vector2();
  19701. this.v1 = v1 || new Vector2();
  19702. this.v2 = v2 || new Vector2();
  19703. }
  19704. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  19705. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  19706. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  19707. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19708. var point = optionalTarget || new Vector2();
  19709. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19710. point.set(
  19711. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19712. QuadraticBezier( t, v0.y, v1.y, v2.y )
  19713. );
  19714. return point;
  19715. };
  19716. QuadraticBezierCurve.prototype.copy = function ( source ) {
  19717. Curve.prototype.copy.call( this, source );
  19718. this.v0.copy( source.v0 );
  19719. this.v1.copy( source.v1 );
  19720. this.v2.copy( source.v2 );
  19721. return this;
  19722. };
  19723. QuadraticBezierCurve.prototype.toJSON = function () {
  19724. var data = Curve.prototype.toJSON.call( this );
  19725. data.v0 = this.v0.toArray();
  19726. data.v1 = this.v1.toArray();
  19727. data.v2 = this.v2.toArray();
  19728. return data;
  19729. };
  19730. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  19731. Curve.prototype.fromJSON.call( this, json );
  19732. this.v0.fromArray( json.v0 );
  19733. this.v1.fromArray( json.v1 );
  19734. this.v2.fromArray( json.v2 );
  19735. return this;
  19736. };
  19737. function QuadraticBezierCurve3( v0, v1, v2 ) {
  19738. Curve.call( this );
  19739. this.type = 'QuadraticBezierCurve3';
  19740. this.v0 = v0 || new Vector3();
  19741. this.v1 = v1 || new Vector3();
  19742. this.v2 = v2 || new Vector3();
  19743. }
  19744. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  19745. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  19746. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  19747. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19748. var point = optionalTarget || new Vector3();
  19749. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19750. point.set(
  19751. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19752. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  19753. QuadraticBezier( t, v0.z, v1.z, v2.z )
  19754. );
  19755. return point;
  19756. };
  19757. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  19758. Curve.prototype.copy.call( this, source );
  19759. this.v0.copy( source.v0 );
  19760. this.v1.copy( source.v1 );
  19761. this.v2.copy( source.v2 );
  19762. return this;
  19763. };
  19764. QuadraticBezierCurve3.prototype.toJSON = function () {
  19765. var data = Curve.prototype.toJSON.call( this );
  19766. data.v0 = this.v0.toArray();
  19767. data.v1 = this.v1.toArray();
  19768. data.v2 = this.v2.toArray();
  19769. return data;
  19770. };
  19771. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  19772. Curve.prototype.fromJSON.call( this, json );
  19773. this.v0.fromArray( json.v0 );
  19774. this.v1.fromArray( json.v1 );
  19775. this.v2.fromArray( json.v2 );
  19776. return this;
  19777. };
  19778. function SplineCurve( points /* array of Vector2 */ ) {
  19779. Curve.call( this );
  19780. this.type = 'SplineCurve';
  19781. this.points = points || [];
  19782. }
  19783. SplineCurve.prototype = Object.create( Curve.prototype );
  19784. SplineCurve.prototype.constructor = SplineCurve;
  19785. SplineCurve.prototype.isSplineCurve = true;
  19786. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19787. var point = optionalTarget || new Vector2();
  19788. var points = this.points;
  19789. var p = ( points.length - 1 ) * t;
  19790. var intPoint = Math.floor( p );
  19791. var weight = p - intPoint;
  19792. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  19793. var p1 = points[ intPoint ];
  19794. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  19795. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  19796. point.set(
  19797. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  19798. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  19799. );
  19800. return point;
  19801. };
  19802. SplineCurve.prototype.copy = function ( source ) {
  19803. Curve.prototype.copy.call( this, source );
  19804. this.points = [];
  19805. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19806. var point = source.points[ i ];
  19807. this.points.push( point.clone() );
  19808. }
  19809. return this;
  19810. };
  19811. SplineCurve.prototype.toJSON = function () {
  19812. var data = Curve.prototype.toJSON.call( this );
  19813. data.points = [];
  19814. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  19815. var point = this.points[ i ];
  19816. data.points.push( point.toArray() );
  19817. }
  19818. return data;
  19819. };
  19820. SplineCurve.prototype.fromJSON = function ( json ) {
  19821. Curve.prototype.fromJSON.call( this, json );
  19822. this.points = [];
  19823. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  19824. var point = json.points[ i ];
  19825. this.points.push( new Vector2().fromArray( point ) );
  19826. }
  19827. return this;
  19828. };
  19829. var Curves = Object.freeze({
  19830. ArcCurve: ArcCurve,
  19831. CatmullRomCurve3: CatmullRomCurve3,
  19832. CubicBezierCurve: CubicBezierCurve,
  19833. CubicBezierCurve3: CubicBezierCurve3,
  19834. EllipseCurve: EllipseCurve,
  19835. LineCurve: LineCurve,
  19836. LineCurve3: LineCurve3,
  19837. QuadraticBezierCurve: QuadraticBezierCurve,
  19838. QuadraticBezierCurve3: QuadraticBezierCurve3,
  19839. SplineCurve: SplineCurve
  19840. });
  19841. /**
  19842. * @author zz85 / http://www.lab4games.net/zz85/blog
  19843. *
  19844. **/
  19845. /**************************************************************
  19846. * Curved Path - a curve path is simply a array of connected
  19847. * curves, but retains the api of a curve
  19848. **************************************************************/
  19849. function CurvePath() {
  19850. Curve.call( this );
  19851. this.type = 'CurvePath';
  19852. this.curves = [];
  19853. this.autoClose = false; // Automatically closes the path
  19854. }
  19855. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  19856. constructor: CurvePath,
  19857. add: function ( curve ) {
  19858. this.curves.push( curve );
  19859. },
  19860. closePath: function () {
  19861. // Add a line curve if start and end of lines are not connected
  19862. var startPoint = this.curves[ 0 ].getPoint( 0 );
  19863. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  19864. if ( ! startPoint.equals( endPoint ) ) {
  19865. this.curves.push( new LineCurve( endPoint, startPoint ) );
  19866. }
  19867. },
  19868. // To get accurate point with reference to
  19869. // entire path distance at time t,
  19870. // following has to be done:
  19871. // 1. Length of each sub path have to be known
  19872. // 2. Locate and identify type of curve
  19873. // 3. Get t for the curve
  19874. // 4. Return curve.getPointAt(t')
  19875. getPoint: function ( t ) {
  19876. var d = t * this.getLength();
  19877. var curveLengths = this.getCurveLengths();
  19878. var i = 0;
  19879. // To think about boundaries points.
  19880. while ( i < curveLengths.length ) {
  19881. if ( curveLengths[ i ] >= d ) {
  19882. var diff = curveLengths[ i ] - d;
  19883. var curve = this.curves[ i ];
  19884. var segmentLength = curve.getLength();
  19885. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  19886. return curve.getPointAt( u );
  19887. }
  19888. i ++;
  19889. }
  19890. return null;
  19891. // loop where sum != 0, sum > d , sum+1 <d
  19892. },
  19893. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  19894. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  19895. // getPoint() depends on getLength
  19896. getLength: function () {
  19897. var lens = this.getCurveLengths();
  19898. return lens[ lens.length - 1 ];
  19899. },
  19900. // cacheLengths must be recalculated.
  19901. updateArcLengths: function () {
  19902. this.needsUpdate = true;
  19903. this.cacheLengths = null;
  19904. this.getCurveLengths();
  19905. },
  19906. // Compute lengths and cache them
  19907. // We cannot overwrite getLengths() because UtoT mapping uses it.
  19908. getCurveLengths: function () {
  19909. // We use cache values if curves and cache array are same length
  19910. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  19911. return this.cacheLengths;
  19912. }
  19913. // Get length of sub-curve
  19914. // Push sums into cached array
  19915. var lengths = [], sums = 0;
  19916. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19917. sums += this.curves[ i ].getLength();
  19918. lengths.push( sums );
  19919. }
  19920. this.cacheLengths = lengths;
  19921. return lengths;
  19922. },
  19923. getSpacedPoints: function ( divisions ) {
  19924. if ( divisions === undefined ) divisions = 40;
  19925. var points = [];
  19926. for ( var i = 0; i <= divisions; i ++ ) {
  19927. points.push( this.getPoint( i / divisions ) );
  19928. }
  19929. if ( this.autoClose ) {
  19930. points.push( points[ 0 ] );
  19931. }
  19932. return points;
  19933. },
  19934. getPoints: function ( divisions ) {
  19935. divisions = divisions || 12;
  19936. var points = [], last;
  19937. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  19938. var curve = curves[ i ];
  19939. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  19940. : ( curve && curve.isLineCurve ) ? 1
  19941. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  19942. : divisions;
  19943. var pts = curve.getPoints( resolution );
  19944. for ( var j = 0; j < pts.length; j ++ ) {
  19945. var point = pts[ j ];
  19946. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  19947. points.push( point );
  19948. last = point;
  19949. }
  19950. }
  19951. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  19952. points.push( points[ 0 ] );
  19953. }
  19954. return points;
  19955. },
  19956. copy: function ( source ) {
  19957. Curve.prototype.copy.call( this, source );
  19958. this.curves = [];
  19959. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  19960. var curve = source.curves[ i ];
  19961. this.curves.push( curve.clone() );
  19962. }
  19963. this.autoClose = source.autoClose;
  19964. return this;
  19965. },
  19966. toJSON: function () {
  19967. var data = Curve.prototype.toJSON.call( this );
  19968. data.autoClose = this.autoClose;
  19969. data.curves = [];
  19970. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19971. var curve = this.curves[ i ];
  19972. data.curves.push( curve.toJSON() );
  19973. }
  19974. return data;
  19975. },
  19976. fromJSON: function ( json ) {
  19977. Curve.prototype.fromJSON.call( this, json );
  19978. this.autoClose = json.autoClose;
  19979. this.curves = [];
  19980. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  19981. var curve = json.curves[ i ];
  19982. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  19983. }
  19984. return this;
  19985. }
  19986. } );
  19987. /**
  19988. * @author zz85 / http://www.lab4games.net/zz85/blog
  19989. * Creates free form 2d path using series of points, lines or curves.
  19990. **/
  19991. function Path( points ) {
  19992. CurvePath.call( this );
  19993. this.type = 'Path';
  19994. this.currentPoint = new Vector2();
  19995. if ( points ) {
  19996. this.setFromPoints( points );
  19997. }
  19998. }
  19999. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  20000. constructor: Path,
  20001. setFromPoints: function ( points ) {
  20002. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  20003. for ( var i = 1, l = points.length; i < l; i ++ ) {
  20004. this.lineTo( points[ i ].x, points[ i ].y );
  20005. }
  20006. },
  20007. moveTo: function ( x, y ) {
  20008. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  20009. },
  20010. lineTo: function ( x, y ) {
  20011. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  20012. this.curves.push( curve );
  20013. this.currentPoint.set( x, y );
  20014. },
  20015. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  20016. var curve = new QuadraticBezierCurve(
  20017. this.currentPoint.clone(),
  20018. new Vector2( aCPx, aCPy ),
  20019. new Vector2( aX, aY )
  20020. );
  20021. this.curves.push( curve );
  20022. this.currentPoint.set( aX, aY );
  20023. },
  20024. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20025. var curve = new CubicBezierCurve(
  20026. this.currentPoint.clone(),
  20027. new Vector2( aCP1x, aCP1y ),
  20028. new Vector2( aCP2x, aCP2y ),
  20029. new Vector2( aX, aY )
  20030. );
  20031. this.curves.push( curve );
  20032. this.currentPoint.set( aX, aY );
  20033. },
  20034. splineThru: function ( pts /*Array of Vector*/ ) {
  20035. var npts = [ this.currentPoint.clone() ].concat( pts );
  20036. var curve = new SplineCurve( npts );
  20037. this.curves.push( curve );
  20038. this.currentPoint.copy( pts[ pts.length - 1 ] );
  20039. },
  20040. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20041. var x0 = this.currentPoint.x;
  20042. var y0 = this.currentPoint.y;
  20043. this.absarc( aX + x0, aY + y0, aRadius,
  20044. aStartAngle, aEndAngle, aClockwise );
  20045. },
  20046. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20047. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20048. },
  20049. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20050. var x0 = this.currentPoint.x;
  20051. var y0 = this.currentPoint.y;
  20052. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20053. },
  20054. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20055. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20056. if ( this.curves.length > 0 ) {
  20057. // if a previous curve is present, attempt to join
  20058. var firstPoint = curve.getPoint( 0 );
  20059. if ( ! firstPoint.equals( this.currentPoint ) ) {
  20060. this.lineTo( firstPoint.x, firstPoint.y );
  20061. }
  20062. }
  20063. this.curves.push( curve );
  20064. var lastPoint = curve.getPoint( 1 );
  20065. this.currentPoint.copy( lastPoint );
  20066. },
  20067. copy: function ( source ) {
  20068. CurvePath.prototype.copy.call( this, source );
  20069. this.currentPoint.copy( source.currentPoint );
  20070. return this;
  20071. },
  20072. toJSON: function () {
  20073. var data = CurvePath.prototype.toJSON.call( this );
  20074. data.currentPoint = this.currentPoint.toArray();
  20075. return data;
  20076. },
  20077. fromJSON: function ( json ) {
  20078. CurvePath.prototype.fromJSON.call( this, json );
  20079. this.currentPoint.fromArray( json.currentPoint );
  20080. return this;
  20081. }
  20082. } );
  20083. /**
  20084. * @author zz85 / http://www.lab4games.net/zz85/blog
  20085. * Defines a 2d shape plane using paths.
  20086. **/
  20087. // STEP 1 Create a path.
  20088. // STEP 2 Turn path into shape.
  20089. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20090. // STEP 3a - Extract points from each shape, turn to vertices
  20091. // STEP 3b - Triangulate each shape, add faces.
  20092. function Shape( points ) {
  20093. Path.call( this, points );
  20094. this.uuid = _Math.generateUUID();
  20095. this.type = 'Shape';
  20096. this.holes = [];
  20097. }
  20098. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  20099. constructor: Shape,
  20100. getPointsHoles: function ( divisions ) {
  20101. var holesPts = [];
  20102. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20103. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20104. }
  20105. return holesPts;
  20106. },
  20107. // get points of shape and holes (keypoints based on segments parameter)
  20108. extractPoints: function ( divisions ) {
  20109. return {
  20110. shape: this.getPoints( divisions ),
  20111. holes: this.getPointsHoles( divisions )
  20112. };
  20113. },
  20114. copy: function ( source ) {
  20115. Path.prototype.copy.call( this, source );
  20116. this.holes = [];
  20117. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  20118. var hole = source.holes[ i ];
  20119. this.holes.push( hole.clone() );
  20120. }
  20121. return this;
  20122. },
  20123. toJSON: function () {
  20124. var data = Path.prototype.toJSON.call( this );
  20125. data.uuid = this.uuid;
  20126. data.holes = [];
  20127. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20128. var hole = this.holes[ i ];
  20129. data.holes.push( hole.toJSON() );
  20130. }
  20131. return data;
  20132. },
  20133. fromJSON: function ( json ) {
  20134. Path.prototype.fromJSON.call( this, json );
  20135. this.uuid = json.uuid;
  20136. this.holes = [];
  20137. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  20138. var hole = json.holes[ i ];
  20139. this.holes.push( new Path().fromJSON( hole ) );
  20140. }
  20141. return this;
  20142. }
  20143. } );
  20144. /**
  20145. * @author mrdoob / http://mrdoob.com/
  20146. * @author alteredq / http://alteredqualia.com/
  20147. */
  20148. function Light( color, intensity ) {
  20149. Object3D.call( this );
  20150. this.type = 'Light';
  20151. this.color = new Color( color );
  20152. this.intensity = intensity !== undefined ? intensity : 1;
  20153. this.receiveShadow = undefined;
  20154. }
  20155. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  20156. constructor: Light,
  20157. isLight: true,
  20158. copy: function ( source ) {
  20159. Object3D.prototype.copy.call( this, source );
  20160. this.color.copy( source.color );
  20161. this.intensity = source.intensity;
  20162. return this;
  20163. },
  20164. toJSON: function ( meta ) {
  20165. var data = Object3D.prototype.toJSON.call( this, meta );
  20166. data.object.color = this.color.getHex();
  20167. data.object.intensity = this.intensity;
  20168. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  20169. if ( this.distance !== undefined ) data.object.distance = this.distance;
  20170. if ( this.angle !== undefined ) data.object.angle = this.angle;
  20171. if ( this.decay !== undefined ) data.object.decay = this.decay;
  20172. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  20173. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  20174. return data;
  20175. }
  20176. } );
  20177. /**
  20178. * @author alteredq / http://alteredqualia.com/
  20179. */
  20180. function HemisphereLight( skyColor, groundColor, intensity ) {
  20181. Light.call( this, skyColor, intensity );
  20182. this.type = 'HemisphereLight';
  20183. this.castShadow = undefined;
  20184. this.position.copy( Object3D.DefaultUp );
  20185. this.updateMatrix();
  20186. this.groundColor = new Color( groundColor );
  20187. }
  20188. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20189. constructor: HemisphereLight,
  20190. isHemisphereLight: true,
  20191. copy: function ( source ) {
  20192. Light.prototype.copy.call( this, source );
  20193. this.groundColor.copy( source.groundColor );
  20194. return this;
  20195. }
  20196. } );
  20197. /**
  20198. * @author mrdoob / http://mrdoob.com/
  20199. */
  20200. function LightShadow( camera ) {
  20201. this.camera = camera;
  20202. this.bias = 0;
  20203. this.radius = 1;
  20204. this.mapSize = new Vector2( 512, 512 );
  20205. this.map = null;
  20206. this.matrix = new Matrix4();
  20207. }
  20208. Object.assign( LightShadow.prototype, {
  20209. copy: function ( source ) {
  20210. this.camera = source.camera.clone();
  20211. this.bias = source.bias;
  20212. this.radius = source.radius;
  20213. this.mapSize.copy( source.mapSize );
  20214. return this;
  20215. },
  20216. clone: function () {
  20217. return new this.constructor().copy( this );
  20218. },
  20219. toJSON: function () {
  20220. var object = {};
  20221. if ( this.bias !== 0 ) object.bias = this.bias;
  20222. if ( this.radius !== 1 ) object.radius = this.radius;
  20223. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  20224. object.camera = this.camera.toJSON( false ).object;
  20225. delete object.camera.matrix;
  20226. return object;
  20227. }
  20228. } );
  20229. /**
  20230. * @author mrdoob / http://mrdoob.com/
  20231. */
  20232. function SpotLightShadow() {
  20233. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  20234. }
  20235. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  20236. constructor: SpotLightShadow,
  20237. isSpotLightShadow: true,
  20238. update: function ( light ) {
  20239. var camera = this.camera;
  20240. var fov = _Math.RAD2DEG * 2 * light.angle;
  20241. var aspect = this.mapSize.width / this.mapSize.height;
  20242. var far = light.distance || camera.far;
  20243. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  20244. camera.fov = fov;
  20245. camera.aspect = aspect;
  20246. camera.far = far;
  20247. camera.updateProjectionMatrix();
  20248. }
  20249. }
  20250. } );
  20251. /**
  20252. * @author alteredq / http://alteredqualia.com/
  20253. */
  20254. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  20255. Light.call( this, color, intensity );
  20256. this.type = 'SpotLight';
  20257. this.position.copy( Object3D.DefaultUp );
  20258. this.updateMatrix();
  20259. this.target = new Object3D();
  20260. Object.defineProperty( this, 'power', {
  20261. get: function () {
  20262. // intensity = power per solid angle.
  20263. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20264. return this.intensity * Math.PI;
  20265. },
  20266. set: function ( power ) {
  20267. // intensity = power per solid angle.
  20268. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20269. this.intensity = power / Math.PI;
  20270. }
  20271. } );
  20272. this.distance = ( distance !== undefined ) ? distance : 0;
  20273. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  20274. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  20275. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  20276. this.shadow = new SpotLightShadow();
  20277. }
  20278. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20279. constructor: SpotLight,
  20280. isSpotLight: true,
  20281. copy: function ( source ) {
  20282. Light.prototype.copy.call( this, source );
  20283. this.distance = source.distance;
  20284. this.angle = source.angle;
  20285. this.penumbra = source.penumbra;
  20286. this.decay = source.decay;
  20287. this.target = source.target.clone();
  20288. this.shadow = source.shadow.clone();
  20289. return this;
  20290. }
  20291. } );
  20292. /**
  20293. * @author mrdoob / http://mrdoob.com/
  20294. */
  20295. function PointLight( color, intensity, distance, decay ) {
  20296. Light.call( this, color, intensity );
  20297. this.type = 'PointLight';
  20298. Object.defineProperty( this, 'power', {
  20299. get: function () {
  20300. // intensity = power per solid angle.
  20301. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20302. return this.intensity * 4 * Math.PI;
  20303. },
  20304. set: function ( power ) {
  20305. // intensity = power per solid angle.
  20306. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20307. this.intensity = power / ( 4 * Math.PI );
  20308. }
  20309. } );
  20310. this.distance = ( distance !== undefined ) ? distance : 0;
  20311. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  20312. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  20313. }
  20314. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20315. constructor: PointLight,
  20316. isPointLight: true,
  20317. copy: function ( source ) {
  20318. Light.prototype.copy.call( this, source );
  20319. this.distance = source.distance;
  20320. this.decay = source.decay;
  20321. this.shadow = source.shadow.clone();
  20322. return this;
  20323. }
  20324. } );
  20325. /**
  20326. * @author mrdoob / http://mrdoob.com/
  20327. */
  20328. function DirectionalLightShadow( ) {
  20329. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  20330. }
  20331. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  20332. constructor: DirectionalLightShadow
  20333. } );
  20334. /**
  20335. * @author mrdoob / http://mrdoob.com/
  20336. * @author alteredq / http://alteredqualia.com/
  20337. */
  20338. function DirectionalLight( color, intensity ) {
  20339. Light.call( this, color, intensity );
  20340. this.type = 'DirectionalLight';
  20341. this.position.copy( Object3D.DefaultUp );
  20342. this.updateMatrix();
  20343. this.target = new Object3D();
  20344. this.shadow = new DirectionalLightShadow();
  20345. }
  20346. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20347. constructor: DirectionalLight,
  20348. isDirectionalLight: true,
  20349. copy: function ( source ) {
  20350. Light.prototype.copy.call( this, source );
  20351. this.target = source.target.clone();
  20352. this.shadow = source.shadow.clone();
  20353. return this;
  20354. }
  20355. } );
  20356. /**
  20357. * @author mrdoob / http://mrdoob.com/
  20358. */
  20359. function AmbientLight( color, intensity ) {
  20360. Light.call( this, color, intensity );
  20361. this.type = 'AmbientLight';
  20362. this.castShadow = undefined;
  20363. }
  20364. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20365. constructor: AmbientLight,
  20366. isAmbientLight: true
  20367. } );
  20368. /**
  20369. * @author abelnation / http://github.com/abelnation
  20370. */
  20371. function RectAreaLight( color, intensity, width, height ) {
  20372. Light.call( this, color, intensity );
  20373. this.type = 'RectAreaLight';
  20374. this.width = ( width !== undefined ) ? width : 10;
  20375. this.height = ( height !== undefined ) ? height : 10;
  20376. }
  20377. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20378. constructor: RectAreaLight,
  20379. isRectAreaLight: true,
  20380. copy: function ( source ) {
  20381. Light.prototype.copy.call( this, source );
  20382. this.width = source.width;
  20383. this.height = source.height;
  20384. return this;
  20385. },
  20386. toJSON: function ( meta ) {
  20387. var data = Light.prototype.toJSON.call( this, meta );
  20388. data.object.width = this.width;
  20389. data.object.height = this.height;
  20390. return data;
  20391. }
  20392. } );
  20393. /**
  20394. *
  20395. * A Track that interpolates Strings
  20396. *
  20397. *
  20398. * @author Ben Houston / http://clara.io/
  20399. * @author David Sarno / http://lighthaus.us/
  20400. * @author tschw
  20401. */
  20402. function StringKeyframeTrack( name, times, values, interpolation ) {
  20403. KeyframeTrack.call( this, name, times, values, interpolation );
  20404. }
  20405. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20406. constructor: StringKeyframeTrack,
  20407. ValueTypeName: 'string',
  20408. ValueBufferType: Array,
  20409. DefaultInterpolation: InterpolateDiscrete,
  20410. InterpolantFactoryMethodLinear: undefined,
  20411. InterpolantFactoryMethodSmooth: undefined
  20412. } );
  20413. /**
  20414. *
  20415. * A Track of Boolean keyframe values.
  20416. *
  20417. *
  20418. * @author Ben Houston / http://clara.io/
  20419. * @author David Sarno / http://lighthaus.us/
  20420. * @author tschw
  20421. */
  20422. function BooleanKeyframeTrack( name, times, values ) {
  20423. KeyframeTrack.call( this, name, times, values );
  20424. }
  20425. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20426. constructor: BooleanKeyframeTrack,
  20427. ValueTypeName: 'bool',
  20428. ValueBufferType: Array,
  20429. DefaultInterpolation: InterpolateDiscrete,
  20430. InterpolantFactoryMethodLinear: undefined,
  20431. InterpolantFactoryMethodSmooth: undefined
  20432. // Note: Actually this track could have a optimized / compressed
  20433. // representation of a single value and a custom interpolant that
  20434. // computes "firstValue ^ isOdd( index )".
  20435. } );
  20436. /**
  20437. * Abstract base class of interpolants over parametric samples.
  20438. *
  20439. * The parameter domain is one dimensional, typically the time or a path
  20440. * along a curve defined by the data.
  20441. *
  20442. * The sample values can have any dimensionality and derived classes may
  20443. * apply special interpretations to the data.
  20444. *
  20445. * This class provides the interval seek in a Template Method, deferring
  20446. * the actual interpolation to derived classes.
  20447. *
  20448. * Time complexity is O(1) for linear access crossing at most two points
  20449. * and O(log N) for random access, where N is the number of positions.
  20450. *
  20451. * References:
  20452. *
  20453. * http://www.oodesign.com/template-method-pattern.html
  20454. *
  20455. * @author tschw
  20456. */
  20457. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20458. this.parameterPositions = parameterPositions;
  20459. this._cachedIndex = 0;
  20460. this.resultBuffer = resultBuffer !== undefined ?
  20461. resultBuffer : new sampleValues.constructor( sampleSize );
  20462. this.sampleValues = sampleValues;
  20463. this.valueSize = sampleSize;
  20464. }
  20465. Object.assign( Interpolant.prototype, {
  20466. evaluate: function ( t ) {
  20467. var pp = this.parameterPositions,
  20468. i1 = this._cachedIndex,
  20469. t1 = pp[ i1 ],
  20470. t0 = pp[ i1 - 1 ];
  20471. validate_interval: {
  20472. seek: {
  20473. var right;
  20474. linear_scan: {
  20475. //- See http://jsperf.com/comparison-to-undefined/3
  20476. //- slower code:
  20477. //-
  20478. //- if ( t >= t1 || t1 === undefined ) {
  20479. forward_scan: if ( ! ( t < t1 ) ) {
  20480. for ( var giveUpAt = i1 + 2; ; ) {
  20481. if ( t1 === undefined ) {
  20482. if ( t < t0 ) break forward_scan;
  20483. // after end
  20484. i1 = pp.length;
  20485. this._cachedIndex = i1;
  20486. return this.afterEnd_( i1 - 1, t, t0 );
  20487. }
  20488. if ( i1 === giveUpAt ) break; // this loop
  20489. t0 = t1;
  20490. t1 = pp[ ++ i1 ];
  20491. if ( t < t1 ) {
  20492. // we have arrived at the sought interval
  20493. break seek;
  20494. }
  20495. }
  20496. // prepare binary search on the right side of the index
  20497. right = pp.length;
  20498. break linear_scan;
  20499. }
  20500. //- slower code:
  20501. //- if ( t < t0 || t0 === undefined ) {
  20502. if ( ! ( t >= t0 ) ) {
  20503. // looping?
  20504. var t1global = pp[ 1 ];
  20505. if ( t < t1global ) {
  20506. i1 = 2; // + 1, using the scan for the details
  20507. t0 = t1global;
  20508. }
  20509. // linear reverse scan
  20510. for ( var giveUpAt = i1 - 2; ; ) {
  20511. if ( t0 === undefined ) {
  20512. // before start
  20513. this._cachedIndex = 0;
  20514. return this.beforeStart_( 0, t, t1 );
  20515. }
  20516. if ( i1 === giveUpAt ) break; // this loop
  20517. t1 = t0;
  20518. t0 = pp[ -- i1 - 1 ];
  20519. if ( t >= t0 ) {
  20520. // we have arrived at the sought interval
  20521. break seek;
  20522. }
  20523. }
  20524. // prepare binary search on the left side of the index
  20525. right = i1;
  20526. i1 = 0;
  20527. break linear_scan;
  20528. }
  20529. // the interval is valid
  20530. break validate_interval;
  20531. } // linear scan
  20532. // binary search
  20533. while ( i1 < right ) {
  20534. var mid = ( i1 + right ) >>> 1;
  20535. if ( t < pp[ mid ] ) {
  20536. right = mid;
  20537. } else {
  20538. i1 = mid + 1;
  20539. }
  20540. }
  20541. t1 = pp[ i1 ];
  20542. t0 = pp[ i1 - 1 ];
  20543. // check boundary cases, again
  20544. if ( t0 === undefined ) {
  20545. this._cachedIndex = 0;
  20546. return this.beforeStart_( 0, t, t1 );
  20547. }
  20548. if ( t1 === undefined ) {
  20549. i1 = pp.length;
  20550. this._cachedIndex = i1;
  20551. return this.afterEnd_( i1 - 1, t0, t );
  20552. }
  20553. } // seek
  20554. this._cachedIndex = i1;
  20555. this.intervalChanged_( i1, t0, t1 );
  20556. } // validate_interval
  20557. return this.interpolate_( i1, t0, t, t1 );
  20558. },
  20559. settings: null, // optional, subclass-specific settings structure
  20560. // Note: The indirection allows central control of many interpolants.
  20561. // --- Protected interface
  20562. DefaultSettings_: {},
  20563. getSettings_: function () {
  20564. return this.settings || this.DefaultSettings_;
  20565. },
  20566. copySampleValue_: function ( index ) {
  20567. // copies a sample value to the result buffer
  20568. var result = this.resultBuffer,
  20569. values = this.sampleValues,
  20570. stride = this.valueSize,
  20571. offset = index * stride;
  20572. for ( var i = 0; i !== stride; ++ i ) {
  20573. result[ i ] = values[ offset + i ];
  20574. }
  20575. return result;
  20576. },
  20577. // Template methods for derived classes:
  20578. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20579. throw new Error( 'call to abstract method' );
  20580. // implementations shall return this.resultBuffer
  20581. },
  20582. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20583. // empty
  20584. }
  20585. } );
  20586. //!\ DECLARE ALIAS AFTER assign prototype !
  20587. Object.assign( Interpolant.prototype, {
  20588. //( 0, t, t0 ), returns this.resultBuffer
  20589. beforeStart_: Interpolant.prototype.copySampleValue_,
  20590. //( N-1, tN-1, t ), returns this.resultBuffer
  20591. afterEnd_: Interpolant.prototype.copySampleValue_,
  20592. } );
  20593. /**
  20594. * Spherical linear unit quaternion interpolant.
  20595. *
  20596. * @author tschw
  20597. */
  20598. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20599. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20600. }
  20601. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20602. constructor: QuaternionLinearInterpolant,
  20603. interpolate_: function ( i1, t0, t, t1 ) {
  20604. var result = this.resultBuffer,
  20605. values = this.sampleValues,
  20606. stride = this.valueSize,
  20607. offset = i1 * stride,
  20608. alpha = ( t - t0 ) / ( t1 - t0 );
  20609. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20610. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20611. }
  20612. return result;
  20613. }
  20614. } );
  20615. /**
  20616. *
  20617. * A Track of quaternion keyframe values.
  20618. *
  20619. * @author Ben Houston / http://clara.io/
  20620. * @author David Sarno / http://lighthaus.us/
  20621. * @author tschw
  20622. */
  20623. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20624. KeyframeTrack.call( this, name, times, values, interpolation );
  20625. }
  20626. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20627. constructor: QuaternionKeyframeTrack,
  20628. ValueTypeName: 'quaternion',
  20629. // ValueBufferType is inherited
  20630. DefaultInterpolation: InterpolateLinear,
  20631. InterpolantFactoryMethodLinear: function ( result ) {
  20632. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20633. },
  20634. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20635. } );
  20636. /**
  20637. *
  20638. * A Track of keyframe values that represent color.
  20639. *
  20640. *
  20641. * @author Ben Houston / http://clara.io/
  20642. * @author David Sarno / http://lighthaus.us/
  20643. * @author tschw
  20644. */
  20645. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20646. KeyframeTrack.call( this, name, times, values, interpolation );
  20647. }
  20648. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20649. constructor: ColorKeyframeTrack,
  20650. ValueTypeName: 'color'
  20651. // ValueBufferType is inherited
  20652. // DefaultInterpolation is inherited
  20653. // Note: Very basic implementation and nothing special yet.
  20654. // However, this is the place for color space parameterization.
  20655. } );
  20656. /**
  20657. *
  20658. * A Track of numeric keyframe values.
  20659. *
  20660. * @author Ben Houston / http://clara.io/
  20661. * @author David Sarno / http://lighthaus.us/
  20662. * @author tschw
  20663. */
  20664. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20665. KeyframeTrack.call( this, name, times, values, interpolation );
  20666. }
  20667. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20668. constructor: NumberKeyframeTrack,
  20669. ValueTypeName: 'number'
  20670. // ValueBufferType is inherited
  20671. // DefaultInterpolation is inherited
  20672. } );
  20673. /**
  20674. * Fast and simple cubic spline interpolant.
  20675. *
  20676. * It was derived from a Hermitian construction setting the first derivative
  20677. * at each sample position to the linear slope between neighboring positions
  20678. * over their parameter interval.
  20679. *
  20680. * @author tschw
  20681. */
  20682. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20683. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20684. this._weightPrev = - 0;
  20685. this._offsetPrev = - 0;
  20686. this._weightNext = - 0;
  20687. this._offsetNext = - 0;
  20688. }
  20689. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20690. constructor: CubicInterpolant,
  20691. DefaultSettings_: {
  20692. endingStart: ZeroCurvatureEnding,
  20693. endingEnd: ZeroCurvatureEnding
  20694. },
  20695. intervalChanged_: function ( i1, t0, t1 ) {
  20696. var pp = this.parameterPositions,
  20697. iPrev = i1 - 2,
  20698. iNext = i1 + 1,
  20699. tPrev = pp[ iPrev ],
  20700. tNext = pp[ iNext ];
  20701. if ( tPrev === undefined ) {
  20702. switch ( this.getSettings_().endingStart ) {
  20703. case ZeroSlopeEnding:
  20704. // f'(t0) = 0
  20705. iPrev = i1;
  20706. tPrev = 2 * t0 - t1;
  20707. break;
  20708. case WrapAroundEnding:
  20709. // use the other end of the curve
  20710. iPrev = pp.length - 2;
  20711. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20712. break;
  20713. default: // ZeroCurvatureEnding
  20714. // f''(t0) = 0 a.k.a. Natural Spline
  20715. iPrev = i1;
  20716. tPrev = t1;
  20717. }
  20718. }
  20719. if ( tNext === undefined ) {
  20720. switch ( this.getSettings_().endingEnd ) {
  20721. case ZeroSlopeEnding:
  20722. // f'(tN) = 0
  20723. iNext = i1;
  20724. tNext = 2 * t1 - t0;
  20725. break;
  20726. case WrapAroundEnding:
  20727. // use the other end of the curve
  20728. iNext = 1;
  20729. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20730. break;
  20731. default: // ZeroCurvatureEnding
  20732. // f''(tN) = 0, a.k.a. Natural Spline
  20733. iNext = i1 - 1;
  20734. tNext = t0;
  20735. }
  20736. }
  20737. var halfDt = ( t1 - t0 ) * 0.5,
  20738. stride = this.valueSize;
  20739. this._weightPrev = halfDt / ( t0 - tPrev );
  20740. this._weightNext = halfDt / ( tNext - t1 );
  20741. this._offsetPrev = iPrev * stride;
  20742. this._offsetNext = iNext * stride;
  20743. },
  20744. interpolate_: function ( i1, t0, t, t1 ) {
  20745. var result = this.resultBuffer,
  20746. values = this.sampleValues,
  20747. stride = this.valueSize,
  20748. o1 = i1 * stride, o0 = o1 - stride,
  20749. oP = this._offsetPrev, oN = this._offsetNext,
  20750. wP = this._weightPrev, wN = this._weightNext,
  20751. p = ( t - t0 ) / ( t1 - t0 ),
  20752. pp = p * p,
  20753. ppp = pp * p;
  20754. // evaluate polynomials
  20755. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20756. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20757. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20758. var sN = wN * ppp - wN * pp;
  20759. // combine data linearly
  20760. for ( var i = 0; i !== stride; ++ i ) {
  20761. result[ i ] =
  20762. sP * values[ oP + i ] +
  20763. s0 * values[ o0 + i ] +
  20764. s1 * values[ o1 + i ] +
  20765. sN * values[ oN + i ];
  20766. }
  20767. return result;
  20768. }
  20769. } );
  20770. /**
  20771. * @author tschw
  20772. */
  20773. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20774. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20775. }
  20776. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20777. constructor: LinearInterpolant,
  20778. interpolate_: function ( i1, t0, t, t1 ) {
  20779. var result = this.resultBuffer,
  20780. values = this.sampleValues,
  20781. stride = this.valueSize,
  20782. offset1 = i1 * stride,
  20783. offset0 = offset1 - stride,
  20784. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20785. weight0 = 1 - weight1;
  20786. for ( var i = 0; i !== stride; ++ i ) {
  20787. result[ i ] =
  20788. values[ offset0 + i ] * weight0 +
  20789. values[ offset1 + i ] * weight1;
  20790. }
  20791. return result;
  20792. }
  20793. } );
  20794. /**
  20795. *
  20796. * Interpolant that evaluates to the sample value at the position preceeding
  20797. * the parameter.
  20798. *
  20799. * @author tschw
  20800. */
  20801. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20802. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20803. }
  20804. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20805. constructor: DiscreteInterpolant,
  20806. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20807. return this.copySampleValue_( i1 - 1 );
  20808. }
  20809. } );
  20810. /**
  20811. * @author tschw
  20812. * @author Ben Houston / http://clara.io/
  20813. * @author David Sarno / http://lighthaus.us/
  20814. */
  20815. var AnimationUtils = {
  20816. // same as Array.prototype.slice, but also works on typed arrays
  20817. arraySlice: function ( array, from, to ) {
  20818. if ( AnimationUtils.isTypedArray( array ) ) {
  20819. // in ios9 array.subarray(from, undefined) will return empty array
  20820. // but array.subarray(from) or array.subarray(from, len) is correct
  20821. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20822. }
  20823. return array.slice( from, to );
  20824. },
  20825. // converts an array to a specific type
  20826. convertArray: function ( array, type, forceClone ) {
  20827. if ( ! array || // let 'undefined' and 'null' pass
  20828. ! forceClone && array.constructor === type ) return array;
  20829. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20830. return new type( array ); // create typed array
  20831. }
  20832. return Array.prototype.slice.call( array ); // create Array
  20833. },
  20834. isTypedArray: function ( object ) {
  20835. return ArrayBuffer.isView( object ) &&
  20836. ! ( object instanceof DataView );
  20837. },
  20838. // returns an array by which times and values can be sorted
  20839. getKeyframeOrder: function ( times ) {
  20840. function compareTime( i, j ) {
  20841. return times[ i ] - times[ j ];
  20842. }
  20843. var n = times.length;
  20844. var result = new Array( n );
  20845. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  20846. result.sort( compareTime );
  20847. return result;
  20848. },
  20849. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20850. sortedArray: function ( values, stride, order ) {
  20851. var nValues = values.length;
  20852. var result = new values.constructor( nValues );
  20853. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20854. var srcOffset = order[ i ] * stride;
  20855. for ( var j = 0; j !== stride; ++ j ) {
  20856. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20857. }
  20858. }
  20859. return result;
  20860. },
  20861. // function for parsing AOS keyframe formats
  20862. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20863. var i = 1, key = jsonKeys[ 0 ];
  20864. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20865. key = jsonKeys[ i ++ ];
  20866. }
  20867. if ( key === undefined ) return; // no data
  20868. var value = key[ valuePropertyName ];
  20869. if ( value === undefined ) return; // no data
  20870. if ( Array.isArray( value ) ) {
  20871. do {
  20872. value = key[ valuePropertyName ];
  20873. if ( value !== undefined ) {
  20874. times.push( key.time );
  20875. values.push.apply( values, value ); // push all elements
  20876. }
  20877. key = jsonKeys[ i ++ ];
  20878. } while ( key !== undefined );
  20879. } else if ( value.toArray !== undefined ) {
  20880. // ...assume THREE.Math-ish
  20881. do {
  20882. value = key[ valuePropertyName ];
  20883. if ( value !== undefined ) {
  20884. times.push( key.time );
  20885. value.toArray( values, values.length );
  20886. }
  20887. key = jsonKeys[ i ++ ];
  20888. } while ( key !== undefined );
  20889. } else {
  20890. // otherwise push as-is
  20891. do {
  20892. value = key[ valuePropertyName ];
  20893. if ( value !== undefined ) {
  20894. times.push( key.time );
  20895. values.push( value );
  20896. }
  20897. key = jsonKeys[ i ++ ];
  20898. } while ( key !== undefined );
  20899. }
  20900. }
  20901. };
  20902. /**
  20903. *
  20904. * A timed sequence of keyframes for a specific property.
  20905. *
  20906. *
  20907. * @author Ben Houston / http://clara.io/
  20908. * @author David Sarno / http://lighthaus.us/
  20909. * @author tschw
  20910. */
  20911. function KeyframeTrack( name, times, values, interpolation ) {
  20912. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20913. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20914. this.name = name;
  20915. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20916. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20917. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20918. this.validate();
  20919. this.optimize();
  20920. }
  20921. // Static methods:
  20922. Object.assign( KeyframeTrack, {
  20923. // Serialization (in static context, because of constructor invocation
  20924. // and automatic invocation of .toJSON):
  20925. parse: function ( json ) {
  20926. if ( json.type === undefined ) {
  20927. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20928. }
  20929. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  20930. if ( json.times === undefined ) {
  20931. var times = [], values = [];
  20932. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20933. json.times = times;
  20934. json.values = values;
  20935. }
  20936. // derived classes can define a static parse method
  20937. if ( trackType.parse !== undefined ) {
  20938. return trackType.parse( json );
  20939. } else {
  20940. // by default, we assume a constructor compatible with the base
  20941. return new trackType( json.name, json.times, json.values, json.interpolation );
  20942. }
  20943. },
  20944. toJSON: function ( track ) {
  20945. var trackType = track.constructor;
  20946. var json;
  20947. // derived classes can define a static toJSON method
  20948. if ( trackType.toJSON !== undefined ) {
  20949. json = trackType.toJSON( track );
  20950. } else {
  20951. // by default, we assume the data can be serialized as-is
  20952. json = {
  20953. 'name': track.name,
  20954. 'times': AnimationUtils.convertArray( track.times, Array ),
  20955. 'values': AnimationUtils.convertArray( track.values, Array )
  20956. };
  20957. var interpolation = track.getInterpolation();
  20958. if ( interpolation !== track.DefaultInterpolation ) {
  20959. json.interpolation = interpolation;
  20960. }
  20961. }
  20962. json.type = track.ValueTypeName; // mandatory
  20963. return json;
  20964. },
  20965. _getTrackTypeForValueTypeName: function ( typeName ) {
  20966. switch ( typeName.toLowerCase() ) {
  20967. case 'scalar':
  20968. case 'double':
  20969. case 'float':
  20970. case 'number':
  20971. case 'integer':
  20972. return NumberKeyframeTrack;
  20973. case 'vector':
  20974. case 'vector2':
  20975. case 'vector3':
  20976. case 'vector4':
  20977. return VectorKeyframeTrack;
  20978. case 'color':
  20979. return ColorKeyframeTrack;
  20980. case 'quaternion':
  20981. return QuaternionKeyframeTrack;
  20982. case 'bool':
  20983. case 'boolean':
  20984. return BooleanKeyframeTrack;
  20985. case 'string':
  20986. return StringKeyframeTrack;
  20987. }
  20988. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20989. }
  20990. } );
  20991. Object.assign( KeyframeTrack.prototype, {
  20992. constructor: KeyframeTrack,
  20993. TimeBufferType: Float32Array,
  20994. ValueBufferType: Float32Array,
  20995. DefaultInterpolation: InterpolateLinear,
  20996. InterpolantFactoryMethodDiscrete: function ( result ) {
  20997. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20998. },
  20999. InterpolantFactoryMethodLinear: function ( result ) {
  21000. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21001. },
  21002. InterpolantFactoryMethodSmooth: function ( result ) {
  21003. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  21004. },
  21005. setInterpolation: function ( interpolation ) {
  21006. var factoryMethod;
  21007. switch ( interpolation ) {
  21008. case InterpolateDiscrete:
  21009. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21010. break;
  21011. case InterpolateLinear:
  21012. factoryMethod = this.InterpolantFactoryMethodLinear;
  21013. break;
  21014. case InterpolateSmooth:
  21015. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21016. break;
  21017. }
  21018. if ( factoryMethod === undefined ) {
  21019. var message = "unsupported interpolation for " +
  21020. this.ValueTypeName + " keyframe track named " + this.name;
  21021. if ( this.createInterpolant === undefined ) {
  21022. // fall back to default, unless the default itself is messed up
  21023. if ( interpolation !== this.DefaultInterpolation ) {
  21024. this.setInterpolation( this.DefaultInterpolation );
  21025. } else {
  21026. throw new Error( message ); // fatal, in this case
  21027. }
  21028. }
  21029. console.warn( 'THREE.KeyframeTrack:', message );
  21030. return;
  21031. }
  21032. this.createInterpolant = factoryMethod;
  21033. },
  21034. getInterpolation: function () {
  21035. switch ( this.createInterpolant ) {
  21036. case this.InterpolantFactoryMethodDiscrete:
  21037. return InterpolateDiscrete;
  21038. case this.InterpolantFactoryMethodLinear:
  21039. return InterpolateLinear;
  21040. case this.InterpolantFactoryMethodSmooth:
  21041. return InterpolateSmooth;
  21042. }
  21043. },
  21044. getValueSize: function () {
  21045. return this.values.length / this.times.length;
  21046. },
  21047. // move all keyframes either forwards or backwards in time
  21048. shift: function ( timeOffset ) {
  21049. if ( timeOffset !== 0.0 ) {
  21050. var times = this.times;
  21051. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21052. times[ i ] += timeOffset;
  21053. }
  21054. }
  21055. return this;
  21056. },
  21057. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21058. scale: function ( timeScale ) {
  21059. if ( timeScale !== 1.0 ) {
  21060. var times = this.times;
  21061. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21062. times[ i ] *= timeScale;
  21063. }
  21064. }
  21065. return this;
  21066. },
  21067. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21068. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21069. trim: function ( startTime, endTime ) {
  21070. var times = this.times,
  21071. nKeys = times.length,
  21072. from = 0,
  21073. to = nKeys - 1;
  21074. while ( from !== nKeys && times[ from ] < startTime ) {
  21075. ++ from;
  21076. }
  21077. while ( to !== - 1 && times[ to ] > endTime ) {
  21078. -- to;
  21079. }
  21080. ++ to; // inclusive -> exclusive bound
  21081. if ( from !== 0 || to !== nKeys ) {
  21082. // empty tracks are forbidden, so keep at least one keyframe
  21083. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  21084. var stride = this.getValueSize();
  21085. this.times = AnimationUtils.arraySlice( times, from, to );
  21086. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  21087. }
  21088. return this;
  21089. },
  21090. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21091. validate: function () {
  21092. var valid = true;
  21093. var valueSize = this.getValueSize();
  21094. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  21095. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  21096. valid = false;
  21097. }
  21098. var times = this.times,
  21099. values = this.values,
  21100. nKeys = times.length;
  21101. if ( nKeys === 0 ) {
  21102. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  21103. valid = false;
  21104. }
  21105. var prevTime = null;
  21106. for ( var i = 0; i !== nKeys; i ++ ) {
  21107. var currTime = times[ i ];
  21108. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  21109. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  21110. valid = false;
  21111. break;
  21112. }
  21113. if ( prevTime !== null && prevTime > currTime ) {
  21114. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  21115. valid = false;
  21116. break;
  21117. }
  21118. prevTime = currTime;
  21119. }
  21120. if ( values !== undefined ) {
  21121. if ( AnimationUtils.isTypedArray( values ) ) {
  21122. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  21123. var value = values[ i ];
  21124. if ( isNaN( value ) ) {
  21125. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  21126. valid = false;
  21127. break;
  21128. }
  21129. }
  21130. }
  21131. }
  21132. return valid;
  21133. },
  21134. // removes equivalent sequential keys as common in morph target sequences
  21135. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21136. optimize: function () {
  21137. var times = this.times,
  21138. values = this.values,
  21139. stride = this.getValueSize(),
  21140. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21141. writeIndex = 1,
  21142. lastIndex = times.length - 1;
  21143. for ( var i = 1; i < lastIndex; ++ i ) {
  21144. var keep = false;
  21145. var time = times[ i ];
  21146. var timeNext = times[ i + 1 ];
  21147. // remove adjacent keyframes scheduled at the same time
  21148. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  21149. if ( ! smoothInterpolation ) {
  21150. // remove unnecessary keyframes same as their neighbors
  21151. var offset = i * stride,
  21152. offsetP = offset - stride,
  21153. offsetN = offset + stride;
  21154. for ( var j = 0; j !== stride; ++ j ) {
  21155. var value = values[ offset + j ];
  21156. if ( value !== values[ offsetP + j ] ||
  21157. value !== values[ offsetN + j ] ) {
  21158. keep = true;
  21159. break;
  21160. }
  21161. }
  21162. } else {
  21163. keep = true;
  21164. }
  21165. }
  21166. // in-place compaction
  21167. if ( keep ) {
  21168. if ( i !== writeIndex ) {
  21169. times[ writeIndex ] = times[ i ];
  21170. var readOffset = i * stride,
  21171. writeOffset = writeIndex * stride;
  21172. for ( var j = 0; j !== stride; ++ j ) {
  21173. values[ writeOffset + j ] = values[ readOffset + j ];
  21174. }
  21175. }
  21176. ++ writeIndex;
  21177. }
  21178. }
  21179. // flush last keyframe (compaction looks ahead)
  21180. if ( lastIndex > 0 ) {
  21181. times[ writeIndex ] = times[ lastIndex ];
  21182. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  21183. values[ writeOffset + j ] = values[ readOffset + j ];
  21184. }
  21185. ++ writeIndex;
  21186. }
  21187. if ( writeIndex !== times.length ) {
  21188. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  21189. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  21190. }
  21191. return this;
  21192. }
  21193. } );
  21194. /**
  21195. *
  21196. * A Track of vectored keyframe values.
  21197. *
  21198. *
  21199. * @author Ben Houston / http://clara.io/
  21200. * @author David Sarno / http://lighthaus.us/
  21201. * @author tschw
  21202. */
  21203. function VectorKeyframeTrack( name, times, values, interpolation ) {
  21204. KeyframeTrack.call( this, name, times, values, interpolation );
  21205. }
  21206. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21207. constructor: VectorKeyframeTrack,
  21208. ValueTypeName: 'vector'
  21209. // ValueBufferType is inherited
  21210. // DefaultInterpolation is inherited
  21211. } );
  21212. /**
  21213. *
  21214. * Reusable set of Tracks that represent an animation.
  21215. *
  21216. * @author Ben Houston / http://clara.io/
  21217. * @author David Sarno / http://lighthaus.us/
  21218. */
  21219. function AnimationClip( name, duration, tracks ) {
  21220. this.name = name;
  21221. this.tracks = tracks;
  21222. this.duration = ( duration !== undefined ) ? duration : - 1;
  21223. this.uuid = _Math.generateUUID();
  21224. // this means it should figure out its duration by scanning the tracks
  21225. if ( this.duration < 0 ) {
  21226. this.resetDuration();
  21227. }
  21228. this.optimize();
  21229. }
  21230. Object.assign( AnimationClip, {
  21231. parse: function ( json ) {
  21232. var tracks = [],
  21233. jsonTracks = json.tracks,
  21234. frameTime = 1.0 / ( json.fps || 1.0 );
  21235. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21236. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  21237. }
  21238. return new AnimationClip( json.name, json.duration, tracks );
  21239. },
  21240. toJSON: function ( clip ) {
  21241. var tracks = [],
  21242. clipTracks = clip.tracks;
  21243. var json = {
  21244. 'name': clip.name,
  21245. 'duration': clip.duration,
  21246. 'tracks': tracks,
  21247. 'uuid': clip.uuid
  21248. };
  21249. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21250. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21251. }
  21252. return json;
  21253. },
  21254. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21255. var numMorphTargets = morphTargetSequence.length;
  21256. var tracks = [];
  21257. for ( var i = 0; i < numMorphTargets; i ++ ) {
  21258. var times = [];
  21259. var values = [];
  21260. times.push(
  21261. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21262. i,
  21263. ( i + 1 ) % numMorphTargets );
  21264. values.push( 0, 1, 0 );
  21265. var order = AnimationUtils.getKeyframeOrder( times );
  21266. times = AnimationUtils.sortedArray( times, 1, order );
  21267. values = AnimationUtils.sortedArray( values, 1, order );
  21268. // if there is a key at the first frame, duplicate it as the
  21269. // last frame as well for perfect loop.
  21270. if ( ! noLoop && times[ 0 ] === 0 ) {
  21271. times.push( numMorphTargets );
  21272. values.push( values[ 0 ] );
  21273. }
  21274. tracks.push(
  21275. new NumberKeyframeTrack(
  21276. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21277. times, values
  21278. ).scale( 1.0 / fps ) );
  21279. }
  21280. return new AnimationClip( name, - 1, tracks );
  21281. },
  21282. findByName: function ( objectOrClipArray, name ) {
  21283. var clipArray = objectOrClipArray;
  21284. if ( ! Array.isArray( objectOrClipArray ) ) {
  21285. var o = objectOrClipArray;
  21286. clipArray = o.geometry && o.geometry.animations || o.animations;
  21287. }
  21288. for ( var i = 0; i < clipArray.length; i ++ ) {
  21289. if ( clipArray[ i ].name === name ) {
  21290. return clipArray[ i ];
  21291. }
  21292. }
  21293. return null;
  21294. },
  21295. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21296. var animationToMorphTargets = {};
  21297. // tested with https://regex101.com/ on trick sequences
  21298. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21299. var pattern = /^([\w-]*?)([\d]+)$/;
  21300. // sort morph target names into animation groups based
  21301. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21302. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  21303. var morphTarget = morphTargets[ i ];
  21304. var parts = morphTarget.name.match( pattern );
  21305. if ( parts && parts.length > 1 ) {
  21306. var name = parts[ 1 ];
  21307. var animationMorphTargets = animationToMorphTargets[ name ];
  21308. if ( ! animationMorphTargets ) {
  21309. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21310. }
  21311. animationMorphTargets.push( morphTarget );
  21312. }
  21313. }
  21314. var clips = [];
  21315. for ( var name in animationToMorphTargets ) {
  21316. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21317. }
  21318. return clips;
  21319. },
  21320. // parse the animation.hierarchy format
  21321. parseAnimation: function ( animation, bones ) {
  21322. if ( ! animation ) {
  21323. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21324. return null;
  21325. }
  21326. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21327. // only return track if there are actually keys.
  21328. if ( animationKeys.length !== 0 ) {
  21329. var times = [];
  21330. var values = [];
  21331. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21332. // empty keys are filtered out, so check again
  21333. if ( times.length !== 0 ) {
  21334. destTracks.push( new trackType( trackName, times, values ) );
  21335. }
  21336. }
  21337. };
  21338. var tracks = [];
  21339. var clipName = animation.name || 'default';
  21340. // automatic length determination in AnimationClip.
  21341. var duration = animation.length || - 1;
  21342. var fps = animation.fps || 30;
  21343. var hierarchyTracks = animation.hierarchy || [];
  21344. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  21345. var animationKeys = hierarchyTracks[ h ].keys;
  21346. // skip empty tracks
  21347. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21348. // process morph targets
  21349. if ( animationKeys[ 0 ].morphTargets ) {
  21350. // figure out all morph targets used in this track
  21351. var morphTargetNames = {};
  21352. for ( var k = 0; k < animationKeys.length; k ++ ) {
  21353. if ( animationKeys[ k ].morphTargets ) {
  21354. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21355. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21356. }
  21357. }
  21358. }
  21359. // create a track for each morph target with all zero
  21360. // morphTargetInfluences except for the keys in which
  21361. // the morphTarget is named.
  21362. for ( var morphTargetName in morphTargetNames ) {
  21363. var times = [];
  21364. var values = [];
  21365. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21366. var animationKey = animationKeys[ k ];
  21367. times.push( animationKey.time );
  21368. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21369. }
  21370. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21371. }
  21372. duration = morphTargetNames.length * ( fps || 1.0 );
  21373. } else {
  21374. // ...assume skeletal animation
  21375. var boneName = '.bones[' + bones[ h ].name + ']';
  21376. addNonemptyTrack(
  21377. VectorKeyframeTrack, boneName + '.position',
  21378. animationKeys, 'pos', tracks );
  21379. addNonemptyTrack(
  21380. QuaternionKeyframeTrack, boneName + '.quaternion',
  21381. animationKeys, 'rot', tracks );
  21382. addNonemptyTrack(
  21383. VectorKeyframeTrack, boneName + '.scale',
  21384. animationKeys, 'scl', tracks );
  21385. }
  21386. }
  21387. if ( tracks.length === 0 ) {
  21388. return null;
  21389. }
  21390. var clip = new AnimationClip( clipName, duration, tracks );
  21391. return clip;
  21392. }
  21393. } );
  21394. Object.assign( AnimationClip.prototype, {
  21395. resetDuration: function () {
  21396. var tracks = this.tracks, duration = 0;
  21397. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  21398. var track = this.tracks[ i ];
  21399. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21400. }
  21401. this.duration = duration;
  21402. },
  21403. trim: function () {
  21404. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21405. this.tracks[ i ].trim( 0, this.duration );
  21406. }
  21407. return this;
  21408. },
  21409. optimize: function () {
  21410. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21411. this.tracks[ i ].optimize();
  21412. }
  21413. return this;
  21414. }
  21415. } );
  21416. /**
  21417. * @author mrdoob / http://mrdoob.com/
  21418. */
  21419. function MaterialLoader( manager ) {
  21420. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21421. this.textures = {};
  21422. }
  21423. Object.assign( MaterialLoader.prototype, {
  21424. load: function ( url, onLoad, onProgress, onError ) {
  21425. var scope = this;
  21426. var loader = new FileLoader( scope.manager );
  21427. loader.load( url, function ( text ) {
  21428. onLoad( scope.parse( JSON.parse( text ) ) );
  21429. }, onProgress, onError );
  21430. },
  21431. setTextures: function ( value ) {
  21432. this.textures = value;
  21433. },
  21434. parse: function ( json ) {
  21435. var textures = this.textures;
  21436. function getTexture( name ) {
  21437. if ( textures[ name ] === undefined ) {
  21438. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  21439. }
  21440. return textures[ name ];
  21441. }
  21442. var material = new Materials[ json.type ]();
  21443. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  21444. if ( json.name !== undefined ) material.name = json.name;
  21445. if ( json.color !== undefined ) material.color.setHex( json.color );
  21446. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  21447. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  21448. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  21449. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  21450. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  21451. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  21452. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  21453. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  21454. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  21455. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  21456. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  21457. if ( json.fog !== undefined ) material.fog = json.fog;
  21458. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  21459. if ( json.blending !== undefined ) material.blending = json.blending;
  21460. if ( json.side !== undefined ) material.side = json.side;
  21461. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  21462. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  21463. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  21464. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  21465. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  21466. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  21467. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  21468. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  21469. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  21470. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  21471. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  21472. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  21473. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  21474. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  21475. if ( json.scale !== undefined ) material.scale = json.scale;
  21476. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  21477. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  21478. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  21479. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  21480. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  21481. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  21482. if ( json.visible !== undefined ) material.visible = json.visible;
  21483. if ( json.userData !== undefined ) material.userData = json.userData;
  21484. // Deprecated
  21485. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  21486. // for PointsMaterial
  21487. if ( json.size !== undefined ) material.size = json.size;
  21488. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  21489. // maps
  21490. if ( json.map !== undefined ) material.map = getTexture( json.map );
  21491. if ( json.alphaMap !== undefined ) {
  21492. material.alphaMap = getTexture( json.alphaMap );
  21493. material.transparent = true;
  21494. }
  21495. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  21496. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  21497. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  21498. if ( json.normalScale !== undefined ) {
  21499. var normalScale = json.normalScale;
  21500. if ( Array.isArray( normalScale ) === false ) {
  21501. // Blender exporter used to export a scalar. See #7459
  21502. normalScale = [ normalScale, normalScale ];
  21503. }
  21504. material.normalScale = new Vector2().fromArray( normalScale );
  21505. }
  21506. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  21507. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  21508. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  21509. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  21510. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  21511. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  21512. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  21513. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  21514. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  21515. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  21516. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  21517. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  21518. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  21519. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  21520. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  21521. return material;
  21522. }
  21523. } );
  21524. /**
  21525. * @author mrdoob / http://mrdoob.com/
  21526. */
  21527. function BufferGeometryLoader( manager ) {
  21528. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21529. }
  21530. Object.assign( BufferGeometryLoader.prototype, {
  21531. load: function ( url, onLoad, onProgress, onError ) {
  21532. var scope = this;
  21533. var loader = new FileLoader( scope.manager );
  21534. loader.load( url, function ( text ) {
  21535. onLoad( scope.parse( JSON.parse( text ) ) );
  21536. }, onProgress, onError );
  21537. },
  21538. parse: function ( json ) {
  21539. var geometry = new BufferGeometry();
  21540. var index = json.data.index;
  21541. if ( index !== undefined ) {
  21542. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  21543. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  21544. }
  21545. var attributes = json.data.attributes;
  21546. for ( var key in attributes ) {
  21547. var attribute = attributes[ key ];
  21548. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  21549. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  21550. }
  21551. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  21552. if ( groups !== undefined ) {
  21553. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  21554. var group = groups[ i ];
  21555. geometry.addGroup( group.start, group.count, group.materialIndex );
  21556. }
  21557. }
  21558. var boundingSphere = json.data.boundingSphere;
  21559. if ( boundingSphere !== undefined ) {
  21560. var center = new Vector3();
  21561. if ( boundingSphere.center !== undefined ) {
  21562. center.fromArray( boundingSphere.center );
  21563. }
  21564. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  21565. }
  21566. return geometry;
  21567. }
  21568. } );
  21569. var TYPED_ARRAYS = {
  21570. Int8Array: Int8Array,
  21571. Uint8Array: Uint8Array,
  21572. // Workaround for IE11 pre KB2929437. See #11440
  21573. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  21574. Int16Array: Int16Array,
  21575. Uint16Array: Uint16Array,
  21576. Int32Array: Int32Array,
  21577. Uint32Array: Uint32Array,
  21578. Float32Array: Float32Array,
  21579. Float64Array: Float64Array
  21580. };
  21581. /**
  21582. * @author alteredq / http://alteredqualia.com/
  21583. */
  21584. function Loader() {}
  21585. Loader.Handlers = {
  21586. handlers: [],
  21587. add: function ( regex, loader ) {
  21588. this.handlers.push( regex, loader );
  21589. },
  21590. get: function ( file ) {
  21591. var handlers = this.handlers;
  21592. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  21593. var regex = handlers[ i ];
  21594. var loader = handlers[ i + 1 ];
  21595. if ( regex.test( file ) ) {
  21596. return loader;
  21597. }
  21598. }
  21599. return null;
  21600. }
  21601. };
  21602. Object.assign( Loader.prototype, {
  21603. crossOrigin: undefined,
  21604. onLoadStart: function () {},
  21605. onLoadProgress: function () {},
  21606. onLoadComplete: function () {},
  21607. initMaterials: function ( materials, texturePath, crossOrigin ) {
  21608. var array = [];
  21609. for ( var i = 0; i < materials.length; ++ i ) {
  21610. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  21611. }
  21612. return array;
  21613. },
  21614. createMaterial: ( function () {
  21615. var BlendingMode = {
  21616. NoBlending: NoBlending,
  21617. NormalBlending: NormalBlending,
  21618. AdditiveBlending: AdditiveBlending,
  21619. SubtractiveBlending: SubtractiveBlending,
  21620. MultiplyBlending: MultiplyBlending,
  21621. CustomBlending: CustomBlending
  21622. };
  21623. var color = new Color();
  21624. var textureLoader = new TextureLoader();
  21625. var materialLoader = new MaterialLoader();
  21626. return function createMaterial( m, texturePath, crossOrigin ) {
  21627. // convert from old material format
  21628. var textures = {};
  21629. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  21630. var fullPath = texturePath + path;
  21631. var loader = Loader.Handlers.get( fullPath );
  21632. var texture;
  21633. if ( loader !== null ) {
  21634. texture = loader.load( fullPath );
  21635. } else {
  21636. textureLoader.setCrossOrigin( crossOrigin );
  21637. texture = textureLoader.load( fullPath );
  21638. }
  21639. if ( repeat !== undefined ) {
  21640. texture.repeat.fromArray( repeat );
  21641. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  21642. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  21643. }
  21644. if ( offset !== undefined ) {
  21645. texture.offset.fromArray( offset );
  21646. }
  21647. if ( wrap !== undefined ) {
  21648. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  21649. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  21650. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  21651. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  21652. }
  21653. if ( anisotropy !== undefined ) {
  21654. texture.anisotropy = anisotropy;
  21655. }
  21656. var uuid = _Math.generateUUID();
  21657. textures[ uuid ] = texture;
  21658. return uuid;
  21659. }
  21660. //
  21661. var json = {
  21662. uuid: _Math.generateUUID(),
  21663. type: 'MeshLambertMaterial'
  21664. };
  21665. for ( var name in m ) {
  21666. var value = m[ name ];
  21667. switch ( name ) {
  21668. case 'DbgColor':
  21669. case 'DbgIndex':
  21670. case 'opticalDensity':
  21671. case 'illumination':
  21672. break;
  21673. case 'DbgName':
  21674. json.name = value;
  21675. break;
  21676. case 'blending':
  21677. json.blending = BlendingMode[ value ];
  21678. break;
  21679. case 'colorAmbient':
  21680. case 'mapAmbient':
  21681. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  21682. break;
  21683. case 'colorDiffuse':
  21684. json.color = color.fromArray( value ).getHex();
  21685. break;
  21686. case 'colorSpecular':
  21687. json.specular = color.fromArray( value ).getHex();
  21688. break;
  21689. case 'colorEmissive':
  21690. json.emissive = color.fromArray( value ).getHex();
  21691. break;
  21692. case 'specularCoef':
  21693. json.shininess = value;
  21694. break;
  21695. case 'shading':
  21696. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  21697. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  21698. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  21699. break;
  21700. case 'mapDiffuse':
  21701. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  21702. break;
  21703. case 'mapDiffuseRepeat':
  21704. case 'mapDiffuseOffset':
  21705. case 'mapDiffuseWrap':
  21706. case 'mapDiffuseAnisotropy':
  21707. break;
  21708. case 'mapEmissive':
  21709. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  21710. break;
  21711. case 'mapEmissiveRepeat':
  21712. case 'mapEmissiveOffset':
  21713. case 'mapEmissiveWrap':
  21714. case 'mapEmissiveAnisotropy':
  21715. break;
  21716. case 'mapLight':
  21717. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  21718. break;
  21719. case 'mapLightRepeat':
  21720. case 'mapLightOffset':
  21721. case 'mapLightWrap':
  21722. case 'mapLightAnisotropy':
  21723. break;
  21724. case 'mapAO':
  21725. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  21726. break;
  21727. case 'mapAORepeat':
  21728. case 'mapAOOffset':
  21729. case 'mapAOWrap':
  21730. case 'mapAOAnisotropy':
  21731. break;
  21732. case 'mapBump':
  21733. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  21734. break;
  21735. case 'mapBumpScale':
  21736. json.bumpScale = value;
  21737. break;
  21738. case 'mapBumpRepeat':
  21739. case 'mapBumpOffset':
  21740. case 'mapBumpWrap':
  21741. case 'mapBumpAnisotropy':
  21742. break;
  21743. case 'mapNormal':
  21744. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  21745. break;
  21746. case 'mapNormalFactor':
  21747. json.normalScale = value;
  21748. break;
  21749. case 'mapNormalRepeat':
  21750. case 'mapNormalOffset':
  21751. case 'mapNormalWrap':
  21752. case 'mapNormalAnisotropy':
  21753. break;
  21754. case 'mapSpecular':
  21755. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  21756. break;
  21757. case 'mapSpecularRepeat':
  21758. case 'mapSpecularOffset':
  21759. case 'mapSpecularWrap':
  21760. case 'mapSpecularAnisotropy':
  21761. break;
  21762. case 'mapMetalness':
  21763. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  21764. break;
  21765. case 'mapMetalnessRepeat':
  21766. case 'mapMetalnessOffset':
  21767. case 'mapMetalnessWrap':
  21768. case 'mapMetalnessAnisotropy':
  21769. break;
  21770. case 'mapRoughness':
  21771. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  21772. break;
  21773. case 'mapRoughnessRepeat':
  21774. case 'mapRoughnessOffset':
  21775. case 'mapRoughnessWrap':
  21776. case 'mapRoughnessAnisotropy':
  21777. break;
  21778. case 'mapAlpha':
  21779. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  21780. break;
  21781. case 'mapAlphaRepeat':
  21782. case 'mapAlphaOffset':
  21783. case 'mapAlphaWrap':
  21784. case 'mapAlphaAnisotropy':
  21785. break;
  21786. case 'flipSided':
  21787. json.side = BackSide;
  21788. break;
  21789. case 'doubleSided':
  21790. json.side = DoubleSide;
  21791. break;
  21792. case 'transparency':
  21793. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  21794. json.opacity = value;
  21795. break;
  21796. case 'depthTest':
  21797. case 'depthWrite':
  21798. case 'colorWrite':
  21799. case 'opacity':
  21800. case 'reflectivity':
  21801. case 'transparent':
  21802. case 'visible':
  21803. case 'wireframe':
  21804. json[ name ] = value;
  21805. break;
  21806. case 'vertexColors':
  21807. if ( value === true ) json.vertexColors = VertexColors;
  21808. if ( value === 'face' ) json.vertexColors = FaceColors;
  21809. break;
  21810. default:
  21811. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  21812. break;
  21813. }
  21814. }
  21815. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  21816. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  21817. if ( json.opacity < 1 ) json.transparent = true;
  21818. materialLoader.setTextures( textures );
  21819. return materialLoader.parse( json );
  21820. };
  21821. } )()
  21822. } );
  21823. /**
  21824. * @author Don McCurdy / https://www.donmccurdy.com
  21825. */
  21826. var LoaderUtils = {
  21827. decodeText: function ( array ) {
  21828. if ( typeof TextDecoder !== 'undefined' ) {
  21829. return new TextDecoder().decode( array );
  21830. }
  21831. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  21832. // throws a "maximum call stack size exceeded" error for large arrays.
  21833. var s = '';
  21834. for ( var i = 0, il = array.length; i < il; i ++ ) {
  21835. // Implicitly assumes little-endian.
  21836. s += String.fromCharCode( array[ i ] );
  21837. }
  21838. // Merges multi-byte utf-8 characters.
  21839. return decodeURIComponent( escape( s ) );
  21840. },
  21841. extractUrlBase: function ( url ) {
  21842. var index = url.lastIndexOf( '/' );
  21843. if ( index === - 1 ) return './';
  21844. return url.substr( 0, index + 1 );
  21845. }
  21846. };
  21847. /**
  21848. * @author mrdoob / http://mrdoob.com/
  21849. * @author alteredq / http://alteredqualia.com/
  21850. */
  21851. function JSONLoader( manager ) {
  21852. if ( typeof manager === 'boolean' ) {
  21853. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  21854. manager = undefined;
  21855. }
  21856. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21857. this.withCredentials = false;
  21858. }
  21859. Object.assign( JSONLoader.prototype, {
  21860. load: function ( url, onLoad, onProgress, onError ) {
  21861. var scope = this;
  21862. var texturePath = this.texturePath && ( typeof this.texturePath === 'string' ) ? this.texturePath : LoaderUtils.extractUrlBase( url );
  21863. var loader = new FileLoader( this.manager );
  21864. loader.setWithCredentials( this.withCredentials );
  21865. loader.load( url, function ( text ) {
  21866. var json = JSON.parse( text );
  21867. var metadata = json.metadata;
  21868. if ( metadata !== undefined ) {
  21869. var type = metadata.type;
  21870. if ( type !== undefined ) {
  21871. if ( type.toLowerCase() === 'object' ) {
  21872. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  21873. return;
  21874. }
  21875. }
  21876. }
  21877. var object = scope.parse( json, texturePath );
  21878. onLoad( object.geometry, object.materials );
  21879. }, onProgress, onError );
  21880. },
  21881. setTexturePath: function ( value ) {
  21882. this.texturePath = value;
  21883. },
  21884. parse: ( function () {
  21885. function parseModel( json, geometry ) {
  21886. function isBitSet( value, position ) {
  21887. return value & ( 1 << position );
  21888. }
  21889. var i, j, fi,
  21890. offset, zLength,
  21891. colorIndex, normalIndex, uvIndex, materialIndex,
  21892. type,
  21893. isQuad,
  21894. hasMaterial,
  21895. hasFaceVertexUv,
  21896. hasFaceNormal, hasFaceVertexNormal,
  21897. hasFaceColor, hasFaceVertexColor,
  21898. vertex, face, faceA, faceB, hex, normal,
  21899. uvLayer, uv, u, v,
  21900. faces = json.faces,
  21901. vertices = json.vertices,
  21902. normals = json.normals,
  21903. colors = json.colors,
  21904. scale = json.scale,
  21905. nUvLayers = 0;
  21906. if ( json.uvs !== undefined ) {
  21907. // disregard empty arrays
  21908. for ( i = 0; i < json.uvs.length; i ++ ) {
  21909. if ( json.uvs[ i ].length ) nUvLayers ++;
  21910. }
  21911. for ( i = 0; i < nUvLayers; i ++ ) {
  21912. geometry.faceVertexUvs[ i ] = [];
  21913. }
  21914. }
  21915. offset = 0;
  21916. zLength = vertices.length;
  21917. while ( offset < zLength ) {
  21918. vertex = new Vector3();
  21919. vertex.x = vertices[ offset ++ ] * scale;
  21920. vertex.y = vertices[ offset ++ ] * scale;
  21921. vertex.z = vertices[ offset ++ ] * scale;
  21922. geometry.vertices.push( vertex );
  21923. }
  21924. offset = 0;
  21925. zLength = faces.length;
  21926. while ( offset < zLength ) {
  21927. type = faces[ offset ++ ];
  21928. isQuad = isBitSet( type, 0 );
  21929. hasMaterial = isBitSet( type, 1 );
  21930. hasFaceVertexUv = isBitSet( type, 3 );
  21931. hasFaceNormal = isBitSet( type, 4 );
  21932. hasFaceVertexNormal = isBitSet( type, 5 );
  21933. hasFaceColor = isBitSet( type, 6 );
  21934. hasFaceVertexColor = isBitSet( type, 7 );
  21935. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  21936. if ( isQuad ) {
  21937. faceA = new Face3();
  21938. faceA.a = faces[ offset ];
  21939. faceA.b = faces[ offset + 1 ];
  21940. faceA.c = faces[ offset + 3 ];
  21941. faceB = new Face3();
  21942. faceB.a = faces[ offset + 1 ];
  21943. faceB.b = faces[ offset + 2 ];
  21944. faceB.c = faces[ offset + 3 ];
  21945. offset += 4;
  21946. if ( hasMaterial ) {
  21947. materialIndex = faces[ offset ++ ];
  21948. faceA.materialIndex = materialIndex;
  21949. faceB.materialIndex = materialIndex;
  21950. }
  21951. // to get face <=> uv index correspondence
  21952. fi = geometry.faces.length;
  21953. if ( hasFaceVertexUv ) {
  21954. for ( i = 0; i < nUvLayers; i ++ ) {
  21955. uvLayer = json.uvs[ i ];
  21956. geometry.faceVertexUvs[ i ][ fi ] = [];
  21957. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  21958. for ( j = 0; j < 4; j ++ ) {
  21959. uvIndex = faces[ offset ++ ];
  21960. u = uvLayer[ uvIndex * 2 ];
  21961. v = uvLayer[ uvIndex * 2 + 1 ];
  21962. uv = new Vector2( u, v );
  21963. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  21964. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  21965. }
  21966. }
  21967. }
  21968. if ( hasFaceNormal ) {
  21969. normalIndex = faces[ offset ++ ] * 3;
  21970. faceA.normal.set(
  21971. normals[ normalIndex ++ ],
  21972. normals[ normalIndex ++ ],
  21973. normals[ normalIndex ]
  21974. );
  21975. faceB.normal.copy( faceA.normal );
  21976. }
  21977. if ( hasFaceVertexNormal ) {
  21978. for ( i = 0; i < 4; i ++ ) {
  21979. normalIndex = faces[ offset ++ ] * 3;
  21980. normal = new Vector3(
  21981. normals[ normalIndex ++ ],
  21982. normals[ normalIndex ++ ],
  21983. normals[ normalIndex ]
  21984. );
  21985. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  21986. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  21987. }
  21988. }
  21989. if ( hasFaceColor ) {
  21990. colorIndex = faces[ offset ++ ];
  21991. hex = colors[ colorIndex ];
  21992. faceA.color.setHex( hex );
  21993. faceB.color.setHex( hex );
  21994. }
  21995. if ( hasFaceVertexColor ) {
  21996. for ( i = 0; i < 4; i ++ ) {
  21997. colorIndex = faces[ offset ++ ];
  21998. hex = colors[ colorIndex ];
  21999. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  22000. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  22001. }
  22002. }
  22003. geometry.faces.push( faceA );
  22004. geometry.faces.push( faceB );
  22005. } else {
  22006. face = new Face3();
  22007. face.a = faces[ offset ++ ];
  22008. face.b = faces[ offset ++ ];
  22009. face.c = faces[ offset ++ ];
  22010. if ( hasMaterial ) {
  22011. materialIndex = faces[ offset ++ ];
  22012. face.materialIndex = materialIndex;
  22013. }
  22014. // to get face <=> uv index correspondence
  22015. fi = geometry.faces.length;
  22016. if ( hasFaceVertexUv ) {
  22017. for ( i = 0; i < nUvLayers; i ++ ) {
  22018. uvLayer = json.uvs[ i ];
  22019. geometry.faceVertexUvs[ i ][ fi ] = [];
  22020. for ( j = 0; j < 3; j ++ ) {
  22021. uvIndex = faces[ offset ++ ];
  22022. u = uvLayer[ uvIndex * 2 ];
  22023. v = uvLayer[ uvIndex * 2 + 1 ];
  22024. uv = new Vector2( u, v );
  22025. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  22026. }
  22027. }
  22028. }
  22029. if ( hasFaceNormal ) {
  22030. normalIndex = faces[ offset ++ ] * 3;
  22031. face.normal.set(
  22032. normals[ normalIndex ++ ],
  22033. normals[ normalIndex ++ ],
  22034. normals[ normalIndex ]
  22035. );
  22036. }
  22037. if ( hasFaceVertexNormal ) {
  22038. for ( i = 0; i < 3; i ++ ) {
  22039. normalIndex = faces[ offset ++ ] * 3;
  22040. normal = new Vector3(
  22041. normals[ normalIndex ++ ],
  22042. normals[ normalIndex ++ ],
  22043. normals[ normalIndex ]
  22044. );
  22045. face.vertexNormals.push( normal );
  22046. }
  22047. }
  22048. if ( hasFaceColor ) {
  22049. colorIndex = faces[ offset ++ ];
  22050. face.color.setHex( colors[ colorIndex ] );
  22051. }
  22052. if ( hasFaceVertexColor ) {
  22053. for ( i = 0; i < 3; i ++ ) {
  22054. colorIndex = faces[ offset ++ ];
  22055. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  22056. }
  22057. }
  22058. geometry.faces.push( face );
  22059. }
  22060. }
  22061. }
  22062. function parseSkin( json, geometry ) {
  22063. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  22064. if ( json.skinWeights ) {
  22065. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  22066. var x = json.skinWeights[ i ];
  22067. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  22068. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  22069. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  22070. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  22071. }
  22072. }
  22073. if ( json.skinIndices ) {
  22074. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  22075. var a = json.skinIndices[ i ];
  22076. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  22077. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  22078. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  22079. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  22080. }
  22081. }
  22082. geometry.bones = json.bones;
  22083. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  22084. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  22085. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  22086. }
  22087. }
  22088. function parseMorphing( json, geometry ) {
  22089. var scale = json.scale;
  22090. if ( json.morphTargets !== undefined ) {
  22091. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  22092. geometry.morphTargets[ i ] = {};
  22093. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  22094. geometry.morphTargets[ i ].vertices = [];
  22095. var dstVertices = geometry.morphTargets[ i ].vertices;
  22096. var srcVertices = json.morphTargets[ i ].vertices;
  22097. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  22098. var vertex = new Vector3();
  22099. vertex.x = srcVertices[ v ] * scale;
  22100. vertex.y = srcVertices[ v + 1 ] * scale;
  22101. vertex.z = srcVertices[ v + 2 ] * scale;
  22102. dstVertices.push( vertex );
  22103. }
  22104. }
  22105. }
  22106. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  22107. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  22108. var faces = geometry.faces;
  22109. var morphColors = json.morphColors[ 0 ].colors;
  22110. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22111. faces[ i ].color.fromArray( morphColors, i * 3 );
  22112. }
  22113. }
  22114. }
  22115. function parseAnimations( json, geometry ) {
  22116. var outputAnimations = [];
  22117. // parse old style Bone/Hierarchy animations
  22118. var animations = [];
  22119. if ( json.animation !== undefined ) {
  22120. animations.push( json.animation );
  22121. }
  22122. if ( json.animations !== undefined ) {
  22123. if ( json.animations.length ) {
  22124. animations = animations.concat( json.animations );
  22125. } else {
  22126. animations.push( json.animations );
  22127. }
  22128. }
  22129. for ( var i = 0; i < animations.length; i ++ ) {
  22130. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  22131. if ( clip ) outputAnimations.push( clip );
  22132. }
  22133. // parse implicit morph animations
  22134. if ( geometry.morphTargets ) {
  22135. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  22136. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  22137. outputAnimations = outputAnimations.concat( morphAnimationClips );
  22138. }
  22139. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  22140. }
  22141. return function parse( json, texturePath ) {
  22142. if ( json.data !== undefined ) {
  22143. // Geometry 4.0 spec
  22144. json = json.data;
  22145. }
  22146. if ( json.scale !== undefined ) {
  22147. json.scale = 1.0 / json.scale;
  22148. } else {
  22149. json.scale = 1.0;
  22150. }
  22151. var geometry = new Geometry();
  22152. parseModel( json, geometry );
  22153. parseSkin( json, geometry );
  22154. parseMorphing( json, geometry );
  22155. parseAnimations( json, geometry );
  22156. geometry.computeFaceNormals();
  22157. geometry.computeBoundingSphere();
  22158. if ( json.materials === undefined || json.materials.length === 0 ) {
  22159. return { geometry: geometry };
  22160. } else {
  22161. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  22162. return { geometry: geometry, materials: materials };
  22163. }
  22164. };
  22165. } )()
  22166. } );
  22167. /**
  22168. * @author mrdoob / http://mrdoob.com/
  22169. */
  22170. function ObjectLoader( manager ) {
  22171. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22172. this.texturePath = '';
  22173. }
  22174. Object.assign( ObjectLoader.prototype, {
  22175. load: function ( url, onLoad, onProgress, onError ) {
  22176. if ( this.texturePath === '' ) {
  22177. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  22178. }
  22179. var scope = this;
  22180. var loader = new FileLoader( scope.manager );
  22181. loader.load( url, function ( text ) {
  22182. var json = null;
  22183. try {
  22184. json = JSON.parse( text );
  22185. } catch ( error ) {
  22186. if ( onError !== undefined ) onError( error );
  22187. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22188. return;
  22189. }
  22190. var metadata = json.metadata;
  22191. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22192. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  22193. return;
  22194. }
  22195. scope.parse( json, onLoad );
  22196. }, onProgress, onError );
  22197. },
  22198. setTexturePath: function ( value ) {
  22199. this.texturePath = value;
  22200. return this;
  22201. },
  22202. setCrossOrigin: function ( value ) {
  22203. this.crossOrigin = value;
  22204. return this;
  22205. },
  22206. parse: function ( json, onLoad ) {
  22207. var shapes = this.parseShape( json.shapes );
  22208. var geometries = this.parseGeometries( json.geometries, shapes );
  22209. var images = this.parseImages( json.images, function () {
  22210. if ( onLoad !== undefined ) onLoad( object );
  22211. } );
  22212. var textures = this.parseTextures( json.textures, images );
  22213. var materials = this.parseMaterials( json.materials, textures );
  22214. var object = this.parseObject( json.object, geometries, materials );
  22215. if ( json.animations ) {
  22216. object.animations = this.parseAnimations( json.animations );
  22217. }
  22218. if ( json.images === undefined || json.images.length === 0 ) {
  22219. if ( onLoad !== undefined ) onLoad( object );
  22220. }
  22221. return object;
  22222. },
  22223. parseShape: function ( json ) {
  22224. var shapes = {};
  22225. if ( json !== undefined ) {
  22226. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22227. var shape = new Shape().fromJSON( json[ i ] );
  22228. shapes[ shape.uuid ] = shape;
  22229. }
  22230. }
  22231. return shapes;
  22232. },
  22233. parseGeometries: function ( json, shapes ) {
  22234. var geometries = {};
  22235. if ( json !== undefined ) {
  22236. var geometryLoader = new JSONLoader();
  22237. var bufferGeometryLoader = new BufferGeometryLoader();
  22238. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22239. var geometry;
  22240. var data = json[ i ];
  22241. switch ( data.type ) {
  22242. case 'PlaneGeometry':
  22243. case 'PlaneBufferGeometry':
  22244. geometry = new Geometries[ data.type ](
  22245. data.width,
  22246. data.height,
  22247. data.widthSegments,
  22248. data.heightSegments
  22249. );
  22250. break;
  22251. case 'BoxGeometry':
  22252. case 'BoxBufferGeometry':
  22253. case 'CubeGeometry': // backwards compatible
  22254. geometry = new Geometries[ data.type ](
  22255. data.width,
  22256. data.height,
  22257. data.depth,
  22258. data.widthSegments,
  22259. data.heightSegments,
  22260. data.depthSegments
  22261. );
  22262. break;
  22263. case 'CircleGeometry':
  22264. case 'CircleBufferGeometry':
  22265. geometry = new Geometries[ data.type ](
  22266. data.radius,
  22267. data.segments,
  22268. data.thetaStart,
  22269. data.thetaLength
  22270. );
  22271. break;
  22272. case 'CylinderGeometry':
  22273. case 'CylinderBufferGeometry':
  22274. geometry = new Geometries[ data.type ](
  22275. data.radiusTop,
  22276. data.radiusBottom,
  22277. data.height,
  22278. data.radialSegments,
  22279. data.heightSegments,
  22280. data.openEnded,
  22281. data.thetaStart,
  22282. data.thetaLength
  22283. );
  22284. break;
  22285. case 'ConeGeometry':
  22286. case 'ConeBufferGeometry':
  22287. geometry = new Geometries[ data.type ](
  22288. data.radius,
  22289. data.height,
  22290. data.radialSegments,
  22291. data.heightSegments,
  22292. data.openEnded,
  22293. data.thetaStart,
  22294. data.thetaLength
  22295. );
  22296. break;
  22297. case 'SphereGeometry':
  22298. case 'SphereBufferGeometry':
  22299. geometry = new Geometries[ data.type ](
  22300. data.radius,
  22301. data.widthSegments,
  22302. data.heightSegments,
  22303. data.phiStart,
  22304. data.phiLength,
  22305. data.thetaStart,
  22306. data.thetaLength
  22307. );
  22308. break;
  22309. case 'DodecahedronGeometry':
  22310. case 'DodecahedronBufferGeometry':
  22311. case 'IcosahedronGeometry':
  22312. case 'IcosahedronBufferGeometry':
  22313. case 'OctahedronGeometry':
  22314. case 'OctahedronBufferGeometry':
  22315. case 'TetrahedronGeometry':
  22316. case 'TetrahedronBufferGeometry':
  22317. geometry = new Geometries[ data.type ](
  22318. data.radius,
  22319. data.detail
  22320. );
  22321. break;
  22322. case 'RingGeometry':
  22323. case 'RingBufferGeometry':
  22324. geometry = new Geometries[ data.type ](
  22325. data.innerRadius,
  22326. data.outerRadius,
  22327. data.thetaSegments,
  22328. data.phiSegments,
  22329. data.thetaStart,
  22330. data.thetaLength
  22331. );
  22332. break;
  22333. case 'TorusGeometry':
  22334. case 'TorusBufferGeometry':
  22335. geometry = new Geometries[ data.type ](
  22336. data.radius,
  22337. data.tube,
  22338. data.radialSegments,
  22339. data.tubularSegments,
  22340. data.arc
  22341. );
  22342. break;
  22343. case 'TorusKnotGeometry':
  22344. case 'TorusKnotBufferGeometry':
  22345. geometry = new Geometries[ data.type ](
  22346. data.radius,
  22347. data.tube,
  22348. data.tubularSegments,
  22349. data.radialSegments,
  22350. data.p,
  22351. data.q
  22352. );
  22353. break;
  22354. case 'LatheGeometry':
  22355. case 'LatheBufferGeometry':
  22356. geometry = new Geometries[ data.type ](
  22357. data.points,
  22358. data.segments,
  22359. data.phiStart,
  22360. data.phiLength
  22361. );
  22362. break;
  22363. case 'PolyhedronGeometry':
  22364. case 'PolyhedronBufferGeometry':
  22365. geometry = new Geometries[ data.type ](
  22366. data.vertices,
  22367. data.indices,
  22368. data.radius,
  22369. data.details
  22370. );
  22371. break;
  22372. case 'ShapeGeometry':
  22373. case 'ShapeBufferGeometry':
  22374. var geometryShapes = [];
  22375. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22376. var shape = shapes[ data.shapes[ j ] ];
  22377. geometryShapes.push( shape );
  22378. }
  22379. geometry = new Geometries[ data.type ](
  22380. geometryShapes,
  22381. data.curveSegments
  22382. );
  22383. break;
  22384. case 'BufferGeometry':
  22385. geometry = bufferGeometryLoader.parse( data );
  22386. break;
  22387. case 'Geometry':
  22388. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  22389. break;
  22390. default:
  22391. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  22392. continue;
  22393. }
  22394. geometry.uuid = data.uuid;
  22395. if ( data.name !== undefined ) geometry.name = data.name;
  22396. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  22397. geometries[ data.uuid ] = geometry;
  22398. }
  22399. }
  22400. return geometries;
  22401. },
  22402. parseMaterials: function ( json, textures ) {
  22403. var materials = {};
  22404. if ( json !== undefined ) {
  22405. var loader = new MaterialLoader();
  22406. loader.setTextures( textures );
  22407. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22408. var data = json[ i ];
  22409. if ( data.type === 'MultiMaterial' ) {
  22410. // Deprecated
  22411. var array = [];
  22412. for ( var j = 0; j < data.materials.length; j ++ ) {
  22413. array.push( loader.parse( data.materials[ j ] ) );
  22414. }
  22415. materials[ data.uuid ] = array;
  22416. } else {
  22417. materials[ data.uuid ] = loader.parse( data );
  22418. }
  22419. }
  22420. }
  22421. return materials;
  22422. },
  22423. parseAnimations: function ( json ) {
  22424. var animations = [];
  22425. for ( var i = 0; i < json.length; i ++ ) {
  22426. var data = json[ i ];
  22427. var clip = AnimationClip.parse( data );
  22428. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  22429. animations.push( clip );
  22430. }
  22431. return animations;
  22432. },
  22433. parseImages: function ( json, onLoad ) {
  22434. var scope = this;
  22435. var images = {};
  22436. function loadImage( url ) {
  22437. scope.manager.itemStart( url );
  22438. return loader.load( url, function () {
  22439. scope.manager.itemEnd( url );
  22440. }, undefined, function () {
  22441. scope.manager.itemEnd( url );
  22442. scope.manager.itemError( url );
  22443. } );
  22444. }
  22445. if ( json !== undefined && json.length > 0 ) {
  22446. var manager = new LoadingManager( onLoad );
  22447. var loader = new ImageLoader( manager );
  22448. loader.setCrossOrigin( this.crossOrigin );
  22449. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22450. var image = json[ i ];
  22451. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  22452. images[ image.uuid ] = loadImage( path );
  22453. }
  22454. }
  22455. return images;
  22456. },
  22457. parseTextures: function ( json, images ) {
  22458. function parseConstant( value, type ) {
  22459. if ( typeof value === 'number' ) return value;
  22460. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  22461. return type[ value ];
  22462. }
  22463. var textures = {};
  22464. if ( json !== undefined ) {
  22465. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22466. var data = json[ i ];
  22467. if ( data.image === undefined ) {
  22468. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  22469. }
  22470. if ( images[ data.image ] === undefined ) {
  22471. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  22472. }
  22473. var texture = new Texture( images[ data.image ] );
  22474. texture.needsUpdate = true;
  22475. texture.uuid = data.uuid;
  22476. if ( data.name !== undefined ) texture.name = data.name;
  22477. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  22478. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  22479. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  22480. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  22481. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  22482. if ( data.wrap !== undefined ) {
  22483. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  22484. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  22485. }
  22486. if ( data.format !== undefined ) texture.format = data.format;
  22487. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  22488. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  22489. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  22490. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  22491. textures[ data.uuid ] = texture;
  22492. }
  22493. }
  22494. return textures;
  22495. },
  22496. parseObject: function ( data, geometries, materials ) {
  22497. var object;
  22498. function getGeometry( name ) {
  22499. if ( geometries[ name ] === undefined ) {
  22500. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  22501. }
  22502. return geometries[ name ];
  22503. }
  22504. function getMaterial( name ) {
  22505. if ( name === undefined ) return undefined;
  22506. if ( Array.isArray( name ) ) {
  22507. var array = [];
  22508. for ( var i = 0, l = name.length; i < l; i ++ ) {
  22509. var uuid = name[ i ];
  22510. if ( materials[ uuid ] === undefined ) {
  22511. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  22512. }
  22513. array.push( materials[ uuid ] );
  22514. }
  22515. return array;
  22516. }
  22517. if ( materials[ name ] === undefined ) {
  22518. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  22519. }
  22520. return materials[ name ];
  22521. }
  22522. switch ( data.type ) {
  22523. case 'Scene':
  22524. object = new Scene();
  22525. if ( data.background !== undefined ) {
  22526. if ( Number.isInteger( data.background ) ) {
  22527. object.background = new Color( data.background );
  22528. }
  22529. }
  22530. if ( data.fog !== undefined ) {
  22531. if ( data.fog.type === 'Fog' ) {
  22532. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  22533. } else if ( data.fog.type === 'FogExp2' ) {
  22534. object.fog = new FogExp2( data.fog.color, data.fog.density );
  22535. }
  22536. }
  22537. break;
  22538. case 'PerspectiveCamera':
  22539. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  22540. if ( data.focus !== undefined ) object.focus = data.focus;
  22541. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22542. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  22543. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  22544. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22545. break;
  22546. case 'OrthographicCamera':
  22547. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  22548. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22549. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22550. break;
  22551. case 'AmbientLight':
  22552. object = new AmbientLight( data.color, data.intensity );
  22553. break;
  22554. case 'DirectionalLight':
  22555. object = new DirectionalLight( data.color, data.intensity );
  22556. break;
  22557. case 'PointLight':
  22558. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  22559. break;
  22560. case 'RectAreaLight':
  22561. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  22562. break;
  22563. case 'SpotLight':
  22564. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  22565. break;
  22566. case 'HemisphereLight':
  22567. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  22568. break;
  22569. case 'SkinnedMesh':
  22570. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  22571. case 'Mesh':
  22572. var geometry = getGeometry( data.geometry );
  22573. var material = getMaterial( data.material );
  22574. if ( geometry.bones && geometry.bones.length > 0 ) {
  22575. object = new SkinnedMesh( geometry, material );
  22576. } else {
  22577. object = new Mesh( geometry, material );
  22578. }
  22579. break;
  22580. case 'LOD':
  22581. object = new LOD();
  22582. break;
  22583. case 'Line':
  22584. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  22585. break;
  22586. case 'LineLoop':
  22587. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  22588. break;
  22589. case 'LineSegments':
  22590. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  22591. break;
  22592. case 'PointCloud':
  22593. case 'Points':
  22594. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  22595. break;
  22596. case 'Sprite':
  22597. object = new Sprite( getMaterial( data.material ) );
  22598. break;
  22599. case 'Group':
  22600. object = new Group();
  22601. break;
  22602. default:
  22603. object = new Object3D();
  22604. }
  22605. object.uuid = data.uuid;
  22606. if ( data.name !== undefined ) object.name = data.name;
  22607. if ( data.matrix !== undefined ) {
  22608. object.matrix.fromArray( data.matrix );
  22609. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  22610. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  22611. } else {
  22612. if ( data.position !== undefined ) object.position.fromArray( data.position );
  22613. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  22614. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  22615. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  22616. }
  22617. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  22618. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  22619. if ( data.shadow ) {
  22620. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  22621. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  22622. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  22623. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  22624. }
  22625. if ( data.visible !== undefined ) object.visible = data.visible;
  22626. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  22627. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  22628. if ( data.userData !== undefined ) object.userData = data.userData;
  22629. if ( data.children !== undefined ) {
  22630. var children = data.children;
  22631. for ( var i = 0; i < children.length; i ++ ) {
  22632. object.add( this.parseObject( children[ i ], geometries, materials ) );
  22633. }
  22634. }
  22635. if ( data.type === 'LOD' ) {
  22636. var levels = data.levels;
  22637. for ( var l = 0; l < levels.length; l ++ ) {
  22638. var level = levels[ l ];
  22639. var child = object.getObjectByProperty( 'uuid', level.object );
  22640. if ( child !== undefined ) {
  22641. object.addLevel( child, level.distance );
  22642. }
  22643. }
  22644. }
  22645. return object;
  22646. }
  22647. } );
  22648. var TEXTURE_MAPPING = {
  22649. UVMapping: UVMapping,
  22650. CubeReflectionMapping: CubeReflectionMapping,
  22651. CubeRefractionMapping: CubeRefractionMapping,
  22652. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  22653. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  22654. SphericalReflectionMapping: SphericalReflectionMapping,
  22655. CubeUVReflectionMapping: CubeUVReflectionMapping,
  22656. CubeUVRefractionMapping: CubeUVRefractionMapping
  22657. };
  22658. var TEXTURE_WRAPPING = {
  22659. RepeatWrapping: RepeatWrapping,
  22660. ClampToEdgeWrapping: ClampToEdgeWrapping,
  22661. MirroredRepeatWrapping: MirroredRepeatWrapping
  22662. };
  22663. var TEXTURE_FILTER = {
  22664. NearestFilter: NearestFilter,
  22665. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  22666. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  22667. LinearFilter: LinearFilter,
  22668. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  22669. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  22670. };
  22671. /**
  22672. * @author thespite / http://clicktorelease.com/
  22673. */
  22674. function ImageBitmapLoader( manager ) {
  22675. if ( typeof createImageBitmap === 'undefined' ) {
  22676. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  22677. }
  22678. if ( typeof fetch === 'undefined' ) {
  22679. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  22680. }
  22681. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22682. this.options = undefined;
  22683. }
  22684. ImageBitmapLoader.prototype = {
  22685. constructor: ImageBitmapLoader,
  22686. setOptions: function setOptions( options ) {
  22687. this.options = options;
  22688. return this;
  22689. },
  22690. load: function ( url, onLoad, onProgress, onError ) {
  22691. if ( url === undefined ) url = '';
  22692. if ( this.path !== undefined ) url = this.path + url;
  22693. url = this.manager.resolveURL( url );
  22694. var scope = this;
  22695. var cached = Cache.get( url );
  22696. if ( cached !== undefined ) {
  22697. scope.manager.itemStart( url );
  22698. setTimeout( function () {
  22699. if ( onLoad ) onLoad( cached );
  22700. scope.manager.itemEnd( url );
  22701. }, 0 );
  22702. return cached;
  22703. }
  22704. fetch( url ).then( function ( res ) {
  22705. return res.blob();
  22706. } ).then( function ( blob ) {
  22707. return createImageBitmap( blob, scope.options );
  22708. } ).then( function ( imageBitmap ) {
  22709. Cache.add( url, imageBitmap );
  22710. if ( onLoad ) onLoad( imageBitmap );
  22711. scope.manager.itemEnd( url );
  22712. } ).catch( function ( e ) {
  22713. if ( onError ) onError( e );
  22714. scope.manager.itemEnd( url );
  22715. scope.manager.itemError( url );
  22716. } );
  22717. },
  22718. setCrossOrigin: function ( /* value */ ) {
  22719. return this;
  22720. },
  22721. setPath: function ( value ) {
  22722. this.path = value;
  22723. return this;
  22724. }
  22725. };
  22726. /**
  22727. * @author zz85 / http://www.lab4games.net/zz85/blog
  22728. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  22729. **/
  22730. function ShapePath() {
  22731. this.type = 'ShapePath';
  22732. this.color = new Color();
  22733. this.subPaths = [];
  22734. this.currentPath = null;
  22735. }
  22736. Object.assign( ShapePath.prototype, {
  22737. moveTo: function ( x, y ) {
  22738. this.currentPath = new Path();
  22739. this.subPaths.push( this.currentPath );
  22740. this.currentPath.moveTo( x, y );
  22741. },
  22742. lineTo: function ( x, y ) {
  22743. this.currentPath.lineTo( x, y );
  22744. },
  22745. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22746. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  22747. },
  22748. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22749. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  22750. },
  22751. splineThru: function ( pts ) {
  22752. this.currentPath.splineThru( pts );
  22753. },
  22754. toShapes: function ( isCCW, noHoles ) {
  22755. function toShapesNoHoles( inSubpaths ) {
  22756. var shapes = [];
  22757. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  22758. var tmpPath = inSubpaths[ i ];
  22759. var tmpShape = new Shape();
  22760. tmpShape.curves = tmpPath.curves;
  22761. shapes.push( tmpShape );
  22762. }
  22763. return shapes;
  22764. }
  22765. function isPointInsidePolygon( inPt, inPolygon ) {
  22766. var polyLen = inPolygon.length;
  22767. // inPt on polygon contour => immediate success or
  22768. // toggling of inside/outside at every single! intersection point of an edge
  22769. // with the horizontal line through inPt, left of inPt
  22770. // not counting lowerY endpoints of edges and whole edges on that line
  22771. var inside = false;
  22772. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  22773. var edgeLowPt = inPolygon[ p ];
  22774. var edgeHighPt = inPolygon[ q ];
  22775. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  22776. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  22777. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  22778. // not parallel
  22779. if ( edgeDy < 0 ) {
  22780. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  22781. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  22782. }
  22783. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  22784. if ( inPt.y === edgeLowPt.y ) {
  22785. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  22786. // continue; // no intersection or edgeLowPt => doesn't count !!!
  22787. } else {
  22788. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  22789. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  22790. if ( perpEdge < 0 ) continue;
  22791. inside = ! inside; // true intersection left of inPt
  22792. }
  22793. } else {
  22794. // parallel or collinear
  22795. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  22796. // edge lies on the same horizontal line as inPt
  22797. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  22798. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  22799. // continue;
  22800. }
  22801. }
  22802. return inside;
  22803. }
  22804. var isClockWise = ShapeUtils.isClockWise;
  22805. var subPaths = this.subPaths;
  22806. if ( subPaths.length === 0 ) return [];
  22807. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  22808. var solid, tmpPath, tmpShape, shapes = [];
  22809. if ( subPaths.length === 1 ) {
  22810. tmpPath = subPaths[ 0 ];
  22811. tmpShape = new Shape();
  22812. tmpShape.curves = tmpPath.curves;
  22813. shapes.push( tmpShape );
  22814. return shapes;
  22815. }
  22816. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  22817. holesFirst = isCCW ? ! holesFirst : holesFirst;
  22818. // console.log("Holes first", holesFirst);
  22819. var betterShapeHoles = [];
  22820. var newShapes = [];
  22821. var newShapeHoles = [];
  22822. var mainIdx = 0;
  22823. var tmpPoints;
  22824. newShapes[ mainIdx ] = undefined;
  22825. newShapeHoles[ mainIdx ] = [];
  22826. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  22827. tmpPath = subPaths[ i ];
  22828. tmpPoints = tmpPath.getPoints();
  22829. solid = isClockWise( tmpPoints );
  22830. solid = isCCW ? ! solid : solid;
  22831. if ( solid ) {
  22832. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  22833. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  22834. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  22835. if ( holesFirst ) mainIdx ++;
  22836. newShapeHoles[ mainIdx ] = [];
  22837. //console.log('cw', i);
  22838. } else {
  22839. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  22840. //console.log('ccw', i);
  22841. }
  22842. }
  22843. // only Holes? -> probably all Shapes with wrong orientation
  22844. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  22845. if ( newShapes.length > 1 ) {
  22846. var ambiguous = false;
  22847. var toChange = [];
  22848. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22849. betterShapeHoles[ sIdx ] = [];
  22850. }
  22851. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22852. var sho = newShapeHoles[ sIdx ];
  22853. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  22854. var ho = sho[ hIdx ];
  22855. var hole_unassigned = true;
  22856. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  22857. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  22858. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  22859. if ( hole_unassigned ) {
  22860. hole_unassigned = false;
  22861. betterShapeHoles[ s2Idx ].push( ho );
  22862. } else {
  22863. ambiguous = true;
  22864. }
  22865. }
  22866. }
  22867. if ( hole_unassigned ) {
  22868. betterShapeHoles[ sIdx ].push( ho );
  22869. }
  22870. }
  22871. }
  22872. // console.log("ambiguous: ", ambiguous);
  22873. if ( toChange.length > 0 ) {
  22874. // console.log("to change: ", toChange);
  22875. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  22876. }
  22877. }
  22878. var tmpHoles;
  22879. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  22880. tmpShape = newShapes[ i ].s;
  22881. shapes.push( tmpShape );
  22882. tmpHoles = newShapeHoles[ i ];
  22883. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  22884. tmpShape.holes.push( tmpHoles[ j ].h );
  22885. }
  22886. }
  22887. //console.log("shape", shapes);
  22888. return shapes;
  22889. }
  22890. } );
  22891. /**
  22892. * @author zz85 / http://www.lab4games.net/zz85/blog
  22893. * @author mrdoob / http://mrdoob.com/
  22894. */
  22895. function Font( data ) {
  22896. this.type = 'Font';
  22897. this.data = data;
  22898. }
  22899. Object.assign( Font.prototype, {
  22900. isFont: true,
  22901. generateShapes: function ( text, size, divisions ) {
  22902. if ( size === undefined ) size = 100;
  22903. if ( divisions === undefined ) divisions = 4;
  22904. var shapes = [];
  22905. var paths = createPaths( text, size, divisions, this.data );
  22906. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  22907. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  22908. }
  22909. return shapes;
  22910. }
  22911. } );
  22912. function createPaths( text, size, divisions, data ) {
  22913. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  22914. var scale = size / data.resolution;
  22915. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  22916. var paths = [];
  22917. var offsetX = 0, offsetY = 0;
  22918. for ( var i = 0; i < chars.length; i ++ ) {
  22919. var char = chars[ i ];
  22920. if ( char === '\n' ) {
  22921. offsetX = 0;
  22922. offsetY -= line_height;
  22923. } else {
  22924. var ret = createPath( char, divisions, scale, offsetX, offsetY, data );
  22925. offsetX += ret.offsetX;
  22926. paths.push( ret.path );
  22927. }
  22928. }
  22929. return paths;
  22930. }
  22931. function createPath( char, divisions, scale, offsetX, offsetY, data ) {
  22932. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  22933. if ( ! glyph ) return;
  22934. var path = new ShapePath();
  22935. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  22936. if ( glyph.o ) {
  22937. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  22938. for ( var i = 0, l = outline.length; i < l; ) {
  22939. var action = outline[ i ++ ];
  22940. switch ( action ) {
  22941. case 'm': // moveTo
  22942. x = outline[ i ++ ] * scale + offsetX;
  22943. y = outline[ i ++ ] * scale + offsetY;
  22944. path.moveTo( x, y );
  22945. break;
  22946. case 'l': // lineTo
  22947. x = outline[ i ++ ] * scale + offsetX;
  22948. y = outline[ i ++ ] * scale + offsetY;
  22949. path.lineTo( x, y );
  22950. break;
  22951. case 'q': // quadraticCurveTo
  22952. cpx = outline[ i ++ ] * scale + offsetX;
  22953. cpy = outline[ i ++ ] * scale + offsetY;
  22954. cpx1 = outline[ i ++ ] * scale + offsetX;
  22955. cpy1 = outline[ i ++ ] * scale + offsetY;
  22956. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  22957. break;
  22958. case 'b': // bezierCurveTo
  22959. cpx = outline[ i ++ ] * scale + offsetX;
  22960. cpy = outline[ i ++ ] * scale + offsetY;
  22961. cpx1 = outline[ i ++ ] * scale + offsetX;
  22962. cpy1 = outline[ i ++ ] * scale + offsetY;
  22963. cpx2 = outline[ i ++ ] * scale + offsetX;
  22964. cpy2 = outline[ i ++ ] * scale + offsetY;
  22965. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  22966. break;
  22967. }
  22968. }
  22969. }
  22970. return { offsetX: glyph.ha * scale, path: path };
  22971. }
  22972. /**
  22973. * @author mrdoob / http://mrdoob.com/
  22974. */
  22975. function FontLoader( manager ) {
  22976. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22977. }
  22978. Object.assign( FontLoader.prototype, {
  22979. load: function ( url, onLoad, onProgress, onError ) {
  22980. var scope = this;
  22981. var loader = new FileLoader( this.manager );
  22982. loader.setPath( this.path );
  22983. loader.load( url, function ( text ) {
  22984. var json;
  22985. try {
  22986. json = JSON.parse( text );
  22987. } catch ( e ) {
  22988. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  22989. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  22990. }
  22991. var font = scope.parse( json );
  22992. if ( onLoad ) onLoad( font );
  22993. }, onProgress, onError );
  22994. },
  22995. parse: function ( json ) {
  22996. return new Font( json );
  22997. },
  22998. setPath: function ( value ) {
  22999. this.path = value;
  23000. return this;
  23001. }
  23002. } );
  23003. /**
  23004. * @author mrdoob / http://mrdoob.com/
  23005. */
  23006. var context;
  23007. var AudioContext = {
  23008. getContext: function () {
  23009. if ( context === undefined ) {
  23010. context = new ( window.AudioContext || window.webkitAudioContext )();
  23011. }
  23012. return context;
  23013. },
  23014. setContext: function ( value ) {
  23015. context = value;
  23016. }
  23017. };
  23018. /**
  23019. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23020. */
  23021. function AudioLoader( manager ) {
  23022. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23023. }
  23024. Object.assign( AudioLoader.prototype, {
  23025. load: function ( url, onLoad, onProgress, onError ) {
  23026. var loader = new FileLoader( this.manager );
  23027. loader.setResponseType( 'arraybuffer' );
  23028. loader.load( url, function ( buffer ) {
  23029. var context = AudioContext.getContext();
  23030. context.decodeAudioData( buffer, function ( audioBuffer ) {
  23031. onLoad( audioBuffer );
  23032. } );
  23033. }, onProgress, onError );
  23034. }
  23035. } );
  23036. /**
  23037. * @author mrdoob / http://mrdoob.com/
  23038. */
  23039. function StereoCamera() {
  23040. this.type = 'StereoCamera';
  23041. this.aspect = 1;
  23042. this.eyeSep = 0.064;
  23043. this.cameraL = new PerspectiveCamera();
  23044. this.cameraL.layers.enable( 1 );
  23045. this.cameraL.matrixAutoUpdate = false;
  23046. this.cameraR = new PerspectiveCamera();
  23047. this.cameraR.layers.enable( 2 );
  23048. this.cameraR.matrixAutoUpdate = false;
  23049. }
  23050. Object.assign( StereoCamera.prototype, {
  23051. update: ( function () {
  23052. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  23053. var eyeRight = new Matrix4();
  23054. var eyeLeft = new Matrix4();
  23055. return function update( camera ) {
  23056. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  23057. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  23058. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  23059. if ( needsUpdate ) {
  23060. instance = this;
  23061. focus = camera.focus;
  23062. fov = camera.fov;
  23063. aspect = camera.aspect * this.aspect;
  23064. near = camera.near;
  23065. far = camera.far;
  23066. zoom = camera.zoom;
  23067. // Off-axis stereoscopic effect based on
  23068. // http://paulbourke.net/stereographics/stereorender/
  23069. var projectionMatrix = camera.projectionMatrix.clone();
  23070. eyeSep = this.eyeSep / 2;
  23071. var eyeSepOnProjection = eyeSep * near / focus;
  23072. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  23073. var xmin, xmax;
  23074. // translate xOffset
  23075. eyeLeft.elements[ 12 ] = - eyeSep;
  23076. eyeRight.elements[ 12 ] = eyeSep;
  23077. // for left eye
  23078. xmin = - ymax * aspect + eyeSepOnProjection;
  23079. xmax = ymax * aspect + eyeSepOnProjection;
  23080. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23081. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23082. this.cameraL.projectionMatrix.copy( projectionMatrix );
  23083. // for right eye
  23084. xmin = - ymax * aspect - eyeSepOnProjection;
  23085. xmax = ymax * aspect - eyeSepOnProjection;
  23086. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23087. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23088. this.cameraR.projectionMatrix.copy( projectionMatrix );
  23089. }
  23090. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  23091. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  23092. };
  23093. } )()
  23094. } );
  23095. /**
  23096. * Camera for rendering cube maps
  23097. * - renders scene into axis-aligned cube
  23098. *
  23099. * @author alteredq / http://alteredqualia.com/
  23100. */
  23101. function CubeCamera( near, far, cubeResolution ) {
  23102. Object3D.call( this );
  23103. this.type = 'CubeCamera';
  23104. var fov = 90, aspect = 1;
  23105. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  23106. cameraPX.up.set( 0, - 1, 0 );
  23107. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  23108. this.add( cameraPX );
  23109. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  23110. cameraNX.up.set( 0, - 1, 0 );
  23111. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  23112. this.add( cameraNX );
  23113. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  23114. cameraPY.up.set( 0, 0, 1 );
  23115. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  23116. this.add( cameraPY );
  23117. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  23118. cameraNY.up.set( 0, 0, - 1 );
  23119. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  23120. this.add( cameraNY );
  23121. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  23122. cameraPZ.up.set( 0, - 1, 0 );
  23123. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  23124. this.add( cameraPZ );
  23125. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  23126. cameraNZ.up.set( 0, - 1, 0 );
  23127. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  23128. this.add( cameraNZ );
  23129. var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  23130. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  23131. this.renderTarget.texture.name = "CubeCamera";
  23132. this.update = function ( renderer, scene ) {
  23133. if ( this.parent === null ) this.updateMatrixWorld();
  23134. var renderTarget = this.renderTarget;
  23135. var generateMipmaps = renderTarget.texture.generateMipmaps;
  23136. renderTarget.texture.generateMipmaps = false;
  23137. renderTarget.activeCubeFace = 0;
  23138. renderer.render( scene, cameraPX, renderTarget );
  23139. renderTarget.activeCubeFace = 1;
  23140. renderer.render( scene, cameraNX, renderTarget );
  23141. renderTarget.activeCubeFace = 2;
  23142. renderer.render( scene, cameraPY, renderTarget );
  23143. renderTarget.activeCubeFace = 3;
  23144. renderer.render( scene, cameraNY, renderTarget );
  23145. renderTarget.activeCubeFace = 4;
  23146. renderer.render( scene, cameraPZ, renderTarget );
  23147. renderTarget.texture.generateMipmaps = generateMipmaps;
  23148. renderTarget.activeCubeFace = 5;
  23149. renderer.render( scene, cameraNZ, renderTarget );
  23150. renderer.setRenderTarget( null );
  23151. };
  23152. this.clear = function ( renderer, color, depth, stencil ) {
  23153. var renderTarget = this.renderTarget;
  23154. for ( var i = 0; i < 6; i ++ ) {
  23155. renderTarget.activeCubeFace = i;
  23156. renderer.setRenderTarget( renderTarget );
  23157. renderer.clear( color, depth, stencil );
  23158. }
  23159. renderer.setRenderTarget( null );
  23160. };
  23161. }
  23162. CubeCamera.prototype = Object.create( Object3D.prototype );
  23163. CubeCamera.prototype.constructor = CubeCamera;
  23164. /**
  23165. * @author mrdoob / http://mrdoob.com/
  23166. */
  23167. function AudioListener() {
  23168. Object3D.call( this );
  23169. this.type = 'AudioListener';
  23170. this.context = AudioContext.getContext();
  23171. this.gain = this.context.createGain();
  23172. this.gain.connect( this.context.destination );
  23173. this.filter = null;
  23174. }
  23175. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23176. constructor: AudioListener,
  23177. getInput: function () {
  23178. return this.gain;
  23179. },
  23180. removeFilter: function ( ) {
  23181. if ( this.filter !== null ) {
  23182. this.gain.disconnect( this.filter );
  23183. this.filter.disconnect( this.context.destination );
  23184. this.gain.connect( this.context.destination );
  23185. this.filter = null;
  23186. }
  23187. },
  23188. getFilter: function () {
  23189. return this.filter;
  23190. },
  23191. setFilter: function ( value ) {
  23192. if ( this.filter !== null ) {
  23193. this.gain.disconnect( this.filter );
  23194. this.filter.disconnect( this.context.destination );
  23195. } else {
  23196. this.gain.disconnect( this.context.destination );
  23197. }
  23198. this.filter = value;
  23199. this.gain.connect( this.filter );
  23200. this.filter.connect( this.context.destination );
  23201. },
  23202. getMasterVolume: function () {
  23203. return this.gain.gain.value;
  23204. },
  23205. setMasterVolume: function ( value ) {
  23206. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  23207. },
  23208. updateMatrixWorld: ( function () {
  23209. var position = new Vector3();
  23210. var quaternion = new Quaternion();
  23211. var scale = new Vector3();
  23212. var orientation = new Vector3();
  23213. return function updateMatrixWorld( force ) {
  23214. Object3D.prototype.updateMatrixWorld.call( this, force );
  23215. var listener = this.context.listener;
  23216. var up = this.up;
  23217. this.matrixWorld.decompose( position, quaternion, scale );
  23218. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  23219. if ( listener.positionX ) {
  23220. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  23221. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  23222. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  23223. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  23224. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  23225. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  23226. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  23227. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  23228. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  23229. } else {
  23230. listener.setPosition( position.x, position.y, position.z );
  23231. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  23232. }
  23233. };
  23234. } )()
  23235. } );
  23236. /**
  23237. * @author mrdoob / http://mrdoob.com/
  23238. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23239. */
  23240. function Audio( listener ) {
  23241. Object3D.call( this );
  23242. this.type = 'Audio';
  23243. this.context = listener.context;
  23244. this.gain = this.context.createGain();
  23245. this.gain.connect( listener.getInput() );
  23246. this.autoplay = false;
  23247. this.buffer = null;
  23248. this.loop = false;
  23249. this.startTime = 0;
  23250. this.offset = 0;
  23251. this.playbackRate = 1;
  23252. this.isPlaying = false;
  23253. this.hasPlaybackControl = true;
  23254. this.sourceType = 'empty';
  23255. this.filters = [];
  23256. }
  23257. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23258. constructor: Audio,
  23259. getOutput: function () {
  23260. return this.gain;
  23261. },
  23262. setNodeSource: function ( audioNode ) {
  23263. this.hasPlaybackControl = false;
  23264. this.sourceType = 'audioNode';
  23265. this.source = audioNode;
  23266. this.connect();
  23267. return this;
  23268. },
  23269. setMediaElementSource: function ( mediaElement ) {
  23270. this.hasPlaybackControl = false;
  23271. this.sourceType = 'mediaNode';
  23272. this.source = this.context.createMediaElementSource( mediaElement );
  23273. this.connect();
  23274. return this;
  23275. },
  23276. setBuffer: function ( audioBuffer ) {
  23277. this.buffer = audioBuffer;
  23278. this.sourceType = 'buffer';
  23279. if ( this.autoplay ) this.play();
  23280. return this;
  23281. },
  23282. play: function () {
  23283. if ( this.isPlaying === true ) {
  23284. console.warn( 'THREE.Audio: Audio is already playing.' );
  23285. return;
  23286. }
  23287. if ( this.hasPlaybackControl === false ) {
  23288. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23289. return;
  23290. }
  23291. var source = this.context.createBufferSource();
  23292. source.buffer = this.buffer;
  23293. source.loop = this.loop;
  23294. source.onended = this.onEnded.bind( this );
  23295. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  23296. this.startTime = this.context.currentTime;
  23297. source.start( this.startTime, this.offset );
  23298. this.isPlaying = true;
  23299. this.source = source;
  23300. return this.connect();
  23301. },
  23302. pause: function () {
  23303. if ( this.hasPlaybackControl === false ) {
  23304. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23305. return;
  23306. }
  23307. if ( this.isPlaying === true ) {
  23308. this.source.stop();
  23309. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  23310. this.isPlaying = false;
  23311. }
  23312. return this;
  23313. },
  23314. stop: function () {
  23315. if ( this.hasPlaybackControl === false ) {
  23316. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23317. return;
  23318. }
  23319. this.source.stop();
  23320. this.offset = 0;
  23321. this.isPlaying = false;
  23322. return this;
  23323. },
  23324. connect: function () {
  23325. if ( this.filters.length > 0 ) {
  23326. this.source.connect( this.filters[ 0 ] );
  23327. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  23328. this.filters[ i - 1 ].connect( this.filters[ i ] );
  23329. }
  23330. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  23331. } else {
  23332. this.source.connect( this.getOutput() );
  23333. }
  23334. return this;
  23335. },
  23336. disconnect: function () {
  23337. if ( this.filters.length > 0 ) {
  23338. this.source.disconnect( this.filters[ 0 ] );
  23339. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  23340. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  23341. }
  23342. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  23343. } else {
  23344. this.source.disconnect( this.getOutput() );
  23345. }
  23346. return this;
  23347. },
  23348. getFilters: function () {
  23349. return this.filters;
  23350. },
  23351. setFilters: function ( value ) {
  23352. if ( ! value ) value = [];
  23353. if ( this.isPlaying === true ) {
  23354. this.disconnect();
  23355. this.filters = value;
  23356. this.connect();
  23357. } else {
  23358. this.filters = value;
  23359. }
  23360. return this;
  23361. },
  23362. getFilter: function () {
  23363. return this.getFilters()[ 0 ];
  23364. },
  23365. setFilter: function ( filter ) {
  23366. return this.setFilters( filter ? [ filter ] : [] );
  23367. },
  23368. setPlaybackRate: function ( value ) {
  23369. if ( this.hasPlaybackControl === false ) {
  23370. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23371. return;
  23372. }
  23373. this.playbackRate = value;
  23374. if ( this.isPlaying === true ) {
  23375. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  23376. }
  23377. return this;
  23378. },
  23379. getPlaybackRate: function () {
  23380. return this.playbackRate;
  23381. },
  23382. onEnded: function () {
  23383. this.isPlaying = false;
  23384. },
  23385. getLoop: function () {
  23386. if ( this.hasPlaybackControl === false ) {
  23387. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23388. return false;
  23389. }
  23390. return this.loop;
  23391. },
  23392. setLoop: function ( value ) {
  23393. if ( this.hasPlaybackControl === false ) {
  23394. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23395. return;
  23396. }
  23397. this.loop = value;
  23398. if ( this.isPlaying === true ) {
  23399. this.source.loop = this.loop;
  23400. }
  23401. return this;
  23402. },
  23403. getVolume: function () {
  23404. return this.gain.gain.value;
  23405. },
  23406. setVolume: function ( value ) {
  23407. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  23408. return this;
  23409. }
  23410. } );
  23411. /**
  23412. * @author mrdoob / http://mrdoob.com/
  23413. */
  23414. function PositionalAudio( listener ) {
  23415. Audio.call( this, listener );
  23416. this.panner = this.context.createPanner();
  23417. this.panner.connect( this.gain );
  23418. }
  23419. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  23420. constructor: PositionalAudio,
  23421. getOutput: function () {
  23422. return this.panner;
  23423. },
  23424. getRefDistance: function () {
  23425. return this.panner.refDistance;
  23426. },
  23427. setRefDistance: function ( value ) {
  23428. this.panner.refDistance = value;
  23429. },
  23430. getRolloffFactor: function () {
  23431. return this.panner.rolloffFactor;
  23432. },
  23433. setRolloffFactor: function ( value ) {
  23434. this.panner.rolloffFactor = value;
  23435. },
  23436. getDistanceModel: function () {
  23437. return this.panner.distanceModel;
  23438. },
  23439. setDistanceModel: function ( value ) {
  23440. this.panner.distanceModel = value;
  23441. },
  23442. getMaxDistance: function () {
  23443. return this.panner.maxDistance;
  23444. },
  23445. setMaxDistance: function ( value ) {
  23446. this.panner.maxDistance = value;
  23447. },
  23448. updateMatrixWorld: ( function () {
  23449. var position = new Vector3();
  23450. return function updateMatrixWorld( force ) {
  23451. Object3D.prototype.updateMatrixWorld.call( this, force );
  23452. position.setFromMatrixPosition( this.matrixWorld );
  23453. this.panner.setPosition( position.x, position.y, position.z );
  23454. };
  23455. } )()
  23456. } );
  23457. /**
  23458. * @author mrdoob / http://mrdoob.com/
  23459. */
  23460. function AudioAnalyser( audio, fftSize ) {
  23461. this.analyser = audio.context.createAnalyser();
  23462. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  23463. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  23464. audio.getOutput().connect( this.analyser );
  23465. }
  23466. Object.assign( AudioAnalyser.prototype, {
  23467. getFrequencyData: function () {
  23468. this.analyser.getByteFrequencyData( this.data );
  23469. return this.data;
  23470. },
  23471. getAverageFrequency: function () {
  23472. var value = 0, data = this.getFrequencyData();
  23473. for ( var i = 0; i < data.length; i ++ ) {
  23474. value += data[ i ];
  23475. }
  23476. return value / data.length;
  23477. }
  23478. } );
  23479. /**
  23480. *
  23481. * Buffered scene graph property that allows weighted accumulation.
  23482. *
  23483. *
  23484. * @author Ben Houston / http://clara.io/
  23485. * @author David Sarno / http://lighthaus.us/
  23486. * @author tschw
  23487. */
  23488. function PropertyMixer( binding, typeName, valueSize ) {
  23489. this.binding = binding;
  23490. this.valueSize = valueSize;
  23491. var bufferType = Float64Array,
  23492. mixFunction;
  23493. switch ( typeName ) {
  23494. case 'quaternion':
  23495. mixFunction = this._slerp;
  23496. break;
  23497. case 'string':
  23498. case 'bool':
  23499. bufferType = Array;
  23500. mixFunction = this._select;
  23501. break;
  23502. default:
  23503. mixFunction = this._lerp;
  23504. }
  23505. this.buffer = new bufferType( valueSize * 4 );
  23506. // layout: [ incoming | accu0 | accu1 | orig ]
  23507. //
  23508. // interpolators can use .buffer as their .result
  23509. // the data then goes to 'incoming'
  23510. //
  23511. // 'accu0' and 'accu1' are used frame-interleaved for
  23512. // the cumulative result and are compared to detect
  23513. // changes
  23514. //
  23515. // 'orig' stores the original state of the property
  23516. this._mixBufferRegion = mixFunction;
  23517. this.cumulativeWeight = 0;
  23518. this.useCount = 0;
  23519. this.referenceCount = 0;
  23520. }
  23521. Object.assign( PropertyMixer.prototype, {
  23522. // accumulate data in the 'incoming' region into 'accu<i>'
  23523. accumulate: function ( accuIndex, weight ) {
  23524. // note: happily accumulating nothing when weight = 0, the caller knows
  23525. // the weight and shouldn't have made the call in the first place
  23526. var buffer = this.buffer,
  23527. stride = this.valueSize,
  23528. offset = accuIndex * stride + stride,
  23529. currentWeight = this.cumulativeWeight;
  23530. if ( currentWeight === 0 ) {
  23531. // accuN := incoming * weight
  23532. for ( var i = 0; i !== stride; ++ i ) {
  23533. buffer[ offset + i ] = buffer[ i ];
  23534. }
  23535. currentWeight = weight;
  23536. } else {
  23537. // accuN := accuN + incoming * weight
  23538. currentWeight += weight;
  23539. var mix = weight / currentWeight;
  23540. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  23541. }
  23542. this.cumulativeWeight = currentWeight;
  23543. },
  23544. // apply the state of 'accu<i>' to the binding when accus differ
  23545. apply: function ( accuIndex ) {
  23546. var stride = this.valueSize,
  23547. buffer = this.buffer,
  23548. offset = accuIndex * stride + stride,
  23549. weight = this.cumulativeWeight,
  23550. binding = this.binding;
  23551. this.cumulativeWeight = 0;
  23552. if ( weight < 1 ) {
  23553. // accuN := accuN + original * ( 1 - cumulativeWeight )
  23554. var originalValueOffset = stride * 3;
  23555. this._mixBufferRegion(
  23556. buffer, offset, originalValueOffset, 1 - weight, stride );
  23557. }
  23558. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  23559. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  23560. // value has changed -> update scene graph
  23561. binding.setValue( buffer, offset );
  23562. break;
  23563. }
  23564. }
  23565. },
  23566. // remember the state of the bound property and copy it to both accus
  23567. saveOriginalState: function () {
  23568. var binding = this.binding;
  23569. var buffer = this.buffer,
  23570. stride = this.valueSize,
  23571. originalValueOffset = stride * 3;
  23572. binding.getValue( buffer, originalValueOffset );
  23573. // accu[0..1] := orig -- initially detect changes against the original
  23574. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  23575. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  23576. }
  23577. this.cumulativeWeight = 0;
  23578. },
  23579. // apply the state previously taken via 'saveOriginalState' to the binding
  23580. restoreOriginalState: function () {
  23581. var originalValueOffset = this.valueSize * 3;
  23582. this.binding.setValue( this.buffer, originalValueOffset );
  23583. },
  23584. // mix functions
  23585. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23586. if ( t >= 0.5 ) {
  23587. for ( var i = 0; i !== stride; ++ i ) {
  23588. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  23589. }
  23590. }
  23591. },
  23592. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  23593. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  23594. },
  23595. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23596. var s = 1 - t;
  23597. for ( var i = 0; i !== stride; ++ i ) {
  23598. var j = dstOffset + i;
  23599. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  23600. }
  23601. }
  23602. } );
  23603. /**
  23604. *
  23605. * A reference to a real property in the scene graph.
  23606. *
  23607. *
  23608. * @author Ben Houston / http://clara.io/
  23609. * @author David Sarno / http://lighthaus.us/
  23610. * @author tschw
  23611. */
  23612. // Characters [].:/ are reserved for track binding syntax.
  23613. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  23614. function Composite( targetGroup, path, optionalParsedPath ) {
  23615. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  23616. this._targetGroup = targetGroup;
  23617. this._bindings = targetGroup.subscribe_( path, parsedPath );
  23618. }
  23619. Object.assign( Composite.prototype, {
  23620. getValue: function ( array, offset ) {
  23621. this.bind(); // bind all binding
  23622. var firstValidIndex = this._targetGroup.nCachedObjects_,
  23623. binding = this._bindings[ firstValidIndex ];
  23624. // and only call .getValue on the first
  23625. if ( binding !== undefined ) binding.getValue( array, offset );
  23626. },
  23627. setValue: function ( array, offset ) {
  23628. var bindings = this._bindings;
  23629. for ( var i = this._targetGroup.nCachedObjects_,
  23630. n = bindings.length; i !== n; ++ i ) {
  23631. bindings[ i ].setValue( array, offset );
  23632. }
  23633. },
  23634. bind: function () {
  23635. var bindings = this._bindings;
  23636. for ( var i = this._targetGroup.nCachedObjects_,
  23637. n = bindings.length; i !== n; ++ i ) {
  23638. bindings[ i ].bind();
  23639. }
  23640. },
  23641. unbind: function () {
  23642. var bindings = this._bindings;
  23643. for ( var i = this._targetGroup.nCachedObjects_,
  23644. n = bindings.length; i !== n; ++ i ) {
  23645. bindings[ i ].unbind();
  23646. }
  23647. }
  23648. } );
  23649. function PropertyBinding( rootNode, path, parsedPath ) {
  23650. this.path = path;
  23651. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  23652. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  23653. this.rootNode = rootNode;
  23654. }
  23655. Object.assign( PropertyBinding, {
  23656. Composite: Composite,
  23657. create: function ( root, path, parsedPath ) {
  23658. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  23659. return new PropertyBinding( root, path, parsedPath );
  23660. } else {
  23661. return new PropertyBinding.Composite( root, path, parsedPath );
  23662. }
  23663. },
  23664. /**
  23665. * Replaces spaces with underscores and removes unsupported characters from
  23666. * node names, to ensure compatibility with parseTrackName().
  23667. *
  23668. * @param {string} name Node name to be sanitized.
  23669. * @return {string}
  23670. */
  23671. sanitizeNodeName: ( function () {
  23672. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  23673. return function sanitizeNodeName( name ) {
  23674. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  23675. };
  23676. }() ),
  23677. parseTrackName: function () {
  23678. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  23679. // only latin characters, and the unicode \p{L} is not yet supported. So
  23680. // instead, we exclude reserved characters and match everything else.
  23681. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  23682. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  23683. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  23684. // be matched to parse the rest of the track name.
  23685. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  23686. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  23687. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  23688. // Object on target node, and accessor. May not contain reserved
  23689. // characters. Accessor may contain any character except closing bracket.
  23690. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  23691. // Property and accessor. May not contain reserved characters. Accessor may
  23692. // contain any non-bracket characters.
  23693. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  23694. var trackRe = new RegExp( ''
  23695. + '^'
  23696. + directoryRe
  23697. + nodeRe
  23698. + objectRe
  23699. + propertyRe
  23700. + '$'
  23701. );
  23702. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  23703. return function parseTrackName( trackName ) {
  23704. var matches = trackRe.exec( trackName );
  23705. if ( ! matches ) {
  23706. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  23707. }
  23708. var results = {
  23709. // directoryName: matches[ 1 ], // (tschw) currently unused
  23710. nodeName: matches[ 2 ],
  23711. objectName: matches[ 3 ],
  23712. objectIndex: matches[ 4 ],
  23713. propertyName: matches[ 5 ], // required
  23714. propertyIndex: matches[ 6 ]
  23715. };
  23716. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  23717. if ( lastDot !== undefined && lastDot !== - 1 ) {
  23718. var objectName = results.nodeName.substring( lastDot + 1 );
  23719. // Object names must be checked against a whitelist. Otherwise, there
  23720. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  23721. // 'bar' could be the objectName, or part of a nodeName (which can
  23722. // include '.' characters).
  23723. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  23724. results.nodeName = results.nodeName.substring( 0, lastDot );
  23725. results.objectName = objectName;
  23726. }
  23727. }
  23728. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  23729. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  23730. }
  23731. return results;
  23732. };
  23733. }(),
  23734. findNode: function ( root, nodeName ) {
  23735. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  23736. return root;
  23737. }
  23738. // search into skeleton bones.
  23739. if ( root.skeleton ) {
  23740. var bone = root.skeleton.getBoneByName( nodeName );
  23741. if ( bone !== undefined ) {
  23742. return bone;
  23743. }
  23744. }
  23745. // search into node subtree.
  23746. if ( root.children ) {
  23747. var searchNodeSubtree = function ( children ) {
  23748. for ( var i = 0; i < children.length; i ++ ) {
  23749. var childNode = children[ i ];
  23750. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  23751. return childNode;
  23752. }
  23753. var result = searchNodeSubtree( childNode.children );
  23754. if ( result ) return result;
  23755. }
  23756. return null;
  23757. };
  23758. var subTreeNode = searchNodeSubtree( root.children );
  23759. if ( subTreeNode ) {
  23760. return subTreeNode;
  23761. }
  23762. }
  23763. return null;
  23764. }
  23765. } );
  23766. Object.assign( PropertyBinding.prototype, { // prototype, continued
  23767. // these are used to "bind" a nonexistent property
  23768. _getValue_unavailable: function () {},
  23769. _setValue_unavailable: function () {},
  23770. BindingType: {
  23771. Direct: 0,
  23772. EntireArray: 1,
  23773. ArrayElement: 2,
  23774. HasFromToArray: 3
  23775. },
  23776. Versioning: {
  23777. None: 0,
  23778. NeedsUpdate: 1,
  23779. MatrixWorldNeedsUpdate: 2
  23780. },
  23781. GetterByBindingType: [
  23782. function getValue_direct( buffer, offset ) {
  23783. buffer[ offset ] = this.node[ this.propertyName ];
  23784. },
  23785. function getValue_array( buffer, offset ) {
  23786. var source = this.resolvedProperty;
  23787. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  23788. buffer[ offset ++ ] = source[ i ];
  23789. }
  23790. },
  23791. function getValue_arrayElement( buffer, offset ) {
  23792. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  23793. },
  23794. function getValue_toArray( buffer, offset ) {
  23795. this.resolvedProperty.toArray( buffer, offset );
  23796. }
  23797. ],
  23798. SetterByBindingTypeAndVersioning: [
  23799. [
  23800. // Direct
  23801. function setValue_direct( buffer, offset ) {
  23802. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23803. },
  23804. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  23805. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23806. this.targetObject.needsUpdate = true;
  23807. },
  23808. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23809. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23810. this.targetObject.matrixWorldNeedsUpdate = true;
  23811. }
  23812. ], [
  23813. // EntireArray
  23814. function setValue_array( buffer, offset ) {
  23815. var dest = this.resolvedProperty;
  23816. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23817. dest[ i ] = buffer[ offset ++ ];
  23818. }
  23819. },
  23820. function setValue_array_setNeedsUpdate( buffer, offset ) {
  23821. var dest = this.resolvedProperty;
  23822. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23823. dest[ i ] = buffer[ offset ++ ];
  23824. }
  23825. this.targetObject.needsUpdate = true;
  23826. },
  23827. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23828. var dest = this.resolvedProperty;
  23829. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23830. dest[ i ] = buffer[ offset ++ ];
  23831. }
  23832. this.targetObject.matrixWorldNeedsUpdate = true;
  23833. }
  23834. ], [
  23835. // ArrayElement
  23836. function setValue_arrayElement( buffer, offset ) {
  23837. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23838. },
  23839. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  23840. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23841. this.targetObject.needsUpdate = true;
  23842. },
  23843. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23844. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23845. this.targetObject.matrixWorldNeedsUpdate = true;
  23846. }
  23847. ], [
  23848. // HasToFromArray
  23849. function setValue_fromArray( buffer, offset ) {
  23850. this.resolvedProperty.fromArray( buffer, offset );
  23851. },
  23852. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  23853. this.resolvedProperty.fromArray( buffer, offset );
  23854. this.targetObject.needsUpdate = true;
  23855. },
  23856. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23857. this.resolvedProperty.fromArray( buffer, offset );
  23858. this.targetObject.matrixWorldNeedsUpdate = true;
  23859. }
  23860. ]
  23861. ],
  23862. getValue: function getValue_unbound( targetArray, offset ) {
  23863. this.bind();
  23864. this.getValue( targetArray, offset );
  23865. // Note: This class uses a State pattern on a per-method basis:
  23866. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  23867. // prototype version of these methods with one that represents
  23868. // the bound state. When the property is not found, the methods
  23869. // become no-ops.
  23870. },
  23871. setValue: function getValue_unbound( sourceArray, offset ) {
  23872. this.bind();
  23873. this.setValue( sourceArray, offset );
  23874. },
  23875. // create getter / setter pair for a property in the scene graph
  23876. bind: function () {
  23877. var targetObject = this.node,
  23878. parsedPath = this.parsedPath,
  23879. objectName = parsedPath.objectName,
  23880. propertyName = parsedPath.propertyName,
  23881. propertyIndex = parsedPath.propertyIndex;
  23882. if ( ! targetObject ) {
  23883. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  23884. this.node = targetObject;
  23885. }
  23886. // set fail state so we can just 'return' on error
  23887. this.getValue = this._getValue_unavailable;
  23888. this.setValue = this._setValue_unavailable;
  23889. // ensure there is a value node
  23890. if ( ! targetObject ) {
  23891. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  23892. return;
  23893. }
  23894. if ( objectName ) {
  23895. var objectIndex = parsedPath.objectIndex;
  23896. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  23897. switch ( objectName ) {
  23898. case 'materials':
  23899. if ( ! targetObject.material ) {
  23900. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  23901. return;
  23902. }
  23903. if ( ! targetObject.material.materials ) {
  23904. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  23905. return;
  23906. }
  23907. targetObject = targetObject.material.materials;
  23908. break;
  23909. case 'bones':
  23910. if ( ! targetObject.skeleton ) {
  23911. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  23912. return;
  23913. }
  23914. // potential future optimization: skip this if propertyIndex is already an integer
  23915. // and convert the integer string to a true integer.
  23916. targetObject = targetObject.skeleton.bones;
  23917. // support resolving morphTarget names into indices.
  23918. for ( var i = 0; i < targetObject.length; i ++ ) {
  23919. if ( targetObject[ i ].name === objectIndex ) {
  23920. objectIndex = i;
  23921. break;
  23922. }
  23923. }
  23924. break;
  23925. default:
  23926. if ( targetObject[ objectName ] === undefined ) {
  23927. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  23928. return;
  23929. }
  23930. targetObject = targetObject[ objectName ];
  23931. }
  23932. if ( objectIndex !== undefined ) {
  23933. if ( targetObject[ objectIndex ] === undefined ) {
  23934. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  23935. return;
  23936. }
  23937. targetObject = targetObject[ objectIndex ];
  23938. }
  23939. }
  23940. // resolve property
  23941. var nodeProperty = targetObject[ propertyName ];
  23942. if ( nodeProperty === undefined ) {
  23943. var nodeName = parsedPath.nodeName;
  23944. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  23945. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  23946. return;
  23947. }
  23948. // determine versioning scheme
  23949. var versioning = this.Versioning.None;
  23950. if ( targetObject.needsUpdate !== undefined ) { // material
  23951. versioning = this.Versioning.NeedsUpdate;
  23952. this.targetObject = targetObject;
  23953. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  23954. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  23955. this.targetObject = targetObject;
  23956. }
  23957. // determine how the property gets bound
  23958. var bindingType = this.BindingType.Direct;
  23959. if ( propertyIndex !== undefined ) {
  23960. // access a sub element of the property array (only primitives are supported right now)
  23961. if ( propertyName === "morphTargetInfluences" ) {
  23962. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  23963. // support resolving morphTarget names into indices.
  23964. if ( ! targetObject.geometry ) {
  23965. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  23966. return;
  23967. }
  23968. if ( targetObject.geometry.isBufferGeometry ) {
  23969. if ( ! targetObject.geometry.morphAttributes ) {
  23970. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  23971. return;
  23972. }
  23973. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  23974. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  23975. propertyIndex = i;
  23976. break;
  23977. }
  23978. }
  23979. } else {
  23980. if ( ! targetObject.geometry.morphTargets ) {
  23981. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  23982. return;
  23983. }
  23984. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  23985. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  23986. propertyIndex = i;
  23987. break;
  23988. }
  23989. }
  23990. }
  23991. }
  23992. bindingType = this.BindingType.ArrayElement;
  23993. this.resolvedProperty = nodeProperty;
  23994. this.propertyIndex = propertyIndex;
  23995. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  23996. // must use copy for Object3D.Euler/Quaternion
  23997. bindingType = this.BindingType.HasFromToArray;
  23998. this.resolvedProperty = nodeProperty;
  23999. } else if ( Array.isArray( nodeProperty ) ) {
  24000. bindingType = this.BindingType.EntireArray;
  24001. this.resolvedProperty = nodeProperty;
  24002. } else {
  24003. this.propertyName = propertyName;
  24004. }
  24005. // select getter / setter
  24006. this.getValue = this.GetterByBindingType[ bindingType ];
  24007. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  24008. },
  24009. unbind: function () {
  24010. this.node = null;
  24011. // back to the prototype version of getValue / setValue
  24012. // note: avoiding to mutate the shape of 'this' via 'delete'
  24013. this.getValue = this._getValue_unbound;
  24014. this.setValue = this._setValue_unbound;
  24015. }
  24016. } );
  24017. //!\ DECLARE ALIAS AFTER assign prototype !
  24018. Object.assign( PropertyBinding.prototype, {
  24019. // initial state of these methods that calls 'bind'
  24020. _getValue_unbound: PropertyBinding.prototype.getValue,
  24021. _setValue_unbound: PropertyBinding.prototype.setValue,
  24022. } );
  24023. /**
  24024. *
  24025. * A group of objects that receives a shared animation state.
  24026. *
  24027. * Usage:
  24028. *
  24029. * - Add objects you would otherwise pass as 'root' to the
  24030. * constructor or the .clipAction method of AnimationMixer.
  24031. *
  24032. * - Instead pass this object as 'root'.
  24033. *
  24034. * - You can also add and remove objects later when the mixer
  24035. * is running.
  24036. *
  24037. * Note:
  24038. *
  24039. * Objects of this class appear as one object to the mixer,
  24040. * so cache control of the individual objects must be done
  24041. * on the group.
  24042. *
  24043. * Limitation:
  24044. *
  24045. * - The animated properties must be compatible among the
  24046. * all objects in the group.
  24047. *
  24048. * - A single property can either be controlled through a
  24049. * target group or directly, but not both.
  24050. *
  24051. * @author tschw
  24052. */
  24053. function AnimationObjectGroup() {
  24054. this.uuid = _Math.generateUUID();
  24055. // cached objects followed by the active ones
  24056. this._objects = Array.prototype.slice.call( arguments );
  24057. this.nCachedObjects_ = 0; // threshold
  24058. // note: read by PropertyBinding.Composite
  24059. var indices = {};
  24060. this._indicesByUUID = indices; // for bookkeeping
  24061. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24062. indices[ arguments[ i ].uuid ] = i;
  24063. }
  24064. this._paths = []; // inside: string
  24065. this._parsedPaths = []; // inside: { we don't care, here }
  24066. this._bindings = []; // inside: Array< PropertyBinding >
  24067. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  24068. var scope = this;
  24069. this.stats = {
  24070. objects: {
  24071. get total() {
  24072. return scope._objects.length;
  24073. },
  24074. get inUse() {
  24075. return this.total - scope.nCachedObjects_;
  24076. }
  24077. },
  24078. get bindingsPerObject() {
  24079. return scope._bindings.length;
  24080. }
  24081. };
  24082. }
  24083. Object.assign( AnimationObjectGroup.prototype, {
  24084. isAnimationObjectGroup: true,
  24085. add: function () {
  24086. var objects = this._objects,
  24087. nObjects = objects.length,
  24088. nCachedObjects = this.nCachedObjects_,
  24089. indicesByUUID = this._indicesByUUID,
  24090. paths = this._paths,
  24091. parsedPaths = this._parsedPaths,
  24092. bindings = this._bindings,
  24093. nBindings = bindings.length,
  24094. knownObject = undefined;
  24095. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24096. var object = arguments[ i ],
  24097. uuid = object.uuid,
  24098. index = indicesByUUID[ uuid ];
  24099. if ( index === undefined ) {
  24100. // unknown object -> add it to the ACTIVE region
  24101. index = nObjects ++;
  24102. indicesByUUID[ uuid ] = index;
  24103. objects.push( object );
  24104. // accounting is done, now do the same for all bindings
  24105. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24106. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  24107. }
  24108. } else if ( index < nCachedObjects ) {
  24109. knownObject = objects[ index ];
  24110. // move existing object to the ACTIVE region
  24111. var firstActiveIndex = -- nCachedObjects,
  24112. lastCachedObject = objects[ firstActiveIndex ];
  24113. indicesByUUID[ lastCachedObject.uuid ] = index;
  24114. objects[ index ] = lastCachedObject;
  24115. indicesByUUID[ uuid ] = firstActiveIndex;
  24116. objects[ firstActiveIndex ] = object;
  24117. // accounting is done, now do the same for all bindings
  24118. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24119. var bindingsForPath = bindings[ j ],
  24120. lastCached = bindingsForPath[ firstActiveIndex ],
  24121. binding = bindingsForPath[ index ];
  24122. bindingsForPath[ index ] = lastCached;
  24123. if ( binding === undefined ) {
  24124. // since we do not bother to create new bindings
  24125. // for objects that are cached, the binding may
  24126. // or may not exist
  24127. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  24128. }
  24129. bindingsForPath[ firstActiveIndex ] = binding;
  24130. }
  24131. } else if ( objects[ index ] !== knownObject ) {
  24132. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  24133. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  24134. } // else the object is already where we want it to be
  24135. } // for arguments
  24136. this.nCachedObjects_ = nCachedObjects;
  24137. },
  24138. remove: function () {
  24139. var objects = this._objects,
  24140. nCachedObjects = this.nCachedObjects_,
  24141. indicesByUUID = this._indicesByUUID,
  24142. bindings = this._bindings,
  24143. nBindings = bindings.length;
  24144. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24145. var object = arguments[ i ],
  24146. uuid = object.uuid,
  24147. index = indicesByUUID[ uuid ];
  24148. if ( index !== undefined && index >= nCachedObjects ) {
  24149. // move existing object into the CACHED region
  24150. var lastCachedIndex = nCachedObjects ++,
  24151. firstActiveObject = objects[ lastCachedIndex ];
  24152. indicesByUUID[ firstActiveObject.uuid ] = index;
  24153. objects[ index ] = firstActiveObject;
  24154. indicesByUUID[ uuid ] = lastCachedIndex;
  24155. objects[ lastCachedIndex ] = object;
  24156. // accounting is done, now do the same for all bindings
  24157. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24158. var bindingsForPath = bindings[ j ],
  24159. firstActive = bindingsForPath[ lastCachedIndex ],
  24160. binding = bindingsForPath[ index ];
  24161. bindingsForPath[ index ] = firstActive;
  24162. bindingsForPath[ lastCachedIndex ] = binding;
  24163. }
  24164. }
  24165. } // for arguments
  24166. this.nCachedObjects_ = nCachedObjects;
  24167. },
  24168. // remove & forget
  24169. uncache: function () {
  24170. var objects = this._objects,
  24171. nObjects = objects.length,
  24172. nCachedObjects = this.nCachedObjects_,
  24173. indicesByUUID = this._indicesByUUID,
  24174. bindings = this._bindings,
  24175. nBindings = bindings.length;
  24176. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24177. var object = arguments[ i ],
  24178. uuid = object.uuid,
  24179. index = indicesByUUID[ uuid ];
  24180. if ( index !== undefined ) {
  24181. delete indicesByUUID[ uuid ];
  24182. if ( index < nCachedObjects ) {
  24183. // object is cached, shrink the CACHED region
  24184. var firstActiveIndex = -- nCachedObjects,
  24185. lastCachedObject = objects[ firstActiveIndex ],
  24186. lastIndex = -- nObjects,
  24187. lastObject = objects[ lastIndex ];
  24188. // last cached object takes this object's place
  24189. indicesByUUID[ lastCachedObject.uuid ] = index;
  24190. objects[ index ] = lastCachedObject;
  24191. // last object goes to the activated slot and pop
  24192. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  24193. objects[ firstActiveIndex ] = lastObject;
  24194. objects.pop();
  24195. // accounting is done, now do the same for all bindings
  24196. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24197. var bindingsForPath = bindings[ j ],
  24198. lastCached = bindingsForPath[ firstActiveIndex ],
  24199. last = bindingsForPath[ lastIndex ];
  24200. bindingsForPath[ index ] = lastCached;
  24201. bindingsForPath[ firstActiveIndex ] = last;
  24202. bindingsForPath.pop();
  24203. }
  24204. } else {
  24205. // object is active, just swap with the last and pop
  24206. var lastIndex = -- nObjects,
  24207. lastObject = objects[ lastIndex ];
  24208. indicesByUUID[ lastObject.uuid ] = index;
  24209. objects[ index ] = lastObject;
  24210. objects.pop();
  24211. // accounting is done, now do the same for all bindings
  24212. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24213. var bindingsForPath = bindings[ j ];
  24214. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  24215. bindingsForPath.pop();
  24216. }
  24217. } // cached or active
  24218. } // if object is known
  24219. } // for arguments
  24220. this.nCachedObjects_ = nCachedObjects;
  24221. },
  24222. // Internal interface used by befriended PropertyBinding.Composite:
  24223. subscribe_: function ( path, parsedPath ) {
  24224. // returns an array of bindings for the given path that is changed
  24225. // according to the contained objects in the group
  24226. var indicesByPath = this._bindingsIndicesByPath,
  24227. index = indicesByPath[ path ],
  24228. bindings = this._bindings;
  24229. if ( index !== undefined ) return bindings[ index ];
  24230. var paths = this._paths,
  24231. parsedPaths = this._parsedPaths,
  24232. objects = this._objects,
  24233. nObjects = objects.length,
  24234. nCachedObjects = this.nCachedObjects_,
  24235. bindingsForPath = new Array( nObjects );
  24236. index = bindings.length;
  24237. indicesByPath[ path ] = index;
  24238. paths.push( path );
  24239. parsedPaths.push( parsedPath );
  24240. bindings.push( bindingsForPath );
  24241. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  24242. var object = objects[ i ];
  24243. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  24244. }
  24245. return bindingsForPath;
  24246. },
  24247. unsubscribe_: function ( path ) {
  24248. // tells the group to forget about a property path and no longer
  24249. // update the array previously obtained with 'subscribe_'
  24250. var indicesByPath = this._bindingsIndicesByPath,
  24251. index = indicesByPath[ path ];
  24252. if ( index !== undefined ) {
  24253. var paths = this._paths,
  24254. parsedPaths = this._parsedPaths,
  24255. bindings = this._bindings,
  24256. lastBindingsIndex = bindings.length - 1,
  24257. lastBindings = bindings[ lastBindingsIndex ],
  24258. lastBindingsPath = path[ lastBindingsIndex ];
  24259. indicesByPath[ lastBindingsPath ] = index;
  24260. bindings[ index ] = lastBindings;
  24261. bindings.pop();
  24262. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  24263. parsedPaths.pop();
  24264. paths[ index ] = paths[ lastBindingsIndex ];
  24265. paths.pop();
  24266. }
  24267. }
  24268. } );
  24269. /**
  24270. *
  24271. * Action provided by AnimationMixer for scheduling clip playback on specific
  24272. * objects.
  24273. *
  24274. * @author Ben Houston / http://clara.io/
  24275. * @author David Sarno / http://lighthaus.us/
  24276. * @author tschw
  24277. *
  24278. */
  24279. function AnimationAction( mixer, clip, localRoot ) {
  24280. this._mixer = mixer;
  24281. this._clip = clip;
  24282. this._localRoot = localRoot || null;
  24283. var tracks = clip.tracks,
  24284. nTracks = tracks.length,
  24285. interpolants = new Array( nTracks );
  24286. var interpolantSettings = {
  24287. endingStart: ZeroCurvatureEnding,
  24288. endingEnd: ZeroCurvatureEnding
  24289. };
  24290. for ( var i = 0; i !== nTracks; ++ i ) {
  24291. var interpolant = tracks[ i ].createInterpolant( null );
  24292. interpolants[ i ] = interpolant;
  24293. interpolant.settings = interpolantSettings;
  24294. }
  24295. this._interpolantSettings = interpolantSettings;
  24296. this._interpolants = interpolants; // bound by the mixer
  24297. // inside: PropertyMixer (managed by the mixer)
  24298. this._propertyBindings = new Array( nTracks );
  24299. this._cacheIndex = null; // for the memory manager
  24300. this._byClipCacheIndex = null; // for the memory manager
  24301. this._timeScaleInterpolant = null;
  24302. this._weightInterpolant = null;
  24303. this.loop = LoopRepeat;
  24304. this._loopCount = - 1;
  24305. // global mixer time when the action is to be started
  24306. // it's set back to 'null' upon start of the action
  24307. this._startTime = null;
  24308. // scaled local time of the action
  24309. // gets clamped or wrapped to 0..clip.duration according to loop
  24310. this.time = 0;
  24311. this.timeScale = 1;
  24312. this._effectiveTimeScale = 1;
  24313. this.weight = 1;
  24314. this._effectiveWeight = 1;
  24315. this.repetitions = Infinity; // no. of repetitions when looping
  24316. this.paused = false; // true -> zero effective time scale
  24317. this.enabled = true; // false -> zero effective weight
  24318. this.clampWhenFinished = false; // keep feeding the last frame?
  24319. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  24320. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  24321. }
  24322. Object.assign( AnimationAction.prototype, {
  24323. // State & Scheduling
  24324. play: function () {
  24325. this._mixer._activateAction( this );
  24326. return this;
  24327. },
  24328. stop: function () {
  24329. this._mixer._deactivateAction( this );
  24330. return this.reset();
  24331. },
  24332. reset: function () {
  24333. this.paused = false;
  24334. this.enabled = true;
  24335. this.time = 0; // restart clip
  24336. this._loopCount = - 1; // forget previous loops
  24337. this._startTime = null; // forget scheduling
  24338. return this.stopFading().stopWarping();
  24339. },
  24340. isRunning: function () {
  24341. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  24342. this._startTime === null && this._mixer._isActiveAction( this );
  24343. },
  24344. // return true when play has been called
  24345. isScheduled: function () {
  24346. return this._mixer._isActiveAction( this );
  24347. },
  24348. startAt: function ( time ) {
  24349. this._startTime = time;
  24350. return this;
  24351. },
  24352. setLoop: function ( mode, repetitions ) {
  24353. this.loop = mode;
  24354. this.repetitions = repetitions;
  24355. return this;
  24356. },
  24357. // Weight
  24358. // set the weight stopping any scheduled fading
  24359. // although .enabled = false yields an effective weight of zero, this
  24360. // method does *not* change .enabled, because it would be confusing
  24361. setEffectiveWeight: function ( weight ) {
  24362. this.weight = weight;
  24363. // note: same logic as when updated at runtime
  24364. this._effectiveWeight = this.enabled ? weight : 0;
  24365. return this.stopFading();
  24366. },
  24367. // return the weight considering fading and .enabled
  24368. getEffectiveWeight: function () {
  24369. return this._effectiveWeight;
  24370. },
  24371. fadeIn: function ( duration ) {
  24372. return this._scheduleFading( duration, 0, 1 );
  24373. },
  24374. fadeOut: function ( duration ) {
  24375. return this._scheduleFading( duration, 1, 0 );
  24376. },
  24377. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  24378. fadeOutAction.fadeOut( duration );
  24379. this.fadeIn( duration );
  24380. if ( warp ) {
  24381. var fadeInDuration = this._clip.duration,
  24382. fadeOutDuration = fadeOutAction._clip.duration,
  24383. startEndRatio = fadeOutDuration / fadeInDuration,
  24384. endStartRatio = fadeInDuration / fadeOutDuration;
  24385. fadeOutAction.warp( 1.0, startEndRatio, duration );
  24386. this.warp( endStartRatio, 1.0, duration );
  24387. }
  24388. return this;
  24389. },
  24390. crossFadeTo: function ( fadeInAction, duration, warp ) {
  24391. return fadeInAction.crossFadeFrom( this, duration, warp );
  24392. },
  24393. stopFading: function () {
  24394. var weightInterpolant = this._weightInterpolant;
  24395. if ( weightInterpolant !== null ) {
  24396. this._weightInterpolant = null;
  24397. this._mixer._takeBackControlInterpolant( weightInterpolant );
  24398. }
  24399. return this;
  24400. },
  24401. // Time Scale Control
  24402. // set the time scale stopping any scheduled warping
  24403. // although .paused = true yields an effective time scale of zero, this
  24404. // method does *not* change .paused, because it would be confusing
  24405. setEffectiveTimeScale: function ( timeScale ) {
  24406. this.timeScale = timeScale;
  24407. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  24408. return this.stopWarping();
  24409. },
  24410. // return the time scale considering warping and .paused
  24411. getEffectiveTimeScale: function () {
  24412. return this._effectiveTimeScale;
  24413. },
  24414. setDuration: function ( duration ) {
  24415. this.timeScale = this._clip.duration / duration;
  24416. return this.stopWarping();
  24417. },
  24418. syncWith: function ( action ) {
  24419. this.time = action.time;
  24420. this.timeScale = action.timeScale;
  24421. return this.stopWarping();
  24422. },
  24423. halt: function ( duration ) {
  24424. return this.warp( this._effectiveTimeScale, 0, duration );
  24425. },
  24426. warp: function ( startTimeScale, endTimeScale, duration ) {
  24427. var mixer = this._mixer, now = mixer.time,
  24428. interpolant = this._timeScaleInterpolant,
  24429. timeScale = this.timeScale;
  24430. if ( interpolant === null ) {
  24431. interpolant = mixer._lendControlInterpolant();
  24432. this._timeScaleInterpolant = interpolant;
  24433. }
  24434. var times = interpolant.parameterPositions,
  24435. values = interpolant.sampleValues;
  24436. times[ 0 ] = now;
  24437. times[ 1 ] = now + duration;
  24438. values[ 0 ] = startTimeScale / timeScale;
  24439. values[ 1 ] = endTimeScale / timeScale;
  24440. return this;
  24441. },
  24442. stopWarping: function () {
  24443. var timeScaleInterpolant = this._timeScaleInterpolant;
  24444. if ( timeScaleInterpolant !== null ) {
  24445. this._timeScaleInterpolant = null;
  24446. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  24447. }
  24448. return this;
  24449. },
  24450. // Object Accessors
  24451. getMixer: function () {
  24452. return this._mixer;
  24453. },
  24454. getClip: function () {
  24455. return this._clip;
  24456. },
  24457. getRoot: function () {
  24458. return this._localRoot || this._mixer._root;
  24459. },
  24460. // Interna
  24461. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  24462. // called by the mixer
  24463. if ( ! this.enabled ) {
  24464. // call ._updateWeight() to update ._effectiveWeight
  24465. this._updateWeight( time );
  24466. return;
  24467. }
  24468. var startTime = this._startTime;
  24469. if ( startTime !== null ) {
  24470. // check for scheduled start of action
  24471. var timeRunning = ( time - startTime ) * timeDirection;
  24472. if ( timeRunning < 0 || timeDirection === 0 ) {
  24473. return; // yet to come / don't decide when delta = 0
  24474. }
  24475. // start
  24476. this._startTime = null; // unschedule
  24477. deltaTime = timeDirection * timeRunning;
  24478. }
  24479. // apply time scale and advance time
  24480. deltaTime *= this._updateTimeScale( time );
  24481. var clipTime = this._updateTime( deltaTime );
  24482. // note: _updateTime may disable the action resulting in
  24483. // an effective weight of 0
  24484. var weight = this._updateWeight( time );
  24485. if ( weight > 0 ) {
  24486. var interpolants = this._interpolants;
  24487. var propertyMixers = this._propertyBindings;
  24488. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  24489. interpolants[ j ].evaluate( clipTime );
  24490. propertyMixers[ j ].accumulate( accuIndex, weight );
  24491. }
  24492. }
  24493. },
  24494. _updateWeight: function ( time ) {
  24495. var weight = 0;
  24496. if ( this.enabled ) {
  24497. weight = this.weight;
  24498. var interpolant = this._weightInterpolant;
  24499. if ( interpolant !== null ) {
  24500. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24501. weight *= interpolantValue;
  24502. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24503. this.stopFading();
  24504. if ( interpolantValue === 0 ) {
  24505. // faded out, disable
  24506. this.enabled = false;
  24507. }
  24508. }
  24509. }
  24510. }
  24511. this._effectiveWeight = weight;
  24512. return weight;
  24513. },
  24514. _updateTimeScale: function ( time ) {
  24515. var timeScale = 0;
  24516. if ( ! this.paused ) {
  24517. timeScale = this.timeScale;
  24518. var interpolant = this._timeScaleInterpolant;
  24519. if ( interpolant !== null ) {
  24520. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24521. timeScale *= interpolantValue;
  24522. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24523. this.stopWarping();
  24524. if ( timeScale === 0 ) {
  24525. // motion has halted, pause
  24526. this.paused = true;
  24527. } else {
  24528. // warp done - apply final time scale
  24529. this.timeScale = timeScale;
  24530. }
  24531. }
  24532. }
  24533. }
  24534. this._effectiveTimeScale = timeScale;
  24535. return timeScale;
  24536. },
  24537. _updateTime: function ( deltaTime ) {
  24538. var time = this.time + deltaTime;
  24539. if ( deltaTime === 0 ) return time;
  24540. var duration = this._clip.duration,
  24541. loop = this.loop,
  24542. loopCount = this._loopCount;
  24543. if ( loop === LoopOnce ) {
  24544. if ( loopCount === - 1 ) {
  24545. // just started
  24546. this._loopCount = 0;
  24547. this._setEndings( true, true, false );
  24548. }
  24549. handle_stop: {
  24550. if ( time >= duration ) {
  24551. time = duration;
  24552. } else if ( time < 0 ) {
  24553. time = 0;
  24554. } else break handle_stop;
  24555. if ( this.clampWhenFinished ) this.paused = true;
  24556. else this.enabled = false;
  24557. this._mixer.dispatchEvent( {
  24558. type: 'finished', action: this,
  24559. direction: deltaTime < 0 ? - 1 : 1
  24560. } );
  24561. }
  24562. } else { // repetitive Repeat or PingPong
  24563. var pingPong = ( loop === LoopPingPong );
  24564. if ( loopCount === - 1 ) {
  24565. // just started
  24566. if ( deltaTime >= 0 ) {
  24567. loopCount = 0;
  24568. this._setEndings( true, this.repetitions === 0, pingPong );
  24569. } else {
  24570. // when looping in reverse direction, the initial
  24571. // transition through zero counts as a repetition,
  24572. // so leave loopCount at -1
  24573. this._setEndings( this.repetitions === 0, true, pingPong );
  24574. }
  24575. }
  24576. if ( time >= duration || time < 0 ) {
  24577. // wrap around
  24578. var loopDelta = Math.floor( time / duration ); // signed
  24579. time -= duration * loopDelta;
  24580. loopCount += Math.abs( loopDelta );
  24581. var pending = this.repetitions - loopCount;
  24582. if ( pending <= 0 ) {
  24583. // have to stop (switch state, clamp time, fire event)
  24584. if ( this.clampWhenFinished ) this.paused = true;
  24585. else this.enabled = false;
  24586. time = deltaTime > 0 ? duration : 0;
  24587. this._mixer.dispatchEvent( {
  24588. type: 'finished', action: this,
  24589. direction: deltaTime > 0 ? 1 : - 1
  24590. } );
  24591. } else {
  24592. // keep running
  24593. if ( pending === 1 ) {
  24594. // entering the last round
  24595. var atStart = deltaTime < 0;
  24596. this._setEndings( atStart, ! atStart, pingPong );
  24597. } else {
  24598. this._setEndings( false, false, pingPong );
  24599. }
  24600. this._loopCount = loopCount;
  24601. this._mixer.dispatchEvent( {
  24602. type: 'loop', action: this, loopDelta: loopDelta
  24603. } );
  24604. }
  24605. }
  24606. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  24607. // invert time for the "pong round"
  24608. this.time = time;
  24609. return duration - time;
  24610. }
  24611. }
  24612. this.time = time;
  24613. return time;
  24614. },
  24615. _setEndings: function ( atStart, atEnd, pingPong ) {
  24616. var settings = this._interpolantSettings;
  24617. if ( pingPong ) {
  24618. settings.endingStart = ZeroSlopeEnding;
  24619. settings.endingEnd = ZeroSlopeEnding;
  24620. } else {
  24621. // assuming for LoopOnce atStart == atEnd == true
  24622. if ( atStart ) {
  24623. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24624. } else {
  24625. settings.endingStart = WrapAroundEnding;
  24626. }
  24627. if ( atEnd ) {
  24628. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24629. } else {
  24630. settings.endingEnd = WrapAroundEnding;
  24631. }
  24632. }
  24633. },
  24634. _scheduleFading: function ( duration, weightNow, weightThen ) {
  24635. var mixer = this._mixer, now = mixer.time,
  24636. interpolant = this._weightInterpolant;
  24637. if ( interpolant === null ) {
  24638. interpolant = mixer._lendControlInterpolant();
  24639. this._weightInterpolant = interpolant;
  24640. }
  24641. var times = interpolant.parameterPositions,
  24642. values = interpolant.sampleValues;
  24643. times[ 0 ] = now; values[ 0 ] = weightNow;
  24644. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  24645. return this;
  24646. }
  24647. } );
  24648. /**
  24649. *
  24650. * Player for AnimationClips.
  24651. *
  24652. *
  24653. * @author Ben Houston / http://clara.io/
  24654. * @author David Sarno / http://lighthaus.us/
  24655. * @author tschw
  24656. */
  24657. function AnimationMixer( root ) {
  24658. this._root = root;
  24659. this._initMemoryManager();
  24660. this._accuIndex = 0;
  24661. this.time = 0;
  24662. this.timeScale = 1.0;
  24663. }
  24664. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  24665. constructor: AnimationMixer,
  24666. _bindAction: function ( action, prototypeAction ) {
  24667. var root = action._localRoot || this._root,
  24668. tracks = action._clip.tracks,
  24669. nTracks = tracks.length,
  24670. bindings = action._propertyBindings,
  24671. interpolants = action._interpolants,
  24672. rootUuid = root.uuid,
  24673. bindingsByRoot = this._bindingsByRootAndName,
  24674. bindingsByName = bindingsByRoot[ rootUuid ];
  24675. if ( bindingsByName === undefined ) {
  24676. bindingsByName = {};
  24677. bindingsByRoot[ rootUuid ] = bindingsByName;
  24678. }
  24679. for ( var i = 0; i !== nTracks; ++ i ) {
  24680. var track = tracks[ i ],
  24681. trackName = track.name,
  24682. binding = bindingsByName[ trackName ];
  24683. if ( binding !== undefined ) {
  24684. bindings[ i ] = binding;
  24685. } else {
  24686. binding = bindings[ i ];
  24687. if ( binding !== undefined ) {
  24688. // existing binding, make sure the cache knows
  24689. if ( binding._cacheIndex === null ) {
  24690. ++ binding.referenceCount;
  24691. this._addInactiveBinding( binding, rootUuid, trackName );
  24692. }
  24693. continue;
  24694. }
  24695. var path = prototypeAction && prototypeAction.
  24696. _propertyBindings[ i ].binding.parsedPath;
  24697. binding = new PropertyMixer(
  24698. PropertyBinding.create( root, trackName, path ),
  24699. track.ValueTypeName, track.getValueSize() );
  24700. ++ binding.referenceCount;
  24701. this._addInactiveBinding( binding, rootUuid, trackName );
  24702. bindings[ i ] = binding;
  24703. }
  24704. interpolants[ i ].resultBuffer = binding.buffer;
  24705. }
  24706. },
  24707. _activateAction: function ( action ) {
  24708. if ( ! this._isActiveAction( action ) ) {
  24709. if ( action._cacheIndex === null ) {
  24710. // this action has been forgotten by the cache, but the user
  24711. // appears to be still using it -> rebind
  24712. var rootUuid = ( action._localRoot || this._root ).uuid,
  24713. clipUuid = action._clip.uuid,
  24714. actionsForClip = this._actionsByClip[ clipUuid ];
  24715. this._bindAction( action,
  24716. actionsForClip && actionsForClip.knownActions[ 0 ] );
  24717. this._addInactiveAction( action, clipUuid, rootUuid );
  24718. }
  24719. var bindings = action._propertyBindings;
  24720. // increment reference counts / sort out state
  24721. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24722. var binding = bindings[ i ];
  24723. if ( binding.useCount ++ === 0 ) {
  24724. this._lendBinding( binding );
  24725. binding.saveOriginalState();
  24726. }
  24727. }
  24728. this._lendAction( action );
  24729. }
  24730. },
  24731. _deactivateAction: function ( action ) {
  24732. if ( this._isActiveAction( action ) ) {
  24733. var bindings = action._propertyBindings;
  24734. // decrement reference counts / sort out state
  24735. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24736. var binding = bindings[ i ];
  24737. if ( -- binding.useCount === 0 ) {
  24738. binding.restoreOriginalState();
  24739. this._takeBackBinding( binding );
  24740. }
  24741. }
  24742. this._takeBackAction( action );
  24743. }
  24744. },
  24745. // Memory manager
  24746. _initMemoryManager: function () {
  24747. this._actions = []; // 'nActiveActions' followed by inactive ones
  24748. this._nActiveActions = 0;
  24749. this._actionsByClip = {};
  24750. // inside:
  24751. // {
  24752. // knownActions: Array< AnimationAction > - used as prototypes
  24753. // actionByRoot: AnimationAction - lookup
  24754. // }
  24755. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  24756. this._nActiveBindings = 0;
  24757. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  24758. this._controlInterpolants = []; // same game as above
  24759. this._nActiveControlInterpolants = 0;
  24760. var scope = this;
  24761. this.stats = {
  24762. actions: {
  24763. get total() {
  24764. return scope._actions.length;
  24765. },
  24766. get inUse() {
  24767. return scope._nActiveActions;
  24768. }
  24769. },
  24770. bindings: {
  24771. get total() {
  24772. return scope._bindings.length;
  24773. },
  24774. get inUse() {
  24775. return scope._nActiveBindings;
  24776. }
  24777. },
  24778. controlInterpolants: {
  24779. get total() {
  24780. return scope._controlInterpolants.length;
  24781. },
  24782. get inUse() {
  24783. return scope._nActiveControlInterpolants;
  24784. }
  24785. }
  24786. };
  24787. },
  24788. // Memory management for AnimationAction objects
  24789. _isActiveAction: function ( action ) {
  24790. var index = action._cacheIndex;
  24791. return index !== null && index < this._nActiveActions;
  24792. },
  24793. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  24794. var actions = this._actions,
  24795. actionsByClip = this._actionsByClip,
  24796. actionsForClip = actionsByClip[ clipUuid ];
  24797. if ( actionsForClip === undefined ) {
  24798. actionsForClip = {
  24799. knownActions: [ action ],
  24800. actionByRoot: {}
  24801. };
  24802. action._byClipCacheIndex = 0;
  24803. actionsByClip[ clipUuid ] = actionsForClip;
  24804. } else {
  24805. var knownActions = actionsForClip.knownActions;
  24806. action._byClipCacheIndex = knownActions.length;
  24807. knownActions.push( action );
  24808. }
  24809. action._cacheIndex = actions.length;
  24810. actions.push( action );
  24811. actionsForClip.actionByRoot[ rootUuid ] = action;
  24812. },
  24813. _removeInactiveAction: function ( action ) {
  24814. var actions = this._actions,
  24815. lastInactiveAction = actions[ actions.length - 1 ],
  24816. cacheIndex = action._cacheIndex;
  24817. lastInactiveAction._cacheIndex = cacheIndex;
  24818. actions[ cacheIndex ] = lastInactiveAction;
  24819. actions.pop();
  24820. action._cacheIndex = null;
  24821. var clipUuid = action._clip.uuid,
  24822. actionsByClip = this._actionsByClip,
  24823. actionsForClip = actionsByClip[ clipUuid ],
  24824. knownActionsForClip = actionsForClip.knownActions,
  24825. lastKnownAction =
  24826. knownActionsForClip[ knownActionsForClip.length - 1 ],
  24827. byClipCacheIndex = action._byClipCacheIndex;
  24828. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  24829. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  24830. knownActionsForClip.pop();
  24831. action._byClipCacheIndex = null;
  24832. var actionByRoot = actionsForClip.actionByRoot,
  24833. rootUuid = ( action._localRoot || this._root ).uuid;
  24834. delete actionByRoot[ rootUuid ];
  24835. if ( knownActionsForClip.length === 0 ) {
  24836. delete actionsByClip[ clipUuid ];
  24837. }
  24838. this._removeInactiveBindingsForAction( action );
  24839. },
  24840. _removeInactiveBindingsForAction: function ( action ) {
  24841. var bindings = action._propertyBindings;
  24842. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24843. var binding = bindings[ i ];
  24844. if ( -- binding.referenceCount === 0 ) {
  24845. this._removeInactiveBinding( binding );
  24846. }
  24847. }
  24848. },
  24849. _lendAction: function ( action ) {
  24850. // [ active actions | inactive actions ]
  24851. // [ active actions >| inactive actions ]
  24852. // s a
  24853. // <-swap->
  24854. // a s
  24855. var actions = this._actions,
  24856. prevIndex = action._cacheIndex,
  24857. lastActiveIndex = this._nActiveActions ++,
  24858. firstInactiveAction = actions[ lastActiveIndex ];
  24859. action._cacheIndex = lastActiveIndex;
  24860. actions[ lastActiveIndex ] = action;
  24861. firstInactiveAction._cacheIndex = prevIndex;
  24862. actions[ prevIndex ] = firstInactiveAction;
  24863. },
  24864. _takeBackAction: function ( action ) {
  24865. // [ active actions | inactive actions ]
  24866. // [ active actions |< inactive actions ]
  24867. // a s
  24868. // <-swap->
  24869. // s a
  24870. var actions = this._actions,
  24871. prevIndex = action._cacheIndex,
  24872. firstInactiveIndex = -- this._nActiveActions,
  24873. lastActiveAction = actions[ firstInactiveIndex ];
  24874. action._cacheIndex = firstInactiveIndex;
  24875. actions[ firstInactiveIndex ] = action;
  24876. lastActiveAction._cacheIndex = prevIndex;
  24877. actions[ prevIndex ] = lastActiveAction;
  24878. },
  24879. // Memory management for PropertyMixer objects
  24880. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  24881. var bindingsByRoot = this._bindingsByRootAndName,
  24882. bindingByName = bindingsByRoot[ rootUuid ],
  24883. bindings = this._bindings;
  24884. if ( bindingByName === undefined ) {
  24885. bindingByName = {};
  24886. bindingsByRoot[ rootUuid ] = bindingByName;
  24887. }
  24888. bindingByName[ trackName ] = binding;
  24889. binding._cacheIndex = bindings.length;
  24890. bindings.push( binding );
  24891. },
  24892. _removeInactiveBinding: function ( binding ) {
  24893. var bindings = this._bindings,
  24894. propBinding = binding.binding,
  24895. rootUuid = propBinding.rootNode.uuid,
  24896. trackName = propBinding.path,
  24897. bindingsByRoot = this._bindingsByRootAndName,
  24898. bindingByName = bindingsByRoot[ rootUuid ],
  24899. lastInactiveBinding = bindings[ bindings.length - 1 ],
  24900. cacheIndex = binding._cacheIndex;
  24901. lastInactiveBinding._cacheIndex = cacheIndex;
  24902. bindings[ cacheIndex ] = lastInactiveBinding;
  24903. bindings.pop();
  24904. delete bindingByName[ trackName ];
  24905. remove_empty_map: {
  24906. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  24907. delete bindingsByRoot[ rootUuid ];
  24908. }
  24909. },
  24910. _lendBinding: function ( binding ) {
  24911. var bindings = this._bindings,
  24912. prevIndex = binding._cacheIndex,
  24913. lastActiveIndex = this._nActiveBindings ++,
  24914. firstInactiveBinding = bindings[ lastActiveIndex ];
  24915. binding._cacheIndex = lastActiveIndex;
  24916. bindings[ lastActiveIndex ] = binding;
  24917. firstInactiveBinding._cacheIndex = prevIndex;
  24918. bindings[ prevIndex ] = firstInactiveBinding;
  24919. },
  24920. _takeBackBinding: function ( binding ) {
  24921. var bindings = this._bindings,
  24922. prevIndex = binding._cacheIndex,
  24923. firstInactiveIndex = -- this._nActiveBindings,
  24924. lastActiveBinding = bindings[ firstInactiveIndex ];
  24925. binding._cacheIndex = firstInactiveIndex;
  24926. bindings[ firstInactiveIndex ] = binding;
  24927. lastActiveBinding._cacheIndex = prevIndex;
  24928. bindings[ prevIndex ] = lastActiveBinding;
  24929. },
  24930. // Memory management of Interpolants for weight and time scale
  24931. _lendControlInterpolant: function () {
  24932. var interpolants = this._controlInterpolants,
  24933. lastActiveIndex = this._nActiveControlInterpolants ++,
  24934. interpolant = interpolants[ lastActiveIndex ];
  24935. if ( interpolant === undefined ) {
  24936. interpolant = new LinearInterpolant(
  24937. new Float32Array( 2 ), new Float32Array( 2 ),
  24938. 1, this._controlInterpolantsResultBuffer );
  24939. interpolant.__cacheIndex = lastActiveIndex;
  24940. interpolants[ lastActiveIndex ] = interpolant;
  24941. }
  24942. return interpolant;
  24943. },
  24944. _takeBackControlInterpolant: function ( interpolant ) {
  24945. var interpolants = this._controlInterpolants,
  24946. prevIndex = interpolant.__cacheIndex,
  24947. firstInactiveIndex = -- this._nActiveControlInterpolants,
  24948. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  24949. interpolant.__cacheIndex = firstInactiveIndex;
  24950. interpolants[ firstInactiveIndex ] = interpolant;
  24951. lastActiveInterpolant.__cacheIndex = prevIndex;
  24952. interpolants[ prevIndex ] = lastActiveInterpolant;
  24953. },
  24954. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  24955. // return an action for a clip optionally using a custom root target
  24956. // object (this method allocates a lot of dynamic memory in case a
  24957. // previously unknown clip/root combination is specified)
  24958. clipAction: function ( clip, optionalRoot ) {
  24959. var root = optionalRoot || this._root,
  24960. rootUuid = root.uuid,
  24961. clipObject = typeof clip === 'string' ?
  24962. AnimationClip.findByName( root, clip ) : clip,
  24963. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  24964. actionsForClip = this._actionsByClip[ clipUuid ],
  24965. prototypeAction = null;
  24966. if ( actionsForClip !== undefined ) {
  24967. var existingAction =
  24968. actionsForClip.actionByRoot[ rootUuid ];
  24969. if ( existingAction !== undefined ) {
  24970. return existingAction;
  24971. }
  24972. // we know the clip, so we don't have to parse all
  24973. // the bindings again but can just copy
  24974. prototypeAction = actionsForClip.knownActions[ 0 ];
  24975. // also, take the clip from the prototype action
  24976. if ( clipObject === null )
  24977. clipObject = prototypeAction._clip;
  24978. }
  24979. // clip must be known when specified via string
  24980. if ( clipObject === null ) return null;
  24981. // allocate all resources required to run it
  24982. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  24983. this._bindAction( newAction, prototypeAction );
  24984. // and make the action known to the memory manager
  24985. this._addInactiveAction( newAction, clipUuid, rootUuid );
  24986. return newAction;
  24987. },
  24988. // get an existing action
  24989. existingAction: function ( clip, optionalRoot ) {
  24990. var root = optionalRoot || this._root,
  24991. rootUuid = root.uuid,
  24992. clipObject = typeof clip === 'string' ?
  24993. AnimationClip.findByName( root, clip ) : clip,
  24994. clipUuid = clipObject ? clipObject.uuid : clip,
  24995. actionsForClip = this._actionsByClip[ clipUuid ];
  24996. if ( actionsForClip !== undefined ) {
  24997. return actionsForClip.actionByRoot[ rootUuid ] || null;
  24998. }
  24999. return null;
  25000. },
  25001. // deactivates all previously scheduled actions
  25002. stopAllAction: function () {
  25003. var actions = this._actions,
  25004. nActions = this._nActiveActions,
  25005. bindings = this._bindings,
  25006. nBindings = this._nActiveBindings;
  25007. this._nActiveActions = 0;
  25008. this._nActiveBindings = 0;
  25009. for ( var i = 0; i !== nActions; ++ i ) {
  25010. actions[ i ].reset();
  25011. }
  25012. for ( var i = 0; i !== nBindings; ++ i ) {
  25013. bindings[ i ].useCount = 0;
  25014. }
  25015. return this;
  25016. },
  25017. // advance the time and update apply the animation
  25018. update: function ( deltaTime ) {
  25019. deltaTime *= this.timeScale;
  25020. var actions = this._actions,
  25021. nActions = this._nActiveActions,
  25022. time = this.time += deltaTime,
  25023. timeDirection = Math.sign( deltaTime ),
  25024. accuIndex = this._accuIndex ^= 1;
  25025. // run active actions
  25026. for ( var i = 0; i !== nActions; ++ i ) {
  25027. var action = actions[ i ];
  25028. action._update( time, deltaTime, timeDirection, accuIndex );
  25029. }
  25030. // update scene graph
  25031. var bindings = this._bindings,
  25032. nBindings = this._nActiveBindings;
  25033. for ( var i = 0; i !== nBindings; ++ i ) {
  25034. bindings[ i ].apply( accuIndex );
  25035. }
  25036. return this;
  25037. },
  25038. // return this mixer's root target object
  25039. getRoot: function () {
  25040. return this._root;
  25041. },
  25042. // free all resources specific to a particular clip
  25043. uncacheClip: function ( clip ) {
  25044. var actions = this._actions,
  25045. clipUuid = clip.uuid,
  25046. actionsByClip = this._actionsByClip,
  25047. actionsForClip = actionsByClip[ clipUuid ];
  25048. if ( actionsForClip !== undefined ) {
  25049. // note: just calling _removeInactiveAction would mess up the
  25050. // iteration state and also require updating the state we can
  25051. // just throw away
  25052. var actionsToRemove = actionsForClip.knownActions;
  25053. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  25054. var action = actionsToRemove[ i ];
  25055. this._deactivateAction( action );
  25056. var cacheIndex = action._cacheIndex,
  25057. lastInactiveAction = actions[ actions.length - 1 ];
  25058. action._cacheIndex = null;
  25059. action._byClipCacheIndex = null;
  25060. lastInactiveAction._cacheIndex = cacheIndex;
  25061. actions[ cacheIndex ] = lastInactiveAction;
  25062. actions.pop();
  25063. this._removeInactiveBindingsForAction( action );
  25064. }
  25065. delete actionsByClip[ clipUuid ];
  25066. }
  25067. },
  25068. // free all resources specific to a particular root target object
  25069. uncacheRoot: function ( root ) {
  25070. var rootUuid = root.uuid,
  25071. actionsByClip = this._actionsByClip;
  25072. for ( var clipUuid in actionsByClip ) {
  25073. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  25074. action = actionByRoot[ rootUuid ];
  25075. if ( action !== undefined ) {
  25076. this._deactivateAction( action );
  25077. this._removeInactiveAction( action );
  25078. }
  25079. }
  25080. var bindingsByRoot = this._bindingsByRootAndName,
  25081. bindingByName = bindingsByRoot[ rootUuid ];
  25082. if ( bindingByName !== undefined ) {
  25083. for ( var trackName in bindingByName ) {
  25084. var binding = bindingByName[ trackName ];
  25085. binding.restoreOriginalState();
  25086. this._removeInactiveBinding( binding );
  25087. }
  25088. }
  25089. },
  25090. // remove a targeted clip from the cache
  25091. uncacheAction: function ( clip, optionalRoot ) {
  25092. var action = this.existingAction( clip, optionalRoot );
  25093. if ( action !== null ) {
  25094. this._deactivateAction( action );
  25095. this._removeInactiveAction( action );
  25096. }
  25097. }
  25098. } );
  25099. /**
  25100. * @author mrdoob / http://mrdoob.com/
  25101. */
  25102. function Uniform( value ) {
  25103. if ( typeof value === 'string' ) {
  25104. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  25105. value = arguments[ 1 ];
  25106. }
  25107. this.value = value;
  25108. }
  25109. Uniform.prototype.clone = function () {
  25110. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  25111. };
  25112. /**
  25113. * @author benaadams / https://twitter.com/ben_a_adams
  25114. */
  25115. function InstancedBufferGeometry() {
  25116. BufferGeometry.call( this );
  25117. this.type = 'InstancedBufferGeometry';
  25118. this.maxInstancedCount = undefined;
  25119. }
  25120. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  25121. constructor: InstancedBufferGeometry,
  25122. isInstancedBufferGeometry: true,
  25123. copy: function ( source ) {
  25124. BufferGeometry.prototype.copy.call( this, source );
  25125. this.maxInstancedCount = source.maxInstancedCount;
  25126. return this;
  25127. },
  25128. clone: function () {
  25129. return new this.constructor().copy( this );
  25130. }
  25131. } );
  25132. /**
  25133. * @author benaadams / https://twitter.com/ben_a_adams
  25134. */
  25135. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  25136. this.data = interleavedBuffer;
  25137. this.itemSize = itemSize;
  25138. this.offset = offset;
  25139. this.normalized = normalized === true;
  25140. }
  25141. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  25142. count: {
  25143. get: function () {
  25144. return this.data.count;
  25145. }
  25146. },
  25147. array: {
  25148. get: function () {
  25149. return this.data.array;
  25150. }
  25151. }
  25152. } );
  25153. Object.assign( InterleavedBufferAttribute.prototype, {
  25154. isInterleavedBufferAttribute: true,
  25155. setX: function ( index, x ) {
  25156. this.data.array[ index * this.data.stride + this.offset ] = x;
  25157. return this;
  25158. },
  25159. setY: function ( index, y ) {
  25160. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  25161. return this;
  25162. },
  25163. setZ: function ( index, z ) {
  25164. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  25165. return this;
  25166. },
  25167. setW: function ( index, w ) {
  25168. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  25169. return this;
  25170. },
  25171. getX: function ( index ) {
  25172. return this.data.array[ index * this.data.stride + this.offset ];
  25173. },
  25174. getY: function ( index ) {
  25175. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  25176. },
  25177. getZ: function ( index ) {
  25178. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  25179. },
  25180. getW: function ( index ) {
  25181. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  25182. },
  25183. setXY: function ( index, x, y ) {
  25184. index = index * this.data.stride + this.offset;
  25185. this.data.array[ index + 0 ] = x;
  25186. this.data.array[ index + 1 ] = y;
  25187. return this;
  25188. },
  25189. setXYZ: function ( index, x, y, z ) {
  25190. index = index * this.data.stride + this.offset;
  25191. this.data.array[ index + 0 ] = x;
  25192. this.data.array[ index + 1 ] = y;
  25193. this.data.array[ index + 2 ] = z;
  25194. return this;
  25195. },
  25196. setXYZW: function ( index, x, y, z, w ) {
  25197. index = index * this.data.stride + this.offset;
  25198. this.data.array[ index + 0 ] = x;
  25199. this.data.array[ index + 1 ] = y;
  25200. this.data.array[ index + 2 ] = z;
  25201. this.data.array[ index + 3 ] = w;
  25202. return this;
  25203. }
  25204. } );
  25205. /**
  25206. * @author benaadams / https://twitter.com/ben_a_adams
  25207. */
  25208. function InterleavedBuffer( array, stride ) {
  25209. this.array = array;
  25210. this.stride = stride;
  25211. this.count = array !== undefined ? array.length / stride : 0;
  25212. this.dynamic = false;
  25213. this.updateRange = { offset: 0, count: - 1 };
  25214. this.version = 0;
  25215. }
  25216. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  25217. set: function ( value ) {
  25218. if ( value === true ) this.version ++;
  25219. }
  25220. } );
  25221. Object.assign( InterleavedBuffer.prototype, {
  25222. isInterleavedBuffer: true,
  25223. onUploadCallback: function () {},
  25224. setArray: function ( array ) {
  25225. if ( Array.isArray( array ) ) {
  25226. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  25227. }
  25228. this.count = array !== undefined ? array.length / this.stride : 0;
  25229. this.array = array;
  25230. return this;
  25231. },
  25232. setDynamic: function ( value ) {
  25233. this.dynamic = value;
  25234. return this;
  25235. },
  25236. copy: function ( source ) {
  25237. this.array = new source.array.constructor( source.array );
  25238. this.count = source.count;
  25239. this.stride = source.stride;
  25240. this.dynamic = source.dynamic;
  25241. return this;
  25242. },
  25243. copyAt: function ( index1, attribute, index2 ) {
  25244. index1 *= this.stride;
  25245. index2 *= attribute.stride;
  25246. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  25247. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  25248. }
  25249. return this;
  25250. },
  25251. set: function ( value, offset ) {
  25252. if ( offset === undefined ) offset = 0;
  25253. this.array.set( value, offset );
  25254. return this;
  25255. },
  25256. clone: function () {
  25257. return new this.constructor().copy( this );
  25258. },
  25259. onUpload: function ( callback ) {
  25260. this.onUploadCallback = callback;
  25261. return this;
  25262. }
  25263. } );
  25264. /**
  25265. * @author benaadams / https://twitter.com/ben_a_adams
  25266. */
  25267. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  25268. InterleavedBuffer.call( this, array, stride );
  25269. this.meshPerAttribute = meshPerAttribute || 1;
  25270. }
  25271. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  25272. constructor: InstancedInterleavedBuffer,
  25273. isInstancedInterleavedBuffer: true,
  25274. copy: function ( source ) {
  25275. InterleavedBuffer.prototype.copy.call( this, source );
  25276. this.meshPerAttribute = source.meshPerAttribute;
  25277. return this;
  25278. }
  25279. } );
  25280. /**
  25281. * @author benaadams / https://twitter.com/ben_a_adams
  25282. */
  25283. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  25284. BufferAttribute.call( this, array, itemSize );
  25285. this.meshPerAttribute = meshPerAttribute || 1;
  25286. }
  25287. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  25288. constructor: InstancedBufferAttribute,
  25289. isInstancedBufferAttribute: true,
  25290. copy: function ( source ) {
  25291. BufferAttribute.prototype.copy.call( this, source );
  25292. this.meshPerAttribute = source.meshPerAttribute;
  25293. return this;
  25294. }
  25295. } );
  25296. /**
  25297. * @author mrdoob / http://mrdoob.com/
  25298. * @author bhouston / http://clara.io/
  25299. * @author stephomi / http://stephaneginier.com/
  25300. */
  25301. function Raycaster( origin, direction, near, far ) {
  25302. this.ray = new Ray( origin, direction );
  25303. // direction is assumed to be normalized (for accurate distance calculations)
  25304. this.near = near || 0;
  25305. this.far = far || Infinity;
  25306. this.params = {
  25307. Mesh: {},
  25308. Line: {},
  25309. LOD: {},
  25310. Points: { threshold: 1 },
  25311. Sprite: {}
  25312. };
  25313. Object.defineProperties( this.params, {
  25314. PointCloud: {
  25315. get: function () {
  25316. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  25317. return this.Points;
  25318. }
  25319. }
  25320. } );
  25321. }
  25322. function ascSort( a, b ) {
  25323. return a.distance - b.distance;
  25324. }
  25325. function intersectObject( object, raycaster, intersects, recursive ) {
  25326. if ( object.visible === false ) return;
  25327. object.raycast( raycaster, intersects );
  25328. if ( recursive === true ) {
  25329. var children = object.children;
  25330. for ( var i = 0, l = children.length; i < l; i ++ ) {
  25331. intersectObject( children[ i ], raycaster, intersects, true );
  25332. }
  25333. }
  25334. }
  25335. Object.assign( Raycaster.prototype, {
  25336. linePrecision: 1,
  25337. set: function ( origin, direction ) {
  25338. // direction is assumed to be normalized (for accurate distance calculations)
  25339. this.ray.set( origin, direction );
  25340. },
  25341. setFromCamera: function ( coords, camera ) {
  25342. if ( ( camera && camera.isPerspectiveCamera ) ) {
  25343. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  25344. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  25345. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  25346. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  25347. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  25348. } else {
  25349. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  25350. }
  25351. },
  25352. intersectObject: function ( object, recursive, optionalTarget ) {
  25353. var intersects = optionalTarget || [];
  25354. intersectObject( object, this, intersects, recursive );
  25355. intersects.sort( ascSort );
  25356. return intersects;
  25357. },
  25358. intersectObjects: function ( objects, recursive, optionalTarget ) {
  25359. var intersects = optionalTarget || [];
  25360. if ( Array.isArray( objects ) === false ) {
  25361. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  25362. return intersects;
  25363. }
  25364. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  25365. intersectObject( objects[ i ], this, intersects, recursive );
  25366. }
  25367. intersects.sort( ascSort );
  25368. return intersects;
  25369. }
  25370. } );
  25371. /**
  25372. * @author alteredq / http://alteredqualia.com/
  25373. */
  25374. function Clock( autoStart ) {
  25375. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25376. this.startTime = 0;
  25377. this.oldTime = 0;
  25378. this.elapsedTime = 0;
  25379. this.running = false;
  25380. }
  25381. Object.assign( Clock.prototype, {
  25382. start: function () {
  25383. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25384. this.oldTime = this.startTime;
  25385. this.elapsedTime = 0;
  25386. this.running = true;
  25387. },
  25388. stop: function () {
  25389. this.getElapsedTime();
  25390. this.running = false;
  25391. this.autoStart = false;
  25392. },
  25393. getElapsedTime: function () {
  25394. this.getDelta();
  25395. return this.elapsedTime;
  25396. },
  25397. getDelta: function () {
  25398. var diff = 0;
  25399. if ( this.autoStart && ! this.running ) {
  25400. this.start();
  25401. return 0;
  25402. }
  25403. if ( this.running ) {
  25404. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25405. diff = ( newTime - this.oldTime ) / 1000;
  25406. this.oldTime = newTime;
  25407. this.elapsedTime += diff;
  25408. }
  25409. return diff;
  25410. }
  25411. } );
  25412. /**
  25413. * @author bhouston / http://clara.io
  25414. * @author WestLangley / http://github.com/WestLangley
  25415. *
  25416. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  25417. *
  25418. * The poles (phi) are at the positive and negative y axis.
  25419. * The equator starts at positive z.
  25420. */
  25421. function Spherical( radius, phi, theta ) {
  25422. this.radius = ( radius !== undefined ) ? radius : 1.0;
  25423. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  25424. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  25425. return this;
  25426. }
  25427. Object.assign( Spherical.prototype, {
  25428. set: function ( radius, phi, theta ) {
  25429. this.radius = radius;
  25430. this.phi = phi;
  25431. this.theta = theta;
  25432. return this;
  25433. },
  25434. clone: function () {
  25435. return new this.constructor().copy( this );
  25436. },
  25437. copy: function ( other ) {
  25438. this.radius = other.radius;
  25439. this.phi = other.phi;
  25440. this.theta = other.theta;
  25441. return this;
  25442. },
  25443. // restrict phi to be betwee EPS and PI-EPS
  25444. makeSafe: function () {
  25445. var EPS = 0.000001;
  25446. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  25447. return this;
  25448. },
  25449. setFromVector3: function ( vec3 ) {
  25450. this.radius = vec3.length();
  25451. if ( this.radius === 0 ) {
  25452. this.theta = 0;
  25453. this.phi = 0;
  25454. } else {
  25455. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  25456. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  25457. }
  25458. return this;
  25459. }
  25460. } );
  25461. /**
  25462. * @author Mugen87 / https://github.com/Mugen87
  25463. *
  25464. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  25465. *
  25466. */
  25467. function Cylindrical( radius, theta, y ) {
  25468. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  25469. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  25470. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  25471. return this;
  25472. }
  25473. Object.assign( Cylindrical.prototype, {
  25474. set: function ( radius, theta, y ) {
  25475. this.radius = radius;
  25476. this.theta = theta;
  25477. this.y = y;
  25478. return this;
  25479. },
  25480. clone: function () {
  25481. return new this.constructor().copy( this );
  25482. },
  25483. copy: function ( other ) {
  25484. this.radius = other.radius;
  25485. this.theta = other.theta;
  25486. this.y = other.y;
  25487. return this;
  25488. },
  25489. setFromVector3: function ( vec3 ) {
  25490. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  25491. this.theta = Math.atan2( vec3.x, vec3.z );
  25492. this.y = vec3.y;
  25493. return this;
  25494. }
  25495. } );
  25496. /**
  25497. * @author bhouston / http://clara.io
  25498. */
  25499. function Box2( min, max ) {
  25500. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  25501. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  25502. }
  25503. Object.assign( Box2.prototype, {
  25504. set: function ( min, max ) {
  25505. this.min.copy( min );
  25506. this.max.copy( max );
  25507. return this;
  25508. },
  25509. setFromPoints: function ( points ) {
  25510. this.makeEmpty();
  25511. for ( var i = 0, il = points.length; i < il; i ++ ) {
  25512. this.expandByPoint( points[ i ] );
  25513. }
  25514. return this;
  25515. },
  25516. setFromCenterAndSize: function () {
  25517. var v1 = new Vector2();
  25518. return function setFromCenterAndSize( center, size ) {
  25519. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  25520. this.min.copy( center ).sub( halfSize );
  25521. this.max.copy( center ).add( halfSize );
  25522. return this;
  25523. };
  25524. }(),
  25525. clone: function () {
  25526. return new this.constructor().copy( this );
  25527. },
  25528. copy: function ( box ) {
  25529. this.min.copy( box.min );
  25530. this.max.copy( box.max );
  25531. return this;
  25532. },
  25533. makeEmpty: function () {
  25534. this.min.x = this.min.y = + Infinity;
  25535. this.max.x = this.max.y = - Infinity;
  25536. return this;
  25537. },
  25538. isEmpty: function () {
  25539. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  25540. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  25541. },
  25542. getCenter: function ( target ) {
  25543. if ( target === undefined ) {
  25544. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  25545. target = new Vector2();
  25546. }
  25547. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  25548. },
  25549. getSize: function ( target ) {
  25550. if ( target === undefined ) {
  25551. console.warn( 'THREE.Box2: .getSize() target is now required' );
  25552. target = new Vector2();
  25553. }
  25554. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  25555. },
  25556. expandByPoint: function ( point ) {
  25557. this.min.min( point );
  25558. this.max.max( point );
  25559. return this;
  25560. },
  25561. expandByVector: function ( vector ) {
  25562. this.min.sub( vector );
  25563. this.max.add( vector );
  25564. return this;
  25565. },
  25566. expandByScalar: function ( scalar ) {
  25567. this.min.addScalar( - scalar );
  25568. this.max.addScalar( scalar );
  25569. return this;
  25570. },
  25571. containsPoint: function ( point ) {
  25572. return point.x < this.min.x || point.x > this.max.x ||
  25573. point.y < this.min.y || point.y > this.max.y ? false : true;
  25574. },
  25575. containsBox: function ( box ) {
  25576. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  25577. this.min.y <= box.min.y && box.max.y <= this.max.y;
  25578. },
  25579. getParameter: function ( point, target ) {
  25580. // This can potentially have a divide by zero if the box
  25581. // has a size dimension of 0.
  25582. if ( target === undefined ) {
  25583. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  25584. target = new Vector2();
  25585. }
  25586. return target.set(
  25587. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  25588. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  25589. );
  25590. },
  25591. intersectsBox: function ( box ) {
  25592. // using 4 splitting planes to rule out intersections
  25593. return box.max.x < this.min.x || box.min.x > this.max.x ||
  25594. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  25595. },
  25596. clampPoint: function ( point, target ) {
  25597. if ( target === undefined ) {
  25598. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  25599. target = new Vector2();
  25600. }
  25601. return target.copy( point ).clamp( this.min, this.max );
  25602. },
  25603. distanceToPoint: function () {
  25604. var v1 = new Vector2();
  25605. return function distanceToPoint( point ) {
  25606. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  25607. return clampedPoint.sub( point ).length();
  25608. };
  25609. }(),
  25610. intersect: function ( box ) {
  25611. this.min.max( box.min );
  25612. this.max.min( box.max );
  25613. return this;
  25614. },
  25615. union: function ( box ) {
  25616. this.min.min( box.min );
  25617. this.max.max( box.max );
  25618. return this;
  25619. },
  25620. translate: function ( offset ) {
  25621. this.min.add( offset );
  25622. this.max.add( offset );
  25623. return this;
  25624. },
  25625. equals: function ( box ) {
  25626. return box.min.equals( this.min ) && box.max.equals( this.max );
  25627. }
  25628. } );
  25629. /**
  25630. * @author alteredq / http://alteredqualia.com/
  25631. */
  25632. function ImmediateRenderObject( material ) {
  25633. Object3D.call( this );
  25634. this.material = material;
  25635. this.render = function ( /* renderCallback */ ) {};
  25636. }
  25637. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  25638. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  25639. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  25640. /**
  25641. * @author mrdoob / http://mrdoob.com/
  25642. * @author WestLangley / http://github.com/WestLangley
  25643. */
  25644. function VertexNormalsHelper( object, size, hex, linewidth ) {
  25645. this.object = object;
  25646. this.size = ( size !== undefined ) ? size : 1;
  25647. var color = ( hex !== undefined ) ? hex : 0xff0000;
  25648. var width = ( linewidth !== undefined ) ? linewidth : 1;
  25649. //
  25650. var nNormals = 0;
  25651. var objGeometry = this.object.geometry;
  25652. if ( objGeometry && objGeometry.isGeometry ) {
  25653. nNormals = objGeometry.faces.length * 3;
  25654. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25655. nNormals = objGeometry.attributes.normal.count;
  25656. }
  25657. //
  25658. var geometry = new BufferGeometry();
  25659. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  25660. geometry.addAttribute( 'position', positions );
  25661. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  25662. //
  25663. this.matrixAutoUpdate = false;
  25664. this.update();
  25665. }
  25666. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  25667. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  25668. VertexNormalsHelper.prototype.update = ( function () {
  25669. var v1 = new Vector3();
  25670. var v2 = new Vector3();
  25671. var normalMatrix = new Matrix3();
  25672. return function update() {
  25673. var keys = [ 'a', 'b', 'c' ];
  25674. this.object.updateMatrixWorld( true );
  25675. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  25676. var matrixWorld = this.object.matrixWorld;
  25677. var position = this.geometry.attributes.position;
  25678. //
  25679. var objGeometry = this.object.geometry;
  25680. if ( objGeometry && objGeometry.isGeometry ) {
  25681. var vertices = objGeometry.vertices;
  25682. var faces = objGeometry.faces;
  25683. var idx = 0;
  25684. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  25685. var face = faces[ i ];
  25686. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  25687. var vertex = vertices[ face[ keys[ j ] ] ];
  25688. var normal = face.vertexNormals[ j ];
  25689. v1.copy( vertex ).applyMatrix4( matrixWorld );
  25690. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25691. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25692. idx = idx + 1;
  25693. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25694. idx = idx + 1;
  25695. }
  25696. }
  25697. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25698. var objPos = objGeometry.attributes.position;
  25699. var objNorm = objGeometry.attributes.normal;
  25700. var idx = 0;
  25701. // for simplicity, ignore index and drawcalls, and render every normal
  25702. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  25703. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  25704. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  25705. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25706. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25707. idx = idx + 1;
  25708. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25709. idx = idx + 1;
  25710. }
  25711. }
  25712. position.needsUpdate = true;
  25713. };
  25714. }() );
  25715. /**
  25716. * @author alteredq / http://alteredqualia.com/
  25717. * @author mrdoob / http://mrdoob.com/
  25718. * @author WestLangley / http://github.com/WestLangley
  25719. */
  25720. function SpotLightHelper( light, color ) {
  25721. Object3D.call( this );
  25722. this.light = light;
  25723. this.light.updateMatrixWorld();
  25724. this.matrix = light.matrixWorld;
  25725. this.matrixAutoUpdate = false;
  25726. this.color = color;
  25727. var geometry = new BufferGeometry();
  25728. var positions = [
  25729. 0, 0, 0, 0, 0, 1,
  25730. 0, 0, 0, 1, 0, 1,
  25731. 0, 0, 0, - 1, 0, 1,
  25732. 0, 0, 0, 0, 1, 1,
  25733. 0, 0, 0, 0, - 1, 1
  25734. ];
  25735. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  25736. var p1 = ( i / l ) * Math.PI * 2;
  25737. var p2 = ( j / l ) * Math.PI * 2;
  25738. positions.push(
  25739. Math.cos( p1 ), Math.sin( p1 ), 1,
  25740. Math.cos( p2 ), Math.sin( p2 ), 1
  25741. );
  25742. }
  25743. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  25744. var material = new LineBasicMaterial( { fog: false } );
  25745. this.cone = new LineSegments( geometry, material );
  25746. this.add( this.cone );
  25747. this.update();
  25748. }
  25749. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  25750. SpotLightHelper.prototype.constructor = SpotLightHelper;
  25751. SpotLightHelper.prototype.dispose = function () {
  25752. this.cone.geometry.dispose();
  25753. this.cone.material.dispose();
  25754. };
  25755. SpotLightHelper.prototype.update = function () {
  25756. var vector = new Vector3();
  25757. var vector2 = new Vector3();
  25758. return function update() {
  25759. this.light.updateMatrixWorld();
  25760. var coneLength = this.light.distance ? this.light.distance : 1000;
  25761. var coneWidth = coneLength * Math.tan( this.light.angle );
  25762. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  25763. vector.setFromMatrixPosition( this.light.matrixWorld );
  25764. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  25765. this.cone.lookAt( vector2.sub( vector ) );
  25766. if ( this.color !== undefined ) {
  25767. this.cone.material.color.set( this.color );
  25768. } else {
  25769. this.cone.material.color.copy( this.light.color );
  25770. }
  25771. };
  25772. }();
  25773. /**
  25774. * @author Sean Griffin / http://twitter.com/sgrif
  25775. * @author Michael Guerrero / http://realitymeltdown.com
  25776. * @author mrdoob / http://mrdoob.com/
  25777. * @author ikerr / http://verold.com
  25778. * @author Mugen87 / https://github.com/Mugen87
  25779. */
  25780. function getBoneList( object ) {
  25781. var boneList = [];
  25782. if ( object && object.isBone ) {
  25783. boneList.push( object );
  25784. }
  25785. for ( var i = 0; i < object.children.length; i ++ ) {
  25786. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  25787. }
  25788. return boneList;
  25789. }
  25790. function SkeletonHelper( object ) {
  25791. var bones = getBoneList( object );
  25792. var geometry = new BufferGeometry();
  25793. var vertices = [];
  25794. var colors = [];
  25795. var color1 = new Color( 0, 0, 1 );
  25796. var color2 = new Color( 0, 1, 0 );
  25797. for ( var i = 0; i < bones.length; i ++ ) {
  25798. var bone = bones[ i ];
  25799. if ( bone.parent && bone.parent.isBone ) {
  25800. vertices.push( 0, 0, 0 );
  25801. vertices.push( 0, 0, 0 );
  25802. colors.push( color1.r, color1.g, color1.b );
  25803. colors.push( color2.r, color2.g, color2.b );
  25804. }
  25805. }
  25806. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25807. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25808. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  25809. LineSegments.call( this, geometry, material );
  25810. this.root = object;
  25811. this.bones = bones;
  25812. this.matrix = object.matrixWorld;
  25813. this.matrixAutoUpdate = false;
  25814. }
  25815. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  25816. SkeletonHelper.prototype.constructor = SkeletonHelper;
  25817. SkeletonHelper.prototype.updateMatrixWorld = function () {
  25818. var vector = new Vector3();
  25819. var boneMatrix = new Matrix4();
  25820. var matrixWorldInv = new Matrix4();
  25821. return function updateMatrixWorld( force ) {
  25822. var bones = this.bones;
  25823. var geometry = this.geometry;
  25824. var position = geometry.getAttribute( 'position' );
  25825. matrixWorldInv.getInverse( this.root.matrixWorld );
  25826. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  25827. var bone = bones[ i ];
  25828. if ( bone.parent && bone.parent.isBone ) {
  25829. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  25830. vector.setFromMatrixPosition( boneMatrix );
  25831. position.setXYZ( j, vector.x, vector.y, vector.z );
  25832. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  25833. vector.setFromMatrixPosition( boneMatrix );
  25834. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  25835. j += 2;
  25836. }
  25837. }
  25838. geometry.getAttribute( 'position' ).needsUpdate = true;
  25839. Object3D.prototype.updateMatrixWorld.call( this, force );
  25840. };
  25841. }();
  25842. /**
  25843. * @author alteredq / http://alteredqualia.com/
  25844. * @author mrdoob / http://mrdoob.com/
  25845. */
  25846. function PointLightHelper( light, sphereSize, color ) {
  25847. this.light = light;
  25848. this.light.updateMatrixWorld();
  25849. this.color = color;
  25850. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  25851. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25852. Mesh.call( this, geometry, material );
  25853. this.matrix = this.light.matrixWorld;
  25854. this.matrixAutoUpdate = false;
  25855. this.update();
  25856. /*
  25857. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  25858. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  25859. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  25860. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  25861. var d = light.distance;
  25862. if ( d === 0.0 ) {
  25863. this.lightDistance.visible = false;
  25864. } else {
  25865. this.lightDistance.scale.set( d, d, d );
  25866. }
  25867. this.add( this.lightDistance );
  25868. */
  25869. }
  25870. PointLightHelper.prototype = Object.create( Mesh.prototype );
  25871. PointLightHelper.prototype.constructor = PointLightHelper;
  25872. PointLightHelper.prototype.dispose = function () {
  25873. this.geometry.dispose();
  25874. this.material.dispose();
  25875. };
  25876. PointLightHelper.prototype.update = function () {
  25877. if ( this.color !== undefined ) {
  25878. this.material.color.set( this.color );
  25879. } else {
  25880. this.material.color.copy( this.light.color );
  25881. }
  25882. /*
  25883. var d = this.light.distance;
  25884. if ( d === 0.0 ) {
  25885. this.lightDistance.visible = false;
  25886. } else {
  25887. this.lightDistance.visible = true;
  25888. this.lightDistance.scale.set( d, d, d );
  25889. }
  25890. */
  25891. };
  25892. /**
  25893. * @author abelnation / http://github.com/abelnation
  25894. * @author Mugen87 / http://github.com/Mugen87
  25895. * @author WestLangley / http://github.com/WestLangley
  25896. */
  25897. function RectAreaLightHelper( light, color ) {
  25898. Object3D.call( this );
  25899. this.light = light;
  25900. this.light.updateMatrixWorld();
  25901. this.matrix = light.matrixWorld;
  25902. this.matrixAutoUpdate = false;
  25903. this.color = color;
  25904. var material = new LineBasicMaterial( { fog: false } );
  25905. var geometry = new BufferGeometry();
  25906. geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) );
  25907. this.line = new Line( geometry, material );
  25908. this.add( this.line );
  25909. this.update();
  25910. }
  25911. RectAreaLightHelper.prototype = Object.create( Object3D.prototype );
  25912. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  25913. RectAreaLightHelper.prototype.dispose = function () {
  25914. this.children[ 0 ].geometry.dispose();
  25915. this.children[ 0 ].material.dispose();
  25916. };
  25917. RectAreaLightHelper.prototype.update = function () {
  25918. // calculate new dimensions of the helper
  25919. var hx = this.light.width * 0.5;
  25920. var hy = this.light.height * 0.5;
  25921. var position = this.line.geometry.attributes.position;
  25922. var array = position.array;
  25923. // update vertices
  25924. array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0;
  25925. array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0;
  25926. array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0;
  25927. array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0;
  25928. array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0;
  25929. position.needsUpdate = true;
  25930. if ( this.color !== undefined ) {
  25931. this.line.material.color.set( this.color );
  25932. } else {
  25933. this.line.material.color.copy( this.light.color );
  25934. }
  25935. };
  25936. /**
  25937. * @author alteredq / http://alteredqualia.com/
  25938. * @author mrdoob / http://mrdoob.com/
  25939. * @author Mugen87 / https://github.com/Mugen87
  25940. */
  25941. function HemisphereLightHelper( light, size, color ) {
  25942. Object3D.call( this );
  25943. this.light = light;
  25944. this.light.updateMatrixWorld();
  25945. this.matrix = light.matrixWorld;
  25946. this.matrixAutoUpdate = false;
  25947. this.color = color;
  25948. var geometry = new OctahedronBufferGeometry( size );
  25949. geometry.rotateY( Math.PI * 0.5 );
  25950. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25951. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  25952. var position = geometry.getAttribute( 'position' );
  25953. var colors = new Float32Array( position.count * 3 );
  25954. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  25955. this.add( new Mesh( geometry, this.material ) );
  25956. this.update();
  25957. }
  25958. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  25959. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  25960. HemisphereLightHelper.prototype.dispose = function () {
  25961. this.children[ 0 ].geometry.dispose();
  25962. this.children[ 0 ].material.dispose();
  25963. };
  25964. HemisphereLightHelper.prototype.update = function () {
  25965. var vector = new Vector3();
  25966. var color1 = new Color();
  25967. var color2 = new Color();
  25968. return function update() {
  25969. var mesh = this.children[ 0 ];
  25970. if ( this.color !== undefined ) {
  25971. this.material.color.set( this.color );
  25972. } else {
  25973. var colors = mesh.geometry.getAttribute( 'color' );
  25974. color1.copy( this.light.color );
  25975. color2.copy( this.light.groundColor );
  25976. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  25977. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  25978. colors.setXYZ( i, color.r, color.g, color.b );
  25979. }
  25980. colors.needsUpdate = true;
  25981. }
  25982. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  25983. };
  25984. }();
  25985. /**
  25986. * @author mrdoob / http://mrdoob.com/
  25987. */
  25988. function GridHelper( size, divisions, color1, color2 ) {
  25989. size = size || 10;
  25990. divisions = divisions || 10;
  25991. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  25992. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  25993. var center = divisions / 2;
  25994. var step = size / divisions;
  25995. var halfSize = size / 2;
  25996. var vertices = [], colors = [];
  25997. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  25998. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  25999. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  26000. var color = i === center ? color1 : color2;
  26001. color.toArray( colors, j ); j += 3;
  26002. color.toArray( colors, j ); j += 3;
  26003. color.toArray( colors, j ); j += 3;
  26004. color.toArray( colors, j ); j += 3;
  26005. }
  26006. var geometry = new BufferGeometry();
  26007. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26008. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26009. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26010. LineSegments.call( this, geometry, material );
  26011. }
  26012. GridHelper.prototype = Object.create( LineSegments.prototype );
  26013. GridHelper.prototype.constructor = GridHelper;
  26014. /**
  26015. * @author mrdoob / http://mrdoob.com/
  26016. * @author Mugen87 / http://github.com/Mugen87
  26017. * @author Hectate / http://www.github.com/Hectate
  26018. */
  26019. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  26020. radius = radius || 10;
  26021. radials = radials || 16;
  26022. circles = circles || 8;
  26023. divisions = divisions || 64;
  26024. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26025. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26026. var vertices = [];
  26027. var colors = [];
  26028. var x, z;
  26029. var v, i, j, r, color;
  26030. // create the radials
  26031. for ( i = 0; i <= radials; i ++ ) {
  26032. v = ( i / radials ) * ( Math.PI * 2 );
  26033. x = Math.sin( v ) * radius;
  26034. z = Math.cos( v ) * radius;
  26035. vertices.push( 0, 0, 0 );
  26036. vertices.push( x, 0, z );
  26037. color = ( i & 1 ) ? color1 : color2;
  26038. colors.push( color.r, color.g, color.b );
  26039. colors.push( color.r, color.g, color.b );
  26040. }
  26041. // create the circles
  26042. for ( i = 0; i <= circles; i ++ ) {
  26043. color = ( i & 1 ) ? color1 : color2;
  26044. r = radius - ( radius / circles * i );
  26045. for ( j = 0; j < divisions; j ++ ) {
  26046. // first vertex
  26047. v = ( j / divisions ) * ( Math.PI * 2 );
  26048. x = Math.sin( v ) * r;
  26049. z = Math.cos( v ) * r;
  26050. vertices.push( x, 0, z );
  26051. colors.push( color.r, color.g, color.b );
  26052. // second vertex
  26053. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  26054. x = Math.sin( v ) * r;
  26055. z = Math.cos( v ) * r;
  26056. vertices.push( x, 0, z );
  26057. colors.push( color.r, color.g, color.b );
  26058. }
  26059. }
  26060. var geometry = new BufferGeometry();
  26061. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26062. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26063. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26064. LineSegments.call( this, geometry, material );
  26065. }
  26066. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  26067. PolarGridHelper.prototype.constructor = PolarGridHelper;
  26068. /**
  26069. * @author mrdoob / http://mrdoob.com/
  26070. * @author WestLangley / http://github.com/WestLangley
  26071. */
  26072. function FaceNormalsHelper( object, size, hex, linewidth ) {
  26073. // FaceNormalsHelper only supports THREE.Geometry
  26074. this.object = object;
  26075. this.size = ( size !== undefined ) ? size : 1;
  26076. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26077. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26078. //
  26079. var nNormals = 0;
  26080. var objGeometry = this.object.geometry;
  26081. if ( objGeometry && objGeometry.isGeometry ) {
  26082. nNormals = objGeometry.faces.length;
  26083. } else {
  26084. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  26085. }
  26086. //
  26087. var geometry = new BufferGeometry();
  26088. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26089. geometry.addAttribute( 'position', positions );
  26090. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26091. //
  26092. this.matrixAutoUpdate = false;
  26093. this.update();
  26094. }
  26095. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26096. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  26097. FaceNormalsHelper.prototype.update = ( function () {
  26098. var v1 = new Vector3();
  26099. var v2 = new Vector3();
  26100. var normalMatrix = new Matrix3();
  26101. return function update() {
  26102. this.object.updateMatrixWorld( true );
  26103. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26104. var matrixWorld = this.object.matrixWorld;
  26105. var position = this.geometry.attributes.position;
  26106. //
  26107. var objGeometry = this.object.geometry;
  26108. var vertices = objGeometry.vertices;
  26109. var faces = objGeometry.faces;
  26110. var idx = 0;
  26111. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26112. var face = faces[ i ];
  26113. var normal = face.normal;
  26114. v1.copy( vertices[ face.a ] )
  26115. .add( vertices[ face.b ] )
  26116. .add( vertices[ face.c ] )
  26117. .divideScalar( 3 )
  26118. .applyMatrix4( matrixWorld );
  26119. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26120. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26121. idx = idx + 1;
  26122. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26123. idx = idx + 1;
  26124. }
  26125. position.needsUpdate = true;
  26126. };
  26127. }() );
  26128. /**
  26129. * @author alteredq / http://alteredqualia.com/
  26130. * @author mrdoob / http://mrdoob.com/
  26131. * @author WestLangley / http://github.com/WestLangley
  26132. */
  26133. function DirectionalLightHelper( light, size, color ) {
  26134. Object3D.call( this );
  26135. this.light = light;
  26136. this.light.updateMatrixWorld();
  26137. this.matrix = light.matrixWorld;
  26138. this.matrixAutoUpdate = false;
  26139. this.color = color;
  26140. if ( size === undefined ) size = 1;
  26141. var geometry = new BufferGeometry();
  26142. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  26143. - size, size, 0,
  26144. size, size, 0,
  26145. size, - size, 0,
  26146. - size, - size, 0,
  26147. - size, size, 0
  26148. ], 3 ) );
  26149. var material = new LineBasicMaterial( { fog: false } );
  26150. this.lightPlane = new Line( geometry, material );
  26151. this.add( this.lightPlane );
  26152. geometry = new BufferGeometry();
  26153. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  26154. this.targetLine = new Line( geometry, material );
  26155. this.add( this.targetLine );
  26156. this.update();
  26157. }
  26158. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  26159. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  26160. DirectionalLightHelper.prototype.dispose = function () {
  26161. this.lightPlane.geometry.dispose();
  26162. this.lightPlane.material.dispose();
  26163. this.targetLine.geometry.dispose();
  26164. this.targetLine.material.dispose();
  26165. };
  26166. DirectionalLightHelper.prototype.update = function () {
  26167. var v1 = new Vector3();
  26168. var v2 = new Vector3();
  26169. var v3 = new Vector3();
  26170. return function update() {
  26171. v1.setFromMatrixPosition( this.light.matrixWorld );
  26172. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  26173. v3.subVectors( v2, v1 );
  26174. this.lightPlane.lookAt( v3 );
  26175. if ( this.color !== undefined ) {
  26176. this.lightPlane.material.color.set( this.color );
  26177. this.targetLine.material.color.set( this.color );
  26178. } else {
  26179. this.lightPlane.material.color.copy( this.light.color );
  26180. this.targetLine.material.color.copy( this.light.color );
  26181. }
  26182. this.targetLine.lookAt( v3 );
  26183. this.targetLine.scale.z = v3.length();
  26184. };
  26185. }();
  26186. /**
  26187. * @author alteredq / http://alteredqualia.com/
  26188. * @author Mugen87 / https://github.com/Mugen87
  26189. *
  26190. * - shows frustum, line of sight and up of the camera
  26191. * - suitable for fast updates
  26192. * - based on frustum visualization in lightgl.js shadowmap example
  26193. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  26194. */
  26195. function CameraHelper( camera ) {
  26196. var geometry = new BufferGeometry();
  26197. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  26198. var vertices = [];
  26199. var colors = [];
  26200. var pointMap = {};
  26201. // colors
  26202. var colorFrustum = new Color( 0xffaa00 );
  26203. var colorCone = new Color( 0xff0000 );
  26204. var colorUp = new Color( 0x00aaff );
  26205. var colorTarget = new Color( 0xffffff );
  26206. var colorCross = new Color( 0x333333 );
  26207. // near
  26208. addLine( 'n1', 'n2', colorFrustum );
  26209. addLine( 'n2', 'n4', colorFrustum );
  26210. addLine( 'n4', 'n3', colorFrustum );
  26211. addLine( 'n3', 'n1', colorFrustum );
  26212. // far
  26213. addLine( 'f1', 'f2', colorFrustum );
  26214. addLine( 'f2', 'f4', colorFrustum );
  26215. addLine( 'f4', 'f3', colorFrustum );
  26216. addLine( 'f3', 'f1', colorFrustum );
  26217. // sides
  26218. addLine( 'n1', 'f1', colorFrustum );
  26219. addLine( 'n2', 'f2', colorFrustum );
  26220. addLine( 'n3', 'f3', colorFrustum );
  26221. addLine( 'n4', 'f4', colorFrustum );
  26222. // cone
  26223. addLine( 'p', 'n1', colorCone );
  26224. addLine( 'p', 'n2', colorCone );
  26225. addLine( 'p', 'n3', colorCone );
  26226. addLine( 'p', 'n4', colorCone );
  26227. // up
  26228. addLine( 'u1', 'u2', colorUp );
  26229. addLine( 'u2', 'u3', colorUp );
  26230. addLine( 'u3', 'u1', colorUp );
  26231. // target
  26232. addLine( 'c', 't', colorTarget );
  26233. addLine( 'p', 'c', colorCross );
  26234. // cross
  26235. addLine( 'cn1', 'cn2', colorCross );
  26236. addLine( 'cn3', 'cn4', colorCross );
  26237. addLine( 'cf1', 'cf2', colorCross );
  26238. addLine( 'cf3', 'cf4', colorCross );
  26239. function addLine( a, b, color ) {
  26240. addPoint( a, color );
  26241. addPoint( b, color );
  26242. }
  26243. function addPoint( id, color ) {
  26244. vertices.push( 0, 0, 0 );
  26245. colors.push( color.r, color.g, color.b );
  26246. if ( pointMap[ id ] === undefined ) {
  26247. pointMap[ id ] = [];
  26248. }
  26249. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  26250. }
  26251. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26252. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26253. LineSegments.call( this, geometry, material );
  26254. this.camera = camera;
  26255. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  26256. this.matrix = camera.matrixWorld;
  26257. this.matrixAutoUpdate = false;
  26258. this.pointMap = pointMap;
  26259. this.update();
  26260. }
  26261. CameraHelper.prototype = Object.create( LineSegments.prototype );
  26262. CameraHelper.prototype.constructor = CameraHelper;
  26263. CameraHelper.prototype.update = function () {
  26264. var geometry, pointMap;
  26265. var vector = new Vector3();
  26266. var camera = new Camera();
  26267. function setPoint( point, x, y, z ) {
  26268. vector.set( x, y, z ).unproject( camera );
  26269. var points = pointMap[ point ];
  26270. if ( points !== undefined ) {
  26271. var position = geometry.getAttribute( 'position' );
  26272. for ( var i = 0, l = points.length; i < l; i ++ ) {
  26273. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  26274. }
  26275. }
  26276. }
  26277. return function update() {
  26278. geometry = this.geometry;
  26279. pointMap = this.pointMap;
  26280. var w = 1, h = 1;
  26281. // we need just camera projection matrix
  26282. // world matrix must be identity
  26283. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  26284. // center / target
  26285. setPoint( 'c', 0, 0, - 1 );
  26286. setPoint( 't', 0, 0, 1 );
  26287. // near
  26288. setPoint( 'n1', - w, - h, - 1 );
  26289. setPoint( 'n2', w, - h, - 1 );
  26290. setPoint( 'n3', - w, h, - 1 );
  26291. setPoint( 'n4', w, h, - 1 );
  26292. // far
  26293. setPoint( 'f1', - w, - h, 1 );
  26294. setPoint( 'f2', w, - h, 1 );
  26295. setPoint( 'f3', - w, h, 1 );
  26296. setPoint( 'f4', w, h, 1 );
  26297. // up
  26298. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  26299. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  26300. setPoint( 'u3', 0, h * 2, - 1 );
  26301. // cross
  26302. setPoint( 'cf1', - w, 0, 1 );
  26303. setPoint( 'cf2', w, 0, 1 );
  26304. setPoint( 'cf3', 0, - h, 1 );
  26305. setPoint( 'cf4', 0, h, 1 );
  26306. setPoint( 'cn1', - w, 0, - 1 );
  26307. setPoint( 'cn2', w, 0, - 1 );
  26308. setPoint( 'cn3', 0, - h, - 1 );
  26309. setPoint( 'cn4', 0, h, - 1 );
  26310. geometry.getAttribute( 'position' ).needsUpdate = true;
  26311. };
  26312. }();
  26313. /**
  26314. * @author mrdoob / http://mrdoob.com/
  26315. * @author Mugen87 / http://github.com/Mugen87
  26316. */
  26317. function BoxHelper( object, color ) {
  26318. this.object = object;
  26319. if ( color === undefined ) color = 0xffff00;
  26320. 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 ] );
  26321. var positions = new Float32Array( 8 * 3 );
  26322. var geometry = new BufferGeometry();
  26323. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  26324. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  26325. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26326. this.matrixAutoUpdate = false;
  26327. this.update();
  26328. }
  26329. BoxHelper.prototype = Object.create( LineSegments.prototype );
  26330. BoxHelper.prototype.constructor = BoxHelper;
  26331. BoxHelper.prototype.update = ( function () {
  26332. var box = new Box3();
  26333. return function update( object ) {
  26334. if ( object !== undefined ) {
  26335. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  26336. }
  26337. if ( this.object !== undefined ) {
  26338. box.setFromObject( this.object );
  26339. }
  26340. if ( box.isEmpty() ) return;
  26341. var min = box.min;
  26342. var max = box.max;
  26343. /*
  26344. 5____4
  26345. 1/___0/|
  26346. | 6__|_7
  26347. 2/___3/
  26348. 0: max.x, max.y, max.z
  26349. 1: min.x, max.y, max.z
  26350. 2: min.x, min.y, max.z
  26351. 3: max.x, min.y, max.z
  26352. 4: max.x, max.y, min.z
  26353. 5: min.x, max.y, min.z
  26354. 6: min.x, min.y, min.z
  26355. 7: max.x, min.y, min.z
  26356. */
  26357. var position = this.geometry.attributes.position;
  26358. var array = position.array;
  26359. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  26360. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  26361. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  26362. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  26363. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  26364. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  26365. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  26366. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  26367. position.needsUpdate = true;
  26368. this.geometry.computeBoundingSphere();
  26369. };
  26370. } )();
  26371. BoxHelper.prototype.setFromObject = function ( object ) {
  26372. this.object = object;
  26373. this.update();
  26374. return this;
  26375. };
  26376. /**
  26377. * @author WestLangley / http://github.com/WestLangley
  26378. */
  26379. function Box3Helper( box, hex ) {
  26380. this.type = 'Box3Helper';
  26381. this.box = box;
  26382. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26383. 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 ] );
  26384. var positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];
  26385. var geometry = new BufferGeometry();
  26386. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  26387. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26388. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26389. this.geometry.computeBoundingSphere();
  26390. }
  26391. Box3Helper.prototype = Object.create( LineSegments.prototype );
  26392. Box3Helper.prototype.constructor = Box3Helper;
  26393. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  26394. var box = this.box;
  26395. if ( box.isEmpty() ) return;
  26396. box.getCenter( this.position );
  26397. box.getSize( this.scale );
  26398. this.scale.multiplyScalar( 0.5 );
  26399. Object3D.prototype.updateMatrixWorld.call( this, force );
  26400. };
  26401. /**
  26402. * @author WestLangley / http://github.com/WestLangley
  26403. */
  26404. function PlaneHelper( plane, size, hex ) {
  26405. this.type = 'PlaneHelper';
  26406. this.plane = plane;
  26407. this.size = ( size === undefined ) ? 1 : size;
  26408. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26409. var positions = [ 1, - 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 ];
  26410. var geometry = new BufferGeometry();
  26411. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26412. geometry.computeBoundingSphere();
  26413. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26414. //
  26415. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  26416. var geometry2 = new BufferGeometry();
  26417. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  26418. geometry2.computeBoundingSphere();
  26419. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  26420. }
  26421. PlaneHelper.prototype = Object.create( Line.prototype );
  26422. PlaneHelper.prototype.constructor = PlaneHelper;
  26423. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  26424. var scale = - this.plane.constant;
  26425. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  26426. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  26427. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  26428. this.lookAt( this.plane.normal );
  26429. Object3D.prototype.updateMatrixWorld.call( this, force );
  26430. };
  26431. /**
  26432. * @author WestLangley / http://github.com/WestLangley
  26433. * @author zz85 / http://github.com/zz85
  26434. * @author bhouston / http://clara.io
  26435. *
  26436. * Creates an arrow for visualizing directions
  26437. *
  26438. * Parameters:
  26439. * dir - Vector3
  26440. * origin - Vector3
  26441. * length - Number
  26442. * color - color in hex value
  26443. * headLength - Number
  26444. * headWidth - Number
  26445. */
  26446. var lineGeometry;
  26447. var coneGeometry;
  26448. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  26449. // dir is assumed to be normalized
  26450. Object3D.call( this );
  26451. if ( color === undefined ) color = 0xffff00;
  26452. if ( length === undefined ) length = 1;
  26453. if ( headLength === undefined ) headLength = 0.2 * length;
  26454. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  26455. if ( lineGeometry === undefined ) {
  26456. lineGeometry = new BufferGeometry();
  26457. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  26458. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  26459. coneGeometry.translate( 0, - 0.5, 0 );
  26460. }
  26461. this.position.copy( origin );
  26462. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  26463. this.line.matrixAutoUpdate = false;
  26464. this.add( this.line );
  26465. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  26466. this.cone.matrixAutoUpdate = false;
  26467. this.add( this.cone );
  26468. this.setDirection( dir );
  26469. this.setLength( length, headLength, headWidth );
  26470. }
  26471. ArrowHelper.prototype = Object.create( Object3D.prototype );
  26472. ArrowHelper.prototype.constructor = ArrowHelper;
  26473. ArrowHelper.prototype.setDirection = ( function () {
  26474. var axis = new Vector3();
  26475. var radians;
  26476. return function setDirection( dir ) {
  26477. // dir is assumed to be normalized
  26478. if ( dir.y > 0.99999 ) {
  26479. this.quaternion.set( 0, 0, 0, 1 );
  26480. } else if ( dir.y < - 0.99999 ) {
  26481. this.quaternion.set( 1, 0, 0, 0 );
  26482. } else {
  26483. axis.set( dir.z, 0, - dir.x ).normalize();
  26484. radians = Math.acos( dir.y );
  26485. this.quaternion.setFromAxisAngle( axis, radians );
  26486. }
  26487. };
  26488. }() );
  26489. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  26490. if ( headLength === undefined ) headLength = 0.2 * length;
  26491. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  26492. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  26493. this.line.updateMatrix();
  26494. this.cone.scale.set( headWidth, headLength, headWidth );
  26495. this.cone.position.y = length;
  26496. this.cone.updateMatrix();
  26497. };
  26498. ArrowHelper.prototype.setColor = function ( color ) {
  26499. this.line.material.color.copy( color );
  26500. this.cone.material.color.copy( color );
  26501. };
  26502. /**
  26503. * @author sroucheray / http://sroucheray.org/
  26504. * @author mrdoob / http://mrdoob.com/
  26505. */
  26506. function AxesHelper( size ) {
  26507. size = size || 1;
  26508. var vertices = [
  26509. 0, 0, 0, size, 0, 0,
  26510. 0, 0, 0, 0, size, 0,
  26511. 0, 0, 0, 0, 0, size
  26512. ];
  26513. var colors = [
  26514. 1, 0, 0, 1, 0.6, 0,
  26515. 0, 1, 0, 0.6, 1, 0,
  26516. 0, 0, 1, 0, 0.6, 1
  26517. ];
  26518. var geometry = new BufferGeometry();
  26519. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26520. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26521. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26522. LineSegments.call( this, geometry, material );
  26523. }
  26524. AxesHelper.prototype = Object.create( LineSegments.prototype );
  26525. AxesHelper.prototype.constructor = AxesHelper;
  26526. /**
  26527. * @author mrdoob / http://mrdoob.com/
  26528. */
  26529. function Face4( a, b, c, d, normal, color, materialIndex ) {
  26530. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  26531. return new Face3( a, b, c, normal, color, materialIndex );
  26532. }
  26533. var LineStrip = 0;
  26534. var LinePieces = 1;
  26535. function MeshFaceMaterial( materials ) {
  26536. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  26537. return materials;
  26538. }
  26539. function MultiMaterial( materials ) {
  26540. if ( materials === undefined ) materials = [];
  26541. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  26542. materials.isMultiMaterial = true;
  26543. materials.materials = materials;
  26544. materials.clone = function () {
  26545. return materials.slice();
  26546. };
  26547. return materials;
  26548. }
  26549. function PointCloud( geometry, material ) {
  26550. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  26551. return new Points( geometry, material );
  26552. }
  26553. function Particle( material ) {
  26554. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  26555. return new Sprite( material );
  26556. }
  26557. function ParticleSystem( geometry, material ) {
  26558. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  26559. return new Points( geometry, material );
  26560. }
  26561. function PointCloudMaterial( parameters ) {
  26562. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  26563. return new PointsMaterial( parameters );
  26564. }
  26565. function ParticleBasicMaterial( parameters ) {
  26566. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  26567. return new PointsMaterial( parameters );
  26568. }
  26569. function ParticleSystemMaterial( parameters ) {
  26570. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  26571. return new PointsMaterial( parameters );
  26572. }
  26573. function Vertex( x, y, z ) {
  26574. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  26575. return new Vector3( x, y, z );
  26576. }
  26577. //
  26578. function DynamicBufferAttribute( array, itemSize ) {
  26579. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  26580. return new BufferAttribute( array, itemSize ).setDynamic( true );
  26581. }
  26582. function Int8Attribute( array, itemSize ) {
  26583. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  26584. return new Int8BufferAttribute( array, itemSize );
  26585. }
  26586. function Uint8Attribute( array, itemSize ) {
  26587. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  26588. return new Uint8BufferAttribute( array, itemSize );
  26589. }
  26590. function Uint8ClampedAttribute( array, itemSize ) {
  26591. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  26592. return new Uint8ClampedBufferAttribute( array, itemSize );
  26593. }
  26594. function Int16Attribute( array, itemSize ) {
  26595. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  26596. return new Int16BufferAttribute( array, itemSize );
  26597. }
  26598. function Uint16Attribute( array, itemSize ) {
  26599. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  26600. return new Uint16BufferAttribute( array, itemSize );
  26601. }
  26602. function Int32Attribute( array, itemSize ) {
  26603. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  26604. return new Int32BufferAttribute( array, itemSize );
  26605. }
  26606. function Uint32Attribute( array, itemSize ) {
  26607. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  26608. return new Uint32BufferAttribute( array, itemSize );
  26609. }
  26610. function Float32Attribute( array, itemSize ) {
  26611. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  26612. return new Float32BufferAttribute( array, itemSize );
  26613. }
  26614. function Float64Attribute( array, itemSize ) {
  26615. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  26616. return new Float64BufferAttribute( array, itemSize );
  26617. }
  26618. //
  26619. Curve.create = function ( construct, getPoint ) {
  26620. console.log( 'THREE.Curve.create() has been deprecated' );
  26621. construct.prototype = Object.create( Curve.prototype );
  26622. construct.prototype.constructor = construct;
  26623. construct.prototype.getPoint = getPoint;
  26624. return construct;
  26625. };
  26626. //
  26627. Object.assign( CurvePath.prototype, {
  26628. createPointsGeometry: function ( divisions ) {
  26629. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26630. // generate geometry from path points (for Line or Points objects)
  26631. var pts = this.getPoints( divisions );
  26632. return this.createGeometry( pts );
  26633. },
  26634. createSpacedPointsGeometry: function ( divisions ) {
  26635. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26636. // generate geometry from equidistant sampling along the path
  26637. var pts = this.getSpacedPoints( divisions );
  26638. return this.createGeometry( pts );
  26639. },
  26640. createGeometry: function ( points ) {
  26641. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26642. var geometry = new Geometry();
  26643. for ( var i = 0, l = points.length; i < l; i ++ ) {
  26644. var point = points[ i ];
  26645. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  26646. }
  26647. return geometry;
  26648. }
  26649. } );
  26650. //
  26651. Object.assign( Path.prototype, {
  26652. fromPoints: function ( points ) {
  26653. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  26654. this.setFromPoints( points );
  26655. }
  26656. } );
  26657. //
  26658. function ClosedSplineCurve3( points ) {
  26659. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26660. CatmullRomCurve3.call( this, points );
  26661. this.type = 'catmullrom';
  26662. this.closed = true;
  26663. }
  26664. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26665. //
  26666. function SplineCurve3( points ) {
  26667. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26668. CatmullRomCurve3.call( this, points );
  26669. this.type = 'catmullrom';
  26670. }
  26671. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26672. //
  26673. function Spline( points ) {
  26674. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  26675. CatmullRomCurve3.call( this, points );
  26676. this.type = 'catmullrom';
  26677. }
  26678. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  26679. Object.assign( Spline.prototype, {
  26680. initFromArray: function ( /* a */ ) {
  26681. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  26682. },
  26683. getControlPointsArray: function ( /* optionalTarget */ ) {
  26684. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  26685. },
  26686. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  26687. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  26688. }
  26689. } );
  26690. //
  26691. function AxisHelper( size ) {
  26692. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  26693. return new AxesHelper( size );
  26694. }
  26695. function BoundingBoxHelper( object, color ) {
  26696. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  26697. return new BoxHelper( object, color );
  26698. }
  26699. function EdgesHelper( object, hex ) {
  26700. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  26701. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26702. }
  26703. GridHelper.prototype.setColors = function () {
  26704. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  26705. };
  26706. SkeletonHelper.prototype.update = function () {
  26707. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  26708. };
  26709. function WireframeHelper( object, hex ) {
  26710. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  26711. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26712. }
  26713. //
  26714. Object.assign( Loader.prototype, {
  26715. extractUrlBase: function ( url ) {
  26716. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  26717. return LoaderUtils.extractUrlBase( url );
  26718. }
  26719. } );
  26720. function XHRLoader( manager ) {
  26721. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  26722. return new FileLoader( manager );
  26723. }
  26724. function BinaryTextureLoader( manager ) {
  26725. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  26726. return new DataTextureLoader( manager );
  26727. }
  26728. //
  26729. Object.assign( Box2.prototype, {
  26730. center: function ( optionalTarget ) {
  26731. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  26732. return this.getCenter( optionalTarget );
  26733. },
  26734. empty: function () {
  26735. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  26736. return this.isEmpty();
  26737. },
  26738. isIntersectionBox: function ( box ) {
  26739. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26740. return this.intersectsBox( box );
  26741. },
  26742. size: function ( optionalTarget ) {
  26743. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  26744. return this.getSize( optionalTarget );
  26745. }
  26746. } );
  26747. Object.assign( Box3.prototype, {
  26748. center: function ( optionalTarget ) {
  26749. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  26750. return this.getCenter( optionalTarget );
  26751. },
  26752. empty: function () {
  26753. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  26754. return this.isEmpty();
  26755. },
  26756. isIntersectionBox: function ( box ) {
  26757. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26758. return this.intersectsBox( box );
  26759. },
  26760. isIntersectionSphere: function ( sphere ) {
  26761. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26762. return this.intersectsSphere( sphere );
  26763. },
  26764. size: function ( optionalTarget ) {
  26765. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  26766. return this.getSize( optionalTarget );
  26767. }
  26768. } );
  26769. Line3.prototype.center = function ( optionalTarget ) {
  26770. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  26771. return this.getCenter( optionalTarget );
  26772. };
  26773. Object.assign( _Math, {
  26774. random16: function () {
  26775. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  26776. return Math.random();
  26777. },
  26778. nearestPowerOfTwo: function ( value ) {
  26779. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  26780. return _Math.floorPowerOfTwo( value );
  26781. },
  26782. nextPowerOfTwo: function ( value ) {
  26783. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  26784. return _Math.ceilPowerOfTwo( value );
  26785. }
  26786. } );
  26787. Object.assign( Matrix3.prototype, {
  26788. flattenToArrayOffset: function ( array, offset ) {
  26789. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26790. return this.toArray( array, offset );
  26791. },
  26792. multiplyVector3: function ( vector ) {
  26793. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  26794. return vector.applyMatrix3( this );
  26795. },
  26796. multiplyVector3Array: function ( /* a */ ) {
  26797. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  26798. },
  26799. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26800. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26801. return this.applyToBufferAttribute( buffer );
  26802. },
  26803. applyToVector3Array: function ( /* array, offset, length */ ) {
  26804. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  26805. }
  26806. } );
  26807. Object.assign( Matrix4.prototype, {
  26808. extractPosition: function ( m ) {
  26809. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  26810. return this.copyPosition( m );
  26811. },
  26812. flattenToArrayOffset: function ( array, offset ) {
  26813. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26814. return this.toArray( array, offset );
  26815. },
  26816. getPosition: function () {
  26817. var v1;
  26818. return function getPosition() {
  26819. if ( v1 === undefined ) v1 = new Vector3();
  26820. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  26821. return v1.setFromMatrixColumn( this, 3 );
  26822. };
  26823. }(),
  26824. setRotationFromQuaternion: function ( q ) {
  26825. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  26826. return this.makeRotationFromQuaternion( q );
  26827. },
  26828. multiplyToArray: function () {
  26829. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  26830. },
  26831. multiplyVector3: function ( vector ) {
  26832. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26833. return vector.applyMatrix4( this );
  26834. },
  26835. multiplyVector4: function ( vector ) {
  26836. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26837. return vector.applyMatrix4( this );
  26838. },
  26839. multiplyVector3Array: function ( /* a */ ) {
  26840. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  26841. },
  26842. rotateAxis: function ( v ) {
  26843. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  26844. v.transformDirection( this );
  26845. },
  26846. crossVector: function ( vector ) {
  26847. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26848. return vector.applyMatrix4( this );
  26849. },
  26850. translate: function () {
  26851. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  26852. },
  26853. rotateX: function () {
  26854. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  26855. },
  26856. rotateY: function () {
  26857. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  26858. },
  26859. rotateZ: function () {
  26860. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  26861. },
  26862. rotateByAxis: function () {
  26863. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  26864. },
  26865. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26866. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26867. return this.applyToBufferAttribute( buffer );
  26868. },
  26869. applyToVector3Array: function ( /* array, offset, length */ ) {
  26870. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  26871. },
  26872. makeFrustum: function ( left, right, bottom, top, near, far ) {
  26873. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  26874. return this.makePerspective( left, right, top, bottom, near, far );
  26875. }
  26876. } );
  26877. Plane.prototype.isIntersectionLine = function ( line ) {
  26878. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  26879. return this.intersectsLine( line );
  26880. };
  26881. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  26882. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  26883. return vector.applyQuaternion( this );
  26884. };
  26885. Object.assign( Ray.prototype, {
  26886. isIntersectionBox: function ( box ) {
  26887. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26888. return this.intersectsBox( box );
  26889. },
  26890. isIntersectionPlane: function ( plane ) {
  26891. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  26892. return this.intersectsPlane( plane );
  26893. },
  26894. isIntersectionSphere: function ( sphere ) {
  26895. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26896. return this.intersectsSphere( sphere );
  26897. }
  26898. } );
  26899. Object.assign( Triangle.prototype, {
  26900. area: function () {
  26901. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  26902. return this.getArea();
  26903. },
  26904. barycoordFromPoint: function ( point, target ) {
  26905. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  26906. return this.getBarycoord( point, target );
  26907. },
  26908. midpoint: function ( target ) {
  26909. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  26910. return this.getMidpoint( target );
  26911. },
  26912. normal: function ( target ) {
  26913. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  26914. return this.getNormal( target );
  26915. },
  26916. plane: function ( target ) {
  26917. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  26918. return this.getPlane( target );
  26919. }
  26920. } );
  26921. Object.assign( Triangle, {
  26922. barycoordFromPoint: function ( point, a, b, c, target ) {
  26923. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  26924. return Triangle.getBarycoord( point, a, b, c, target );
  26925. },
  26926. normal: function ( a, b, c, target ) {
  26927. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  26928. return Triangle.getNormal( a, b, c, target );
  26929. }
  26930. } );
  26931. Object.assign( Shape.prototype, {
  26932. extractAllPoints: function ( divisions ) {
  26933. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  26934. return this.extractPoints( divisions );
  26935. },
  26936. extrude: function ( options ) {
  26937. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  26938. return new ExtrudeGeometry( this, options );
  26939. },
  26940. makeGeometry: function ( options ) {
  26941. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  26942. return new ShapeGeometry( this, options );
  26943. }
  26944. } );
  26945. Object.assign( Vector2.prototype, {
  26946. fromAttribute: function ( attribute, index, offset ) {
  26947. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26948. return this.fromBufferAttribute( attribute, index, offset );
  26949. },
  26950. distanceToManhattan: function ( v ) {
  26951. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26952. return this.manhattanDistanceTo( v );
  26953. },
  26954. lengthManhattan: function () {
  26955. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  26956. return this.manhattanLength();
  26957. }
  26958. } );
  26959. Object.assign( Vector3.prototype, {
  26960. setEulerFromRotationMatrix: function () {
  26961. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  26962. },
  26963. setEulerFromQuaternion: function () {
  26964. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  26965. },
  26966. getPositionFromMatrix: function ( m ) {
  26967. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  26968. return this.setFromMatrixPosition( m );
  26969. },
  26970. getScaleFromMatrix: function ( m ) {
  26971. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  26972. return this.setFromMatrixScale( m );
  26973. },
  26974. getColumnFromMatrix: function ( index, matrix ) {
  26975. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  26976. return this.setFromMatrixColumn( matrix, index );
  26977. },
  26978. applyProjection: function ( m ) {
  26979. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  26980. return this.applyMatrix4( m );
  26981. },
  26982. fromAttribute: function ( attribute, index, offset ) {
  26983. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26984. return this.fromBufferAttribute( attribute, index, offset );
  26985. },
  26986. distanceToManhattan: function ( v ) {
  26987. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26988. return this.manhattanDistanceTo( v );
  26989. },
  26990. lengthManhattan: function () {
  26991. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  26992. return this.manhattanLength();
  26993. }
  26994. } );
  26995. Object.assign( Vector4.prototype, {
  26996. fromAttribute: function ( attribute, index, offset ) {
  26997. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26998. return this.fromBufferAttribute( attribute, index, offset );
  26999. },
  27000. lengthManhattan: function () {
  27001. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  27002. return this.manhattanLength();
  27003. }
  27004. } );
  27005. //
  27006. Object.assign( Geometry.prototype, {
  27007. computeTangents: function () {
  27008. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  27009. },
  27010. computeLineDistances: function () {
  27011. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  27012. }
  27013. } );
  27014. Object.assign( Object3D.prototype, {
  27015. getChildByName: function ( name ) {
  27016. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  27017. return this.getObjectByName( name );
  27018. },
  27019. renderDepth: function () {
  27020. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  27021. },
  27022. translate: function ( distance, axis ) {
  27023. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  27024. return this.translateOnAxis( axis, distance );
  27025. },
  27026. getWorldRotation: function () {
  27027. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  27028. }
  27029. } );
  27030. Object.defineProperties( Object3D.prototype, {
  27031. eulerOrder: {
  27032. get: function () {
  27033. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27034. return this.rotation.order;
  27035. },
  27036. set: function ( value ) {
  27037. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27038. this.rotation.order = value;
  27039. }
  27040. },
  27041. useQuaternion: {
  27042. get: function () {
  27043. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27044. },
  27045. set: function () {
  27046. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27047. }
  27048. }
  27049. } );
  27050. Object.defineProperties( LOD.prototype, {
  27051. objects: {
  27052. get: function () {
  27053. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  27054. return this.levels;
  27055. }
  27056. }
  27057. } );
  27058. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  27059. get: function () {
  27060. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27061. },
  27062. set: function () {
  27063. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27064. }
  27065. } );
  27066. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  27067. get: function () {
  27068. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  27069. return this.arcLengthDivisions;
  27070. },
  27071. set: function ( value ) {
  27072. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  27073. this.arcLengthDivisions = value;
  27074. }
  27075. } );
  27076. //
  27077. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  27078. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  27079. "Use .setFocalLength and .filmGauge for a photographic setup." );
  27080. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  27081. this.setFocalLength( focalLength );
  27082. };
  27083. //
  27084. Object.defineProperties( Light.prototype, {
  27085. onlyShadow: {
  27086. set: function () {
  27087. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  27088. }
  27089. },
  27090. shadowCameraFov: {
  27091. set: function ( value ) {
  27092. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  27093. this.shadow.camera.fov = value;
  27094. }
  27095. },
  27096. shadowCameraLeft: {
  27097. set: function ( value ) {
  27098. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  27099. this.shadow.camera.left = value;
  27100. }
  27101. },
  27102. shadowCameraRight: {
  27103. set: function ( value ) {
  27104. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  27105. this.shadow.camera.right = value;
  27106. }
  27107. },
  27108. shadowCameraTop: {
  27109. set: function ( value ) {
  27110. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  27111. this.shadow.camera.top = value;
  27112. }
  27113. },
  27114. shadowCameraBottom: {
  27115. set: function ( value ) {
  27116. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  27117. this.shadow.camera.bottom = value;
  27118. }
  27119. },
  27120. shadowCameraNear: {
  27121. set: function ( value ) {
  27122. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  27123. this.shadow.camera.near = value;
  27124. }
  27125. },
  27126. shadowCameraFar: {
  27127. set: function ( value ) {
  27128. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  27129. this.shadow.camera.far = value;
  27130. }
  27131. },
  27132. shadowCameraVisible: {
  27133. set: function () {
  27134. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  27135. }
  27136. },
  27137. shadowBias: {
  27138. set: function ( value ) {
  27139. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  27140. this.shadow.bias = value;
  27141. }
  27142. },
  27143. shadowDarkness: {
  27144. set: function () {
  27145. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  27146. }
  27147. },
  27148. shadowMapWidth: {
  27149. set: function ( value ) {
  27150. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  27151. this.shadow.mapSize.width = value;
  27152. }
  27153. },
  27154. shadowMapHeight: {
  27155. set: function ( value ) {
  27156. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  27157. this.shadow.mapSize.height = value;
  27158. }
  27159. }
  27160. } );
  27161. //
  27162. Object.defineProperties( BufferAttribute.prototype, {
  27163. length: {
  27164. get: function () {
  27165. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  27166. return this.array.length;
  27167. }
  27168. },
  27169. copyIndicesArray: function ( /* indices */ ) {
  27170. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  27171. }
  27172. } );
  27173. Object.assign( BufferGeometry.prototype, {
  27174. addIndex: function ( index ) {
  27175. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  27176. this.setIndex( index );
  27177. },
  27178. addDrawCall: function ( start, count, indexOffset ) {
  27179. if ( indexOffset !== undefined ) {
  27180. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  27181. }
  27182. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  27183. this.addGroup( start, count );
  27184. },
  27185. clearDrawCalls: function () {
  27186. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  27187. this.clearGroups();
  27188. },
  27189. computeTangents: function () {
  27190. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  27191. },
  27192. computeOffsets: function () {
  27193. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  27194. }
  27195. } );
  27196. Object.defineProperties( BufferGeometry.prototype, {
  27197. drawcalls: {
  27198. get: function () {
  27199. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  27200. return this.groups;
  27201. }
  27202. },
  27203. offsets: {
  27204. get: function () {
  27205. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  27206. return this.groups;
  27207. }
  27208. }
  27209. } );
  27210. //
  27211. Object.assign( ExtrudeBufferGeometry.prototype, {
  27212. getArrays: function () {
  27213. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  27214. },
  27215. addShapeList: function () {
  27216. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  27217. },
  27218. addShape: function () {
  27219. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  27220. }
  27221. } );
  27222. //
  27223. Object.defineProperties( Uniform.prototype, {
  27224. dynamic: {
  27225. set: function () {
  27226. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  27227. }
  27228. },
  27229. onUpdate: {
  27230. value: function () {
  27231. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  27232. return this;
  27233. }
  27234. }
  27235. } );
  27236. //
  27237. Object.defineProperties( Material.prototype, {
  27238. wrapAround: {
  27239. get: function () {
  27240. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  27241. },
  27242. set: function () {
  27243. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  27244. }
  27245. },
  27246. wrapRGB: {
  27247. get: function () {
  27248. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  27249. return new Color();
  27250. }
  27251. },
  27252. shading: {
  27253. get: function () {
  27254. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  27255. },
  27256. set: function ( value ) {
  27257. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  27258. this.flatShading = ( value === FlatShading );
  27259. }
  27260. }
  27261. } );
  27262. Object.defineProperties( MeshPhongMaterial.prototype, {
  27263. metal: {
  27264. get: function () {
  27265. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  27266. return false;
  27267. },
  27268. set: function () {
  27269. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  27270. }
  27271. }
  27272. } );
  27273. Object.defineProperties( ShaderMaterial.prototype, {
  27274. derivatives: {
  27275. get: function () {
  27276. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  27277. return this.extensions.derivatives;
  27278. },
  27279. set: function ( value ) {
  27280. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  27281. this.extensions.derivatives = value;
  27282. }
  27283. }
  27284. } );
  27285. //
  27286. Object.assign( WebGLRenderer.prototype, {
  27287. animate: function ( callback ) {
  27288. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  27289. this.setAnimationLoop( callback );
  27290. },
  27291. getCurrentRenderTarget: function () {
  27292. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  27293. return this.getRenderTarget();
  27294. },
  27295. getMaxAnisotropy: function () {
  27296. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  27297. return this.capabilities.getMaxAnisotropy();
  27298. },
  27299. getPrecision: function () {
  27300. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  27301. return this.capabilities.precision;
  27302. },
  27303. resetGLState: function () {
  27304. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  27305. return this.state.reset();
  27306. },
  27307. supportsFloatTextures: function () {
  27308. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  27309. return this.extensions.get( 'OES_texture_float' );
  27310. },
  27311. supportsHalfFloatTextures: function () {
  27312. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  27313. return this.extensions.get( 'OES_texture_half_float' );
  27314. },
  27315. supportsStandardDerivatives: function () {
  27316. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  27317. return this.extensions.get( 'OES_standard_derivatives' );
  27318. },
  27319. supportsCompressedTextureS3TC: function () {
  27320. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  27321. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  27322. },
  27323. supportsCompressedTexturePVRTC: function () {
  27324. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  27325. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  27326. },
  27327. supportsBlendMinMax: function () {
  27328. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  27329. return this.extensions.get( 'EXT_blend_minmax' );
  27330. },
  27331. supportsVertexTextures: function () {
  27332. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  27333. return this.capabilities.vertexTextures;
  27334. },
  27335. supportsInstancedArrays: function () {
  27336. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  27337. return this.extensions.get( 'ANGLE_instanced_arrays' );
  27338. },
  27339. enableScissorTest: function ( boolean ) {
  27340. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  27341. this.setScissorTest( boolean );
  27342. },
  27343. initMaterial: function () {
  27344. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  27345. },
  27346. addPrePlugin: function () {
  27347. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  27348. },
  27349. addPostPlugin: function () {
  27350. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  27351. },
  27352. updateShadowMap: function () {
  27353. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  27354. },
  27355. setFaceCulling: function () {
  27356. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  27357. }
  27358. } );
  27359. Object.defineProperties( WebGLRenderer.prototype, {
  27360. shadowMapEnabled: {
  27361. get: function () {
  27362. return this.shadowMap.enabled;
  27363. },
  27364. set: function ( value ) {
  27365. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  27366. this.shadowMap.enabled = value;
  27367. }
  27368. },
  27369. shadowMapType: {
  27370. get: function () {
  27371. return this.shadowMap.type;
  27372. },
  27373. set: function ( value ) {
  27374. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  27375. this.shadowMap.type = value;
  27376. }
  27377. },
  27378. shadowMapCullFace: {
  27379. get: function () {
  27380. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  27381. return undefined;
  27382. },
  27383. set: function ( /* value */ ) {
  27384. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  27385. }
  27386. }
  27387. } );
  27388. Object.defineProperties( WebGLShadowMap.prototype, {
  27389. cullFace: {
  27390. get: function () {
  27391. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  27392. return undefined;
  27393. },
  27394. set: function ( /* cullFace */ ) {
  27395. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  27396. }
  27397. },
  27398. renderReverseSided: {
  27399. get: function () {
  27400. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  27401. return undefined;
  27402. },
  27403. set: function () {
  27404. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  27405. }
  27406. },
  27407. renderSingleSided: {
  27408. get: function () {
  27409. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  27410. return undefined;
  27411. },
  27412. set: function () {
  27413. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  27414. }
  27415. }
  27416. } );
  27417. //
  27418. Object.defineProperties( WebGLRenderTarget.prototype, {
  27419. wrapS: {
  27420. get: function () {
  27421. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  27422. return this.texture.wrapS;
  27423. },
  27424. set: function ( value ) {
  27425. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  27426. this.texture.wrapS = value;
  27427. }
  27428. },
  27429. wrapT: {
  27430. get: function () {
  27431. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  27432. return this.texture.wrapT;
  27433. },
  27434. set: function ( value ) {
  27435. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  27436. this.texture.wrapT = value;
  27437. }
  27438. },
  27439. magFilter: {
  27440. get: function () {
  27441. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  27442. return this.texture.magFilter;
  27443. },
  27444. set: function ( value ) {
  27445. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  27446. this.texture.magFilter = value;
  27447. }
  27448. },
  27449. minFilter: {
  27450. get: function () {
  27451. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  27452. return this.texture.minFilter;
  27453. },
  27454. set: function ( value ) {
  27455. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  27456. this.texture.minFilter = value;
  27457. }
  27458. },
  27459. anisotropy: {
  27460. get: function () {
  27461. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  27462. return this.texture.anisotropy;
  27463. },
  27464. set: function ( value ) {
  27465. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  27466. this.texture.anisotropy = value;
  27467. }
  27468. },
  27469. offset: {
  27470. get: function () {
  27471. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  27472. return this.texture.offset;
  27473. },
  27474. set: function ( value ) {
  27475. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  27476. this.texture.offset = value;
  27477. }
  27478. },
  27479. repeat: {
  27480. get: function () {
  27481. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  27482. return this.texture.repeat;
  27483. },
  27484. set: function ( value ) {
  27485. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  27486. this.texture.repeat = value;
  27487. }
  27488. },
  27489. format: {
  27490. get: function () {
  27491. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  27492. return this.texture.format;
  27493. },
  27494. set: function ( value ) {
  27495. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  27496. this.texture.format = value;
  27497. }
  27498. },
  27499. type: {
  27500. get: function () {
  27501. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  27502. return this.texture.type;
  27503. },
  27504. set: function ( value ) {
  27505. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  27506. this.texture.type = value;
  27507. }
  27508. },
  27509. generateMipmaps: {
  27510. get: function () {
  27511. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  27512. return this.texture.generateMipmaps;
  27513. },
  27514. set: function ( value ) {
  27515. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  27516. this.texture.generateMipmaps = value;
  27517. }
  27518. }
  27519. } );
  27520. //
  27521. Object.defineProperties( WebVRManager.prototype, {
  27522. standing: {
  27523. set: function ( /* value */ ) {
  27524. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  27525. }
  27526. }
  27527. } );
  27528. //
  27529. Audio.prototype.load = function ( file ) {
  27530. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  27531. var scope = this;
  27532. var audioLoader = new AudioLoader();
  27533. audioLoader.load( file, function ( buffer ) {
  27534. scope.setBuffer( buffer );
  27535. } );
  27536. return this;
  27537. };
  27538. AudioAnalyser.prototype.getData = function () {
  27539. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  27540. return this.getFrequencyData();
  27541. };
  27542. //
  27543. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  27544. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  27545. return this.update( renderer, scene );
  27546. };
  27547. //
  27548. var GeometryUtils = {
  27549. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  27550. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  27551. var matrix;
  27552. if ( geometry2.isMesh ) {
  27553. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  27554. matrix = geometry2.matrix;
  27555. geometry2 = geometry2.geometry;
  27556. }
  27557. geometry1.merge( geometry2, matrix, materialIndexOffset );
  27558. },
  27559. center: function ( geometry ) {
  27560. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  27561. return geometry.center();
  27562. }
  27563. };
  27564. var ImageUtils = {
  27565. crossOrigin: undefined,
  27566. loadTexture: function ( url, mapping, onLoad, onError ) {
  27567. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  27568. var loader = new TextureLoader();
  27569. loader.setCrossOrigin( this.crossOrigin );
  27570. var texture = loader.load( url, onLoad, undefined, onError );
  27571. if ( mapping ) texture.mapping = mapping;
  27572. return texture;
  27573. },
  27574. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  27575. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  27576. var loader = new CubeTextureLoader();
  27577. loader.setCrossOrigin( this.crossOrigin );
  27578. var texture = loader.load( urls, onLoad, undefined, onError );
  27579. if ( mapping ) texture.mapping = mapping;
  27580. return texture;
  27581. },
  27582. loadCompressedTexture: function () {
  27583. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  27584. },
  27585. loadCompressedTextureCube: function () {
  27586. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  27587. }
  27588. };
  27589. //
  27590. function Projector() {
  27591. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  27592. this.projectVector = function ( vector, camera ) {
  27593. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  27594. vector.project( camera );
  27595. };
  27596. this.unprojectVector = function ( vector, camera ) {
  27597. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  27598. vector.unproject( camera );
  27599. };
  27600. this.pickingRay = function () {
  27601. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  27602. };
  27603. }
  27604. //
  27605. function CanvasRenderer() {
  27606. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  27607. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  27608. this.clear = function () {};
  27609. this.render = function () {};
  27610. this.setClearColor = function () {};
  27611. this.setSize = function () {};
  27612. }
  27613. //
  27614. var SceneUtils = {
  27615. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  27616. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27617. },
  27618. detach: function ( /* child, parent, scene */ ) {
  27619. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27620. },
  27621. attach: function ( /* child, scene, parent */ ) {
  27622. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27623. }
  27624. };
  27625. //
  27626. function LensFlare() {
  27627. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  27628. }
  27629. export { WebGLRenderTargetCube, WebGLRenderTarget, WebGLRenderer, ShaderLib, UniformsLib, UniformsUtils, ShaderChunk, FogExp2, Fog, Scene, Sprite, LOD, SkinnedMesh, Skeleton, Bone, Mesh, LineSegments, LineLoop, Line, Points, Group, VideoTexture, DataTexture, CompressedTexture, CubeTexture, CanvasTexture, DepthTexture, Texture, CompressedTextureLoader, DataTextureLoader, CubeTextureLoader, TextureLoader, ObjectLoader, MaterialLoader, BufferGeometryLoader, DefaultLoadingManager, LoadingManager, JSONLoader, ImageLoader, ImageBitmapLoader, FontLoader, FileLoader, Loader, LoaderUtils, Cache, AudioLoader, SpotLightShadow, SpotLight, PointLight, RectAreaLight, HemisphereLight, DirectionalLightShadow, DirectionalLight, AmbientLight, LightShadow, Light, StereoCamera, PerspectiveCamera, OrthographicCamera, CubeCamera, ArrayCamera, Camera, AudioListener, PositionalAudio, AudioContext, AudioAnalyser, Audio, VectorKeyframeTrack, StringKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, ColorKeyframeTrack, BooleanKeyframeTrack, PropertyMixer, PropertyBinding, KeyframeTrack, AnimationUtils, AnimationObjectGroup, AnimationMixer, AnimationClip, Uniform, InstancedBufferGeometry, BufferGeometry, Geometry, InterleavedBufferAttribute, InstancedInterleavedBuffer, InterleavedBuffer, InstancedBufferAttribute, Face3, Object3D, Raycaster, Layers, EventDispatcher, Clock, QuaternionLinearInterpolant, LinearInterpolant, DiscreteInterpolant, CubicInterpolant, Interpolant, Triangle, _Math as Math, Spherical, Cylindrical, Plane, Frustum, Sphere, Ray, Matrix4, Matrix3, Box3, Box2, Line3, Euler, Vector4, Vector3, Vector2, Quaternion, Color, ImmediateRenderObject, VertexNormalsHelper, SpotLightHelper, SkeletonHelper, PointLightHelper, RectAreaLightHelper, HemisphereLightHelper, GridHelper, PolarGridHelper, FaceNormalsHelper, DirectionalLightHelper, CameraHelper, BoxHelper, Box3Helper, PlaneHelper, ArrowHelper, AxesHelper, Shape, Path, ShapePath, Font, CurvePath, Curve, ShapeUtils, WebGLUtils, WireframeGeometry, ParametricGeometry, ParametricBufferGeometry, TetrahedronGeometry, TetrahedronBufferGeometry, OctahedronGeometry, OctahedronBufferGeometry, IcosahedronGeometry, IcosahedronBufferGeometry, DodecahedronGeometry, DodecahedronBufferGeometry, PolyhedronGeometry, PolyhedronBufferGeometry, TubeGeometry, TubeBufferGeometry, TorusKnotGeometry, TorusKnotBufferGeometry, TorusGeometry, TorusBufferGeometry, TextGeometry, TextBufferGeometry, SphereGeometry, SphereBufferGeometry, RingGeometry, RingBufferGeometry, PlaneGeometry, PlaneBufferGeometry, LatheGeometry, LatheBufferGeometry, ShapeGeometry, ShapeBufferGeometry, ExtrudeGeometry, ExtrudeBufferGeometry, EdgesGeometry, ConeGeometry, ConeBufferGeometry, CylinderGeometry, CylinderBufferGeometry, CircleGeometry, CircleBufferGeometry, BoxGeometry, BoxBufferGeometry, ShadowMaterial, SpriteMaterial, RawShaderMaterial, ShaderMaterial, PointsMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshPhongMaterial, MeshToonMaterial, MeshNormalMaterial, MeshLambertMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshBasicMaterial, LineDashedMaterial, LineBasicMaterial, Material, Float64BufferAttribute, Float32BufferAttribute, Uint32BufferAttribute, Int32BufferAttribute, Uint16BufferAttribute, Int16BufferAttribute, Uint8ClampedBufferAttribute, Uint8BufferAttribute, Int8BufferAttribute, BufferAttribute, ArcCurve, CatmullRomCurve3, CubicBezierCurve, CubicBezierCurve3, EllipseCurve, LineCurve, LineCurve3, QuadraticBezierCurve, QuadraticBezierCurve3, SplineCurve, REVISION, MOUSE, CullFaceNone, CullFaceBack, CullFaceFront, CullFaceFrontBack, FrontFaceDirectionCW, FrontFaceDirectionCCW, BasicShadowMap, PCFShadowMap, PCFSoftShadowMap, FrontSide, BackSide, DoubleSide, FlatShading, SmoothShading, NoColors, FaceColors, VertexColors, NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor, NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth, MultiplyOperation, MixOperation, AddOperation, NoToneMapping, LinearToneMapping, ReinhardToneMapping, Uncharted2ToneMapping, CineonToneMapping, UVMapping, CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, SphericalReflectionMapping, CubeUVReflectionMapping, CubeUVRefractionMapping, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter, LinearFilter, LinearMipMapNearestFilter, LinearMipMapLinearFilter, UnsignedByteType, ByteType, ShortType, UnsignedShortType, IntType, UnsignedIntType, FloatType, HalfFloatType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedInt248Type, AlphaFormat, RGBFormat, RGBAFormat, LuminanceFormat, LuminanceAlphaFormat, RGBEFormat, DepthFormat, DepthStencilFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, LoopOnce, LoopRepeat, LoopPingPong, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, ZeroCurvatureEnding, ZeroSlopeEnding, WrapAroundEnding, TrianglesDrawMode, TriangleStripDrawMode, TriangleFanDrawMode, LinearEncoding, sRGBEncoding, GammaEncoding, RGBEEncoding, LogLuvEncoding, RGBM7Encoding, RGBM16Encoding, RGBDEncoding, BasicDepthPacking, RGBADepthPacking, BoxGeometry as CubeGeometry, Face4, LineStrip, LinePieces, MeshFaceMaterial, MultiMaterial, PointCloud, Particle, ParticleSystem, PointCloudMaterial, ParticleBasicMaterial, ParticleSystemMaterial, Vertex, DynamicBufferAttribute, Int8Attribute, Uint8Attribute, Uint8ClampedAttribute, Int16Attribute, Uint16Attribute, Int32Attribute, Uint32Attribute, Float32Attribute, Float64Attribute, ClosedSplineCurve3, SplineCurve3, Spline, AxisHelper, BoundingBoxHelper, EdgesHelper, WireframeHelper, XHRLoader, BinaryTextureLoader, GeometryUtils, ImageUtils, Projector, CanvasRenderer, SceneUtils, LensFlare };