three.module.js 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942
  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 = '102';
  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 ACESFilmicToneMapping = 5;
  153. var UVMapping = 300;
  154. var CubeReflectionMapping = 301;
  155. var CubeRefractionMapping = 302;
  156. var EquirectangularReflectionMapping = 303;
  157. var EquirectangularRefractionMapping = 304;
  158. var SphericalReflectionMapping = 305;
  159. var CubeUVReflectionMapping = 306;
  160. var CubeUVRefractionMapping = 307;
  161. var RepeatWrapping = 1000;
  162. var ClampToEdgeWrapping = 1001;
  163. var MirroredRepeatWrapping = 1002;
  164. var NearestFilter = 1003;
  165. var NearestMipMapNearestFilter = 1004;
  166. var NearestMipMapLinearFilter = 1005;
  167. var LinearFilter = 1006;
  168. var LinearMipMapNearestFilter = 1007;
  169. var LinearMipMapLinearFilter = 1008;
  170. var UnsignedByteType = 1009;
  171. var ByteType = 1010;
  172. var ShortType = 1011;
  173. var UnsignedShortType = 1012;
  174. var IntType = 1013;
  175. var UnsignedIntType = 1014;
  176. var FloatType = 1015;
  177. var HalfFloatType = 1016;
  178. var UnsignedShort4444Type = 1017;
  179. var UnsignedShort5551Type = 1018;
  180. var UnsignedShort565Type = 1019;
  181. var UnsignedInt248Type = 1020;
  182. var AlphaFormat = 1021;
  183. var RGBFormat = 1022;
  184. var RGBAFormat = 1023;
  185. var LuminanceFormat = 1024;
  186. var LuminanceAlphaFormat = 1025;
  187. var RGBEFormat = RGBAFormat;
  188. var DepthFormat = 1026;
  189. var DepthStencilFormat = 1027;
  190. var RedFormat = 1028;
  191. var RGB_S3TC_DXT1_Format = 33776;
  192. var RGBA_S3TC_DXT1_Format = 33777;
  193. var RGBA_S3TC_DXT3_Format = 33778;
  194. var RGBA_S3TC_DXT5_Format = 33779;
  195. var RGB_PVRTC_4BPPV1_Format = 35840;
  196. var RGB_PVRTC_2BPPV1_Format = 35841;
  197. var RGBA_PVRTC_4BPPV1_Format = 35842;
  198. var RGBA_PVRTC_2BPPV1_Format = 35843;
  199. var RGB_ETC1_Format = 36196;
  200. var RGBA_ASTC_4x4_Format = 37808;
  201. var RGBA_ASTC_5x4_Format = 37809;
  202. var RGBA_ASTC_5x5_Format = 37810;
  203. var RGBA_ASTC_6x5_Format = 37811;
  204. var RGBA_ASTC_6x6_Format = 37812;
  205. var RGBA_ASTC_8x5_Format = 37813;
  206. var RGBA_ASTC_8x6_Format = 37814;
  207. var RGBA_ASTC_8x8_Format = 37815;
  208. var RGBA_ASTC_10x5_Format = 37816;
  209. var RGBA_ASTC_10x6_Format = 37817;
  210. var RGBA_ASTC_10x8_Format = 37818;
  211. var RGBA_ASTC_10x10_Format = 37819;
  212. var RGBA_ASTC_12x10_Format = 37820;
  213. var RGBA_ASTC_12x12_Format = 37821;
  214. var LoopOnce = 2200;
  215. var LoopRepeat = 2201;
  216. var LoopPingPong = 2202;
  217. var InterpolateDiscrete = 2300;
  218. var InterpolateLinear = 2301;
  219. var InterpolateSmooth = 2302;
  220. var ZeroCurvatureEnding = 2400;
  221. var ZeroSlopeEnding = 2401;
  222. var WrapAroundEnding = 2402;
  223. var TrianglesDrawMode = 0;
  224. var TriangleStripDrawMode = 1;
  225. var TriangleFanDrawMode = 2;
  226. var LinearEncoding = 3000;
  227. var sRGBEncoding = 3001;
  228. var GammaEncoding = 3007;
  229. var RGBEEncoding = 3002;
  230. var LogLuvEncoding = 3003;
  231. var RGBM7Encoding = 3004;
  232. var RGBM16Encoding = 3005;
  233. var RGBDEncoding = 3006;
  234. var BasicDepthPacking = 3200;
  235. var RGBADepthPacking = 3201;
  236. var TangentSpaceNormalMap = 0;
  237. var ObjectSpaceNormalMap = 1;
  238. /**
  239. * @author alteredq / http://alteredqualia.com/
  240. * @author mrdoob / http://mrdoob.com/
  241. */
  242. var _Math = {
  243. DEG2RAD: Math.PI / 180,
  244. RAD2DEG: 180 / Math.PI,
  245. generateUUID: ( function () {
  246. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  247. var lut = [];
  248. for ( var i = 0; i < 256; i ++ ) {
  249. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  250. }
  251. return function generateUUID() {
  252. var d0 = Math.random() * 0xffffffff | 0;
  253. var d1 = Math.random() * 0xffffffff | 0;
  254. var d2 = Math.random() * 0xffffffff | 0;
  255. var d3 = Math.random() * 0xffffffff | 0;
  256. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  257. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  258. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  259. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  260. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  261. return uuid.toUpperCase();
  262. };
  263. } )(),
  264. clamp: function ( value, min, max ) {
  265. return Math.max( min, Math.min( max, value ) );
  266. },
  267. // compute euclidian modulo of m % n
  268. // https://en.wikipedia.org/wiki/Modulo_operation
  269. euclideanModulo: function ( n, m ) {
  270. return ( ( n % m ) + m ) % m;
  271. },
  272. // Linear mapping from range <a1, a2> to range <b1, b2>
  273. mapLinear: function ( x, a1, a2, b1, b2 ) {
  274. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  275. },
  276. // https://en.wikipedia.org/wiki/Linear_interpolation
  277. lerp: function ( x, y, t ) {
  278. return ( 1 - t ) * x + t * y;
  279. },
  280. // http://en.wikipedia.org/wiki/Smoothstep
  281. smoothstep: function ( x, min, max ) {
  282. if ( x <= min ) return 0;
  283. if ( x >= max ) return 1;
  284. x = ( x - min ) / ( max - min );
  285. return x * x * ( 3 - 2 * x );
  286. },
  287. smootherstep: function ( x, min, max ) {
  288. if ( x <= min ) return 0;
  289. if ( x >= max ) return 1;
  290. x = ( x - min ) / ( max - min );
  291. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  292. },
  293. // Random integer from <low, high> interval
  294. randInt: function ( low, high ) {
  295. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  296. },
  297. // Random float from <low, high> interval
  298. randFloat: function ( low, high ) {
  299. return low + Math.random() * ( high - low );
  300. },
  301. // Random float from <-range/2, range/2> interval
  302. randFloatSpread: function ( range ) {
  303. return range * ( 0.5 - Math.random() );
  304. },
  305. degToRad: function ( degrees ) {
  306. return degrees * _Math.DEG2RAD;
  307. },
  308. radToDeg: function ( radians ) {
  309. return radians * _Math.RAD2DEG;
  310. },
  311. isPowerOfTwo: function ( value ) {
  312. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  313. },
  314. ceilPowerOfTwo: function ( value ) {
  315. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  316. },
  317. floorPowerOfTwo: function ( value ) {
  318. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  319. }
  320. };
  321. /**
  322. * @author mrdoob / http://mrdoob.com/
  323. * @author philogb / http://blog.thejit.org/
  324. * @author egraether / http://egraether.com/
  325. * @author zz85 / http://www.lab4games.net/zz85/blog
  326. */
  327. function Vector2( x, y ) {
  328. this.x = x || 0;
  329. this.y = y || 0;
  330. }
  331. Object.defineProperties( Vector2.prototype, {
  332. "width": {
  333. get: function () {
  334. return this.x;
  335. },
  336. set: function ( value ) {
  337. this.x = value;
  338. }
  339. },
  340. "height": {
  341. get: function () {
  342. return this.y;
  343. },
  344. set: function ( value ) {
  345. this.y = value;
  346. }
  347. }
  348. } );
  349. Object.assign( Vector2.prototype, {
  350. isVector2: true,
  351. set: function ( x, y ) {
  352. this.x = x;
  353. this.y = y;
  354. return this;
  355. },
  356. setScalar: function ( scalar ) {
  357. this.x = scalar;
  358. this.y = scalar;
  359. return this;
  360. },
  361. setX: function ( x ) {
  362. this.x = x;
  363. return this;
  364. },
  365. setY: function ( y ) {
  366. this.y = y;
  367. return this;
  368. },
  369. setComponent: function ( index, value ) {
  370. switch ( index ) {
  371. case 0: this.x = value; break;
  372. case 1: this.y = value; break;
  373. default: throw new Error( 'index is out of range: ' + index );
  374. }
  375. return this;
  376. },
  377. getComponent: function ( index ) {
  378. switch ( index ) {
  379. case 0: return this.x;
  380. case 1: return this.y;
  381. default: throw new Error( 'index is out of range: ' + index );
  382. }
  383. },
  384. clone: function () {
  385. return new this.constructor( this.x, this.y );
  386. },
  387. copy: function ( v ) {
  388. this.x = v.x;
  389. this.y = v.y;
  390. return this;
  391. },
  392. add: function ( v, w ) {
  393. if ( w !== undefined ) {
  394. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  395. return this.addVectors( v, w );
  396. }
  397. this.x += v.x;
  398. this.y += v.y;
  399. return this;
  400. },
  401. addScalar: function ( s ) {
  402. this.x += s;
  403. this.y += s;
  404. return this;
  405. },
  406. addVectors: function ( a, b ) {
  407. this.x = a.x + b.x;
  408. this.y = a.y + b.y;
  409. return this;
  410. },
  411. addScaledVector: function ( v, s ) {
  412. this.x += v.x * s;
  413. this.y += v.y * s;
  414. return this;
  415. },
  416. sub: function ( v, w ) {
  417. if ( w !== undefined ) {
  418. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  419. return this.subVectors( v, w );
  420. }
  421. this.x -= v.x;
  422. this.y -= v.y;
  423. return this;
  424. },
  425. subScalar: function ( s ) {
  426. this.x -= s;
  427. this.y -= s;
  428. return this;
  429. },
  430. subVectors: function ( a, b ) {
  431. this.x = a.x - b.x;
  432. this.y = a.y - b.y;
  433. return this;
  434. },
  435. multiply: function ( v ) {
  436. this.x *= v.x;
  437. this.y *= v.y;
  438. return this;
  439. },
  440. multiplyScalar: function ( scalar ) {
  441. this.x *= scalar;
  442. this.y *= scalar;
  443. return this;
  444. },
  445. divide: function ( v ) {
  446. this.x /= v.x;
  447. this.y /= v.y;
  448. return this;
  449. },
  450. divideScalar: function ( scalar ) {
  451. return this.multiplyScalar( 1 / scalar );
  452. },
  453. applyMatrix3: function ( m ) {
  454. var x = this.x, y = this.y;
  455. var e = m.elements;
  456. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  457. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  458. return this;
  459. },
  460. min: function ( v ) {
  461. this.x = Math.min( this.x, v.x );
  462. this.y = Math.min( this.y, v.y );
  463. return this;
  464. },
  465. max: function ( v ) {
  466. this.x = Math.max( this.x, v.x );
  467. this.y = Math.max( this.y, v.y );
  468. return this;
  469. },
  470. clamp: function ( min, max ) {
  471. // assumes min < max, componentwise
  472. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  473. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  474. return this;
  475. },
  476. clampScalar: function () {
  477. var min = new Vector2();
  478. var max = new Vector2();
  479. return function clampScalar( minVal, maxVal ) {
  480. min.set( minVal, minVal );
  481. max.set( maxVal, maxVal );
  482. return this.clamp( min, max );
  483. };
  484. }(),
  485. clampLength: function ( min, max ) {
  486. var length = this.length();
  487. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  488. },
  489. floor: function () {
  490. this.x = Math.floor( this.x );
  491. this.y = Math.floor( this.y );
  492. return this;
  493. },
  494. ceil: function () {
  495. this.x = Math.ceil( this.x );
  496. this.y = Math.ceil( this.y );
  497. return this;
  498. },
  499. round: function () {
  500. this.x = Math.round( this.x );
  501. this.y = Math.round( this.y );
  502. return this;
  503. },
  504. roundToZero: function () {
  505. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  506. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  507. return this;
  508. },
  509. negate: function () {
  510. this.x = - this.x;
  511. this.y = - this.y;
  512. return this;
  513. },
  514. dot: function ( v ) {
  515. return this.x * v.x + this.y * v.y;
  516. },
  517. cross: function ( v ) {
  518. return this.x * v.y - this.y * v.x;
  519. },
  520. lengthSq: function () {
  521. return this.x * this.x + this.y * this.y;
  522. },
  523. length: function () {
  524. return Math.sqrt( this.x * this.x + this.y * this.y );
  525. },
  526. manhattanLength: function () {
  527. return Math.abs( this.x ) + Math.abs( this.y );
  528. },
  529. normalize: function () {
  530. return this.divideScalar( this.length() || 1 );
  531. },
  532. angle: function () {
  533. // computes the angle in radians with respect to the positive x-axis
  534. var angle = Math.atan2( this.y, this.x );
  535. if ( angle < 0 ) angle += 2 * Math.PI;
  536. return angle;
  537. },
  538. distanceTo: function ( v ) {
  539. return Math.sqrt( this.distanceToSquared( v ) );
  540. },
  541. distanceToSquared: function ( v ) {
  542. var dx = this.x - v.x, dy = this.y - v.y;
  543. return dx * dx + dy * dy;
  544. },
  545. manhattanDistanceTo: function ( v ) {
  546. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  547. },
  548. setLength: function ( length ) {
  549. return this.normalize().multiplyScalar( length );
  550. },
  551. lerp: function ( v, alpha ) {
  552. this.x += ( v.x - this.x ) * alpha;
  553. this.y += ( v.y - this.y ) * alpha;
  554. return this;
  555. },
  556. lerpVectors: function ( v1, v2, alpha ) {
  557. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  558. },
  559. equals: function ( v ) {
  560. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  561. },
  562. fromArray: function ( array, offset ) {
  563. if ( offset === undefined ) offset = 0;
  564. this.x = array[ offset ];
  565. this.y = array[ offset + 1 ];
  566. return this;
  567. },
  568. toArray: function ( array, offset ) {
  569. if ( array === undefined ) array = [];
  570. if ( offset === undefined ) offset = 0;
  571. array[ offset ] = this.x;
  572. array[ offset + 1 ] = this.y;
  573. return array;
  574. },
  575. fromBufferAttribute: function ( attribute, index, offset ) {
  576. if ( offset !== undefined ) {
  577. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  578. }
  579. this.x = attribute.getX( index );
  580. this.y = attribute.getY( index );
  581. return this;
  582. },
  583. rotateAround: function ( center, angle ) {
  584. var c = Math.cos( angle ), s = Math.sin( angle );
  585. var x = this.x - center.x;
  586. var y = this.y - center.y;
  587. this.x = x * c - y * s + center.x;
  588. this.y = x * s + y * c + center.y;
  589. return this;
  590. }
  591. } );
  592. /**
  593. * @author mrdoob / http://mrdoob.com/
  594. * @author supereggbert / http://www.paulbrunt.co.uk/
  595. * @author philogb / http://blog.thejit.org/
  596. * @author jordi_ros / http://plattsoft.com
  597. * @author D1plo1d / http://github.com/D1plo1d
  598. * @author alteredq / http://alteredqualia.com/
  599. * @author mikael emtinger / http://gomo.se/
  600. * @author timknip / http://www.floorplanner.com/
  601. * @author bhouston / http://clara.io
  602. * @author WestLangley / http://github.com/WestLangley
  603. */
  604. function Matrix4() {
  605. this.elements = [
  606. 1, 0, 0, 0,
  607. 0, 1, 0, 0,
  608. 0, 0, 1, 0,
  609. 0, 0, 0, 1
  610. ];
  611. if ( arguments.length > 0 ) {
  612. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  613. }
  614. }
  615. Object.assign( Matrix4.prototype, {
  616. isMatrix4: true,
  617. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  618. var te = this.elements;
  619. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  620. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  621. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  622. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  623. return this;
  624. },
  625. identity: function () {
  626. this.set(
  627. 1, 0, 0, 0,
  628. 0, 1, 0, 0,
  629. 0, 0, 1, 0,
  630. 0, 0, 0, 1
  631. );
  632. return this;
  633. },
  634. clone: function () {
  635. return new Matrix4().fromArray( this.elements );
  636. },
  637. copy: function ( m ) {
  638. var te = this.elements;
  639. var me = m.elements;
  640. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  641. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  642. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  643. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  644. return this;
  645. },
  646. copyPosition: function ( m ) {
  647. var te = this.elements, me = m.elements;
  648. te[ 12 ] = me[ 12 ];
  649. te[ 13 ] = me[ 13 ];
  650. te[ 14 ] = me[ 14 ];
  651. return this;
  652. },
  653. extractBasis: function ( xAxis, yAxis, zAxis ) {
  654. xAxis.setFromMatrixColumn( this, 0 );
  655. yAxis.setFromMatrixColumn( this, 1 );
  656. zAxis.setFromMatrixColumn( this, 2 );
  657. return this;
  658. },
  659. makeBasis: function ( xAxis, yAxis, zAxis ) {
  660. this.set(
  661. xAxis.x, yAxis.x, zAxis.x, 0,
  662. xAxis.y, yAxis.y, zAxis.y, 0,
  663. xAxis.z, yAxis.z, zAxis.z, 0,
  664. 0, 0, 0, 1
  665. );
  666. return this;
  667. },
  668. extractRotation: function () {
  669. var v1 = new Vector3();
  670. return function extractRotation( m ) {
  671. // this method does not support reflection matrices
  672. var te = this.elements;
  673. var me = m.elements;
  674. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  675. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  676. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  677. te[ 0 ] = me[ 0 ] * scaleX;
  678. te[ 1 ] = me[ 1 ] * scaleX;
  679. te[ 2 ] = me[ 2 ] * scaleX;
  680. te[ 3 ] = 0;
  681. te[ 4 ] = me[ 4 ] * scaleY;
  682. te[ 5 ] = me[ 5 ] * scaleY;
  683. te[ 6 ] = me[ 6 ] * scaleY;
  684. te[ 7 ] = 0;
  685. te[ 8 ] = me[ 8 ] * scaleZ;
  686. te[ 9 ] = me[ 9 ] * scaleZ;
  687. te[ 10 ] = me[ 10 ] * scaleZ;
  688. te[ 11 ] = 0;
  689. te[ 12 ] = 0;
  690. te[ 13 ] = 0;
  691. te[ 14 ] = 0;
  692. te[ 15 ] = 1;
  693. return this;
  694. };
  695. }(),
  696. makeRotationFromEuler: function ( euler ) {
  697. if ( ! ( euler && euler.isEuler ) ) {
  698. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  699. }
  700. var te = this.elements;
  701. var x = euler.x, y = euler.y, z = euler.z;
  702. var a = Math.cos( x ), b = Math.sin( x );
  703. var c = Math.cos( y ), d = Math.sin( y );
  704. var e = Math.cos( z ), f = Math.sin( z );
  705. if ( euler.order === 'XYZ' ) {
  706. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  707. te[ 0 ] = c * e;
  708. te[ 4 ] = - c * f;
  709. te[ 8 ] = d;
  710. te[ 1 ] = af + be * d;
  711. te[ 5 ] = ae - bf * d;
  712. te[ 9 ] = - b * c;
  713. te[ 2 ] = bf - ae * d;
  714. te[ 6 ] = be + af * d;
  715. te[ 10 ] = a * c;
  716. } else if ( euler.order === 'YXZ' ) {
  717. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  718. te[ 0 ] = ce + df * b;
  719. te[ 4 ] = de * b - cf;
  720. te[ 8 ] = a * d;
  721. te[ 1 ] = a * f;
  722. te[ 5 ] = a * e;
  723. te[ 9 ] = - b;
  724. te[ 2 ] = cf * b - de;
  725. te[ 6 ] = df + ce * b;
  726. te[ 10 ] = a * c;
  727. } else if ( euler.order === 'ZXY' ) {
  728. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  729. te[ 0 ] = ce - df * b;
  730. te[ 4 ] = - a * f;
  731. te[ 8 ] = de + cf * b;
  732. te[ 1 ] = cf + de * b;
  733. te[ 5 ] = a * e;
  734. te[ 9 ] = df - ce * b;
  735. te[ 2 ] = - a * d;
  736. te[ 6 ] = b;
  737. te[ 10 ] = a * c;
  738. } else if ( euler.order === 'ZYX' ) {
  739. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  740. te[ 0 ] = c * e;
  741. te[ 4 ] = be * d - af;
  742. te[ 8 ] = ae * d + bf;
  743. te[ 1 ] = c * f;
  744. te[ 5 ] = bf * d + ae;
  745. te[ 9 ] = af * d - be;
  746. te[ 2 ] = - d;
  747. te[ 6 ] = b * c;
  748. te[ 10 ] = a * c;
  749. } else if ( euler.order === 'YZX' ) {
  750. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  751. te[ 0 ] = c * e;
  752. te[ 4 ] = bd - ac * f;
  753. te[ 8 ] = bc * f + ad;
  754. te[ 1 ] = f;
  755. te[ 5 ] = a * e;
  756. te[ 9 ] = - b * e;
  757. te[ 2 ] = - d * e;
  758. te[ 6 ] = ad * f + bc;
  759. te[ 10 ] = ac - bd * f;
  760. } else if ( euler.order === 'XZY' ) {
  761. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  762. te[ 0 ] = c * e;
  763. te[ 4 ] = - f;
  764. te[ 8 ] = d * e;
  765. te[ 1 ] = ac * f + bd;
  766. te[ 5 ] = a * e;
  767. te[ 9 ] = ad * f - bc;
  768. te[ 2 ] = bc * f - ad;
  769. te[ 6 ] = b * e;
  770. te[ 10 ] = bd * f + ac;
  771. }
  772. // bottom row
  773. te[ 3 ] = 0;
  774. te[ 7 ] = 0;
  775. te[ 11 ] = 0;
  776. // last column
  777. te[ 12 ] = 0;
  778. te[ 13 ] = 0;
  779. te[ 14 ] = 0;
  780. te[ 15 ] = 1;
  781. return this;
  782. },
  783. makeRotationFromQuaternion: function () {
  784. var zero = new Vector3( 0, 0, 0 );
  785. var one = new Vector3( 1, 1, 1 );
  786. return function makeRotationFromQuaternion( q ) {
  787. return this.compose( zero, q, one );
  788. };
  789. }(),
  790. lookAt: function () {
  791. var x = new Vector3();
  792. var y = new Vector3();
  793. var z = new Vector3();
  794. return function lookAt( eye, target, up ) {
  795. var te = this.elements;
  796. z.subVectors( eye, target );
  797. if ( z.lengthSq() === 0 ) {
  798. // eye and target are in the same position
  799. z.z = 1;
  800. }
  801. z.normalize();
  802. x.crossVectors( up, z );
  803. if ( x.lengthSq() === 0 ) {
  804. // up and z are parallel
  805. if ( Math.abs( up.z ) === 1 ) {
  806. z.x += 0.0001;
  807. } else {
  808. z.z += 0.0001;
  809. }
  810. z.normalize();
  811. x.crossVectors( up, z );
  812. }
  813. x.normalize();
  814. y.crossVectors( z, x );
  815. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  816. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  817. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  818. return this;
  819. };
  820. }(),
  821. multiply: function ( m, n ) {
  822. if ( n !== undefined ) {
  823. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  824. return this.multiplyMatrices( m, n );
  825. }
  826. return this.multiplyMatrices( this, m );
  827. },
  828. premultiply: function ( m ) {
  829. return this.multiplyMatrices( m, this );
  830. },
  831. multiplyMatrices: function ( a, b ) {
  832. var ae = a.elements;
  833. var be = b.elements;
  834. var te = this.elements;
  835. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  836. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  837. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  838. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  839. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  840. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  841. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  842. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  843. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  844. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  845. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  846. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  847. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  848. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  849. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  850. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  851. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  852. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  853. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  854. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  855. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  856. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  857. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  858. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  859. return this;
  860. },
  861. multiplyScalar: function ( s ) {
  862. var te = this.elements;
  863. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  864. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  865. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  866. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  867. return this;
  868. },
  869. applyToBufferAttribute: function () {
  870. var v1 = new Vector3();
  871. return function applyToBufferAttribute( attribute ) {
  872. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  873. v1.x = attribute.getX( i );
  874. v1.y = attribute.getY( i );
  875. v1.z = attribute.getZ( i );
  876. v1.applyMatrix4( this );
  877. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  878. }
  879. return attribute;
  880. };
  881. }(),
  882. determinant: function () {
  883. var te = this.elements;
  884. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  885. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  886. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  887. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  888. //TODO: make this more efficient
  889. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  890. return (
  891. n41 * (
  892. + n14 * n23 * n32
  893. - n13 * n24 * n32
  894. - n14 * n22 * n33
  895. + n12 * n24 * n33
  896. + n13 * n22 * n34
  897. - n12 * n23 * n34
  898. ) +
  899. n42 * (
  900. + n11 * n23 * n34
  901. - n11 * n24 * n33
  902. + n14 * n21 * n33
  903. - n13 * n21 * n34
  904. + n13 * n24 * n31
  905. - n14 * n23 * n31
  906. ) +
  907. n43 * (
  908. + n11 * n24 * n32
  909. - n11 * n22 * n34
  910. - n14 * n21 * n32
  911. + n12 * n21 * n34
  912. + n14 * n22 * n31
  913. - n12 * n24 * n31
  914. ) +
  915. n44 * (
  916. - n13 * n22 * n31
  917. - n11 * n23 * n32
  918. + n11 * n22 * n33
  919. + n13 * n21 * n32
  920. - n12 * n21 * n33
  921. + n12 * n23 * n31
  922. )
  923. );
  924. },
  925. transpose: function () {
  926. var te = this.elements;
  927. var tmp;
  928. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  929. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  930. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  931. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  932. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  933. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  934. return this;
  935. },
  936. setPosition: function ( v ) {
  937. var te = this.elements;
  938. te[ 12 ] = v.x;
  939. te[ 13 ] = v.y;
  940. te[ 14 ] = v.z;
  941. return this;
  942. },
  943. getInverse: function ( m, throwOnDegenerate ) {
  944. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  945. var te = this.elements,
  946. me = m.elements,
  947. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  948. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  949. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  950. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  951. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  952. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  953. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  954. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  955. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  956. if ( det === 0 ) {
  957. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  958. if ( throwOnDegenerate === true ) {
  959. throw new Error( msg );
  960. } else {
  961. console.warn( msg );
  962. }
  963. return this.identity();
  964. }
  965. var detInv = 1 / det;
  966. te[ 0 ] = t11 * detInv;
  967. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  968. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  969. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  970. te[ 4 ] = t12 * detInv;
  971. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  972. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  973. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  974. te[ 8 ] = t13 * detInv;
  975. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  976. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  977. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  978. te[ 12 ] = t14 * detInv;
  979. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  980. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  981. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  982. return this;
  983. },
  984. scale: function ( v ) {
  985. var te = this.elements;
  986. var x = v.x, y = v.y, z = v.z;
  987. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  988. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  989. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  990. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  991. return this;
  992. },
  993. getMaxScaleOnAxis: function () {
  994. var te = this.elements;
  995. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  996. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  997. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  998. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  999. },
  1000. makeTranslation: function ( x, y, z ) {
  1001. this.set(
  1002. 1, 0, 0, x,
  1003. 0, 1, 0, y,
  1004. 0, 0, 1, z,
  1005. 0, 0, 0, 1
  1006. );
  1007. return this;
  1008. },
  1009. makeRotationX: function ( theta ) {
  1010. var c = Math.cos( theta ), s = Math.sin( theta );
  1011. this.set(
  1012. 1, 0, 0, 0,
  1013. 0, c, - s, 0,
  1014. 0, s, c, 0,
  1015. 0, 0, 0, 1
  1016. );
  1017. return this;
  1018. },
  1019. makeRotationY: function ( theta ) {
  1020. var c = Math.cos( theta ), s = Math.sin( theta );
  1021. this.set(
  1022. c, 0, s, 0,
  1023. 0, 1, 0, 0,
  1024. - s, 0, c, 0,
  1025. 0, 0, 0, 1
  1026. );
  1027. return this;
  1028. },
  1029. makeRotationZ: function ( theta ) {
  1030. var c = Math.cos( theta ), s = Math.sin( theta );
  1031. this.set(
  1032. c, - s, 0, 0,
  1033. s, c, 0, 0,
  1034. 0, 0, 1, 0,
  1035. 0, 0, 0, 1
  1036. );
  1037. return this;
  1038. },
  1039. makeRotationAxis: function ( axis, angle ) {
  1040. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1041. var c = Math.cos( angle );
  1042. var s = Math.sin( angle );
  1043. var t = 1 - c;
  1044. var x = axis.x, y = axis.y, z = axis.z;
  1045. var tx = t * x, ty = t * y;
  1046. this.set(
  1047. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1048. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1049. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1050. 0, 0, 0, 1
  1051. );
  1052. return this;
  1053. },
  1054. makeScale: function ( x, y, z ) {
  1055. this.set(
  1056. x, 0, 0, 0,
  1057. 0, y, 0, 0,
  1058. 0, 0, z, 0,
  1059. 0, 0, 0, 1
  1060. );
  1061. return this;
  1062. },
  1063. makeShear: function ( x, y, z ) {
  1064. this.set(
  1065. 1, y, z, 0,
  1066. x, 1, z, 0,
  1067. x, y, 1, 0,
  1068. 0, 0, 0, 1
  1069. );
  1070. return this;
  1071. },
  1072. compose: function ( position, quaternion, scale ) {
  1073. var te = this.elements;
  1074. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  1075. var x2 = x + x, y2 = y + y, z2 = z + z;
  1076. var xx = x * x2, xy = x * y2, xz = x * z2;
  1077. var yy = y * y2, yz = y * z2, zz = z * z2;
  1078. var wx = w * x2, wy = w * y2, wz = w * z2;
  1079. var sx = scale.x, sy = scale.y, sz = scale.z;
  1080. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  1081. te[ 1 ] = ( xy + wz ) * sx;
  1082. te[ 2 ] = ( xz - wy ) * sx;
  1083. te[ 3 ] = 0;
  1084. te[ 4 ] = ( xy - wz ) * sy;
  1085. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  1086. te[ 6 ] = ( yz + wx ) * sy;
  1087. te[ 7 ] = 0;
  1088. te[ 8 ] = ( xz + wy ) * sz;
  1089. te[ 9 ] = ( yz - wx ) * sz;
  1090. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  1091. te[ 11 ] = 0;
  1092. te[ 12 ] = position.x;
  1093. te[ 13 ] = position.y;
  1094. te[ 14 ] = position.z;
  1095. te[ 15 ] = 1;
  1096. return this;
  1097. },
  1098. decompose: function () {
  1099. var vector = new Vector3();
  1100. var matrix = new Matrix4();
  1101. return function decompose( position, quaternion, scale ) {
  1102. var te = this.elements;
  1103. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  1104. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  1105. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  1106. // if determine is negative, we need to invert one scale
  1107. var det = this.determinant();
  1108. if ( det < 0 ) sx = - sx;
  1109. position.x = te[ 12 ];
  1110. position.y = te[ 13 ];
  1111. position.z = te[ 14 ];
  1112. // scale the rotation part
  1113. matrix.copy( this );
  1114. var invSX = 1 / sx;
  1115. var invSY = 1 / sy;
  1116. var invSZ = 1 / sz;
  1117. matrix.elements[ 0 ] *= invSX;
  1118. matrix.elements[ 1 ] *= invSX;
  1119. matrix.elements[ 2 ] *= invSX;
  1120. matrix.elements[ 4 ] *= invSY;
  1121. matrix.elements[ 5 ] *= invSY;
  1122. matrix.elements[ 6 ] *= invSY;
  1123. matrix.elements[ 8 ] *= invSZ;
  1124. matrix.elements[ 9 ] *= invSZ;
  1125. matrix.elements[ 10 ] *= invSZ;
  1126. quaternion.setFromRotationMatrix( matrix );
  1127. scale.x = sx;
  1128. scale.y = sy;
  1129. scale.z = sz;
  1130. return this;
  1131. };
  1132. }(),
  1133. makePerspective: function ( left, right, top, bottom, near, far ) {
  1134. if ( far === undefined ) {
  1135. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  1136. }
  1137. var te = this.elements;
  1138. var x = 2 * near / ( right - left );
  1139. var y = 2 * near / ( top - bottom );
  1140. var a = ( right + left ) / ( right - left );
  1141. var b = ( top + bottom ) / ( top - bottom );
  1142. var c = - ( far + near ) / ( far - near );
  1143. var d = - 2 * far * near / ( far - near );
  1144. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  1145. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  1146. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  1147. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  1148. return this;
  1149. },
  1150. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1151. var te = this.elements;
  1152. var w = 1.0 / ( right - left );
  1153. var h = 1.0 / ( top - bottom );
  1154. var p = 1.0 / ( far - near );
  1155. var x = ( right + left ) * w;
  1156. var y = ( top + bottom ) * h;
  1157. var z = ( far + near ) * p;
  1158. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  1159. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  1160. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  1161. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  1162. return this;
  1163. },
  1164. equals: function ( matrix ) {
  1165. var te = this.elements;
  1166. var me = matrix.elements;
  1167. for ( var i = 0; i < 16; i ++ ) {
  1168. if ( te[ i ] !== me[ i ] ) return false;
  1169. }
  1170. return true;
  1171. },
  1172. fromArray: function ( array, offset ) {
  1173. if ( offset === undefined ) offset = 0;
  1174. for ( var i = 0; i < 16; i ++ ) {
  1175. this.elements[ i ] = array[ i + offset ];
  1176. }
  1177. return this;
  1178. },
  1179. toArray: function ( array, offset ) {
  1180. if ( array === undefined ) array = [];
  1181. if ( offset === undefined ) offset = 0;
  1182. var te = this.elements;
  1183. array[ offset ] = te[ 0 ];
  1184. array[ offset + 1 ] = te[ 1 ];
  1185. array[ offset + 2 ] = te[ 2 ];
  1186. array[ offset + 3 ] = te[ 3 ];
  1187. array[ offset + 4 ] = te[ 4 ];
  1188. array[ offset + 5 ] = te[ 5 ];
  1189. array[ offset + 6 ] = te[ 6 ];
  1190. array[ offset + 7 ] = te[ 7 ];
  1191. array[ offset + 8 ] = te[ 8 ];
  1192. array[ offset + 9 ] = te[ 9 ];
  1193. array[ offset + 10 ] = te[ 10 ];
  1194. array[ offset + 11 ] = te[ 11 ];
  1195. array[ offset + 12 ] = te[ 12 ];
  1196. array[ offset + 13 ] = te[ 13 ];
  1197. array[ offset + 14 ] = te[ 14 ];
  1198. array[ offset + 15 ] = te[ 15 ];
  1199. return array;
  1200. }
  1201. } );
  1202. /**
  1203. * @author mikael emtinger / http://gomo.se/
  1204. * @author alteredq / http://alteredqualia.com/
  1205. * @author WestLangley / http://github.com/WestLangley
  1206. * @author bhouston / http://clara.io
  1207. */
  1208. function Quaternion( x, y, z, w ) {
  1209. this._x = x || 0;
  1210. this._y = y || 0;
  1211. this._z = z || 0;
  1212. this._w = ( w !== undefined ) ? w : 1;
  1213. }
  1214. Object.assign( Quaternion, {
  1215. slerp: function ( qa, qb, qm, t ) {
  1216. return qm.copy( qa ).slerp( qb, t );
  1217. },
  1218. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1219. // fuzz-free, array-based Quaternion SLERP operation
  1220. var x0 = src0[ srcOffset0 + 0 ],
  1221. y0 = src0[ srcOffset0 + 1 ],
  1222. z0 = src0[ srcOffset0 + 2 ],
  1223. w0 = src0[ srcOffset0 + 3 ],
  1224. x1 = src1[ srcOffset1 + 0 ],
  1225. y1 = src1[ srcOffset1 + 1 ],
  1226. z1 = src1[ srcOffset1 + 2 ],
  1227. w1 = src1[ srcOffset1 + 3 ];
  1228. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1229. var s = 1 - t,
  1230. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1231. dir = ( cos >= 0 ? 1 : - 1 ),
  1232. sqrSin = 1 - cos * cos;
  1233. // Skip the Slerp for tiny steps to avoid numeric problems:
  1234. if ( sqrSin > Number.EPSILON ) {
  1235. var sin = Math.sqrt( sqrSin ),
  1236. len = Math.atan2( sin, cos * dir );
  1237. s = Math.sin( s * len ) / sin;
  1238. t = Math.sin( t * len ) / sin;
  1239. }
  1240. var tDir = t * dir;
  1241. x0 = x0 * s + x1 * tDir;
  1242. y0 = y0 * s + y1 * tDir;
  1243. z0 = z0 * s + z1 * tDir;
  1244. w0 = w0 * s + w1 * tDir;
  1245. // Normalize in case we just did a lerp:
  1246. if ( s === 1 - t ) {
  1247. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1248. x0 *= f;
  1249. y0 *= f;
  1250. z0 *= f;
  1251. w0 *= f;
  1252. }
  1253. }
  1254. dst[ dstOffset ] = x0;
  1255. dst[ dstOffset + 1 ] = y0;
  1256. dst[ dstOffset + 2 ] = z0;
  1257. dst[ dstOffset + 3 ] = w0;
  1258. }
  1259. } );
  1260. Object.defineProperties( Quaternion.prototype, {
  1261. x: {
  1262. get: function () {
  1263. return this._x;
  1264. },
  1265. set: function ( value ) {
  1266. this._x = value;
  1267. this.onChangeCallback();
  1268. }
  1269. },
  1270. y: {
  1271. get: function () {
  1272. return this._y;
  1273. },
  1274. set: function ( value ) {
  1275. this._y = value;
  1276. this.onChangeCallback();
  1277. }
  1278. },
  1279. z: {
  1280. get: function () {
  1281. return this._z;
  1282. },
  1283. set: function ( value ) {
  1284. this._z = value;
  1285. this.onChangeCallback();
  1286. }
  1287. },
  1288. w: {
  1289. get: function () {
  1290. return this._w;
  1291. },
  1292. set: function ( value ) {
  1293. this._w = value;
  1294. this.onChangeCallback();
  1295. }
  1296. }
  1297. } );
  1298. Object.assign( Quaternion.prototype, {
  1299. isQuaternion: true,
  1300. set: function ( x, y, z, w ) {
  1301. this._x = x;
  1302. this._y = y;
  1303. this._z = z;
  1304. this._w = w;
  1305. this.onChangeCallback();
  1306. return this;
  1307. },
  1308. clone: function () {
  1309. return new this.constructor( this._x, this._y, this._z, this._w );
  1310. },
  1311. copy: function ( quaternion ) {
  1312. this._x = quaternion.x;
  1313. this._y = quaternion.y;
  1314. this._z = quaternion.z;
  1315. this._w = quaternion.w;
  1316. this.onChangeCallback();
  1317. return this;
  1318. },
  1319. setFromEuler: function ( euler, update ) {
  1320. if ( ! ( euler && euler.isEuler ) ) {
  1321. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1322. }
  1323. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1324. // http://www.mathworks.com/matlabcentral/fileexchange/
  1325. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1326. // content/SpinCalc.m
  1327. var cos = Math.cos;
  1328. var sin = Math.sin;
  1329. var c1 = cos( x / 2 );
  1330. var c2 = cos( y / 2 );
  1331. var c3 = cos( z / 2 );
  1332. var s1 = sin( x / 2 );
  1333. var s2 = sin( y / 2 );
  1334. var s3 = sin( z / 2 );
  1335. if ( order === 'XYZ' ) {
  1336. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1337. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1338. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1339. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1340. } else if ( order === 'YXZ' ) {
  1341. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1342. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1343. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1344. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1345. } else if ( order === 'ZXY' ) {
  1346. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1347. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1348. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1349. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1350. } else if ( order === 'ZYX' ) {
  1351. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1352. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1353. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1354. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1355. } else if ( order === 'YZX' ) {
  1356. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1357. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1358. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1359. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1360. } else if ( order === 'XZY' ) {
  1361. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1362. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1363. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1364. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1365. }
  1366. if ( update !== false ) this.onChangeCallback();
  1367. return this;
  1368. },
  1369. setFromAxisAngle: function ( axis, angle ) {
  1370. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1371. // assumes axis is normalized
  1372. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1373. this._x = axis.x * s;
  1374. this._y = axis.y * s;
  1375. this._z = axis.z * s;
  1376. this._w = Math.cos( halfAngle );
  1377. this.onChangeCallback();
  1378. return this;
  1379. },
  1380. setFromRotationMatrix: function ( m ) {
  1381. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1382. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1383. var te = m.elements,
  1384. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1385. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1386. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1387. trace = m11 + m22 + m33,
  1388. s;
  1389. if ( trace > 0 ) {
  1390. s = 0.5 / Math.sqrt( trace + 1.0 );
  1391. this._w = 0.25 / s;
  1392. this._x = ( m32 - m23 ) * s;
  1393. this._y = ( m13 - m31 ) * s;
  1394. this._z = ( m21 - m12 ) * s;
  1395. } else if ( m11 > m22 && m11 > m33 ) {
  1396. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1397. this._w = ( m32 - m23 ) / s;
  1398. this._x = 0.25 * s;
  1399. this._y = ( m12 + m21 ) / s;
  1400. this._z = ( m13 + m31 ) / s;
  1401. } else if ( m22 > m33 ) {
  1402. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1403. this._w = ( m13 - m31 ) / s;
  1404. this._x = ( m12 + m21 ) / s;
  1405. this._y = 0.25 * s;
  1406. this._z = ( m23 + m32 ) / s;
  1407. } else {
  1408. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1409. this._w = ( m21 - m12 ) / s;
  1410. this._x = ( m13 + m31 ) / s;
  1411. this._y = ( m23 + m32 ) / s;
  1412. this._z = 0.25 * s;
  1413. }
  1414. this.onChangeCallback();
  1415. return this;
  1416. },
  1417. setFromUnitVectors: function () {
  1418. // assumes direction vectors vFrom and vTo are normalized
  1419. var v1 = new Vector3();
  1420. var r;
  1421. var EPS = 0.000001;
  1422. return function setFromUnitVectors( vFrom, vTo ) {
  1423. if ( v1 === undefined ) v1 = new Vector3();
  1424. r = vFrom.dot( vTo ) + 1;
  1425. if ( r < EPS ) {
  1426. r = 0;
  1427. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1428. v1.set( - vFrom.y, vFrom.x, 0 );
  1429. } else {
  1430. v1.set( 0, - vFrom.z, vFrom.y );
  1431. }
  1432. } else {
  1433. v1.crossVectors( vFrom, vTo );
  1434. }
  1435. this._x = v1.x;
  1436. this._y = v1.y;
  1437. this._z = v1.z;
  1438. this._w = r;
  1439. return this.normalize();
  1440. };
  1441. }(),
  1442. angleTo: function ( q ) {
  1443. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  1444. },
  1445. rotateTowards: function ( q, step ) {
  1446. var angle = this.angleTo( q );
  1447. if ( angle === 0 ) return this;
  1448. var t = Math.min( 1, step / angle );
  1449. this.slerp( q, t );
  1450. return this;
  1451. },
  1452. inverse: function () {
  1453. // quaternion is assumed to have unit length
  1454. return this.conjugate();
  1455. },
  1456. conjugate: function () {
  1457. this._x *= - 1;
  1458. this._y *= - 1;
  1459. this._z *= - 1;
  1460. this.onChangeCallback();
  1461. return this;
  1462. },
  1463. dot: function ( v ) {
  1464. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1465. },
  1466. lengthSq: function () {
  1467. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1468. },
  1469. length: function () {
  1470. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1471. },
  1472. normalize: function () {
  1473. var l = this.length();
  1474. if ( l === 0 ) {
  1475. this._x = 0;
  1476. this._y = 0;
  1477. this._z = 0;
  1478. this._w = 1;
  1479. } else {
  1480. l = 1 / l;
  1481. this._x = this._x * l;
  1482. this._y = this._y * l;
  1483. this._z = this._z * l;
  1484. this._w = this._w * l;
  1485. }
  1486. this.onChangeCallback();
  1487. return this;
  1488. },
  1489. multiply: function ( q, p ) {
  1490. if ( p !== undefined ) {
  1491. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1492. return this.multiplyQuaternions( q, p );
  1493. }
  1494. return this.multiplyQuaternions( this, q );
  1495. },
  1496. premultiply: function ( q ) {
  1497. return this.multiplyQuaternions( q, this );
  1498. },
  1499. multiplyQuaternions: function ( a, b ) {
  1500. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1501. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1502. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1503. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1504. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1505. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1506. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1507. this.onChangeCallback();
  1508. return this;
  1509. },
  1510. slerp: function ( qb, t ) {
  1511. if ( t === 0 ) return this;
  1512. if ( t === 1 ) return this.copy( qb );
  1513. var x = this._x, y = this._y, z = this._z, w = this._w;
  1514. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1515. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1516. if ( cosHalfTheta < 0 ) {
  1517. this._w = - qb._w;
  1518. this._x = - qb._x;
  1519. this._y = - qb._y;
  1520. this._z = - qb._z;
  1521. cosHalfTheta = - cosHalfTheta;
  1522. } else {
  1523. this.copy( qb );
  1524. }
  1525. if ( cosHalfTheta >= 1.0 ) {
  1526. this._w = w;
  1527. this._x = x;
  1528. this._y = y;
  1529. this._z = z;
  1530. return this;
  1531. }
  1532. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1533. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1534. var s = 1 - t;
  1535. this._w = s * w + t * this._w;
  1536. this._x = s * x + t * this._x;
  1537. this._y = s * y + t * this._y;
  1538. this._z = s * z + t * this._z;
  1539. return this.normalize();
  1540. }
  1541. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1542. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1543. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1544. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1545. this._w = ( w * ratioA + this._w * ratioB );
  1546. this._x = ( x * ratioA + this._x * ratioB );
  1547. this._y = ( y * ratioA + this._y * ratioB );
  1548. this._z = ( z * ratioA + this._z * ratioB );
  1549. this.onChangeCallback();
  1550. return this;
  1551. },
  1552. equals: function ( quaternion ) {
  1553. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1554. },
  1555. fromArray: function ( array, offset ) {
  1556. if ( offset === undefined ) offset = 0;
  1557. this._x = array[ offset ];
  1558. this._y = array[ offset + 1 ];
  1559. this._z = array[ offset + 2 ];
  1560. this._w = array[ offset + 3 ];
  1561. this.onChangeCallback();
  1562. return this;
  1563. },
  1564. toArray: function ( array, offset ) {
  1565. if ( array === undefined ) array = [];
  1566. if ( offset === undefined ) offset = 0;
  1567. array[ offset ] = this._x;
  1568. array[ offset + 1 ] = this._y;
  1569. array[ offset + 2 ] = this._z;
  1570. array[ offset + 3 ] = this._w;
  1571. return array;
  1572. },
  1573. onChange: function ( callback ) {
  1574. this.onChangeCallback = callback;
  1575. return this;
  1576. },
  1577. onChangeCallback: function () {}
  1578. } );
  1579. /**
  1580. * @author mrdoob / http://mrdoob.com/
  1581. * @author kile / http://kile.stravaganza.org/
  1582. * @author philogb / http://blog.thejit.org/
  1583. * @author mikael emtinger / http://gomo.se/
  1584. * @author egraether / http://egraether.com/
  1585. * @author WestLangley / http://github.com/WestLangley
  1586. */
  1587. function Vector3( x, y, z ) {
  1588. this.x = x || 0;
  1589. this.y = y || 0;
  1590. this.z = z || 0;
  1591. }
  1592. Object.assign( Vector3.prototype, {
  1593. isVector3: true,
  1594. set: function ( x, y, z ) {
  1595. this.x = x;
  1596. this.y = y;
  1597. this.z = z;
  1598. return this;
  1599. },
  1600. setScalar: function ( scalar ) {
  1601. this.x = scalar;
  1602. this.y = scalar;
  1603. this.z = scalar;
  1604. return this;
  1605. },
  1606. setX: function ( x ) {
  1607. this.x = x;
  1608. return this;
  1609. },
  1610. setY: function ( y ) {
  1611. this.y = y;
  1612. return this;
  1613. },
  1614. setZ: function ( z ) {
  1615. this.z = z;
  1616. return this;
  1617. },
  1618. setComponent: function ( index, value ) {
  1619. switch ( index ) {
  1620. case 0: this.x = value; break;
  1621. case 1: this.y = value; break;
  1622. case 2: this.z = value; break;
  1623. default: throw new Error( 'index is out of range: ' + index );
  1624. }
  1625. return this;
  1626. },
  1627. getComponent: function ( index ) {
  1628. switch ( index ) {
  1629. case 0: return this.x;
  1630. case 1: return this.y;
  1631. case 2: return this.z;
  1632. default: throw new Error( 'index is out of range: ' + index );
  1633. }
  1634. },
  1635. clone: function () {
  1636. return new this.constructor( this.x, this.y, this.z );
  1637. },
  1638. copy: function ( v ) {
  1639. this.x = v.x;
  1640. this.y = v.y;
  1641. this.z = v.z;
  1642. return this;
  1643. },
  1644. add: function ( v, w ) {
  1645. if ( w !== undefined ) {
  1646. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1647. return this.addVectors( v, w );
  1648. }
  1649. this.x += v.x;
  1650. this.y += v.y;
  1651. this.z += v.z;
  1652. return this;
  1653. },
  1654. addScalar: function ( s ) {
  1655. this.x += s;
  1656. this.y += s;
  1657. this.z += s;
  1658. return this;
  1659. },
  1660. addVectors: 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. addScaledVector: function ( v, s ) {
  1667. this.x += v.x * s;
  1668. this.y += v.y * s;
  1669. this.z += v.z * s;
  1670. return this;
  1671. },
  1672. sub: function ( v, w ) {
  1673. if ( w !== undefined ) {
  1674. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1675. return this.subVectors( v, w );
  1676. }
  1677. this.x -= v.x;
  1678. this.y -= v.y;
  1679. this.z -= v.z;
  1680. return this;
  1681. },
  1682. subScalar: function ( s ) {
  1683. this.x -= s;
  1684. this.y -= s;
  1685. this.z -= s;
  1686. return this;
  1687. },
  1688. subVectors: function ( a, b ) {
  1689. this.x = a.x - b.x;
  1690. this.y = a.y - b.y;
  1691. this.z = a.z - b.z;
  1692. return this;
  1693. },
  1694. multiply: function ( v, w ) {
  1695. if ( w !== undefined ) {
  1696. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1697. return this.multiplyVectors( v, w );
  1698. }
  1699. this.x *= v.x;
  1700. this.y *= v.y;
  1701. this.z *= v.z;
  1702. return this;
  1703. },
  1704. multiplyScalar: function ( scalar ) {
  1705. this.x *= scalar;
  1706. this.y *= scalar;
  1707. this.z *= scalar;
  1708. return this;
  1709. },
  1710. multiplyVectors: function ( a, b ) {
  1711. this.x = a.x * b.x;
  1712. this.y = a.y * b.y;
  1713. this.z = a.z * b.z;
  1714. return this;
  1715. },
  1716. applyEuler: function () {
  1717. var quaternion = new Quaternion();
  1718. return function applyEuler( euler ) {
  1719. if ( ! ( euler && euler.isEuler ) ) {
  1720. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1721. }
  1722. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1723. };
  1724. }(),
  1725. applyAxisAngle: function () {
  1726. var quaternion = new Quaternion();
  1727. return function applyAxisAngle( axis, angle ) {
  1728. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1729. };
  1730. }(),
  1731. applyMatrix3: function ( m ) {
  1732. var x = this.x, y = this.y, z = this.z;
  1733. var e = m.elements;
  1734. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1735. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1736. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1737. return this;
  1738. },
  1739. applyMatrix4: function ( m ) {
  1740. var x = this.x, y = this.y, z = this.z;
  1741. var e = m.elements;
  1742. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1743. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1744. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1745. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1746. return this;
  1747. },
  1748. applyQuaternion: function ( q ) {
  1749. var x = this.x, y = this.y, z = this.z;
  1750. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1751. // calculate quat * vector
  1752. var ix = qw * x + qy * z - qz * y;
  1753. var iy = qw * y + qz * x - qx * z;
  1754. var iz = qw * z + qx * y - qy * x;
  1755. var iw = - qx * x - qy * y - qz * z;
  1756. // calculate result * inverse quat
  1757. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1758. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1759. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1760. return this;
  1761. },
  1762. project: function ( camera ) {
  1763. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1764. },
  1765. unproject: function () {
  1766. var matrix = new Matrix4();
  1767. return function unproject( camera ) {
  1768. return this.applyMatrix4( matrix.getInverse( camera.projectionMatrix ) ).applyMatrix4( camera.matrixWorld );
  1769. };
  1770. }(),
  1771. transformDirection: function ( m ) {
  1772. // input: THREE.Matrix4 affine matrix
  1773. // vector interpreted as a direction
  1774. var x = this.x, y = this.y, z = this.z;
  1775. var e = m.elements;
  1776. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1777. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1778. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1779. return this.normalize();
  1780. },
  1781. divide: function ( v ) {
  1782. this.x /= v.x;
  1783. this.y /= v.y;
  1784. this.z /= v.z;
  1785. return this;
  1786. },
  1787. divideScalar: function ( scalar ) {
  1788. return this.multiplyScalar( 1 / scalar );
  1789. },
  1790. min: function ( v ) {
  1791. this.x = Math.min( this.x, v.x );
  1792. this.y = Math.min( this.y, v.y );
  1793. this.z = Math.min( this.z, v.z );
  1794. return this;
  1795. },
  1796. max: function ( v ) {
  1797. this.x = Math.max( this.x, v.x );
  1798. this.y = Math.max( this.y, v.y );
  1799. this.z = Math.max( this.z, v.z );
  1800. return this;
  1801. },
  1802. clamp: function ( min, max ) {
  1803. // assumes min < max, componentwise
  1804. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1805. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1806. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1807. return this;
  1808. },
  1809. clampScalar: function () {
  1810. var min = new Vector3();
  1811. var max = new Vector3();
  1812. return function clampScalar( minVal, maxVal ) {
  1813. min.set( minVal, minVal, minVal );
  1814. max.set( maxVal, maxVal, maxVal );
  1815. return this.clamp( min, max );
  1816. };
  1817. }(),
  1818. clampLength: function ( min, max ) {
  1819. var length = this.length();
  1820. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1821. },
  1822. floor: function () {
  1823. this.x = Math.floor( this.x );
  1824. this.y = Math.floor( this.y );
  1825. this.z = Math.floor( this.z );
  1826. return this;
  1827. },
  1828. ceil: function () {
  1829. this.x = Math.ceil( this.x );
  1830. this.y = Math.ceil( this.y );
  1831. this.z = Math.ceil( this.z );
  1832. return this;
  1833. },
  1834. round: function () {
  1835. this.x = Math.round( this.x );
  1836. this.y = Math.round( this.y );
  1837. this.z = Math.round( this.z );
  1838. return this;
  1839. },
  1840. roundToZero: function () {
  1841. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1842. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1843. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1844. return this;
  1845. },
  1846. negate: function () {
  1847. this.x = - this.x;
  1848. this.y = - this.y;
  1849. this.z = - this.z;
  1850. return this;
  1851. },
  1852. dot: function ( v ) {
  1853. return this.x * v.x + this.y * v.y + this.z * v.z;
  1854. },
  1855. // TODO lengthSquared?
  1856. lengthSq: function () {
  1857. return this.x * this.x + this.y * this.y + this.z * this.z;
  1858. },
  1859. length: function () {
  1860. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1861. },
  1862. manhattanLength: function () {
  1863. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1864. },
  1865. normalize: function () {
  1866. return this.divideScalar( this.length() || 1 );
  1867. },
  1868. setLength: function ( length ) {
  1869. return this.normalize().multiplyScalar( length );
  1870. },
  1871. lerp: function ( v, alpha ) {
  1872. this.x += ( v.x - this.x ) * alpha;
  1873. this.y += ( v.y - this.y ) * alpha;
  1874. this.z += ( v.z - this.z ) * alpha;
  1875. return this;
  1876. },
  1877. lerpVectors: function ( v1, v2, alpha ) {
  1878. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1879. },
  1880. cross: function ( v, w ) {
  1881. if ( w !== undefined ) {
  1882. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1883. return this.crossVectors( v, w );
  1884. }
  1885. return this.crossVectors( this, v );
  1886. },
  1887. crossVectors: function ( a, b ) {
  1888. var ax = a.x, ay = a.y, az = a.z;
  1889. var bx = b.x, by = b.y, bz = b.z;
  1890. this.x = ay * bz - az * by;
  1891. this.y = az * bx - ax * bz;
  1892. this.z = ax * by - ay * bx;
  1893. return this;
  1894. },
  1895. projectOnVector: function ( vector ) {
  1896. var scalar = vector.dot( this ) / vector.lengthSq();
  1897. return this.copy( vector ).multiplyScalar( scalar );
  1898. },
  1899. projectOnPlane: function () {
  1900. var v1 = new Vector3();
  1901. return function projectOnPlane( planeNormal ) {
  1902. v1.copy( this ).projectOnVector( planeNormal );
  1903. return this.sub( v1 );
  1904. };
  1905. }(),
  1906. reflect: function () {
  1907. // reflect incident vector off plane orthogonal to normal
  1908. // normal is assumed to have unit length
  1909. var v1 = new Vector3();
  1910. return function reflect( normal ) {
  1911. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1912. };
  1913. }(),
  1914. angleTo: function ( v ) {
  1915. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1916. // clamp, to handle numerical problems
  1917. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1918. },
  1919. distanceTo: function ( v ) {
  1920. return Math.sqrt( this.distanceToSquared( v ) );
  1921. },
  1922. distanceToSquared: function ( v ) {
  1923. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1924. return dx * dx + dy * dy + dz * dz;
  1925. },
  1926. manhattanDistanceTo: function ( v ) {
  1927. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1928. },
  1929. setFromSpherical: function ( s ) {
  1930. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1931. },
  1932. setFromSphericalCoords: function ( radius, phi, theta ) {
  1933. var sinPhiRadius = Math.sin( phi ) * radius;
  1934. this.x = sinPhiRadius * Math.sin( theta );
  1935. this.y = Math.cos( phi ) * radius;
  1936. this.z = sinPhiRadius * Math.cos( theta );
  1937. return this;
  1938. },
  1939. setFromCylindrical: function ( c ) {
  1940. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1941. },
  1942. setFromCylindricalCoords: function ( radius, theta, y ) {
  1943. this.x = radius * Math.sin( theta );
  1944. this.y = y;
  1945. this.z = radius * Math.cos( theta );
  1946. return this;
  1947. },
  1948. setFromMatrixPosition: function ( m ) {
  1949. var e = m.elements;
  1950. this.x = e[ 12 ];
  1951. this.y = e[ 13 ];
  1952. this.z = e[ 14 ];
  1953. return this;
  1954. },
  1955. setFromMatrixScale: function ( m ) {
  1956. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1957. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1958. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1959. this.x = sx;
  1960. this.y = sy;
  1961. this.z = sz;
  1962. return this;
  1963. },
  1964. setFromMatrixColumn: function ( m, index ) {
  1965. return this.fromArray( m.elements, index * 4 );
  1966. },
  1967. equals: function ( v ) {
  1968. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1969. },
  1970. fromArray: function ( array, offset ) {
  1971. if ( offset === undefined ) offset = 0;
  1972. this.x = array[ offset ];
  1973. this.y = array[ offset + 1 ];
  1974. this.z = array[ offset + 2 ];
  1975. return this;
  1976. },
  1977. toArray: function ( array, offset ) {
  1978. if ( array === undefined ) array = [];
  1979. if ( offset === undefined ) offset = 0;
  1980. array[ offset ] = this.x;
  1981. array[ offset + 1 ] = this.y;
  1982. array[ offset + 2 ] = this.z;
  1983. return array;
  1984. },
  1985. fromBufferAttribute: function ( attribute, index, offset ) {
  1986. if ( offset !== undefined ) {
  1987. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1988. }
  1989. this.x = attribute.getX( index );
  1990. this.y = attribute.getY( index );
  1991. this.z = attribute.getZ( index );
  1992. return this;
  1993. }
  1994. } );
  1995. /**
  1996. * @author alteredq / http://alteredqualia.com/
  1997. * @author WestLangley / http://github.com/WestLangley
  1998. * @author bhouston / http://clara.io
  1999. * @author tschw
  2000. */
  2001. function Matrix3() {
  2002. this.elements = [
  2003. 1, 0, 0,
  2004. 0, 1, 0,
  2005. 0, 0, 1
  2006. ];
  2007. if ( arguments.length > 0 ) {
  2008. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2009. }
  2010. }
  2011. Object.assign( Matrix3.prototype, {
  2012. isMatrix3: true,
  2013. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2014. var te = this.elements;
  2015. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2016. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2017. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2018. return this;
  2019. },
  2020. identity: function () {
  2021. this.set(
  2022. 1, 0, 0,
  2023. 0, 1, 0,
  2024. 0, 0, 1
  2025. );
  2026. return this;
  2027. },
  2028. clone: function () {
  2029. return new this.constructor().fromArray( this.elements );
  2030. },
  2031. copy: function ( m ) {
  2032. var te = this.elements;
  2033. var me = m.elements;
  2034. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  2035. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  2036. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  2037. return this;
  2038. },
  2039. setFromMatrix4: function ( m ) {
  2040. var me = m.elements;
  2041. this.set(
  2042. me[ 0 ], me[ 4 ], me[ 8 ],
  2043. me[ 1 ], me[ 5 ], me[ 9 ],
  2044. me[ 2 ], me[ 6 ], me[ 10 ]
  2045. );
  2046. return this;
  2047. },
  2048. applyToBufferAttribute: function () {
  2049. var v1 = new Vector3();
  2050. return function applyToBufferAttribute( attribute ) {
  2051. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2052. v1.x = attribute.getX( i );
  2053. v1.y = attribute.getY( i );
  2054. v1.z = attribute.getZ( i );
  2055. v1.applyMatrix3( this );
  2056. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2057. }
  2058. return attribute;
  2059. };
  2060. }(),
  2061. multiply: function ( m ) {
  2062. return this.multiplyMatrices( this, m );
  2063. },
  2064. premultiply: function ( m ) {
  2065. return this.multiplyMatrices( m, this );
  2066. },
  2067. multiplyMatrices: function ( a, b ) {
  2068. var ae = a.elements;
  2069. var be = b.elements;
  2070. var te = this.elements;
  2071. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  2072. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  2073. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  2074. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  2075. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  2076. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  2077. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  2078. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  2079. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  2080. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  2081. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  2082. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  2083. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  2084. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  2085. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  2086. return this;
  2087. },
  2088. multiplyScalar: function ( s ) {
  2089. var te = this.elements;
  2090. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2091. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2092. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2093. return this;
  2094. },
  2095. determinant: function () {
  2096. var te = this.elements;
  2097. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2098. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2099. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2100. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2101. },
  2102. getInverse: function ( matrix, throwOnDegenerate ) {
  2103. if ( matrix && matrix.isMatrix4 ) {
  2104. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  2105. }
  2106. var me = matrix.elements,
  2107. te = this.elements,
  2108. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2109. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2110. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2111. t11 = n33 * n22 - n32 * n23,
  2112. t12 = n32 * n13 - n33 * n12,
  2113. t13 = n23 * n12 - n22 * n13,
  2114. det = n11 * t11 + n21 * t12 + n31 * t13;
  2115. if ( det === 0 ) {
  2116. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  2117. if ( throwOnDegenerate === true ) {
  2118. throw new Error( msg );
  2119. } else {
  2120. console.warn( msg );
  2121. }
  2122. return this.identity();
  2123. }
  2124. var detInv = 1 / det;
  2125. te[ 0 ] = t11 * detInv;
  2126. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2127. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2128. te[ 3 ] = t12 * detInv;
  2129. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2130. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2131. te[ 6 ] = t13 * detInv;
  2132. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2133. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2134. return this;
  2135. },
  2136. transpose: function () {
  2137. var tmp, m = this.elements;
  2138. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2139. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2140. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2141. return this;
  2142. },
  2143. getNormalMatrix: function ( matrix4 ) {
  2144. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2145. },
  2146. transposeIntoArray: function ( r ) {
  2147. var m = this.elements;
  2148. r[ 0 ] = m[ 0 ];
  2149. r[ 1 ] = m[ 3 ];
  2150. r[ 2 ] = m[ 6 ];
  2151. r[ 3 ] = m[ 1 ];
  2152. r[ 4 ] = m[ 4 ];
  2153. r[ 5 ] = m[ 7 ];
  2154. r[ 6 ] = m[ 2 ];
  2155. r[ 7 ] = m[ 5 ];
  2156. r[ 8 ] = m[ 8 ];
  2157. return this;
  2158. },
  2159. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  2160. var c = Math.cos( rotation );
  2161. var s = Math.sin( rotation );
  2162. this.set(
  2163. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  2164. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  2165. 0, 0, 1
  2166. );
  2167. },
  2168. scale: function ( sx, sy ) {
  2169. var te = this.elements;
  2170. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  2171. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  2172. return this;
  2173. },
  2174. rotate: function ( theta ) {
  2175. var c = Math.cos( theta );
  2176. var s = Math.sin( theta );
  2177. var te = this.elements;
  2178. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  2179. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  2180. te[ 0 ] = c * a11 + s * a21;
  2181. te[ 3 ] = c * a12 + s * a22;
  2182. te[ 6 ] = c * a13 + s * a23;
  2183. te[ 1 ] = - s * a11 + c * a21;
  2184. te[ 4 ] = - s * a12 + c * a22;
  2185. te[ 7 ] = - s * a13 + c * a23;
  2186. return this;
  2187. },
  2188. translate: function ( tx, ty ) {
  2189. var te = this.elements;
  2190. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  2191. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  2192. return this;
  2193. },
  2194. equals: function ( matrix ) {
  2195. var te = this.elements;
  2196. var me = matrix.elements;
  2197. for ( var i = 0; i < 9; i ++ ) {
  2198. if ( te[ i ] !== me[ i ] ) return false;
  2199. }
  2200. return true;
  2201. },
  2202. fromArray: function ( array, offset ) {
  2203. if ( offset === undefined ) offset = 0;
  2204. for ( var i = 0; i < 9; i ++ ) {
  2205. this.elements[ i ] = array[ i + offset ];
  2206. }
  2207. return this;
  2208. },
  2209. toArray: function ( array, offset ) {
  2210. if ( array === undefined ) array = [];
  2211. if ( offset === undefined ) offset = 0;
  2212. var te = this.elements;
  2213. array[ offset ] = te[ 0 ];
  2214. array[ offset + 1 ] = te[ 1 ];
  2215. array[ offset + 2 ] = te[ 2 ];
  2216. array[ offset + 3 ] = te[ 3 ];
  2217. array[ offset + 4 ] = te[ 4 ];
  2218. array[ offset + 5 ] = te[ 5 ];
  2219. array[ offset + 6 ] = te[ 6 ];
  2220. array[ offset + 7 ] = te[ 7 ];
  2221. array[ offset + 8 ] = te[ 8 ];
  2222. return array;
  2223. }
  2224. } );
  2225. /**
  2226. * @author mrdoob / http://mrdoob.com/
  2227. * @author alteredq / http://alteredqualia.com/
  2228. * @author szimek / https://github.com/szimek/
  2229. */
  2230. var _canvas;
  2231. var ImageUtils = {
  2232. getDataURL: function ( image ) {
  2233. var canvas;
  2234. if ( typeof HTMLCanvasElement == 'undefined' ) {
  2235. return image.src;
  2236. } else if ( image instanceof HTMLCanvasElement ) {
  2237. canvas = image;
  2238. } else {
  2239. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  2240. _canvas.width = image.width;
  2241. _canvas.height = image.height;
  2242. var context = _canvas.getContext( '2d' );
  2243. if ( image instanceof ImageData ) {
  2244. context.putImageData( image, 0, 0 );
  2245. } else {
  2246. context.drawImage( image, 0, 0, image.width, image.height );
  2247. }
  2248. canvas = _canvas;
  2249. }
  2250. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  2251. return canvas.toDataURL( 'image/jpeg', 0.6 );
  2252. } else {
  2253. return canvas.toDataURL( 'image/png' );
  2254. }
  2255. }
  2256. };
  2257. /**
  2258. * @author mrdoob / http://mrdoob.com/
  2259. * @author alteredq / http://alteredqualia.com/
  2260. * @author szimek / https://github.com/szimek/
  2261. */
  2262. var textureId = 0;
  2263. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2264. Object.defineProperty( this, 'id', { value: textureId ++ } );
  2265. this.uuid = _Math.generateUUID();
  2266. this.name = '';
  2267. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  2268. this.mipmaps = [];
  2269. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  2270. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  2271. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  2272. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  2273. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  2274. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  2275. this.format = format !== undefined ? format : RGBAFormat;
  2276. this.type = type !== undefined ? type : UnsignedByteType;
  2277. this.offset = new Vector2( 0, 0 );
  2278. this.repeat = new Vector2( 1, 1 );
  2279. this.center = new Vector2( 0, 0 );
  2280. this.rotation = 0;
  2281. this.matrixAutoUpdate = true;
  2282. this.matrix = new Matrix3();
  2283. this.generateMipmaps = true;
  2284. this.premultiplyAlpha = false;
  2285. this.flipY = true;
  2286. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  2287. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  2288. //
  2289. // Also changing the encoding after already used by a Material will not automatically make the Material
  2290. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  2291. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  2292. this.version = 0;
  2293. this.onUpdate = null;
  2294. }
  2295. Texture.DEFAULT_IMAGE = undefined;
  2296. Texture.DEFAULT_MAPPING = UVMapping;
  2297. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2298. constructor: Texture,
  2299. isTexture: true,
  2300. updateMatrix: function () {
  2301. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  2302. },
  2303. clone: function () {
  2304. return new this.constructor().copy( this );
  2305. },
  2306. copy: function ( source ) {
  2307. this.name = source.name;
  2308. this.image = source.image;
  2309. this.mipmaps = source.mipmaps.slice( 0 );
  2310. this.mapping = source.mapping;
  2311. this.wrapS = source.wrapS;
  2312. this.wrapT = source.wrapT;
  2313. this.magFilter = source.magFilter;
  2314. this.minFilter = source.minFilter;
  2315. this.anisotropy = source.anisotropy;
  2316. this.format = source.format;
  2317. this.type = source.type;
  2318. this.offset.copy( source.offset );
  2319. this.repeat.copy( source.repeat );
  2320. this.center.copy( source.center );
  2321. this.rotation = source.rotation;
  2322. this.matrixAutoUpdate = source.matrixAutoUpdate;
  2323. this.matrix.copy( source.matrix );
  2324. this.generateMipmaps = source.generateMipmaps;
  2325. this.premultiplyAlpha = source.premultiplyAlpha;
  2326. this.flipY = source.flipY;
  2327. this.unpackAlignment = source.unpackAlignment;
  2328. this.encoding = source.encoding;
  2329. return this;
  2330. },
  2331. toJSON: function ( meta ) {
  2332. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  2333. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  2334. return meta.textures[ this.uuid ];
  2335. }
  2336. var output = {
  2337. metadata: {
  2338. version: 4.5,
  2339. type: 'Texture',
  2340. generator: 'Texture.toJSON'
  2341. },
  2342. uuid: this.uuid,
  2343. name: this.name,
  2344. mapping: this.mapping,
  2345. repeat: [ this.repeat.x, this.repeat.y ],
  2346. offset: [ this.offset.x, this.offset.y ],
  2347. center: [ this.center.x, this.center.y ],
  2348. rotation: this.rotation,
  2349. wrap: [ this.wrapS, this.wrapT ],
  2350. format: this.format,
  2351. type: this.type,
  2352. encoding: this.encoding,
  2353. minFilter: this.minFilter,
  2354. magFilter: this.magFilter,
  2355. anisotropy: this.anisotropy,
  2356. flipY: this.flipY,
  2357. premultiplyAlpha: this.premultiplyAlpha,
  2358. unpackAlignment: this.unpackAlignment
  2359. };
  2360. if ( this.image !== undefined ) {
  2361. // TODO: Move to THREE.Image
  2362. var image = this.image;
  2363. if ( image.uuid === undefined ) {
  2364. image.uuid = _Math.generateUUID(); // UGH
  2365. }
  2366. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  2367. var url;
  2368. if ( Array.isArray( image ) ) {
  2369. // process array of images e.g. CubeTexture
  2370. url = [];
  2371. for ( var i = 0, l = image.length; i < l; i ++ ) {
  2372. url.push( ImageUtils.getDataURL( image[ i ] ) );
  2373. }
  2374. } else {
  2375. // process single image
  2376. url = ImageUtils.getDataURL( image );
  2377. }
  2378. meta.images[ image.uuid ] = {
  2379. uuid: image.uuid,
  2380. url: url
  2381. };
  2382. }
  2383. output.image = image.uuid;
  2384. }
  2385. if ( ! isRootObject ) {
  2386. meta.textures[ this.uuid ] = output;
  2387. }
  2388. return output;
  2389. },
  2390. dispose: function () {
  2391. this.dispatchEvent( { type: 'dispose' } );
  2392. },
  2393. transformUv: function ( uv ) {
  2394. if ( this.mapping !== UVMapping ) return uv;
  2395. uv.applyMatrix3( this.matrix );
  2396. if ( uv.x < 0 || uv.x > 1 ) {
  2397. switch ( this.wrapS ) {
  2398. case RepeatWrapping:
  2399. uv.x = uv.x - Math.floor( uv.x );
  2400. break;
  2401. case ClampToEdgeWrapping:
  2402. uv.x = uv.x < 0 ? 0 : 1;
  2403. break;
  2404. case MirroredRepeatWrapping:
  2405. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  2406. uv.x = Math.ceil( uv.x ) - uv.x;
  2407. } else {
  2408. uv.x = uv.x - Math.floor( uv.x );
  2409. }
  2410. break;
  2411. }
  2412. }
  2413. if ( uv.y < 0 || uv.y > 1 ) {
  2414. switch ( this.wrapT ) {
  2415. case RepeatWrapping:
  2416. uv.y = uv.y - Math.floor( uv.y );
  2417. break;
  2418. case ClampToEdgeWrapping:
  2419. uv.y = uv.y < 0 ? 0 : 1;
  2420. break;
  2421. case MirroredRepeatWrapping:
  2422. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  2423. uv.y = Math.ceil( uv.y ) - uv.y;
  2424. } else {
  2425. uv.y = uv.y - Math.floor( uv.y );
  2426. }
  2427. break;
  2428. }
  2429. }
  2430. if ( this.flipY ) {
  2431. uv.y = 1 - uv.y;
  2432. }
  2433. return uv;
  2434. }
  2435. } );
  2436. Object.defineProperty( Texture.prototype, "needsUpdate", {
  2437. set: function ( value ) {
  2438. if ( value === true ) this.version ++;
  2439. }
  2440. } );
  2441. /**
  2442. * @author supereggbert / http://www.paulbrunt.co.uk/
  2443. * @author philogb / http://blog.thejit.org/
  2444. * @author mikael emtinger / http://gomo.se/
  2445. * @author egraether / http://egraether.com/
  2446. * @author WestLangley / http://github.com/WestLangley
  2447. */
  2448. function Vector4( x, y, z, w ) {
  2449. this.x = x || 0;
  2450. this.y = y || 0;
  2451. this.z = z || 0;
  2452. this.w = ( w !== undefined ) ? w : 1;
  2453. }
  2454. Object.assign( Vector4.prototype, {
  2455. isVector4: true,
  2456. set: function ( x, y, z, w ) {
  2457. this.x = x;
  2458. this.y = y;
  2459. this.z = z;
  2460. this.w = w;
  2461. return this;
  2462. },
  2463. setScalar: function ( scalar ) {
  2464. this.x = scalar;
  2465. this.y = scalar;
  2466. this.z = scalar;
  2467. this.w = scalar;
  2468. return this;
  2469. },
  2470. setX: function ( x ) {
  2471. this.x = x;
  2472. return this;
  2473. },
  2474. setY: function ( y ) {
  2475. this.y = y;
  2476. return this;
  2477. },
  2478. setZ: function ( z ) {
  2479. this.z = z;
  2480. return this;
  2481. },
  2482. setW: function ( w ) {
  2483. this.w = w;
  2484. return this;
  2485. },
  2486. setComponent: function ( index, value ) {
  2487. switch ( index ) {
  2488. case 0: this.x = value; break;
  2489. case 1: this.y = value; break;
  2490. case 2: this.z = value; break;
  2491. case 3: this.w = value; break;
  2492. default: throw new Error( 'index is out of range: ' + index );
  2493. }
  2494. return this;
  2495. },
  2496. getComponent: function ( index ) {
  2497. switch ( index ) {
  2498. case 0: return this.x;
  2499. case 1: return this.y;
  2500. case 2: return this.z;
  2501. case 3: return this.w;
  2502. default: throw new Error( 'index is out of range: ' + index );
  2503. }
  2504. },
  2505. clone: function () {
  2506. return new this.constructor( this.x, this.y, this.z, this.w );
  2507. },
  2508. copy: function ( v ) {
  2509. this.x = v.x;
  2510. this.y = v.y;
  2511. this.z = v.z;
  2512. this.w = ( v.w !== undefined ) ? v.w : 1;
  2513. return this;
  2514. },
  2515. add: function ( v, w ) {
  2516. if ( w !== undefined ) {
  2517. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2518. return this.addVectors( v, w );
  2519. }
  2520. this.x += v.x;
  2521. this.y += v.y;
  2522. this.z += v.z;
  2523. this.w += v.w;
  2524. return this;
  2525. },
  2526. addScalar: function ( s ) {
  2527. this.x += s;
  2528. this.y += s;
  2529. this.z += s;
  2530. this.w += s;
  2531. return this;
  2532. },
  2533. addVectors: function ( a, b ) {
  2534. this.x = a.x + b.x;
  2535. this.y = a.y + b.y;
  2536. this.z = a.z + b.z;
  2537. this.w = a.w + b.w;
  2538. return this;
  2539. },
  2540. addScaledVector: function ( v, s ) {
  2541. this.x += v.x * s;
  2542. this.y += v.y * s;
  2543. this.z += v.z * s;
  2544. this.w += v.w * s;
  2545. return this;
  2546. },
  2547. sub: function ( v, w ) {
  2548. if ( w !== undefined ) {
  2549. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2550. return this.subVectors( v, w );
  2551. }
  2552. this.x -= v.x;
  2553. this.y -= v.y;
  2554. this.z -= v.z;
  2555. this.w -= v.w;
  2556. return this;
  2557. },
  2558. subScalar: function ( s ) {
  2559. this.x -= s;
  2560. this.y -= s;
  2561. this.z -= s;
  2562. this.w -= s;
  2563. return this;
  2564. },
  2565. subVectors: function ( a, b ) {
  2566. this.x = a.x - b.x;
  2567. this.y = a.y - b.y;
  2568. this.z = a.z - b.z;
  2569. this.w = a.w - b.w;
  2570. return this;
  2571. },
  2572. multiplyScalar: function ( scalar ) {
  2573. this.x *= scalar;
  2574. this.y *= scalar;
  2575. this.z *= scalar;
  2576. this.w *= scalar;
  2577. return this;
  2578. },
  2579. applyMatrix4: function ( m ) {
  2580. var x = this.x, y = this.y, z = this.z, w = this.w;
  2581. var e = m.elements;
  2582. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2583. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2584. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2585. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2586. return this;
  2587. },
  2588. divideScalar: function ( scalar ) {
  2589. return this.multiplyScalar( 1 / scalar );
  2590. },
  2591. setAxisAngleFromQuaternion: function ( q ) {
  2592. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2593. // q is assumed to be normalized
  2594. this.w = 2 * Math.acos( q.w );
  2595. var s = Math.sqrt( 1 - q.w * q.w );
  2596. if ( s < 0.0001 ) {
  2597. this.x = 1;
  2598. this.y = 0;
  2599. this.z = 0;
  2600. } else {
  2601. this.x = q.x / s;
  2602. this.y = q.y / s;
  2603. this.z = q.z / s;
  2604. }
  2605. return this;
  2606. },
  2607. setAxisAngleFromRotationMatrix: function ( m ) {
  2608. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2609. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2610. var angle, x, y, z, // variables for result
  2611. epsilon = 0.01, // margin to allow for rounding errors
  2612. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2613. te = m.elements,
  2614. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2615. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2616. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2617. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2618. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2619. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2620. // singularity found
  2621. // first check for identity matrix which must have +1 for all terms
  2622. // in leading diagonal and zero in other terms
  2623. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2624. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2625. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2626. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2627. // this singularity is identity matrix so angle = 0
  2628. this.set( 1, 0, 0, 0 );
  2629. return this; // zero angle, arbitrary axis
  2630. }
  2631. // otherwise this singularity is angle = 180
  2632. angle = Math.PI;
  2633. var xx = ( m11 + 1 ) / 2;
  2634. var yy = ( m22 + 1 ) / 2;
  2635. var zz = ( m33 + 1 ) / 2;
  2636. var xy = ( m12 + m21 ) / 4;
  2637. var xz = ( m13 + m31 ) / 4;
  2638. var yz = ( m23 + m32 ) / 4;
  2639. if ( ( xx > yy ) && ( xx > zz ) ) {
  2640. // m11 is the largest diagonal term
  2641. if ( xx < epsilon ) {
  2642. x = 0;
  2643. y = 0.707106781;
  2644. z = 0.707106781;
  2645. } else {
  2646. x = Math.sqrt( xx );
  2647. y = xy / x;
  2648. z = xz / x;
  2649. }
  2650. } else if ( yy > zz ) {
  2651. // m22 is the largest diagonal term
  2652. if ( yy < epsilon ) {
  2653. x = 0.707106781;
  2654. y = 0;
  2655. z = 0.707106781;
  2656. } else {
  2657. y = Math.sqrt( yy );
  2658. x = xy / y;
  2659. z = yz / y;
  2660. }
  2661. } else {
  2662. // m33 is the largest diagonal term so base result on this
  2663. if ( zz < epsilon ) {
  2664. x = 0.707106781;
  2665. y = 0.707106781;
  2666. z = 0;
  2667. } else {
  2668. z = Math.sqrt( zz );
  2669. x = xz / z;
  2670. y = yz / z;
  2671. }
  2672. }
  2673. this.set( x, y, z, angle );
  2674. return this; // return 180 deg rotation
  2675. }
  2676. // as we have reached here there are no singularities so we can handle normally
  2677. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2678. ( m13 - m31 ) * ( m13 - m31 ) +
  2679. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2680. if ( Math.abs( s ) < 0.001 ) s = 1;
  2681. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2682. // caught by singularity test above, but I've left it in just in case
  2683. this.x = ( m32 - m23 ) / s;
  2684. this.y = ( m13 - m31 ) / s;
  2685. this.z = ( m21 - m12 ) / s;
  2686. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2687. return this;
  2688. },
  2689. min: function ( v ) {
  2690. this.x = Math.min( this.x, v.x );
  2691. this.y = Math.min( this.y, v.y );
  2692. this.z = Math.min( this.z, v.z );
  2693. this.w = Math.min( this.w, v.w );
  2694. return this;
  2695. },
  2696. max: function ( v ) {
  2697. this.x = Math.max( this.x, v.x );
  2698. this.y = Math.max( this.y, v.y );
  2699. this.z = Math.max( this.z, v.z );
  2700. this.w = Math.max( this.w, v.w );
  2701. return this;
  2702. },
  2703. clamp: function ( min, max ) {
  2704. // assumes min < max, componentwise
  2705. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2706. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2707. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2708. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2709. return this;
  2710. },
  2711. clampScalar: function () {
  2712. var min, max;
  2713. return function clampScalar( minVal, maxVal ) {
  2714. if ( min === undefined ) {
  2715. min = new Vector4();
  2716. max = new Vector4();
  2717. }
  2718. min.set( minVal, minVal, minVal, minVal );
  2719. max.set( maxVal, maxVal, maxVal, maxVal );
  2720. return this.clamp( min, max );
  2721. };
  2722. }(),
  2723. clampLength: function ( min, max ) {
  2724. var length = this.length();
  2725. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2726. },
  2727. floor: function () {
  2728. this.x = Math.floor( this.x );
  2729. this.y = Math.floor( this.y );
  2730. this.z = Math.floor( this.z );
  2731. this.w = Math.floor( this.w );
  2732. return this;
  2733. },
  2734. ceil: function () {
  2735. this.x = Math.ceil( this.x );
  2736. this.y = Math.ceil( this.y );
  2737. this.z = Math.ceil( this.z );
  2738. this.w = Math.ceil( this.w );
  2739. return this;
  2740. },
  2741. round: function () {
  2742. this.x = Math.round( this.x );
  2743. this.y = Math.round( this.y );
  2744. this.z = Math.round( this.z );
  2745. this.w = Math.round( this.w );
  2746. return this;
  2747. },
  2748. roundToZero: function () {
  2749. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2750. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2751. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2752. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2753. return this;
  2754. },
  2755. negate: function () {
  2756. this.x = - this.x;
  2757. this.y = - this.y;
  2758. this.z = - this.z;
  2759. this.w = - this.w;
  2760. return this;
  2761. },
  2762. dot: function ( v ) {
  2763. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2764. },
  2765. lengthSq: function () {
  2766. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2767. },
  2768. length: function () {
  2769. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2770. },
  2771. manhattanLength: function () {
  2772. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2773. },
  2774. normalize: function () {
  2775. return this.divideScalar( this.length() || 1 );
  2776. },
  2777. setLength: function ( length ) {
  2778. return this.normalize().multiplyScalar( length );
  2779. },
  2780. lerp: function ( v, alpha ) {
  2781. this.x += ( v.x - this.x ) * alpha;
  2782. this.y += ( v.y - this.y ) * alpha;
  2783. this.z += ( v.z - this.z ) * alpha;
  2784. this.w += ( v.w - this.w ) * alpha;
  2785. return this;
  2786. },
  2787. lerpVectors: function ( v1, v2, alpha ) {
  2788. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2789. },
  2790. equals: function ( v ) {
  2791. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2792. },
  2793. fromArray: function ( array, offset ) {
  2794. if ( offset === undefined ) offset = 0;
  2795. this.x = array[ offset ];
  2796. this.y = array[ offset + 1 ];
  2797. this.z = array[ offset + 2 ];
  2798. this.w = array[ offset + 3 ];
  2799. return this;
  2800. },
  2801. toArray: function ( array, offset ) {
  2802. if ( array === undefined ) array = [];
  2803. if ( offset === undefined ) offset = 0;
  2804. array[ offset ] = this.x;
  2805. array[ offset + 1 ] = this.y;
  2806. array[ offset + 2 ] = this.z;
  2807. array[ offset + 3 ] = this.w;
  2808. return array;
  2809. },
  2810. fromBufferAttribute: function ( attribute, index, offset ) {
  2811. if ( offset !== undefined ) {
  2812. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2813. }
  2814. this.x = attribute.getX( index );
  2815. this.y = attribute.getY( index );
  2816. this.z = attribute.getZ( index );
  2817. this.w = attribute.getW( index );
  2818. return this;
  2819. }
  2820. } );
  2821. /**
  2822. * @author szimek / https://github.com/szimek/
  2823. * @author alteredq / http://alteredqualia.com/
  2824. * @author Marius Kintel / https://github.com/kintel
  2825. */
  2826. /*
  2827. In options, we can specify:
  2828. * Texture parameters for an auto-generated target texture
  2829. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2830. */
  2831. function WebGLRenderTarget( width, height, options ) {
  2832. this.width = width;
  2833. this.height = height;
  2834. this.scissor = new Vector4( 0, 0, width, height );
  2835. this.scissorTest = false;
  2836. this.viewport = new Vector4( 0, 0, width, height );
  2837. options = options || {};
  2838. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2839. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2840. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2841. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2842. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2843. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2844. }
  2845. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2846. constructor: WebGLRenderTarget,
  2847. isWebGLRenderTarget: true,
  2848. setSize: function ( width, height ) {
  2849. if ( this.width !== width || this.height !== height ) {
  2850. this.width = width;
  2851. this.height = height;
  2852. this.dispose();
  2853. }
  2854. this.viewport.set( 0, 0, width, height );
  2855. this.scissor.set( 0, 0, width, height );
  2856. },
  2857. clone: function () {
  2858. return new this.constructor().copy( this );
  2859. },
  2860. copy: function ( source ) {
  2861. this.width = source.width;
  2862. this.height = source.height;
  2863. this.viewport.copy( source.viewport );
  2864. this.texture = source.texture.clone();
  2865. this.depthBuffer = source.depthBuffer;
  2866. this.stencilBuffer = source.stencilBuffer;
  2867. this.depthTexture = source.depthTexture;
  2868. return this;
  2869. },
  2870. dispose: function () {
  2871. this.dispatchEvent( { type: 'dispose' } );
  2872. }
  2873. } );
  2874. /**
  2875. * @author Mugen87 / https://github.com/Mugen87
  2876. * @author Matt DesLauriers / @mattdesl
  2877. */
  2878. function WebGLMultisampleRenderTarget( width, height, options ) {
  2879. WebGLRenderTarget.call( this, width, height, options );
  2880. this.samples = 4;
  2881. }
  2882. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2883. constructor: WebGLMultisampleRenderTarget,
  2884. isWebGLMultisampleRenderTarget: true,
  2885. copy: function ( source ) {
  2886. WebGLRenderTarget.prototype.copy.call( this, source );
  2887. this.samples = source.samples;
  2888. return this;
  2889. }
  2890. } );
  2891. /**
  2892. * @author alteredq / http://alteredqualia.com
  2893. */
  2894. function WebGLRenderTargetCube( width, height, options ) {
  2895. WebGLRenderTarget.call( this, width, height, options );
  2896. }
  2897. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2898. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2899. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2900. /**
  2901. * @author alteredq / http://alteredqualia.com/
  2902. */
  2903. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2904. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2905. this.image = { data: data, width: width, height: height };
  2906. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2907. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2908. this.generateMipmaps = false;
  2909. this.flipY = false;
  2910. this.unpackAlignment = 1;
  2911. }
  2912. DataTexture.prototype = Object.create( Texture.prototype );
  2913. DataTexture.prototype.constructor = DataTexture;
  2914. DataTexture.prototype.isDataTexture = true;
  2915. /**
  2916. * @author bhouston / http://clara.io
  2917. * @author WestLangley / http://github.com/WestLangley
  2918. */
  2919. function Box3( min, max ) {
  2920. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2921. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2922. }
  2923. Object.assign( Box3.prototype, {
  2924. isBox3: true,
  2925. set: function ( min, max ) {
  2926. this.min.copy( min );
  2927. this.max.copy( max );
  2928. return this;
  2929. },
  2930. setFromArray: function ( array ) {
  2931. var minX = + Infinity;
  2932. var minY = + Infinity;
  2933. var minZ = + Infinity;
  2934. var maxX = - Infinity;
  2935. var maxY = - Infinity;
  2936. var maxZ = - Infinity;
  2937. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2938. var x = array[ i ];
  2939. var y = array[ i + 1 ];
  2940. var z = array[ i + 2 ];
  2941. if ( x < minX ) minX = x;
  2942. if ( y < minY ) minY = y;
  2943. if ( z < minZ ) minZ = z;
  2944. if ( x > maxX ) maxX = x;
  2945. if ( y > maxY ) maxY = y;
  2946. if ( z > maxZ ) maxZ = z;
  2947. }
  2948. this.min.set( minX, minY, minZ );
  2949. this.max.set( maxX, maxY, maxZ );
  2950. return this;
  2951. },
  2952. setFromBufferAttribute: function ( attribute ) {
  2953. var minX = + Infinity;
  2954. var minY = + Infinity;
  2955. var minZ = + Infinity;
  2956. var maxX = - Infinity;
  2957. var maxY = - Infinity;
  2958. var maxZ = - Infinity;
  2959. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2960. var x = attribute.getX( i );
  2961. var y = attribute.getY( i );
  2962. var z = attribute.getZ( i );
  2963. if ( x < minX ) minX = x;
  2964. if ( y < minY ) minY = y;
  2965. if ( z < minZ ) minZ = z;
  2966. if ( x > maxX ) maxX = x;
  2967. if ( y > maxY ) maxY = y;
  2968. if ( z > maxZ ) maxZ = z;
  2969. }
  2970. this.min.set( minX, minY, minZ );
  2971. this.max.set( maxX, maxY, maxZ );
  2972. return this;
  2973. },
  2974. setFromPoints: function ( points ) {
  2975. this.makeEmpty();
  2976. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2977. this.expandByPoint( points[ i ] );
  2978. }
  2979. return this;
  2980. },
  2981. setFromCenterAndSize: function () {
  2982. var v1 = new Vector3();
  2983. return function setFromCenterAndSize( center, size ) {
  2984. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2985. this.min.copy( center ).sub( halfSize );
  2986. this.max.copy( center ).add( halfSize );
  2987. return this;
  2988. };
  2989. }(),
  2990. setFromObject: function ( object ) {
  2991. this.makeEmpty();
  2992. return this.expandByObject( object );
  2993. },
  2994. clone: function () {
  2995. return new this.constructor().copy( this );
  2996. },
  2997. copy: function ( box ) {
  2998. this.min.copy( box.min );
  2999. this.max.copy( box.max );
  3000. return this;
  3001. },
  3002. makeEmpty: function () {
  3003. this.min.x = this.min.y = this.min.z = + Infinity;
  3004. this.max.x = this.max.y = this.max.z = - Infinity;
  3005. return this;
  3006. },
  3007. isEmpty: function () {
  3008. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3009. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3010. },
  3011. getCenter: function ( target ) {
  3012. if ( target === undefined ) {
  3013. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3014. target = new Vector3();
  3015. }
  3016. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3017. },
  3018. getSize: function ( target ) {
  3019. if ( target === undefined ) {
  3020. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3021. target = new Vector3();
  3022. }
  3023. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3024. },
  3025. expandByPoint: function ( point ) {
  3026. this.min.min( point );
  3027. this.max.max( point );
  3028. return this;
  3029. },
  3030. expandByVector: function ( vector ) {
  3031. this.min.sub( vector );
  3032. this.max.add( vector );
  3033. return this;
  3034. },
  3035. expandByScalar: function ( scalar ) {
  3036. this.min.addScalar( - scalar );
  3037. this.max.addScalar( scalar );
  3038. return this;
  3039. },
  3040. expandByObject: function () {
  3041. // Computes the world-axis-aligned bounding box of an object (including its children),
  3042. // accounting for both the object's, and children's, world transforms
  3043. var scope, i, l;
  3044. var v1 = new Vector3();
  3045. function traverse( node ) {
  3046. var geometry = node.geometry;
  3047. if ( geometry !== undefined ) {
  3048. if ( geometry.isGeometry ) {
  3049. var vertices = geometry.vertices;
  3050. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3051. v1.copy( vertices[ i ] );
  3052. v1.applyMatrix4( node.matrixWorld );
  3053. scope.expandByPoint( v1 );
  3054. }
  3055. } else if ( geometry.isBufferGeometry ) {
  3056. var attribute = geometry.attributes.position;
  3057. if ( attribute !== undefined ) {
  3058. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3059. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  3060. scope.expandByPoint( v1 );
  3061. }
  3062. }
  3063. }
  3064. }
  3065. }
  3066. return function expandByObject( object ) {
  3067. scope = this;
  3068. object.updateMatrixWorld( true );
  3069. object.traverse( traverse );
  3070. return this;
  3071. };
  3072. }(),
  3073. containsPoint: function ( point ) {
  3074. return point.x < this.min.x || point.x > this.max.x ||
  3075. point.y < this.min.y || point.y > this.max.y ||
  3076. point.z < this.min.z || point.z > this.max.z ? false : true;
  3077. },
  3078. containsBox: function ( box ) {
  3079. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3080. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3081. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3082. },
  3083. getParameter: function ( point, target ) {
  3084. // This can potentially have a divide by zero if the box
  3085. // has a size dimension of 0.
  3086. if ( target === undefined ) {
  3087. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3088. target = new Vector3();
  3089. }
  3090. return target.set(
  3091. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3092. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3093. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3094. );
  3095. },
  3096. intersectsBox: function ( box ) {
  3097. // using 6 splitting planes to rule out intersections.
  3098. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3099. box.max.y < this.min.y || box.min.y > this.max.y ||
  3100. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3101. },
  3102. intersectsSphere: ( function () {
  3103. var closestPoint = new Vector3();
  3104. return function intersectsSphere( sphere ) {
  3105. // Find the point on the AABB closest to the sphere center.
  3106. this.clampPoint( sphere.center, closestPoint );
  3107. // If that point is inside the sphere, the AABB and sphere intersect.
  3108. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3109. };
  3110. } )(),
  3111. intersectsPlane: function ( plane ) {
  3112. // We compute the minimum and maximum dot product values. If those values
  3113. // are on the same side (back or front) of the plane, then there is no intersection.
  3114. var min, max;
  3115. if ( plane.normal.x > 0 ) {
  3116. min = plane.normal.x * this.min.x;
  3117. max = plane.normal.x * this.max.x;
  3118. } else {
  3119. min = plane.normal.x * this.max.x;
  3120. max = plane.normal.x * this.min.x;
  3121. }
  3122. if ( plane.normal.y > 0 ) {
  3123. min += plane.normal.y * this.min.y;
  3124. max += plane.normal.y * this.max.y;
  3125. } else {
  3126. min += plane.normal.y * this.max.y;
  3127. max += plane.normal.y * this.min.y;
  3128. }
  3129. if ( plane.normal.z > 0 ) {
  3130. min += plane.normal.z * this.min.z;
  3131. max += plane.normal.z * this.max.z;
  3132. } else {
  3133. min += plane.normal.z * this.max.z;
  3134. max += plane.normal.z * this.min.z;
  3135. }
  3136. return ( min <= - plane.constant && max >= - plane.constant );
  3137. },
  3138. intersectsTriangle: ( function () {
  3139. // triangle centered vertices
  3140. var v0 = new Vector3();
  3141. var v1 = new Vector3();
  3142. var v2 = new Vector3();
  3143. // triangle edge vectors
  3144. var f0 = new Vector3();
  3145. var f1 = new Vector3();
  3146. var f2 = new Vector3();
  3147. var testAxis = new Vector3();
  3148. var center = new Vector3();
  3149. var extents = new Vector3();
  3150. var triangleNormal = new Vector3();
  3151. function satForAxes( axes ) {
  3152. var i, j;
  3153. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3154. testAxis.fromArray( axes, i );
  3155. // project the aabb onto the seperating axis
  3156. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3157. // project all 3 vertices of the triangle onto the seperating axis
  3158. var p0 = v0.dot( testAxis );
  3159. var p1 = v1.dot( testAxis );
  3160. var p2 = v2.dot( testAxis );
  3161. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3162. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3163. // points of the projected triangle are outside the projected half-length of the aabb
  3164. // the axis is seperating and we can exit
  3165. return false;
  3166. }
  3167. }
  3168. return true;
  3169. }
  3170. return function intersectsTriangle( triangle ) {
  3171. if ( this.isEmpty() ) {
  3172. return false;
  3173. }
  3174. // compute box center and extents
  3175. this.getCenter( center );
  3176. extents.subVectors( this.max, center );
  3177. // translate triangle to aabb origin
  3178. v0.subVectors( triangle.a, center );
  3179. v1.subVectors( triangle.b, center );
  3180. v2.subVectors( triangle.c, center );
  3181. // compute edge vectors for triangle
  3182. f0.subVectors( v1, v0 );
  3183. f1.subVectors( v2, v1 );
  3184. f2.subVectors( v0, v2 );
  3185. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3186. // 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
  3187. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3188. var axes = [
  3189. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3190. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3191. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3192. ];
  3193. if ( ! satForAxes( axes ) ) {
  3194. return false;
  3195. }
  3196. // test 3 face normals from the aabb
  3197. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3198. if ( ! satForAxes( axes ) ) {
  3199. return false;
  3200. }
  3201. // finally testing the face normal of the triangle
  3202. // use already existing triangle edge vectors here
  3203. triangleNormal.crossVectors( f0, f1 );
  3204. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3205. return satForAxes( axes );
  3206. };
  3207. } )(),
  3208. clampPoint: function ( point, target ) {
  3209. if ( target === undefined ) {
  3210. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3211. target = new Vector3();
  3212. }
  3213. return target.copy( point ).clamp( this.min, this.max );
  3214. },
  3215. distanceToPoint: function () {
  3216. var v1 = new Vector3();
  3217. return function distanceToPoint( point ) {
  3218. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3219. return clampedPoint.sub( point ).length();
  3220. };
  3221. }(),
  3222. getBoundingSphere: function () {
  3223. var v1 = new Vector3();
  3224. return function getBoundingSphere( target ) {
  3225. if ( target === undefined ) {
  3226. console.warn( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3227. target = new Sphere();
  3228. }
  3229. this.getCenter( target.center );
  3230. target.radius = this.getSize( v1 ).length() * 0.5;
  3231. return target;
  3232. };
  3233. }(),
  3234. intersect: function ( box ) {
  3235. this.min.max( box.min );
  3236. this.max.min( box.max );
  3237. // 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.
  3238. if ( this.isEmpty() ) this.makeEmpty();
  3239. return this;
  3240. },
  3241. union: function ( box ) {
  3242. this.min.min( box.min );
  3243. this.max.max( box.max );
  3244. return this;
  3245. },
  3246. applyMatrix4: function () {
  3247. var points = [
  3248. new Vector3(),
  3249. new Vector3(),
  3250. new Vector3(),
  3251. new Vector3(),
  3252. new Vector3(),
  3253. new Vector3(),
  3254. new Vector3(),
  3255. new Vector3()
  3256. ];
  3257. return function applyMatrix4( matrix ) {
  3258. // transform of empty box is an empty box.
  3259. if ( this.isEmpty() ) return this;
  3260. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3261. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3262. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3263. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3264. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3265. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3266. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3267. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3268. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3269. this.setFromPoints( points );
  3270. return this;
  3271. };
  3272. }(),
  3273. translate: function ( offset ) {
  3274. this.min.add( offset );
  3275. this.max.add( offset );
  3276. return this;
  3277. },
  3278. equals: function ( box ) {
  3279. return box.min.equals( this.min ) && box.max.equals( this.max );
  3280. }
  3281. } );
  3282. /**
  3283. * @author bhouston / http://clara.io
  3284. * @author mrdoob / http://mrdoob.com/
  3285. */
  3286. function Sphere( center, radius ) {
  3287. this.center = ( center !== undefined ) ? center : new Vector3();
  3288. this.radius = ( radius !== undefined ) ? radius : 0;
  3289. }
  3290. Object.assign( Sphere.prototype, {
  3291. set: function ( center, radius ) {
  3292. this.center.copy( center );
  3293. this.radius = radius;
  3294. return this;
  3295. },
  3296. setFromPoints: function () {
  3297. var box = new Box3();
  3298. return function setFromPoints( points, optionalCenter ) {
  3299. var center = this.center;
  3300. if ( optionalCenter !== undefined ) {
  3301. center.copy( optionalCenter );
  3302. } else {
  3303. box.setFromPoints( points ).getCenter( center );
  3304. }
  3305. var maxRadiusSq = 0;
  3306. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3307. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3308. }
  3309. this.radius = Math.sqrt( maxRadiusSq );
  3310. return this;
  3311. };
  3312. }(),
  3313. clone: function () {
  3314. return new this.constructor().copy( this );
  3315. },
  3316. copy: function ( sphere ) {
  3317. this.center.copy( sphere.center );
  3318. this.radius = sphere.radius;
  3319. return this;
  3320. },
  3321. empty: function () {
  3322. return ( this.radius <= 0 );
  3323. },
  3324. containsPoint: function ( point ) {
  3325. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3326. },
  3327. distanceToPoint: function ( point ) {
  3328. return ( point.distanceTo( this.center ) - this.radius );
  3329. },
  3330. intersectsSphere: function ( sphere ) {
  3331. var radiusSum = this.radius + sphere.radius;
  3332. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3333. },
  3334. intersectsBox: function ( box ) {
  3335. return box.intersectsSphere( this );
  3336. },
  3337. intersectsPlane: function ( plane ) {
  3338. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3339. },
  3340. clampPoint: function ( point, target ) {
  3341. var deltaLengthSq = this.center.distanceToSquared( point );
  3342. if ( target === undefined ) {
  3343. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  3344. target = new Vector3();
  3345. }
  3346. target.copy( point );
  3347. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3348. target.sub( this.center ).normalize();
  3349. target.multiplyScalar( this.radius ).add( this.center );
  3350. }
  3351. return target;
  3352. },
  3353. getBoundingBox: function ( target ) {
  3354. if ( target === undefined ) {
  3355. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  3356. target = new Box3();
  3357. }
  3358. target.set( this.center, this.center );
  3359. target.expandByScalar( this.radius );
  3360. return target;
  3361. },
  3362. applyMatrix4: function ( matrix ) {
  3363. this.center.applyMatrix4( matrix );
  3364. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3365. return this;
  3366. },
  3367. translate: function ( offset ) {
  3368. this.center.add( offset );
  3369. return this;
  3370. },
  3371. equals: function ( sphere ) {
  3372. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3373. }
  3374. } );
  3375. /**
  3376. * @author bhouston / http://clara.io
  3377. */
  3378. function Plane( normal, constant ) {
  3379. // normal is assumed to be normalized
  3380. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  3381. this.constant = ( constant !== undefined ) ? constant : 0;
  3382. }
  3383. Object.assign( Plane.prototype, {
  3384. set: function ( normal, constant ) {
  3385. this.normal.copy( normal );
  3386. this.constant = constant;
  3387. return this;
  3388. },
  3389. setComponents: function ( x, y, z, w ) {
  3390. this.normal.set( x, y, z );
  3391. this.constant = w;
  3392. return this;
  3393. },
  3394. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3395. this.normal.copy( normal );
  3396. this.constant = - point.dot( this.normal );
  3397. return this;
  3398. },
  3399. setFromCoplanarPoints: function () {
  3400. var v1 = new Vector3();
  3401. var v2 = new Vector3();
  3402. return function setFromCoplanarPoints( a, b, c ) {
  3403. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3404. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3405. this.setFromNormalAndCoplanarPoint( normal, a );
  3406. return this;
  3407. };
  3408. }(),
  3409. clone: function () {
  3410. return new this.constructor().copy( this );
  3411. },
  3412. copy: function ( plane ) {
  3413. this.normal.copy( plane.normal );
  3414. this.constant = plane.constant;
  3415. return this;
  3416. },
  3417. normalize: function () {
  3418. // Note: will lead to a divide by zero if the plane is invalid.
  3419. var inverseNormalLength = 1.0 / this.normal.length();
  3420. this.normal.multiplyScalar( inverseNormalLength );
  3421. this.constant *= inverseNormalLength;
  3422. return this;
  3423. },
  3424. negate: function () {
  3425. this.constant *= - 1;
  3426. this.normal.negate();
  3427. return this;
  3428. },
  3429. distanceToPoint: function ( point ) {
  3430. return this.normal.dot( point ) + this.constant;
  3431. },
  3432. distanceToSphere: function ( sphere ) {
  3433. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3434. },
  3435. projectPoint: function ( point, target ) {
  3436. if ( target === undefined ) {
  3437. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  3438. target = new Vector3();
  3439. }
  3440. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  3441. },
  3442. intersectLine: function () {
  3443. var v1 = new Vector3();
  3444. return function intersectLine( line, target ) {
  3445. if ( target === undefined ) {
  3446. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  3447. target = new Vector3();
  3448. }
  3449. var direction = line.delta( v1 );
  3450. var denominator = this.normal.dot( direction );
  3451. if ( denominator === 0 ) {
  3452. // line is coplanar, return origin
  3453. if ( this.distanceToPoint( line.start ) === 0 ) {
  3454. return target.copy( line.start );
  3455. }
  3456. // Unsure if this is the correct method to handle this case.
  3457. return undefined;
  3458. }
  3459. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3460. if ( t < 0 || t > 1 ) {
  3461. return undefined;
  3462. }
  3463. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  3464. };
  3465. }(),
  3466. intersectsLine: function ( line ) {
  3467. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3468. var startSign = this.distanceToPoint( line.start );
  3469. var endSign = this.distanceToPoint( line.end );
  3470. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3471. },
  3472. intersectsBox: function ( box ) {
  3473. return box.intersectsPlane( this );
  3474. },
  3475. intersectsSphere: function ( sphere ) {
  3476. return sphere.intersectsPlane( this );
  3477. },
  3478. coplanarPoint: function ( target ) {
  3479. if ( target === undefined ) {
  3480. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  3481. target = new Vector3();
  3482. }
  3483. return target.copy( this.normal ).multiplyScalar( - this.constant );
  3484. },
  3485. applyMatrix4: function () {
  3486. var v1 = new Vector3();
  3487. var m1 = new Matrix3();
  3488. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  3489. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3490. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  3491. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  3492. this.constant = - referencePoint.dot( normal );
  3493. return this;
  3494. };
  3495. }(),
  3496. translate: function ( offset ) {
  3497. this.constant -= offset.dot( this.normal );
  3498. return this;
  3499. },
  3500. equals: function ( plane ) {
  3501. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3502. }
  3503. } );
  3504. /**
  3505. * @author mrdoob / http://mrdoob.com/
  3506. * @author alteredq / http://alteredqualia.com/
  3507. * @author bhouston / http://clara.io
  3508. */
  3509. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  3510. this.planes = [
  3511. ( p0 !== undefined ) ? p0 : new Plane(),
  3512. ( p1 !== undefined ) ? p1 : new Plane(),
  3513. ( p2 !== undefined ) ? p2 : new Plane(),
  3514. ( p3 !== undefined ) ? p3 : new Plane(),
  3515. ( p4 !== undefined ) ? p4 : new Plane(),
  3516. ( p5 !== undefined ) ? p5 : new Plane()
  3517. ];
  3518. }
  3519. Object.assign( Frustum.prototype, {
  3520. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3521. var planes = this.planes;
  3522. planes[ 0 ].copy( p0 );
  3523. planes[ 1 ].copy( p1 );
  3524. planes[ 2 ].copy( p2 );
  3525. planes[ 3 ].copy( p3 );
  3526. planes[ 4 ].copy( p4 );
  3527. planes[ 5 ].copy( p5 );
  3528. return this;
  3529. },
  3530. clone: function () {
  3531. return new this.constructor().copy( this );
  3532. },
  3533. copy: function ( frustum ) {
  3534. var planes = this.planes;
  3535. for ( var i = 0; i < 6; i ++ ) {
  3536. planes[ i ].copy( frustum.planes[ i ] );
  3537. }
  3538. return this;
  3539. },
  3540. setFromMatrix: function ( m ) {
  3541. var planes = this.planes;
  3542. var me = m.elements;
  3543. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3544. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3545. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3546. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3547. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3548. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3549. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3550. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3551. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3552. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3553. return this;
  3554. },
  3555. intersectsObject: function () {
  3556. var sphere = new Sphere();
  3557. return function intersectsObject( object ) {
  3558. var geometry = object.geometry;
  3559. if ( geometry.boundingSphere === null )
  3560. geometry.computeBoundingSphere();
  3561. sphere.copy( geometry.boundingSphere )
  3562. .applyMatrix4( object.matrixWorld );
  3563. return this.intersectsSphere( sphere );
  3564. };
  3565. }(),
  3566. intersectsSprite: function () {
  3567. var sphere = new Sphere();
  3568. return function intersectsSprite( sprite ) {
  3569. sphere.center.set( 0, 0, 0 );
  3570. sphere.radius = 0.7071067811865476;
  3571. sphere.applyMatrix4( sprite.matrixWorld );
  3572. return this.intersectsSphere( sphere );
  3573. };
  3574. }(),
  3575. intersectsSphere: function ( sphere ) {
  3576. var planes = this.planes;
  3577. var center = sphere.center;
  3578. var negRadius = - sphere.radius;
  3579. for ( var i = 0; i < 6; i ++ ) {
  3580. var distance = planes[ i ].distanceToPoint( center );
  3581. if ( distance < negRadius ) {
  3582. return false;
  3583. }
  3584. }
  3585. return true;
  3586. },
  3587. intersectsBox: function () {
  3588. var p = new Vector3();
  3589. return function intersectsBox( box ) {
  3590. var planes = this.planes;
  3591. for ( var i = 0; i < 6; i ++ ) {
  3592. var plane = planes[ i ];
  3593. // corner at max distance
  3594. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3595. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3596. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3597. if ( plane.distanceToPoint( p ) < 0 ) {
  3598. return false;
  3599. }
  3600. }
  3601. return true;
  3602. };
  3603. }(),
  3604. containsPoint: function ( point ) {
  3605. var planes = this.planes;
  3606. for ( var i = 0; i < 6; i ++ ) {
  3607. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3608. return false;
  3609. }
  3610. }
  3611. return true;
  3612. }
  3613. } );
  3614. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  3615. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  3616. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  3617. 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";
  3618. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3619. var begin_vertex = "vec3 transformed = vec3( position );";
  3620. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  3621. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\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\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick( specularColor, dotNV );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}";
  3622. 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";
  3623. 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";
  3624. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  3625. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  3626. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  3627. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3628. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3629. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3630. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3631. 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}";
  3632. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV( sampler2D envMap, vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif";
  3633. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = normalMatrix * objectTangent;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  3634. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  3635. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  3636. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  3637. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  3638. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  3639. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = min( floor( D ) / 255.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
  3640. 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";
  3641. 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";
  3642. 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";
  3643. 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";
  3644. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  3645. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  3646. 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";
  3647. 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";
  3648. 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";
  3649. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  3650. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3651. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n#endif";
  3652. 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";
  3653. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, queryVec, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in 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( envMap, queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent ));\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  3654. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  3655. 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)";
  3656. 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";
  3657. 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\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#endif\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifndef STANDARD\n\t\tfloat 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\tfloat clearCoatInv = 1.0 - clearCoatDHR;\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 singleScattering = vec3( 0.0 );\n\t\tvec3 multiScattering = vec3( 0.0 );\n\t\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\t\tvec3 diffuse = material.diffuseColor;\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;\n\t\treflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;\n\t\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\t#else\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#endif\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}";
  3658. 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";
  3659. 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";
  3660. var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, irradiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif";
  3661. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3662. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  3663. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  3664. 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";
  3665. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  3666. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  3667. 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";
  3668. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  3669. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  3670. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3671. 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";
  3672. 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";
  3673. 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";
  3674. var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t#endif\n#endif";
  3675. var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t#ifdef FLIP_SIDED\n\t\t\tnormal = - normal;\n\t\t#endif\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\tnormal = normalize( normalMatrix * normal );\n\t#else\n\t\t#ifdef USE_TANGENT\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy = normalScale * mapN.xy;\n\t\t\tnormal = normalize( vTBN * mapN );\n\t\t#else\n\t\t\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n\t\t#endif\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  3676. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tuniform mat3 normalMatrix;\n\t#else\n\t\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\t\tvec2 st0 = dFdx( vUv.st );\n\t\t\tvec2 st1 = dFdy( vUv.st );\n\t\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\t\tvec3 N = normalize( surf_norm );\n\t\t\tmat3 tsn = mat3( S, T, N );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy *= normalScale;\n\t\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\treturn normalize( tsn * mapN );\n\t\t}\n\t#endif\n#endif";
  3677. 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}";
  3678. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  3679. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  3680. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  3681. 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";
  3682. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  3683. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3684. 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";
  3685. 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";
  3686. 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";
  3687. 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}";
  3688. 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";
  3689. 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";
  3690. 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";
  3691. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";
  3692. 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";
  3693. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3694. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  3695. var tonemapping_pars_fragment = "#ifndef saturate\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
  3696. 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";
  3697. 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";
  3698. 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";
  3699. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3700. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3701. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3702. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  3703. var background_frag = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3704. var background_vert = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
  3705. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3706. var cube_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
  3707. 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}";
  3708. 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}";
  3709. 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}";
  3710. 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}";
  3711. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV;\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3712. var equirect_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
  3713. 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}";
  3714. 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}";
  3715. 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}";
  3716. 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}";
  3717. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  3718. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3719. var meshmatcap_frag = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3720. var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
  3721. var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  3722. 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}";
  3723. var meshphysical_frag = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifndef STANDARD\n\tuniform float clearCoat;\n\tuniform float clearCoatRoughness;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <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}";
  3724. var meshphysical_vert = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3725. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\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}";
  3726. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  3727. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3728. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
  3729. 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}";
  3730. 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}";
  3731. var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3732. var sprite_vert = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  3733. var ShaderChunk = {
  3734. alphamap_fragment: alphamap_fragment,
  3735. alphamap_pars_fragment: alphamap_pars_fragment,
  3736. alphatest_fragment: alphatest_fragment,
  3737. aomap_fragment: aomap_fragment,
  3738. aomap_pars_fragment: aomap_pars_fragment,
  3739. begin_vertex: begin_vertex,
  3740. beginnormal_vertex: beginnormal_vertex,
  3741. bsdfs: bsdfs,
  3742. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3743. clipping_planes_fragment: clipping_planes_fragment,
  3744. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3745. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3746. clipping_planes_vertex: clipping_planes_vertex,
  3747. color_fragment: color_fragment,
  3748. color_pars_fragment: color_pars_fragment,
  3749. color_pars_vertex: color_pars_vertex,
  3750. color_vertex: color_vertex,
  3751. common: common,
  3752. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3753. defaultnormal_vertex: defaultnormal_vertex,
  3754. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3755. displacementmap_vertex: displacementmap_vertex,
  3756. emissivemap_fragment: emissivemap_fragment,
  3757. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3758. encodings_fragment: encodings_fragment,
  3759. encodings_pars_fragment: encodings_pars_fragment,
  3760. envmap_fragment: envmap_fragment,
  3761. envmap_pars_fragment: envmap_pars_fragment,
  3762. envmap_pars_vertex: envmap_pars_vertex,
  3763. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  3764. envmap_vertex: envmap_vertex,
  3765. fog_vertex: fog_vertex,
  3766. fog_pars_vertex: fog_pars_vertex,
  3767. fog_fragment: fog_fragment,
  3768. fog_pars_fragment: fog_pars_fragment,
  3769. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3770. lightmap_fragment: lightmap_fragment,
  3771. lightmap_pars_fragment: lightmap_pars_fragment,
  3772. lights_lambert_vertex: lights_lambert_vertex,
  3773. lights_pars_begin: lights_pars_begin,
  3774. lights_phong_fragment: lights_phong_fragment,
  3775. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3776. lights_physical_fragment: lights_physical_fragment,
  3777. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3778. lights_fragment_begin: lights_fragment_begin,
  3779. lights_fragment_maps: lights_fragment_maps,
  3780. lights_fragment_end: lights_fragment_end,
  3781. logdepthbuf_fragment: logdepthbuf_fragment,
  3782. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3783. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3784. logdepthbuf_vertex: logdepthbuf_vertex,
  3785. map_fragment: map_fragment,
  3786. map_pars_fragment: map_pars_fragment,
  3787. map_particle_fragment: map_particle_fragment,
  3788. map_particle_pars_fragment: map_particle_pars_fragment,
  3789. metalnessmap_fragment: metalnessmap_fragment,
  3790. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3791. morphnormal_vertex: morphnormal_vertex,
  3792. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3793. morphtarget_vertex: morphtarget_vertex,
  3794. normal_fragment_begin: normal_fragment_begin,
  3795. normal_fragment_maps: normal_fragment_maps,
  3796. normalmap_pars_fragment: normalmap_pars_fragment,
  3797. packing: packing,
  3798. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3799. project_vertex: project_vertex,
  3800. dithering_fragment: dithering_fragment,
  3801. dithering_pars_fragment: dithering_pars_fragment,
  3802. roughnessmap_fragment: roughnessmap_fragment,
  3803. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3804. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3805. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3806. shadowmap_vertex: shadowmap_vertex,
  3807. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3808. skinbase_vertex: skinbase_vertex,
  3809. skinning_pars_vertex: skinning_pars_vertex,
  3810. skinning_vertex: skinning_vertex,
  3811. skinnormal_vertex: skinnormal_vertex,
  3812. specularmap_fragment: specularmap_fragment,
  3813. specularmap_pars_fragment: specularmap_pars_fragment,
  3814. tonemapping_fragment: tonemapping_fragment,
  3815. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3816. uv_pars_fragment: uv_pars_fragment,
  3817. uv_pars_vertex: uv_pars_vertex,
  3818. uv_vertex: uv_vertex,
  3819. uv2_pars_fragment: uv2_pars_fragment,
  3820. uv2_pars_vertex: uv2_pars_vertex,
  3821. uv2_vertex: uv2_vertex,
  3822. worldpos_vertex: worldpos_vertex,
  3823. background_frag: background_frag,
  3824. background_vert: background_vert,
  3825. cube_frag: cube_frag,
  3826. cube_vert: cube_vert,
  3827. depth_frag: depth_frag,
  3828. depth_vert: depth_vert,
  3829. distanceRGBA_frag: distanceRGBA_frag,
  3830. distanceRGBA_vert: distanceRGBA_vert,
  3831. equirect_frag: equirect_frag,
  3832. equirect_vert: equirect_vert,
  3833. linedashed_frag: linedashed_frag,
  3834. linedashed_vert: linedashed_vert,
  3835. meshbasic_frag: meshbasic_frag,
  3836. meshbasic_vert: meshbasic_vert,
  3837. meshlambert_frag: meshlambert_frag,
  3838. meshlambert_vert: meshlambert_vert,
  3839. meshmatcap_frag: meshmatcap_frag,
  3840. meshmatcap_vert: meshmatcap_vert,
  3841. meshphong_frag: meshphong_frag,
  3842. meshphong_vert: meshphong_vert,
  3843. meshphysical_frag: meshphysical_frag,
  3844. meshphysical_vert: meshphysical_vert,
  3845. normal_frag: normal_frag,
  3846. normal_vert: normal_vert,
  3847. points_frag: points_frag,
  3848. points_vert: points_vert,
  3849. shadow_frag: shadow_frag,
  3850. shadow_vert: shadow_vert,
  3851. sprite_frag: sprite_frag,
  3852. sprite_vert: sprite_vert
  3853. };
  3854. /**
  3855. * Uniform Utilities
  3856. */
  3857. function cloneUniforms( src ) {
  3858. var dst = {};
  3859. for ( var u in src ) {
  3860. dst[ u ] = {};
  3861. for ( var p in src[ u ] ) {
  3862. var property = src[ u ][ p ];
  3863. if ( property && ( property.isColor ||
  3864. property.isMatrix3 || property.isMatrix4 ||
  3865. property.isVector2 || property.isVector3 || property.isVector4 ||
  3866. property.isTexture ) ) {
  3867. dst[ u ][ p ] = property.clone();
  3868. } else if ( Array.isArray( property ) ) {
  3869. dst[ u ][ p ] = property.slice();
  3870. } else {
  3871. dst[ u ][ p ] = property;
  3872. }
  3873. }
  3874. }
  3875. return dst;
  3876. }
  3877. function mergeUniforms( uniforms ) {
  3878. var merged = {};
  3879. for ( var u = 0; u < uniforms.length; u ++ ) {
  3880. var tmp = cloneUniforms( uniforms[ u ] );
  3881. for ( var p in tmp ) {
  3882. merged[ p ] = tmp[ p ];
  3883. }
  3884. }
  3885. return merged;
  3886. }
  3887. // Legacy
  3888. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  3889. /**
  3890. * @author mrdoob / http://mrdoob.com/
  3891. */
  3892. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3893. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3894. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3895. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3896. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3897. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3898. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3899. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3900. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3901. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3902. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3903. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3904. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3905. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3906. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3907. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3908. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3909. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3910. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3911. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3912. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3913. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3914. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3915. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3916. function Color( r, g, b ) {
  3917. if ( g === undefined && b === undefined ) {
  3918. // r is THREE.Color, hex or string
  3919. return this.set( r );
  3920. }
  3921. return this.setRGB( r, g, b );
  3922. }
  3923. Object.assign( Color.prototype, {
  3924. isColor: true,
  3925. r: 1, g: 1, b: 1,
  3926. set: function ( value ) {
  3927. if ( value && value.isColor ) {
  3928. this.copy( value );
  3929. } else if ( typeof value === 'number' ) {
  3930. this.setHex( value );
  3931. } else if ( typeof value === 'string' ) {
  3932. this.setStyle( value );
  3933. }
  3934. return this;
  3935. },
  3936. setScalar: function ( scalar ) {
  3937. this.r = scalar;
  3938. this.g = scalar;
  3939. this.b = scalar;
  3940. return this;
  3941. },
  3942. setHex: function ( hex ) {
  3943. hex = Math.floor( hex );
  3944. this.r = ( hex >> 16 & 255 ) / 255;
  3945. this.g = ( hex >> 8 & 255 ) / 255;
  3946. this.b = ( hex & 255 ) / 255;
  3947. return this;
  3948. },
  3949. setRGB: function ( r, g, b ) {
  3950. this.r = r;
  3951. this.g = g;
  3952. this.b = b;
  3953. return this;
  3954. },
  3955. setHSL: function () {
  3956. function hue2rgb( p, q, t ) {
  3957. if ( t < 0 ) t += 1;
  3958. if ( t > 1 ) t -= 1;
  3959. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3960. if ( t < 1 / 2 ) return q;
  3961. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3962. return p;
  3963. }
  3964. return function setHSL( h, s, l ) {
  3965. // h,s,l ranges are in 0.0 - 1.0
  3966. h = _Math.euclideanModulo( h, 1 );
  3967. s = _Math.clamp( s, 0, 1 );
  3968. l = _Math.clamp( l, 0, 1 );
  3969. if ( s === 0 ) {
  3970. this.r = this.g = this.b = l;
  3971. } else {
  3972. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3973. var q = ( 2 * l ) - p;
  3974. this.r = hue2rgb( q, p, h + 1 / 3 );
  3975. this.g = hue2rgb( q, p, h );
  3976. this.b = hue2rgb( q, p, h - 1 / 3 );
  3977. }
  3978. return this;
  3979. };
  3980. }(),
  3981. setStyle: function ( style ) {
  3982. function handleAlpha( string ) {
  3983. if ( string === undefined ) return;
  3984. if ( parseFloat( string ) < 1 ) {
  3985. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3986. }
  3987. }
  3988. var m;
  3989. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3990. // rgb / hsl
  3991. var color;
  3992. var name = m[ 1 ];
  3993. var components = m[ 2 ];
  3994. switch ( name ) {
  3995. case 'rgb':
  3996. case 'rgba':
  3997. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3998. // rgb(255,0,0) rgba(255,0,0,0.5)
  3999. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4000. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4001. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4002. handleAlpha( color[ 5 ] );
  4003. return this;
  4004. }
  4005. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4006. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4007. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4008. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4009. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4010. handleAlpha( color[ 5 ] );
  4011. return this;
  4012. }
  4013. break;
  4014. case 'hsl':
  4015. case 'hsla':
  4016. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4017. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4018. var h = parseFloat( color[ 1 ] ) / 360;
  4019. var s = parseInt( color[ 2 ], 10 ) / 100;
  4020. var l = parseInt( color[ 3 ], 10 ) / 100;
  4021. handleAlpha( color[ 5 ] );
  4022. return this.setHSL( h, s, l );
  4023. }
  4024. break;
  4025. }
  4026. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4027. // hex color
  4028. var hex = m[ 1 ];
  4029. var size = hex.length;
  4030. if ( size === 3 ) {
  4031. // #ff0
  4032. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4033. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4034. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4035. return this;
  4036. } else if ( size === 6 ) {
  4037. // #ff0000
  4038. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4039. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4040. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4041. return this;
  4042. }
  4043. }
  4044. if ( style && style.length > 0 ) {
  4045. // color keywords
  4046. var hex = ColorKeywords[ style ];
  4047. if ( hex !== undefined ) {
  4048. // red
  4049. this.setHex( hex );
  4050. } else {
  4051. // unknown color
  4052. console.warn( 'THREE.Color: Unknown color ' + style );
  4053. }
  4054. }
  4055. return this;
  4056. },
  4057. clone: function () {
  4058. return new this.constructor( this.r, this.g, this.b );
  4059. },
  4060. copy: function ( color ) {
  4061. this.r = color.r;
  4062. this.g = color.g;
  4063. this.b = color.b;
  4064. return this;
  4065. },
  4066. copyGammaToLinear: function ( color, gammaFactor ) {
  4067. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4068. this.r = Math.pow( color.r, gammaFactor );
  4069. this.g = Math.pow( color.g, gammaFactor );
  4070. this.b = Math.pow( color.b, gammaFactor );
  4071. return this;
  4072. },
  4073. copyLinearToGamma: function ( color, gammaFactor ) {
  4074. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4075. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4076. this.r = Math.pow( color.r, safeInverse );
  4077. this.g = Math.pow( color.g, safeInverse );
  4078. this.b = Math.pow( color.b, safeInverse );
  4079. return this;
  4080. },
  4081. convertGammaToLinear: function ( gammaFactor ) {
  4082. this.copyGammaToLinear( this, gammaFactor );
  4083. return this;
  4084. },
  4085. convertLinearToGamma: function ( gammaFactor ) {
  4086. this.copyLinearToGamma( this, gammaFactor );
  4087. return this;
  4088. },
  4089. copySRGBToLinear: function () {
  4090. function SRGBToLinear( c ) {
  4091. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4092. }
  4093. return function copySRGBToLinear( color ) {
  4094. this.r = SRGBToLinear( color.r );
  4095. this.g = SRGBToLinear( color.g );
  4096. this.b = SRGBToLinear( color.b );
  4097. return this;
  4098. };
  4099. }(),
  4100. copyLinearToSRGB: function () {
  4101. function LinearToSRGB( c ) {
  4102. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4103. }
  4104. return function copyLinearToSRGB( color ) {
  4105. this.r = LinearToSRGB( color.r );
  4106. this.g = LinearToSRGB( color.g );
  4107. this.b = LinearToSRGB( color.b );
  4108. return this;
  4109. };
  4110. }(),
  4111. convertSRGBToLinear: function () {
  4112. this.copySRGBToLinear( this );
  4113. return this;
  4114. },
  4115. convertLinearToSRGB: function () {
  4116. this.copyLinearToSRGB( this );
  4117. return this;
  4118. },
  4119. getHex: function () {
  4120. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4121. },
  4122. getHexString: function () {
  4123. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4124. },
  4125. getHSL: function ( target ) {
  4126. // h,s,l ranges are in 0.0 - 1.0
  4127. if ( target === undefined ) {
  4128. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4129. target = { h: 0, s: 0, l: 0 };
  4130. }
  4131. var r = this.r, g = this.g, b = this.b;
  4132. var max = Math.max( r, g, b );
  4133. var min = Math.min( r, g, b );
  4134. var hue, saturation;
  4135. var lightness = ( min + max ) / 2.0;
  4136. if ( min === max ) {
  4137. hue = 0;
  4138. saturation = 0;
  4139. } else {
  4140. var delta = max - min;
  4141. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4142. switch ( max ) {
  4143. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4144. case g: hue = ( b - r ) / delta + 2; break;
  4145. case b: hue = ( r - g ) / delta + 4; break;
  4146. }
  4147. hue /= 6;
  4148. }
  4149. target.h = hue;
  4150. target.s = saturation;
  4151. target.l = lightness;
  4152. return target;
  4153. },
  4154. getStyle: function () {
  4155. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4156. },
  4157. offsetHSL: function () {
  4158. var hsl = {};
  4159. return function ( h, s, l ) {
  4160. this.getHSL( hsl );
  4161. hsl.h += h; hsl.s += s; hsl.l += l;
  4162. this.setHSL( hsl.h, hsl.s, hsl.l );
  4163. return this;
  4164. };
  4165. }(),
  4166. add: function ( color ) {
  4167. this.r += color.r;
  4168. this.g += color.g;
  4169. this.b += color.b;
  4170. return this;
  4171. },
  4172. addColors: function ( color1, color2 ) {
  4173. this.r = color1.r + color2.r;
  4174. this.g = color1.g + color2.g;
  4175. this.b = color1.b + color2.b;
  4176. return this;
  4177. },
  4178. addScalar: function ( s ) {
  4179. this.r += s;
  4180. this.g += s;
  4181. this.b += s;
  4182. return this;
  4183. },
  4184. sub: function ( color ) {
  4185. this.r = Math.max( 0, this.r - color.r );
  4186. this.g = Math.max( 0, this.g - color.g );
  4187. this.b = Math.max( 0, this.b - color.b );
  4188. return this;
  4189. },
  4190. multiply: function ( color ) {
  4191. this.r *= color.r;
  4192. this.g *= color.g;
  4193. this.b *= color.b;
  4194. return this;
  4195. },
  4196. multiplyScalar: function ( s ) {
  4197. this.r *= s;
  4198. this.g *= s;
  4199. this.b *= s;
  4200. return this;
  4201. },
  4202. lerp: function ( color, alpha ) {
  4203. this.r += ( color.r - this.r ) * alpha;
  4204. this.g += ( color.g - this.g ) * alpha;
  4205. this.b += ( color.b - this.b ) * alpha;
  4206. return this;
  4207. },
  4208. lerpHSL: function () {
  4209. var hslA = { h: 0, s: 0, l: 0 };
  4210. var hslB = { h: 0, s: 0, l: 0 };
  4211. return function lerpHSL( color, alpha ) {
  4212. this.getHSL( hslA );
  4213. color.getHSL( hslB );
  4214. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  4215. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  4216. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  4217. this.setHSL( h, s, l );
  4218. return this;
  4219. };
  4220. }(),
  4221. equals: function ( c ) {
  4222. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4223. },
  4224. fromArray: function ( array, offset ) {
  4225. if ( offset === undefined ) offset = 0;
  4226. this.r = array[ offset ];
  4227. this.g = array[ offset + 1 ];
  4228. this.b = array[ offset + 2 ];
  4229. return this;
  4230. },
  4231. toArray: function ( array, offset ) {
  4232. if ( array === undefined ) array = [];
  4233. if ( offset === undefined ) offset = 0;
  4234. array[ offset ] = this.r;
  4235. array[ offset + 1 ] = this.g;
  4236. array[ offset + 2 ] = this.b;
  4237. return array;
  4238. },
  4239. toJSON: function () {
  4240. return this.getHex();
  4241. }
  4242. } );
  4243. /**
  4244. * Uniforms library for shared webgl shaders
  4245. */
  4246. var UniformsLib = {
  4247. common: {
  4248. diffuse: { value: new Color( 0xeeeeee ) },
  4249. opacity: { value: 1.0 },
  4250. map: { value: null },
  4251. uvTransform: { value: new Matrix3() },
  4252. alphaMap: { value: null },
  4253. },
  4254. specularmap: {
  4255. specularMap: { value: null },
  4256. },
  4257. envmap: {
  4258. envMap: { value: null },
  4259. flipEnvMap: { value: - 1 },
  4260. reflectivity: { value: 1.0 },
  4261. refractionRatio: { value: 0.98 },
  4262. maxMipLevel: { value: 0 }
  4263. },
  4264. aomap: {
  4265. aoMap: { value: null },
  4266. aoMapIntensity: { value: 1 }
  4267. },
  4268. lightmap: {
  4269. lightMap: { value: null },
  4270. lightMapIntensity: { value: 1 }
  4271. },
  4272. emissivemap: {
  4273. emissiveMap: { value: null }
  4274. },
  4275. bumpmap: {
  4276. bumpMap: { value: null },
  4277. bumpScale: { value: 1 }
  4278. },
  4279. normalmap: {
  4280. normalMap: { value: null },
  4281. normalScale: { value: new Vector2( 1, 1 ) }
  4282. },
  4283. displacementmap: {
  4284. displacementMap: { value: null },
  4285. displacementScale: { value: 1 },
  4286. displacementBias: { value: 0 }
  4287. },
  4288. roughnessmap: {
  4289. roughnessMap: { value: null }
  4290. },
  4291. metalnessmap: {
  4292. metalnessMap: { value: null }
  4293. },
  4294. gradientmap: {
  4295. gradientMap: { value: null }
  4296. },
  4297. fog: {
  4298. fogDensity: { value: 0.00025 },
  4299. fogNear: { value: 1 },
  4300. fogFar: { value: 2000 },
  4301. fogColor: { value: new Color( 0xffffff ) }
  4302. },
  4303. lights: {
  4304. ambientLightColor: { value: [] },
  4305. directionalLights: { value: [], properties: {
  4306. direction: {},
  4307. color: {},
  4308. shadow: {},
  4309. shadowBias: {},
  4310. shadowRadius: {},
  4311. shadowMapSize: {}
  4312. } },
  4313. directionalShadowMap: { value: [] },
  4314. directionalShadowMatrix: { value: [] },
  4315. spotLights: { value: [], properties: {
  4316. color: {},
  4317. position: {},
  4318. direction: {},
  4319. distance: {},
  4320. coneCos: {},
  4321. penumbraCos: {},
  4322. decay: {},
  4323. shadow: {},
  4324. shadowBias: {},
  4325. shadowRadius: {},
  4326. shadowMapSize: {}
  4327. } },
  4328. spotShadowMap: { value: [] },
  4329. spotShadowMatrix: { value: [] },
  4330. pointLights: { value: [], properties: {
  4331. color: {},
  4332. position: {},
  4333. decay: {},
  4334. distance: {},
  4335. shadow: {},
  4336. shadowBias: {},
  4337. shadowRadius: {},
  4338. shadowMapSize: {},
  4339. shadowCameraNear: {},
  4340. shadowCameraFar: {}
  4341. } },
  4342. pointShadowMap: { value: [] },
  4343. pointShadowMatrix: { value: [] },
  4344. hemisphereLights: { value: [], properties: {
  4345. direction: {},
  4346. skyColor: {},
  4347. groundColor: {}
  4348. } },
  4349. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4350. rectAreaLights: { value: [], properties: {
  4351. color: {},
  4352. position: {},
  4353. width: {},
  4354. height: {}
  4355. } }
  4356. },
  4357. points: {
  4358. diffuse: { value: new Color( 0xeeeeee ) },
  4359. opacity: { value: 1.0 },
  4360. size: { value: 1.0 },
  4361. scale: { value: 1.0 },
  4362. map: { value: null },
  4363. uvTransform: { value: new Matrix3() }
  4364. },
  4365. sprite: {
  4366. diffuse: { value: new Color( 0xeeeeee ) },
  4367. opacity: { value: 1.0 },
  4368. center: { value: new Vector2( 0.5, 0.5 ) },
  4369. rotation: { value: 0.0 },
  4370. map: { value: null },
  4371. uvTransform: { value: new Matrix3() }
  4372. }
  4373. };
  4374. /**
  4375. * @author alteredq / http://alteredqualia.com/
  4376. * @author mrdoob / http://mrdoob.com/
  4377. * @author mikael emtinger / http://gomo.se/
  4378. */
  4379. var ShaderLib = {
  4380. basic: {
  4381. uniforms: mergeUniforms( [
  4382. UniformsLib.common,
  4383. UniformsLib.specularmap,
  4384. UniformsLib.envmap,
  4385. UniformsLib.aomap,
  4386. UniformsLib.lightmap,
  4387. UniformsLib.fog
  4388. ] ),
  4389. vertexShader: ShaderChunk.meshbasic_vert,
  4390. fragmentShader: ShaderChunk.meshbasic_frag
  4391. },
  4392. lambert: {
  4393. uniforms: mergeUniforms( [
  4394. UniformsLib.common,
  4395. UniformsLib.specularmap,
  4396. UniformsLib.envmap,
  4397. UniformsLib.aomap,
  4398. UniformsLib.lightmap,
  4399. UniformsLib.emissivemap,
  4400. UniformsLib.fog,
  4401. UniformsLib.lights,
  4402. {
  4403. emissive: { value: new Color( 0x000000 ) }
  4404. }
  4405. ] ),
  4406. vertexShader: ShaderChunk.meshlambert_vert,
  4407. fragmentShader: ShaderChunk.meshlambert_frag
  4408. },
  4409. phong: {
  4410. uniforms: mergeUniforms( [
  4411. UniformsLib.common,
  4412. UniformsLib.specularmap,
  4413. UniformsLib.envmap,
  4414. UniformsLib.aomap,
  4415. UniformsLib.lightmap,
  4416. UniformsLib.emissivemap,
  4417. UniformsLib.bumpmap,
  4418. UniformsLib.normalmap,
  4419. UniformsLib.displacementmap,
  4420. UniformsLib.gradientmap,
  4421. UniformsLib.fog,
  4422. UniformsLib.lights,
  4423. {
  4424. emissive: { value: new Color( 0x000000 ) },
  4425. specular: { value: new Color( 0x111111 ) },
  4426. shininess: { value: 30 }
  4427. }
  4428. ] ),
  4429. vertexShader: ShaderChunk.meshphong_vert,
  4430. fragmentShader: ShaderChunk.meshphong_frag
  4431. },
  4432. standard: {
  4433. uniforms: mergeUniforms( [
  4434. UniformsLib.common,
  4435. UniformsLib.envmap,
  4436. UniformsLib.aomap,
  4437. UniformsLib.lightmap,
  4438. UniformsLib.emissivemap,
  4439. UniformsLib.bumpmap,
  4440. UniformsLib.normalmap,
  4441. UniformsLib.displacementmap,
  4442. UniformsLib.roughnessmap,
  4443. UniformsLib.metalnessmap,
  4444. UniformsLib.fog,
  4445. UniformsLib.lights,
  4446. {
  4447. emissive: { value: new Color( 0x000000 ) },
  4448. roughness: { value: 0.5 },
  4449. metalness: { value: 0.5 },
  4450. envMapIntensity: { value: 1 } // temporary
  4451. }
  4452. ] ),
  4453. vertexShader: ShaderChunk.meshphysical_vert,
  4454. fragmentShader: ShaderChunk.meshphysical_frag
  4455. },
  4456. matcap: {
  4457. uniforms: mergeUniforms( [
  4458. UniformsLib.common,
  4459. UniformsLib.bumpmap,
  4460. UniformsLib.normalmap,
  4461. UniformsLib.displacementmap,
  4462. UniformsLib.fog,
  4463. {
  4464. matcap: { value: null }
  4465. }
  4466. ] ),
  4467. vertexShader: ShaderChunk.meshmatcap_vert,
  4468. fragmentShader: ShaderChunk.meshmatcap_frag
  4469. },
  4470. points: {
  4471. uniforms: mergeUniforms( [
  4472. UniformsLib.points,
  4473. UniformsLib.fog
  4474. ] ),
  4475. vertexShader: ShaderChunk.points_vert,
  4476. fragmentShader: ShaderChunk.points_frag
  4477. },
  4478. dashed: {
  4479. uniforms: mergeUniforms( [
  4480. UniformsLib.common,
  4481. UniformsLib.fog,
  4482. {
  4483. scale: { value: 1 },
  4484. dashSize: { value: 1 },
  4485. totalSize: { value: 2 }
  4486. }
  4487. ] ),
  4488. vertexShader: ShaderChunk.linedashed_vert,
  4489. fragmentShader: ShaderChunk.linedashed_frag
  4490. },
  4491. depth: {
  4492. uniforms: mergeUniforms( [
  4493. UniformsLib.common,
  4494. UniformsLib.displacementmap
  4495. ] ),
  4496. vertexShader: ShaderChunk.depth_vert,
  4497. fragmentShader: ShaderChunk.depth_frag
  4498. },
  4499. normal: {
  4500. uniforms: mergeUniforms( [
  4501. UniformsLib.common,
  4502. UniformsLib.bumpmap,
  4503. UniformsLib.normalmap,
  4504. UniformsLib.displacementmap,
  4505. {
  4506. opacity: { value: 1.0 }
  4507. }
  4508. ] ),
  4509. vertexShader: ShaderChunk.normal_vert,
  4510. fragmentShader: ShaderChunk.normal_frag
  4511. },
  4512. sprite: {
  4513. uniforms: mergeUniforms( [
  4514. UniformsLib.sprite,
  4515. UniformsLib.fog
  4516. ] ),
  4517. vertexShader: ShaderChunk.sprite_vert,
  4518. fragmentShader: ShaderChunk.sprite_frag
  4519. },
  4520. background: {
  4521. uniforms: {
  4522. uvTransform: { value: new Matrix3() },
  4523. t2D: { value: null },
  4524. },
  4525. vertexShader: ShaderChunk.background_vert,
  4526. fragmentShader: ShaderChunk.background_frag
  4527. },
  4528. /* -------------------------------------------------------------------------
  4529. // Cube map shader
  4530. ------------------------------------------------------------------------- */
  4531. cube: {
  4532. uniforms: {
  4533. tCube: { value: null },
  4534. tFlip: { value: - 1 },
  4535. opacity: { value: 1.0 }
  4536. },
  4537. vertexShader: ShaderChunk.cube_vert,
  4538. fragmentShader: ShaderChunk.cube_frag
  4539. },
  4540. equirect: {
  4541. uniforms: {
  4542. tEquirect: { value: null },
  4543. },
  4544. vertexShader: ShaderChunk.equirect_vert,
  4545. fragmentShader: ShaderChunk.equirect_frag
  4546. },
  4547. distanceRGBA: {
  4548. uniforms: mergeUniforms( [
  4549. UniformsLib.common,
  4550. UniformsLib.displacementmap,
  4551. {
  4552. referencePosition: { value: new Vector3() },
  4553. nearDistance: { value: 1 },
  4554. farDistance: { value: 1000 }
  4555. }
  4556. ] ),
  4557. vertexShader: ShaderChunk.distanceRGBA_vert,
  4558. fragmentShader: ShaderChunk.distanceRGBA_frag
  4559. },
  4560. shadow: {
  4561. uniforms: mergeUniforms( [
  4562. UniformsLib.lights,
  4563. UniformsLib.fog,
  4564. {
  4565. color: { value: new Color( 0x00000 ) },
  4566. opacity: { value: 1.0 }
  4567. },
  4568. ] ),
  4569. vertexShader: ShaderChunk.shadow_vert,
  4570. fragmentShader: ShaderChunk.shadow_frag
  4571. }
  4572. };
  4573. ShaderLib.physical = {
  4574. uniforms: mergeUniforms( [
  4575. ShaderLib.standard.uniforms,
  4576. {
  4577. clearCoat: { value: 0 },
  4578. clearCoatRoughness: { value: 0 }
  4579. }
  4580. ] ),
  4581. vertexShader: ShaderChunk.meshphysical_vert,
  4582. fragmentShader: ShaderChunk.meshphysical_frag
  4583. };
  4584. /**
  4585. * @author mrdoob / http://mrdoob.com/
  4586. */
  4587. function WebGLAnimation() {
  4588. var context = null;
  4589. var isAnimating = false;
  4590. var animationLoop = null;
  4591. function onAnimationFrame( time, frame ) {
  4592. if ( isAnimating === false ) return;
  4593. animationLoop( time, frame );
  4594. context.requestAnimationFrame( onAnimationFrame );
  4595. }
  4596. return {
  4597. start: function () {
  4598. if ( isAnimating === true ) return;
  4599. if ( animationLoop === null ) return;
  4600. context.requestAnimationFrame( onAnimationFrame );
  4601. isAnimating = true;
  4602. },
  4603. stop: function () {
  4604. isAnimating = false;
  4605. },
  4606. setAnimationLoop: function ( callback ) {
  4607. animationLoop = callback;
  4608. },
  4609. setContext: function ( value ) {
  4610. context = value;
  4611. }
  4612. };
  4613. }
  4614. /**
  4615. * @author mrdoob / http://mrdoob.com/
  4616. */
  4617. function WebGLAttributes( gl ) {
  4618. var buffers = new WeakMap();
  4619. function createBuffer( attribute, bufferType ) {
  4620. var array = attribute.array;
  4621. var usage = attribute.dynamic ? 35048 : 35044;
  4622. var buffer = gl.createBuffer();
  4623. gl.bindBuffer( bufferType, buffer );
  4624. gl.bufferData( bufferType, array, usage );
  4625. attribute.onUploadCallback();
  4626. var type = 5126;
  4627. if ( array instanceof Float32Array ) {
  4628. type = 5126;
  4629. } else if ( array instanceof Float64Array ) {
  4630. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4631. } else if ( array instanceof Uint16Array ) {
  4632. type = 5123;
  4633. } else if ( array instanceof Int16Array ) {
  4634. type = 5122;
  4635. } else if ( array instanceof Uint32Array ) {
  4636. type = 5125;
  4637. } else if ( array instanceof Int32Array ) {
  4638. type = 5124;
  4639. } else if ( array instanceof Int8Array ) {
  4640. type = 5120;
  4641. } else if ( array instanceof Uint8Array ) {
  4642. type = 5121;
  4643. }
  4644. return {
  4645. buffer: buffer,
  4646. type: type,
  4647. bytesPerElement: array.BYTES_PER_ELEMENT,
  4648. version: attribute.version
  4649. };
  4650. }
  4651. function updateBuffer( buffer, attribute, bufferType ) {
  4652. var array = attribute.array;
  4653. var updateRange = attribute.updateRange;
  4654. gl.bindBuffer( bufferType, buffer );
  4655. if ( attribute.dynamic === false ) {
  4656. gl.bufferData( bufferType, array, 35044 );
  4657. } else if ( updateRange.count === - 1 ) {
  4658. // Not using update ranges
  4659. gl.bufferSubData( bufferType, 0, array );
  4660. } else if ( updateRange.count === 0 ) {
  4661. 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.' );
  4662. } else {
  4663. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4664. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4665. updateRange.count = - 1; // reset range
  4666. }
  4667. }
  4668. //
  4669. function get( attribute ) {
  4670. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4671. return buffers.get( attribute );
  4672. }
  4673. function remove( attribute ) {
  4674. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4675. var data = buffers.get( attribute );
  4676. if ( data ) {
  4677. gl.deleteBuffer( data.buffer );
  4678. buffers.delete( attribute );
  4679. }
  4680. }
  4681. function update( attribute, bufferType ) {
  4682. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4683. var data = buffers.get( attribute );
  4684. if ( data === undefined ) {
  4685. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4686. } else if ( data.version < attribute.version ) {
  4687. updateBuffer( data.buffer, attribute, bufferType );
  4688. data.version = attribute.version;
  4689. }
  4690. }
  4691. return {
  4692. get: get,
  4693. remove: remove,
  4694. update: update
  4695. };
  4696. }
  4697. /**
  4698. * @author mrdoob / http://mrdoob.com/
  4699. * @author alteredq / http://alteredqualia.com/
  4700. */
  4701. function Face3( a, b, c, normal, color, materialIndex ) {
  4702. this.a = a;
  4703. this.b = b;
  4704. this.c = c;
  4705. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4706. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4707. this.color = ( color && color.isColor ) ? color : new Color();
  4708. this.vertexColors = Array.isArray( color ) ? color : [];
  4709. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4710. }
  4711. Object.assign( Face3.prototype, {
  4712. clone: function () {
  4713. return new this.constructor().copy( this );
  4714. },
  4715. copy: function ( source ) {
  4716. this.a = source.a;
  4717. this.b = source.b;
  4718. this.c = source.c;
  4719. this.normal.copy( source.normal );
  4720. this.color.copy( source.color );
  4721. this.materialIndex = source.materialIndex;
  4722. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4723. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4724. }
  4725. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4726. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4727. }
  4728. return this;
  4729. }
  4730. } );
  4731. /**
  4732. * @author mrdoob / http://mrdoob.com/
  4733. * @author WestLangley / http://github.com/WestLangley
  4734. * @author bhouston / http://clara.io
  4735. */
  4736. function Euler( x, y, z, order ) {
  4737. this._x = x || 0;
  4738. this._y = y || 0;
  4739. this._z = z || 0;
  4740. this._order = order || Euler.DefaultOrder;
  4741. }
  4742. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4743. Euler.DefaultOrder = 'XYZ';
  4744. Object.defineProperties( Euler.prototype, {
  4745. x: {
  4746. get: function () {
  4747. return this._x;
  4748. },
  4749. set: function ( value ) {
  4750. this._x = value;
  4751. this.onChangeCallback();
  4752. }
  4753. },
  4754. y: {
  4755. get: function () {
  4756. return this._y;
  4757. },
  4758. set: function ( value ) {
  4759. this._y = value;
  4760. this.onChangeCallback();
  4761. }
  4762. },
  4763. z: {
  4764. get: function () {
  4765. return this._z;
  4766. },
  4767. set: function ( value ) {
  4768. this._z = value;
  4769. this.onChangeCallback();
  4770. }
  4771. },
  4772. order: {
  4773. get: function () {
  4774. return this._order;
  4775. },
  4776. set: function ( value ) {
  4777. this._order = value;
  4778. this.onChangeCallback();
  4779. }
  4780. }
  4781. } );
  4782. Object.assign( Euler.prototype, {
  4783. isEuler: true,
  4784. set: function ( x, y, z, order ) {
  4785. this._x = x;
  4786. this._y = y;
  4787. this._z = z;
  4788. this._order = order || this._order;
  4789. this.onChangeCallback();
  4790. return this;
  4791. },
  4792. clone: function () {
  4793. return new this.constructor( this._x, this._y, this._z, this._order );
  4794. },
  4795. copy: function ( euler ) {
  4796. this._x = euler._x;
  4797. this._y = euler._y;
  4798. this._z = euler._z;
  4799. this._order = euler._order;
  4800. this.onChangeCallback();
  4801. return this;
  4802. },
  4803. setFromRotationMatrix: function ( m, order, update ) {
  4804. var clamp = _Math.clamp;
  4805. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4806. var te = m.elements;
  4807. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4808. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4809. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4810. order = order || this._order;
  4811. if ( order === 'XYZ' ) {
  4812. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4813. if ( Math.abs( m13 ) < 0.99999 ) {
  4814. this._x = Math.atan2( - m23, m33 );
  4815. this._z = Math.atan2( - m12, m11 );
  4816. } else {
  4817. this._x = Math.atan2( m32, m22 );
  4818. this._z = 0;
  4819. }
  4820. } else if ( order === 'YXZ' ) {
  4821. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4822. if ( Math.abs( m23 ) < 0.99999 ) {
  4823. this._y = Math.atan2( m13, m33 );
  4824. this._z = Math.atan2( m21, m22 );
  4825. } else {
  4826. this._y = Math.atan2( - m31, m11 );
  4827. this._z = 0;
  4828. }
  4829. } else if ( order === 'ZXY' ) {
  4830. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4831. if ( Math.abs( m32 ) < 0.99999 ) {
  4832. this._y = Math.atan2( - m31, m33 );
  4833. this._z = Math.atan2( - m12, m22 );
  4834. } else {
  4835. this._y = 0;
  4836. this._z = Math.atan2( m21, m11 );
  4837. }
  4838. } else if ( order === 'ZYX' ) {
  4839. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4840. if ( Math.abs( m31 ) < 0.99999 ) {
  4841. this._x = Math.atan2( m32, m33 );
  4842. this._z = Math.atan2( m21, m11 );
  4843. } else {
  4844. this._x = 0;
  4845. this._z = Math.atan2( - m12, m22 );
  4846. }
  4847. } else if ( order === 'YZX' ) {
  4848. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4849. if ( Math.abs( m21 ) < 0.99999 ) {
  4850. this._x = Math.atan2( - m23, m22 );
  4851. this._y = Math.atan2( - m31, m11 );
  4852. } else {
  4853. this._x = 0;
  4854. this._y = Math.atan2( m13, m33 );
  4855. }
  4856. } else if ( order === 'XZY' ) {
  4857. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4858. if ( Math.abs( m12 ) < 0.99999 ) {
  4859. this._x = Math.atan2( m32, m22 );
  4860. this._y = Math.atan2( m13, m11 );
  4861. } else {
  4862. this._x = Math.atan2( - m23, m33 );
  4863. this._y = 0;
  4864. }
  4865. } else {
  4866. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4867. }
  4868. this._order = order;
  4869. if ( update !== false ) this.onChangeCallback();
  4870. return this;
  4871. },
  4872. setFromQuaternion: function () {
  4873. var matrix = new Matrix4();
  4874. return function setFromQuaternion( q, order, update ) {
  4875. matrix.makeRotationFromQuaternion( q );
  4876. return this.setFromRotationMatrix( matrix, order, update );
  4877. };
  4878. }(),
  4879. setFromVector3: function ( v, order ) {
  4880. return this.set( v.x, v.y, v.z, order || this._order );
  4881. },
  4882. reorder: function () {
  4883. // WARNING: this discards revolution information -bhouston
  4884. var q = new Quaternion();
  4885. return function reorder( newOrder ) {
  4886. q.setFromEuler( this );
  4887. return this.setFromQuaternion( q, newOrder );
  4888. };
  4889. }(),
  4890. equals: function ( euler ) {
  4891. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4892. },
  4893. fromArray: function ( array ) {
  4894. this._x = array[ 0 ];
  4895. this._y = array[ 1 ];
  4896. this._z = array[ 2 ];
  4897. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4898. this.onChangeCallback();
  4899. return this;
  4900. },
  4901. toArray: function ( array, offset ) {
  4902. if ( array === undefined ) array = [];
  4903. if ( offset === undefined ) offset = 0;
  4904. array[ offset ] = this._x;
  4905. array[ offset + 1 ] = this._y;
  4906. array[ offset + 2 ] = this._z;
  4907. array[ offset + 3 ] = this._order;
  4908. return array;
  4909. },
  4910. toVector3: function ( optionalResult ) {
  4911. if ( optionalResult ) {
  4912. return optionalResult.set( this._x, this._y, this._z );
  4913. } else {
  4914. return new Vector3( this._x, this._y, this._z );
  4915. }
  4916. },
  4917. onChange: function ( callback ) {
  4918. this.onChangeCallback = callback;
  4919. return this;
  4920. },
  4921. onChangeCallback: function () {}
  4922. } );
  4923. /**
  4924. * @author mrdoob / http://mrdoob.com/
  4925. */
  4926. function Layers() {
  4927. this.mask = 1 | 0;
  4928. }
  4929. Object.assign( Layers.prototype, {
  4930. set: function ( channel ) {
  4931. this.mask = 1 << channel | 0;
  4932. },
  4933. enable: function ( channel ) {
  4934. this.mask |= 1 << channel | 0;
  4935. },
  4936. toggle: function ( channel ) {
  4937. this.mask ^= 1 << channel | 0;
  4938. },
  4939. disable: function ( channel ) {
  4940. this.mask &= ~ ( 1 << channel | 0 );
  4941. },
  4942. test: function ( layers ) {
  4943. return ( this.mask & layers.mask ) !== 0;
  4944. }
  4945. } );
  4946. /**
  4947. * @author mrdoob / http://mrdoob.com/
  4948. * @author mikael emtinger / http://gomo.se/
  4949. * @author alteredq / http://alteredqualia.com/
  4950. * @author WestLangley / http://github.com/WestLangley
  4951. * @author elephantatwork / www.elephantatwork.ch
  4952. */
  4953. var object3DId = 0;
  4954. function Object3D() {
  4955. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4956. this.uuid = _Math.generateUUID();
  4957. this.name = '';
  4958. this.type = 'Object3D';
  4959. this.parent = null;
  4960. this.children = [];
  4961. this.up = Object3D.DefaultUp.clone();
  4962. var position = new Vector3();
  4963. var rotation = new Euler();
  4964. var quaternion = new Quaternion();
  4965. var scale = new Vector3( 1, 1, 1 );
  4966. function onRotationChange() {
  4967. quaternion.setFromEuler( rotation, false );
  4968. }
  4969. function onQuaternionChange() {
  4970. rotation.setFromQuaternion( quaternion, undefined, false );
  4971. }
  4972. rotation.onChange( onRotationChange );
  4973. quaternion.onChange( onQuaternionChange );
  4974. Object.defineProperties( this, {
  4975. position: {
  4976. configurable: true,
  4977. enumerable: true,
  4978. value: position
  4979. },
  4980. rotation: {
  4981. configurable: true,
  4982. enumerable: true,
  4983. value: rotation
  4984. },
  4985. quaternion: {
  4986. configurable: true,
  4987. enumerable: true,
  4988. value: quaternion
  4989. },
  4990. scale: {
  4991. configurable: true,
  4992. enumerable: true,
  4993. value: scale
  4994. },
  4995. modelViewMatrix: {
  4996. value: new Matrix4()
  4997. },
  4998. normalMatrix: {
  4999. value: new Matrix3()
  5000. }
  5001. } );
  5002. this.matrix = new Matrix4();
  5003. this.matrixWorld = new Matrix4();
  5004. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5005. this.matrixWorldNeedsUpdate = false;
  5006. this.layers = new Layers();
  5007. this.visible = true;
  5008. this.castShadow = false;
  5009. this.receiveShadow = false;
  5010. this.frustumCulled = true;
  5011. this.renderOrder = 0;
  5012. this.userData = {};
  5013. }
  5014. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5015. Object3D.DefaultMatrixAutoUpdate = true;
  5016. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5017. constructor: Object3D,
  5018. isObject3D: true,
  5019. onBeforeRender: function () {},
  5020. onAfterRender: function () {},
  5021. applyMatrix: function ( matrix ) {
  5022. this.matrix.multiplyMatrices( matrix, this.matrix );
  5023. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5024. },
  5025. applyQuaternion: function ( q ) {
  5026. this.quaternion.premultiply( q );
  5027. return this;
  5028. },
  5029. setRotationFromAxisAngle: function ( axis, angle ) {
  5030. // assumes axis is normalized
  5031. this.quaternion.setFromAxisAngle( axis, angle );
  5032. },
  5033. setRotationFromEuler: function ( euler ) {
  5034. this.quaternion.setFromEuler( euler, true );
  5035. },
  5036. setRotationFromMatrix: function ( m ) {
  5037. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5038. this.quaternion.setFromRotationMatrix( m );
  5039. },
  5040. setRotationFromQuaternion: function ( q ) {
  5041. // assumes q is normalized
  5042. this.quaternion.copy( q );
  5043. },
  5044. rotateOnAxis: function () {
  5045. // rotate object on axis in object space
  5046. // axis is assumed to be normalized
  5047. var q1 = new Quaternion();
  5048. return function rotateOnAxis( axis, angle ) {
  5049. q1.setFromAxisAngle( axis, angle );
  5050. this.quaternion.multiply( q1 );
  5051. return this;
  5052. };
  5053. }(),
  5054. rotateOnWorldAxis: function () {
  5055. // rotate object on axis in world space
  5056. // axis is assumed to be normalized
  5057. // method assumes no rotated parent
  5058. var q1 = new Quaternion();
  5059. return function rotateOnWorldAxis( axis, angle ) {
  5060. q1.setFromAxisAngle( axis, angle );
  5061. this.quaternion.premultiply( q1 );
  5062. return this;
  5063. };
  5064. }(),
  5065. rotateX: function () {
  5066. var v1 = new Vector3( 1, 0, 0 );
  5067. return function rotateX( angle ) {
  5068. return this.rotateOnAxis( v1, angle );
  5069. };
  5070. }(),
  5071. rotateY: function () {
  5072. var v1 = new Vector3( 0, 1, 0 );
  5073. return function rotateY( angle ) {
  5074. return this.rotateOnAxis( v1, angle );
  5075. };
  5076. }(),
  5077. rotateZ: function () {
  5078. var v1 = new Vector3( 0, 0, 1 );
  5079. return function rotateZ( angle ) {
  5080. return this.rotateOnAxis( v1, angle );
  5081. };
  5082. }(),
  5083. translateOnAxis: function () {
  5084. // translate object by distance along axis in object space
  5085. // axis is assumed to be normalized
  5086. var v1 = new Vector3();
  5087. return function translateOnAxis( axis, distance ) {
  5088. v1.copy( axis ).applyQuaternion( this.quaternion );
  5089. this.position.add( v1.multiplyScalar( distance ) );
  5090. return this;
  5091. };
  5092. }(),
  5093. translateX: function () {
  5094. var v1 = new Vector3( 1, 0, 0 );
  5095. return function translateX( distance ) {
  5096. return this.translateOnAxis( v1, distance );
  5097. };
  5098. }(),
  5099. translateY: function () {
  5100. var v1 = new Vector3( 0, 1, 0 );
  5101. return function translateY( distance ) {
  5102. return this.translateOnAxis( v1, distance );
  5103. };
  5104. }(),
  5105. translateZ: function () {
  5106. var v1 = new Vector3( 0, 0, 1 );
  5107. return function translateZ( distance ) {
  5108. return this.translateOnAxis( v1, distance );
  5109. };
  5110. }(),
  5111. localToWorld: function ( vector ) {
  5112. return vector.applyMatrix4( this.matrixWorld );
  5113. },
  5114. worldToLocal: function () {
  5115. var m1 = new Matrix4();
  5116. return function worldToLocal( vector ) {
  5117. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5118. };
  5119. }(),
  5120. lookAt: function () {
  5121. // This method does not support objects having non-uniformly-scaled parent(s)
  5122. var q1 = new Quaternion();
  5123. var m1 = new Matrix4();
  5124. var target = new Vector3();
  5125. var position = new Vector3();
  5126. return function lookAt( x, y, z ) {
  5127. if ( x.isVector3 ) {
  5128. target.copy( x );
  5129. } else {
  5130. target.set( x, y, z );
  5131. }
  5132. var parent = this.parent;
  5133. this.updateWorldMatrix( true, false );
  5134. position.setFromMatrixPosition( this.matrixWorld );
  5135. if ( this.isCamera || this.isLight ) {
  5136. m1.lookAt( position, target, this.up );
  5137. } else {
  5138. m1.lookAt( target, position, this.up );
  5139. }
  5140. this.quaternion.setFromRotationMatrix( m1 );
  5141. if ( parent ) {
  5142. m1.extractRotation( parent.matrixWorld );
  5143. q1.setFromRotationMatrix( m1 );
  5144. this.quaternion.premultiply( q1.inverse() );
  5145. }
  5146. };
  5147. }(),
  5148. add: function ( object ) {
  5149. if ( arguments.length > 1 ) {
  5150. for ( var i = 0; i < arguments.length; i ++ ) {
  5151. this.add( arguments[ i ] );
  5152. }
  5153. return this;
  5154. }
  5155. if ( object === this ) {
  5156. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5157. return this;
  5158. }
  5159. if ( ( object && object.isObject3D ) ) {
  5160. if ( object.parent !== null ) {
  5161. object.parent.remove( object );
  5162. }
  5163. object.parent = this;
  5164. object.dispatchEvent( { type: 'added' } );
  5165. this.children.push( object );
  5166. } else {
  5167. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5168. }
  5169. return this;
  5170. },
  5171. remove: function ( object ) {
  5172. if ( arguments.length > 1 ) {
  5173. for ( var i = 0; i < arguments.length; i ++ ) {
  5174. this.remove( arguments[ i ] );
  5175. }
  5176. return this;
  5177. }
  5178. var index = this.children.indexOf( object );
  5179. if ( index !== - 1 ) {
  5180. object.parent = null;
  5181. object.dispatchEvent( { type: 'removed' } );
  5182. this.children.splice( index, 1 );
  5183. }
  5184. return this;
  5185. },
  5186. getObjectById: function ( id ) {
  5187. return this.getObjectByProperty( 'id', id );
  5188. },
  5189. getObjectByName: function ( name ) {
  5190. return this.getObjectByProperty( 'name', name );
  5191. },
  5192. getObjectByProperty: function ( name, value ) {
  5193. if ( this[ name ] === value ) return this;
  5194. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5195. var child = this.children[ i ];
  5196. var object = child.getObjectByProperty( name, value );
  5197. if ( object !== undefined ) {
  5198. return object;
  5199. }
  5200. }
  5201. return undefined;
  5202. },
  5203. getWorldPosition: function ( target ) {
  5204. if ( target === undefined ) {
  5205. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  5206. target = new Vector3();
  5207. }
  5208. this.updateMatrixWorld( true );
  5209. return target.setFromMatrixPosition( this.matrixWorld );
  5210. },
  5211. getWorldQuaternion: function () {
  5212. var position = new Vector3();
  5213. var scale = new Vector3();
  5214. return function getWorldQuaternion( target ) {
  5215. if ( target === undefined ) {
  5216. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5217. target = new Quaternion();
  5218. }
  5219. this.updateMatrixWorld( true );
  5220. this.matrixWorld.decompose( position, target, scale );
  5221. return target;
  5222. };
  5223. }(),
  5224. getWorldScale: function () {
  5225. var position = new Vector3();
  5226. var quaternion = new Quaternion();
  5227. return function getWorldScale( target ) {
  5228. if ( target === undefined ) {
  5229. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5230. target = new Vector3();
  5231. }
  5232. this.updateMatrixWorld( true );
  5233. this.matrixWorld.decompose( position, quaternion, target );
  5234. return target;
  5235. };
  5236. }(),
  5237. getWorldDirection: function ( target ) {
  5238. if ( target === undefined ) {
  5239. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5240. target = new Vector3();
  5241. }
  5242. this.updateMatrixWorld( true );
  5243. var e = this.matrixWorld.elements;
  5244. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  5245. },
  5246. raycast: function () {},
  5247. traverse: function ( callback ) {
  5248. callback( this );
  5249. var children = this.children;
  5250. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5251. children[ i ].traverse( callback );
  5252. }
  5253. },
  5254. traverseVisible: function ( callback ) {
  5255. if ( this.visible === false ) return;
  5256. callback( this );
  5257. var children = this.children;
  5258. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5259. children[ i ].traverseVisible( callback );
  5260. }
  5261. },
  5262. traverseAncestors: function ( callback ) {
  5263. var parent = this.parent;
  5264. if ( parent !== null ) {
  5265. callback( parent );
  5266. parent.traverseAncestors( callback );
  5267. }
  5268. },
  5269. updateMatrix: function () {
  5270. this.matrix.compose( this.position, this.quaternion, this.scale );
  5271. this.matrixWorldNeedsUpdate = true;
  5272. },
  5273. updateMatrixWorld: function ( force ) {
  5274. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5275. if ( this.matrixWorldNeedsUpdate || force ) {
  5276. if ( this.parent === null ) {
  5277. this.matrixWorld.copy( this.matrix );
  5278. } else {
  5279. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5280. }
  5281. this.matrixWorldNeedsUpdate = false;
  5282. force = true;
  5283. }
  5284. // update children
  5285. var children = this.children;
  5286. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5287. children[ i ].updateMatrixWorld( force );
  5288. }
  5289. },
  5290. updateWorldMatrix: function ( updateParents, updateChildren ) {
  5291. var parent = this.parent;
  5292. if ( updateParents === true && parent !== null ) {
  5293. parent.updateWorldMatrix( true, false );
  5294. }
  5295. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5296. if ( this.parent === null ) {
  5297. this.matrixWorld.copy( this.matrix );
  5298. } else {
  5299. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5300. }
  5301. // update children
  5302. if ( updateChildren === true ) {
  5303. var children = this.children;
  5304. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5305. children[ i ].updateWorldMatrix( false, true );
  5306. }
  5307. }
  5308. },
  5309. toJSON: function ( meta ) {
  5310. // meta is a string when called from JSON.stringify
  5311. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5312. var output = {};
  5313. // meta is a hash used to collect geometries, materials.
  5314. // not providing it implies that this is the root object
  5315. // being serialized.
  5316. if ( isRootObject ) {
  5317. // initialize meta obj
  5318. meta = {
  5319. geometries: {},
  5320. materials: {},
  5321. textures: {},
  5322. images: {},
  5323. shapes: {}
  5324. };
  5325. output.metadata = {
  5326. version: 4.5,
  5327. type: 'Object',
  5328. generator: 'Object3D.toJSON'
  5329. };
  5330. }
  5331. // standard Object3D serialization
  5332. var object = {};
  5333. object.uuid = this.uuid;
  5334. object.type = this.type;
  5335. if ( this.name !== '' ) object.name = this.name;
  5336. if ( this.castShadow === true ) object.castShadow = true;
  5337. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5338. if ( this.visible === false ) object.visible = false;
  5339. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5340. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5341. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5342. object.layers = this.layers.mask;
  5343. object.matrix = this.matrix.toArray();
  5344. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5345. // object specific properties
  5346. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  5347. //
  5348. function serialize( library, element ) {
  5349. if ( library[ element.uuid ] === undefined ) {
  5350. library[ element.uuid ] = element.toJSON( meta );
  5351. }
  5352. return element.uuid;
  5353. }
  5354. if ( this.isMesh || this.isLine || this.isPoints ) {
  5355. object.geometry = serialize( meta.geometries, this.geometry );
  5356. var parameters = this.geometry.parameters;
  5357. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5358. var shapes = parameters.shapes;
  5359. if ( Array.isArray( shapes ) ) {
  5360. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5361. var shape = shapes[ i ];
  5362. serialize( meta.shapes, shape );
  5363. }
  5364. } else {
  5365. serialize( meta.shapes, shapes );
  5366. }
  5367. }
  5368. }
  5369. if ( this.material !== undefined ) {
  5370. if ( Array.isArray( this.material ) ) {
  5371. var uuids = [];
  5372. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5373. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5374. }
  5375. object.material = uuids;
  5376. } else {
  5377. object.material = serialize( meta.materials, this.material );
  5378. }
  5379. }
  5380. //
  5381. if ( this.children.length > 0 ) {
  5382. object.children = [];
  5383. for ( var i = 0; i < this.children.length; i ++ ) {
  5384. object.children.push( this.children[ i ].toJSON( meta ).object );
  5385. }
  5386. }
  5387. if ( isRootObject ) {
  5388. var geometries = extractFromCache( meta.geometries );
  5389. var materials = extractFromCache( meta.materials );
  5390. var textures = extractFromCache( meta.textures );
  5391. var images = extractFromCache( meta.images );
  5392. var shapes = extractFromCache( meta.shapes );
  5393. if ( geometries.length > 0 ) output.geometries = geometries;
  5394. if ( materials.length > 0 ) output.materials = materials;
  5395. if ( textures.length > 0 ) output.textures = textures;
  5396. if ( images.length > 0 ) output.images = images;
  5397. if ( shapes.length > 0 ) output.shapes = shapes;
  5398. }
  5399. output.object = object;
  5400. return output;
  5401. // extract data from the cache hash
  5402. // remove metadata on each item
  5403. // and return as array
  5404. function extractFromCache( cache ) {
  5405. var values = [];
  5406. for ( var key in cache ) {
  5407. var data = cache[ key ];
  5408. delete data.metadata;
  5409. values.push( data );
  5410. }
  5411. return values;
  5412. }
  5413. },
  5414. clone: function ( recursive ) {
  5415. return new this.constructor().copy( this, recursive );
  5416. },
  5417. copy: function ( source, recursive ) {
  5418. if ( recursive === undefined ) recursive = true;
  5419. this.name = source.name;
  5420. this.up.copy( source.up );
  5421. this.position.copy( source.position );
  5422. this.quaternion.copy( source.quaternion );
  5423. this.scale.copy( source.scale );
  5424. this.matrix.copy( source.matrix );
  5425. this.matrixWorld.copy( source.matrixWorld );
  5426. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5427. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5428. this.layers.mask = source.layers.mask;
  5429. this.visible = source.visible;
  5430. this.castShadow = source.castShadow;
  5431. this.receiveShadow = source.receiveShadow;
  5432. this.frustumCulled = source.frustumCulled;
  5433. this.renderOrder = source.renderOrder;
  5434. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5435. if ( recursive === true ) {
  5436. for ( var i = 0; i < source.children.length; i ++ ) {
  5437. var child = source.children[ i ];
  5438. this.add( child.clone() );
  5439. }
  5440. }
  5441. return this;
  5442. }
  5443. } );
  5444. /**
  5445. * @author mrdoob / http://mrdoob.com/
  5446. * @author kile / http://kile.stravaganza.org/
  5447. * @author alteredq / http://alteredqualia.com/
  5448. * @author mikael emtinger / http://gomo.se/
  5449. * @author zz85 / http://www.lab4games.net/zz85/blog
  5450. * @author bhouston / http://clara.io
  5451. */
  5452. var geometryId = 0; // Geometry uses even numbers as Id
  5453. function Geometry() {
  5454. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5455. this.uuid = _Math.generateUUID();
  5456. this.name = '';
  5457. this.type = 'Geometry';
  5458. this.vertices = [];
  5459. this.colors = [];
  5460. this.faces = [];
  5461. this.faceVertexUvs = [[]];
  5462. this.morphTargets = [];
  5463. this.morphNormals = [];
  5464. this.skinWeights = [];
  5465. this.skinIndices = [];
  5466. this.lineDistances = [];
  5467. this.boundingBox = null;
  5468. this.boundingSphere = null;
  5469. // update flags
  5470. this.elementsNeedUpdate = false;
  5471. this.verticesNeedUpdate = false;
  5472. this.uvsNeedUpdate = false;
  5473. this.normalsNeedUpdate = false;
  5474. this.colorsNeedUpdate = false;
  5475. this.lineDistancesNeedUpdate = false;
  5476. this.groupsNeedUpdate = false;
  5477. }
  5478. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5479. constructor: Geometry,
  5480. isGeometry: true,
  5481. applyMatrix: function ( matrix ) {
  5482. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5483. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5484. var vertex = this.vertices[ i ];
  5485. vertex.applyMatrix4( matrix );
  5486. }
  5487. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5488. var face = this.faces[ i ];
  5489. face.normal.applyMatrix3( normalMatrix ).normalize();
  5490. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5491. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5492. }
  5493. }
  5494. if ( this.boundingBox !== null ) {
  5495. this.computeBoundingBox();
  5496. }
  5497. if ( this.boundingSphere !== null ) {
  5498. this.computeBoundingSphere();
  5499. }
  5500. this.verticesNeedUpdate = true;
  5501. this.normalsNeedUpdate = true;
  5502. return this;
  5503. },
  5504. rotateX: function () {
  5505. // rotate geometry around world x-axis
  5506. var m1 = new Matrix4();
  5507. return function rotateX( angle ) {
  5508. m1.makeRotationX( angle );
  5509. this.applyMatrix( m1 );
  5510. return this;
  5511. };
  5512. }(),
  5513. rotateY: function () {
  5514. // rotate geometry around world y-axis
  5515. var m1 = new Matrix4();
  5516. return function rotateY( angle ) {
  5517. m1.makeRotationY( angle );
  5518. this.applyMatrix( m1 );
  5519. return this;
  5520. };
  5521. }(),
  5522. rotateZ: function () {
  5523. // rotate geometry around world z-axis
  5524. var m1 = new Matrix4();
  5525. return function rotateZ( angle ) {
  5526. m1.makeRotationZ( angle );
  5527. this.applyMatrix( m1 );
  5528. return this;
  5529. };
  5530. }(),
  5531. translate: function () {
  5532. // translate geometry
  5533. var m1 = new Matrix4();
  5534. return function translate( x, y, z ) {
  5535. m1.makeTranslation( x, y, z );
  5536. this.applyMatrix( m1 );
  5537. return this;
  5538. };
  5539. }(),
  5540. scale: function () {
  5541. // scale geometry
  5542. var m1 = new Matrix4();
  5543. return function scale( x, y, z ) {
  5544. m1.makeScale( x, y, z );
  5545. this.applyMatrix( m1 );
  5546. return this;
  5547. };
  5548. }(),
  5549. lookAt: function () {
  5550. var obj = new Object3D();
  5551. return function lookAt( vector ) {
  5552. obj.lookAt( vector );
  5553. obj.updateMatrix();
  5554. this.applyMatrix( obj.matrix );
  5555. };
  5556. }(),
  5557. fromBufferGeometry: function ( geometry ) {
  5558. var scope = this;
  5559. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5560. var attributes = geometry.attributes;
  5561. var positions = attributes.position.array;
  5562. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5563. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5564. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5565. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5566. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5567. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5568. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  5569. if ( colors !== undefined ) {
  5570. scope.colors.push( new Color().fromArray( colors, i ) );
  5571. }
  5572. }
  5573. function addFace( a, b, c, materialIndex ) {
  5574. var vertexColors = ( colors === undefined ) ? [] : [
  5575. scope.colors[ a ].clone(),
  5576. scope.colors[ b ].clone(),
  5577. scope.colors[ c ].clone() ];
  5578. var vertexNormals = ( normals === undefined ) ? [] : [
  5579. new Vector3().fromArray( normals, a * 3 ),
  5580. new Vector3().fromArray( normals, b * 3 ),
  5581. new Vector3().fromArray( normals, c * 3 )
  5582. ];
  5583. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5584. scope.faces.push( face );
  5585. if ( uvs !== undefined ) {
  5586. scope.faceVertexUvs[ 0 ].push( [
  5587. new Vector2().fromArray( uvs, a * 2 ),
  5588. new Vector2().fromArray( uvs, b * 2 ),
  5589. new Vector2().fromArray( uvs, c * 2 )
  5590. ] );
  5591. }
  5592. if ( uvs2 !== undefined ) {
  5593. scope.faceVertexUvs[ 1 ].push( [
  5594. new Vector2().fromArray( uvs2, a * 2 ),
  5595. new Vector2().fromArray( uvs2, b * 2 ),
  5596. new Vector2().fromArray( uvs2, c * 2 )
  5597. ] );
  5598. }
  5599. }
  5600. var groups = geometry.groups;
  5601. if ( groups.length > 0 ) {
  5602. for ( var i = 0; i < groups.length; i ++ ) {
  5603. var group = groups[ i ];
  5604. var start = group.start;
  5605. var count = group.count;
  5606. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5607. if ( indices !== undefined ) {
  5608. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5609. } else {
  5610. addFace( j, j + 1, j + 2, group.materialIndex );
  5611. }
  5612. }
  5613. }
  5614. } else {
  5615. if ( indices !== undefined ) {
  5616. for ( var i = 0; i < indices.length; i += 3 ) {
  5617. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5618. }
  5619. } else {
  5620. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5621. addFace( i, i + 1, i + 2 );
  5622. }
  5623. }
  5624. }
  5625. this.computeFaceNormals();
  5626. if ( geometry.boundingBox !== null ) {
  5627. this.boundingBox = geometry.boundingBox.clone();
  5628. }
  5629. if ( geometry.boundingSphere !== null ) {
  5630. this.boundingSphere = geometry.boundingSphere.clone();
  5631. }
  5632. return this;
  5633. },
  5634. center: function () {
  5635. var offset = new Vector3();
  5636. return function center() {
  5637. this.computeBoundingBox();
  5638. this.boundingBox.getCenter( offset ).negate();
  5639. this.translate( offset.x, offset.y, offset.z );
  5640. return this;
  5641. };
  5642. }(),
  5643. normalize: function () {
  5644. this.computeBoundingSphere();
  5645. var center = this.boundingSphere.center;
  5646. var radius = this.boundingSphere.radius;
  5647. var s = radius === 0 ? 1 : 1.0 / radius;
  5648. var matrix = new Matrix4();
  5649. matrix.set(
  5650. s, 0, 0, - s * center.x,
  5651. 0, s, 0, - s * center.y,
  5652. 0, 0, s, - s * center.z,
  5653. 0, 0, 0, 1
  5654. );
  5655. this.applyMatrix( matrix );
  5656. return this;
  5657. },
  5658. computeFaceNormals: function () {
  5659. var cb = new Vector3(), ab = new Vector3();
  5660. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5661. var face = this.faces[ f ];
  5662. var vA = this.vertices[ face.a ];
  5663. var vB = this.vertices[ face.b ];
  5664. var vC = this.vertices[ face.c ];
  5665. cb.subVectors( vC, vB );
  5666. ab.subVectors( vA, vB );
  5667. cb.cross( ab );
  5668. cb.normalize();
  5669. face.normal.copy( cb );
  5670. }
  5671. },
  5672. computeVertexNormals: function ( areaWeighted ) {
  5673. if ( areaWeighted === undefined ) areaWeighted = true;
  5674. var v, vl, f, fl, face, vertices;
  5675. vertices = new Array( this.vertices.length );
  5676. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5677. vertices[ v ] = new Vector3();
  5678. }
  5679. if ( areaWeighted ) {
  5680. // vertex normals weighted by triangle areas
  5681. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5682. var vA, vB, vC;
  5683. var cb = new Vector3(), ab = new Vector3();
  5684. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5685. face = this.faces[ f ];
  5686. vA = this.vertices[ face.a ];
  5687. vB = this.vertices[ face.b ];
  5688. vC = this.vertices[ face.c ];
  5689. cb.subVectors( vC, vB );
  5690. ab.subVectors( vA, vB );
  5691. cb.cross( ab );
  5692. vertices[ face.a ].add( cb );
  5693. vertices[ face.b ].add( cb );
  5694. vertices[ face.c ].add( cb );
  5695. }
  5696. } else {
  5697. this.computeFaceNormals();
  5698. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5699. face = this.faces[ f ];
  5700. vertices[ face.a ].add( face.normal );
  5701. vertices[ face.b ].add( face.normal );
  5702. vertices[ face.c ].add( face.normal );
  5703. }
  5704. }
  5705. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5706. vertices[ v ].normalize();
  5707. }
  5708. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5709. face = this.faces[ f ];
  5710. var vertexNormals = face.vertexNormals;
  5711. if ( vertexNormals.length === 3 ) {
  5712. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5713. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5714. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5715. } else {
  5716. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5717. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5718. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5719. }
  5720. }
  5721. if ( this.faces.length > 0 ) {
  5722. this.normalsNeedUpdate = true;
  5723. }
  5724. },
  5725. computeFlatVertexNormals: function () {
  5726. var f, fl, face;
  5727. this.computeFaceNormals();
  5728. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5729. face = this.faces[ f ];
  5730. var vertexNormals = face.vertexNormals;
  5731. if ( vertexNormals.length === 3 ) {
  5732. vertexNormals[ 0 ].copy( face.normal );
  5733. vertexNormals[ 1 ].copy( face.normal );
  5734. vertexNormals[ 2 ].copy( face.normal );
  5735. } else {
  5736. vertexNormals[ 0 ] = face.normal.clone();
  5737. vertexNormals[ 1 ] = face.normal.clone();
  5738. vertexNormals[ 2 ] = face.normal.clone();
  5739. }
  5740. }
  5741. if ( this.faces.length > 0 ) {
  5742. this.normalsNeedUpdate = true;
  5743. }
  5744. },
  5745. computeMorphNormals: function () {
  5746. var i, il, f, fl, face;
  5747. // save original normals
  5748. // - create temp variables on first access
  5749. // otherwise just copy (for faster repeated calls)
  5750. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5751. face = this.faces[ f ];
  5752. if ( ! face.__originalFaceNormal ) {
  5753. face.__originalFaceNormal = face.normal.clone();
  5754. } else {
  5755. face.__originalFaceNormal.copy( face.normal );
  5756. }
  5757. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5758. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5759. if ( ! face.__originalVertexNormals[ i ] ) {
  5760. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5761. } else {
  5762. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5763. }
  5764. }
  5765. }
  5766. // use temp geometry to compute face and vertex normals for each morph
  5767. var tmpGeo = new Geometry();
  5768. tmpGeo.faces = this.faces;
  5769. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5770. // create on first access
  5771. if ( ! this.morphNormals[ i ] ) {
  5772. this.morphNormals[ i ] = {};
  5773. this.morphNormals[ i ].faceNormals = [];
  5774. this.morphNormals[ i ].vertexNormals = [];
  5775. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5776. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5777. var faceNormal, vertexNormals;
  5778. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5779. faceNormal = new Vector3();
  5780. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5781. dstNormalsFace.push( faceNormal );
  5782. dstNormalsVertex.push( vertexNormals );
  5783. }
  5784. }
  5785. var morphNormals = this.morphNormals[ i ];
  5786. // set vertices to morph target
  5787. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5788. // compute morph normals
  5789. tmpGeo.computeFaceNormals();
  5790. tmpGeo.computeVertexNormals();
  5791. // store morph normals
  5792. var faceNormal, vertexNormals;
  5793. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5794. face = this.faces[ f ];
  5795. faceNormal = morphNormals.faceNormals[ f ];
  5796. vertexNormals = morphNormals.vertexNormals[ f ];
  5797. faceNormal.copy( face.normal );
  5798. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5799. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5800. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5801. }
  5802. }
  5803. // restore original normals
  5804. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5805. face = this.faces[ f ];
  5806. face.normal = face.__originalFaceNormal;
  5807. face.vertexNormals = face.__originalVertexNormals;
  5808. }
  5809. },
  5810. computeBoundingBox: function () {
  5811. if ( this.boundingBox === null ) {
  5812. this.boundingBox = new Box3();
  5813. }
  5814. this.boundingBox.setFromPoints( this.vertices );
  5815. },
  5816. computeBoundingSphere: function () {
  5817. if ( this.boundingSphere === null ) {
  5818. this.boundingSphere = new Sphere();
  5819. }
  5820. this.boundingSphere.setFromPoints( this.vertices );
  5821. },
  5822. merge: function ( geometry, matrix, materialIndexOffset ) {
  5823. if ( ! ( geometry && geometry.isGeometry ) ) {
  5824. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5825. return;
  5826. }
  5827. var normalMatrix,
  5828. vertexOffset = this.vertices.length,
  5829. vertices1 = this.vertices,
  5830. vertices2 = geometry.vertices,
  5831. faces1 = this.faces,
  5832. faces2 = geometry.faces,
  5833. uvs1 = this.faceVertexUvs[ 0 ],
  5834. uvs2 = geometry.faceVertexUvs[ 0 ],
  5835. colors1 = this.colors,
  5836. colors2 = geometry.colors;
  5837. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5838. if ( matrix !== undefined ) {
  5839. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5840. }
  5841. // vertices
  5842. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5843. var vertex = vertices2[ i ];
  5844. var vertexCopy = vertex.clone();
  5845. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5846. vertices1.push( vertexCopy );
  5847. }
  5848. // colors
  5849. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5850. colors1.push( colors2[ i ].clone() );
  5851. }
  5852. // faces
  5853. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5854. var face = faces2[ i ], faceCopy, normal, color,
  5855. faceVertexNormals = face.vertexNormals,
  5856. faceVertexColors = face.vertexColors;
  5857. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5858. faceCopy.normal.copy( face.normal );
  5859. if ( normalMatrix !== undefined ) {
  5860. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5861. }
  5862. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5863. normal = faceVertexNormals[ j ].clone();
  5864. if ( normalMatrix !== undefined ) {
  5865. normal.applyMatrix3( normalMatrix ).normalize();
  5866. }
  5867. faceCopy.vertexNormals.push( normal );
  5868. }
  5869. faceCopy.color.copy( face.color );
  5870. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5871. color = faceVertexColors[ j ];
  5872. faceCopy.vertexColors.push( color.clone() );
  5873. }
  5874. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5875. faces1.push( faceCopy );
  5876. }
  5877. // uvs
  5878. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5879. var uv = uvs2[ i ], uvCopy = [];
  5880. if ( uv === undefined ) {
  5881. continue;
  5882. }
  5883. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5884. uvCopy.push( uv[ j ].clone() );
  5885. }
  5886. uvs1.push( uvCopy );
  5887. }
  5888. },
  5889. mergeMesh: function ( mesh ) {
  5890. if ( ! ( mesh && mesh.isMesh ) ) {
  5891. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5892. return;
  5893. }
  5894. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5895. this.merge( mesh.geometry, mesh.matrix );
  5896. },
  5897. /*
  5898. * Checks for duplicate vertices with hashmap.
  5899. * Duplicated vertices are removed
  5900. * and faces' vertices are updated.
  5901. */
  5902. mergeVertices: function () {
  5903. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5904. var unique = [], changes = [];
  5905. var v, key;
  5906. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5907. var precision = Math.pow( 10, precisionPoints );
  5908. var i, il, face;
  5909. var indices, j, jl;
  5910. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5911. v = this.vertices[ i ];
  5912. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5913. if ( verticesMap[ key ] === undefined ) {
  5914. verticesMap[ key ] = i;
  5915. unique.push( this.vertices[ i ] );
  5916. changes[ i ] = unique.length - 1;
  5917. } else {
  5918. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5919. changes[ i ] = changes[ verticesMap[ key ] ];
  5920. }
  5921. }
  5922. // if faces are completely degenerate after merging vertices, we
  5923. // have to remove them from the geometry.
  5924. var faceIndicesToRemove = [];
  5925. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5926. face = this.faces[ i ];
  5927. face.a = changes[ face.a ];
  5928. face.b = changes[ face.b ];
  5929. face.c = changes[ face.c ];
  5930. indices = [ face.a, face.b, face.c ];
  5931. // if any duplicate vertices are found in a Face3
  5932. // we have to remove the face as nothing can be saved
  5933. for ( var n = 0; n < 3; n ++ ) {
  5934. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5935. faceIndicesToRemove.push( i );
  5936. break;
  5937. }
  5938. }
  5939. }
  5940. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5941. var idx = faceIndicesToRemove[ i ];
  5942. this.faces.splice( idx, 1 );
  5943. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5944. this.faceVertexUvs[ j ].splice( idx, 1 );
  5945. }
  5946. }
  5947. // Use unique set of vertices
  5948. var diff = this.vertices.length - unique.length;
  5949. this.vertices = unique;
  5950. return diff;
  5951. },
  5952. setFromPoints: function ( points ) {
  5953. this.vertices = [];
  5954. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5955. var point = points[ i ];
  5956. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5957. }
  5958. return this;
  5959. },
  5960. sortFacesByMaterialIndex: function () {
  5961. var faces = this.faces;
  5962. var length = faces.length;
  5963. // tag faces
  5964. for ( var i = 0; i < length; i ++ ) {
  5965. faces[ i ]._id = i;
  5966. }
  5967. // sort faces
  5968. function materialIndexSort( a, b ) {
  5969. return a.materialIndex - b.materialIndex;
  5970. }
  5971. faces.sort( materialIndexSort );
  5972. // sort uvs
  5973. var uvs1 = this.faceVertexUvs[ 0 ];
  5974. var uvs2 = this.faceVertexUvs[ 1 ];
  5975. var newUvs1, newUvs2;
  5976. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5977. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5978. for ( var i = 0; i < length; i ++ ) {
  5979. var id = faces[ i ]._id;
  5980. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5981. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5982. }
  5983. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5984. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5985. },
  5986. toJSON: function () {
  5987. var data = {
  5988. metadata: {
  5989. version: 4.5,
  5990. type: 'Geometry',
  5991. generator: 'Geometry.toJSON'
  5992. }
  5993. };
  5994. // standard Geometry serialization
  5995. data.uuid = this.uuid;
  5996. data.type = this.type;
  5997. if ( this.name !== '' ) data.name = this.name;
  5998. if ( this.parameters !== undefined ) {
  5999. var parameters = this.parameters;
  6000. for ( var key in parameters ) {
  6001. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6002. }
  6003. return data;
  6004. }
  6005. var vertices = [];
  6006. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6007. var vertex = this.vertices[ i ];
  6008. vertices.push( vertex.x, vertex.y, vertex.z );
  6009. }
  6010. var faces = [];
  6011. var normals = [];
  6012. var normalsHash = {};
  6013. var colors = [];
  6014. var colorsHash = {};
  6015. var uvs = [];
  6016. var uvsHash = {};
  6017. for ( var i = 0; i < this.faces.length; i ++ ) {
  6018. var face = this.faces[ i ];
  6019. var hasMaterial = true;
  6020. var hasFaceUv = false; // deprecated
  6021. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6022. var hasFaceNormal = face.normal.length() > 0;
  6023. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6024. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6025. var hasFaceVertexColor = face.vertexColors.length > 0;
  6026. var faceType = 0;
  6027. faceType = setBit( faceType, 0, 0 ); // isQuad
  6028. faceType = setBit( faceType, 1, hasMaterial );
  6029. faceType = setBit( faceType, 2, hasFaceUv );
  6030. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6031. faceType = setBit( faceType, 4, hasFaceNormal );
  6032. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6033. faceType = setBit( faceType, 6, hasFaceColor );
  6034. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6035. faces.push( faceType );
  6036. faces.push( face.a, face.b, face.c );
  6037. faces.push( face.materialIndex );
  6038. if ( hasFaceVertexUv ) {
  6039. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6040. faces.push(
  6041. getUvIndex( faceVertexUvs[ 0 ] ),
  6042. getUvIndex( faceVertexUvs[ 1 ] ),
  6043. getUvIndex( faceVertexUvs[ 2 ] )
  6044. );
  6045. }
  6046. if ( hasFaceNormal ) {
  6047. faces.push( getNormalIndex( face.normal ) );
  6048. }
  6049. if ( hasFaceVertexNormal ) {
  6050. var vertexNormals = face.vertexNormals;
  6051. faces.push(
  6052. getNormalIndex( vertexNormals[ 0 ] ),
  6053. getNormalIndex( vertexNormals[ 1 ] ),
  6054. getNormalIndex( vertexNormals[ 2 ] )
  6055. );
  6056. }
  6057. if ( hasFaceColor ) {
  6058. faces.push( getColorIndex( face.color ) );
  6059. }
  6060. if ( hasFaceVertexColor ) {
  6061. var vertexColors = face.vertexColors;
  6062. faces.push(
  6063. getColorIndex( vertexColors[ 0 ] ),
  6064. getColorIndex( vertexColors[ 1 ] ),
  6065. getColorIndex( vertexColors[ 2 ] )
  6066. );
  6067. }
  6068. }
  6069. function setBit( value, position, enabled ) {
  6070. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6071. }
  6072. function getNormalIndex( normal ) {
  6073. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6074. if ( normalsHash[ hash ] !== undefined ) {
  6075. return normalsHash[ hash ];
  6076. }
  6077. normalsHash[ hash ] = normals.length / 3;
  6078. normals.push( normal.x, normal.y, normal.z );
  6079. return normalsHash[ hash ];
  6080. }
  6081. function getColorIndex( color ) {
  6082. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6083. if ( colorsHash[ hash ] !== undefined ) {
  6084. return colorsHash[ hash ];
  6085. }
  6086. colorsHash[ hash ] = colors.length;
  6087. colors.push( color.getHex() );
  6088. return colorsHash[ hash ];
  6089. }
  6090. function getUvIndex( uv ) {
  6091. var hash = uv.x.toString() + uv.y.toString();
  6092. if ( uvsHash[ hash ] !== undefined ) {
  6093. return uvsHash[ hash ];
  6094. }
  6095. uvsHash[ hash ] = uvs.length / 2;
  6096. uvs.push( uv.x, uv.y );
  6097. return uvsHash[ hash ];
  6098. }
  6099. data.data = {};
  6100. data.data.vertices = vertices;
  6101. data.data.normals = normals;
  6102. if ( colors.length > 0 ) data.data.colors = colors;
  6103. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6104. data.data.faces = faces;
  6105. return data;
  6106. },
  6107. clone: function () {
  6108. /*
  6109. // Handle primitives
  6110. var parameters = this.parameters;
  6111. if ( parameters !== undefined ) {
  6112. var values = [];
  6113. for ( var key in parameters ) {
  6114. values.push( parameters[ key ] );
  6115. }
  6116. var geometry = Object.create( this.constructor.prototype );
  6117. this.constructor.apply( geometry, values );
  6118. return geometry;
  6119. }
  6120. return new this.constructor().copy( this );
  6121. */
  6122. return new Geometry().copy( this );
  6123. },
  6124. copy: function ( source ) {
  6125. var i, il, j, jl, k, kl;
  6126. // reset
  6127. this.vertices = [];
  6128. this.colors = [];
  6129. this.faces = [];
  6130. this.faceVertexUvs = [[]];
  6131. this.morphTargets = [];
  6132. this.morphNormals = [];
  6133. this.skinWeights = [];
  6134. this.skinIndices = [];
  6135. this.lineDistances = [];
  6136. this.boundingBox = null;
  6137. this.boundingSphere = null;
  6138. // name
  6139. this.name = source.name;
  6140. // vertices
  6141. var vertices = source.vertices;
  6142. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6143. this.vertices.push( vertices[ i ].clone() );
  6144. }
  6145. // colors
  6146. var colors = source.colors;
  6147. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6148. this.colors.push( colors[ i ].clone() );
  6149. }
  6150. // faces
  6151. var faces = source.faces;
  6152. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6153. this.faces.push( faces[ i ].clone() );
  6154. }
  6155. // face vertex uvs
  6156. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6157. var faceVertexUvs = source.faceVertexUvs[ i ];
  6158. if ( this.faceVertexUvs[ i ] === undefined ) {
  6159. this.faceVertexUvs[ i ] = [];
  6160. }
  6161. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6162. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6163. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6164. var uv = uvs[ k ];
  6165. uvsCopy.push( uv.clone() );
  6166. }
  6167. this.faceVertexUvs[ i ].push( uvsCopy );
  6168. }
  6169. }
  6170. // morph targets
  6171. var morphTargets = source.morphTargets;
  6172. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6173. var morphTarget = {};
  6174. morphTarget.name = morphTargets[ i ].name;
  6175. // vertices
  6176. if ( morphTargets[ i ].vertices !== undefined ) {
  6177. morphTarget.vertices = [];
  6178. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6179. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6180. }
  6181. }
  6182. // normals
  6183. if ( morphTargets[ i ].normals !== undefined ) {
  6184. morphTarget.normals = [];
  6185. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6186. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6187. }
  6188. }
  6189. this.morphTargets.push( morphTarget );
  6190. }
  6191. // morph normals
  6192. var morphNormals = source.morphNormals;
  6193. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6194. var morphNormal = {};
  6195. // vertex normals
  6196. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6197. morphNormal.vertexNormals = [];
  6198. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6199. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6200. var destVertexNormal = {};
  6201. destVertexNormal.a = srcVertexNormal.a.clone();
  6202. destVertexNormal.b = srcVertexNormal.b.clone();
  6203. destVertexNormal.c = srcVertexNormal.c.clone();
  6204. morphNormal.vertexNormals.push( destVertexNormal );
  6205. }
  6206. }
  6207. // face normals
  6208. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6209. morphNormal.faceNormals = [];
  6210. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6211. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6212. }
  6213. }
  6214. this.morphNormals.push( morphNormal );
  6215. }
  6216. // skin weights
  6217. var skinWeights = source.skinWeights;
  6218. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6219. this.skinWeights.push( skinWeights[ i ].clone() );
  6220. }
  6221. // skin indices
  6222. var skinIndices = source.skinIndices;
  6223. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6224. this.skinIndices.push( skinIndices[ i ].clone() );
  6225. }
  6226. // line distances
  6227. var lineDistances = source.lineDistances;
  6228. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6229. this.lineDistances.push( lineDistances[ i ] );
  6230. }
  6231. // bounding box
  6232. var boundingBox = source.boundingBox;
  6233. if ( boundingBox !== null ) {
  6234. this.boundingBox = boundingBox.clone();
  6235. }
  6236. // bounding sphere
  6237. var boundingSphere = source.boundingSphere;
  6238. if ( boundingSphere !== null ) {
  6239. this.boundingSphere = boundingSphere.clone();
  6240. }
  6241. // update flags
  6242. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6243. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6244. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6245. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6246. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6247. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6248. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6249. return this;
  6250. },
  6251. dispose: function () {
  6252. this.dispatchEvent( { type: 'dispose' } );
  6253. }
  6254. } );
  6255. /**
  6256. * @author mrdoob / http://mrdoob.com/
  6257. */
  6258. function BufferAttribute( array, itemSize, normalized ) {
  6259. if ( Array.isArray( array ) ) {
  6260. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6261. }
  6262. this.name = '';
  6263. this.array = array;
  6264. this.itemSize = itemSize;
  6265. this.count = array !== undefined ? array.length / itemSize : 0;
  6266. this.normalized = normalized === true;
  6267. this.dynamic = false;
  6268. this.updateRange = { offset: 0, count: - 1 };
  6269. this.version = 0;
  6270. }
  6271. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6272. set: function ( value ) {
  6273. if ( value === true ) this.version ++;
  6274. }
  6275. } );
  6276. Object.assign( BufferAttribute.prototype, {
  6277. isBufferAttribute: true,
  6278. onUploadCallback: function () {},
  6279. setArray: function ( array ) {
  6280. if ( Array.isArray( array ) ) {
  6281. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6282. }
  6283. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6284. this.array = array;
  6285. return this;
  6286. },
  6287. setDynamic: function ( value ) {
  6288. this.dynamic = value;
  6289. return this;
  6290. },
  6291. copy: function ( source ) {
  6292. this.name = source.name;
  6293. this.array = new source.array.constructor( source.array );
  6294. this.itemSize = source.itemSize;
  6295. this.count = source.count;
  6296. this.normalized = source.normalized;
  6297. this.dynamic = source.dynamic;
  6298. return this;
  6299. },
  6300. copyAt: function ( index1, attribute, index2 ) {
  6301. index1 *= this.itemSize;
  6302. index2 *= attribute.itemSize;
  6303. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6304. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6305. }
  6306. return this;
  6307. },
  6308. copyArray: function ( array ) {
  6309. this.array.set( array );
  6310. return this;
  6311. },
  6312. copyColorsArray: function ( colors ) {
  6313. var array = this.array, offset = 0;
  6314. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6315. var color = colors[ i ];
  6316. if ( color === undefined ) {
  6317. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6318. color = new Color();
  6319. }
  6320. array[ offset ++ ] = color.r;
  6321. array[ offset ++ ] = color.g;
  6322. array[ offset ++ ] = color.b;
  6323. }
  6324. return this;
  6325. },
  6326. copyVector2sArray: function ( vectors ) {
  6327. var array = this.array, offset = 0;
  6328. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6329. var vector = vectors[ i ];
  6330. if ( vector === undefined ) {
  6331. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6332. vector = new Vector2();
  6333. }
  6334. array[ offset ++ ] = vector.x;
  6335. array[ offset ++ ] = vector.y;
  6336. }
  6337. return this;
  6338. },
  6339. copyVector3sArray: function ( vectors ) {
  6340. var array = this.array, offset = 0;
  6341. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6342. var vector = vectors[ i ];
  6343. if ( vector === undefined ) {
  6344. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6345. vector = new Vector3();
  6346. }
  6347. array[ offset ++ ] = vector.x;
  6348. array[ offset ++ ] = vector.y;
  6349. array[ offset ++ ] = vector.z;
  6350. }
  6351. return this;
  6352. },
  6353. copyVector4sArray: function ( vectors ) {
  6354. var array = this.array, offset = 0;
  6355. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6356. var vector = vectors[ i ];
  6357. if ( vector === undefined ) {
  6358. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6359. vector = new Vector4();
  6360. }
  6361. array[ offset ++ ] = vector.x;
  6362. array[ offset ++ ] = vector.y;
  6363. array[ offset ++ ] = vector.z;
  6364. array[ offset ++ ] = vector.w;
  6365. }
  6366. return this;
  6367. },
  6368. set: function ( value, offset ) {
  6369. if ( offset === undefined ) offset = 0;
  6370. this.array.set( value, offset );
  6371. return this;
  6372. },
  6373. getX: function ( index ) {
  6374. return this.array[ index * this.itemSize ];
  6375. },
  6376. setX: function ( index, x ) {
  6377. this.array[ index * this.itemSize ] = x;
  6378. return this;
  6379. },
  6380. getY: function ( index ) {
  6381. return this.array[ index * this.itemSize + 1 ];
  6382. },
  6383. setY: function ( index, y ) {
  6384. this.array[ index * this.itemSize + 1 ] = y;
  6385. return this;
  6386. },
  6387. getZ: function ( index ) {
  6388. return this.array[ index * this.itemSize + 2 ];
  6389. },
  6390. setZ: function ( index, z ) {
  6391. this.array[ index * this.itemSize + 2 ] = z;
  6392. return this;
  6393. },
  6394. getW: function ( index ) {
  6395. return this.array[ index * this.itemSize + 3 ];
  6396. },
  6397. setW: function ( index, w ) {
  6398. this.array[ index * this.itemSize + 3 ] = w;
  6399. return this;
  6400. },
  6401. setXY: function ( index, x, y ) {
  6402. index *= this.itemSize;
  6403. this.array[ index + 0 ] = x;
  6404. this.array[ index + 1 ] = y;
  6405. return this;
  6406. },
  6407. setXYZ: function ( index, x, y, z ) {
  6408. index *= this.itemSize;
  6409. this.array[ index + 0 ] = x;
  6410. this.array[ index + 1 ] = y;
  6411. this.array[ index + 2 ] = z;
  6412. return this;
  6413. },
  6414. setXYZW: function ( index, x, y, z, w ) {
  6415. index *= this.itemSize;
  6416. this.array[ index + 0 ] = x;
  6417. this.array[ index + 1 ] = y;
  6418. this.array[ index + 2 ] = z;
  6419. this.array[ index + 3 ] = w;
  6420. return this;
  6421. },
  6422. onUpload: function ( callback ) {
  6423. this.onUploadCallback = callback;
  6424. return this;
  6425. },
  6426. clone: function () {
  6427. return new this.constructor( this.array, this.itemSize ).copy( this );
  6428. }
  6429. } );
  6430. //
  6431. function Int8BufferAttribute( array, itemSize, normalized ) {
  6432. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6433. }
  6434. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6435. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6436. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6437. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6438. }
  6439. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6440. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6441. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6442. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6443. }
  6444. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6445. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6446. function Int16BufferAttribute( array, itemSize, normalized ) {
  6447. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6448. }
  6449. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6450. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6451. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6452. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6453. }
  6454. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6455. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6456. function Int32BufferAttribute( array, itemSize, normalized ) {
  6457. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6458. }
  6459. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6460. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6461. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6462. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6463. }
  6464. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6465. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6466. function Float32BufferAttribute( array, itemSize, normalized ) {
  6467. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6468. }
  6469. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6470. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6471. function Float64BufferAttribute( array, itemSize, normalized ) {
  6472. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6473. }
  6474. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6475. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6476. /**
  6477. * @author mrdoob / http://mrdoob.com/
  6478. */
  6479. function DirectGeometry() {
  6480. this.vertices = [];
  6481. this.normals = [];
  6482. this.colors = [];
  6483. this.uvs = [];
  6484. this.uvs2 = [];
  6485. this.groups = [];
  6486. this.morphTargets = {};
  6487. this.skinWeights = [];
  6488. this.skinIndices = [];
  6489. // this.lineDistances = [];
  6490. this.boundingBox = null;
  6491. this.boundingSphere = null;
  6492. // update flags
  6493. this.verticesNeedUpdate = false;
  6494. this.normalsNeedUpdate = false;
  6495. this.colorsNeedUpdate = false;
  6496. this.uvsNeedUpdate = false;
  6497. this.groupsNeedUpdate = false;
  6498. }
  6499. Object.assign( DirectGeometry.prototype, {
  6500. computeGroups: function ( geometry ) {
  6501. var group;
  6502. var groups = [];
  6503. var materialIndex = undefined;
  6504. var faces = geometry.faces;
  6505. for ( var i = 0; i < faces.length; i ++ ) {
  6506. var face = faces[ i ];
  6507. // materials
  6508. if ( face.materialIndex !== materialIndex ) {
  6509. materialIndex = face.materialIndex;
  6510. if ( group !== undefined ) {
  6511. group.count = ( i * 3 ) - group.start;
  6512. groups.push( group );
  6513. }
  6514. group = {
  6515. start: i * 3,
  6516. materialIndex: materialIndex
  6517. };
  6518. }
  6519. }
  6520. if ( group !== undefined ) {
  6521. group.count = ( i * 3 ) - group.start;
  6522. groups.push( group );
  6523. }
  6524. this.groups = groups;
  6525. },
  6526. fromGeometry: function ( geometry ) {
  6527. var faces = geometry.faces;
  6528. var vertices = geometry.vertices;
  6529. var faceVertexUvs = geometry.faceVertexUvs;
  6530. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6531. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6532. // morphs
  6533. var morphTargets = geometry.morphTargets;
  6534. var morphTargetsLength = morphTargets.length;
  6535. var morphTargetsPosition;
  6536. if ( morphTargetsLength > 0 ) {
  6537. morphTargetsPosition = [];
  6538. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6539. morphTargetsPosition[ i ] = {
  6540. name: morphTargets[ i ].name,
  6541. data: []
  6542. };
  6543. }
  6544. this.morphTargets.position = morphTargetsPosition;
  6545. }
  6546. var morphNormals = geometry.morphNormals;
  6547. var morphNormalsLength = morphNormals.length;
  6548. var morphTargetsNormal;
  6549. if ( morphNormalsLength > 0 ) {
  6550. morphTargetsNormal = [];
  6551. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6552. morphTargetsNormal[ i ] = {
  6553. name: morphNormals[ i ].name,
  6554. data: []
  6555. };
  6556. }
  6557. this.morphTargets.normal = morphTargetsNormal;
  6558. }
  6559. // skins
  6560. var skinIndices = geometry.skinIndices;
  6561. var skinWeights = geometry.skinWeights;
  6562. var hasSkinIndices = skinIndices.length === vertices.length;
  6563. var hasSkinWeights = skinWeights.length === vertices.length;
  6564. //
  6565. if ( vertices.length > 0 && faces.length === 0 ) {
  6566. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6567. }
  6568. for ( var i = 0; i < faces.length; i ++ ) {
  6569. var face = faces[ i ];
  6570. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6571. var vertexNormals = face.vertexNormals;
  6572. if ( vertexNormals.length === 3 ) {
  6573. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6574. } else {
  6575. var normal = face.normal;
  6576. this.normals.push( normal, normal, normal );
  6577. }
  6578. var vertexColors = face.vertexColors;
  6579. if ( vertexColors.length === 3 ) {
  6580. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6581. } else {
  6582. var color = face.color;
  6583. this.colors.push( color, color, color );
  6584. }
  6585. if ( hasFaceVertexUv === true ) {
  6586. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6587. if ( vertexUvs !== undefined ) {
  6588. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6589. } else {
  6590. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6591. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6592. }
  6593. }
  6594. if ( hasFaceVertexUv2 === true ) {
  6595. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6596. if ( vertexUvs !== undefined ) {
  6597. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6598. } else {
  6599. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6600. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6601. }
  6602. }
  6603. // morphs
  6604. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6605. var morphTarget = morphTargets[ j ].vertices;
  6606. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6607. }
  6608. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6609. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6610. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6611. }
  6612. // skins
  6613. if ( hasSkinIndices ) {
  6614. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6615. }
  6616. if ( hasSkinWeights ) {
  6617. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6618. }
  6619. }
  6620. this.computeGroups( geometry );
  6621. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6622. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6623. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6624. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6625. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6626. return this;
  6627. }
  6628. } );
  6629. /**
  6630. * @author mrdoob / http://mrdoob.com/
  6631. */
  6632. function arrayMax( array ) {
  6633. if ( array.length === 0 ) return - Infinity;
  6634. var max = array[ 0 ];
  6635. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6636. if ( array[ i ] > max ) max = array[ i ];
  6637. }
  6638. return max;
  6639. }
  6640. /**
  6641. * @author alteredq / http://alteredqualia.com/
  6642. * @author mrdoob / http://mrdoob.com/
  6643. */
  6644. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6645. function BufferGeometry() {
  6646. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6647. this.uuid = _Math.generateUUID();
  6648. this.name = '';
  6649. this.type = 'BufferGeometry';
  6650. this.index = null;
  6651. this.attributes = {};
  6652. this.morphAttributes = {};
  6653. this.groups = [];
  6654. this.boundingBox = null;
  6655. this.boundingSphere = null;
  6656. this.drawRange = { start: 0, count: Infinity };
  6657. this.userData = {};
  6658. }
  6659. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6660. constructor: BufferGeometry,
  6661. isBufferGeometry: true,
  6662. getIndex: function () {
  6663. return this.index;
  6664. },
  6665. setIndex: function ( index ) {
  6666. if ( Array.isArray( index ) ) {
  6667. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6668. } else {
  6669. this.index = index;
  6670. }
  6671. },
  6672. addAttribute: function ( name, attribute ) {
  6673. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6674. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6675. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6676. }
  6677. if ( name === 'index' ) {
  6678. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6679. this.setIndex( attribute );
  6680. return this;
  6681. }
  6682. this.attributes[ name ] = attribute;
  6683. return this;
  6684. },
  6685. getAttribute: function ( name ) {
  6686. return this.attributes[ name ];
  6687. },
  6688. removeAttribute: function ( name ) {
  6689. delete this.attributes[ name ];
  6690. return this;
  6691. },
  6692. addGroup: function ( start, count, materialIndex ) {
  6693. this.groups.push( {
  6694. start: start,
  6695. count: count,
  6696. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6697. } );
  6698. },
  6699. clearGroups: function () {
  6700. this.groups = [];
  6701. },
  6702. setDrawRange: function ( start, count ) {
  6703. this.drawRange.start = start;
  6704. this.drawRange.count = count;
  6705. },
  6706. applyMatrix: function ( matrix ) {
  6707. var position = this.attributes.position;
  6708. if ( position !== undefined ) {
  6709. matrix.applyToBufferAttribute( position );
  6710. position.needsUpdate = true;
  6711. }
  6712. var normal = this.attributes.normal;
  6713. if ( normal !== undefined ) {
  6714. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6715. normalMatrix.applyToBufferAttribute( normal );
  6716. normal.needsUpdate = true;
  6717. }
  6718. var tangent = this.attributes.tangent;
  6719. if ( tangent !== undefined ) {
  6720. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6721. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  6722. normalMatrix.applyToBufferAttribute( tangent );
  6723. tangent.needsUpdate = true;
  6724. }
  6725. if ( this.boundingBox !== null ) {
  6726. this.computeBoundingBox();
  6727. }
  6728. if ( this.boundingSphere !== null ) {
  6729. this.computeBoundingSphere();
  6730. }
  6731. return this;
  6732. },
  6733. rotateX: function () {
  6734. // rotate geometry around world x-axis
  6735. var m1 = new Matrix4();
  6736. return function rotateX( angle ) {
  6737. m1.makeRotationX( angle );
  6738. this.applyMatrix( m1 );
  6739. return this;
  6740. };
  6741. }(),
  6742. rotateY: function () {
  6743. // rotate geometry around world y-axis
  6744. var m1 = new Matrix4();
  6745. return function rotateY( angle ) {
  6746. m1.makeRotationY( angle );
  6747. this.applyMatrix( m1 );
  6748. return this;
  6749. };
  6750. }(),
  6751. rotateZ: function () {
  6752. // rotate geometry around world z-axis
  6753. var m1 = new Matrix4();
  6754. return function rotateZ( angle ) {
  6755. m1.makeRotationZ( angle );
  6756. this.applyMatrix( m1 );
  6757. return this;
  6758. };
  6759. }(),
  6760. translate: function () {
  6761. // translate geometry
  6762. var m1 = new Matrix4();
  6763. return function translate( x, y, z ) {
  6764. m1.makeTranslation( x, y, z );
  6765. this.applyMatrix( m1 );
  6766. return this;
  6767. };
  6768. }(),
  6769. scale: function () {
  6770. // scale geometry
  6771. var m1 = new Matrix4();
  6772. return function scale( x, y, z ) {
  6773. m1.makeScale( x, y, z );
  6774. this.applyMatrix( m1 );
  6775. return this;
  6776. };
  6777. }(),
  6778. lookAt: function () {
  6779. var obj = new Object3D();
  6780. return function lookAt( vector ) {
  6781. obj.lookAt( vector );
  6782. obj.updateMatrix();
  6783. this.applyMatrix( obj.matrix );
  6784. };
  6785. }(),
  6786. center: function () {
  6787. var offset = new Vector3();
  6788. return function center() {
  6789. this.computeBoundingBox();
  6790. this.boundingBox.getCenter( offset ).negate();
  6791. this.translate( offset.x, offset.y, offset.z );
  6792. return this;
  6793. };
  6794. }(),
  6795. setFromObject: function ( object ) {
  6796. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6797. var geometry = object.geometry;
  6798. if ( object.isPoints || object.isLine ) {
  6799. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6800. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6801. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6802. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6803. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6804. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6805. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6806. }
  6807. if ( geometry.boundingSphere !== null ) {
  6808. this.boundingSphere = geometry.boundingSphere.clone();
  6809. }
  6810. if ( geometry.boundingBox !== null ) {
  6811. this.boundingBox = geometry.boundingBox.clone();
  6812. }
  6813. } else if ( object.isMesh ) {
  6814. if ( geometry && geometry.isGeometry ) {
  6815. this.fromGeometry( geometry );
  6816. }
  6817. }
  6818. return this;
  6819. },
  6820. setFromPoints: function ( points ) {
  6821. var position = [];
  6822. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6823. var point = points[ i ];
  6824. position.push( point.x, point.y, point.z || 0 );
  6825. }
  6826. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6827. return this;
  6828. },
  6829. updateFromObject: function ( object ) {
  6830. var geometry = object.geometry;
  6831. if ( object.isMesh ) {
  6832. var direct = geometry.__directGeometry;
  6833. if ( geometry.elementsNeedUpdate === true ) {
  6834. direct = undefined;
  6835. geometry.elementsNeedUpdate = false;
  6836. }
  6837. if ( direct === undefined ) {
  6838. return this.fromGeometry( geometry );
  6839. }
  6840. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6841. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6842. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6843. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6844. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6845. geometry.verticesNeedUpdate = false;
  6846. geometry.normalsNeedUpdate = false;
  6847. geometry.colorsNeedUpdate = false;
  6848. geometry.uvsNeedUpdate = false;
  6849. geometry.groupsNeedUpdate = false;
  6850. geometry = direct;
  6851. }
  6852. var attribute;
  6853. if ( geometry.verticesNeedUpdate === true ) {
  6854. attribute = this.attributes.position;
  6855. if ( attribute !== undefined ) {
  6856. attribute.copyVector3sArray( geometry.vertices );
  6857. attribute.needsUpdate = true;
  6858. }
  6859. geometry.verticesNeedUpdate = false;
  6860. }
  6861. if ( geometry.normalsNeedUpdate === true ) {
  6862. attribute = this.attributes.normal;
  6863. if ( attribute !== undefined ) {
  6864. attribute.copyVector3sArray( geometry.normals );
  6865. attribute.needsUpdate = true;
  6866. }
  6867. geometry.normalsNeedUpdate = false;
  6868. }
  6869. if ( geometry.colorsNeedUpdate === true ) {
  6870. attribute = this.attributes.color;
  6871. if ( attribute !== undefined ) {
  6872. attribute.copyColorsArray( geometry.colors );
  6873. attribute.needsUpdate = true;
  6874. }
  6875. geometry.colorsNeedUpdate = false;
  6876. }
  6877. if ( geometry.uvsNeedUpdate ) {
  6878. attribute = this.attributes.uv;
  6879. if ( attribute !== undefined ) {
  6880. attribute.copyVector2sArray( geometry.uvs );
  6881. attribute.needsUpdate = true;
  6882. }
  6883. geometry.uvsNeedUpdate = false;
  6884. }
  6885. if ( geometry.lineDistancesNeedUpdate ) {
  6886. attribute = this.attributes.lineDistance;
  6887. if ( attribute !== undefined ) {
  6888. attribute.copyArray( geometry.lineDistances );
  6889. attribute.needsUpdate = true;
  6890. }
  6891. geometry.lineDistancesNeedUpdate = false;
  6892. }
  6893. if ( geometry.groupsNeedUpdate ) {
  6894. geometry.computeGroups( object.geometry );
  6895. this.groups = geometry.groups;
  6896. geometry.groupsNeedUpdate = false;
  6897. }
  6898. return this;
  6899. },
  6900. fromGeometry: function ( geometry ) {
  6901. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6902. return this.fromDirectGeometry( geometry.__directGeometry );
  6903. },
  6904. fromDirectGeometry: function ( geometry ) {
  6905. var positions = new Float32Array( geometry.vertices.length * 3 );
  6906. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6907. if ( geometry.normals.length > 0 ) {
  6908. var normals = new Float32Array( geometry.normals.length * 3 );
  6909. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6910. }
  6911. if ( geometry.colors.length > 0 ) {
  6912. var colors = new Float32Array( geometry.colors.length * 3 );
  6913. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6914. }
  6915. if ( geometry.uvs.length > 0 ) {
  6916. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6917. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6918. }
  6919. if ( geometry.uvs2.length > 0 ) {
  6920. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6921. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6922. }
  6923. // groups
  6924. this.groups = geometry.groups;
  6925. // morphs
  6926. for ( var name in geometry.morphTargets ) {
  6927. var array = [];
  6928. var morphTargets = geometry.morphTargets[ name ];
  6929. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6930. var morphTarget = morphTargets[ i ];
  6931. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6932. attribute.name = morphTarget.name;
  6933. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6934. }
  6935. this.morphAttributes[ name ] = array;
  6936. }
  6937. // skinning
  6938. if ( geometry.skinIndices.length > 0 ) {
  6939. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6940. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6941. }
  6942. if ( geometry.skinWeights.length > 0 ) {
  6943. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6944. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6945. }
  6946. //
  6947. if ( geometry.boundingSphere !== null ) {
  6948. this.boundingSphere = geometry.boundingSphere.clone();
  6949. }
  6950. if ( geometry.boundingBox !== null ) {
  6951. this.boundingBox = geometry.boundingBox.clone();
  6952. }
  6953. return this;
  6954. },
  6955. computeBoundingBox: function () {
  6956. if ( this.boundingBox === null ) {
  6957. this.boundingBox = new Box3();
  6958. }
  6959. var position = this.attributes.position;
  6960. if ( position !== undefined ) {
  6961. this.boundingBox.setFromBufferAttribute( position );
  6962. } else {
  6963. this.boundingBox.makeEmpty();
  6964. }
  6965. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6966. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6967. }
  6968. },
  6969. computeBoundingSphere: function () {
  6970. var box = new Box3();
  6971. var vector = new Vector3();
  6972. return function computeBoundingSphere() {
  6973. if ( this.boundingSphere === null ) {
  6974. this.boundingSphere = new Sphere();
  6975. }
  6976. var position = this.attributes.position;
  6977. if ( position ) {
  6978. var center = this.boundingSphere.center;
  6979. box.setFromBufferAttribute( position );
  6980. box.getCenter( center );
  6981. // hoping to find a boundingSphere with a radius smaller than the
  6982. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6983. var maxRadiusSq = 0;
  6984. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6985. vector.x = position.getX( i );
  6986. vector.y = position.getY( i );
  6987. vector.z = position.getZ( i );
  6988. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6989. }
  6990. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6991. if ( isNaN( this.boundingSphere.radius ) ) {
  6992. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6993. }
  6994. }
  6995. };
  6996. }(),
  6997. computeFaceNormals: function () {
  6998. // backwards compatibility
  6999. },
  7000. computeVertexNormals: function () {
  7001. var index = this.index;
  7002. var attributes = this.attributes;
  7003. if ( attributes.position ) {
  7004. var positions = attributes.position.array;
  7005. if ( attributes.normal === undefined ) {
  7006. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7007. } else {
  7008. // reset existing normals to zero
  7009. var array = attributes.normal.array;
  7010. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7011. array[ i ] = 0;
  7012. }
  7013. }
  7014. var normals = attributes.normal.array;
  7015. var vA, vB, vC;
  7016. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  7017. var cb = new Vector3(), ab = new Vector3();
  7018. // indexed elements
  7019. if ( index ) {
  7020. var indices = index.array;
  7021. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  7022. vA = indices[ i + 0 ] * 3;
  7023. vB = indices[ i + 1 ] * 3;
  7024. vC = indices[ i + 2 ] * 3;
  7025. pA.fromArray( positions, vA );
  7026. pB.fromArray( positions, vB );
  7027. pC.fromArray( positions, vC );
  7028. cb.subVectors( pC, pB );
  7029. ab.subVectors( pA, pB );
  7030. cb.cross( ab );
  7031. normals[ vA ] += cb.x;
  7032. normals[ vA + 1 ] += cb.y;
  7033. normals[ vA + 2 ] += cb.z;
  7034. normals[ vB ] += cb.x;
  7035. normals[ vB + 1 ] += cb.y;
  7036. normals[ vB + 2 ] += cb.z;
  7037. normals[ vC ] += cb.x;
  7038. normals[ vC + 1 ] += cb.y;
  7039. normals[ vC + 2 ] += cb.z;
  7040. }
  7041. } else {
  7042. // non-indexed elements (unconnected triangle soup)
  7043. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7044. pA.fromArray( positions, i );
  7045. pB.fromArray( positions, i + 3 );
  7046. pC.fromArray( positions, i + 6 );
  7047. cb.subVectors( pC, pB );
  7048. ab.subVectors( pA, pB );
  7049. cb.cross( ab );
  7050. normals[ i ] = cb.x;
  7051. normals[ i + 1 ] = cb.y;
  7052. normals[ i + 2 ] = cb.z;
  7053. normals[ i + 3 ] = cb.x;
  7054. normals[ i + 4 ] = cb.y;
  7055. normals[ i + 5 ] = cb.z;
  7056. normals[ i + 6 ] = cb.x;
  7057. normals[ i + 7 ] = cb.y;
  7058. normals[ i + 8 ] = cb.z;
  7059. }
  7060. }
  7061. this.normalizeNormals();
  7062. attributes.normal.needsUpdate = true;
  7063. }
  7064. },
  7065. merge: function ( geometry, offset ) {
  7066. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  7067. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7068. return;
  7069. }
  7070. if ( offset === undefined ) {
  7071. offset = 0;
  7072. console.warn(
  7073. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7074. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7075. );
  7076. }
  7077. var attributes = this.attributes;
  7078. for ( var key in attributes ) {
  7079. if ( geometry.attributes[ key ] === undefined ) continue;
  7080. var attribute1 = attributes[ key ];
  7081. var attributeArray1 = attribute1.array;
  7082. var attribute2 = geometry.attributes[ key ];
  7083. var attributeArray2 = attribute2.array;
  7084. var attributeSize = attribute2.itemSize;
  7085. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7086. attributeArray1[ j ] = attributeArray2[ i ];
  7087. }
  7088. }
  7089. return this;
  7090. },
  7091. normalizeNormals: function () {
  7092. var vector = new Vector3();
  7093. return function normalizeNormals() {
  7094. var normals = this.attributes.normal;
  7095. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7096. vector.x = normals.getX( i );
  7097. vector.y = normals.getY( i );
  7098. vector.z = normals.getZ( i );
  7099. vector.normalize();
  7100. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7101. }
  7102. };
  7103. }(),
  7104. toNonIndexed: function () {
  7105. function convertBufferAttribute( attribute, indices ) {
  7106. var array = attribute.array;
  7107. var itemSize = attribute.itemSize;
  7108. var array2 = new array.constructor( indices.length * itemSize );
  7109. var index = 0, index2 = 0;
  7110. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7111. index = indices[ i ] * itemSize;
  7112. for ( var j = 0; j < itemSize; j ++ ) {
  7113. array2[ index2 ++ ] = array[ index ++ ];
  7114. }
  7115. }
  7116. return new BufferAttribute( array2, itemSize );
  7117. }
  7118. //
  7119. if ( this.index === null ) {
  7120. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7121. return this;
  7122. }
  7123. var geometry2 = new BufferGeometry();
  7124. var indices = this.index.array;
  7125. var attributes = this.attributes;
  7126. // attributes
  7127. for ( var name in attributes ) {
  7128. var attribute = attributes[ name ];
  7129. var newAttribute = convertBufferAttribute( attribute, indices );
  7130. geometry2.addAttribute( name, newAttribute );
  7131. }
  7132. // morph attributes
  7133. var morphAttributes = this.morphAttributes;
  7134. for ( name in morphAttributes ) {
  7135. var morphArray = [];
  7136. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7137. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  7138. var attribute = morphAttribute[ i ];
  7139. var newAttribute = convertBufferAttribute( attribute, indices );
  7140. morphArray.push( newAttribute );
  7141. }
  7142. geometry2.morphAttributes[ name ] = morphArray;
  7143. }
  7144. // groups
  7145. var groups = this.groups;
  7146. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7147. var group = groups[ i ];
  7148. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7149. }
  7150. return geometry2;
  7151. },
  7152. toJSON: function () {
  7153. var data = {
  7154. metadata: {
  7155. version: 4.5,
  7156. type: 'BufferGeometry',
  7157. generator: 'BufferGeometry.toJSON'
  7158. }
  7159. };
  7160. // standard BufferGeometry serialization
  7161. data.uuid = this.uuid;
  7162. data.type = this.type;
  7163. if ( this.name !== '' ) data.name = this.name;
  7164. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7165. if ( this.parameters !== undefined ) {
  7166. var parameters = this.parameters;
  7167. for ( var key in parameters ) {
  7168. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7169. }
  7170. return data;
  7171. }
  7172. data.data = { attributes: {} };
  7173. var index = this.index;
  7174. if ( index !== null ) {
  7175. data.data.index = {
  7176. type: index.array.constructor.name,
  7177. array: Array.prototype.slice.call( index.array )
  7178. };
  7179. }
  7180. var attributes = this.attributes;
  7181. for ( var key in attributes ) {
  7182. var attribute = attributes[ key ];
  7183. var attributeData = {
  7184. itemSize: attribute.itemSize,
  7185. type: attribute.array.constructor.name,
  7186. array: Array.prototype.slice.call( attribute.array ),
  7187. normalized: attribute.normalized
  7188. };
  7189. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7190. data.data.attributes[ key ] = attributeData;
  7191. }
  7192. var morphAttributes = {};
  7193. var hasMorphAttributes = false;
  7194. for ( var key in this.morphAttributes ) {
  7195. var attributeArray = this.morphAttributes[ key ];
  7196. var array = [];
  7197. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  7198. var attribute = attributeArray[ i ];
  7199. var attributeData = {
  7200. itemSize: attribute.itemSize,
  7201. type: attribute.array.constructor.name,
  7202. array: Array.prototype.slice.call( attribute.array ),
  7203. normalized: attribute.normalized
  7204. };
  7205. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7206. array.push( attributeData );
  7207. }
  7208. if ( array.length > 0 ) {
  7209. morphAttributes[ key ] = array;
  7210. hasMorphAttributes = true;
  7211. }
  7212. }
  7213. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  7214. var groups = this.groups;
  7215. if ( groups.length > 0 ) {
  7216. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7217. }
  7218. var boundingSphere = this.boundingSphere;
  7219. if ( boundingSphere !== null ) {
  7220. data.data.boundingSphere = {
  7221. center: boundingSphere.center.toArray(),
  7222. radius: boundingSphere.radius
  7223. };
  7224. }
  7225. return data;
  7226. },
  7227. clone: function () {
  7228. /*
  7229. // Handle primitives
  7230. var parameters = this.parameters;
  7231. if ( parameters !== undefined ) {
  7232. var values = [];
  7233. for ( var key in parameters ) {
  7234. values.push( parameters[ key ] );
  7235. }
  7236. var geometry = Object.create( this.constructor.prototype );
  7237. this.constructor.apply( geometry, values );
  7238. return geometry;
  7239. }
  7240. return new this.constructor().copy( this );
  7241. */
  7242. return new BufferGeometry().copy( this );
  7243. },
  7244. copy: function ( source ) {
  7245. var name, i, l;
  7246. // reset
  7247. this.index = null;
  7248. this.attributes = {};
  7249. this.morphAttributes = {};
  7250. this.groups = [];
  7251. this.boundingBox = null;
  7252. this.boundingSphere = null;
  7253. // name
  7254. this.name = source.name;
  7255. // index
  7256. var index = source.index;
  7257. if ( index !== null ) {
  7258. this.setIndex( index.clone() );
  7259. }
  7260. // attributes
  7261. var attributes = source.attributes;
  7262. for ( name in attributes ) {
  7263. var attribute = attributes[ name ];
  7264. this.addAttribute( name, attribute.clone() );
  7265. }
  7266. // morph attributes
  7267. var morphAttributes = source.morphAttributes;
  7268. for ( name in morphAttributes ) {
  7269. var array = [];
  7270. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7271. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7272. array.push( morphAttribute[ i ].clone() );
  7273. }
  7274. this.morphAttributes[ name ] = array;
  7275. }
  7276. // groups
  7277. var groups = source.groups;
  7278. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7279. var group = groups[ i ];
  7280. this.addGroup( group.start, group.count, group.materialIndex );
  7281. }
  7282. // bounding box
  7283. var boundingBox = source.boundingBox;
  7284. if ( boundingBox !== null ) {
  7285. this.boundingBox = boundingBox.clone();
  7286. }
  7287. // bounding sphere
  7288. var boundingSphere = source.boundingSphere;
  7289. if ( boundingSphere !== null ) {
  7290. this.boundingSphere = boundingSphere.clone();
  7291. }
  7292. // draw range
  7293. this.drawRange.start = source.drawRange.start;
  7294. this.drawRange.count = source.drawRange.count;
  7295. // user data
  7296. this.userData = source.userData;
  7297. return this;
  7298. },
  7299. dispose: function () {
  7300. this.dispatchEvent( { type: 'dispose' } );
  7301. }
  7302. } );
  7303. /**
  7304. * @author mrdoob / http://mrdoob.com/
  7305. * @author Mugen87 / https://github.com/Mugen87
  7306. */
  7307. // BoxGeometry
  7308. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7309. Geometry.call( this );
  7310. this.type = 'BoxGeometry';
  7311. this.parameters = {
  7312. width: width,
  7313. height: height,
  7314. depth: depth,
  7315. widthSegments: widthSegments,
  7316. heightSegments: heightSegments,
  7317. depthSegments: depthSegments
  7318. };
  7319. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7320. this.mergeVertices();
  7321. }
  7322. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7323. BoxGeometry.prototype.constructor = BoxGeometry;
  7324. // BoxBufferGeometry
  7325. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7326. BufferGeometry.call( this );
  7327. this.type = 'BoxBufferGeometry';
  7328. this.parameters = {
  7329. width: width,
  7330. height: height,
  7331. depth: depth,
  7332. widthSegments: widthSegments,
  7333. heightSegments: heightSegments,
  7334. depthSegments: depthSegments
  7335. };
  7336. var scope = this;
  7337. width = width || 1;
  7338. height = height || 1;
  7339. depth = depth || 1;
  7340. // segments
  7341. widthSegments = Math.floor( widthSegments ) || 1;
  7342. heightSegments = Math.floor( heightSegments ) || 1;
  7343. depthSegments = Math.floor( depthSegments ) || 1;
  7344. // buffers
  7345. var indices = [];
  7346. var vertices = [];
  7347. var normals = [];
  7348. var uvs = [];
  7349. // helper variables
  7350. var numberOfVertices = 0;
  7351. var groupStart = 0;
  7352. // build each side of the box geometry
  7353. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7354. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7355. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7356. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7357. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7358. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7359. // build geometry
  7360. this.setIndex( indices );
  7361. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7362. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7363. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7364. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7365. var segmentWidth = width / gridX;
  7366. var segmentHeight = height / gridY;
  7367. var widthHalf = width / 2;
  7368. var heightHalf = height / 2;
  7369. var depthHalf = depth / 2;
  7370. var gridX1 = gridX + 1;
  7371. var gridY1 = gridY + 1;
  7372. var vertexCounter = 0;
  7373. var groupCount = 0;
  7374. var ix, iy;
  7375. var vector = new Vector3();
  7376. // generate vertices, normals and uvs
  7377. for ( iy = 0; iy < gridY1; iy ++ ) {
  7378. var y = iy * segmentHeight - heightHalf;
  7379. for ( ix = 0; ix < gridX1; ix ++ ) {
  7380. var x = ix * segmentWidth - widthHalf;
  7381. // set values to correct vector component
  7382. vector[ u ] = x * udir;
  7383. vector[ v ] = y * vdir;
  7384. vector[ w ] = depthHalf;
  7385. // now apply vector to vertex buffer
  7386. vertices.push( vector.x, vector.y, vector.z );
  7387. // set values to correct vector component
  7388. vector[ u ] = 0;
  7389. vector[ v ] = 0;
  7390. vector[ w ] = depth > 0 ? 1 : - 1;
  7391. // now apply vector to normal buffer
  7392. normals.push( vector.x, vector.y, vector.z );
  7393. // uvs
  7394. uvs.push( ix / gridX );
  7395. uvs.push( 1 - ( iy / gridY ) );
  7396. // counters
  7397. vertexCounter += 1;
  7398. }
  7399. }
  7400. // indices
  7401. // 1. you need three indices to draw a single face
  7402. // 2. a single segment consists of two faces
  7403. // 3. so we need to generate six (2*3) indices per segment
  7404. for ( iy = 0; iy < gridY; iy ++ ) {
  7405. for ( ix = 0; ix < gridX; ix ++ ) {
  7406. var a = numberOfVertices + ix + gridX1 * iy;
  7407. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7408. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7409. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7410. // faces
  7411. indices.push( a, b, d );
  7412. indices.push( b, c, d );
  7413. // increase counter
  7414. groupCount += 6;
  7415. }
  7416. }
  7417. // add a group to the geometry. this will ensure multi material support
  7418. scope.addGroup( groupStart, groupCount, materialIndex );
  7419. // calculate new start value for groups
  7420. groupStart += groupCount;
  7421. // update total number of vertices
  7422. numberOfVertices += vertexCounter;
  7423. }
  7424. }
  7425. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7426. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7427. /**
  7428. * @author mrdoob / http://mrdoob.com/
  7429. * @author Mugen87 / https://github.com/Mugen87
  7430. */
  7431. // PlaneGeometry
  7432. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7433. Geometry.call( this );
  7434. this.type = 'PlaneGeometry';
  7435. this.parameters = {
  7436. width: width,
  7437. height: height,
  7438. widthSegments: widthSegments,
  7439. heightSegments: heightSegments
  7440. };
  7441. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7442. this.mergeVertices();
  7443. }
  7444. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7445. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7446. // PlaneBufferGeometry
  7447. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7448. BufferGeometry.call( this );
  7449. this.type = 'PlaneBufferGeometry';
  7450. this.parameters = {
  7451. width: width,
  7452. height: height,
  7453. widthSegments: widthSegments,
  7454. heightSegments: heightSegments
  7455. };
  7456. width = width || 1;
  7457. height = height || 1;
  7458. var width_half = width / 2;
  7459. var height_half = height / 2;
  7460. var gridX = Math.floor( widthSegments ) || 1;
  7461. var gridY = Math.floor( heightSegments ) || 1;
  7462. var gridX1 = gridX + 1;
  7463. var gridY1 = gridY + 1;
  7464. var segment_width = width / gridX;
  7465. var segment_height = height / gridY;
  7466. var ix, iy;
  7467. // buffers
  7468. var indices = [];
  7469. var vertices = [];
  7470. var normals = [];
  7471. var uvs = [];
  7472. // generate vertices, normals and uvs
  7473. for ( iy = 0; iy < gridY1; iy ++ ) {
  7474. var y = iy * segment_height - height_half;
  7475. for ( ix = 0; ix < gridX1; ix ++ ) {
  7476. var x = ix * segment_width - width_half;
  7477. vertices.push( x, - y, 0 );
  7478. normals.push( 0, 0, 1 );
  7479. uvs.push( ix / gridX );
  7480. uvs.push( 1 - ( iy / gridY ) );
  7481. }
  7482. }
  7483. // indices
  7484. for ( iy = 0; iy < gridY; iy ++ ) {
  7485. for ( ix = 0; ix < gridX; ix ++ ) {
  7486. var a = ix + gridX1 * iy;
  7487. var b = ix + gridX1 * ( iy + 1 );
  7488. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7489. var d = ( ix + 1 ) + gridX1 * iy;
  7490. // faces
  7491. indices.push( a, b, d );
  7492. indices.push( b, c, d );
  7493. }
  7494. }
  7495. // build geometry
  7496. this.setIndex( indices );
  7497. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7498. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7499. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7500. }
  7501. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7502. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7503. /**
  7504. * @author mrdoob / http://mrdoob.com/
  7505. * @author alteredq / http://alteredqualia.com/
  7506. */
  7507. var materialId = 0;
  7508. function Material() {
  7509. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7510. this.uuid = _Math.generateUUID();
  7511. this.name = '';
  7512. this.type = 'Material';
  7513. this.fog = true;
  7514. this.lights = true;
  7515. this.blending = NormalBlending;
  7516. this.side = FrontSide;
  7517. this.flatShading = false;
  7518. this.vertexTangents = false;
  7519. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7520. this.opacity = 1;
  7521. this.transparent = false;
  7522. this.blendSrc = SrcAlphaFactor;
  7523. this.blendDst = OneMinusSrcAlphaFactor;
  7524. this.blendEquation = AddEquation;
  7525. this.blendSrcAlpha = null;
  7526. this.blendDstAlpha = null;
  7527. this.blendEquationAlpha = null;
  7528. this.depthFunc = LessEqualDepth;
  7529. this.depthTest = true;
  7530. this.depthWrite = true;
  7531. this.clippingPlanes = null;
  7532. this.clipIntersection = false;
  7533. this.clipShadows = false;
  7534. this.shadowSide = null;
  7535. this.colorWrite = true;
  7536. this.precision = null; // override the renderer's default precision for this material
  7537. this.polygonOffset = false;
  7538. this.polygonOffsetFactor = 0;
  7539. this.polygonOffsetUnits = 0;
  7540. this.dithering = false;
  7541. this.alphaTest = 0;
  7542. this.premultipliedAlpha = false;
  7543. this.visible = true;
  7544. this.userData = {};
  7545. this.needsUpdate = true;
  7546. }
  7547. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7548. constructor: Material,
  7549. isMaterial: true,
  7550. onBeforeCompile: function () {},
  7551. setValues: function ( values ) {
  7552. if ( values === undefined ) return;
  7553. for ( var key in values ) {
  7554. var newValue = values[ key ];
  7555. if ( newValue === undefined ) {
  7556. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7557. continue;
  7558. }
  7559. // for backward compatability if shading is set in the constructor
  7560. if ( key === 'shading' ) {
  7561. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7562. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7563. continue;
  7564. }
  7565. var currentValue = this[ key ];
  7566. if ( currentValue === undefined ) {
  7567. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7568. continue;
  7569. }
  7570. if ( currentValue && currentValue.isColor ) {
  7571. currentValue.set( newValue );
  7572. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7573. currentValue.copy( newValue );
  7574. } else {
  7575. this[ key ] = newValue;
  7576. }
  7577. }
  7578. },
  7579. toJSON: function ( meta ) {
  7580. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7581. if ( isRoot ) {
  7582. meta = {
  7583. textures: {},
  7584. images: {}
  7585. };
  7586. }
  7587. var data = {
  7588. metadata: {
  7589. version: 4.5,
  7590. type: 'Material',
  7591. generator: 'Material.toJSON'
  7592. }
  7593. };
  7594. // standard Material serialization
  7595. data.uuid = this.uuid;
  7596. data.type = this.type;
  7597. if ( this.name !== '' ) data.name = this.name;
  7598. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7599. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7600. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7601. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7602. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7603. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7604. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7605. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7606. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7607. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7608. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7609. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7610. if ( this.aoMap && this.aoMap.isTexture ) {
  7611. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7612. data.aoMapIntensity = this.aoMapIntensity;
  7613. }
  7614. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7615. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7616. data.bumpScale = this.bumpScale;
  7617. }
  7618. if ( this.normalMap && this.normalMap.isTexture ) {
  7619. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7620. data.normalMapType = this.normalMapType;
  7621. data.normalScale = this.normalScale.toArray();
  7622. }
  7623. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7624. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7625. data.displacementScale = this.displacementScale;
  7626. data.displacementBias = this.displacementBias;
  7627. }
  7628. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7629. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7630. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7631. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7632. if ( this.envMap && this.envMap.isTexture ) {
  7633. data.envMap = this.envMap.toJSON( meta ).uuid;
  7634. data.reflectivity = this.reflectivity; // Scale behind envMap
  7635. if ( this.combine !== undefined ) data.combine = this.combine;
  7636. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  7637. }
  7638. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7639. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7640. }
  7641. if ( this.size !== undefined ) data.size = this.size;
  7642. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7643. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7644. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7645. if ( this.side !== FrontSide ) data.side = this.side;
  7646. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7647. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7648. if ( this.transparent === true ) data.transparent = this.transparent;
  7649. data.depthFunc = this.depthFunc;
  7650. data.depthTest = this.depthTest;
  7651. data.depthWrite = this.depthWrite;
  7652. // rotation (SpriteMaterial)
  7653. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7654. if ( this.polygonOffset === true ) data.polygonOffset = true;
  7655. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  7656. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  7657. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7658. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7659. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7660. if ( this.scale !== undefined ) data.scale = this.scale;
  7661. if ( this.dithering === true ) data.dithering = true;
  7662. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7663. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7664. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7665. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7666. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7667. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7668. if ( this.morphTargets === true ) data.morphTargets = true;
  7669. if ( this.skinning === true ) data.skinning = true;
  7670. if ( this.visible === false ) data.visible = false;
  7671. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7672. // TODO: Copied from Object3D.toJSON
  7673. function extractFromCache( cache ) {
  7674. var values = [];
  7675. for ( var key in cache ) {
  7676. var data = cache[ key ];
  7677. delete data.metadata;
  7678. values.push( data );
  7679. }
  7680. return values;
  7681. }
  7682. if ( isRoot ) {
  7683. var textures = extractFromCache( meta.textures );
  7684. var images = extractFromCache( meta.images );
  7685. if ( textures.length > 0 ) data.textures = textures;
  7686. if ( images.length > 0 ) data.images = images;
  7687. }
  7688. return data;
  7689. },
  7690. clone: function () {
  7691. return new this.constructor().copy( this );
  7692. },
  7693. copy: function ( source ) {
  7694. this.name = source.name;
  7695. this.fog = source.fog;
  7696. this.lights = source.lights;
  7697. this.blending = source.blending;
  7698. this.side = source.side;
  7699. this.flatShading = source.flatShading;
  7700. this.vertexColors = source.vertexColors;
  7701. this.opacity = source.opacity;
  7702. this.transparent = source.transparent;
  7703. this.blendSrc = source.blendSrc;
  7704. this.blendDst = source.blendDst;
  7705. this.blendEquation = source.blendEquation;
  7706. this.blendSrcAlpha = source.blendSrcAlpha;
  7707. this.blendDstAlpha = source.blendDstAlpha;
  7708. this.blendEquationAlpha = source.blendEquationAlpha;
  7709. this.depthFunc = source.depthFunc;
  7710. this.depthTest = source.depthTest;
  7711. this.depthWrite = source.depthWrite;
  7712. this.colorWrite = source.colorWrite;
  7713. this.precision = source.precision;
  7714. this.polygonOffset = source.polygonOffset;
  7715. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7716. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7717. this.dithering = source.dithering;
  7718. this.alphaTest = source.alphaTest;
  7719. this.premultipliedAlpha = source.premultipliedAlpha;
  7720. this.visible = source.visible;
  7721. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7722. this.clipShadows = source.clipShadows;
  7723. this.clipIntersection = source.clipIntersection;
  7724. var srcPlanes = source.clippingPlanes,
  7725. dstPlanes = null;
  7726. if ( srcPlanes !== null ) {
  7727. var n = srcPlanes.length;
  7728. dstPlanes = new Array( n );
  7729. for ( var i = 0; i !== n; ++ i )
  7730. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7731. }
  7732. this.clippingPlanes = dstPlanes;
  7733. this.shadowSide = source.shadowSide;
  7734. return this;
  7735. },
  7736. dispose: function () {
  7737. this.dispatchEvent( { type: 'dispose' } );
  7738. }
  7739. } );
  7740. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7741. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7742. /**
  7743. * @author alteredq / http://alteredqualia.com/
  7744. *
  7745. * parameters = {
  7746. * defines: { "label" : "value" },
  7747. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7748. *
  7749. * fragmentShader: <string>,
  7750. * vertexShader: <string>,
  7751. *
  7752. * wireframe: <boolean>,
  7753. * wireframeLinewidth: <float>,
  7754. *
  7755. * lights: <bool>,
  7756. *
  7757. * skinning: <bool>,
  7758. * morphTargets: <bool>,
  7759. * morphNormals: <bool>
  7760. * }
  7761. */
  7762. function ShaderMaterial( parameters ) {
  7763. Material.call( this );
  7764. this.type = 'ShaderMaterial';
  7765. this.defines = {};
  7766. this.uniforms = {};
  7767. this.vertexShader = default_vertex;
  7768. this.fragmentShader = default_fragment;
  7769. this.linewidth = 1;
  7770. this.wireframe = false;
  7771. this.wireframeLinewidth = 1;
  7772. this.fog = false; // set to use scene fog
  7773. this.lights = false; // set to use scene lights
  7774. this.clipping = false; // set to use user-defined clipping planes
  7775. this.skinning = false; // set to use skinning attribute streams
  7776. this.morphTargets = false; // set to use morph targets
  7777. this.morphNormals = false; // set to use morph normals
  7778. this.extensions = {
  7779. derivatives: false, // set to use derivatives
  7780. fragDepth: false, // set to use fragment depth values
  7781. drawBuffers: false, // set to use draw buffers
  7782. shaderTextureLOD: false // set to use shader texture LOD
  7783. };
  7784. // When rendered geometry doesn't include these attributes but the material does,
  7785. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7786. this.defaultAttributeValues = {
  7787. 'color': [ 1, 1, 1 ],
  7788. 'uv': [ 0, 0 ],
  7789. 'uv2': [ 0, 0 ]
  7790. };
  7791. this.index0AttributeName = undefined;
  7792. this.uniformsNeedUpdate = false;
  7793. if ( parameters !== undefined ) {
  7794. if ( parameters.attributes !== undefined ) {
  7795. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7796. }
  7797. this.setValues( parameters );
  7798. }
  7799. }
  7800. ShaderMaterial.prototype = Object.create( Material.prototype );
  7801. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7802. ShaderMaterial.prototype.isShaderMaterial = true;
  7803. ShaderMaterial.prototype.copy = function ( source ) {
  7804. Material.prototype.copy.call( this, source );
  7805. this.fragmentShader = source.fragmentShader;
  7806. this.vertexShader = source.vertexShader;
  7807. this.uniforms = cloneUniforms( source.uniforms );
  7808. this.defines = Object.assign( {}, source.defines );
  7809. this.wireframe = source.wireframe;
  7810. this.wireframeLinewidth = source.wireframeLinewidth;
  7811. this.lights = source.lights;
  7812. this.clipping = source.clipping;
  7813. this.skinning = source.skinning;
  7814. this.morphTargets = source.morphTargets;
  7815. this.morphNormals = source.morphNormals;
  7816. this.extensions = source.extensions;
  7817. return this;
  7818. };
  7819. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7820. var data = Material.prototype.toJSON.call( this, meta );
  7821. data.uniforms = {};
  7822. for ( var name in this.uniforms ) {
  7823. var uniform = this.uniforms[ name ];
  7824. var value = uniform.value;
  7825. if ( value && value.isTexture ) {
  7826. data.uniforms[ name ] = {
  7827. type: 't',
  7828. value: value.toJSON( meta ).uuid
  7829. };
  7830. } else if ( value && value.isColor ) {
  7831. data.uniforms[ name ] = {
  7832. type: 'c',
  7833. value: value.getHex()
  7834. };
  7835. } else if ( value && value.isVector2 ) {
  7836. data.uniforms[ name ] = {
  7837. type: 'v2',
  7838. value: value.toArray()
  7839. };
  7840. } else if ( value && value.isVector3 ) {
  7841. data.uniforms[ name ] = {
  7842. type: 'v3',
  7843. value: value.toArray()
  7844. };
  7845. } else if ( value && value.isVector4 ) {
  7846. data.uniforms[ name ] = {
  7847. type: 'v4',
  7848. value: value.toArray()
  7849. };
  7850. } else if ( value && value.isMatrix3 ) {
  7851. data.uniforms[ name ] = {
  7852. type: 'm3',
  7853. value: value.toArray()
  7854. };
  7855. } else if ( value && value.isMatrix4 ) {
  7856. data.uniforms[ name ] = {
  7857. type: 'm4',
  7858. value: value.toArray()
  7859. };
  7860. } else {
  7861. data.uniforms[ name ] = {
  7862. value: value
  7863. };
  7864. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7865. }
  7866. }
  7867. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7868. data.vertexShader = this.vertexShader;
  7869. data.fragmentShader = this.fragmentShader;
  7870. var extensions = {};
  7871. for ( var key in this.extensions ) {
  7872. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7873. }
  7874. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7875. return data;
  7876. };
  7877. /**
  7878. * @author bhouston / http://clara.io
  7879. */
  7880. function Ray( origin, direction ) {
  7881. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7882. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7883. }
  7884. Object.assign( Ray.prototype, {
  7885. set: function ( origin, direction ) {
  7886. this.origin.copy( origin );
  7887. this.direction.copy( direction );
  7888. return this;
  7889. },
  7890. clone: function () {
  7891. return new this.constructor().copy( this );
  7892. },
  7893. copy: function ( ray ) {
  7894. this.origin.copy( ray.origin );
  7895. this.direction.copy( ray.direction );
  7896. return this;
  7897. },
  7898. at: function ( t, target ) {
  7899. if ( target === undefined ) {
  7900. console.warn( 'THREE.Ray: .at() target is now required' );
  7901. target = new Vector3();
  7902. }
  7903. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7904. },
  7905. lookAt: function ( v ) {
  7906. this.direction.copy( v ).sub( this.origin ).normalize();
  7907. return this;
  7908. },
  7909. recast: function () {
  7910. var v1 = new Vector3();
  7911. return function recast( t ) {
  7912. this.origin.copy( this.at( t, v1 ) );
  7913. return this;
  7914. };
  7915. }(),
  7916. closestPointToPoint: function ( point, target ) {
  7917. if ( target === undefined ) {
  7918. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7919. target = new Vector3();
  7920. }
  7921. target.subVectors( point, this.origin );
  7922. var directionDistance = target.dot( this.direction );
  7923. if ( directionDistance < 0 ) {
  7924. return target.copy( this.origin );
  7925. }
  7926. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7927. },
  7928. distanceToPoint: function ( point ) {
  7929. return Math.sqrt( this.distanceSqToPoint( point ) );
  7930. },
  7931. distanceSqToPoint: function () {
  7932. var v1 = new Vector3();
  7933. return function distanceSqToPoint( point ) {
  7934. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7935. // point behind the ray
  7936. if ( directionDistance < 0 ) {
  7937. return this.origin.distanceToSquared( point );
  7938. }
  7939. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7940. return v1.distanceToSquared( point );
  7941. };
  7942. }(),
  7943. distanceSqToSegment: function () {
  7944. var segCenter = new Vector3();
  7945. var segDir = new Vector3();
  7946. var diff = new Vector3();
  7947. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7948. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7949. // It returns the min distance between the ray and the segment
  7950. // defined by v0 and v1
  7951. // It can also set two optional targets :
  7952. // - The closest point on the ray
  7953. // - The closest point on the segment
  7954. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7955. segDir.copy( v1 ).sub( v0 ).normalize();
  7956. diff.copy( this.origin ).sub( segCenter );
  7957. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7958. var a01 = - this.direction.dot( segDir );
  7959. var b0 = diff.dot( this.direction );
  7960. var b1 = - diff.dot( segDir );
  7961. var c = diff.lengthSq();
  7962. var det = Math.abs( 1 - a01 * a01 );
  7963. var s0, s1, sqrDist, extDet;
  7964. if ( det > 0 ) {
  7965. // The ray and segment are not parallel.
  7966. s0 = a01 * b1 - b0;
  7967. s1 = a01 * b0 - b1;
  7968. extDet = segExtent * det;
  7969. if ( s0 >= 0 ) {
  7970. if ( s1 >= - extDet ) {
  7971. if ( s1 <= extDet ) {
  7972. // region 0
  7973. // Minimum at interior points of ray and segment.
  7974. var invDet = 1 / det;
  7975. s0 *= invDet;
  7976. s1 *= invDet;
  7977. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  7978. } else {
  7979. // region 1
  7980. s1 = segExtent;
  7981. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7982. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7983. }
  7984. } else {
  7985. // region 5
  7986. s1 = - segExtent;
  7987. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7988. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7989. }
  7990. } else {
  7991. if ( s1 <= - extDet ) {
  7992. // region 4
  7993. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  7994. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7995. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7996. } else if ( s1 <= extDet ) {
  7997. // region 3
  7998. s0 = 0;
  7999. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8000. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  8001. } else {
  8002. // region 2
  8003. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  8004. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8005. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8006. }
  8007. }
  8008. } else {
  8009. // Ray and segment are parallel.
  8010. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  8011. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8012. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8013. }
  8014. if ( optionalPointOnRay ) {
  8015. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  8016. }
  8017. if ( optionalPointOnSegment ) {
  8018. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  8019. }
  8020. return sqrDist;
  8021. };
  8022. }(),
  8023. intersectSphere: function () {
  8024. var v1 = new Vector3();
  8025. return function intersectSphere( sphere, target ) {
  8026. v1.subVectors( sphere.center, this.origin );
  8027. var tca = v1.dot( this.direction );
  8028. var d2 = v1.dot( v1 ) - tca * tca;
  8029. var radius2 = sphere.radius * sphere.radius;
  8030. if ( d2 > radius2 ) return null;
  8031. var thc = Math.sqrt( radius2 - d2 );
  8032. // t0 = first intersect point - entrance on front of sphere
  8033. var t0 = tca - thc;
  8034. // t1 = second intersect point - exit point on back of sphere
  8035. var t1 = tca + thc;
  8036. // test to see if both t0 and t1 are behind the ray - if so, return null
  8037. if ( t0 < 0 && t1 < 0 ) return null;
  8038. // test to see if t0 is behind the ray:
  8039. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  8040. // in order to always return an intersect point that is in front of the ray.
  8041. if ( t0 < 0 ) return this.at( t1, target );
  8042. // else t0 is in front of the ray, so return the first collision point scaled by t0
  8043. return this.at( t0, target );
  8044. };
  8045. }(),
  8046. intersectsSphere: function ( sphere ) {
  8047. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  8048. },
  8049. distanceToPlane: function ( plane ) {
  8050. var denominator = plane.normal.dot( this.direction );
  8051. if ( denominator === 0 ) {
  8052. // line is coplanar, return origin
  8053. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8054. return 0;
  8055. }
  8056. // Null is preferable to undefined since undefined means.... it is undefined
  8057. return null;
  8058. }
  8059. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8060. // Return if the ray never intersects the plane
  8061. return t >= 0 ? t : null;
  8062. },
  8063. intersectPlane: function ( plane, target ) {
  8064. var t = this.distanceToPlane( plane );
  8065. if ( t === null ) {
  8066. return null;
  8067. }
  8068. return this.at( t, target );
  8069. },
  8070. intersectsPlane: function ( plane ) {
  8071. // check if the ray lies on the plane first
  8072. var distToPoint = plane.distanceToPoint( this.origin );
  8073. if ( distToPoint === 0 ) {
  8074. return true;
  8075. }
  8076. var denominator = plane.normal.dot( this.direction );
  8077. if ( denominator * distToPoint < 0 ) {
  8078. return true;
  8079. }
  8080. // ray origin is behind the plane (and is pointing behind it)
  8081. return false;
  8082. },
  8083. intersectBox: function ( box, target ) {
  8084. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8085. var invdirx = 1 / this.direction.x,
  8086. invdiry = 1 / this.direction.y,
  8087. invdirz = 1 / this.direction.z;
  8088. var origin = this.origin;
  8089. if ( invdirx >= 0 ) {
  8090. tmin = ( box.min.x - origin.x ) * invdirx;
  8091. tmax = ( box.max.x - origin.x ) * invdirx;
  8092. } else {
  8093. tmin = ( box.max.x - origin.x ) * invdirx;
  8094. tmax = ( box.min.x - origin.x ) * invdirx;
  8095. }
  8096. if ( invdiry >= 0 ) {
  8097. tymin = ( box.min.y - origin.y ) * invdiry;
  8098. tymax = ( box.max.y - origin.y ) * invdiry;
  8099. } else {
  8100. tymin = ( box.max.y - origin.y ) * invdiry;
  8101. tymax = ( box.min.y - origin.y ) * invdiry;
  8102. }
  8103. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8104. // These lines also handle the case where tmin or tmax is NaN
  8105. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8106. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8107. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8108. if ( invdirz >= 0 ) {
  8109. tzmin = ( box.min.z - origin.z ) * invdirz;
  8110. tzmax = ( box.max.z - origin.z ) * invdirz;
  8111. } else {
  8112. tzmin = ( box.max.z - origin.z ) * invdirz;
  8113. tzmax = ( box.min.z - origin.z ) * invdirz;
  8114. }
  8115. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8116. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8117. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8118. //return point closest to the ray (positive side)
  8119. if ( tmax < 0 ) return null;
  8120. return this.at( tmin >= 0 ? tmin : tmax, target );
  8121. },
  8122. intersectsBox: ( function () {
  8123. var v = new Vector3();
  8124. return function intersectsBox( box ) {
  8125. return this.intersectBox( box, v ) !== null;
  8126. };
  8127. } )(),
  8128. intersectTriangle: function () {
  8129. // Compute the offset origin, edges, and normal.
  8130. var diff = new Vector3();
  8131. var edge1 = new Vector3();
  8132. var edge2 = new Vector3();
  8133. var normal = new Vector3();
  8134. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8135. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8136. edge1.subVectors( b, a );
  8137. edge2.subVectors( c, a );
  8138. normal.crossVectors( edge1, edge2 );
  8139. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8140. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8141. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8142. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8143. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8144. var DdN = this.direction.dot( normal );
  8145. var sign;
  8146. if ( DdN > 0 ) {
  8147. if ( backfaceCulling ) return null;
  8148. sign = 1;
  8149. } else if ( DdN < 0 ) {
  8150. sign = - 1;
  8151. DdN = - DdN;
  8152. } else {
  8153. return null;
  8154. }
  8155. diff.subVectors( this.origin, a );
  8156. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8157. // b1 < 0, no intersection
  8158. if ( DdQxE2 < 0 ) {
  8159. return null;
  8160. }
  8161. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8162. // b2 < 0, no intersection
  8163. if ( DdE1xQ < 0 ) {
  8164. return null;
  8165. }
  8166. // b1+b2 > 1, no intersection
  8167. if ( DdQxE2 + DdE1xQ > DdN ) {
  8168. return null;
  8169. }
  8170. // Line intersects triangle, check if ray does.
  8171. var QdN = - sign * diff.dot( normal );
  8172. // t < 0, no intersection
  8173. if ( QdN < 0 ) {
  8174. return null;
  8175. }
  8176. // Ray intersects triangle.
  8177. return this.at( QdN / DdN, target );
  8178. };
  8179. }(),
  8180. applyMatrix4: function ( matrix4 ) {
  8181. this.origin.applyMatrix4( matrix4 );
  8182. this.direction.transformDirection( matrix4 );
  8183. return this;
  8184. },
  8185. equals: function ( ray ) {
  8186. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8187. }
  8188. } );
  8189. /**
  8190. * @author bhouston / http://clara.io
  8191. * @author mrdoob / http://mrdoob.com/
  8192. */
  8193. function Triangle( a, b, c ) {
  8194. this.a = ( a !== undefined ) ? a : new Vector3();
  8195. this.b = ( b !== undefined ) ? b : new Vector3();
  8196. this.c = ( c !== undefined ) ? c : new Vector3();
  8197. }
  8198. Object.assign( Triangle, {
  8199. getNormal: function () {
  8200. var v0 = new Vector3();
  8201. return function getNormal( a, b, c, target ) {
  8202. if ( target === undefined ) {
  8203. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8204. target = new Vector3();
  8205. }
  8206. target.subVectors( c, b );
  8207. v0.subVectors( a, b );
  8208. target.cross( v0 );
  8209. var targetLengthSq = target.lengthSq();
  8210. if ( targetLengthSq > 0 ) {
  8211. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8212. }
  8213. return target.set( 0, 0, 0 );
  8214. };
  8215. }(),
  8216. // static/instance method to calculate barycentric coordinates
  8217. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8218. getBarycoord: function () {
  8219. var v0 = new Vector3();
  8220. var v1 = new Vector3();
  8221. var v2 = new Vector3();
  8222. return function getBarycoord( point, a, b, c, target ) {
  8223. v0.subVectors( c, a );
  8224. v1.subVectors( b, a );
  8225. v2.subVectors( point, a );
  8226. var dot00 = v0.dot( v0 );
  8227. var dot01 = v0.dot( v1 );
  8228. var dot02 = v0.dot( v2 );
  8229. var dot11 = v1.dot( v1 );
  8230. var dot12 = v1.dot( v2 );
  8231. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8232. if ( target === undefined ) {
  8233. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8234. target = new Vector3();
  8235. }
  8236. // collinear or singular triangle
  8237. if ( denom === 0 ) {
  8238. // arbitrary location outside of triangle?
  8239. // not sure if this is the best idea, maybe should be returning undefined
  8240. return target.set( - 2, - 1, - 1 );
  8241. }
  8242. var invDenom = 1 / denom;
  8243. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8244. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8245. // barycentric coordinates must always sum to 1
  8246. return target.set( 1 - u - v, v, u );
  8247. };
  8248. }(),
  8249. containsPoint: function () {
  8250. var v1 = new Vector3();
  8251. return function containsPoint( point, a, b, c ) {
  8252. Triangle.getBarycoord( point, a, b, c, v1 );
  8253. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8254. };
  8255. }(),
  8256. getUV: function () {
  8257. var barycoord = new Vector3();
  8258. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  8259. this.getBarycoord( point, p1, p2, p3, barycoord );
  8260. target.set( 0, 0 );
  8261. target.addScaledVector( uv1, barycoord.x );
  8262. target.addScaledVector( uv2, barycoord.y );
  8263. target.addScaledVector( uv3, barycoord.z );
  8264. return target;
  8265. };
  8266. }()
  8267. } );
  8268. Object.assign( Triangle.prototype, {
  8269. set: function ( a, b, c ) {
  8270. this.a.copy( a );
  8271. this.b.copy( b );
  8272. this.c.copy( c );
  8273. return this;
  8274. },
  8275. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8276. this.a.copy( points[ i0 ] );
  8277. this.b.copy( points[ i1 ] );
  8278. this.c.copy( points[ i2 ] );
  8279. return this;
  8280. },
  8281. clone: function () {
  8282. return new this.constructor().copy( this );
  8283. },
  8284. copy: function ( triangle ) {
  8285. this.a.copy( triangle.a );
  8286. this.b.copy( triangle.b );
  8287. this.c.copy( triangle.c );
  8288. return this;
  8289. },
  8290. getArea: function () {
  8291. var v0 = new Vector3();
  8292. var v1 = new Vector3();
  8293. return function getArea() {
  8294. v0.subVectors( this.c, this.b );
  8295. v1.subVectors( this.a, this.b );
  8296. return v0.cross( v1 ).length() * 0.5;
  8297. };
  8298. }(),
  8299. getMidpoint: function ( target ) {
  8300. if ( target === undefined ) {
  8301. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8302. target = new Vector3();
  8303. }
  8304. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8305. },
  8306. getNormal: function ( target ) {
  8307. return Triangle.getNormal( this.a, this.b, this.c, target );
  8308. },
  8309. getPlane: function ( target ) {
  8310. if ( target === undefined ) {
  8311. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8312. target = new Vector3();
  8313. }
  8314. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8315. },
  8316. getBarycoord: function ( point, target ) {
  8317. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8318. },
  8319. containsPoint: function ( point ) {
  8320. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8321. },
  8322. getUV: function ( point, uv1, uv2, uv3, result ) {
  8323. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
  8324. },
  8325. intersectsBox: function ( box ) {
  8326. return box.intersectsTriangle( this );
  8327. },
  8328. closestPointToPoint: function () {
  8329. var vab = new Vector3();
  8330. var vac = new Vector3();
  8331. var vbc = new Vector3();
  8332. var vap = new Vector3();
  8333. var vbp = new Vector3();
  8334. var vcp = new Vector3();
  8335. return function closestPointToPoint( p, target ) {
  8336. if ( target === undefined ) {
  8337. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8338. target = new Vector3();
  8339. }
  8340. var a = this.a, b = this.b, c = this.c;
  8341. var v, w;
  8342. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  8343. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  8344. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  8345. // basically, we're distinguishing which of the voronoi regions of the triangle
  8346. // the point lies in with the minimum amount of redundant computation.
  8347. vab.subVectors( b, a );
  8348. vac.subVectors( c, a );
  8349. vap.subVectors( p, a );
  8350. var d1 = vab.dot( vap );
  8351. var d2 = vac.dot( vap );
  8352. if ( d1 <= 0 && d2 <= 0 ) {
  8353. // vertex region of A; barycentric coords (1, 0, 0)
  8354. return target.copy( a );
  8355. }
  8356. vbp.subVectors( p, b );
  8357. var d3 = vab.dot( vbp );
  8358. var d4 = vac.dot( vbp );
  8359. if ( d3 >= 0 && d4 <= d3 ) {
  8360. // vertex region of B; barycentric coords (0, 1, 0)
  8361. return target.copy( b );
  8362. }
  8363. var vc = d1 * d4 - d3 * d2;
  8364. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  8365. v = d1 / ( d1 - d3 );
  8366. // edge region of AB; barycentric coords (1-v, v, 0)
  8367. return target.copy( a ).addScaledVector( vab, v );
  8368. }
  8369. vcp.subVectors( p, c );
  8370. var d5 = vab.dot( vcp );
  8371. var d6 = vac.dot( vcp );
  8372. if ( d6 >= 0 && d5 <= d6 ) {
  8373. // vertex region of C; barycentric coords (0, 0, 1)
  8374. return target.copy( c );
  8375. }
  8376. var vb = d5 * d2 - d1 * d6;
  8377. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  8378. w = d2 / ( d2 - d6 );
  8379. // edge region of AC; barycentric coords (1-w, 0, w)
  8380. return target.copy( a ).addScaledVector( vac, w );
  8381. }
  8382. var va = d3 * d6 - d5 * d4;
  8383. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  8384. vbc.subVectors( c, b );
  8385. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  8386. // edge region of BC; barycentric coords (0, 1-w, w)
  8387. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  8388. }
  8389. // face region
  8390. var denom = 1 / ( va + vb + vc );
  8391. // u = va * denom
  8392. v = vb * denom;
  8393. w = vc * denom;
  8394. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  8395. };
  8396. }(),
  8397. equals: function ( triangle ) {
  8398. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8399. }
  8400. } );
  8401. /**
  8402. * @author mrdoob / http://mrdoob.com/
  8403. * @author alteredq / http://alteredqualia.com/
  8404. *
  8405. * parameters = {
  8406. * color: <hex>,
  8407. * opacity: <float>,
  8408. * map: new THREE.Texture( <Image> ),
  8409. *
  8410. * lightMap: new THREE.Texture( <Image> ),
  8411. * lightMapIntensity: <float>
  8412. *
  8413. * aoMap: new THREE.Texture( <Image> ),
  8414. * aoMapIntensity: <float>
  8415. *
  8416. * specularMap: new THREE.Texture( <Image> ),
  8417. *
  8418. * alphaMap: new THREE.Texture( <Image> ),
  8419. *
  8420. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  8421. * combine: THREE.Multiply,
  8422. * reflectivity: <float>,
  8423. * refractionRatio: <float>,
  8424. *
  8425. * depthTest: <bool>,
  8426. * depthWrite: <bool>,
  8427. *
  8428. * wireframe: <boolean>,
  8429. * wireframeLinewidth: <float>,
  8430. *
  8431. * skinning: <bool>,
  8432. * morphTargets: <bool>
  8433. * }
  8434. */
  8435. function MeshBasicMaterial( parameters ) {
  8436. Material.call( this );
  8437. this.type = 'MeshBasicMaterial';
  8438. this.color = new Color( 0xffffff ); // emissive
  8439. this.map = null;
  8440. this.lightMap = null;
  8441. this.lightMapIntensity = 1.0;
  8442. this.aoMap = null;
  8443. this.aoMapIntensity = 1.0;
  8444. this.specularMap = null;
  8445. this.alphaMap = null;
  8446. this.envMap = null;
  8447. this.combine = MultiplyOperation;
  8448. this.reflectivity = 1;
  8449. this.refractionRatio = 0.98;
  8450. this.wireframe = false;
  8451. this.wireframeLinewidth = 1;
  8452. this.wireframeLinecap = 'round';
  8453. this.wireframeLinejoin = 'round';
  8454. this.skinning = false;
  8455. this.morphTargets = false;
  8456. this.lights = false;
  8457. this.setValues( parameters );
  8458. }
  8459. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8460. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8461. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8462. MeshBasicMaterial.prototype.copy = function ( source ) {
  8463. Material.prototype.copy.call( this, source );
  8464. this.color.copy( source.color );
  8465. this.map = source.map;
  8466. this.lightMap = source.lightMap;
  8467. this.lightMapIntensity = source.lightMapIntensity;
  8468. this.aoMap = source.aoMap;
  8469. this.aoMapIntensity = source.aoMapIntensity;
  8470. this.specularMap = source.specularMap;
  8471. this.alphaMap = source.alphaMap;
  8472. this.envMap = source.envMap;
  8473. this.combine = source.combine;
  8474. this.reflectivity = source.reflectivity;
  8475. this.refractionRatio = source.refractionRatio;
  8476. this.wireframe = source.wireframe;
  8477. this.wireframeLinewidth = source.wireframeLinewidth;
  8478. this.wireframeLinecap = source.wireframeLinecap;
  8479. this.wireframeLinejoin = source.wireframeLinejoin;
  8480. this.skinning = source.skinning;
  8481. this.morphTargets = source.morphTargets;
  8482. return this;
  8483. };
  8484. /**
  8485. * @author mrdoob / http://mrdoob.com/
  8486. * @author alteredq / http://alteredqualia.com/
  8487. * @author mikael emtinger / http://gomo.se/
  8488. * @author jonobr1 / http://jonobr1.com/
  8489. */
  8490. function Mesh( geometry, material ) {
  8491. Object3D.call( this );
  8492. this.type = 'Mesh';
  8493. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8494. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8495. this.drawMode = TrianglesDrawMode;
  8496. this.updateMorphTargets();
  8497. }
  8498. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8499. constructor: Mesh,
  8500. isMesh: true,
  8501. setDrawMode: function ( value ) {
  8502. this.drawMode = value;
  8503. },
  8504. copy: function ( source ) {
  8505. Object3D.prototype.copy.call( this, source );
  8506. this.drawMode = source.drawMode;
  8507. if ( source.morphTargetInfluences !== undefined ) {
  8508. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8509. }
  8510. if ( source.morphTargetDictionary !== undefined ) {
  8511. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8512. }
  8513. return this;
  8514. },
  8515. updateMorphTargets: function () {
  8516. var geometry = this.geometry;
  8517. var m, ml, name;
  8518. if ( geometry.isBufferGeometry ) {
  8519. var morphAttributes = geometry.morphAttributes;
  8520. var keys = Object.keys( morphAttributes );
  8521. if ( keys.length > 0 ) {
  8522. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8523. if ( morphAttribute !== undefined ) {
  8524. this.morphTargetInfluences = [];
  8525. this.morphTargetDictionary = {};
  8526. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8527. name = morphAttribute[ m ].name || String( m );
  8528. this.morphTargetInfluences.push( 0 );
  8529. this.morphTargetDictionary[ name ] = m;
  8530. }
  8531. }
  8532. }
  8533. } else {
  8534. var morphTargets = geometry.morphTargets;
  8535. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8536. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  8537. }
  8538. }
  8539. },
  8540. raycast: ( function () {
  8541. var inverseMatrix = new Matrix4();
  8542. var ray = new Ray();
  8543. var sphere = new Sphere();
  8544. var vA = new Vector3();
  8545. var vB = new Vector3();
  8546. var vC = new Vector3();
  8547. var tempA = new Vector3();
  8548. var tempB = new Vector3();
  8549. var tempC = new Vector3();
  8550. var uvA = new Vector2();
  8551. var uvB = new Vector2();
  8552. var uvC = new Vector2();
  8553. var intersectionPoint = new Vector3();
  8554. var intersectionPointWorld = new Vector3();
  8555. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8556. var intersect;
  8557. if ( material.side === BackSide ) {
  8558. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8559. } else {
  8560. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8561. }
  8562. if ( intersect === null ) return null;
  8563. intersectionPointWorld.copy( point );
  8564. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8565. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8566. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8567. return {
  8568. distance: distance,
  8569. point: intersectionPointWorld.clone(),
  8570. object: object
  8571. };
  8572. }
  8573. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, uv, a, b, c ) {
  8574. vA.fromBufferAttribute( position, a );
  8575. vB.fromBufferAttribute( position, b );
  8576. vC.fromBufferAttribute( position, c );
  8577. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8578. if ( intersection ) {
  8579. if ( uv ) {
  8580. uvA.fromBufferAttribute( uv, a );
  8581. uvB.fromBufferAttribute( uv, b );
  8582. uvC.fromBufferAttribute( uv, c );
  8583. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  8584. }
  8585. var face = new Face3( a, b, c );
  8586. Triangle.getNormal( vA, vB, vC, face.normal );
  8587. intersection.face = face;
  8588. }
  8589. return intersection;
  8590. }
  8591. return function raycast( raycaster, intersects ) {
  8592. var geometry = this.geometry;
  8593. var material = this.material;
  8594. var matrixWorld = this.matrixWorld;
  8595. if ( material === undefined ) return;
  8596. // Checking boundingSphere distance to ray
  8597. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8598. sphere.copy( geometry.boundingSphere );
  8599. sphere.applyMatrix4( matrixWorld );
  8600. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8601. //
  8602. inverseMatrix.getInverse( matrixWorld );
  8603. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8604. // Check boundingBox before continuing
  8605. if ( geometry.boundingBox !== null ) {
  8606. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8607. }
  8608. var intersection;
  8609. if ( geometry.isBufferGeometry ) {
  8610. var a, b, c;
  8611. var index = geometry.index;
  8612. var position = geometry.attributes.position;
  8613. var uv = geometry.attributes.uv;
  8614. var groups = geometry.groups;
  8615. var drawRange = geometry.drawRange;
  8616. var i, j, il, jl;
  8617. var group, groupMaterial;
  8618. var start, end;
  8619. if ( index !== null ) {
  8620. // indexed buffer geometry
  8621. if ( Array.isArray( material ) ) {
  8622. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8623. group = groups[ i ];
  8624. groupMaterial = material[ group.materialIndex ];
  8625. start = Math.max( group.start, drawRange.start );
  8626. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8627. for ( j = start, jl = end; j < jl; j += 3 ) {
  8628. a = index.getX( j );
  8629. b = index.getX( j + 1 );
  8630. c = index.getX( j + 2 );
  8631. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, uv, a, b, c );
  8632. if ( intersection ) {
  8633. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  8634. intersection.face.materialIndex = group.materialIndex;
  8635. intersects.push( intersection );
  8636. }
  8637. }
  8638. }
  8639. } else {
  8640. start = Math.max( 0, drawRange.start );
  8641. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  8642. for ( i = start, il = end; i < il; i += 3 ) {
  8643. a = index.getX( i );
  8644. b = index.getX( i + 1 );
  8645. c = index.getX( i + 2 );
  8646. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, uv, a, b, c );
  8647. if ( intersection ) {
  8648. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8649. intersects.push( intersection );
  8650. }
  8651. }
  8652. }
  8653. } else if ( position !== undefined ) {
  8654. // non-indexed buffer geometry
  8655. if ( Array.isArray( material ) ) {
  8656. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8657. group = groups[ i ];
  8658. groupMaterial = material[ group.materialIndex ];
  8659. start = Math.max( group.start, drawRange.start );
  8660. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8661. for ( j = start, jl = end; j < jl; j += 3 ) {
  8662. a = j;
  8663. b = j + 1;
  8664. c = j + 2;
  8665. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, uv, a, b, c );
  8666. if ( intersection ) {
  8667. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  8668. intersection.face.materialIndex = group.materialIndex;
  8669. intersects.push( intersection );
  8670. }
  8671. }
  8672. }
  8673. } else {
  8674. start = Math.max( 0, drawRange.start );
  8675. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  8676. for ( i = start, il = end; i < il; i += 3 ) {
  8677. a = i;
  8678. b = i + 1;
  8679. c = i + 2;
  8680. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, uv, a, b, c );
  8681. if ( intersection ) {
  8682. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8683. intersects.push( intersection );
  8684. }
  8685. }
  8686. }
  8687. }
  8688. } else if ( geometry.isGeometry ) {
  8689. var fvA, fvB, fvC;
  8690. var isMultiMaterial = Array.isArray( material );
  8691. var vertices = geometry.vertices;
  8692. var faces = geometry.faces;
  8693. var uvs;
  8694. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8695. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8696. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8697. var face = faces[ f ];
  8698. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8699. if ( faceMaterial === undefined ) continue;
  8700. fvA = vertices[ face.a ];
  8701. fvB = vertices[ face.b ];
  8702. fvC = vertices[ face.c ];
  8703. if ( faceMaterial.morphTargets === true ) {
  8704. var morphTargets = geometry.morphTargets;
  8705. var morphInfluences = this.morphTargetInfluences;
  8706. vA.set( 0, 0, 0 );
  8707. vB.set( 0, 0, 0 );
  8708. vC.set( 0, 0, 0 );
  8709. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  8710. var influence = morphInfluences[ t ];
  8711. if ( influence === 0 ) continue;
  8712. var targets = morphTargets[ t ].vertices;
  8713. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  8714. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  8715. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  8716. }
  8717. vA.add( fvA );
  8718. vB.add( fvB );
  8719. vC.add( fvC );
  8720. fvA = vA;
  8721. fvB = vB;
  8722. fvC = vC;
  8723. }
  8724. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8725. if ( intersection ) {
  8726. if ( uvs && uvs[ f ] ) {
  8727. var uvs_f = uvs[ f ];
  8728. uvA.copy( uvs_f[ 0 ] );
  8729. uvB.copy( uvs_f[ 1 ] );
  8730. uvC.copy( uvs_f[ 2 ] );
  8731. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  8732. }
  8733. intersection.face = face;
  8734. intersection.faceIndex = f;
  8735. intersects.push( intersection );
  8736. }
  8737. }
  8738. }
  8739. };
  8740. }() ),
  8741. clone: function () {
  8742. return new this.constructor( this.geometry, this.material ).copy( this );
  8743. }
  8744. } );
  8745. /**
  8746. * @author mrdoob / http://mrdoob.com/
  8747. */
  8748. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8749. var clearColor = new Color( 0x000000 );
  8750. var clearAlpha = 0;
  8751. var planeMesh;
  8752. var boxMesh;
  8753. // Store the current background texture and its `version`
  8754. // so we can recompile the material accordingly.
  8755. var currentBackground = null;
  8756. var currentBackgroundVersion = 0;
  8757. function render( renderList, scene, camera, forceClear ) {
  8758. var background = scene.background;
  8759. if ( background === null ) {
  8760. setClear( clearColor, clearAlpha );
  8761. currentBackground = null;
  8762. currentBackgroundVersion = 0;
  8763. } else if ( background && background.isColor ) {
  8764. setClear( background, 1 );
  8765. forceClear = true;
  8766. currentBackground = null;
  8767. currentBackgroundVersion = 0;
  8768. }
  8769. if ( renderer.autoClear || forceClear ) {
  8770. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8771. }
  8772. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  8773. if ( boxMesh === undefined ) {
  8774. boxMesh = new Mesh(
  8775. new BoxBufferGeometry( 1, 1, 1 ),
  8776. new ShaderMaterial( {
  8777. type: 'BackgroundCubeMaterial',
  8778. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8779. vertexShader: ShaderLib.cube.vertexShader,
  8780. fragmentShader: ShaderLib.cube.fragmentShader,
  8781. side: BackSide,
  8782. depthTest: false,
  8783. depthWrite: false,
  8784. fog: false
  8785. } )
  8786. );
  8787. boxMesh.geometry.removeAttribute( 'normal' );
  8788. boxMesh.geometry.removeAttribute( 'uv' );
  8789. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8790. this.matrixWorld.copyPosition( camera.matrixWorld );
  8791. };
  8792. // enable code injection for non-built-in material
  8793. Object.defineProperty( boxMesh.material, 'map', {
  8794. get: function () {
  8795. return this.uniforms.tCube.value;
  8796. }
  8797. } );
  8798. objects.update( boxMesh );
  8799. }
  8800. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  8801. boxMesh.material.uniforms.tCube.value = texture;
  8802. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  8803. if ( currentBackground !== background ||
  8804. currentBackgroundVersion !== texture.version ) {
  8805. boxMesh.material.needsUpdate = true;
  8806. currentBackground = background;
  8807. currentBackgroundVersion = texture.version;
  8808. }
  8809. // push to the pre-sorted opaque render list
  8810. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8811. } else if ( background && background.isTexture ) {
  8812. if ( planeMesh === undefined ) {
  8813. planeMesh = new Mesh(
  8814. new PlaneBufferGeometry( 2, 2 ),
  8815. new ShaderMaterial( {
  8816. type: 'BackgroundMaterial',
  8817. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8818. vertexShader: ShaderLib.background.vertexShader,
  8819. fragmentShader: ShaderLib.background.fragmentShader,
  8820. side: FrontSide,
  8821. depthTest: false,
  8822. depthWrite: false,
  8823. fog: false
  8824. } )
  8825. );
  8826. planeMesh.geometry.removeAttribute( 'normal' );
  8827. // enable code injection for non-built-in material
  8828. Object.defineProperty( planeMesh.material, 'map', {
  8829. get: function () {
  8830. return this.uniforms.t2D.value;
  8831. }
  8832. } );
  8833. objects.update( planeMesh );
  8834. }
  8835. planeMesh.material.uniforms.t2D.value = background;
  8836. if ( background.matrixAutoUpdate === true ) {
  8837. background.updateMatrix();
  8838. }
  8839. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8840. if ( currentBackground !== background ||
  8841. currentBackgroundVersion !== background.version ) {
  8842. planeMesh.material.needsUpdate = true;
  8843. currentBackground = background;
  8844. currentBackgroundVersion = background.version;
  8845. }
  8846. // push to the pre-sorted opaque render list
  8847. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8848. }
  8849. }
  8850. function setClear( color, alpha ) {
  8851. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8852. }
  8853. return {
  8854. getClearColor: function () {
  8855. return clearColor;
  8856. },
  8857. setClearColor: function ( color, alpha ) {
  8858. clearColor.set( color );
  8859. clearAlpha = alpha !== undefined ? alpha : 1;
  8860. setClear( clearColor, clearAlpha );
  8861. },
  8862. getClearAlpha: function () {
  8863. return clearAlpha;
  8864. },
  8865. setClearAlpha: function ( alpha ) {
  8866. clearAlpha = alpha;
  8867. setClear( clearColor, clearAlpha );
  8868. },
  8869. render: render
  8870. };
  8871. }
  8872. /**
  8873. * @author mrdoob / http://mrdoob.com/
  8874. */
  8875. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8876. var mode;
  8877. function setMode( value ) {
  8878. mode = value;
  8879. }
  8880. function render( start, count ) {
  8881. gl.drawArrays( mode, start, count );
  8882. info.update( count, mode );
  8883. }
  8884. function renderInstances( geometry, start, count ) {
  8885. var extension;
  8886. if ( capabilities.isWebGL2 ) {
  8887. extension = gl;
  8888. } else {
  8889. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8890. if ( extension === null ) {
  8891. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8892. return;
  8893. }
  8894. }
  8895. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  8896. info.update( count, mode, geometry.maxInstancedCount );
  8897. }
  8898. //
  8899. this.setMode = setMode;
  8900. this.render = render;
  8901. this.renderInstances = renderInstances;
  8902. }
  8903. /**
  8904. * @author mrdoob / http://mrdoob.com/
  8905. */
  8906. function WebGLCapabilities( gl, extensions, parameters ) {
  8907. var maxAnisotropy;
  8908. function getMaxAnisotropy() {
  8909. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8910. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8911. if ( extension !== null ) {
  8912. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8913. } else {
  8914. maxAnisotropy = 0;
  8915. }
  8916. return maxAnisotropy;
  8917. }
  8918. function getMaxPrecision( precision ) {
  8919. if ( precision === 'highp' ) {
  8920. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8921. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8922. return 'highp';
  8923. }
  8924. precision = 'mediump';
  8925. }
  8926. if ( precision === 'mediump' ) {
  8927. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8928. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8929. return 'mediump';
  8930. }
  8931. }
  8932. return 'lowp';
  8933. }
  8934. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  8935. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8936. var maxPrecision = getMaxPrecision( precision );
  8937. if ( maxPrecision !== precision ) {
  8938. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8939. precision = maxPrecision;
  8940. }
  8941. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8942. var maxTextures = gl.getParameter( 34930 );
  8943. var maxVertexTextures = gl.getParameter( 35660 );
  8944. var maxTextureSize = gl.getParameter( 3379 );
  8945. var maxCubemapSize = gl.getParameter( 34076 );
  8946. var maxAttributes = gl.getParameter( 34921 );
  8947. var maxVertexUniforms = gl.getParameter( 36347 );
  8948. var maxVaryings = gl.getParameter( 36348 );
  8949. var maxFragmentUniforms = gl.getParameter( 36349 );
  8950. var vertexTextures = maxVertexTextures > 0;
  8951. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8952. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8953. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8954. return {
  8955. isWebGL2: isWebGL2,
  8956. getMaxAnisotropy: getMaxAnisotropy,
  8957. getMaxPrecision: getMaxPrecision,
  8958. precision: precision,
  8959. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8960. maxTextures: maxTextures,
  8961. maxVertexTextures: maxVertexTextures,
  8962. maxTextureSize: maxTextureSize,
  8963. maxCubemapSize: maxCubemapSize,
  8964. maxAttributes: maxAttributes,
  8965. maxVertexUniforms: maxVertexUniforms,
  8966. maxVaryings: maxVaryings,
  8967. maxFragmentUniforms: maxFragmentUniforms,
  8968. vertexTextures: vertexTextures,
  8969. floatFragmentTextures: floatFragmentTextures,
  8970. floatVertexTextures: floatVertexTextures,
  8971. maxSamples: maxSamples
  8972. };
  8973. }
  8974. /**
  8975. * @author tschw
  8976. */
  8977. function WebGLClipping() {
  8978. var scope = this,
  8979. globalState = null,
  8980. numGlobalPlanes = 0,
  8981. localClippingEnabled = false,
  8982. renderingShadows = false,
  8983. plane = new Plane(),
  8984. viewNormalMatrix = new Matrix3(),
  8985. uniform = { value: null, needsUpdate: false };
  8986. this.uniform = uniform;
  8987. this.numPlanes = 0;
  8988. this.numIntersection = 0;
  8989. this.init = function ( planes, enableLocalClipping, camera ) {
  8990. var enabled =
  8991. planes.length !== 0 ||
  8992. enableLocalClipping ||
  8993. // enable state of previous frame - the clipping code has to
  8994. // run another frame in order to reset the state:
  8995. numGlobalPlanes !== 0 ||
  8996. localClippingEnabled;
  8997. localClippingEnabled = enableLocalClipping;
  8998. globalState = projectPlanes( planes, camera, 0 );
  8999. numGlobalPlanes = planes.length;
  9000. return enabled;
  9001. };
  9002. this.beginShadows = function () {
  9003. renderingShadows = true;
  9004. projectPlanes( null );
  9005. };
  9006. this.endShadows = function () {
  9007. renderingShadows = false;
  9008. resetGlobalState();
  9009. };
  9010. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9011. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9012. // there's no local clipping
  9013. if ( renderingShadows ) {
  9014. // there's no global clipping
  9015. projectPlanes( null );
  9016. } else {
  9017. resetGlobalState();
  9018. }
  9019. } else {
  9020. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9021. lGlobal = nGlobal * 4,
  9022. dstArray = cache.clippingState || null;
  9023. uniform.value = dstArray; // ensure unique state
  9024. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9025. for ( var i = 0; i !== lGlobal; ++ i ) {
  9026. dstArray[ i ] = globalState[ i ];
  9027. }
  9028. cache.clippingState = dstArray;
  9029. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9030. this.numPlanes += nGlobal;
  9031. }
  9032. };
  9033. function resetGlobalState() {
  9034. if ( uniform.value !== globalState ) {
  9035. uniform.value = globalState;
  9036. uniform.needsUpdate = numGlobalPlanes > 0;
  9037. }
  9038. scope.numPlanes = numGlobalPlanes;
  9039. scope.numIntersection = 0;
  9040. }
  9041. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9042. var nPlanes = planes !== null ? planes.length : 0,
  9043. dstArray = null;
  9044. if ( nPlanes !== 0 ) {
  9045. dstArray = uniform.value;
  9046. if ( skipTransform !== true || dstArray === null ) {
  9047. var flatSize = dstOffset + nPlanes * 4,
  9048. viewMatrix = camera.matrixWorldInverse;
  9049. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9050. if ( dstArray === null || dstArray.length < flatSize ) {
  9051. dstArray = new Float32Array( flatSize );
  9052. }
  9053. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9054. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9055. plane.normal.toArray( dstArray, i4 );
  9056. dstArray[ i4 + 3 ] = plane.constant;
  9057. }
  9058. }
  9059. uniform.value = dstArray;
  9060. uniform.needsUpdate = true;
  9061. }
  9062. scope.numPlanes = nPlanes;
  9063. return dstArray;
  9064. }
  9065. }
  9066. /**
  9067. * @author mrdoob / http://mrdoob.com/
  9068. */
  9069. function WebGLExtensions( gl ) {
  9070. var extensions = {};
  9071. return {
  9072. get: function ( name ) {
  9073. if ( extensions[ name ] !== undefined ) {
  9074. return extensions[ name ];
  9075. }
  9076. var extension;
  9077. switch ( name ) {
  9078. case 'WEBGL_depth_texture':
  9079. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9080. break;
  9081. case 'EXT_texture_filter_anisotropic':
  9082. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9083. break;
  9084. case 'WEBGL_compressed_texture_s3tc':
  9085. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9086. break;
  9087. case 'WEBGL_compressed_texture_pvrtc':
  9088. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9089. break;
  9090. default:
  9091. extension = gl.getExtension( name );
  9092. }
  9093. if ( extension === null ) {
  9094. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9095. }
  9096. extensions[ name ] = extension;
  9097. return extension;
  9098. }
  9099. };
  9100. }
  9101. /**
  9102. * @author mrdoob / http://mrdoob.com/
  9103. */
  9104. function WebGLGeometries( gl, attributes, info ) {
  9105. var geometries = {};
  9106. var wireframeAttributes = {};
  9107. function onGeometryDispose( event ) {
  9108. var geometry = event.target;
  9109. var buffergeometry = geometries[ geometry.id ];
  9110. if ( buffergeometry.index !== null ) {
  9111. attributes.remove( buffergeometry.index );
  9112. }
  9113. for ( var name in buffergeometry.attributes ) {
  9114. attributes.remove( buffergeometry.attributes[ name ] );
  9115. }
  9116. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9117. delete geometries[ geometry.id ];
  9118. var attribute = wireframeAttributes[ buffergeometry.id ];
  9119. if ( attribute ) {
  9120. attributes.remove( attribute );
  9121. delete wireframeAttributes[ buffergeometry.id ];
  9122. }
  9123. //
  9124. info.memory.geometries --;
  9125. }
  9126. function get( object, geometry ) {
  9127. var buffergeometry = geometries[ geometry.id ];
  9128. if ( buffergeometry ) return buffergeometry;
  9129. geometry.addEventListener( 'dispose', onGeometryDispose );
  9130. if ( geometry.isBufferGeometry ) {
  9131. buffergeometry = geometry;
  9132. } else if ( geometry.isGeometry ) {
  9133. if ( geometry._bufferGeometry === undefined ) {
  9134. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9135. }
  9136. buffergeometry = geometry._bufferGeometry;
  9137. }
  9138. geometries[ geometry.id ] = buffergeometry;
  9139. info.memory.geometries ++;
  9140. return buffergeometry;
  9141. }
  9142. function update( geometry ) {
  9143. var index = geometry.index;
  9144. var geometryAttributes = geometry.attributes;
  9145. if ( index !== null ) {
  9146. attributes.update( index, 34963 );
  9147. }
  9148. for ( var name in geometryAttributes ) {
  9149. attributes.update( geometryAttributes[ name ], 34962 );
  9150. }
  9151. // morph targets
  9152. var morphAttributes = geometry.morphAttributes;
  9153. for ( var name in morphAttributes ) {
  9154. var array = morphAttributes[ name ];
  9155. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9156. attributes.update( array[ i ], 34962 );
  9157. }
  9158. }
  9159. }
  9160. function getWireframeAttribute( geometry ) {
  9161. var attribute = wireframeAttributes[ geometry.id ];
  9162. if ( attribute ) return attribute;
  9163. var indices = [];
  9164. var geometryIndex = geometry.index;
  9165. var geometryAttributes = geometry.attributes;
  9166. // console.time( 'wireframe' );
  9167. if ( geometryIndex !== null ) {
  9168. var array = geometryIndex.array;
  9169. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9170. var a = array[ i + 0 ];
  9171. var b = array[ i + 1 ];
  9172. var c = array[ i + 2 ];
  9173. indices.push( a, b, b, c, c, a );
  9174. }
  9175. } else {
  9176. var array = geometryAttributes.position.array;
  9177. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9178. var a = i + 0;
  9179. var b = i + 1;
  9180. var c = i + 2;
  9181. indices.push( a, b, b, c, c, a );
  9182. }
  9183. }
  9184. // console.timeEnd( 'wireframe' );
  9185. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9186. attributes.update( attribute, 34963 );
  9187. wireframeAttributes[ geometry.id ] = attribute;
  9188. return attribute;
  9189. }
  9190. return {
  9191. get: get,
  9192. update: update,
  9193. getWireframeAttribute: getWireframeAttribute
  9194. };
  9195. }
  9196. /**
  9197. * @author mrdoob / http://mrdoob.com/
  9198. */
  9199. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9200. var mode;
  9201. function setMode( value ) {
  9202. mode = value;
  9203. }
  9204. var type, bytesPerElement;
  9205. function setIndex( value ) {
  9206. type = value.type;
  9207. bytesPerElement = value.bytesPerElement;
  9208. }
  9209. function render( start, count ) {
  9210. gl.drawElements( mode, count, type, start * bytesPerElement );
  9211. info.update( count, mode );
  9212. }
  9213. function renderInstances( geometry, start, count ) {
  9214. var extension;
  9215. if ( capabilities.isWebGL2 ) {
  9216. extension = gl;
  9217. } else {
  9218. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9219. if ( extension === null ) {
  9220. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9221. return;
  9222. }
  9223. }
  9224. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9225. info.update( count, mode, geometry.maxInstancedCount );
  9226. }
  9227. //
  9228. this.setMode = setMode;
  9229. this.setIndex = setIndex;
  9230. this.render = render;
  9231. this.renderInstances = renderInstances;
  9232. }
  9233. /**
  9234. * @author Mugen87 / https://github.com/Mugen87
  9235. */
  9236. function WebGLInfo( gl ) {
  9237. var memory = {
  9238. geometries: 0,
  9239. textures: 0
  9240. };
  9241. var render = {
  9242. frame: 0,
  9243. calls: 0,
  9244. triangles: 0,
  9245. points: 0,
  9246. lines: 0
  9247. };
  9248. function update( count, mode, instanceCount ) {
  9249. instanceCount = instanceCount || 1;
  9250. render.calls ++;
  9251. switch ( mode ) {
  9252. case 4:
  9253. render.triangles += instanceCount * ( count / 3 );
  9254. break;
  9255. case 5:
  9256. case 6:
  9257. render.triangles += instanceCount * ( count - 2 );
  9258. break;
  9259. case 1:
  9260. render.lines += instanceCount * ( count / 2 );
  9261. break;
  9262. case 3:
  9263. render.lines += instanceCount * ( count - 1 );
  9264. break;
  9265. case 2:
  9266. render.lines += instanceCount * count;
  9267. break;
  9268. case 0:
  9269. render.points += instanceCount * count;
  9270. break;
  9271. default:
  9272. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9273. break;
  9274. }
  9275. }
  9276. function reset() {
  9277. render.frame ++;
  9278. render.calls = 0;
  9279. render.triangles = 0;
  9280. render.points = 0;
  9281. render.lines = 0;
  9282. }
  9283. return {
  9284. memory: memory,
  9285. render: render,
  9286. programs: null,
  9287. autoReset: true,
  9288. reset: reset,
  9289. update: update
  9290. };
  9291. }
  9292. /**
  9293. * @author mrdoob / http://mrdoob.com/
  9294. */
  9295. function absNumericalSort( a, b ) {
  9296. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9297. }
  9298. function WebGLMorphtargets( gl ) {
  9299. var influencesList = {};
  9300. var morphInfluences = new Float32Array( 8 );
  9301. function update( object, geometry, material, program ) {
  9302. var objectInfluences = object.morphTargetInfluences;
  9303. var length = objectInfluences.length;
  9304. var influences = influencesList[ geometry.id ];
  9305. if ( influences === undefined ) {
  9306. // initialise list
  9307. influences = [];
  9308. for ( var i = 0; i < length; i ++ ) {
  9309. influences[ i ] = [ i, 0 ];
  9310. }
  9311. influencesList[ geometry.id ] = influences;
  9312. }
  9313. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9314. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9315. // Remove current morphAttributes
  9316. for ( var i = 0; i < length; i ++ ) {
  9317. var influence = influences[ i ];
  9318. if ( influence[ 1 ] !== 0 ) {
  9319. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9320. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9321. }
  9322. }
  9323. // Collect influences
  9324. for ( var i = 0; i < length; i ++ ) {
  9325. var influence = influences[ i ];
  9326. influence[ 0 ] = i;
  9327. influence[ 1 ] = objectInfluences[ i ];
  9328. }
  9329. influences.sort( absNumericalSort );
  9330. // Add morphAttributes
  9331. for ( var i = 0; i < 8; i ++ ) {
  9332. var influence = influences[ i ];
  9333. if ( influence ) {
  9334. var index = influence[ 0 ];
  9335. var value = influence[ 1 ];
  9336. if ( value ) {
  9337. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9338. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9339. morphInfluences[ i ] = value;
  9340. continue;
  9341. }
  9342. }
  9343. morphInfluences[ i ] = 0;
  9344. }
  9345. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9346. }
  9347. return {
  9348. update: update
  9349. };
  9350. }
  9351. /**
  9352. * @author mrdoob / http://mrdoob.com/
  9353. */
  9354. function WebGLObjects( geometries, info ) {
  9355. var updateList = {};
  9356. function update( object ) {
  9357. var frame = info.render.frame;
  9358. var geometry = object.geometry;
  9359. var buffergeometry = geometries.get( object, geometry );
  9360. // Update once per frame
  9361. if ( updateList[ buffergeometry.id ] !== frame ) {
  9362. if ( geometry.isGeometry ) {
  9363. buffergeometry.updateFromObject( object );
  9364. }
  9365. geometries.update( buffergeometry );
  9366. updateList[ buffergeometry.id ] = frame;
  9367. }
  9368. return buffergeometry;
  9369. }
  9370. function dispose() {
  9371. updateList = {};
  9372. }
  9373. return {
  9374. update: update,
  9375. dispose: dispose
  9376. };
  9377. }
  9378. /**
  9379. * @author mrdoob / http://mrdoob.com/
  9380. */
  9381. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9382. images = images !== undefined ? images : [];
  9383. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9384. format = format !== undefined ? format : RGBFormat;
  9385. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9386. this.flipY = false;
  9387. }
  9388. CubeTexture.prototype = Object.create( Texture.prototype );
  9389. CubeTexture.prototype.constructor = CubeTexture;
  9390. CubeTexture.prototype.isCubeTexture = true;
  9391. Object.defineProperty( CubeTexture.prototype, 'images', {
  9392. get: function () {
  9393. return this.image;
  9394. },
  9395. set: function ( value ) {
  9396. this.image = value;
  9397. }
  9398. } );
  9399. /**
  9400. * @author Artur Trzesiok
  9401. */
  9402. function DataTexture3D( data, width, height, depth ) {
  9403. // We're going to add .setXXX() methods for setting properties later.
  9404. // Users can still set in DataTexture3D directly.
  9405. //
  9406. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9407. // texture.anisotropy = 16;
  9408. //
  9409. // See #14839
  9410. Texture.call( this, null );
  9411. this.image = { data: data, width: width, height: height, depth: depth };
  9412. this.magFilter = NearestFilter;
  9413. this.minFilter = NearestFilter;
  9414. this.wrapR = ClampToEdgeWrapping;
  9415. this.generateMipmaps = false;
  9416. this.flipY = false;
  9417. }
  9418. DataTexture3D.prototype = Object.create( Texture.prototype );
  9419. DataTexture3D.prototype.constructor = DataTexture3D;
  9420. DataTexture3D.prototype.isDataTexture3D = true;
  9421. /**
  9422. * @author tschw
  9423. * @author Mugen87 / https://github.com/Mugen87
  9424. * @author mrdoob / http://mrdoob.com/
  9425. *
  9426. * Uniforms of a program.
  9427. * Those form a tree structure with a special top-level container for the root,
  9428. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  9429. *
  9430. *
  9431. * Properties of inner nodes including the top-level container:
  9432. *
  9433. * .seq - array of nested uniforms
  9434. * .map - nested uniforms by name
  9435. *
  9436. *
  9437. * Methods of all nodes except the top-level container:
  9438. *
  9439. * .setValue( gl, value, [renderer] )
  9440. *
  9441. * uploads a uniform value(s)
  9442. * the 'renderer' parameter is needed for sampler uniforms
  9443. *
  9444. *
  9445. * Static methods of the top-level container (renderer factorizations):
  9446. *
  9447. * .upload( gl, seq, values, renderer )
  9448. *
  9449. * sets uniforms in 'seq' to 'values[id].value'
  9450. *
  9451. * .seqWithValue( seq, values ) : filteredSeq
  9452. *
  9453. * filters 'seq' entries with corresponding entry in values
  9454. *
  9455. *
  9456. * Methods of the top-level container (renderer factorizations):
  9457. *
  9458. * .setValue( gl, name, value )
  9459. *
  9460. * sets uniform with name 'name' to 'value'
  9461. *
  9462. * .set( gl, obj, prop )
  9463. *
  9464. * sets uniform from object and property with same name than uniform
  9465. *
  9466. * .setOptional( gl, obj, prop )
  9467. *
  9468. * like .set for an optional property of the object
  9469. *
  9470. */
  9471. var emptyTexture = new Texture();
  9472. var emptyTexture3d = new DataTexture3D();
  9473. var emptyCubeTexture = new CubeTexture();
  9474. // --- Base for inner nodes (including the root) ---
  9475. function UniformContainer() {
  9476. this.seq = [];
  9477. this.map = {};
  9478. }
  9479. // --- Utilities ---
  9480. // Array Caches (provide typed arrays for temporary by size)
  9481. var arrayCacheF32 = [];
  9482. var arrayCacheI32 = [];
  9483. // Float32Array caches used for uploading Matrix uniforms
  9484. var mat4array = new Float32Array( 16 );
  9485. var mat3array = new Float32Array( 9 );
  9486. var mat2array = new Float32Array( 4 );
  9487. // Flattening for arrays of vectors and matrices
  9488. function flatten( array, nBlocks, blockSize ) {
  9489. var firstElem = array[ 0 ];
  9490. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9491. // unoptimized: ! isNaN( firstElem )
  9492. // see http://jacksondunstan.com/articles/983
  9493. var n = nBlocks * blockSize,
  9494. r = arrayCacheF32[ n ];
  9495. if ( r === undefined ) {
  9496. r = new Float32Array( n );
  9497. arrayCacheF32[ n ] = r;
  9498. }
  9499. if ( nBlocks !== 0 ) {
  9500. firstElem.toArray( r, 0 );
  9501. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9502. offset += blockSize;
  9503. array[ i ].toArray( r, offset );
  9504. }
  9505. }
  9506. return r;
  9507. }
  9508. function arraysEqual( a, b ) {
  9509. if ( a.length !== b.length ) return false;
  9510. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9511. if ( a[ i ] !== b[ i ] ) return false;
  9512. }
  9513. return true;
  9514. }
  9515. function copyArray( a, b ) {
  9516. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9517. a[ i ] = b[ i ];
  9518. }
  9519. }
  9520. // Texture unit allocation
  9521. function allocTexUnits( renderer, n ) {
  9522. var r = arrayCacheI32[ n ];
  9523. if ( r === undefined ) {
  9524. r = new Int32Array( n );
  9525. arrayCacheI32[ n ] = r;
  9526. }
  9527. for ( var i = 0; i !== n; ++ i )
  9528. r[ i ] = renderer.allocTextureUnit();
  9529. return r;
  9530. }
  9531. // --- Setters ---
  9532. // Note: Defining these methods externally, because they come in a bunch
  9533. // and this way their names minify.
  9534. // Single scalar
  9535. function setValue1f( gl, v ) {
  9536. var cache = this.cache;
  9537. if ( cache[ 0 ] === v ) return;
  9538. gl.uniform1f( this.addr, v );
  9539. cache[ 0 ] = v;
  9540. }
  9541. function setValue1i( gl, v ) {
  9542. var cache = this.cache;
  9543. if ( cache[ 0 ] === v ) return;
  9544. gl.uniform1i( this.addr, v );
  9545. cache[ 0 ] = v;
  9546. }
  9547. // Single float vector (from flat array or THREE.VectorN)
  9548. function setValue2fv( gl, v ) {
  9549. var cache = this.cache;
  9550. if ( v.x !== undefined ) {
  9551. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9552. gl.uniform2f( this.addr, v.x, v.y );
  9553. cache[ 0 ] = v.x;
  9554. cache[ 1 ] = v.y;
  9555. }
  9556. } else {
  9557. if ( arraysEqual( cache, v ) ) return;
  9558. gl.uniform2fv( this.addr, v );
  9559. copyArray( cache, v );
  9560. }
  9561. }
  9562. function setValue3fv( gl, v ) {
  9563. var cache = this.cache;
  9564. if ( v.x !== undefined ) {
  9565. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9566. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9567. cache[ 0 ] = v.x;
  9568. cache[ 1 ] = v.y;
  9569. cache[ 2 ] = v.z;
  9570. }
  9571. } else if ( v.r !== undefined ) {
  9572. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9573. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9574. cache[ 0 ] = v.r;
  9575. cache[ 1 ] = v.g;
  9576. cache[ 2 ] = v.b;
  9577. }
  9578. } else {
  9579. if ( arraysEqual( cache, v ) ) return;
  9580. gl.uniform3fv( this.addr, v );
  9581. copyArray( cache, v );
  9582. }
  9583. }
  9584. function setValue4fv( gl, v ) {
  9585. var cache = this.cache;
  9586. if ( v.x !== undefined ) {
  9587. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9588. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9589. cache[ 0 ] = v.x;
  9590. cache[ 1 ] = v.y;
  9591. cache[ 2 ] = v.z;
  9592. cache[ 3 ] = v.w;
  9593. }
  9594. } else {
  9595. if ( arraysEqual( cache, v ) ) return;
  9596. gl.uniform4fv( this.addr, v );
  9597. copyArray( cache, v );
  9598. }
  9599. }
  9600. // Single matrix (from flat array or MatrixN)
  9601. function setValue2fm( gl, v ) {
  9602. var cache = this.cache;
  9603. var elements = v.elements;
  9604. if ( elements === undefined ) {
  9605. if ( arraysEqual( cache, v ) ) return;
  9606. gl.uniformMatrix2fv( this.addr, false, v );
  9607. copyArray( cache, v );
  9608. } else {
  9609. if ( arraysEqual( cache, elements ) ) return;
  9610. mat2array.set( elements );
  9611. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9612. copyArray( cache, elements );
  9613. }
  9614. }
  9615. function setValue3fm( gl, v ) {
  9616. var cache = this.cache;
  9617. var elements = v.elements;
  9618. if ( elements === undefined ) {
  9619. if ( arraysEqual( cache, v ) ) return;
  9620. gl.uniformMatrix3fv( this.addr, false, v );
  9621. copyArray( cache, v );
  9622. } else {
  9623. if ( arraysEqual( cache, elements ) ) return;
  9624. mat3array.set( elements );
  9625. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9626. copyArray( cache, elements );
  9627. }
  9628. }
  9629. function setValue4fm( gl, v ) {
  9630. var cache = this.cache;
  9631. var elements = v.elements;
  9632. if ( elements === undefined ) {
  9633. if ( arraysEqual( cache, v ) ) return;
  9634. gl.uniformMatrix4fv( this.addr, false, v );
  9635. copyArray( cache, v );
  9636. } else {
  9637. if ( arraysEqual( cache, elements ) ) return;
  9638. mat4array.set( elements );
  9639. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9640. copyArray( cache, elements );
  9641. }
  9642. }
  9643. // Single texture (2D / Cube)
  9644. function setValueT1( gl, v, renderer ) {
  9645. var cache = this.cache;
  9646. var unit = renderer.allocTextureUnit();
  9647. if ( cache[ 0 ] !== unit ) {
  9648. gl.uniform1i( this.addr, unit );
  9649. cache[ 0 ] = unit;
  9650. }
  9651. renderer.setTexture2D( v || emptyTexture, unit );
  9652. }
  9653. function setValueT3D1( gl, v, renderer ) {
  9654. var cache = this.cache;
  9655. var unit = renderer.allocTextureUnit();
  9656. if ( cache[ 0 ] !== unit ) {
  9657. gl.uniform1i( this.addr, unit );
  9658. cache[ 0 ] = unit;
  9659. }
  9660. renderer.setTexture3D( v || emptyTexture3d, unit );
  9661. }
  9662. function setValueT6( gl, v, renderer ) {
  9663. var cache = this.cache;
  9664. var unit = renderer.allocTextureUnit();
  9665. if ( cache[ 0 ] !== unit ) {
  9666. gl.uniform1i( this.addr, unit );
  9667. cache[ 0 ] = unit;
  9668. }
  9669. renderer.setTextureCube( v || emptyCubeTexture, unit );
  9670. }
  9671. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9672. function setValue2iv( gl, v ) {
  9673. var cache = this.cache;
  9674. if ( arraysEqual( cache, v ) ) return;
  9675. gl.uniform2iv( this.addr, v );
  9676. copyArray( cache, v );
  9677. }
  9678. function setValue3iv( gl, v ) {
  9679. var cache = this.cache;
  9680. if ( arraysEqual( cache, v ) ) return;
  9681. gl.uniform3iv( this.addr, v );
  9682. copyArray( cache, v );
  9683. }
  9684. function setValue4iv( gl, v ) {
  9685. var cache = this.cache;
  9686. if ( arraysEqual( cache, v ) ) return;
  9687. gl.uniform4iv( this.addr, v );
  9688. copyArray( cache, v );
  9689. }
  9690. // Helper to pick the right setter for the singular case
  9691. function getSingularSetter( type ) {
  9692. switch ( type ) {
  9693. case 0x1406: return setValue1f; // FLOAT
  9694. case 0x8b50: return setValue2fv; // _VEC2
  9695. case 0x8b51: return setValue3fv; // _VEC3
  9696. case 0x8b52: return setValue4fv; // _VEC4
  9697. case 0x8b5a: return setValue2fm; // _MAT2
  9698. case 0x8b5b: return setValue3fm; // _MAT3
  9699. case 0x8b5c: return setValue4fm; // _MAT4
  9700. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9701. case 0x8B5F: return setValueT3D1; // SAMPLER_3D
  9702. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9703. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9704. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9705. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9706. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9707. }
  9708. }
  9709. // Array of scalars
  9710. function setValue1fv( gl, v ) {
  9711. var cache = this.cache;
  9712. if ( arraysEqual( cache, v ) ) return;
  9713. gl.uniform1fv( this.addr, v );
  9714. copyArray( cache, v );
  9715. }
  9716. function setValue1iv( gl, v ) {
  9717. var cache = this.cache;
  9718. if ( arraysEqual( cache, v ) ) return;
  9719. gl.uniform1iv( this.addr, v );
  9720. copyArray( cache, v );
  9721. }
  9722. // Array of vectors (flat or from THREE classes)
  9723. function setValueV2a( gl, v ) {
  9724. var cache = this.cache;
  9725. var data = flatten( v, this.size, 2 );
  9726. if ( arraysEqual( cache, data ) ) return;
  9727. gl.uniform2fv( this.addr, data );
  9728. this.updateCache( data );
  9729. }
  9730. function setValueV3a( gl, v ) {
  9731. var cache = this.cache;
  9732. var data = flatten( v, this.size, 3 );
  9733. if ( arraysEqual( cache, data ) ) return;
  9734. gl.uniform3fv( this.addr, data );
  9735. this.updateCache( data );
  9736. }
  9737. function setValueV4a( gl, v ) {
  9738. var cache = this.cache;
  9739. var data = flatten( v, this.size, 4 );
  9740. if ( arraysEqual( cache, data ) ) return;
  9741. gl.uniform4fv( this.addr, data );
  9742. this.updateCache( data );
  9743. }
  9744. // Array of matrices (flat or from THREE clases)
  9745. function setValueM2a( gl, v ) {
  9746. var cache = this.cache;
  9747. var data = flatten( v, this.size, 4 );
  9748. if ( arraysEqual( cache, data ) ) return;
  9749. gl.uniformMatrix2fv( this.addr, false, data );
  9750. this.updateCache( data );
  9751. }
  9752. function setValueM3a( gl, v ) {
  9753. var cache = this.cache;
  9754. var data = flatten( v, this.size, 9 );
  9755. if ( arraysEqual( cache, data ) ) return;
  9756. gl.uniformMatrix3fv( this.addr, false, data );
  9757. this.updateCache( data );
  9758. }
  9759. function setValueM4a( gl, v ) {
  9760. var cache = this.cache;
  9761. var data = flatten( v, this.size, 16 );
  9762. if ( arraysEqual( cache, data ) ) return;
  9763. gl.uniformMatrix4fv( this.addr, false, data );
  9764. this.updateCache( data );
  9765. }
  9766. // Array of textures (2D / Cube)
  9767. function setValueT1a( gl, v, renderer ) {
  9768. var cache = this.cache;
  9769. var n = v.length;
  9770. var units = allocTexUnits( renderer, n );
  9771. if ( arraysEqual( cache, units ) === false ) {
  9772. gl.uniform1iv( this.addr, units );
  9773. copyArray( cache, units );
  9774. }
  9775. for ( var i = 0; i !== n; ++ i ) {
  9776. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9777. }
  9778. }
  9779. function setValueT6a( gl, v, renderer ) {
  9780. var cache = this.cache;
  9781. var n = v.length;
  9782. var units = allocTexUnits( renderer, n );
  9783. if ( arraysEqual( cache, units ) === false ) {
  9784. gl.uniform1iv( this.addr, units );
  9785. copyArray( cache, units );
  9786. }
  9787. for ( var i = 0; i !== n; ++ i ) {
  9788. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9789. }
  9790. }
  9791. // Helper to pick the right setter for a pure (bottom-level) array
  9792. function getPureArraySetter( type ) {
  9793. switch ( type ) {
  9794. case 0x1406: return setValue1fv; // FLOAT
  9795. case 0x8b50: return setValueV2a; // _VEC2
  9796. case 0x8b51: return setValueV3a; // _VEC3
  9797. case 0x8b52: return setValueV4a; // _VEC4
  9798. case 0x8b5a: return setValueM2a; // _MAT2
  9799. case 0x8b5b: return setValueM3a; // _MAT3
  9800. case 0x8b5c: return setValueM4a; // _MAT4
  9801. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9802. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9803. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9804. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9805. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9806. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9807. }
  9808. }
  9809. // --- Uniform Classes ---
  9810. function SingleUniform( id, activeInfo, addr ) {
  9811. this.id = id;
  9812. this.addr = addr;
  9813. this.cache = [];
  9814. this.setValue = getSingularSetter( activeInfo.type );
  9815. // this.path = activeInfo.name; // DEBUG
  9816. }
  9817. function PureArrayUniform( id, activeInfo, addr ) {
  9818. this.id = id;
  9819. this.addr = addr;
  9820. this.cache = [];
  9821. this.size = activeInfo.size;
  9822. this.setValue = getPureArraySetter( activeInfo.type );
  9823. // this.path = activeInfo.name; // DEBUG
  9824. }
  9825. PureArrayUniform.prototype.updateCache = function ( data ) {
  9826. var cache = this.cache;
  9827. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9828. this.cache = new Float32Array( data.length );
  9829. }
  9830. copyArray( cache, data );
  9831. };
  9832. function StructuredUniform( id ) {
  9833. this.id = id;
  9834. UniformContainer.call( this ); // mix-in
  9835. }
  9836. StructuredUniform.prototype.setValue = function ( gl, value, renderer ) {
  9837. var seq = this.seq;
  9838. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9839. var u = seq[ i ];
  9840. u.setValue( gl, value[ u.id ], renderer );
  9841. }
  9842. };
  9843. // --- Top-level ---
  9844. // Parser - builds up the property tree from the path strings
  9845. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9846. // extracts
  9847. // - the identifier (member name or array index)
  9848. // - followed by an optional right bracket (found when array index)
  9849. // - followed by an optional left bracket or dot (type of subscript)
  9850. //
  9851. // Note: These portions can be read in a non-overlapping fashion and
  9852. // allow straightforward parsing of the hierarchy that WebGL encodes
  9853. // in the uniform names.
  9854. function addUniform( container, uniformObject ) {
  9855. container.seq.push( uniformObject );
  9856. container.map[ uniformObject.id ] = uniformObject;
  9857. }
  9858. function parseUniform( activeInfo, addr, container ) {
  9859. var path = activeInfo.name,
  9860. pathLength = path.length;
  9861. // reset RegExp object, because of the early exit of a previous run
  9862. RePathPart.lastIndex = 0;
  9863. while ( true ) {
  9864. var match = RePathPart.exec( path ),
  9865. matchEnd = RePathPart.lastIndex,
  9866. id = match[ 1 ],
  9867. idIsIndex = match[ 2 ] === ']',
  9868. subscript = match[ 3 ];
  9869. if ( idIsIndex ) id = id | 0; // convert to integer
  9870. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9871. // bare name or "pure" bottom-level array "[0]" suffix
  9872. addUniform( container, subscript === undefined ?
  9873. new SingleUniform( id, activeInfo, addr ) :
  9874. new PureArrayUniform( id, activeInfo, addr ) );
  9875. break;
  9876. } else {
  9877. // step into inner node / create it in case it doesn't exist
  9878. var map = container.map, next = map[ id ];
  9879. if ( next === undefined ) {
  9880. next = new StructuredUniform( id );
  9881. addUniform( container, next );
  9882. }
  9883. container = next;
  9884. }
  9885. }
  9886. }
  9887. // Root Container
  9888. function WebGLUniforms( gl, program, renderer ) {
  9889. UniformContainer.call( this );
  9890. this.renderer = renderer;
  9891. var n = gl.getProgramParameter( program, 35718 );
  9892. for ( var i = 0; i < n; ++ i ) {
  9893. var info = gl.getActiveUniform( program, i ),
  9894. addr = gl.getUniformLocation( program, info.name );
  9895. parseUniform( info, addr, this );
  9896. }
  9897. }
  9898. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  9899. var u = this.map[ name ];
  9900. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  9901. };
  9902. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9903. var v = object[ name ];
  9904. if ( v !== undefined ) this.setValue( gl, name, v );
  9905. };
  9906. // Static interface
  9907. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  9908. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9909. var u = seq[ i ],
  9910. v = values[ u.id ];
  9911. if ( v.needsUpdate !== false ) {
  9912. // note: always updating when .needsUpdate is undefined
  9913. u.setValue( gl, v.value, renderer );
  9914. }
  9915. }
  9916. };
  9917. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9918. var r = [];
  9919. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9920. var u = seq[ i ];
  9921. if ( u.id in values ) r.push( u );
  9922. }
  9923. return r;
  9924. };
  9925. /**
  9926. * @author mrdoob / http://mrdoob.com/
  9927. */
  9928. function addLineNumbers( string ) {
  9929. var lines = string.split( '\n' );
  9930. for ( var i = 0; i < lines.length; i ++ ) {
  9931. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9932. }
  9933. return lines.join( '\n' );
  9934. }
  9935. function WebGLShader( gl, type, string ) {
  9936. var shader = gl.createShader( type );
  9937. gl.shaderSource( shader, string );
  9938. gl.compileShader( shader );
  9939. if ( gl.getShaderParameter( shader, 35713 ) === false ) {
  9940. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9941. }
  9942. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9943. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === 35633 ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9944. }
  9945. // --enable-privileged-webgl-extension
  9946. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9947. return shader;
  9948. }
  9949. /**
  9950. * @author mrdoob / http://mrdoob.com/
  9951. */
  9952. var programIdCount = 0;
  9953. function getEncodingComponents( encoding ) {
  9954. switch ( encoding ) {
  9955. case LinearEncoding:
  9956. return [ 'Linear', '( value )' ];
  9957. case sRGBEncoding:
  9958. return [ 'sRGB', '( value )' ];
  9959. case RGBEEncoding:
  9960. return [ 'RGBE', '( value )' ];
  9961. case RGBM7Encoding:
  9962. return [ 'RGBM', '( value, 7.0 )' ];
  9963. case RGBM16Encoding:
  9964. return [ 'RGBM', '( value, 16.0 )' ];
  9965. case RGBDEncoding:
  9966. return [ 'RGBD', '( value, 256.0 )' ];
  9967. case GammaEncoding:
  9968. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9969. default:
  9970. throw new Error( 'unsupported encoding: ' + encoding );
  9971. }
  9972. }
  9973. function getTexelDecodingFunction( functionName, encoding ) {
  9974. var components = getEncodingComponents( encoding );
  9975. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9976. }
  9977. function getTexelEncodingFunction( functionName, encoding ) {
  9978. var components = getEncodingComponents( encoding );
  9979. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9980. }
  9981. function getToneMappingFunction( functionName, toneMapping ) {
  9982. var toneMappingName;
  9983. switch ( toneMapping ) {
  9984. case LinearToneMapping:
  9985. toneMappingName = 'Linear';
  9986. break;
  9987. case ReinhardToneMapping:
  9988. toneMappingName = 'Reinhard';
  9989. break;
  9990. case Uncharted2ToneMapping:
  9991. toneMappingName = 'Uncharted2';
  9992. break;
  9993. case CineonToneMapping:
  9994. toneMappingName = 'OptimizedCineon';
  9995. break;
  9996. case ACESFilmicToneMapping:
  9997. toneMappingName = 'ACESFilmic';
  9998. break;
  9999. default:
  10000. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10001. }
  10002. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10003. }
  10004. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10005. extensions = extensions || {};
  10006. var chunks = [
  10007. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10008. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10009. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10010. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10011. ];
  10012. return chunks.filter( filterEmptyLine ).join( '\n' );
  10013. }
  10014. function generateDefines( defines ) {
  10015. var chunks = [];
  10016. for ( var name in defines ) {
  10017. var value = defines[ name ];
  10018. if ( value === false ) continue;
  10019. chunks.push( '#define ' + name + ' ' + value );
  10020. }
  10021. return chunks.join( '\n' );
  10022. }
  10023. function fetchAttributeLocations( gl, program ) {
  10024. var attributes = {};
  10025. var n = gl.getProgramParameter( program, 35721 );
  10026. for ( var i = 0; i < n; i ++ ) {
  10027. var info = gl.getActiveAttrib( program, i );
  10028. var name = info.name;
  10029. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10030. attributes[ name ] = gl.getAttribLocation( program, name );
  10031. }
  10032. return attributes;
  10033. }
  10034. function filterEmptyLine( string ) {
  10035. return string !== '';
  10036. }
  10037. function replaceLightNums( string, parameters ) {
  10038. return string
  10039. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10040. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10041. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10042. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10043. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10044. }
  10045. function replaceClippingPlaneNums( string, parameters ) {
  10046. return string
  10047. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10048. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10049. }
  10050. function parseIncludes( string ) {
  10051. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10052. function replace( match, include ) {
  10053. var replace = ShaderChunk[ include ];
  10054. if ( replace === undefined ) {
  10055. throw new Error( 'Can not resolve #include <' + include + '>' );
  10056. }
  10057. return parseIncludes( replace );
  10058. }
  10059. return string.replace( pattern, replace );
  10060. }
  10061. function unrollLoops( string ) {
  10062. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10063. function replace( match, start, end, snippet ) {
  10064. var unroll = '';
  10065. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10066. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10067. }
  10068. return unroll;
  10069. }
  10070. return string.replace( pattern, replace );
  10071. }
  10072. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  10073. var gl = renderer.context;
  10074. var defines = material.defines;
  10075. var vertexShader = shader.vertexShader;
  10076. var fragmentShader = shader.fragmentShader;
  10077. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10078. if ( parameters.shadowMapType === PCFShadowMap ) {
  10079. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10080. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10081. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10082. }
  10083. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10084. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10085. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10086. if ( parameters.envMap ) {
  10087. switch ( material.envMap.mapping ) {
  10088. case CubeReflectionMapping:
  10089. case CubeRefractionMapping:
  10090. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10091. break;
  10092. case CubeUVReflectionMapping:
  10093. case CubeUVRefractionMapping:
  10094. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10095. break;
  10096. case EquirectangularReflectionMapping:
  10097. case EquirectangularRefractionMapping:
  10098. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10099. break;
  10100. case SphericalReflectionMapping:
  10101. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10102. break;
  10103. }
  10104. switch ( material.envMap.mapping ) {
  10105. case CubeRefractionMapping:
  10106. case EquirectangularRefractionMapping:
  10107. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10108. break;
  10109. }
  10110. switch ( material.combine ) {
  10111. case MultiplyOperation:
  10112. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10113. break;
  10114. case MixOperation:
  10115. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10116. break;
  10117. case AddOperation:
  10118. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10119. break;
  10120. }
  10121. }
  10122. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10123. // console.log( 'building new program ' );
  10124. //
  10125. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10126. var customDefines = generateDefines( defines );
  10127. //
  10128. var program = gl.createProgram();
  10129. var prefixVertex, prefixFragment;
  10130. if ( material.isRawShaderMaterial ) {
  10131. prefixVertex = [
  10132. customDefines
  10133. ].filter( filterEmptyLine ).join( '\n' );
  10134. if ( prefixVertex.length > 0 ) {
  10135. prefixVertex += '\n';
  10136. }
  10137. prefixFragment = [
  10138. customExtensions,
  10139. customDefines
  10140. ].filter( filterEmptyLine ).join( '\n' );
  10141. if ( prefixFragment.length > 0 ) {
  10142. prefixFragment += '\n';
  10143. }
  10144. } else {
  10145. prefixVertex = [
  10146. 'precision ' + parameters.precision + ' float;',
  10147. 'precision ' + parameters.precision + ' int;',
  10148. '#define SHADER_NAME ' + shader.name,
  10149. customDefines,
  10150. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10151. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10152. '#define MAX_BONES ' + parameters.maxBones,
  10153. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10154. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10155. parameters.map ? '#define USE_MAP' : '',
  10156. parameters.envMap ? '#define USE_ENVMAP' : '',
  10157. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10158. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10159. parameters.aoMap ? '#define USE_AOMAP' : '',
  10160. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10161. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10162. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10163. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10164. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10165. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10166. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10167. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10168. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10169. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10170. parameters.vertexColors ? '#define USE_COLOR' : '',
  10171. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10172. parameters.skinning ? '#define USE_SKINNING' : '',
  10173. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10174. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10175. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10176. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10177. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10178. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10179. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10180. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10181. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10182. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10183. 'uniform mat4 modelMatrix;',
  10184. 'uniform mat4 modelViewMatrix;',
  10185. 'uniform mat4 projectionMatrix;',
  10186. 'uniform mat4 viewMatrix;',
  10187. 'uniform mat3 normalMatrix;',
  10188. 'uniform vec3 cameraPosition;',
  10189. 'attribute vec3 position;',
  10190. 'attribute vec3 normal;',
  10191. 'attribute vec2 uv;',
  10192. '#ifdef USE_TANGENT',
  10193. ' attribute vec4 tangent;',
  10194. '#endif',
  10195. '#ifdef USE_COLOR',
  10196. ' attribute vec3 color;',
  10197. '#endif',
  10198. '#ifdef USE_MORPHTARGETS',
  10199. ' attribute vec3 morphTarget0;',
  10200. ' attribute vec3 morphTarget1;',
  10201. ' attribute vec3 morphTarget2;',
  10202. ' attribute vec3 morphTarget3;',
  10203. ' #ifdef USE_MORPHNORMALS',
  10204. ' attribute vec3 morphNormal0;',
  10205. ' attribute vec3 morphNormal1;',
  10206. ' attribute vec3 morphNormal2;',
  10207. ' attribute vec3 morphNormal3;',
  10208. ' #else',
  10209. ' attribute vec3 morphTarget4;',
  10210. ' attribute vec3 morphTarget5;',
  10211. ' attribute vec3 morphTarget6;',
  10212. ' attribute vec3 morphTarget7;',
  10213. ' #endif',
  10214. '#endif',
  10215. '#ifdef USE_SKINNING',
  10216. ' attribute vec4 skinIndex;',
  10217. ' attribute vec4 skinWeight;',
  10218. '#endif',
  10219. '\n'
  10220. ].filter( filterEmptyLine ).join( '\n' );
  10221. prefixFragment = [
  10222. customExtensions,
  10223. 'precision ' + parameters.precision + ' float;',
  10224. 'precision ' + parameters.precision + ' int;',
  10225. '#define SHADER_NAME ' + shader.name,
  10226. customDefines,
  10227. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10228. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10229. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10230. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10231. parameters.map ? '#define USE_MAP' : '',
  10232. parameters.matcap ? '#define USE_MATCAP' : '',
  10233. parameters.envMap ? '#define USE_ENVMAP' : '',
  10234. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10235. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10236. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10237. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10238. parameters.aoMap ? '#define USE_AOMAP' : '',
  10239. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10240. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10241. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10242. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10243. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10244. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10245. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10246. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10247. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10248. parameters.vertexColors ? '#define USE_COLOR' : '',
  10249. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10250. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10251. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10252. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10253. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10254. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10255. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10256. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10257. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10258. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10259. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10260. 'uniform mat4 viewMatrix;',
  10261. 'uniform vec3 cameraPosition;',
  10262. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10263. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10264. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10265. parameters.dithering ? '#define DITHERING' : '',
  10266. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10267. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10268. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10269. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10270. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10271. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10272. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10273. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10274. '\n'
  10275. ].filter( filterEmptyLine ).join( '\n' );
  10276. }
  10277. vertexShader = parseIncludes( vertexShader );
  10278. vertexShader = replaceLightNums( vertexShader, parameters );
  10279. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10280. fragmentShader = parseIncludes( fragmentShader );
  10281. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10282. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10283. vertexShader = unrollLoops( vertexShader );
  10284. fragmentShader = unrollLoops( fragmentShader );
  10285. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10286. var isGLSL3ShaderMaterial = false;
  10287. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10288. if ( material.isShaderMaterial &&
  10289. vertexShader.match( versionRegex ) !== null &&
  10290. fragmentShader.match( versionRegex ) !== null ) {
  10291. isGLSL3ShaderMaterial = true;
  10292. vertexShader = vertexShader.replace( versionRegex, '' );
  10293. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10294. }
  10295. // GLSL 3.0 conversion
  10296. prefixVertex = [
  10297. '#version 300 es\n',
  10298. '#define attribute in',
  10299. '#define varying out',
  10300. '#define texture2D texture'
  10301. ].join( '\n' ) + '\n' + prefixVertex;
  10302. prefixFragment = [
  10303. '#version 300 es\n',
  10304. '#define varying in',
  10305. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10306. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10307. '#define gl_FragDepthEXT gl_FragDepth',
  10308. '#define texture2D texture',
  10309. '#define textureCube texture',
  10310. '#define texture2DProj textureProj',
  10311. '#define texture2DLodEXT textureLod',
  10312. '#define texture2DProjLodEXT textureProjLod',
  10313. '#define textureCubeLodEXT textureLod',
  10314. '#define texture2DGradEXT textureGrad',
  10315. '#define texture2DProjGradEXT textureProjGrad',
  10316. '#define textureCubeGradEXT textureGrad'
  10317. ].join( '\n' ) + '\n' + prefixFragment;
  10318. }
  10319. var vertexGlsl = prefixVertex + vertexShader;
  10320. var fragmentGlsl = prefixFragment + fragmentShader;
  10321. // console.log( '*VERTEX*', vertexGlsl );
  10322. // console.log( '*FRAGMENT*', fragmentGlsl );
  10323. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10324. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10325. gl.attachShader( program, glVertexShader );
  10326. gl.attachShader( program, glFragmentShader );
  10327. // Force a particular attribute to index 0.
  10328. if ( material.index0AttributeName !== undefined ) {
  10329. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10330. } else if ( parameters.morphTargets === true ) {
  10331. // programs with morphTargets displace position out of attribute 0
  10332. gl.bindAttribLocation( program, 0, 'position' );
  10333. }
  10334. gl.linkProgram( program );
  10335. var programLog = gl.getProgramInfoLog( program ).trim();
  10336. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10337. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10338. var runnable = true;
  10339. var haveDiagnostics = true;
  10340. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10341. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10342. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10343. runnable = false;
  10344. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10345. } else if ( programLog !== '' ) {
  10346. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10347. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10348. haveDiagnostics = false;
  10349. }
  10350. if ( haveDiagnostics ) {
  10351. this.diagnostics = {
  10352. runnable: runnable,
  10353. material: material,
  10354. programLog: programLog,
  10355. vertexShader: {
  10356. log: vertexLog,
  10357. prefix: prefixVertex
  10358. },
  10359. fragmentShader: {
  10360. log: fragmentLog,
  10361. prefix: prefixFragment
  10362. }
  10363. };
  10364. }
  10365. // clean up
  10366. gl.deleteShader( glVertexShader );
  10367. gl.deleteShader( glFragmentShader );
  10368. // set up caching for uniform locations
  10369. var cachedUniforms;
  10370. this.getUniforms = function () {
  10371. if ( cachedUniforms === undefined ) {
  10372. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  10373. }
  10374. return cachedUniforms;
  10375. };
  10376. // set up caching for attribute locations
  10377. var cachedAttributes;
  10378. this.getAttributes = function () {
  10379. if ( cachedAttributes === undefined ) {
  10380. cachedAttributes = fetchAttributeLocations( gl, program );
  10381. }
  10382. return cachedAttributes;
  10383. };
  10384. // free resource
  10385. this.destroy = function () {
  10386. gl.deleteProgram( program );
  10387. this.program = undefined;
  10388. };
  10389. // DEPRECATED
  10390. Object.defineProperties( this, {
  10391. uniforms: {
  10392. get: function () {
  10393. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10394. return this.getUniforms();
  10395. }
  10396. },
  10397. attributes: {
  10398. get: function () {
  10399. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10400. return this.getAttributes();
  10401. }
  10402. }
  10403. } );
  10404. //
  10405. this.name = shader.name;
  10406. this.id = programIdCount ++;
  10407. this.code = code;
  10408. this.usedTimes = 1;
  10409. this.program = program;
  10410. this.vertexShader = glVertexShader;
  10411. this.fragmentShader = glFragmentShader;
  10412. return this;
  10413. }
  10414. /**
  10415. * @author mrdoob / http://mrdoob.com/
  10416. */
  10417. function WebGLPrograms( renderer, extensions, capabilities ) {
  10418. var programs = [];
  10419. var shaderIDs = {
  10420. MeshDepthMaterial: 'depth',
  10421. MeshDistanceMaterial: 'distanceRGBA',
  10422. MeshNormalMaterial: 'normal',
  10423. MeshBasicMaterial: 'basic',
  10424. MeshLambertMaterial: 'lambert',
  10425. MeshPhongMaterial: 'phong',
  10426. MeshToonMaterial: 'phong',
  10427. MeshStandardMaterial: 'physical',
  10428. MeshPhysicalMaterial: 'physical',
  10429. MeshMatcapMaterial: 'matcap',
  10430. LineBasicMaterial: 'basic',
  10431. LineDashedMaterial: 'dashed',
  10432. PointsMaterial: 'points',
  10433. ShadowMaterial: 'shadow',
  10434. SpriteMaterial: 'sprite'
  10435. };
  10436. var parameterNames = [
  10437. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10438. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10439. "roughnessMap", "metalnessMap", "gradientMap",
  10440. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10441. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10442. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10443. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10444. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10445. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10446. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10447. ];
  10448. function allocateBones( object ) {
  10449. var skeleton = object.skeleton;
  10450. var bones = skeleton.bones;
  10451. if ( capabilities.floatVertexTextures ) {
  10452. return 1024;
  10453. } else {
  10454. // default for when object is not specified
  10455. // ( for example when prebuilding shader to be used with multiple objects )
  10456. //
  10457. // - leave some extra space for other uniforms
  10458. // - limit here is ANGLE's 254 max uniform vectors
  10459. // (up to 54 should be safe)
  10460. var nVertexUniforms = capabilities.maxVertexUniforms;
  10461. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10462. var maxBones = Math.min( nVertexMatrices, bones.length );
  10463. if ( maxBones < bones.length ) {
  10464. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10465. return 0;
  10466. }
  10467. return maxBones;
  10468. }
  10469. }
  10470. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10471. var encoding;
  10472. if ( ! map ) {
  10473. encoding = LinearEncoding;
  10474. } else if ( map.isTexture ) {
  10475. encoding = map.encoding;
  10476. } else if ( map.isWebGLRenderTarget ) {
  10477. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10478. encoding = map.texture.encoding;
  10479. }
  10480. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10481. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10482. encoding = GammaEncoding;
  10483. }
  10484. return encoding;
  10485. }
  10486. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10487. var shaderID = shaderIDs[ material.type ];
  10488. // heuristics to create shader parameters according to lights in the scene
  10489. // (not to blow over maxLights budget)
  10490. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10491. var precision = capabilities.precision;
  10492. if ( material.precision !== null ) {
  10493. precision = capabilities.getMaxPrecision( material.precision );
  10494. if ( precision !== material.precision ) {
  10495. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10496. }
  10497. }
  10498. var currentRenderTarget = renderer.getRenderTarget();
  10499. var parameters = {
  10500. shaderID: shaderID,
  10501. precision: precision,
  10502. supportsVertexTextures: capabilities.vertexTextures,
  10503. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10504. map: !! material.map,
  10505. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10506. matcap: !! material.matcap,
  10507. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10508. envMap: !! material.envMap,
  10509. envMapMode: material.envMap && material.envMap.mapping,
  10510. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10511. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10512. lightMap: !! material.lightMap,
  10513. aoMap: !! material.aoMap,
  10514. emissiveMap: !! material.emissiveMap,
  10515. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10516. bumpMap: !! material.bumpMap,
  10517. normalMap: !! material.normalMap,
  10518. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10519. displacementMap: !! material.displacementMap,
  10520. roughnessMap: !! material.roughnessMap,
  10521. metalnessMap: !! material.metalnessMap,
  10522. specularMap: !! material.specularMap,
  10523. alphaMap: !! material.alphaMap,
  10524. gradientMap: !! material.gradientMap,
  10525. combine: material.combine,
  10526. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10527. vertexColors: material.vertexColors,
  10528. fog: !! fog,
  10529. useFog: material.fog,
  10530. fogExp: ( fog && fog.isFogExp2 ),
  10531. flatShading: material.flatShading,
  10532. sizeAttenuation: material.sizeAttenuation,
  10533. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10534. skinning: material.skinning && maxBones > 0,
  10535. maxBones: maxBones,
  10536. useVertexTexture: capabilities.floatVertexTextures,
  10537. morphTargets: material.morphTargets,
  10538. morphNormals: material.morphNormals,
  10539. maxMorphTargets: renderer.maxMorphTargets,
  10540. maxMorphNormals: renderer.maxMorphNormals,
  10541. numDirLights: lights.directional.length,
  10542. numPointLights: lights.point.length,
  10543. numSpotLights: lights.spot.length,
  10544. numRectAreaLights: lights.rectArea.length,
  10545. numHemiLights: lights.hemi.length,
  10546. numClippingPlanes: nClipPlanes,
  10547. numClipIntersection: nClipIntersection,
  10548. dithering: material.dithering,
  10549. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10550. shadowMapType: renderer.shadowMap.type,
  10551. toneMapping: renderer.toneMapping,
  10552. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10553. premultipliedAlpha: material.premultipliedAlpha,
  10554. alphaTest: material.alphaTest,
  10555. doubleSided: material.side === DoubleSide,
  10556. flipSided: material.side === BackSide,
  10557. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10558. };
  10559. return parameters;
  10560. };
  10561. this.getProgramCode = function ( material, parameters ) {
  10562. var array = [];
  10563. if ( parameters.shaderID ) {
  10564. array.push( parameters.shaderID );
  10565. } else {
  10566. array.push( material.fragmentShader );
  10567. array.push( material.vertexShader );
  10568. }
  10569. if ( material.defines !== undefined ) {
  10570. for ( var name in material.defines ) {
  10571. array.push( name );
  10572. array.push( material.defines[ name ] );
  10573. }
  10574. }
  10575. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10576. array.push( parameters[ parameterNames[ i ] ] );
  10577. }
  10578. array.push( material.onBeforeCompile.toString() );
  10579. array.push( renderer.gammaOutput );
  10580. array.push( renderer.gammaFactor );
  10581. return array.join();
  10582. };
  10583. this.acquireProgram = function ( material, shader, parameters, code ) {
  10584. var program;
  10585. // Check if code has been already compiled
  10586. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10587. var programInfo = programs[ p ];
  10588. if ( programInfo.code === code ) {
  10589. program = programInfo;
  10590. ++ program.usedTimes;
  10591. break;
  10592. }
  10593. }
  10594. if ( program === undefined ) {
  10595. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  10596. programs.push( program );
  10597. }
  10598. return program;
  10599. };
  10600. this.releaseProgram = function ( program ) {
  10601. if ( -- program.usedTimes === 0 ) {
  10602. // Remove from unordered set
  10603. var i = programs.indexOf( program );
  10604. programs[ i ] = programs[ programs.length - 1 ];
  10605. programs.pop();
  10606. // Free WebGL resources
  10607. program.destroy();
  10608. }
  10609. };
  10610. // Exposed for resource monitoring & error feedback via renderer.info:
  10611. this.programs = programs;
  10612. }
  10613. /**
  10614. * @author fordacious / fordacious.github.io
  10615. */
  10616. function WebGLProperties() {
  10617. var properties = new WeakMap();
  10618. function get( object ) {
  10619. var map = properties.get( object );
  10620. if ( map === undefined ) {
  10621. map = {};
  10622. properties.set( object, map );
  10623. }
  10624. return map;
  10625. }
  10626. function remove( object ) {
  10627. properties.delete( object );
  10628. }
  10629. function update( object, key, value ) {
  10630. properties.get( object )[ key ] = value;
  10631. }
  10632. function dispose() {
  10633. properties = new WeakMap();
  10634. }
  10635. return {
  10636. get: get,
  10637. remove: remove,
  10638. update: update,
  10639. dispose: dispose
  10640. };
  10641. }
  10642. /**
  10643. * @author mrdoob / http://mrdoob.com/
  10644. */
  10645. function painterSortStable( a, b ) {
  10646. if ( a.groupOrder !== b.groupOrder ) {
  10647. return a.groupOrder - b.groupOrder;
  10648. } else if ( a.renderOrder !== b.renderOrder ) {
  10649. return a.renderOrder - b.renderOrder;
  10650. } else if ( a.program && b.program && a.program !== b.program ) {
  10651. return a.program.id - b.program.id;
  10652. } else if ( a.material.id !== b.material.id ) {
  10653. return a.material.id - b.material.id;
  10654. } else if ( a.z !== b.z ) {
  10655. return a.z - b.z;
  10656. } else {
  10657. return a.id - b.id;
  10658. }
  10659. }
  10660. function reversePainterSortStable( a, b ) {
  10661. if ( a.groupOrder !== b.groupOrder ) {
  10662. return a.groupOrder - b.groupOrder;
  10663. } else if ( a.renderOrder !== b.renderOrder ) {
  10664. return a.renderOrder - b.renderOrder;
  10665. } else if ( a.z !== b.z ) {
  10666. return b.z - a.z;
  10667. } else {
  10668. return a.id - b.id;
  10669. }
  10670. }
  10671. function WebGLRenderList() {
  10672. var renderItems = [];
  10673. var renderItemsIndex = 0;
  10674. var opaque = [];
  10675. var transparent = [];
  10676. function init() {
  10677. renderItemsIndex = 0;
  10678. opaque.length = 0;
  10679. transparent.length = 0;
  10680. }
  10681. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10682. var renderItem = renderItems[ renderItemsIndex ];
  10683. if ( renderItem === undefined ) {
  10684. renderItem = {
  10685. id: object.id,
  10686. object: object,
  10687. geometry: geometry,
  10688. material: material,
  10689. program: material.program,
  10690. groupOrder: groupOrder,
  10691. renderOrder: object.renderOrder,
  10692. z: z,
  10693. group: group
  10694. };
  10695. renderItems[ renderItemsIndex ] = renderItem;
  10696. } else {
  10697. renderItem.id = object.id;
  10698. renderItem.object = object;
  10699. renderItem.geometry = geometry;
  10700. renderItem.material = material;
  10701. renderItem.program = material.program;
  10702. renderItem.groupOrder = groupOrder;
  10703. renderItem.renderOrder = object.renderOrder;
  10704. renderItem.z = z;
  10705. renderItem.group = group;
  10706. }
  10707. renderItemsIndex ++;
  10708. return renderItem;
  10709. }
  10710. function push( object, geometry, material, groupOrder, z, group ) {
  10711. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10712. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10713. }
  10714. function unshift( object, geometry, material, groupOrder, z, group ) {
  10715. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10716. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10717. }
  10718. function sort() {
  10719. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10720. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10721. }
  10722. return {
  10723. opaque: opaque,
  10724. transparent: transparent,
  10725. init: init,
  10726. push: push,
  10727. unshift: unshift,
  10728. sort: sort
  10729. };
  10730. }
  10731. function WebGLRenderLists() {
  10732. var lists = {};
  10733. function onSceneDispose( event ) {
  10734. var scene = event.target;
  10735. scene.removeEventListener( 'dispose', onSceneDispose );
  10736. delete lists[ scene.id ];
  10737. }
  10738. function get( scene, camera ) {
  10739. var cameras = lists[ scene.id ];
  10740. var list;
  10741. if ( cameras === undefined ) {
  10742. list = new WebGLRenderList();
  10743. lists[ scene.id ] = {};
  10744. lists[ scene.id ][ camera.id ] = list;
  10745. scene.addEventListener( 'dispose', onSceneDispose );
  10746. } else {
  10747. list = cameras[ camera.id ];
  10748. if ( list === undefined ) {
  10749. list = new WebGLRenderList();
  10750. cameras[ camera.id ] = list;
  10751. }
  10752. }
  10753. return list;
  10754. }
  10755. function dispose() {
  10756. lists = {};
  10757. }
  10758. return {
  10759. get: get,
  10760. dispose: dispose
  10761. };
  10762. }
  10763. /**
  10764. * @author mrdoob / http://mrdoob.com/
  10765. */
  10766. function UniformsCache() {
  10767. var lights = {};
  10768. return {
  10769. get: function ( light ) {
  10770. if ( lights[ light.id ] !== undefined ) {
  10771. return lights[ light.id ];
  10772. }
  10773. var uniforms;
  10774. switch ( light.type ) {
  10775. case 'DirectionalLight':
  10776. uniforms = {
  10777. direction: new Vector3(),
  10778. color: new Color(),
  10779. shadow: false,
  10780. shadowBias: 0,
  10781. shadowRadius: 1,
  10782. shadowMapSize: new Vector2()
  10783. };
  10784. break;
  10785. case 'SpotLight':
  10786. uniforms = {
  10787. position: new Vector3(),
  10788. direction: new Vector3(),
  10789. color: new Color(),
  10790. distance: 0,
  10791. coneCos: 0,
  10792. penumbraCos: 0,
  10793. decay: 0,
  10794. shadow: false,
  10795. shadowBias: 0,
  10796. shadowRadius: 1,
  10797. shadowMapSize: new Vector2()
  10798. };
  10799. break;
  10800. case 'PointLight':
  10801. uniforms = {
  10802. position: new Vector3(),
  10803. color: new Color(),
  10804. distance: 0,
  10805. decay: 0,
  10806. shadow: false,
  10807. shadowBias: 0,
  10808. shadowRadius: 1,
  10809. shadowMapSize: new Vector2(),
  10810. shadowCameraNear: 1,
  10811. shadowCameraFar: 1000
  10812. };
  10813. break;
  10814. case 'HemisphereLight':
  10815. uniforms = {
  10816. direction: new Vector3(),
  10817. skyColor: new Color(),
  10818. groundColor: new Color()
  10819. };
  10820. break;
  10821. case 'RectAreaLight':
  10822. uniforms = {
  10823. color: new Color(),
  10824. position: new Vector3(),
  10825. halfWidth: new Vector3(),
  10826. halfHeight: new Vector3()
  10827. // TODO (abelnation): set RectAreaLight shadow uniforms
  10828. };
  10829. break;
  10830. }
  10831. lights[ light.id ] = uniforms;
  10832. return uniforms;
  10833. }
  10834. };
  10835. }
  10836. var count = 0;
  10837. function WebGLLights() {
  10838. var cache = new UniformsCache();
  10839. var state = {
  10840. id: count ++,
  10841. hash: {
  10842. stateID: - 1,
  10843. directionalLength: - 1,
  10844. pointLength: - 1,
  10845. spotLength: - 1,
  10846. rectAreaLength: - 1,
  10847. hemiLength: - 1,
  10848. shadowsLength: - 1
  10849. },
  10850. ambient: [ 0, 0, 0 ],
  10851. directional: [],
  10852. directionalShadowMap: [],
  10853. directionalShadowMatrix: [],
  10854. spot: [],
  10855. spotShadowMap: [],
  10856. spotShadowMatrix: [],
  10857. rectArea: [],
  10858. point: [],
  10859. pointShadowMap: [],
  10860. pointShadowMatrix: [],
  10861. hemi: []
  10862. };
  10863. var vector3 = new Vector3();
  10864. var matrix4 = new Matrix4();
  10865. var matrix42 = new Matrix4();
  10866. function setup( lights, shadows, camera ) {
  10867. var r = 0, g = 0, b = 0;
  10868. var directionalLength = 0;
  10869. var pointLength = 0;
  10870. var spotLength = 0;
  10871. var rectAreaLength = 0;
  10872. var hemiLength = 0;
  10873. var viewMatrix = camera.matrixWorldInverse;
  10874. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10875. var light = lights[ i ];
  10876. var color = light.color;
  10877. var intensity = light.intensity;
  10878. var distance = light.distance;
  10879. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10880. if ( light.isAmbientLight ) {
  10881. r += color.r * intensity;
  10882. g += color.g * intensity;
  10883. b += color.b * intensity;
  10884. } else if ( light.isDirectionalLight ) {
  10885. var uniforms = cache.get( light );
  10886. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10887. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10888. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10889. uniforms.direction.sub( vector3 );
  10890. uniforms.direction.transformDirection( viewMatrix );
  10891. uniforms.shadow = light.castShadow;
  10892. if ( light.castShadow ) {
  10893. var shadow = light.shadow;
  10894. uniforms.shadowBias = shadow.bias;
  10895. uniforms.shadowRadius = shadow.radius;
  10896. uniforms.shadowMapSize = shadow.mapSize;
  10897. }
  10898. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10899. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10900. state.directional[ directionalLength ] = uniforms;
  10901. directionalLength ++;
  10902. } else if ( light.isSpotLight ) {
  10903. var uniforms = cache.get( light );
  10904. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10905. uniforms.position.applyMatrix4( viewMatrix );
  10906. uniforms.color.copy( color ).multiplyScalar( intensity );
  10907. uniforms.distance = distance;
  10908. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10909. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10910. uniforms.direction.sub( vector3 );
  10911. uniforms.direction.transformDirection( viewMatrix );
  10912. uniforms.coneCos = Math.cos( light.angle );
  10913. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10914. uniforms.decay = light.decay;
  10915. uniforms.shadow = light.castShadow;
  10916. if ( light.castShadow ) {
  10917. var shadow = light.shadow;
  10918. uniforms.shadowBias = shadow.bias;
  10919. uniforms.shadowRadius = shadow.radius;
  10920. uniforms.shadowMapSize = shadow.mapSize;
  10921. }
  10922. state.spotShadowMap[ spotLength ] = shadowMap;
  10923. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10924. state.spot[ spotLength ] = uniforms;
  10925. spotLength ++;
  10926. } else if ( light.isRectAreaLight ) {
  10927. var uniforms = cache.get( light );
  10928. // (a) intensity is the total visible light emitted
  10929. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10930. // (b) intensity is the brightness of the light
  10931. uniforms.color.copy( color ).multiplyScalar( intensity );
  10932. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10933. uniforms.position.applyMatrix4( viewMatrix );
  10934. // extract local rotation of light to derive width/height half vectors
  10935. matrix42.identity();
  10936. matrix4.copy( light.matrixWorld );
  10937. matrix4.premultiply( viewMatrix );
  10938. matrix42.extractRotation( matrix4 );
  10939. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  10940. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  10941. uniforms.halfWidth.applyMatrix4( matrix42 );
  10942. uniforms.halfHeight.applyMatrix4( matrix42 );
  10943. // TODO (abelnation): RectAreaLight distance?
  10944. // uniforms.distance = distance;
  10945. state.rectArea[ rectAreaLength ] = uniforms;
  10946. rectAreaLength ++;
  10947. } else if ( light.isPointLight ) {
  10948. var uniforms = cache.get( light );
  10949. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10950. uniforms.position.applyMatrix4( viewMatrix );
  10951. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10952. uniforms.distance = light.distance;
  10953. uniforms.decay = light.decay;
  10954. uniforms.shadow = light.castShadow;
  10955. if ( light.castShadow ) {
  10956. var shadow = light.shadow;
  10957. uniforms.shadowBias = shadow.bias;
  10958. uniforms.shadowRadius = shadow.radius;
  10959. uniforms.shadowMapSize = shadow.mapSize;
  10960. uniforms.shadowCameraNear = shadow.camera.near;
  10961. uniforms.shadowCameraFar = shadow.camera.far;
  10962. }
  10963. state.pointShadowMap[ pointLength ] = shadowMap;
  10964. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  10965. state.point[ pointLength ] = uniforms;
  10966. pointLength ++;
  10967. } else if ( light.isHemisphereLight ) {
  10968. var uniforms = cache.get( light );
  10969. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10970. uniforms.direction.transformDirection( viewMatrix );
  10971. uniforms.direction.normalize();
  10972. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  10973. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  10974. state.hemi[ hemiLength ] = uniforms;
  10975. hemiLength ++;
  10976. }
  10977. }
  10978. state.ambient[ 0 ] = r;
  10979. state.ambient[ 1 ] = g;
  10980. state.ambient[ 2 ] = b;
  10981. state.directional.length = directionalLength;
  10982. state.spot.length = spotLength;
  10983. state.rectArea.length = rectAreaLength;
  10984. state.point.length = pointLength;
  10985. state.hemi.length = hemiLength;
  10986. state.hash.stateID = state.id;
  10987. state.hash.directionalLength = directionalLength;
  10988. state.hash.pointLength = pointLength;
  10989. state.hash.spotLength = spotLength;
  10990. state.hash.rectAreaLength = rectAreaLength;
  10991. state.hash.hemiLength = hemiLength;
  10992. state.hash.shadowsLength = shadows.length;
  10993. }
  10994. return {
  10995. setup: setup,
  10996. state: state
  10997. };
  10998. }
  10999. /**
  11000. * @author Mugen87 / https://github.com/Mugen87
  11001. */
  11002. function WebGLRenderState() {
  11003. var lights = new WebGLLights();
  11004. var lightsArray = [];
  11005. var shadowsArray = [];
  11006. function init() {
  11007. lightsArray.length = 0;
  11008. shadowsArray.length = 0;
  11009. }
  11010. function pushLight( light ) {
  11011. lightsArray.push( light );
  11012. }
  11013. function pushShadow( shadowLight ) {
  11014. shadowsArray.push( shadowLight );
  11015. }
  11016. function setupLights( camera ) {
  11017. lights.setup( lightsArray, shadowsArray, camera );
  11018. }
  11019. var state = {
  11020. lightsArray: lightsArray,
  11021. shadowsArray: shadowsArray,
  11022. lights: lights
  11023. };
  11024. return {
  11025. init: init,
  11026. state: state,
  11027. setupLights: setupLights,
  11028. pushLight: pushLight,
  11029. pushShadow: pushShadow
  11030. };
  11031. }
  11032. function WebGLRenderStates() {
  11033. var renderStates = {};
  11034. function onSceneDispose( event ) {
  11035. var scene = event.target;
  11036. scene.removeEventListener( 'dispose', onSceneDispose );
  11037. delete renderStates[ scene.id ];
  11038. }
  11039. function get( scene, camera ) {
  11040. var renderState;
  11041. if ( renderStates[ scene.id ] === undefined ) {
  11042. renderState = new WebGLRenderState();
  11043. renderStates[ scene.id ] = {};
  11044. renderStates[ scene.id ][ camera.id ] = renderState;
  11045. scene.addEventListener( 'dispose', onSceneDispose );
  11046. } else {
  11047. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11048. renderState = new WebGLRenderState();
  11049. renderStates[ scene.id ][ camera.id ] = renderState;
  11050. } else {
  11051. renderState = renderStates[ scene.id ][ camera.id ];
  11052. }
  11053. }
  11054. return renderState;
  11055. }
  11056. function dispose() {
  11057. renderStates = {};
  11058. }
  11059. return {
  11060. get: get,
  11061. dispose: dispose
  11062. };
  11063. }
  11064. /**
  11065. * @author mrdoob / http://mrdoob.com/
  11066. * @author alteredq / http://alteredqualia.com/
  11067. * @author bhouston / https://clara.io
  11068. * @author WestLangley / http://github.com/WestLangley
  11069. *
  11070. * parameters = {
  11071. *
  11072. * opacity: <float>,
  11073. *
  11074. * map: new THREE.Texture( <Image> ),
  11075. *
  11076. * alphaMap: new THREE.Texture( <Image> ),
  11077. *
  11078. * displacementMap: new THREE.Texture( <Image> ),
  11079. * displacementScale: <float>,
  11080. * displacementBias: <float>,
  11081. *
  11082. * wireframe: <boolean>,
  11083. * wireframeLinewidth: <float>
  11084. * }
  11085. */
  11086. function MeshDepthMaterial( parameters ) {
  11087. Material.call( this );
  11088. this.type = 'MeshDepthMaterial';
  11089. this.depthPacking = BasicDepthPacking;
  11090. this.skinning = false;
  11091. this.morphTargets = false;
  11092. this.map = null;
  11093. this.alphaMap = null;
  11094. this.displacementMap = null;
  11095. this.displacementScale = 1;
  11096. this.displacementBias = 0;
  11097. this.wireframe = false;
  11098. this.wireframeLinewidth = 1;
  11099. this.fog = false;
  11100. this.lights = false;
  11101. this.setValues( parameters );
  11102. }
  11103. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11104. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11105. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11106. MeshDepthMaterial.prototype.copy = function ( source ) {
  11107. Material.prototype.copy.call( this, source );
  11108. this.depthPacking = source.depthPacking;
  11109. this.skinning = source.skinning;
  11110. this.morphTargets = source.morphTargets;
  11111. this.map = source.map;
  11112. this.alphaMap = source.alphaMap;
  11113. this.displacementMap = source.displacementMap;
  11114. this.displacementScale = source.displacementScale;
  11115. this.displacementBias = source.displacementBias;
  11116. this.wireframe = source.wireframe;
  11117. this.wireframeLinewidth = source.wireframeLinewidth;
  11118. return this;
  11119. };
  11120. /**
  11121. * @author WestLangley / http://github.com/WestLangley
  11122. *
  11123. * parameters = {
  11124. *
  11125. * referencePosition: <float>,
  11126. * nearDistance: <float>,
  11127. * farDistance: <float>,
  11128. *
  11129. * skinning: <bool>,
  11130. * morphTargets: <bool>,
  11131. *
  11132. * map: new THREE.Texture( <Image> ),
  11133. *
  11134. * alphaMap: new THREE.Texture( <Image> ),
  11135. *
  11136. * displacementMap: new THREE.Texture( <Image> ),
  11137. * displacementScale: <float>,
  11138. * displacementBias: <float>
  11139. *
  11140. * }
  11141. */
  11142. function MeshDistanceMaterial( parameters ) {
  11143. Material.call( this );
  11144. this.type = 'MeshDistanceMaterial';
  11145. this.referencePosition = new Vector3();
  11146. this.nearDistance = 1;
  11147. this.farDistance = 1000;
  11148. this.skinning = false;
  11149. this.morphTargets = false;
  11150. this.map = null;
  11151. this.alphaMap = null;
  11152. this.displacementMap = null;
  11153. this.displacementScale = 1;
  11154. this.displacementBias = 0;
  11155. this.fog = false;
  11156. this.lights = false;
  11157. this.setValues( parameters );
  11158. }
  11159. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11160. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11161. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11162. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11163. Material.prototype.copy.call( this, source );
  11164. this.referencePosition.copy( source.referencePosition );
  11165. this.nearDistance = source.nearDistance;
  11166. this.farDistance = source.farDistance;
  11167. this.skinning = source.skinning;
  11168. this.morphTargets = source.morphTargets;
  11169. this.map = source.map;
  11170. this.alphaMap = source.alphaMap;
  11171. this.displacementMap = source.displacementMap;
  11172. this.displacementScale = source.displacementScale;
  11173. this.displacementBias = source.displacementBias;
  11174. return this;
  11175. };
  11176. /**
  11177. * @author alteredq / http://alteredqualia.com/
  11178. * @author mrdoob / http://mrdoob.com/
  11179. */
  11180. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11181. var _frustum = new Frustum(),
  11182. _projScreenMatrix = new Matrix4(),
  11183. _shadowMapSize = new Vector2(),
  11184. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11185. _lookTarget = new Vector3(),
  11186. _lightPositionWorld = new Vector3(),
  11187. _MorphingFlag = 1,
  11188. _SkinningFlag = 2,
  11189. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11190. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11191. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11192. _materialCache = {};
  11193. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11194. var cubeDirections = [
  11195. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11196. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11197. ];
  11198. var cubeUps = [
  11199. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11200. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11201. ];
  11202. var cube2DViewPorts = [
  11203. new Vector4(), new Vector4(), new Vector4(),
  11204. new Vector4(), new Vector4(), new Vector4()
  11205. ];
  11206. // init
  11207. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11208. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11209. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11210. var depthMaterial = new MeshDepthMaterial( {
  11211. depthPacking: RGBADepthPacking,
  11212. morphTargets: useMorphing,
  11213. skinning: useSkinning
  11214. } );
  11215. _depthMaterials[ i ] = depthMaterial;
  11216. //
  11217. var distanceMaterial = new MeshDistanceMaterial( {
  11218. morphTargets: useMorphing,
  11219. skinning: useSkinning
  11220. } );
  11221. _distanceMaterials[ i ] = distanceMaterial;
  11222. }
  11223. //
  11224. var scope = this;
  11225. this.enabled = false;
  11226. this.autoUpdate = true;
  11227. this.needsUpdate = false;
  11228. this.type = PCFShadowMap;
  11229. this.render = function ( lights, scene, camera ) {
  11230. if ( scope.enabled === false ) return;
  11231. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11232. if ( lights.length === 0 ) return;
  11233. var currentRenderTarget = _renderer.getRenderTarget();
  11234. var _state = _renderer.state;
  11235. // Set GL state for depth map.
  11236. _state.setBlending( NoBlending );
  11237. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11238. _state.buffers.depth.setTest( true );
  11239. _state.setScissorTest( false );
  11240. // render depth map
  11241. var faceCount;
  11242. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11243. var light = lights[ i ];
  11244. var shadow = light.shadow;
  11245. var isPointLight = light && light.isPointLight;
  11246. if ( shadow === undefined ) {
  11247. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11248. continue;
  11249. }
  11250. var shadowCamera = shadow.camera;
  11251. _shadowMapSize.copy( shadow.mapSize );
  11252. _shadowMapSize.min( _maxShadowMapSize );
  11253. if ( isPointLight ) {
  11254. var vpWidth = _shadowMapSize.x;
  11255. var vpHeight = _shadowMapSize.y;
  11256. // These viewports map a cube-map onto a 2D texture with the
  11257. // following orientation:
  11258. //
  11259. // xzXZ
  11260. // y Y
  11261. //
  11262. // X - Positive x direction
  11263. // x - Negative x direction
  11264. // Y - Positive y direction
  11265. // y - Negative y direction
  11266. // Z - Positive z direction
  11267. // z - Negative z direction
  11268. // positive X
  11269. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11270. // negative X
  11271. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11272. // positive Z
  11273. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11274. // negative Z
  11275. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11276. // positive Y
  11277. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11278. // negative Y
  11279. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11280. _shadowMapSize.x *= 4.0;
  11281. _shadowMapSize.y *= 2.0;
  11282. }
  11283. if ( shadow.map === null ) {
  11284. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11285. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11286. shadow.map.texture.name = light.name + ".shadowMap";
  11287. shadowCamera.updateProjectionMatrix();
  11288. }
  11289. if ( shadow.isSpotLightShadow ) {
  11290. shadow.update( light );
  11291. }
  11292. var shadowMap = shadow.map;
  11293. var shadowMatrix = shadow.matrix;
  11294. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11295. shadowCamera.position.copy( _lightPositionWorld );
  11296. if ( isPointLight ) {
  11297. faceCount = 6;
  11298. // for point lights we set the shadow matrix to be a translation-only matrix
  11299. // equal to inverse of the light's position
  11300. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11301. } else {
  11302. faceCount = 1;
  11303. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11304. shadowCamera.lookAt( _lookTarget );
  11305. shadowCamera.updateMatrixWorld();
  11306. // compute shadow matrix
  11307. shadowMatrix.set(
  11308. 0.5, 0.0, 0.0, 0.5,
  11309. 0.0, 0.5, 0.0, 0.5,
  11310. 0.0, 0.0, 0.5, 0.5,
  11311. 0.0, 0.0, 0.0, 1.0
  11312. );
  11313. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11314. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11315. }
  11316. _renderer.setRenderTarget( shadowMap );
  11317. _renderer.clear();
  11318. // render shadow map for each cube face (if omni-directional) or
  11319. // run a single pass if not
  11320. for ( var face = 0; face < faceCount; face ++ ) {
  11321. if ( isPointLight ) {
  11322. _lookTarget.copy( shadowCamera.position );
  11323. _lookTarget.add( cubeDirections[ face ] );
  11324. shadowCamera.up.copy( cubeUps[ face ] );
  11325. shadowCamera.lookAt( _lookTarget );
  11326. shadowCamera.updateMatrixWorld();
  11327. var vpDimensions = cube2DViewPorts[ face ];
  11328. _state.viewport( vpDimensions );
  11329. }
  11330. // update camera matrices and frustum
  11331. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11332. _frustum.setFromMatrix( _projScreenMatrix );
  11333. // set object matrices & frustum culling
  11334. renderObject( scene, camera, shadowCamera, isPointLight );
  11335. }
  11336. }
  11337. scope.needsUpdate = false;
  11338. _renderer.setRenderTarget( currentRenderTarget );
  11339. };
  11340. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11341. var geometry = object.geometry;
  11342. var result = null;
  11343. var materialVariants = _depthMaterials;
  11344. var customMaterial = object.customDepthMaterial;
  11345. if ( isPointLight ) {
  11346. materialVariants = _distanceMaterials;
  11347. customMaterial = object.customDistanceMaterial;
  11348. }
  11349. if ( ! customMaterial ) {
  11350. var useMorphing = false;
  11351. if ( material.morphTargets ) {
  11352. if ( geometry && geometry.isBufferGeometry ) {
  11353. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11354. } else if ( geometry && geometry.isGeometry ) {
  11355. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11356. }
  11357. }
  11358. if ( object.isSkinnedMesh && material.skinning === false ) {
  11359. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11360. }
  11361. var useSkinning = object.isSkinnedMesh && material.skinning;
  11362. var variantIndex = 0;
  11363. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11364. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11365. result = materialVariants[ variantIndex ];
  11366. } else {
  11367. result = customMaterial;
  11368. }
  11369. if ( _renderer.localClippingEnabled &&
  11370. material.clipShadows === true &&
  11371. material.clippingPlanes.length !== 0 ) {
  11372. // in this case we need a unique material instance reflecting the
  11373. // appropriate state
  11374. var keyA = result.uuid, keyB = material.uuid;
  11375. var materialsForVariant = _materialCache[ keyA ];
  11376. if ( materialsForVariant === undefined ) {
  11377. materialsForVariant = {};
  11378. _materialCache[ keyA ] = materialsForVariant;
  11379. }
  11380. var cachedMaterial = materialsForVariant[ keyB ];
  11381. if ( cachedMaterial === undefined ) {
  11382. cachedMaterial = result.clone();
  11383. materialsForVariant[ keyB ] = cachedMaterial;
  11384. }
  11385. result = cachedMaterial;
  11386. }
  11387. result.visible = material.visible;
  11388. result.wireframe = material.wireframe;
  11389. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11390. result.clipShadows = material.clipShadows;
  11391. result.clippingPlanes = material.clippingPlanes;
  11392. result.clipIntersection = material.clipIntersection;
  11393. result.wireframeLinewidth = material.wireframeLinewidth;
  11394. result.linewidth = material.linewidth;
  11395. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11396. result.referencePosition.copy( lightPositionWorld );
  11397. result.nearDistance = shadowCameraNear;
  11398. result.farDistance = shadowCameraFar;
  11399. }
  11400. return result;
  11401. }
  11402. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11403. if ( object.visible === false ) return;
  11404. var visible = object.layers.test( camera.layers );
  11405. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11406. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11407. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11408. var geometry = _objects.update( object );
  11409. var material = object.material;
  11410. if ( Array.isArray( material ) ) {
  11411. var groups = geometry.groups;
  11412. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11413. var group = groups[ k ];
  11414. var groupMaterial = material[ group.materialIndex ];
  11415. if ( groupMaterial && groupMaterial.visible ) {
  11416. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11417. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11418. }
  11419. }
  11420. } else if ( material.visible ) {
  11421. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11422. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11423. }
  11424. }
  11425. }
  11426. var children = object.children;
  11427. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11428. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11429. }
  11430. }
  11431. }
  11432. /**
  11433. * @author mrdoob / http://mrdoob.com/
  11434. */
  11435. function WebGLState( gl, extensions, utils, capabilities ) {
  11436. function ColorBuffer() {
  11437. var locked = false;
  11438. var color = new Vector4();
  11439. var currentColorMask = null;
  11440. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11441. return {
  11442. setMask: function ( colorMask ) {
  11443. if ( currentColorMask !== colorMask && ! locked ) {
  11444. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11445. currentColorMask = colorMask;
  11446. }
  11447. },
  11448. setLocked: function ( lock ) {
  11449. locked = lock;
  11450. },
  11451. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11452. if ( premultipliedAlpha === true ) {
  11453. r *= a; g *= a; b *= a;
  11454. }
  11455. color.set( r, g, b, a );
  11456. if ( currentColorClear.equals( color ) === false ) {
  11457. gl.clearColor( r, g, b, a );
  11458. currentColorClear.copy( color );
  11459. }
  11460. },
  11461. reset: function () {
  11462. locked = false;
  11463. currentColorMask = null;
  11464. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11465. }
  11466. };
  11467. }
  11468. function DepthBuffer() {
  11469. var locked = false;
  11470. var currentDepthMask = null;
  11471. var currentDepthFunc = null;
  11472. var currentDepthClear = null;
  11473. return {
  11474. setTest: function ( depthTest ) {
  11475. if ( depthTest ) {
  11476. enable( 2929 );
  11477. } else {
  11478. disable( 2929 );
  11479. }
  11480. },
  11481. setMask: function ( depthMask ) {
  11482. if ( currentDepthMask !== depthMask && ! locked ) {
  11483. gl.depthMask( depthMask );
  11484. currentDepthMask = depthMask;
  11485. }
  11486. },
  11487. setFunc: function ( depthFunc ) {
  11488. if ( currentDepthFunc !== depthFunc ) {
  11489. if ( depthFunc ) {
  11490. switch ( depthFunc ) {
  11491. case NeverDepth:
  11492. gl.depthFunc( 512 );
  11493. break;
  11494. case AlwaysDepth:
  11495. gl.depthFunc( 519 );
  11496. break;
  11497. case LessDepth:
  11498. gl.depthFunc( 513 );
  11499. break;
  11500. case LessEqualDepth:
  11501. gl.depthFunc( 515 );
  11502. break;
  11503. case EqualDepth:
  11504. gl.depthFunc( 514 );
  11505. break;
  11506. case GreaterEqualDepth:
  11507. gl.depthFunc( 518 );
  11508. break;
  11509. case GreaterDepth:
  11510. gl.depthFunc( 516 );
  11511. break;
  11512. case NotEqualDepth:
  11513. gl.depthFunc( 517 );
  11514. break;
  11515. default:
  11516. gl.depthFunc( 515 );
  11517. }
  11518. } else {
  11519. gl.depthFunc( 515 );
  11520. }
  11521. currentDepthFunc = depthFunc;
  11522. }
  11523. },
  11524. setLocked: function ( lock ) {
  11525. locked = lock;
  11526. },
  11527. setClear: function ( depth ) {
  11528. if ( currentDepthClear !== depth ) {
  11529. gl.clearDepth( depth );
  11530. currentDepthClear = depth;
  11531. }
  11532. },
  11533. reset: function () {
  11534. locked = false;
  11535. currentDepthMask = null;
  11536. currentDepthFunc = null;
  11537. currentDepthClear = null;
  11538. }
  11539. };
  11540. }
  11541. function StencilBuffer() {
  11542. var locked = false;
  11543. var currentStencilMask = null;
  11544. var currentStencilFunc = null;
  11545. var currentStencilRef = null;
  11546. var currentStencilFuncMask = null;
  11547. var currentStencilFail = null;
  11548. var currentStencilZFail = null;
  11549. var currentStencilZPass = null;
  11550. var currentStencilClear = null;
  11551. return {
  11552. setTest: function ( stencilTest ) {
  11553. if ( stencilTest ) {
  11554. enable( 2960 );
  11555. } else {
  11556. disable( 2960 );
  11557. }
  11558. },
  11559. setMask: function ( stencilMask ) {
  11560. if ( currentStencilMask !== stencilMask && ! locked ) {
  11561. gl.stencilMask( stencilMask );
  11562. currentStencilMask = stencilMask;
  11563. }
  11564. },
  11565. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11566. if ( currentStencilFunc !== stencilFunc ||
  11567. currentStencilRef !== stencilRef ||
  11568. currentStencilFuncMask !== stencilMask ) {
  11569. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11570. currentStencilFunc = stencilFunc;
  11571. currentStencilRef = stencilRef;
  11572. currentStencilFuncMask = stencilMask;
  11573. }
  11574. },
  11575. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11576. if ( currentStencilFail !== stencilFail ||
  11577. currentStencilZFail !== stencilZFail ||
  11578. currentStencilZPass !== stencilZPass ) {
  11579. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11580. currentStencilFail = stencilFail;
  11581. currentStencilZFail = stencilZFail;
  11582. currentStencilZPass = stencilZPass;
  11583. }
  11584. },
  11585. setLocked: function ( lock ) {
  11586. locked = lock;
  11587. },
  11588. setClear: function ( stencil ) {
  11589. if ( currentStencilClear !== stencil ) {
  11590. gl.clearStencil( stencil );
  11591. currentStencilClear = stencil;
  11592. }
  11593. },
  11594. reset: function () {
  11595. locked = false;
  11596. currentStencilMask = null;
  11597. currentStencilFunc = null;
  11598. currentStencilRef = null;
  11599. currentStencilFuncMask = null;
  11600. currentStencilFail = null;
  11601. currentStencilZFail = null;
  11602. currentStencilZPass = null;
  11603. currentStencilClear = null;
  11604. }
  11605. };
  11606. }
  11607. //
  11608. var colorBuffer = new ColorBuffer();
  11609. var depthBuffer = new DepthBuffer();
  11610. var stencilBuffer = new StencilBuffer();
  11611. var maxVertexAttributes = gl.getParameter( 34921 );
  11612. var newAttributes = new Uint8Array( maxVertexAttributes );
  11613. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11614. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11615. var enabledCapabilities = {};
  11616. var compressedTextureFormats = null;
  11617. var currentProgram = null;
  11618. var currentBlendingEnabled = null;
  11619. var currentBlending = null;
  11620. var currentBlendEquation = null;
  11621. var currentBlendSrc = null;
  11622. var currentBlendDst = null;
  11623. var currentBlendEquationAlpha = null;
  11624. var currentBlendSrcAlpha = null;
  11625. var currentBlendDstAlpha = null;
  11626. var currentPremultipledAlpha = false;
  11627. var currentFlipSided = null;
  11628. var currentCullFace = null;
  11629. var currentLineWidth = null;
  11630. var currentPolygonOffsetFactor = null;
  11631. var currentPolygonOffsetUnits = null;
  11632. var maxTextures = gl.getParameter( 35661 );
  11633. var lineWidthAvailable = false;
  11634. var version = 0;
  11635. var glVersion = gl.getParameter( 7938 );
  11636. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11637. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11638. lineWidthAvailable = ( version >= 1.0 );
  11639. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11640. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11641. lineWidthAvailable = ( version >= 2.0 );
  11642. }
  11643. var currentTextureSlot = null;
  11644. var currentBoundTextures = {};
  11645. var currentScissor = new Vector4();
  11646. var currentViewport = new Vector4();
  11647. function createTexture( type, target, count ) {
  11648. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11649. var texture = gl.createTexture();
  11650. gl.bindTexture( type, texture );
  11651. gl.texParameteri( type, 10241, 9728 );
  11652. gl.texParameteri( type, 10240, 9728 );
  11653. for ( var i = 0; i < count; i ++ ) {
  11654. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11655. }
  11656. return texture;
  11657. }
  11658. var emptyTextures = {};
  11659. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11660. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11661. // init
  11662. colorBuffer.setClear( 0, 0, 0, 1 );
  11663. depthBuffer.setClear( 1 );
  11664. stencilBuffer.setClear( 0 );
  11665. enable( 2929 );
  11666. depthBuffer.setFunc( LessEqualDepth );
  11667. setFlipSided( false );
  11668. setCullFace( CullFaceBack );
  11669. enable( 2884 );
  11670. setBlending( NoBlending );
  11671. //
  11672. function initAttributes() {
  11673. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11674. newAttributes[ i ] = 0;
  11675. }
  11676. }
  11677. function enableAttribute( attribute ) {
  11678. enableAttributeAndDivisor( attribute, 0 );
  11679. }
  11680. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11681. newAttributes[ attribute ] = 1;
  11682. if ( enabledAttributes[ attribute ] === 0 ) {
  11683. gl.enableVertexAttribArray( attribute );
  11684. enabledAttributes[ attribute ] = 1;
  11685. }
  11686. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11687. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  11688. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  11689. attributeDivisors[ attribute ] = meshPerAttribute;
  11690. }
  11691. }
  11692. function disableUnusedAttributes() {
  11693. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11694. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11695. gl.disableVertexAttribArray( i );
  11696. enabledAttributes[ i ] = 0;
  11697. }
  11698. }
  11699. }
  11700. function enable( id ) {
  11701. if ( enabledCapabilities[ id ] !== true ) {
  11702. gl.enable( id );
  11703. enabledCapabilities[ id ] = true;
  11704. }
  11705. }
  11706. function disable( id ) {
  11707. if ( enabledCapabilities[ id ] !== false ) {
  11708. gl.disable( id );
  11709. enabledCapabilities[ id ] = false;
  11710. }
  11711. }
  11712. function getCompressedTextureFormats() {
  11713. if ( compressedTextureFormats === null ) {
  11714. compressedTextureFormats = [];
  11715. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11716. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11717. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11718. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11719. var formats = gl.getParameter( 34467 );
  11720. for ( var i = 0; i < formats.length; i ++ ) {
  11721. compressedTextureFormats.push( formats[ i ] );
  11722. }
  11723. }
  11724. }
  11725. return compressedTextureFormats;
  11726. }
  11727. function useProgram( program ) {
  11728. if ( currentProgram !== program ) {
  11729. gl.useProgram( program );
  11730. currentProgram = program;
  11731. return true;
  11732. }
  11733. return false;
  11734. }
  11735. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11736. if ( blending === NoBlending ) {
  11737. if ( currentBlendingEnabled ) {
  11738. disable( 3042 );
  11739. currentBlendingEnabled = false;
  11740. }
  11741. return;
  11742. }
  11743. if ( ! currentBlendingEnabled ) {
  11744. enable( 3042 );
  11745. currentBlendingEnabled = true;
  11746. }
  11747. if ( blending !== CustomBlending ) {
  11748. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11749. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11750. gl.blendEquation( 32774 );
  11751. currentBlendEquation = AddEquation;
  11752. currentBlendEquationAlpha = AddEquation;
  11753. }
  11754. if ( premultipliedAlpha ) {
  11755. switch ( blending ) {
  11756. case NormalBlending:
  11757. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11758. break;
  11759. case AdditiveBlending:
  11760. gl.blendFunc( 1, 1 );
  11761. break;
  11762. case SubtractiveBlending:
  11763. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11764. break;
  11765. case MultiplyBlending:
  11766. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11767. break;
  11768. default:
  11769. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11770. break;
  11771. }
  11772. } else {
  11773. switch ( blending ) {
  11774. case NormalBlending:
  11775. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11776. break;
  11777. case AdditiveBlending:
  11778. gl.blendFunc( 770, 1 );
  11779. break;
  11780. case SubtractiveBlending:
  11781. gl.blendFunc( 0, 769 );
  11782. break;
  11783. case MultiplyBlending:
  11784. gl.blendFunc( 0, 768 );
  11785. break;
  11786. default:
  11787. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11788. break;
  11789. }
  11790. }
  11791. currentBlendSrc = null;
  11792. currentBlendDst = null;
  11793. currentBlendSrcAlpha = null;
  11794. currentBlendDstAlpha = null;
  11795. currentBlending = blending;
  11796. currentPremultipledAlpha = premultipliedAlpha;
  11797. }
  11798. return;
  11799. }
  11800. // custom blending
  11801. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11802. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11803. blendDstAlpha = blendDstAlpha || blendDst;
  11804. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11805. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11806. currentBlendEquation = blendEquation;
  11807. currentBlendEquationAlpha = blendEquationAlpha;
  11808. }
  11809. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11810. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11811. currentBlendSrc = blendSrc;
  11812. currentBlendDst = blendDst;
  11813. currentBlendSrcAlpha = blendSrcAlpha;
  11814. currentBlendDstAlpha = blendDstAlpha;
  11815. }
  11816. currentBlending = blending;
  11817. currentPremultipledAlpha = null;
  11818. }
  11819. function setMaterial( material, frontFaceCW ) {
  11820. material.side === DoubleSide
  11821. ? disable( 2884 )
  11822. : enable( 2884 );
  11823. var flipSided = ( material.side === BackSide );
  11824. if ( frontFaceCW ) flipSided = ! flipSided;
  11825. setFlipSided( flipSided );
  11826. ( material.blending === NormalBlending && material.transparent === false )
  11827. ? setBlending( NoBlending )
  11828. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11829. depthBuffer.setFunc( material.depthFunc );
  11830. depthBuffer.setTest( material.depthTest );
  11831. depthBuffer.setMask( material.depthWrite );
  11832. colorBuffer.setMask( material.colorWrite );
  11833. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11834. }
  11835. //
  11836. function setFlipSided( flipSided ) {
  11837. if ( currentFlipSided !== flipSided ) {
  11838. if ( flipSided ) {
  11839. gl.frontFace( 2304 );
  11840. } else {
  11841. gl.frontFace( 2305 );
  11842. }
  11843. currentFlipSided = flipSided;
  11844. }
  11845. }
  11846. function setCullFace( cullFace ) {
  11847. if ( cullFace !== CullFaceNone ) {
  11848. enable( 2884 );
  11849. if ( cullFace !== currentCullFace ) {
  11850. if ( cullFace === CullFaceBack ) {
  11851. gl.cullFace( 1029 );
  11852. } else if ( cullFace === CullFaceFront ) {
  11853. gl.cullFace( 1028 );
  11854. } else {
  11855. gl.cullFace( 1032 );
  11856. }
  11857. }
  11858. } else {
  11859. disable( 2884 );
  11860. }
  11861. currentCullFace = cullFace;
  11862. }
  11863. function setLineWidth( width ) {
  11864. if ( width !== currentLineWidth ) {
  11865. if ( lineWidthAvailable ) gl.lineWidth( width );
  11866. currentLineWidth = width;
  11867. }
  11868. }
  11869. function setPolygonOffset( polygonOffset, factor, units ) {
  11870. if ( polygonOffset ) {
  11871. enable( 32823 );
  11872. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11873. gl.polygonOffset( factor, units );
  11874. currentPolygonOffsetFactor = factor;
  11875. currentPolygonOffsetUnits = units;
  11876. }
  11877. } else {
  11878. disable( 32823 );
  11879. }
  11880. }
  11881. function setScissorTest( scissorTest ) {
  11882. if ( scissorTest ) {
  11883. enable( 3089 );
  11884. } else {
  11885. disable( 3089 );
  11886. }
  11887. }
  11888. // texture
  11889. function activeTexture( webglSlot ) {
  11890. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11891. if ( currentTextureSlot !== webglSlot ) {
  11892. gl.activeTexture( webglSlot );
  11893. currentTextureSlot = webglSlot;
  11894. }
  11895. }
  11896. function bindTexture( webglType, webglTexture ) {
  11897. if ( currentTextureSlot === null ) {
  11898. activeTexture();
  11899. }
  11900. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11901. if ( boundTexture === undefined ) {
  11902. boundTexture = { type: undefined, texture: undefined };
  11903. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11904. }
  11905. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11906. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11907. boundTexture.type = webglType;
  11908. boundTexture.texture = webglTexture;
  11909. }
  11910. }
  11911. function compressedTexImage2D() {
  11912. try {
  11913. gl.compressedTexImage2D.apply( gl, arguments );
  11914. } catch ( error ) {
  11915. console.error( 'THREE.WebGLState:', error );
  11916. }
  11917. }
  11918. function texImage2D() {
  11919. try {
  11920. gl.texImage2D.apply( gl, arguments );
  11921. } catch ( error ) {
  11922. console.error( 'THREE.WebGLState:', error );
  11923. }
  11924. }
  11925. function texImage3D() {
  11926. try {
  11927. gl.texImage3D.apply( gl, arguments );
  11928. } catch ( error ) {
  11929. console.error( 'THREE.WebGLState:', error );
  11930. }
  11931. }
  11932. //
  11933. function scissor( scissor ) {
  11934. if ( currentScissor.equals( scissor ) === false ) {
  11935. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11936. currentScissor.copy( scissor );
  11937. }
  11938. }
  11939. function viewport( viewport ) {
  11940. if ( currentViewport.equals( viewport ) === false ) {
  11941. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11942. currentViewport.copy( viewport );
  11943. }
  11944. }
  11945. //
  11946. function reset() {
  11947. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11948. if ( enabledAttributes[ i ] === 1 ) {
  11949. gl.disableVertexAttribArray( i );
  11950. enabledAttributes[ i ] = 0;
  11951. }
  11952. }
  11953. enabledCapabilities = {};
  11954. compressedTextureFormats = null;
  11955. currentTextureSlot = null;
  11956. currentBoundTextures = {};
  11957. currentProgram = null;
  11958. currentBlending = null;
  11959. currentFlipSided = null;
  11960. currentCullFace = null;
  11961. colorBuffer.reset();
  11962. depthBuffer.reset();
  11963. stencilBuffer.reset();
  11964. }
  11965. return {
  11966. buffers: {
  11967. color: colorBuffer,
  11968. depth: depthBuffer,
  11969. stencil: stencilBuffer
  11970. },
  11971. initAttributes: initAttributes,
  11972. enableAttribute: enableAttribute,
  11973. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11974. disableUnusedAttributes: disableUnusedAttributes,
  11975. enable: enable,
  11976. disable: disable,
  11977. getCompressedTextureFormats: getCompressedTextureFormats,
  11978. useProgram: useProgram,
  11979. setBlending: setBlending,
  11980. setMaterial: setMaterial,
  11981. setFlipSided: setFlipSided,
  11982. setCullFace: setCullFace,
  11983. setLineWidth: setLineWidth,
  11984. setPolygonOffset: setPolygonOffset,
  11985. setScissorTest: setScissorTest,
  11986. activeTexture: activeTexture,
  11987. bindTexture: bindTexture,
  11988. compressedTexImage2D: compressedTexImage2D,
  11989. texImage2D: texImage2D,
  11990. texImage3D: texImage3D,
  11991. scissor: scissor,
  11992. viewport: viewport,
  11993. reset: reset
  11994. };
  11995. }
  11996. /**
  11997. * @author mrdoob / http://mrdoob.com/
  11998. */
  11999. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12000. var _videoTextures = {};
  12001. var _canvas;
  12002. //
  12003. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12004. function createCanvas( width, height ) {
  12005. // Use OffscreenCanvas when available. Specially needed in web workers
  12006. return useOffscreenCanvas ?
  12007. new OffscreenCanvas( width, height ) :
  12008. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12009. }
  12010. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12011. var scale = 1;
  12012. // handle case if texture exceeds max size
  12013. if ( image.width > maxSize || image.height > maxSize ) {
  12014. scale = maxSize / Math.max( image.width, image.height );
  12015. }
  12016. // only perform resize if necessary
  12017. if ( scale < 1 || needsPowerOfTwo === true ) {
  12018. // only perform resize for certain image types
  12019. if ( image instanceof ImageBitmap || image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  12020. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12021. var width = floor( scale * image.width );
  12022. var height = floor( scale * image.height );
  12023. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12024. // cube textures can't reuse the same canvas
  12025. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12026. canvas.width = width;
  12027. canvas.height = height;
  12028. var context = canvas.getContext( '2d' );
  12029. context.drawImage( image, 0, 0, width, height );
  12030. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12031. return useOffscreenCanvas ? canvas.transferToImageBitmap() : canvas;
  12032. } else {
  12033. if ( 'data' in image ) {
  12034. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12035. }
  12036. return image;
  12037. }
  12038. }
  12039. return image;
  12040. }
  12041. function isPowerOfTwo( image ) {
  12042. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12043. }
  12044. function textureNeedsPowerOfTwo( texture ) {
  12045. if ( capabilities.isWebGL2 ) return false;
  12046. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12047. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12048. }
  12049. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12050. return texture.generateMipmaps && supportsMips &&
  12051. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12052. }
  12053. function generateMipmap( target, texture, width, height ) {
  12054. _gl.generateMipmap( target );
  12055. var textureProperties = properties.get( texture );
  12056. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12057. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12058. }
  12059. function getInternalFormat( glFormat, glType ) {
  12060. if ( ! capabilities.isWebGL2 ) return glFormat;
  12061. var internalFormat = glFormat;
  12062. if ( glFormat === 6403 ) {
  12063. if ( glType === 5126 ) internalFormat = 33326;
  12064. if ( glType === 5131 ) internalFormat = 33325;
  12065. if ( glType === 5121 ) internalFormat = 33321;
  12066. }
  12067. if ( glFormat === 6407 ) {
  12068. if ( glType === 5126 ) internalFormat = 34837;
  12069. if ( glType === 5131 ) internalFormat = 34843;
  12070. if ( glType === 5121 ) internalFormat = 32849;
  12071. }
  12072. if ( glFormat === 6408 ) {
  12073. if ( glType === 5126 ) internalFormat = 34836;
  12074. if ( glType === 5131 ) internalFormat = 34842;
  12075. if ( glType === 5121 ) internalFormat = 32856;
  12076. }
  12077. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12078. internalFormat === 34842 || internalFormat === 34836 ) {
  12079. extensions.get( 'EXT_color_buffer_float' );
  12080. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12081. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12082. }
  12083. return internalFormat;
  12084. }
  12085. // Fallback filters for non-power-of-2 textures
  12086. function filterFallback( f ) {
  12087. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  12088. return 9728;
  12089. }
  12090. return 9729;
  12091. }
  12092. //
  12093. function onTextureDispose( event ) {
  12094. var texture = event.target;
  12095. texture.removeEventListener( 'dispose', onTextureDispose );
  12096. deallocateTexture( texture );
  12097. if ( texture.isVideoTexture ) {
  12098. delete _videoTextures[ texture.id ];
  12099. }
  12100. info.memory.textures --;
  12101. }
  12102. function onRenderTargetDispose( event ) {
  12103. var renderTarget = event.target;
  12104. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12105. deallocateRenderTarget( renderTarget );
  12106. info.memory.textures --;
  12107. }
  12108. //
  12109. function deallocateTexture( texture ) {
  12110. var textureProperties = properties.get( texture );
  12111. if ( textureProperties.__webglInit === undefined ) return;
  12112. _gl.deleteTexture( textureProperties.__webglTexture );
  12113. properties.remove( texture );
  12114. }
  12115. function deallocateRenderTarget( renderTarget ) {
  12116. var renderTargetProperties = properties.get( renderTarget );
  12117. var textureProperties = properties.get( renderTarget.texture );
  12118. if ( ! renderTarget ) return;
  12119. if ( textureProperties.__webglTexture !== undefined ) {
  12120. _gl.deleteTexture( textureProperties.__webglTexture );
  12121. }
  12122. if ( renderTarget.depthTexture ) {
  12123. renderTarget.depthTexture.dispose();
  12124. }
  12125. if ( renderTarget.isWebGLRenderTargetCube ) {
  12126. for ( var i = 0; i < 6; i ++ ) {
  12127. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12128. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12129. }
  12130. } else {
  12131. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12132. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12133. }
  12134. properties.remove( renderTarget.texture );
  12135. properties.remove( renderTarget );
  12136. }
  12137. //
  12138. function setTexture2D( texture, slot ) {
  12139. var textureProperties = properties.get( texture );
  12140. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12141. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12142. var image = texture.image;
  12143. if ( image === undefined ) {
  12144. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12145. } else if ( image.complete === false ) {
  12146. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12147. } else {
  12148. uploadTexture( textureProperties, texture, slot );
  12149. return;
  12150. }
  12151. }
  12152. state.activeTexture( 33984 + slot );
  12153. state.bindTexture( 3553, textureProperties.__webglTexture );
  12154. }
  12155. function setTexture3D( texture, slot ) {
  12156. var textureProperties = properties.get( texture );
  12157. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12158. uploadTexture( textureProperties, texture, slot );
  12159. return;
  12160. }
  12161. state.activeTexture( 33984 + slot );
  12162. state.bindTexture( 32879, textureProperties.__webglTexture );
  12163. }
  12164. function setTextureCube( texture, slot ) {
  12165. var textureProperties = properties.get( texture );
  12166. if ( texture.image.length === 6 ) {
  12167. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12168. initTexture( textureProperties, texture );
  12169. state.activeTexture( 33984 + slot );
  12170. state.bindTexture( 34067, textureProperties.__webglTexture );
  12171. _gl.pixelStorei( 37440, texture.flipY );
  12172. var isCompressed = ( texture && texture.isCompressedTexture );
  12173. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12174. var cubeImage = [];
  12175. for ( var i = 0; i < 6; i ++ ) {
  12176. if ( ! isCompressed && ! isDataTexture ) {
  12177. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12178. } else {
  12179. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12180. }
  12181. }
  12182. var image = cubeImage[ 0 ],
  12183. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12184. glFormat = utils.convert( texture.format ),
  12185. glType = utils.convert( texture.type ),
  12186. glInternalFormat = getInternalFormat( glFormat, glType );
  12187. setTextureParameters( 34067, texture, supportsMips );
  12188. for ( var i = 0; i < 6; i ++ ) {
  12189. if ( ! isCompressed ) {
  12190. if ( isDataTexture ) {
  12191. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12192. } else {
  12193. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12194. }
  12195. } else {
  12196. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12197. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12198. mipmap = mipmaps[ j ];
  12199. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12200. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12201. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12202. } else {
  12203. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12204. }
  12205. } else {
  12206. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12207. }
  12208. }
  12209. }
  12210. }
  12211. if ( ! isCompressed ) {
  12212. textureProperties.__maxMipLevel = 0;
  12213. } else {
  12214. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12215. }
  12216. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12217. // We assume images for cube map have the same size.
  12218. generateMipmap( 34067, texture, image.width, image.height );
  12219. }
  12220. textureProperties.__version = texture.version;
  12221. if ( texture.onUpdate ) texture.onUpdate( texture );
  12222. } else {
  12223. state.activeTexture( 33984 + slot );
  12224. state.bindTexture( 34067, textureProperties.__webglTexture );
  12225. }
  12226. }
  12227. }
  12228. function setTextureCubeDynamic( texture, slot ) {
  12229. state.activeTexture( 33984 + slot );
  12230. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12231. }
  12232. function setTextureParameters( textureType, texture, supportsMips ) {
  12233. var extension;
  12234. if ( supportsMips ) {
  12235. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12236. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12237. if ( textureType === 32879 ) {
  12238. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12239. }
  12240. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12241. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12242. } else {
  12243. _gl.texParameteri( textureType, 10242, 33071 );
  12244. _gl.texParameteri( textureType, 10243, 33071 );
  12245. if ( textureType === 32879 ) {
  12246. _gl.texParameteri( textureType, 32882, 33071 );
  12247. }
  12248. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12249. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12250. }
  12251. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12252. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12253. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12254. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12255. }
  12256. }
  12257. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12258. if ( extension ) {
  12259. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12260. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12261. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12262. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12263. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12264. }
  12265. }
  12266. }
  12267. function initTexture( textureProperties, texture ) {
  12268. if ( textureProperties.__webglInit === undefined ) {
  12269. textureProperties.__webglInit = true;
  12270. texture.addEventListener( 'dispose', onTextureDispose );
  12271. textureProperties.__webglTexture = _gl.createTexture();
  12272. info.memory.textures ++;
  12273. }
  12274. }
  12275. function uploadTexture( textureProperties, texture, slot ) {
  12276. var textureType = ( texture.isDataTexture3D ) ? 32879 : 3553;
  12277. initTexture( textureProperties, texture );
  12278. state.activeTexture( 33984 + slot );
  12279. state.bindTexture( textureType, textureProperties.__webglTexture );
  12280. _gl.pixelStorei( 37440, texture.flipY );
  12281. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12282. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12283. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12284. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12285. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12286. glFormat = utils.convert( texture.format ),
  12287. glType = utils.convert( texture.type ),
  12288. glInternalFormat = getInternalFormat( glFormat, glType );
  12289. setTextureParameters( textureType, texture, supportsMips );
  12290. var mipmap, mipmaps = texture.mipmaps;
  12291. if ( texture.isDepthTexture ) {
  12292. // populate depth texture with dummy data
  12293. glInternalFormat = 6402;
  12294. if ( texture.type === FloatType ) {
  12295. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12296. glInternalFormat = 36012;
  12297. } else if ( capabilities.isWebGL2 ) {
  12298. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12299. glInternalFormat = 33189;
  12300. }
  12301. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12302. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12303. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12304. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12305. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12306. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12307. texture.type = UnsignedShortType;
  12308. glType = utils.convert( texture.type );
  12309. }
  12310. }
  12311. // Depth stencil textures need the DEPTH_STENCIL internal format
  12312. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12313. if ( texture.format === DepthStencilFormat ) {
  12314. glInternalFormat = 34041;
  12315. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12316. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12317. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12318. if ( texture.type !== UnsignedInt248Type ) {
  12319. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12320. texture.type = UnsignedInt248Type;
  12321. glType = utils.convert( texture.type );
  12322. }
  12323. }
  12324. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12325. } else if ( texture.isDataTexture ) {
  12326. // use manually created mipmaps if available
  12327. // if there are no manual mipmaps
  12328. // set 0 level mipmap and then use GL to generate other mipmap levels
  12329. if ( mipmaps.length > 0 && supportsMips ) {
  12330. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12331. mipmap = mipmaps[ i ];
  12332. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12333. }
  12334. texture.generateMipmaps = false;
  12335. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12336. } else {
  12337. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12338. textureProperties.__maxMipLevel = 0;
  12339. }
  12340. } else if ( texture.isCompressedTexture ) {
  12341. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12342. mipmap = mipmaps[ i ];
  12343. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12344. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12345. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12346. } else {
  12347. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12348. }
  12349. } else {
  12350. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12351. }
  12352. }
  12353. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12354. } else if ( texture.isDataTexture3D ) {
  12355. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12356. textureProperties.__maxMipLevel = 0;
  12357. } else {
  12358. // regular Texture (image, video, canvas)
  12359. // use manually created mipmaps if available
  12360. // if there are no manual mipmaps
  12361. // set 0 level mipmap and then use GL to generate other mipmap levels
  12362. if ( mipmaps.length > 0 && supportsMips ) {
  12363. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12364. mipmap = mipmaps[ i ];
  12365. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12366. }
  12367. texture.generateMipmaps = false;
  12368. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12369. } else {
  12370. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12371. textureProperties.__maxMipLevel = 0;
  12372. }
  12373. }
  12374. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12375. generateMipmap( 3553, texture, image.width, image.height );
  12376. }
  12377. textureProperties.__version = texture.version;
  12378. if ( texture.onUpdate ) texture.onUpdate( texture );
  12379. }
  12380. // Render targets
  12381. // Setup storage for target texture and bind it to correct framebuffer
  12382. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12383. var glFormat = utils.convert( renderTarget.texture.format );
  12384. var glType = utils.convert( renderTarget.texture.type );
  12385. var glInternalFormat = getInternalFormat( glFormat, glType );
  12386. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12387. _gl.bindFramebuffer( 36160, framebuffer );
  12388. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12389. _gl.bindFramebuffer( 36160, null );
  12390. }
  12391. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12392. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12393. _gl.bindRenderbuffer( 36161, renderbuffer );
  12394. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12395. if ( isMultisample ) {
  12396. var samples = getRenderTargetSamples( renderTarget );
  12397. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12398. } else {
  12399. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12400. }
  12401. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12402. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12403. if ( isMultisample ) {
  12404. var samples = getRenderTargetSamples( renderTarget );
  12405. _gl.renderbufferStorageMultisample( 36161, samples, 34041, renderTarget.width, renderTarget.height );
  12406. } else {
  12407. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12408. }
  12409. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12410. } else {
  12411. var glFormat = utils.convert( renderTarget.texture.format );
  12412. var glType = utils.convert( renderTarget.texture.type );
  12413. var glInternalFormat = getInternalFormat( glFormat, glType );
  12414. if ( isMultisample ) {
  12415. var samples = getRenderTargetSamples( renderTarget );
  12416. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12417. } else {
  12418. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12419. }
  12420. }
  12421. _gl.bindRenderbuffer( 36161, null );
  12422. }
  12423. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12424. function setupDepthTexture( framebuffer, renderTarget ) {
  12425. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12426. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12427. _gl.bindFramebuffer( 36160, framebuffer );
  12428. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12429. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12430. }
  12431. // upload an empty depth texture with framebuffer size
  12432. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12433. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12434. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12435. renderTarget.depthTexture.image.width = renderTarget.width;
  12436. renderTarget.depthTexture.image.height = renderTarget.height;
  12437. renderTarget.depthTexture.needsUpdate = true;
  12438. }
  12439. setTexture2D( renderTarget.depthTexture, 0 );
  12440. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12441. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12442. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12443. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12444. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12445. } else {
  12446. throw new Error( 'Unknown depthTexture format' );
  12447. }
  12448. }
  12449. // Setup GL resources for a non-texture depth buffer
  12450. function setupDepthRenderbuffer( renderTarget ) {
  12451. var renderTargetProperties = properties.get( renderTarget );
  12452. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12453. if ( renderTarget.depthTexture ) {
  12454. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12455. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12456. } else {
  12457. if ( isCube ) {
  12458. renderTargetProperties.__webglDepthbuffer = [];
  12459. for ( var i = 0; i < 6; i ++ ) {
  12460. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12461. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12462. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12463. }
  12464. } else {
  12465. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12466. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12467. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12468. }
  12469. }
  12470. _gl.bindFramebuffer( 36160, null );
  12471. }
  12472. // Set up GL resources for the render target
  12473. function setupRenderTarget( renderTarget ) {
  12474. var renderTargetProperties = properties.get( renderTarget );
  12475. var textureProperties = properties.get( renderTarget.texture );
  12476. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12477. textureProperties.__webglTexture = _gl.createTexture();
  12478. info.memory.textures ++;
  12479. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12480. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12481. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12482. // Setup framebuffer
  12483. if ( isCube ) {
  12484. renderTargetProperties.__webglFramebuffer = [];
  12485. for ( var i = 0; i < 6; i ++ ) {
  12486. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12487. }
  12488. } else {
  12489. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12490. if ( isMultisample ) {
  12491. if ( capabilities.isWebGL2 ) {
  12492. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12493. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12494. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12495. var glFormat = utils.convert( renderTarget.texture.format );
  12496. var glType = utils.convert( renderTarget.texture.type );
  12497. var glInternalFormat = getInternalFormat( glFormat, glType );
  12498. var samples = getRenderTargetSamples( renderTarget );
  12499. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12500. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12501. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12502. _gl.bindRenderbuffer( 36161, null );
  12503. if ( renderTarget.depthBuffer ) {
  12504. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12505. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12506. }
  12507. _gl.bindFramebuffer( 36160, null );
  12508. } else {
  12509. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12510. }
  12511. }
  12512. }
  12513. // Setup color buffer
  12514. if ( isCube ) {
  12515. state.bindTexture( 34067, textureProperties.__webglTexture );
  12516. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12517. for ( var i = 0; i < 6; i ++ ) {
  12518. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12519. }
  12520. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12521. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12522. }
  12523. state.bindTexture( 34067, null );
  12524. } else {
  12525. state.bindTexture( 3553, textureProperties.__webglTexture );
  12526. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12527. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12528. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12529. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12530. }
  12531. state.bindTexture( 3553, null );
  12532. }
  12533. // Setup depth and stencil buffers
  12534. if ( renderTarget.depthBuffer ) {
  12535. setupDepthRenderbuffer( renderTarget );
  12536. }
  12537. }
  12538. function updateRenderTargetMipmap( renderTarget ) {
  12539. var texture = renderTarget.texture;
  12540. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12541. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12542. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  12543. var webglTexture = properties.get( texture ).__webglTexture;
  12544. state.bindTexture( target, webglTexture );
  12545. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12546. state.bindTexture( target, null );
  12547. }
  12548. }
  12549. function updateMultisampleRenderTarget( renderTarget ) {
  12550. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12551. if ( capabilities.isWebGL2 ) {
  12552. var renderTargetProperties = properties.get( renderTarget );
  12553. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12554. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12555. var width = renderTarget.width;
  12556. var height = renderTarget.height;
  12557. var mask = 16384;
  12558. if ( renderTarget.depthBuffer ) mask |= 256;
  12559. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12560. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12561. } else {
  12562. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12563. }
  12564. }
  12565. }
  12566. function getRenderTargetSamples( renderTarget ) {
  12567. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12568. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  12569. }
  12570. function updateVideoTexture( texture ) {
  12571. var id = texture.id;
  12572. var frame = info.render.frame;
  12573. // Check the last frame we updated the VideoTexture
  12574. if ( _videoTextures[ id ] !== frame ) {
  12575. _videoTextures[ id ] = frame;
  12576. texture.update();
  12577. }
  12578. }
  12579. this.setTexture2D = setTexture2D;
  12580. this.setTexture3D = setTexture3D;
  12581. this.setTextureCube = setTextureCube;
  12582. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12583. this.setupRenderTarget = setupRenderTarget;
  12584. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12585. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12586. }
  12587. /**
  12588. * @author thespite / http://www.twitter.com/thespite
  12589. */
  12590. function WebGLUtils( gl, extensions, capabilities ) {
  12591. function convert( p ) {
  12592. var extension;
  12593. if ( p === RepeatWrapping ) return 10497;
  12594. if ( p === ClampToEdgeWrapping ) return 33071;
  12595. if ( p === MirroredRepeatWrapping ) return 33648;
  12596. if ( p === NearestFilter ) return 9728;
  12597. if ( p === NearestMipMapNearestFilter ) return 9984;
  12598. if ( p === NearestMipMapLinearFilter ) return 9986;
  12599. if ( p === LinearFilter ) return 9729;
  12600. if ( p === LinearMipMapNearestFilter ) return 9985;
  12601. if ( p === LinearMipMapLinearFilter ) return 9987;
  12602. if ( p === UnsignedByteType ) return 5121;
  12603. if ( p === UnsignedShort4444Type ) return 32819;
  12604. if ( p === UnsignedShort5551Type ) return 32820;
  12605. if ( p === UnsignedShort565Type ) return 33635;
  12606. if ( p === ByteType ) return 5120;
  12607. if ( p === ShortType ) return 5122;
  12608. if ( p === UnsignedShortType ) return 5123;
  12609. if ( p === IntType ) return 5124;
  12610. if ( p === UnsignedIntType ) return 5125;
  12611. if ( p === FloatType ) return 5126;
  12612. if ( p === HalfFloatType ) {
  12613. if ( capabilities.isWebGL2 ) return 5131;
  12614. extension = extensions.get( 'OES_texture_half_float' );
  12615. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12616. }
  12617. if ( p === AlphaFormat ) return 6406;
  12618. if ( p === RGBFormat ) return 6407;
  12619. if ( p === RGBAFormat ) return 6408;
  12620. if ( p === LuminanceFormat ) return 6409;
  12621. if ( p === LuminanceAlphaFormat ) return 6410;
  12622. if ( p === DepthFormat ) return 6402;
  12623. if ( p === DepthStencilFormat ) return 34041;
  12624. if ( p === RedFormat ) return 6403;
  12625. if ( p === AddEquation ) return 32774;
  12626. if ( p === SubtractEquation ) return 32778;
  12627. if ( p === ReverseSubtractEquation ) return 32779;
  12628. if ( p === ZeroFactor ) return 0;
  12629. if ( p === OneFactor ) return 1;
  12630. if ( p === SrcColorFactor ) return 768;
  12631. if ( p === OneMinusSrcColorFactor ) return 769;
  12632. if ( p === SrcAlphaFactor ) return 770;
  12633. if ( p === OneMinusSrcAlphaFactor ) return 771;
  12634. if ( p === DstAlphaFactor ) return 772;
  12635. if ( p === OneMinusDstAlphaFactor ) return 773;
  12636. if ( p === DstColorFactor ) return 774;
  12637. if ( p === OneMinusDstColorFactor ) return 775;
  12638. if ( p === SrcAlphaSaturateFactor ) return 776;
  12639. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12640. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12641. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12642. if ( extension !== null ) {
  12643. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12644. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12645. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12646. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12647. }
  12648. }
  12649. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12650. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12651. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12652. if ( extension !== null ) {
  12653. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12654. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12655. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12656. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12657. }
  12658. }
  12659. if ( p === RGB_ETC1_Format ) {
  12660. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12661. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12662. }
  12663. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12664. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12665. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12666. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12667. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12668. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12669. if ( extension !== null ) {
  12670. return p;
  12671. }
  12672. }
  12673. if ( p === MinEquation || p === MaxEquation ) {
  12674. if ( capabilities.isWebGL2 ) {
  12675. if ( p === MinEquation ) return 32775;
  12676. if ( p === MaxEquation ) return 32776;
  12677. }
  12678. extension = extensions.get( 'EXT_blend_minmax' );
  12679. if ( extension !== null ) {
  12680. if ( p === MinEquation ) return extension.MIN_EXT;
  12681. if ( p === MaxEquation ) return extension.MAX_EXT;
  12682. }
  12683. }
  12684. if ( p === UnsignedInt248Type ) {
  12685. if ( capabilities.isWebGL2 ) return 34042;
  12686. extension = extensions.get( 'WEBGL_depth_texture' );
  12687. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12688. }
  12689. return 0;
  12690. }
  12691. return { convert: convert };
  12692. }
  12693. /**
  12694. * @author mrdoob / http://mrdoob.com/
  12695. */
  12696. function Group() {
  12697. Object3D.call( this );
  12698. this.type = 'Group';
  12699. }
  12700. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12701. constructor: Group,
  12702. isGroup: true
  12703. } );
  12704. /**
  12705. * @author mrdoob / http://mrdoob.com/
  12706. * @author mikael emtinger / http://gomo.se/
  12707. * @author WestLangley / http://github.com/WestLangley
  12708. */
  12709. function Camera() {
  12710. Object3D.call( this );
  12711. this.type = 'Camera';
  12712. this.matrixWorldInverse = new Matrix4();
  12713. this.projectionMatrix = new Matrix4();
  12714. this.projectionMatrixInverse = new Matrix4();
  12715. }
  12716. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12717. constructor: Camera,
  12718. isCamera: true,
  12719. copy: function ( source, recursive ) {
  12720. Object3D.prototype.copy.call( this, source, recursive );
  12721. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  12722. this.projectionMatrix.copy( source.projectionMatrix );
  12723. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  12724. return this;
  12725. },
  12726. getWorldDirection: function ( target ) {
  12727. if ( target === undefined ) {
  12728. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  12729. target = new Vector3();
  12730. }
  12731. this.updateMatrixWorld( true );
  12732. var e = this.matrixWorld.elements;
  12733. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  12734. },
  12735. updateMatrixWorld: function ( force ) {
  12736. Object3D.prototype.updateMatrixWorld.call( this, force );
  12737. this.matrixWorldInverse.getInverse( this.matrixWorld );
  12738. },
  12739. clone: function () {
  12740. return new this.constructor().copy( this );
  12741. }
  12742. } );
  12743. /**
  12744. * @author mrdoob / http://mrdoob.com/
  12745. * @author greggman / http://games.greggman.com/
  12746. * @author zz85 / http://www.lab4games.net/zz85/blog
  12747. * @author tschw
  12748. */
  12749. function PerspectiveCamera( fov, aspect, near, far ) {
  12750. Camera.call( this );
  12751. this.type = 'PerspectiveCamera';
  12752. this.fov = fov !== undefined ? fov : 50;
  12753. this.zoom = 1;
  12754. this.near = near !== undefined ? near : 0.1;
  12755. this.far = far !== undefined ? far : 2000;
  12756. this.focus = 10;
  12757. this.aspect = aspect !== undefined ? aspect : 1;
  12758. this.view = null;
  12759. this.filmGauge = 35; // width of the film (default in millimeters)
  12760. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12761. this.updateProjectionMatrix();
  12762. }
  12763. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12764. constructor: PerspectiveCamera,
  12765. isPerspectiveCamera: true,
  12766. copy: function ( source, recursive ) {
  12767. Camera.prototype.copy.call( this, source, recursive );
  12768. this.fov = source.fov;
  12769. this.zoom = source.zoom;
  12770. this.near = source.near;
  12771. this.far = source.far;
  12772. this.focus = source.focus;
  12773. this.aspect = source.aspect;
  12774. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12775. this.filmGauge = source.filmGauge;
  12776. this.filmOffset = source.filmOffset;
  12777. return this;
  12778. },
  12779. /**
  12780. * Sets the FOV by focal length in respect to the current .filmGauge.
  12781. *
  12782. * The default film gauge is 35, so that the focal length can be specified for
  12783. * a 35mm (full frame) camera.
  12784. *
  12785. * Values for focal length and film gauge must have the same unit.
  12786. */
  12787. setFocalLength: function ( focalLength ) {
  12788. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12789. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12790. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12791. this.updateProjectionMatrix();
  12792. },
  12793. /**
  12794. * Calculates the focal length from the current .fov and .filmGauge.
  12795. */
  12796. getFocalLength: function () {
  12797. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12798. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12799. },
  12800. getEffectiveFOV: function () {
  12801. return _Math.RAD2DEG * 2 * Math.atan(
  12802. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12803. },
  12804. getFilmWidth: function () {
  12805. // film not completely covered in portrait format (aspect < 1)
  12806. return this.filmGauge * Math.min( this.aspect, 1 );
  12807. },
  12808. getFilmHeight: function () {
  12809. // film not completely covered in landscape format (aspect > 1)
  12810. return this.filmGauge / Math.max( this.aspect, 1 );
  12811. },
  12812. /**
  12813. * Sets an offset in a larger frustum. This is useful for multi-window or
  12814. * multi-monitor/multi-machine setups.
  12815. *
  12816. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12817. * the monitors are in grid like this
  12818. *
  12819. * +---+---+---+
  12820. * | A | B | C |
  12821. * +---+---+---+
  12822. * | D | E | F |
  12823. * +---+---+---+
  12824. *
  12825. * then for each monitor you would call it like this
  12826. *
  12827. * var w = 1920;
  12828. * var h = 1080;
  12829. * var fullWidth = w * 3;
  12830. * var fullHeight = h * 2;
  12831. *
  12832. * --A--
  12833. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12834. * --B--
  12835. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12836. * --C--
  12837. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12838. * --D--
  12839. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12840. * --E--
  12841. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12842. * --F--
  12843. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12844. *
  12845. * Note there is no reason monitors have to be the same size or in a grid.
  12846. */
  12847. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12848. this.aspect = fullWidth / fullHeight;
  12849. if ( this.view === null ) {
  12850. this.view = {
  12851. enabled: true,
  12852. fullWidth: 1,
  12853. fullHeight: 1,
  12854. offsetX: 0,
  12855. offsetY: 0,
  12856. width: 1,
  12857. height: 1
  12858. };
  12859. }
  12860. this.view.enabled = true;
  12861. this.view.fullWidth = fullWidth;
  12862. this.view.fullHeight = fullHeight;
  12863. this.view.offsetX = x;
  12864. this.view.offsetY = y;
  12865. this.view.width = width;
  12866. this.view.height = height;
  12867. this.updateProjectionMatrix();
  12868. },
  12869. clearViewOffset: function () {
  12870. if ( this.view !== null ) {
  12871. this.view.enabled = false;
  12872. }
  12873. this.updateProjectionMatrix();
  12874. },
  12875. updateProjectionMatrix: function () {
  12876. var near = this.near,
  12877. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  12878. height = 2 * top,
  12879. width = this.aspect * height,
  12880. left = - 0.5 * width,
  12881. view = this.view;
  12882. if ( this.view !== null && this.view.enabled ) {
  12883. var fullWidth = view.fullWidth,
  12884. fullHeight = view.fullHeight;
  12885. left += view.offsetX * width / fullWidth;
  12886. top -= view.offsetY * height / fullHeight;
  12887. width *= view.width / fullWidth;
  12888. height *= view.height / fullHeight;
  12889. }
  12890. var skew = this.filmOffset;
  12891. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  12892. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  12893. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  12894. },
  12895. toJSON: function ( meta ) {
  12896. var data = Object3D.prototype.toJSON.call( this, meta );
  12897. data.object.fov = this.fov;
  12898. data.object.zoom = this.zoom;
  12899. data.object.near = this.near;
  12900. data.object.far = this.far;
  12901. data.object.focus = this.focus;
  12902. data.object.aspect = this.aspect;
  12903. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  12904. data.object.filmGauge = this.filmGauge;
  12905. data.object.filmOffset = this.filmOffset;
  12906. return data;
  12907. }
  12908. } );
  12909. /**
  12910. * @author mrdoob / http://mrdoob.com/
  12911. */
  12912. function ArrayCamera( array ) {
  12913. PerspectiveCamera.call( this );
  12914. this.cameras = array || [];
  12915. }
  12916. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  12917. constructor: ArrayCamera,
  12918. isArrayCamera: true
  12919. } );
  12920. /**
  12921. * @author jsantell / https://www.jsantell.com/
  12922. * @author mrdoob / http://mrdoob.com/
  12923. */
  12924. var cameraLPos = new Vector3();
  12925. var cameraRPos = new Vector3();
  12926. /**
  12927. * Assumes 2 cameras that are parallel and share an X-axis, and that
  12928. * the cameras' projection and world matrices have already been set.
  12929. * And that near and far planes are identical for both cameras.
  12930. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  12931. */
  12932. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  12933. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  12934. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  12935. var ipd = cameraLPos.distanceTo( cameraRPos );
  12936. var projL = cameraL.projectionMatrix.elements;
  12937. var projR = cameraR.projectionMatrix.elements;
  12938. // VR systems will have identical far and near planes, and
  12939. // most likely identical top and bottom frustum extents.
  12940. // Use the left camera for these values.
  12941. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  12942. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  12943. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  12944. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  12945. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  12946. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  12947. var left = near * leftFov;
  12948. var right = near * rightFov;
  12949. // Calculate the new camera's position offset from the
  12950. // left camera. xOffset should be roughly half `ipd`.
  12951. var zOffset = ipd / ( - leftFov + rightFov );
  12952. var xOffset = zOffset * - leftFov;
  12953. // TODO: Better way to apply this offset?
  12954. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  12955. camera.translateX( xOffset );
  12956. camera.translateZ( zOffset );
  12957. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  12958. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12959. // Find the union of the frustum values of the cameras and scale
  12960. // the values so that the near plane's position does not change in world space,
  12961. // although must now be relative to the new union camera.
  12962. var near2 = near + zOffset;
  12963. var far2 = far + zOffset;
  12964. var left2 = left - xOffset;
  12965. var right2 = right + ( ipd - xOffset );
  12966. var top2 = topFov * far / far2 * near2;
  12967. var bottom2 = bottomFov * far / far2 * near2;
  12968. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  12969. }
  12970. /**
  12971. * @author mrdoob / http://mrdoob.com/
  12972. */
  12973. function WebVRManager( renderer ) {
  12974. var scope = this;
  12975. var device = null;
  12976. var frameData = null;
  12977. var poseTarget = null;
  12978. var controllers = [];
  12979. var standingMatrix = new Matrix4();
  12980. var standingMatrixInverse = new Matrix4();
  12981. var framebufferScaleFactor = 1.0;
  12982. var frameOfReferenceType = 'stage';
  12983. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  12984. frameData = new window.VRFrameData();
  12985. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  12986. }
  12987. var matrixWorldInverse = new Matrix4();
  12988. var tempQuaternion = new Quaternion();
  12989. var tempPosition = new Vector3();
  12990. var cameraL = new PerspectiveCamera();
  12991. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  12992. cameraL.layers.enable( 1 );
  12993. var cameraR = new PerspectiveCamera();
  12994. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  12995. cameraR.layers.enable( 2 );
  12996. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  12997. cameraVR.layers.enable( 1 );
  12998. cameraVR.layers.enable( 2 );
  12999. //
  13000. function isPresenting() {
  13001. return device !== null && device.isPresenting === true;
  13002. }
  13003. var currentSize = new Vector2(), currentPixelRatio;
  13004. function onVRDisplayPresentChange() {
  13005. if ( isPresenting() ) {
  13006. var eyeParameters = device.getEyeParameters( 'left' );
  13007. var renderWidth = eyeParameters.renderWidth * framebufferScaleFactor;
  13008. var renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13009. currentPixelRatio = renderer.getPixelRatio();
  13010. renderer.getSize( currentSize );
  13011. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  13012. animation.start();
  13013. } else {
  13014. if ( scope.enabled ) {
  13015. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13016. }
  13017. animation.stop();
  13018. }
  13019. }
  13020. //
  13021. var triggers = [];
  13022. function findGamepad( id ) {
  13023. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13024. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13025. var gamepad = gamepads[ i ];
  13026. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13027. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13028. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13029. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13030. if ( j === id ) return gamepad;
  13031. j ++;
  13032. }
  13033. }
  13034. }
  13035. function updateControllers() {
  13036. for ( var i = 0; i < controllers.length; i ++ ) {
  13037. var controller = controllers[ i ];
  13038. var gamepad = findGamepad( i );
  13039. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13040. if ( gamepad.pose === null ) return;
  13041. // Pose
  13042. var pose = gamepad.pose;
  13043. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13044. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13045. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13046. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13047. controller.matrix.premultiply( standingMatrix );
  13048. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13049. controller.matrixWorldNeedsUpdate = true;
  13050. controller.visible = true;
  13051. // Trigger
  13052. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13053. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13054. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13055. if ( triggers[ i ] === true ) {
  13056. controller.dispatchEvent( { type: 'selectstart' } );
  13057. } else {
  13058. controller.dispatchEvent( { type: 'selectend' } );
  13059. controller.dispatchEvent( { type: 'select' } );
  13060. }
  13061. }
  13062. } else {
  13063. controller.visible = false;
  13064. }
  13065. }
  13066. }
  13067. //
  13068. this.enabled = false;
  13069. this.getController = function ( id ) {
  13070. var controller = controllers[ id ];
  13071. if ( controller === undefined ) {
  13072. controller = new Group();
  13073. controller.matrixAutoUpdate = false;
  13074. controller.visible = false;
  13075. controllers[ id ] = controller;
  13076. }
  13077. return controller;
  13078. };
  13079. this.getDevice = function () {
  13080. return device;
  13081. };
  13082. this.setDevice = function ( value ) {
  13083. if ( value !== undefined ) device = value;
  13084. animation.setContext( value );
  13085. };
  13086. this.setFramebufferScaleFactor = function ( value ) {
  13087. framebufferScaleFactor = value;
  13088. };
  13089. this.setFrameOfReferenceType = function ( value ) {
  13090. frameOfReferenceType = value;
  13091. };
  13092. this.setPoseTarget = function ( object ) {
  13093. if ( object !== undefined ) poseTarget = object;
  13094. };
  13095. this.getCamera = function ( camera ) {
  13096. var userHeight = frameOfReferenceType === 'stage' ? 1.6 : 0;
  13097. if ( isPresenting() === false ) {
  13098. camera.position.set( 0, userHeight, 0 );
  13099. camera.rotation.set( 0, 0, 0 );
  13100. return camera;
  13101. }
  13102. device.depthNear = camera.near;
  13103. device.depthFar = camera.far;
  13104. device.getFrameData( frameData );
  13105. //
  13106. if ( frameOfReferenceType === 'stage' ) {
  13107. var stageParameters = device.stageParameters;
  13108. if ( stageParameters ) {
  13109. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13110. } else {
  13111. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13112. }
  13113. }
  13114. var pose = frameData.pose;
  13115. var poseObject = poseTarget !== null ? poseTarget : camera;
  13116. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13117. poseObject.matrix.copy( standingMatrix );
  13118. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13119. if ( pose.orientation !== null ) {
  13120. tempQuaternion.fromArray( pose.orientation );
  13121. poseObject.quaternion.multiply( tempQuaternion );
  13122. }
  13123. if ( pose.position !== null ) {
  13124. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13125. tempPosition.fromArray( pose.position );
  13126. tempPosition.applyQuaternion( tempQuaternion );
  13127. poseObject.position.add( tempPosition );
  13128. }
  13129. poseObject.updateMatrixWorld();
  13130. //
  13131. cameraL.near = camera.near;
  13132. cameraR.near = camera.near;
  13133. cameraL.far = camera.far;
  13134. cameraR.far = camera.far;
  13135. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13136. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13137. // TODO (mrdoob) Double check this code
  13138. standingMatrixInverse.getInverse( standingMatrix );
  13139. if ( frameOfReferenceType === 'stage' ) {
  13140. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13141. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13142. }
  13143. var parent = poseObject.parent;
  13144. if ( parent !== null ) {
  13145. matrixWorldInverse.getInverse( parent.matrixWorld );
  13146. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13147. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13148. }
  13149. // envMap and Mirror needs camera.matrixWorld
  13150. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13151. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13152. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13153. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13154. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13155. //
  13156. var layers = device.getLayers();
  13157. if ( layers.length ) {
  13158. var layer = layers[ 0 ];
  13159. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  13160. cameraL.bounds.fromArray( layer.leftBounds );
  13161. }
  13162. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  13163. cameraR.bounds.fromArray( layer.rightBounds );
  13164. }
  13165. }
  13166. updateControllers();
  13167. return cameraVR;
  13168. };
  13169. this.getStandingMatrix = function () {
  13170. return standingMatrix;
  13171. };
  13172. this.isPresenting = isPresenting;
  13173. // Animation Loop
  13174. var animation = new WebGLAnimation();
  13175. this.setAnimationLoop = function ( callback ) {
  13176. animation.setAnimationLoop( callback );
  13177. };
  13178. this.submitFrame = function () {
  13179. if ( isPresenting() ) device.submitFrame();
  13180. };
  13181. this.dispose = function () {
  13182. if ( typeof window !== 'undefined' ) {
  13183. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13184. }
  13185. };
  13186. }
  13187. /**
  13188. * @author mrdoob / http://mrdoob.com/
  13189. */
  13190. function WebXRManager( renderer ) {
  13191. var gl = renderer.context;
  13192. var device = null;
  13193. var session = null;
  13194. var framebufferScaleFactor = 1.0;
  13195. var frameOfReference = null;
  13196. var frameOfReferenceType = 'stage';
  13197. var pose = null;
  13198. var controllers = [];
  13199. var inputSources = [];
  13200. function isPresenting() {
  13201. return session !== null && frameOfReference !== null;
  13202. }
  13203. //
  13204. var cameraL = new PerspectiveCamera();
  13205. cameraL.layers.enable( 1 );
  13206. cameraL.viewport = new Vector4();
  13207. var cameraR = new PerspectiveCamera();
  13208. cameraR.layers.enable( 2 );
  13209. cameraR.viewport = new Vector4();
  13210. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13211. cameraVR.layers.enable( 1 );
  13212. cameraVR.layers.enable( 2 );
  13213. //
  13214. this.enabled = false;
  13215. this.getController = function ( id ) {
  13216. var controller = controllers[ id ];
  13217. if ( controller === undefined ) {
  13218. controller = new Group();
  13219. controller.matrixAutoUpdate = false;
  13220. controller.visible = false;
  13221. controllers[ id ] = controller;
  13222. }
  13223. return controller;
  13224. };
  13225. this.getDevice = function () {
  13226. return device;
  13227. };
  13228. this.setDevice = function ( value ) {
  13229. if ( value !== undefined ) device = value;
  13230. if ( value instanceof XRDevice ) gl.setCompatibleXRDevice( value );
  13231. };
  13232. //
  13233. function onSessionEvent( event ) {
  13234. var controller = controllers[ inputSources.indexOf( event.inputSource ) ];
  13235. if ( controller ) controller.dispatchEvent( { type: event.type } );
  13236. }
  13237. function onSessionEnd() {
  13238. renderer.setFramebuffer( null );
  13239. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13240. animation.stop();
  13241. }
  13242. this.setFramebufferScaleFactor = function ( value ) {
  13243. framebufferScaleFactor = value;
  13244. };
  13245. this.setFrameOfReferenceType = function ( value ) {
  13246. frameOfReferenceType = value;
  13247. };
  13248. this.setSession = function ( value ) {
  13249. session = value;
  13250. if ( session !== null ) {
  13251. session.addEventListener( 'select', onSessionEvent );
  13252. session.addEventListener( 'selectstart', onSessionEvent );
  13253. session.addEventListener( 'selectend', onSessionEvent );
  13254. session.addEventListener( 'end', onSessionEnd );
  13255. session.baseLayer = new XRWebGLLayer( session, gl, { framebufferScaleFactor: framebufferScaleFactor } );
  13256. session.requestFrameOfReference( frameOfReferenceType ).then( function ( value ) {
  13257. frameOfReference = value;
  13258. renderer.setFramebuffer( session.baseLayer.framebuffer );
  13259. animation.setContext( session );
  13260. animation.start();
  13261. } );
  13262. //
  13263. inputSources = session.getInputSources();
  13264. session.addEventListener( 'inputsourceschange', function () {
  13265. inputSources = session.getInputSources();
  13266. console.log( inputSources );
  13267. for ( var i = 0; i < controllers.length; i ++ ) {
  13268. var controller = controllers[ i ];
  13269. controller.userData.inputSource = inputSources[ i ];
  13270. }
  13271. } );
  13272. }
  13273. };
  13274. function updateCamera( camera, parent ) {
  13275. if ( parent === null ) {
  13276. camera.matrixWorld.copy( camera.matrix );
  13277. } else {
  13278. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13279. }
  13280. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13281. }
  13282. this.getCamera = function ( camera ) {
  13283. if ( isPresenting() ) {
  13284. var parent = camera.parent;
  13285. var cameras = cameraVR.cameras;
  13286. updateCamera( cameraVR, parent );
  13287. for ( var i = 0; i < cameras.length; i ++ ) {
  13288. updateCamera( cameras[ i ], parent );
  13289. }
  13290. // update camera and its children
  13291. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13292. var children = camera.children;
  13293. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13294. children[ i ].updateMatrixWorld( true );
  13295. }
  13296. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13297. return cameraVR;
  13298. }
  13299. return camera;
  13300. };
  13301. this.isPresenting = isPresenting;
  13302. // Animation Loop
  13303. var onAnimationFrameCallback = null;
  13304. function onAnimationFrame( time, frame ) {
  13305. pose = frame.getDevicePose( frameOfReference );
  13306. if ( pose !== null ) {
  13307. var layer = session.baseLayer;
  13308. var views = frame.views;
  13309. for ( var i = 0; i < views.length; i ++ ) {
  13310. var view = views[ i ];
  13311. var viewport = layer.getViewport( view );
  13312. var viewMatrix = pose.getViewMatrix( view );
  13313. var camera = cameraVR.cameras[ i ];
  13314. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13315. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13316. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13317. if ( i === 0 ) {
  13318. cameraVR.matrix.copy( camera.matrix );
  13319. }
  13320. }
  13321. }
  13322. //
  13323. for ( var i = 0; i < controllers.length; i ++ ) {
  13324. var controller = controllers[ i ];
  13325. var inputSource = inputSources[ i ];
  13326. if ( inputSource ) {
  13327. var inputPose = frame.getInputPose( inputSource, frameOfReference );
  13328. if ( inputPose !== null ) {
  13329. if ( 'targetRay' in inputPose ) {
  13330. controller.matrix.elements = inputPose.targetRay.transformMatrix;
  13331. } else if ( 'pointerMatrix' in inputPose ) {
  13332. // DEPRECATED
  13333. controller.matrix.elements = inputPose.pointerMatrix;
  13334. }
  13335. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13336. controller.visible = true;
  13337. continue;
  13338. }
  13339. }
  13340. controller.visible = false;
  13341. }
  13342. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13343. }
  13344. var animation = new WebGLAnimation();
  13345. animation.setAnimationLoop( onAnimationFrame );
  13346. this.setAnimationLoop = function ( callback ) {
  13347. onAnimationFrameCallback = callback;
  13348. };
  13349. this.dispose = function () {};
  13350. // DEPRECATED
  13351. this.getStandingMatrix = function () {
  13352. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13353. return new Matrix4();
  13354. };
  13355. this.submitFrame = function () {};
  13356. }
  13357. /**
  13358. * @author supereggbert / http://www.paulbrunt.co.uk/
  13359. * @author mrdoob / http://mrdoob.com/
  13360. * @author alteredq / http://alteredqualia.com/
  13361. * @author szimek / https://github.com/szimek/
  13362. * @author tschw
  13363. */
  13364. function WebGLRenderer( parameters ) {
  13365. console.log( 'THREE.WebGLRenderer', REVISION );
  13366. parameters = parameters || {};
  13367. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13368. _context = parameters.context !== undefined ? parameters.context : null,
  13369. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13370. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13371. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13372. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13373. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13374. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13375. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  13376. var currentRenderList = null;
  13377. var currentRenderState = null;
  13378. // public properties
  13379. this.domElement = _canvas;
  13380. this.context = null;
  13381. // clearing
  13382. this.autoClear = true;
  13383. this.autoClearColor = true;
  13384. this.autoClearDepth = true;
  13385. this.autoClearStencil = true;
  13386. // scene graph
  13387. this.sortObjects = true;
  13388. // user-defined clipping
  13389. this.clippingPlanes = [];
  13390. this.localClippingEnabled = false;
  13391. // physically based shading
  13392. this.gammaFactor = 2.0; // for backwards compatibility
  13393. this.gammaInput = false;
  13394. this.gammaOutput = false;
  13395. // physical lights
  13396. this.physicallyCorrectLights = false;
  13397. // tone mapping
  13398. this.toneMapping = LinearToneMapping;
  13399. this.toneMappingExposure = 1.0;
  13400. this.toneMappingWhitePoint = 1.0;
  13401. // morphs
  13402. this.maxMorphTargets = 8;
  13403. this.maxMorphNormals = 4;
  13404. // internal properties
  13405. var _this = this,
  13406. _isContextLost = false,
  13407. // internal state cache
  13408. _framebuffer = null,
  13409. _currentRenderTarget = null,
  13410. _currentFramebuffer = null,
  13411. _currentMaterialId = - 1,
  13412. // geometry and program caching
  13413. _currentGeometryProgram = {
  13414. geometry: null,
  13415. program: null,
  13416. wireframe: false
  13417. },
  13418. _currentCamera = null,
  13419. _currentArrayCamera = null,
  13420. _currentViewport = new Vector4(),
  13421. _currentScissor = new Vector4(),
  13422. _currentScissorTest = null,
  13423. //
  13424. _usedTextureUnits = 0,
  13425. //
  13426. _width = _canvas.width,
  13427. _height = _canvas.height,
  13428. _pixelRatio = 1,
  13429. _viewport = new Vector4( 0, 0, _width, _height ),
  13430. _scissor = new Vector4( 0, 0, _width, _height ),
  13431. _scissorTest = false,
  13432. // frustum
  13433. _frustum = new Frustum(),
  13434. // clipping
  13435. _clipping = new WebGLClipping(),
  13436. _clippingEnabled = false,
  13437. _localClippingEnabled = false,
  13438. // camera matrices cache
  13439. _projScreenMatrix = new Matrix4(),
  13440. _vector3 = new Vector3();
  13441. function getTargetPixelRatio() {
  13442. return _currentRenderTarget === null ? _pixelRatio : 1;
  13443. }
  13444. // initialize
  13445. var _gl;
  13446. try {
  13447. var contextAttributes = {
  13448. alpha: _alpha,
  13449. depth: _depth,
  13450. stencil: _stencil,
  13451. antialias: _antialias,
  13452. premultipliedAlpha: _premultipliedAlpha,
  13453. preserveDrawingBuffer: _preserveDrawingBuffer,
  13454. powerPreference: _powerPreference
  13455. };
  13456. // event listeners must be registered before WebGL context is created, see #12753
  13457. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13458. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13459. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13460. if ( _gl === null ) {
  13461. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13462. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13463. } else {
  13464. throw new Error( 'Error creating WebGL context.' );
  13465. }
  13466. }
  13467. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13468. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13469. _gl.getShaderPrecisionFormat = function () {
  13470. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13471. };
  13472. }
  13473. } catch ( error ) {
  13474. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13475. throw error;
  13476. }
  13477. var extensions, capabilities, state, info;
  13478. var properties, textures, attributes, geometries, objects;
  13479. var programCache, renderLists, renderStates;
  13480. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13481. var utils;
  13482. function initGLContext() {
  13483. extensions = new WebGLExtensions( _gl );
  13484. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13485. if ( ! capabilities.isWebGL2 ) {
  13486. extensions.get( 'WEBGL_depth_texture' );
  13487. extensions.get( 'OES_texture_float' );
  13488. extensions.get( 'OES_texture_half_float' );
  13489. extensions.get( 'OES_texture_half_float_linear' );
  13490. extensions.get( 'OES_standard_derivatives' );
  13491. extensions.get( 'OES_element_index_uint' );
  13492. extensions.get( 'ANGLE_instanced_arrays' );
  13493. }
  13494. extensions.get( 'OES_texture_float_linear' );
  13495. utils = new WebGLUtils( _gl, extensions, capabilities );
  13496. state = new WebGLState( _gl, extensions, utils, capabilities );
  13497. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13498. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13499. info = new WebGLInfo( _gl );
  13500. properties = new WebGLProperties();
  13501. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13502. attributes = new WebGLAttributes( _gl );
  13503. geometries = new WebGLGeometries( _gl, attributes, info );
  13504. objects = new WebGLObjects( geometries, info );
  13505. morphtargets = new WebGLMorphtargets( _gl );
  13506. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13507. renderLists = new WebGLRenderLists();
  13508. renderStates = new WebGLRenderStates();
  13509. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13510. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13511. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13512. info.programs = programCache.programs;
  13513. _this.context = _gl;
  13514. _this.capabilities = capabilities;
  13515. _this.extensions = extensions;
  13516. _this.properties = properties;
  13517. _this.renderLists = renderLists;
  13518. _this.state = state;
  13519. _this.info = info;
  13520. }
  13521. initGLContext();
  13522. // vr
  13523. var vr = null;
  13524. if ( typeof navigator !== 'undefined' ) {
  13525. vr = ( 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13526. }
  13527. this.vr = vr;
  13528. // shadow map
  13529. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13530. this.shadowMap = shadowMap;
  13531. // API
  13532. this.getContext = function () {
  13533. return _gl;
  13534. };
  13535. this.getContextAttributes = function () {
  13536. return _gl.getContextAttributes();
  13537. };
  13538. this.forceContextLoss = function () {
  13539. var extension = extensions.get( 'WEBGL_lose_context' );
  13540. if ( extension ) extension.loseContext();
  13541. };
  13542. this.forceContextRestore = function () {
  13543. var extension = extensions.get( 'WEBGL_lose_context' );
  13544. if ( extension ) extension.restoreContext();
  13545. };
  13546. this.getPixelRatio = function () {
  13547. return _pixelRatio;
  13548. };
  13549. this.setPixelRatio = function ( value ) {
  13550. if ( value === undefined ) return;
  13551. _pixelRatio = value;
  13552. this.setSize( _width, _height, false );
  13553. };
  13554. this.getSize = function ( target ) {
  13555. if ( target === undefined ) {
  13556. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13557. target = new Vector2();
  13558. }
  13559. return target.set( _width, _height );
  13560. };
  13561. this.setSize = function ( width, height, updateStyle ) {
  13562. if ( vr.isPresenting() ) {
  13563. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13564. return;
  13565. }
  13566. _width = width;
  13567. _height = height;
  13568. _canvas.width = width * _pixelRatio;
  13569. _canvas.height = height * _pixelRatio;
  13570. if ( updateStyle !== false ) {
  13571. _canvas.style.width = width + 'px';
  13572. _canvas.style.height = height + 'px';
  13573. }
  13574. this.setViewport( 0, 0, width, height );
  13575. };
  13576. this.getDrawingBufferSize = function ( target ) {
  13577. if ( target === undefined ) {
  13578. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13579. target = new Vector2();
  13580. }
  13581. return target.set( _width * _pixelRatio, _height * _pixelRatio );
  13582. };
  13583. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13584. _width = width;
  13585. _height = height;
  13586. _pixelRatio = pixelRatio;
  13587. _canvas.width = width * pixelRatio;
  13588. _canvas.height = height * pixelRatio;
  13589. this.setViewport( 0, 0, width, height );
  13590. };
  13591. this.getCurrentViewport = function ( target ) {
  13592. if ( target === undefined ) {
  13593. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13594. target = new Vector4();
  13595. }
  13596. return target.copy( _currentViewport );
  13597. };
  13598. this.getViewport = function ( target ) {
  13599. return target.copy( _viewport );
  13600. };
  13601. this.setViewport = function ( x, y, width, height ) {
  13602. if ( x.isVector4 ) {
  13603. _viewport.set( x.x, x.y, x.z, x.w );
  13604. } else {
  13605. _viewport.set( x, y, width, height );
  13606. }
  13607. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13608. };
  13609. this.getScissor = function ( target ) {
  13610. return target.copy( _scissor );
  13611. };
  13612. this.setScissor = function ( x, y, width, height ) {
  13613. if ( x.isVector4 ) {
  13614. _scissor.set( x.x, x.y, x.z, x.w );
  13615. } else {
  13616. _scissor.set( x, y, width, height );
  13617. }
  13618. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13619. };
  13620. this.getScissorTest = function () {
  13621. return _scissorTest;
  13622. };
  13623. this.setScissorTest = function ( boolean ) {
  13624. state.setScissorTest( _scissorTest = boolean );
  13625. };
  13626. // Clearing
  13627. this.getClearColor = function () {
  13628. return background.getClearColor();
  13629. };
  13630. this.setClearColor = function () {
  13631. background.setClearColor.apply( background, arguments );
  13632. };
  13633. this.getClearAlpha = function () {
  13634. return background.getClearAlpha();
  13635. };
  13636. this.setClearAlpha = function () {
  13637. background.setClearAlpha.apply( background, arguments );
  13638. };
  13639. this.clear = function ( color, depth, stencil ) {
  13640. var bits = 0;
  13641. if ( color === undefined || color ) bits |= 16384;
  13642. if ( depth === undefined || depth ) bits |= 256;
  13643. if ( stencil === undefined || stencil ) bits |= 1024;
  13644. _gl.clear( bits );
  13645. };
  13646. this.clearColor = function () {
  13647. this.clear( true, false, false );
  13648. };
  13649. this.clearDepth = function () {
  13650. this.clear( false, true, false );
  13651. };
  13652. this.clearStencil = function () {
  13653. this.clear( false, false, true );
  13654. };
  13655. //
  13656. this.dispose = function () {
  13657. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13658. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13659. renderLists.dispose();
  13660. renderStates.dispose();
  13661. properties.dispose();
  13662. objects.dispose();
  13663. vr.dispose();
  13664. animation.stop();
  13665. };
  13666. // Events
  13667. function onContextLost( event ) {
  13668. event.preventDefault();
  13669. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13670. _isContextLost = true;
  13671. }
  13672. function onContextRestore( /* event */ ) {
  13673. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13674. _isContextLost = false;
  13675. initGLContext();
  13676. }
  13677. function onMaterialDispose( event ) {
  13678. var material = event.target;
  13679. material.removeEventListener( 'dispose', onMaterialDispose );
  13680. deallocateMaterial( material );
  13681. }
  13682. // Buffer deallocation
  13683. function deallocateMaterial( material ) {
  13684. releaseMaterialProgramReference( material );
  13685. properties.remove( material );
  13686. }
  13687. function releaseMaterialProgramReference( material ) {
  13688. var programInfo = properties.get( material ).program;
  13689. material.program = undefined;
  13690. if ( programInfo !== undefined ) {
  13691. programCache.releaseProgram( programInfo );
  13692. }
  13693. }
  13694. // Buffer rendering
  13695. function renderObjectImmediate( object, program ) {
  13696. object.render( function ( object ) {
  13697. _this.renderBufferImmediate( object, program );
  13698. } );
  13699. }
  13700. this.renderBufferImmediate = function ( object, program ) {
  13701. state.initAttributes();
  13702. var buffers = properties.get( object );
  13703. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13704. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13705. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13706. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13707. var programAttributes = program.getAttributes();
  13708. if ( object.hasPositions ) {
  13709. _gl.bindBuffer( 34962, buffers.position );
  13710. _gl.bufferData( 34962, object.positionArray, 35048 );
  13711. state.enableAttribute( programAttributes.position );
  13712. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  13713. }
  13714. if ( object.hasNormals ) {
  13715. _gl.bindBuffer( 34962, buffers.normal );
  13716. _gl.bufferData( 34962, object.normalArray, 35048 );
  13717. state.enableAttribute( programAttributes.normal );
  13718. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  13719. }
  13720. if ( object.hasUvs ) {
  13721. _gl.bindBuffer( 34962, buffers.uv );
  13722. _gl.bufferData( 34962, object.uvArray, 35048 );
  13723. state.enableAttribute( programAttributes.uv );
  13724. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  13725. }
  13726. if ( object.hasColors ) {
  13727. _gl.bindBuffer( 34962, buffers.color );
  13728. _gl.bufferData( 34962, object.colorArray, 35048 );
  13729. state.enableAttribute( programAttributes.color );
  13730. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  13731. }
  13732. state.disableUnusedAttributes();
  13733. _gl.drawArrays( 4, 0, object.count );
  13734. object.count = 0;
  13735. };
  13736. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13737. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13738. state.setMaterial( material, frontFaceCW );
  13739. var program = setProgram( camera, fog, material, object );
  13740. var updateBuffers = false;
  13741. if ( _currentGeometryProgram.geometry !== geometry.id ||
  13742. _currentGeometryProgram.program !== program.id ||
  13743. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  13744. _currentGeometryProgram.geometry = geometry.id;
  13745. _currentGeometryProgram.program = program.id;
  13746. _currentGeometryProgram.wireframe = material.wireframe === true;
  13747. updateBuffers = true;
  13748. }
  13749. if ( object.morphTargetInfluences ) {
  13750. morphtargets.update( object, geometry, material, program );
  13751. updateBuffers = true;
  13752. }
  13753. //
  13754. var index = geometry.index;
  13755. var position = geometry.attributes.position;
  13756. var rangeFactor = 1;
  13757. if ( material.wireframe === true ) {
  13758. index = geometries.getWireframeAttribute( geometry );
  13759. rangeFactor = 2;
  13760. }
  13761. var attribute;
  13762. var renderer = bufferRenderer;
  13763. if ( index !== null ) {
  13764. attribute = attributes.get( index );
  13765. renderer = indexedBufferRenderer;
  13766. renderer.setIndex( attribute );
  13767. }
  13768. if ( updateBuffers ) {
  13769. setupVertexAttributes( material, program, geometry );
  13770. if ( index !== null ) {
  13771. _gl.bindBuffer( 34963, attribute.buffer );
  13772. }
  13773. }
  13774. //
  13775. var dataCount = Infinity;
  13776. if ( index !== null ) {
  13777. dataCount = index.count;
  13778. } else if ( position !== undefined ) {
  13779. dataCount = position.count;
  13780. }
  13781. var rangeStart = geometry.drawRange.start * rangeFactor;
  13782. var rangeCount = geometry.drawRange.count * rangeFactor;
  13783. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13784. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13785. var drawStart = Math.max( rangeStart, groupStart );
  13786. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13787. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13788. if ( drawCount === 0 ) return;
  13789. //
  13790. if ( object.isMesh ) {
  13791. if ( material.wireframe === true ) {
  13792. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13793. renderer.setMode( 1 );
  13794. } else {
  13795. switch ( object.drawMode ) {
  13796. case TrianglesDrawMode:
  13797. renderer.setMode( 4 );
  13798. break;
  13799. case TriangleStripDrawMode:
  13800. renderer.setMode( 5 );
  13801. break;
  13802. case TriangleFanDrawMode:
  13803. renderer.setMode( 6 );
  13804. break;
  13805. }
  13806. }
  13807. } else if ( object.isLine ) {
  13808. var lineWidth = material.linewidth;
  13809. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13810. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13811. if ( object.isLineSegments ) {
  13812. renderer.setMode( 1 );
  13813. } else if ( object.isLineLoop ) {
  13814. renderer.setMode( 2 );
  13815. } else {
  13816. renderer.setMode( 3 );
  13817. }
  13818. } else if ( object.isPoints ) {
  13819. renderer.setMode( 0 );
  13820. } else if ( object.isSprite ) {
  13821. renderer.setMode( 4 );
  13822. }
  13823. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13824. if ( geometry.maxInstancedCount > 0 ) {
  13825. renderer.renderInstances( geometry, drawStart, drawCount );
  13826. }
  13827. } else {
  13828. renderer.render( drawStart, drawCount );
  13829. }
  13830. };
  13831. function setupVertexAttributes( material, program, geometry ) {
  13832. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  13833. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13834. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13835. return;
  13836. }
  13837. }
  13838. state.initAttributes();
  13839. var geometryAttributes = geometry.attributes;
  13840. var programAttributes = program.getAttributes();
  13841. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13842. for ( var name in programAttributes ) {
  13843. var programAttribute = programAttributes[ name ];
  13844. if ( programAttribute >= 0 ) {
  13845. var geometryAttribute = geometryAttributes[ name ];
  13846. if ( geometryAttribute !== undefined ) {
  13847. var normalized = geometryAttribute.normalized;
  13848. var size = geometryAttribute.itemSize;
  13849. var attribute = attributes.get( geometryAttribute );
  13850. // TODO Attribute may not be available on context restore
  13851. if ( attribute === undefined ) continue;
  13852. var buffer = attribute.buffer;
  13853. var type = attribute.type;
  13854. var bytesPerElement = attribute.bytesPerElement;
  13855. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13856. var data = geometryAttribute.data;
  13857. var stride = data.stride;
  13858. var offset = geometryAttribute.offset;
  13859. if ( data && data.isInstancedInterleavedBuffer ) {
  13860. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13861. if ( geometry.maxInstancedCount === undefined ) {
  13862. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13863. }
  13864. } else {
  13865. state.enableAttribute( programAttribute );
  13866. }
  13867. _gl.bindBuffer( 34962, buffer );
  13868. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  13869. } else {
  13870. if ( geometryAttribute.isInstancedBufferAttribute ) {
  13871. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  13872. if ( geometry.maxInstancedCount === undefined ) {
  13873. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13874. }
  13875. } else {
  13876. state.enableAttribute( programAttribute );
  13877. }
  13878. _gl.bindBuffer( 34962, buffer );
  13879. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  13880. }
  13881. } else if ( materialDefaultAttributeValues !== undefined ) {
  13882. var value = materialDefaultAttributeValues[ name ];
  13883. if ( value !== undefined ) {
  13884. switch ( value.length ) {
  13885. case 2:
  13886. _gl.vertexAttrib2fv( programAttribute, value );
  13887. break;
  13888. case 3:
  13889. _gl.vertexAttrib3fv( programAttribute, value );
  13890. break;
  13891. case 4:
  13892. _gl.vertexAttrib4fv( programAttribute, value );
  13893. break;
  13894. default:
  13895. _gl.vertexAttrib1fv( programAttribute, value );
  13896. }
  13897. }
  13898. }
  13899. }
  13900. }
  13901. state.disableUnusedAttributes();
  13902. }
  13903. // Compile
  13904. this.compile = function ( scene, camera ) {
  13905. currentRenderState = renderStates.get( scene, camera );
  13906. currentRenderState.init();
  13907. scene.traverse( function ( object ) {
  13908. if ( object.isLight ) {
  13909. currentRenderState.pushLight( object );
  13910. if ( object.castShadow ) {
  13911. currentRenderState.pushShadow( object );
  13912. }
  13913. }
  13914. } );
  13915. currentRenderState.setupLights( camera );
  13916. scene.traverse( function ( object ) {
  13917. if ( object.material ) {
  13918. if ( Array.isArray( object.material ) ) {
  13919. for ( var i = 0; i < object.material.length; i ++ ) {
  13920. initMaterial( object.material[ i ], scene.fog, object );
  13921. }
  13922. } else {
  13923. initMaterial( object.material, scene.fog, object );
  13924. }
  13925. }
  13926. } );
  13927. };
  13928. // Animation Loop
  13929. var onAnimationFrameCallback = null;
  13930. function onAnimationFrame( time ) {
  13931. if ( vr.isPresenting() ) return;
  13932. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13933. }
  13934. var animation = new WebGLAnimation();
  13935. animation.setAnimationLoop( onAnimationFrame );
  13936. if ( typeof window !== 'undefined' ) animation.setContext( window );
  13937. this.setAnimationLoop = function ( callback ) {
  13938. onAnimationFrameCallback = callback;
  13939. vr.setAnimationLoop( callback );
  13940. animation.start();
  13941. };
  13942. // Rendering
  13943. this.render = function ( scene, camera ) {
  13944. var renderTarget, forceClear;
  13945. if ( arguments[ 2 ] !== undefined ) {
  13946. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  13947. renderTarget = arguments[ 2 ];
  13948. }
  13949. if ( arguments[ 3 ] !== undefined ) {
  13950. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  13951. forceClear = arguments[ 3 ];
  13952. }
  13953. if ( ! ( camera && camera.isCamera ) ) {
  13954. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13955. return;
  13956. }
  13957. if ( _isContextLost ) return;
  13958. // reset caching for this frame
  13959. _currentGeometryProgram.geometry = null;
  13960. _currentGeometryProgram.program = null;
  13961. _currentGeometryProgram.wireframe = false;
  13962. _currentMaterialId = - 1;
  13963. _currentCamera = null;
  13964. // update scene graph
  13965. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13966. // update camera matrices and frustum
  13967. if ( camera.parent === null ) camera.updateMatrixWorld();
  13968. if ( vr.enabled ) {
  13969. camera = vr.getCamera( camera );
  13970. }
  13971. //
  13972. currentRenderState = renderStates.get( scene, camera );
  13973. currentRenderState.init();
  13974. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  13975. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13976. _frustum.setFromMatrix( _projScreenMatrix );
  13977. _localClippingEnabled = this.localClippingEnabled;
  13978. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  13979. currentRenderList = renderLists.get( scene, camera );
  13980. currentRenderList.init();
  13981. projectObject( scene, camera, 0, _this.sortObjects );
  13982. if ( _this.sortObjects === true ) {
  13983. currentRenderList.sort();
  13984. }
  13985. //
  13986. if ( _clippingEnabled ) _clipping.beginShadows();
  13987. var shadowsArray = currentRenderState.state.shadowsArray;
  13988. shadowMap.render( shadowsArray, scene, camera );
  13989. currentRenderState.setupLights( camera );
  13990. if ( _clippingEnabled ) _clipping.endShadows();
  13991. //
  13992. if ( this.info.autoReset ) this.info.reset();
  13993. if ( renderTarget !== undefined ) {
  13994. this.setRenderTarget( renderTarget );
  13995. }
  13996. //
  13997. background.render( currentRenderList, scene, camera, forceClear );
  13998. // render scene
  13999. var opaqueObjects = currentRenderList.opaque;
  14000. var transparentObjects = currentRenderList.transparent;
  14001. if ( scene.overrideMaterial ) {
  14002. var overrideMaterial = scene.overrideMaterial;
  14003. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14004. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14005. } else {
  14006. // opaque pass (front-to-back order)
  14007. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14008. // transparent pass (back-to-front order)
  14009. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14010. }
  14011. //
  14012. if ( _currentRenderTarget !== null ) {
  14013. // Generate mipmap if we're using any kind of mipmap filtering
  14014. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14015. // resolve multisample renderbuffers to a single-sample texture if necessary
  14016. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14017. }
  14018. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14019. state.buffers.depth.setTest( true );
  14020. state.buffers.depth.setMask( true );
  14021. state.buffers.color.setMask( true );
  14022. state.setPolygonOffset( false );
  14023. scene.onAfterRender( _this, scene, camera );
  14024. if ( vr.enabled ) {
  14025. vr.submitFrame();
  14026. }
  14027. // _gl.finish();
  14028. currentRenderList = null;
  14029. currentRenderState = null;
  14030. };
  14031. function projectObject( object, camera, groupOrder, sortObjects ) {
  14032. if ( object.visible === false ) return;
  14033. var visible = object.layers.test( camera.layers );
  14034. if ( visible ) {
  14035. if ( object.isGroup ) {
  14036. groupOrder = object.renderOrder;
  14037. } else if ( object.isLight ) {
  14038. currentRenderState.pushLight( object );
  14039. if ( object.castShadow ) {
  14040. currentRenderState.pushShadow( object );
  14041. }
  14042. } else if ( object.isSprite ) {
  14043. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14044. if ( sortObjects ) {
  14045. _vector3.setFromMatrixPosition( object.matrixWorld )
  14046. .applyMatrix4( _projScreenMatrix );
  14047. }
  14048. var geometry = objects.update( object );
  14049. var material = object.material;
  14050. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14051. }
  14052. } else if ( object.isImmediateRenderObject ) {
  14053. if ( sortObjects ) {
  14054. _vector3.setFromMatrixPosition( object.matrixWorld )
  14055. .applyMatrix4( _projScreenMatrix );
  14056. }
  14057. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14058. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14059. if ( object.isSkinnedMesh ) {
  14060. object.skeleton.update();
  14061. }
  14062. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14063. if ( sortObjects ) {
  14064. _vector3.setFromMatrixPosition( object.matrixWorld )
  14065. .applyMatrix4( _projScreenMatrix );
  14066. }
  14067. var geometry = objects.update( object );
  14068. var material = object.material;
  14069. if ( Array.isArray( material ) ) {
  14070. var groups = geometry.groups;
  14071. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14072. var group = groups[ i ];
  14073. var groupMaterial = material[ group.materialIndex ];
  14074. if ( groupMaterial && groupMaterial.visible ) {
  14075. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14076. }
  14077. }
  14078. } else if ( material.visible ) {
  14079. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14080. }
  14081. }
  14082. }
  14083. }
  14084. var children = object.children;
  14085. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14086. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14087. }
  14088. }
  14089. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14090. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14091. var renderItem = renderList[ i ];
  14092. var object = renderItem.object;
  14093. var geometry = renderItem.geometry;
  14094. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14095. var group = renderItem.group;
  14096. if ( camera.isArrayCamera ) {
  14097. _currentArrayCamera = camera;
  14098. var cameras = camera.cameras;
  14099. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14100. var camera2 = cameras[ j ];
  14101. if ( object.layers.test( camera2.layers ) ) {
  14102. if ( 'viewport' in camera2 ) { // XR
  14103. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14104. } else {
  14105. var bounds = camera2.bounds;
  14106. var x = bounds.x * _width;
  14107. var y = bounds.y * _height;
  14108. var width = bounds.z * _width;
  14109. var height = bounds.w * _height;
  14110. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  14111. }
  14112. currentRenderState.setupLights( camera2 );
  14113. renderObject( object, scene, camera2, geometry, material, group );
  14114. }
  14115. }
  14116. } else {
  14117. _currentArrayCamera = null;
  14118. renderObject( object, scene, camera, geometry, material, group );
  14119. }
  14120. }
  14121. }
  14122. function renderObject( object, scene, camera, geometry, material, group ) {
  14123. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14124. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14125. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14126. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14127. if ( object.isImmediateRenderObject ) {
  14128. state.setMaterial( material );
  14129. var program = setProgram( camera, scene.fog, material, object );
  14130. _currentGeometryProgram.geometry = null;
  14131. _currentGeometryProgram.program = null;
  14132. _currentGeometryProgram.wireframe = false;
  14133. renderObjectImmediate( object, program );
  14134. } else {
  14135. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14136. }
  14137. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14138. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14139. }
  14140. function initMaterial( material, fog, object ) {
  14141. var materialProperties = properties.get( material );
  14142. var lights = currentRenderState.state.lights;
  14143. var shadowsArray = currentRenderState.state.shadowsArray;
  14144. var lightsHash = materialProperties.lightsHash;
  14145. var lightsStateHash = lights.state.hash;
  14146. var parameters = programCache.getParameters(
  14147. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14148. var code = programCache.getProgramCode( material, parameters );
  14149. var program = materialProperties.program;
  14150. var programChange = true;
  14151. if ( program === undefined ) {
  14152. // new material
  14153. material.addEventListener( 'dispose', onMaterialDispose );
  14154. } else if ( program.code !== code ) {
  14155. // changed glsl or parameters
  14156. releaseMaterialProgramReference( material );
  14157. } else if ( lightsHash.stateID !== lightsStateHash.stateID ||
  14158. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14159. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14160. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14161. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14162. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14163. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) {
  14164. lightsHash.stateID = lightsStateHash.stateID;
  14165. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14166. lightsHash.pointLength = lightsStateHash.pointLength;
  14167. lightsHash.spotLength = lightsStateHash.spotLength;
  14168. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14169. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14170. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14171. programChange = false;
  14172. } else if ( parameters.shaderID !== undefined ) {
  14173. // same glsl and uniform list
  14174. return;
  14175. } else {
  14176. // only rebuild uniform list
  14177. programChange = false;
  14178. }
  14179. if ( programChange ) {
  14180. if ( parameters.shaderID ) {
  14181. var shader = ShaderLib[ parameters.shaderID ];
  14182. materialProperties.shader = {
  14183. name: material.type,
  14184. uniforms: cloneUniforms( shader.uniforms ),
  14185. vertexShader: shader.vertexShader,
  14186. fragmentShader: shader.fragmentShader
  14187. };
  14188. } else {
  14189. materialProperties.shader = {
  14190. name: material.type,
  14191. uniforms: material.uniforms,
  14192. vertexShader: material.vertexShader,
  14193. fragmentShader: material.fragmentShader
  14194. };
  14195. }
  14196. material.onBeforeCompile( materialProperties.shader, _this );
  14197. // Computing code again as onBeforeCompile may have changed the shaders
  14198. code = programCache.getProgramCode( material, parameters );
  14199. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14200. materialProperties.program = program;
  14201. material.program = program;
  14202. }
  14203. var programAttributes = program.getAttributes();
  14204. if ( material.morphTargets ) {
  14205. material.numSupportedMorphTargets = 0;
  14206. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14207. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14208. material.numSupportedMorphTargets ++;
  14209. }
  14210. }
  14211. }
  14212. if ( material.morphNormals ) {
  14213. material.numSupportedMorphNormals = 0;
  14214. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14215. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14216. material.numSupportedMorphNormals ++;
  14217. }
  14218. }
  14219. }
  14220. var uniforms = materialProperties.shader.uniforms;
  14221. if ( ! material.isShaderMaterial &&
  14222. ! material.isRawShaderMaterial ||
  14223. material.clipping === true ) {
  14224. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14225. materialProperties.numIntersection = _clipping.numIntersection;
  14226. uniforms.clippingPlanes = _clipping.uniform;
  14227. }
  14228. materialProperties.fog = fog;
  14229. // store the light setup it was created for
  14230. if ( lightsHash === undefined ) {
  14231. materialProperties.lightsHash = lightsHash = {};
  14232. }
  14233. lightsHash.stateID = lightsStateHash.stateID;
  14234. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14235. lightsHash.pointLength = lightsStateHash.pointLength;
  14236. lightsHash.spotLength = lightsStateHash.spotLength;
  14237. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14238. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14239. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14240. if ( material.lights ) {
  14241. // wire up the material to this renderer's lighting state
  14242. uniforms.ambientLightColor.value = lights.state.ambient;
  14243. uniforms.directionalLights.value = lights.state.directional;
  14244. uniforms.spotLights.value = lights.state.spot;
  14245. uniforms.rectAreaLights.value = lights.state.rectArea;
  14246. uniforms.pointLights.value = lights.state.point;
  14247. uniforms.hemisphereLights.value = lights.state.hemi;
  14248. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14249. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14250. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14251. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14252. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14253. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14254. // TODO (abelnation): add area lights shadow info to uniforms
  14255. }
  14256. var progUniforms = materialProperties.program.getUniforms(),
  14257. uniformsList =
  14258. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14259. materialProperties.uniformsList = uniformsList;
  14260. }
  14261. function setProgram( camera, fog, material, object ) {
  14262. _usedTextureUnits = 0;
  14263. var materialProperties = properties.get( material );
  14264. var lights = currentRenderState.state.lights;
  14265. var lightsHash = materialProperties.lightsHash;
  14266. var lightsStateHash = lights.state.hash;
  14267. if ( _clippingEnabled ) {
  14268. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14269. var useCache =
  14270. camera === _currentCamera &&
  14271. material.id === _currentMaterialId;
  14272. // we might want to call this function with some ClippingGroup
  14273. // object instead of the material, once it becomes feasible
  14274. // (#8465, #8379)
  14275. _clipping.setState(
  14276. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14277. camera, materialProperties, useCache );
  14278. }
  14279. }
  14280. if ( material.needsUpdate === false ) {
  14281. if ( materialProperties.program === undefined ) {
  14282. material.needsUpdate = true;
  14283. } else if ( material.fog && materialProperties.fog !== fog ) {
  14284. material.needsUpdate = true;
  14285. } else if ( material.lights && ( lightsHash.stateID !== lightsStateHash.stateID ||
  14286. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14287. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14288. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14289. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14290. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14291. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) ) {
  14292. material.needsUpdate = true;
  14293. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14294. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14295. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14296. material.needsUpdate = true;
  14297. }
  14298. }
  14299. if ( material.needsUpdate ) {
  14300. initMaterial( material, fog, object );
  14301. material.needsUpdate = false;
  14302. }
  14303. var refreshProgram = false;
  14304. var refreshMaterial = false;
  14305. var refreshLights = false;
  14306. var program = materialProperties.program,
  14307. p_uniforms = program.getUniforms(),
  14308. m_uniforms = materialProperties.shader.uniforms;
  14309. if ( state.useProgram( program.program ) ) {
  14310. refreshProgram = true;
  14311. refreshMaterial = true;
  14312. refreshLights = true;
  14313. }
  14314. if ( material.id !== _currentMaterialId ) {
  14315. _currentMaterialId = material.id;
  14316. refreshMaterial = true;
  14317. }
  14318. if ( refreshProgram || _currentCamera !== camera ) {
  14319. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14320. if ( capabilities.logarithmicDepthBuffer ) {
  14321. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14322. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14323. }
  14324. if ( _currentCamera !== camera ) {
  14325. _currentCamera = camera;
  14326. // lighting uniforms depend on the camera so enforce an update
  14327. // now, in case this material supports lights - or later, when
  14328. // the next material that does gets activated:
  14329. refreshMaterial = true; // set to true on material change
  14330. refreshLights = true; // remains set until update done
  14331. }
  14332. // load material specific uniforms
  14333. // (shader material also gets them for the sake of genericity)
  14334. if ( material.isShaderMaterial ||
  14335. material.isMeshPhongMaterial ||
  14336. material.isMeshStandardMaterial ||
  14337. material.envMap ) {
  14338. var uCamPos = p_uniforms.map.cameraPosition;
  14339. if ( uCamPos !== undefined ) {
  14340. uCamPos.setValue( _gl,
  14341. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14342. }
  14343. }
  14344. if ( material.isMeshPhongMaterial ||
  14345. material.isMeshLambertMaterial ||
  14346. material.isMeshBasicMaterial ||
  14347. material.isMeshStandardMaterial ||
  14348. material.isShaderMaterial ||
  14349. material.skinning ) {
  14350. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14351. }
  14352. }
  14353. // skinning uniforms must be set even if material didn't change
  14354. // auto-setting of texture unit for bone texture must go before other textures
  14355. // not sure why, but otherwise weird things happen
  14356. if ( material.skinning ) {
  14357. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14358. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14359. var skeleton = object.skeleton;
  14360. if ( skeleton ) {
  14361. var bones = skeleton.bones;
  14362. if ( capabilities.floatVertexTextures ) {
  14363. if ( skeleton.boneTexture === undefined ) {
  14364. // layout (1 matrix = 4 pixels)
  14365. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14366. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14367. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14368. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14369. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14370. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14371. size = _Math.ceilPowerOfTwo( size );
  14372. size = Math.max( size, 4 );
  14373. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14374. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14375. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14376. boneTexture.needsUpdate = true;
  14377. skeleton.boneMatrices = boneMatrices;
  14378. skeleton.boneTexture = boneTexture;
  14379. skeleton.boneTextureSize = size;
  14380. }
  14381. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  14382. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14383. } else {
  14384. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14385. }
  14386. }
  14387. }
  14388. if ( refreshMaterial ) {
  14389. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14390. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14391. if ( material.lights ) {
  14392. // the current material requires lighting info
  14393. // note: all lighting uniforms are always set correctly
  14394. // they simply reference the renderer's state for their
  14395. // values
  14396. //
  14397. // use the current material's .needsUpdate flags to set
  14398. // the GL state when required
  14399. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14400. }
  14401. // refresh uniforms common to several materials
  14402. if ( fog && material.fog ) {
  14403. refreshUniformsFog( m_uniforms, fog );
  14404. }
  14405. if ( material.isMeshBasicMaterial ) {
  14406. refreshUniformsCommon( m_uniforms, material );
  14407. } else if ( material.isMeshLambertMaterial ) {
  14408. refreshUniformsCommon( m_uniforms, material );
  14409. refreshUniformsLambert( m_uniforms, material );
  14410. } else if ( material.isMeshPhongMaterial ) {
  14411. refreshUniformsCommon( m_uniforms, material );
  14412. if ( material.isMeshToonMaterial ) {
  14413. refreshUniformsToon( m_uniforms, material );
  14414. } else {
  14415. refreshUniformsPhong( m_uniforms, material );
  14416. }
  14417. } else if ( material.isMeshStandardMaterial ) {
  14418. refreshUniformsCommon( m_uniforms, material );
  14419. if ( material.isMeshPhysicalMaterial ) {
  14420. refreshUniformsPhysical( m_uniforms, material );
  14421. } else {
  14422. refreshUniformsStandard( m_uniforms, material );
  14423. }
  14424. } else if ( material.isMeshMatcapMaterial ) {
  14425. refreshUniformsCommon( m_uniforms, material );
  14426. refreshUniformsMatcap( m_uniforms, material );
  14427. } else if ( material.isMeshDepthMaterial ) {
  14428. refreshUniformsCommon( m_uniforms, material );
  14429. refreshUniformsDepth( m_uniforms, material );
  14430. } else if ( material.isMeshDistanceMaterial ) {
  14431. refreshUniformsCommon( m_uniforms, material );
  14432. refreshUniformsDistance( m_uniforms, material );
  14433. } else if ( material.isMeshNormalMaterial ) {
  14434. refreshUniformsCommon( m_uniforms, material );
  14435. refreshUniformsNormal( m_uniforms, material );
  14436. } else if ( material.isLineBasicMaterial ) {
  14437. refreshUniformsLine( m_uniforms, material );
  14438. if ( material.isLineDashedMaterial ) {
  14439. refreshUniformsDash( m_uniforms, material );
  14440. }
  14441. } else if ( material.isPointsMaterial ) {
  14442. refreshUniformsPoints( m_uniforms, material );
  14443. } else if ( material.isSpriteMaterial ) {
  14444. refreshUniformsSprites( m_uniforms, material );
  14445. } else if ( material.isShadowMaterial ) {
  14446. m_uniforms.color.value = material.color;
  14447. m_uniforms.opacity.value = material.opacity;
  14448. }
  14449. // RectAreaLight Texture
  14450. // TODO (mrdoob): Find a nicer implementation
  14451. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14452. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14453. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  14454. }
  14455. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14456. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  14457. material.uniformsNeedUpdate = false;
  14458. }
  14459. if ( material.isSpriteMaterial ) {
  14460. p_uniforms.setValue( _gl, 'center', object.center );
  14461. }
  14462. // common matrices
  14463. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14464. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14465. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14466. return program;
  14467. }
  14468. // Uniforms (refresh uniforms objects)
  14469. function refreshUniformsCommon( uniforms, material ) {
  14470. uniforms.opacity.value = material.opacity;
  14471. if ( material.color ) {
  14472. uniforms.diffuse.value = material.color;
  14473. }
  14474. if ( material.emissive ) {
  14475. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14476. }
  14477. if ( material.map ) {
  14478. uniforms.map.value = material.map;
  14479. }
  14480. if ( material.alphaMap ) {
  14481. uniforms.alphaMap.value = material.alphaMap;
  14482. }
  14483. if ( material.specularMap ) {
  14484. uniforms.specularMap.value = material.specularMap;
  14485. }
  14486. if ( material.envMap ) {
  14487. uniforms.envMap.value = material.envMap;
  14488. // don't flip CubeTexture envMaps, flip everything else:
  14489. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14490. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14491. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14492. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14493. uniforms.reflectivity.value = material.reflectivity;
  14494. uniforms.refractionRatio.value = material.refractionRatio;
  14495. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14496. }
  14497. if ( material.lightMap ) {
  14498. uniforms.lightMap.value = material.lightMap;
  14499. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14500. }
  14501. if ( material.aoMap ) {
  14502. uniforms.aoMap.value = material.aoMap;
  14503. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14504. }
  14505. // uv repeat and offset setting priorities
  14506. // 1. color map
  14507. // 2. specular map
  14508. // 3. normal map
  14509. // 4. bump map
  14510. // 5. alpha map
  14511. // 6. emissive map
  14512. var uvScaleMap;
  14513. if ( material.map ) {
  14514. uvScaleMap = material.map;
  14515. } else if ( material.specularMap ) {
  14516. uvScaleMap = material.specularMap;
  14517. } else if ( material.displacementMap ) {
  14518. uvScaleMap = material.displacementMap;
  14519. } else if ( material.normalMap ) {
  14520. uvScaleMap = material.normalMap;
  14521. } else if ( material.bumpMap ) {
  14522. uvScaleMap = material.bumpMap;
  14523. } else if ( material.roughnessMap ) {
  14524. uvScaleMap = material.roughnessMap;
  14525. } else if ( material.metalnessMap ) {
  14526. uvScaleMap = material.metalnessMap;
  14527. } else if ( material.alphaMap ) {
  14528. uvScaleMap = material.alphaMap;
  14529. } else if ( material.emissiveMap ) {
  14530. uvScaleMap = material.emissiveMap;
  14531. }
  14532. if ( uvScaleMap !== undefined ) {
  14533. // backwards compatibility
  14534. if ( uvScaleMap.isWebGLRenderTarget ) {
  14535. uvScaleMap = uvScaleMap.texture;
  14536. }
  14537. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14538. uvScaleMap.updateMatrix();
  14539. }
  14540. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14541. }
  14542. }
  14543. function refreshUniformsLine( uniforms, material ) {
  14544. uniforms.diffuse.value = material.color;
  14545. uniforms.opacity.value = material.opacity;
  14546. }
  14547. function refreshUniformsDash( uniforms, material ) {
  14548. uniforms.dashSize.value = material.dashSize;
  14549. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14550. uniforms.scale.value = material.scale;
  14551. }
  14552. function refreshUniformsPoints( uniforms, material ) {
  14553. uniforms.diffuse.value = material.color;
  14554. uniforms.opacity.value = material.opacity;
  14555. uniforms.size.value = material.size * _pixelRatio;
  14556. uniforms.scale.value = _height * 0.5;
  14557. uniforms.map.value = material.map;
  14558. if ( material.map !== null ) {
  14559. if ( material.map.matrixAutoUpdate === true ) {
  14560. material.map.updateMatrix();
  14561. }
  14562. uniforms.uvTransform.value.copy( material.map.matrix );
  14563. }
  14564. }
  14565. function refreshUniformsSprites( uniforms, material ) {
  14566. uniforms.diffuse.value = material.color;
  14567. uniforms.opacity.value = material.opacity;
  14568. uniforms.rotation.value = material.rotation;
  14569. uniforms.map.value = material.map;
  14570. if ( material.map !== null ) {
  14571. if ( material.map.matrixAutoUpdate === true ) {
  14572. material.map.updateMatrix();
  14573. }
  14574. uniforms.uvTransform.value.copy( material.map.matrix );
  14575. }
  14576. }
  14577. function refreshUniformsFog( uniforms, fog ) {
  14578. uniforms.fogColor.value = fog.color;
  14579. if ( fog.isFog ) {
  14580. uniforms.fogNear.value = fog.near;
  14581. uniforms.fogFar.value = fog.far;
  14582. } else if ( fog.isFogExp2 ) {
  14583. uniforms.fogDensity.value = fog.density;
  14584. }
  14585. }
  14586. function refreshUniformsLambert( uniforms, material ) {
  14587. if ( material.emissiveMap ) {
  14588. uniforms.emissiveMap.value = material.emissiveMap;
  14589. }
  14590. }
  14591. function refreshUniformsPhong( uniforms, material ) {
  14592. uniforms.specular.value = material.specular;
  14593. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14594. if ( material.emissiveMap ) {
  14595. uniforms.emissiveMap.value = material.emissiveMap;
  14596. }
  14597. if ( material.bumpMap ) {
  14598. uniforms.bumpMap.value = material.bumpMap;
  14599. uniforms.bumpScale.value = material.bumpScale;
  14600. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14601. }
  14602. if ( material.normalMap ) {
  14603. uniforms.normalMap.value = material.normalMap;
  14604. uniforms.normalScale.value.copy( material.normalScale );
  14605. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14606. }
  14607. if ( material.displacementMap ) {
  14608. uniforms.displacementMap.value = material.displacementMap;
  14609. uniforms.displacementScale.value = material.displacementScale;
  14610. uniforms.displacementBias.value = material.displacementBias;
  14611. }
  14612. }
  14613. function refreshUniformsToon( uniforms, material ) {
  14614. refreshUniformsPhong( uniforms, material );
  14615. if ( material.gradientMap ) {
  14616. uniforms.gradientMap.value = material.gradientMap;
  14617. }
  14618. }
  14619. function refreshUniformsStandard( uniforms, material ) {
  14620. uniforms.roughness.value = material.roughness;
  14621. uniforms.metalness.value = material.metalness;
  14622. if ( material.roughnessMap ) {
  14623. uniforms.roughnessMap.value = material.roughnessMap;
  14624. }
  14625. if ( material.metalnessMap ) {
  14626. uniforms.metalnessMap.value = material.metalnessMap;
  14627. }
  14628. if ( material.emissiveMap ) {
  14629. uniforms.emissiveMap.value = material.emissiveMap;
  14630. }
  14631. if ( material.bumpMap ) {
  14632. uniforms.bumpMap.value = material.bumpMap;
  14633. uniforms.bumpScale.value = material.bumpScale;
  14634. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14635. }
  14636. if ( material.normalMap ) {
  14637. uniforms.normalMap.value = material.normalMap;
  14638. uniforms.normalScale.value.copy( material.normalScale );
  14639. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14640. }
  14641. if ( material.displacementMap ) {
  14642. uniforms.displacementMap.value = material.displacementMap;
  14643. uniforms.displacementScale.value = material.displacementScale;
  14644. uniforms.displacementBias.value = material.displacementBias;
  14645. }
  14646. if ( material.envMap ) {
  14647. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14648. uniforms.envMapIntensity.value = material.envMapIntensity;
  14649. }
  14650. }
  14651. function refreshUniformsPhysical( uniforms, material ) {
  14652. refreshUniformsStandard( uniforms, material );
  14653. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14654. uniforms.clearCoat.value = material.clearCoat;
  14655. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14656. }
  14657. function refreshUniformsMatcap( uniforms, material ) {
  14658. if ( material.matcap ) {
  14659. uniforms.matcap.value = material.matcap;
  14660. }
  14661. if ( material.bumpMap ) {
  14662. uniforms.bumpMap.value = material.bumpMap;
  14663. uniforms.bumpScale.value = material.bumpScale;
  14664. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14665. }
  14666. if ( material.normalMap ) {
  14667. uniforms.normalMap.value = material.normalMap;
  14668. uniforms.normalScale.value.copy( material.normalScale );
  14669. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14670. }
  14671. if ( material.displacementMap ) {
  14672. uniforms.displacementMap.value = material.displacementMap;
  14673. uniforms.displacementScale.value = material.displacementScale;
  14674. uniforms.displacementBias.value = material.displacementBias;
  14675. }
  14676. }
  14677. function refreshUniformsDepth( uniforms, material ) {
  14678. if ( material.displacementMap ) {
  14679. uniforms.displacementMap.value = material.displacementMap;
  14680. uniforms.displacementScale.value = material.displacementScale;
  14681. uniforms.displacementBias.value = material.displacementBias;
  14682. }
  14683. }
  14684. function refreshUniformsDistance( uniforms, material ) {
  14685. if ( material.displacementMap ) {
  14686. uniforms.displacementMap.value = material.displacementMap;
  14687. uniforms.displacementScale.value = material.displacementScale;
  14688. uniforms.displacementBias.value = material.displacementBias;
  14689. }
  14690. uniforms.referencePosition.value.copy( material.referencePosition );
  14691. uniforms.nearDistance.value = material.nearDistance;
  14692. uniforms.farDistance.value = material.farDistance;
  14693. }
  14694. function refreshUniformsNormal( uniforms, material ) {
  14695. if ( material.bumpMap ) {
  14696. uniforms.bumpMap.value = material.bumpMap;
  14697. uniforms.bumpScale.value = material.bumpScale;
  14698. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14699. }
  14700. if ( material.normalMap ) {
  14701. uniforms.normalMap.value = material.normalMap;
  14702. uniforms.normalScale.value.copy( material.normalScale );
  14703. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14704. }
  14705. if ( material.displacementMap ) {
  14706. uniforms.displacementMap.value = material.displacementMap;
  14707. uniforms.displacementScale.value = material.displacementScale;
  14708. uniforms.displacementBias.value = material.displacementBias;
  14709. }
  14710. }
  14711. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14712. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14713. uniforms.ambientLightColor.needsUpdate = value;
  14714. uniforms.directionalLights.needsUpdate = value;
  14715. uniforms.pointLights.needsUpdate = value;
  14716. uniforms.spotLights.needsUpdate = value;
  14717. uniforms.rectAreaLights.needsUpdate = value;
  14718. uniforms.hemisphereLights.needsUpdate = value;
  14719. }
  14720. // Textures
  14721. function allocTextureUnit() {
  14722. var textureUnit = _usedTextureUnits;
  14723. if ( textureUnit >= capabilities.maxTextures ) {
  14724. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  14725. }
  14726. _usedTextureUnits += 1;
  14727. return textureUnit;
  14728. }
  14729. this.allocTextureUnit = allocTextureUnit;
  14730. // this.setTexture2D = setTexture2D;
  14731. this.setTexture2D = ( function () {
  14732. var warned = false;
  14733. // backwards compatibility: peel texture.texture
  14734. return function setTexture2D( texture, slot ) {
  14735. if ( texture && texture.isWebGLRenderTarget ) {
  14736. if ( ! warned ) {
  14737. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  14738. warned = true;
  14739. }
  14740. texture = texture.texture;
  14741. }
  14742. textures.setTexture2D( texture, slot );
  14743. };
  14744. }() );
  14745. this.setTexture3D = ( function () {
  14746. // backwards compatibility: peel texture.texture
  14747. return function setTexture3D( texture, slot ) {
  14748. textures.setTexture3D( texture, slot );
  14749. };
  14750. }() );
  14751. this.setTexture = ( function () {
  14752. var warned = false;
  14753. return function setTexture( texture, slot ) {
  14754. if ( ! warned ) {
  14755. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  14756. warned = true;
  14757. }
  14758. textures.setTexture2D( texture, slot );
  14759. };
  14760. }() );
  14761. this.setTextureCube = ( function () {
  14762. var warned = false;
  14763. return function setTextureCube( texture, slot ) {
  14764. // backwards compatibility: peel texture.texture
  14765. if ( texture && texture.isWebGLRenderTargetCube ) {
  14766. if ( ! warned ) {
  14767. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  14768. warned = true;
  14769. }
  14770. texture = texture.texture;
  14771. }
  14772. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  14773. // TODO: unify these code paths
  14774. if ( ( texture && texture.isCubeTexture ) ||
  14775. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14776. // CompressedTexture can have Array in image :/
  14777. // this function alone should take care of cube textures
  14778. textures.setTextureCube( texture, slot );
  14779. } else {
  14780. // assumed: texture property of THREE.WebGLRenderTargetCube
  14781. textures.setTextureCubeDynamic( texture, slot );
  14782. }
  14783. };
  14784. }() );
  14785. //
  14786. this.setFramebuffer = function ( value ) {
  14787. _framebuffer = value;
  14788. };
  14789. this.getRenderTarget = function () {
  14790. return _currentRenderTarget;
  14791. };
  14792. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipMapLevel ) {
  14793. _currentRenderTarget = renderTarget;
  14794. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14795. textures.setupRenderTarget( renderTarget );
  14796. }
  14797. var framebuffer = _framebuffer;
  14798. var isCube = false;
  14799. if ( renderTarget ) {
  14800. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14801. if ( renderTarget.isWebGLRenderTargetCube ) {
  14802. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  14803. isCube = true;
  14804. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14805. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14806. } else {
  14807. framebuffer = __webglFramebuffer;
  14808. }
  14809. _currentViewport.copy( renderTarget.viewport );
  14810. _currentScissor.copy( renderTarget.scissor );
  14811. _currentScissorTest = renderTarget.scissorTest;
  14812. } else {
  14813. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14814. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14815. _currentScissorTest = _scissorTest;
  14816. }
  14817. if ( _currentFramebuffer !== framebuffer ) {
  14818. _gl.bindFramebuffer( 36160, framebuffer );
  14819. _currentFramebuffer = framebuffer;
  14820. }
  14821. state.viewport( _currentViewport );
  14822. state.scissor( _currentScissor );
  14823. state.setScissorTest( _currentScissorTest );
  14824. if ( isCube ) {
  14825. var textureProperties = properties.get( renderTarget.texture );
  14826. _gl.framebufferTexture2D( 36160, 36064, 34069 + activeCubeFace || 0, textureProperties.__webglTexture, activeMipMapLevel || 0 );
  14827. }
  14828. };
  14829. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14830. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14831. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14832. return;
  14833. }
  14834. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14835. if ( framebuffer ) {
  14836. var restore = false;
  14837. if ( framebuffer !== _currentFramebuffer ) {
  14838. _gl.bindFramebuffer( 36160, framebuffer );
  14839. restore = true;
  14840. }
  14841. try {
  14842. var texture = renderTarget.texture;
  14843. var textureFormat = texture.format;
  14844. var textureType = texture.type;
  14845. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14846. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14847. return;
  14848. }
  14849. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14850. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14851. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14852. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14853. return;
  14854. }
  14855. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14856. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14857. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14858. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14859. }
  14860. } else {
  14861. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14862. }
  14863. } finally {
  14864. if ( restore ) {
  14865. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14866. }
  14867. }
  14868. }
  14869. };
  14870. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14871. var width = texture.image.width;
  14872. var height = texture.image.height;
  14873. var glFormat = utils.convert( texture.format );
  14874. this.setTexture2D( texture, 0 );
  14875. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14876. };
  14877. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14878. var width = srcTexture.image.width;
  14879. var height = srcTexture.image.height;
  14880. var glFormat = utils.convert( dstTexture.format );
  14881. var glType = utils.convert( dstTexture.type );
  14882. this.setTexture2D( dstTexture, 0 );
  14883. if ( srcTexture.isDataTexture ) {
  14884. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14885. } else {
  14886. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14887. }
  14888. };
  14889. }
  14890. /**
  14891. * @author mrdoob / http://mrdoob.com/
  14892. * @author alteredq / http://alteredqualia.com/
  14893. */
  14894. function FogExp2( color, density ) {
  14895. this.name = '';
  14896. this.color = new Color( color );
  14897. this.density = ( density !== undefined ) ? density : 0.00025;
  14898. }
  14899. Object.assign( FogExp2.prototype, {
  14900. isFogExp2: true,
  14901. clone: function () {
  14902. return new FogExp2( this.color, this.density );
  14903. },
  14904. toJSON: function ( /* meta */ ) {
  14905. return {
  14906. type: 'FogExp2',
  14907. color: this.color.getHex(),
  14908. density: this.density
  14909. };
  14910. }
  14911. } );
  14912. /**
  14913. * @author mrdoob / http://mrdoob.com/
  14914. * @author alteredq / http://alteredqualia.com/
  14915. */
  14916. function Fog( color, near, far ) {
  14917. this.name = '';
  14918. this.color = new Color( color );
  14919. this.near = ( near !== undefined ) ? near : 1;
  14920. this.far = ( far !== undefined ) ? far : 1000;
  14921. }
  14922. Object.assign( Fog.prototype, {
  14923. isFog: true,
  14924. clone: function () {
  14925. return new Fog( this.color, this.near, this.far );
  14926. },
  14927. toJSON: function ( /* meta */ ) {
  14928. return {
  14929. type: 'Fog',
  14930. color: this.color.getHex(),
  14931. near: this.near,
  14932. far: this.far
  14933. };
  14934. }
  14935. } );
  14936. /**
  14937. * @author mrdoob / http://mrdoob.com/
  14938. */
  14939. function Scene() {
  14940. Object3D.call( this );
  14941. this.type = 'Scene';
  14942. this.background = null;
  14943. this.fog = null;
  14944. this.overrideMaterial = null;
  14945. this.autoUpdate = true; // checked by the renderer
  14946. }
  14947. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14948. constructor: Scene,
  14949. isScene: true,
  14950. copy: function ( source, recursive ) {
  14951. Object3D.prototype.copy.call( this, source, recursive );
  14952. if ( source.background !== null ) this.background = source.background.clone();
  14953. if ( source.fog !== null ) this.fog = source.fog.clone();
  14954. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14955. this.autoUpdate = source.autoUpdate;
  14956. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14957. return this;
  14958. },
  14959. toJSON: function ( meta ) {
  14960. var data = Object3D.prototype.toJSON.call( this, meta );
  14961. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  14962. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  14963. return data;
  14964. },
  14965. dispose: function () {
  14966. this.dispatchEvent( { type: 'dispose' } );
  14967. }
  14968. } );
  14969. /**
  14970. * @author benaadams / https://twitter.com/ben_a_adams
  14971. */
  14972. function InterleavedBuffer( array, stride ) {
  14973. this.array = array;
  14974. this.stride = stride;
  14975. this.count = array !== undefined ? array.length / stride : 0;
  14976. this.dynamic = false;
  14977. this.updateRange = { offset: 0, count: - 1 };
  14978. this.version = 0;
  14979. }
  14980. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  14981. set: function ( value ) {
  14982. if ( value === true ) this.version ++;
  14983. }
  14984. } );
  14985. Object.assign( InterleavedBuffer.prototype, {
  14986. isInterleavedBuffer: true,
  14987. onUploadCallback: function () {},
  14988. setArray: function ( array ) {
  14989. if ( Array.isArray( array ) ) {
  14990. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  14991. }
  14992. this.count = array !== undefined ? array.length / this.stride : 0;
  14993. this.array = array;
  14994. return this;
  14995. },
  14996. setDynamic: function ( value ) {
  14997. this.dynamic = value;
  14998. return this;
  14999. },
  15000. copy: function ( source ) {
  15001. this.array = new source.array.constructor( source.array );
  15002. this.count = source.count;
  15003. this.stride = source.stride;
  15004. this.dynamic = source.dynamic;
  15005. return this;
  15006. },
  15007. copyAt: function ( index1, attribute, index2 ) {
  15008. index1 *= this.stride;
  15009. index2 *= attribute.stride;
  15010. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15011. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15012. }
  15013. return this;
  15014. },
  15015. set: function ( value, offset ) {
  15016. if ( offset === undefined ) offset = 0;
  15017. this.array.set( value, offset );
  15018. return this;
  15019. },
  15020. clone: function () {
  15021. return new this.constructor().copy( this );
  15022. },
  15023. onUpload: function ( callback ) {
  15024. this.onUploadCallback = callback;
  15025. return this;
  15026. }
  15027. } );
  15028. /**
  15029. * @author benaadams / https://twitter.com/ben_a_adams
  15030. */
  15031. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15032. this.data = interleavedBuffer;
  15033. this.itemSize = itemSize;
  15034. this.offset = offset;
  15035. this.normalized = normalized === true;
  15036. }
  15037. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15038. count: {
  15039. get: function () {
  15040. return this.data.count;
  15041. }
  15042. },
  15043. array: {
  15044. get: function () {
  15045. return this.data.array;
  15046. }
  15047. }
  15048. } );
  15049. Object.assign( InterleavedBufferAttribute.prototype, {
  15050. isInterleavedBufferAttribute: true,
  15051. setX: function ( index, x ) {
  15052. this.data.array[ index * this.data.stride + this.offset ] = x;
  15053. return this;
  15054. },
  15055. setY: function ( index, y ) {
  15056. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15057. return this;
  15058. },
  15059. setZ: function ( index, z ) {
  15060. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15061. return this;
  15062. },
  15063. setW: function ( index, w ) {
  15064. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15065. return this;
  15066. },
  15067. getX: function ( index ) {
  15068. return this.data.array[ index * this.data.stride + this.offset ];
  15069. },
  15070. getY: function ( index ) {
  15071. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15072. },
  15073. getZ: function ( index ) {
  15074. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15075. },
  15076. getW: function ( index ) {
  15077. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15078. },
  15079. setXY: function ( index, x, y ) {
  15080. index = index * this.data.stride + this.offset;
  15081. this.data.array[ index + 0 ] = x;
  15082. this.data.array[ index + 1 ] = y;
  15083. return this;
  15084. },
  15085. setXYZ: function ( index, x, y, z ) {
  15086. index = index * this.data.stride + this.offset;
  15087. this.data.array[ index + 0 ] = x;
  15088. this.data.array[ index + 1 ] = y;
  15089. this.data.array[ index + 2 ] = z;
  15090. return this;
  15091. },
  15092. setXYZW: function ( index, x, y, z, w ) {
  15093. index = index * this.data.stride + this.offset;
  15094. this.data.array[ index + 0 ] = x;
  15095. this.data.array[ index + 1 ] = y;
  15096. this.data.array[ index + 2 ] = z;
  15097. this.data.array[ index + 3 ] = w;
  15098. return this;
  15099. }
  15100. } );
  15101. /**
  15102. * @author alteredq / http://alteredqualia.com/
  15103. *
  15104. * parameters = {
  15105. * color: <hex>,
  15106. * map: new THREE.Texture( <Image> ),
  15107. * rotation: <float>,
  15108. * sizeAttenuation: <bool>
  15109. * }
  15110. */
  15111. function SpriteMaterial( parameters ) {
  15112. Material.call( this );
  15113. this.type = 'SpriteMaterial';
  15114. this.color = new Color( 0xffffff );
  15115. this.map = null;
  15116. this.rotation = 0;
  15117. this.sizeAttenuation = true;
  15118. this.lights = false;
  15119. this.transparent = true;
  15120. this.setValues( parameters );
  15121. }
  15122. SpriteMaterial.prototype = Object.create( Material.prototype );
  15123. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15124. SpriteMaterial.prototype.isSpriteMaterial = true;
  15125. SpriteMaterial.prototype.copy = function ( source ) {
  15126. Material.prototype.copy.call( this, source );
  15127. this.color.copy( source.color );
  15128. this.map = source.map;
  15129. this.rotation = source.rotation;
  15130. this.sizeAttenuation = source.sizeAttenuation;
  15131. return this;
  15132. };
  15133. /**
  15134. * @author mikael emtinger / http://gomo.se/
  15135. * @author alteredq / http://alteredqualia.com/
  15136. */
  15137. var geometry;
  15138. function Sprite( material ) {
  15139. Object3D.call( this );
  15140. this.type = 'Sprite';
  15141. if ( geometry === undefined ) {
  15142. geometry = new BufferGeometry();
  15143. var float32Array = new Float32Array( [
  15144. - 0.5, - 0.5, 0, 0, 0,
  15145. 0.5, - 0.5, 0, 1, 0,
  15146. 0.5, 0.5, 0, 1, 1,
  15147. - 0.5, 0.5, 0, 0, 1
  15148. ] );
  15149. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15150. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15151. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15152. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15153. }
  15154. this.geometry = geometry;
  15155. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15156. this.center = new Vector2( 0.5, 0.5 );
  15157. }
  15158. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15159. constructor: Sprite,
  15160. isSprite: true,
  15161. raycast: ( function () {
  15162. var intersectPoint = new Vector3();
  15163. var worldScale = new Vector3();
  15164. var mvPosition = new Vector3();
  15165. var alignedPosition = new Vector2();
  15166. var rotatedPosition = new Vector2();
  15167. var viewWorldMatrix = new Matrix4();
  15168. var vA = new Vector3();
  15169. var vB = new Vector3();
  15170. var vC = new Vector3();
  15171. var uvA = new Vector2();
  15172. var uvB = new Vector2();
  15173. var uvC = new Vector2();
  15174. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15175. // compute position in camera space
  15176. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15177. // to check if rotation is not zero
  15178. if ( sin !== undefined ) {
  15179. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15180. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15181. } else {
  15182. rotatedPosition.copy( alignedPosition );
  15183. }
  15184. vertexPosition.copy( mvPosition );
  15185. vertexPosition.x += rotatedPosition.x;
  15186. vertexPosition.y += rotatedPosition.y;
  15187. // transform to world space
  15188. vertexPosition.applyMatrix4( viewWorldMatrix );
  15189. }
  15190. return function raycast( raycaster, intersects ) {
  15191. worldScale.setFromMatrixScale( this.matrixWorld );
  15192. viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
  15193. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15194. var rotation = this.material.rotation;
  15195. var sin, cos;
  15196. if ( rotation !== 0 ) {
  15197. cos = Math.cos( rotation );
  15198. sin = Math.sin( rotation );
  15199. }
  15200. var center = this.center;
  15201. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15202. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15203. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15204. uvA.set( 0, 0 );
  15205. uvB.set( 1, 0 );
  15206. uvC.set( 1, 1 );
  15207. // check first triangle
  15208. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15209. if ( intersect === null ) {
  15210. // check second triangle
  15211. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15212. uvB.set( 0, 1 );
  15213. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15214. if ( intersect === null ) {
  15215. return;
  15216. }
  15217. }
  15218. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15219. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15220. intersects.push( {
  15221. distance: distance,
  15222. point: intersectPoint.clone(),
  15223. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15224. face: null,
  15225. object: this
  15226. } );
  15227. };
  15228. }() ),
  15229. clone: function () {
  15230. return new this.constructor( this.material ).copy( this );
  15231. },
  15232. copy: function ( source ) {
  15233. Object3D.prototype.copy.call( this, source );
  15234. if ( source.center !== undefined ) this.center.copy( source.center );
  15235. return this;
  15236. }
  15237. } );
  15238. /**
  15239. * @author mikael emtinger / http://gomo.se/
  15240. * @author alteredq / http://alteredqualia.com/
  15241. * @author mrdoob / http://mrdoob.com/
  15242. */
  15243. function LOD() {
  15244. Object3D.call( this );
  15245. this.type = 'LOD';
  15246. Object.defineProperties( this, {
  15247. levels: {
  15248. enumerable: true,
  15249. value: []
  15250. }
  15251. } );
  15252. }
  15253. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15254. constructor: LOD,
  15255. copy: function ( source ) {
  15256. Object3D.prototype.copy.call( this, source, false );
  15257. var levels = source.levels;
  15258. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15259. var level = levels[ i ];
  15260. this.addLevel( level.object.clone(), level.distance );
  15261. }
  15262. return this;
  15263. },
  15264. addLevel: function ( object, distance ) {
  15265. if ( distance === undefined ) distance = 0;
  15266. distance = Math.abs( distance );
  15267. var levels = this.levels;
  15268. for ( var l = 0; l < levels.length; l ++ ) {
  15269. if ( distance < levels[ l ].distance ) {
  15270. break;
  15271. }
  15272. }
  15273. levels.splice( l, 0, { distance: distance, object: object } );
  15274. this.add( object );
  15275. },
  15276. getObjectForDistance: function ( distance ) {
  15277. var levels = this.levels;
  15278. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15279. if ( distance < levels[ i ].distance ) {
  15280. break;
  15281. }
  15282. }
  15283. return levels[ i - 1 ].object;
  15284. },
  15285. raycast: ( function () {
  15286. var matrixPosition = new Vector3();
  15287. return function raycast( raycaster, intersects ) {
  15288. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15289. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15290. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15291. };
  15292. }() ),
  15293. update: function () {
  15294. var v1 = new Vector3();
  15295. var v2 = new Vector3();
  15296. return function update( camera ) {
  15297. var levels = this.levels;
  15298. if ( levels.length > 1 ) {
  15299. v1.setFromMatrixPosition( camera.matrixWorld );
  15300. v2.setFromMatrixPosition( this.matrixWorld );
  15301. var distance = v1.distanceTo( v2 );
  15302. levels[ 0 ].object.visible = true;
  15303. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15304. if ( distance >= levels[ i ].distance ) {
  15305. levels[ i - 1 ].object.visible = false;
  15306. levels[ i ].object.visible = true;
  15307. } else {
  15308. break;
  15309. }
  15310. }
  15311. for ( ; i < l; i ++ ) {
  15312. levels[ i ].object.visible = false;
  15313. }
  15314. }
  15315. };
  15316. }(),
  15317. toJSON: function ( meta ) {
  15318. var data = Object3D.prototype.toJSON.call( this, meta );
  15319. data.object.levels = [];
  15320. var levels = this.levels;
  15321. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15322. var level = levels[ i ];
  15323. data.object.levels.push( {
  15324. object: level.object.uuid,
  15325. distance: level.distance
  15326. } );
  15327. }
  15328. return data;
  15329. }
  15330. } );
  15331. /**
  15332. * @author mikael emtinger / http://gomo.se/
  15333. * @author alteredq / http://alteredqualia.com/
  15334. * @author ikerr / http://verold.com
  15335. */
  15336. function SkinnedMesh( geometry, material ) {
  15337. if ( geometry && geometry.isGeometry ) {
  15338. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15339. }
  15340. Mesh.call( this, geometry, material );
  15341. this.type = 'SkinnedMesh';
  15342. this.bindMode = 'attached';
  15343. this.bindMatrix = new Matrix4();
  15344. this.bindMatrixInverse = new Matrix4();
  15345. }
  15346. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15347. constructor: SkinnedMesh,
  15348. isSkinnedMesh: true,
  15349. bind: function ( skeleton, bindMatrix ) {
  15350. this.skeleton = skeleton;
  15351. if ( bindMatrix === undefined ) {
  15352. this.updateMatrixWorld( true );
  15353. this.skeleton.calculateInverses();
  15354. bindMatrix = this.matrixWorld;
  15355. }
  15356. this.bindMatrix.copy( bindMatrix );
  15357. this.bindMatrixInverse.getInverse( bindMatrix );
  15358. },
  15359. pose: function () {
  15360. this.skeleton.pose();
  15361. },
  15362. normalizeSkinWeights: function () {
  15363. var vector = new Vector4();
  15364. var skinWeight = this.geometry.attributes.skinWeight;
  15365. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15366. vector.x = skinWeight.getX( i );
  15367. vector.y = skinWeight.getY( i );
  15368. vector.z = skinWeight.getZ( i );
  15369. vector.w = skinWeight.getW( i );
  15370. var scale = 1.0 / vector.manhattanLength();
  15371. if ( scale !== Infinity ) {
  15372. vector.multiplyScalar( scale );
  15373. } else {
  15374. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15375. }
  15376. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15377. }
  15378. },
  15379. updateMatrixWorld: function ( force ) {
  15380. Mesh.prototype.updateMatrixWorld.call( this, force );
  15381. if ( this.bindMode === 'attached' ) {
  15382. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15383. } else if ( this.bindMode === 'detached' ) {
  15384. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15385. } else {
  15386. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15387. }
  15388. },
  15389. clone: function () {
  15390. return new this.constructor( this.geometry, this.material ).copy( this );
  15391. }
  15392. } );
  15393. /**
  15394. * @author mikael emtinger / http://gomo.se/
  15395. * @author alteredq / http://alteredqualia.com/
  15396. * @author michael guerrero / http://realitymeltdown.com
  15397. * @author ikerr / http://verold.com
  15398. */
  15399. function Skeleton( bones, boneInverses ) {
  15400. // copy the bone array
  15401. bones = bones || [];
  15402. this.bones = bones.slice( 0 );
  15403. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15404. // use the supplied bone inverses or calculate the inverses
  15405. if ( boneInverses === undefined ) {
  15406. this.calculateInverses();
  15407. } else {
  15408. if ( this.bones.length === boneInverses.length ) {
  15409. this.boneInverses = boneInverses.slice( 0 );
  15410. } else {
  15411. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15412. this.boneInverses = [];
  15413. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15414. this.boneInverses.push( new Matrix4() );
  15415. }
  15416. }
  15417. }
  15418. }
  15419. Object.assign( Skeleton.prototype, {
  15420. calculateInverses: function () {
  15421. this.boneInverses = [];
  15422. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15423. var inverse = new Matrix4();
  15424. if ( this.bones[ i ] ) {
  15425. inverse.getInverse( this.bones[ i ].matrixWorld );
  15426. }
  15427. this.boneInverses.push( inverse );
  15428. }
  15429. },
  15430. pose: function () {
  15431. var bone, i, il;
  15432. // recover the bind-time world matrices
  15433. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15434. bone = this.bones[ i ];
  15435. if ( bone ) {
  15436. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15437. }
  15438. }
  15439. // compute the local matrices, positions, rotations and scales
  15440. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15441. bone = this.bones[ i ];
  15442. if ( bone ) {
  15443. if ( bone.parent && bone.parent.isBone ) {
  15444. bone.matrix.getInverse( bone.parent.matrixWorld );
  15445. bone.matrix.multiply( bone.matrixWorld );
  15446. } else {
  15447. bone.matrix.copy( bone.matrixWorld );
  15448. }
  15449. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15450. }
  15451. }
  15452. },
  15453. update: ( function () {
  15454. var offsetMatrix = new Matrix4();
  15455. var identityMatrix = new Matrix4();
  15456. return function update() {
  15457. var bones = this.bones;
  15458. var boneInverses = this.boneInverses;
  15459. var boneMatrices = this.boneMatrices;
  15460. var boneTexture = this.boneTexture;
  15461. // flatten bone matrices to array
  15462. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15463. // compute the offset between the current and the original transform
  15464. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15465. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15466. offsetMatrix.toArray( boneMatrices, i * 16 );
  15467. }
  15468. if ( boneTexture !== undefined ) {
  15469. boneTexture.needsUpdate = true;
  15470. }
  15471. };
  15472. } )(),
  15473. clone: function () {
  15474. return new Skeleton( this.bones, this.boneInverses );
  15475. },
  15476. getBoneByName: function ( name ) {
  15477. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15478. var bone = this.bones[ i ];
  15479. if ( bone.name === name ) {
  15480. return bone;
  15481. }
  15482. }
  15483. return undefined;
  15484. }
  15485. } );
  15486. /**
  15487. * @author mikael emtinger / http://gomo.se/
  15488. * @author alteredq / http://alteredqualia.com/
  15489. * @author ikerr / http://verold.com
  15490. */
  15491. function Bone() {
  15492. Object3D.call( this );
  15493. this.type = 'Bone';
  15494. }
  15495. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15496. constructor: Bone,
  15497. isBone: true
  15498. } );
  15499. /**
  15500. * @author mrdoob / http://mrdoob.com/
  15501. * @author alteredq / http://alteredqualia.com/
  15502. *
  15503. * parameters = {
  15504. * color: <hex>,
  15505. * opacity: <float>,
  15506. *
  15507. * linewidth: <float>,
  15508. * linecap: "round",
  15509. * linejoin: "round"
  15510. * }
  15511. */
  15512. function LineBasicMaterial( parameters ) {
  15513. Material.call( this );
  15514. this.type = 'LineBasicMaterial';
  15515. this.color = new Color( 0xffffff );
  15516. this.linewidth = 1;
  15517. this.linecap = 'round';
  15518. this.linejoin = 'round';
  15519. this.lights = false;
  15520. this.setValues( parameters );
  15521. }
  15522. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15523. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15524. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15525. LineBasicMaterial.prototype.copy = function ( source ) {
  15526. Material.prototype.copy.call( this, source );
  15527. this.color.copy( source.color );
  15528. this.linewidth = source.linewidth;
  15529. this.linecap = source.linecap;
  15530. this.linejoin = source.linejoin;
  15531. return this;
  15532. };
  15533. /**
  15534. * @author mrdoob / http://mrdoob.com/
  15535. */
  15536. function Line( geometry, material, mode ) {
  15537. if ( mode === 1 ) {
  15538. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15539. }
  15540. Object3D.call( this );
  15541. this.type = 'Line';
  15542. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15543. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15544. }
  15545. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15546. constructor: Line,
  15547. isLine: true,
  15548. computeLineDistances: ( function () {
  15549. var start = new Vector3();
  15550. var end = new Vector3();
  15551. return function computeLineDistances() {
  15552. var geometry = this.geometry;
  15553. if ( geometry.isBufferGeometry ) {
  15554. // we assume non-indexed geometry
  15555. if ( geometry.index === null ) {
  15556. var positionAttribute = geometry.attributes.position;
  15557. var lineDistances = [ 0 ];
  15558. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15559. start.fromBufferAttribute( positionAttribute, i - 1 );
  15560. end.fromBufferAttribute( positionAttribute, i );
  15561. lineDistances[ i ] = lineDistances[ i - 1 ];
  15562. lineDistances[ i ] += start.distanceTo( end );
  15563. }
  15564. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15565. } else {
  15566. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15567. }
  15568. } else if ( geometry.isGeometry ) {
  15569. var vertices = geometry.vertices;
  15570. var lineDistances = geometry.lineDistances;
  15571. lineDistances[ 0 ] = 0;
  15572. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15573. lineDistances[ i ] = lineDistances[ i - 1 ];
  15574. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15575. }
  15576. }
  15577. return this;
  15578. };
  15579. }() ),
  15580. raycast: ( function () {
  15581. var inverseMatrix = new Matrix4();
  15582. var ray = new Ray();
  15583. var sphere = new Sphere();
  15584. return function raycast( raycaster, intersects ) {
  15585. var precision = raycaster.linePrecision;
  15586. var geometry = this.geometry;
  15587. var matrixWorld = this.matrixWorld;
  15588. // Checking boundingSphere distance to ray
  15589. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15590. sphere.copy( geometry.boundingSphere );
  15591. sphere.applyMatrix4( matrixWorld );
  15592. sphere.radius += precision;
  15593. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15594. //
  15595. inverseMatrix.getInverse( matrixWorld );
  15596. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15597. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15598. var localPrecisionSq = localPrecision * localPrecision;
  15599. var vStart = new Vector3();
  15600. var vEnd = new Vector3();
  15601. var interSegment = new Vector3();
  15602. var interRay = new Vector3();
  15603. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15604. if ( geometry.isBufferGeometry ) {
  15605. var index = geometry.index;
  15606. var attributes = geometry.attributes;
  15607. var positions = attributes.position.array;
  15608. if ( index !== null ) {
  15609. var indices = index.array;
  15610. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15611. var a = indices[ i ];
  15612. var b = indices[ i + 1 ];
  15613. vStart.fromArray( positions, a * 3 );
  15614. vEnd.fromArray( positions, b * 3 );
  15615. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15616. if ( distSq > localPrecisionSq ) continue;
  15617. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15618. var distance = raycaster.ray.origin.distanceTo( interRay );
  15619. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15620. intersects.push( {
  15621. distance: distance,
  15622. // What do we want? intersection point on the ray or on the segment??
  15623. // point: raycaster.ray.at( distance ),
  15624. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15625. index: i,
  15626. face: null,
  15627. faceIndex: null,
  15628. object: this
  15629. } );
  15630. }
  15631. } else {
  15632. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15633. vStart.fromArray( positions, 3 * i );
  15634. vEnd.fromArray( positions, 3 * i + 3 );
  15635. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15636. if ( distSq > localPrecisionSq ) continue;
  15637. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15638. var distance = raycaster.ray.origin.distanceTo( interRay );
  15639. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15640. intersects.push( {
  15641. distance: distance,
  15642. // What do we want? intersection point on the ray or on the segment??
  15643. // point: raycaster.ray.at( distance ),
  15644. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15645. index: i,
  15646. face: null,
  15647. faceIndex: null,
  15648. object: this
  15649. } );
  15650. }
  15651. }
  15652. } else if ( geometry.isGeometry ) {
  15653. var vertices = geometry.vertices;
  15654. var nbVertices = vertices.length;
  15655. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15656. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15657. if ( distSq > localPrecisionSq ) continue;
  15658. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15659. var distance = raycaster.ray.origin.distanceTo( interRay );
  15660. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15661. intersects.push( {
  15662. distance: distance,
  15663. // What do we want? intersection point on the ray or on the segment??
  15664. // point: raycaster.ray.at( distance ),
  15665. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15666. index: i,
  15667. face: null,
  15668. faceIndex: null,
  15669. object: this
  15670. } );
  15671. }
  15672. }
  15673. };
  15674. }() ),
  15675. copy: function ( source ) {
  15676. Object3D.prototype.copy.call( this, source );
  15677. this.geometry.copy( source.geometry );
  15678. this.material.copy( source.material );
  15679. return this;
  15680. },
  15681. clone: function () {
  15682. return new this.constructor().copy( this );
  15683. }
  15684. } );
  15685. /**
  15686. * @author mrdoob / http://mrdoob.com/
  15687. */
  15688. function LineSegments( geometry, material ) {
  15689. Line.call( this, geometry, material );
  15690. this.type = 'LineSegments';
  15691. }
  15692. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15693. constructor: LineSegments,
  15694. isLineSegments: true,
  15695. computeLineDistances: ( function () {
  15696. var start = new Vector3();
  15697. var end = new Vector3();
  15698. return function computeLineDistances() {
  15699. var geometry = this.geometry;
  15700. if ( geometry.isBufferGeometry ) {
  15701. // we assume non-indexed geometry
  15702. if ( geometry.index === null ) {
  15703. var positionAttribute = geometry.attributes.position;
  15704. var lineDistances = [];
  15705. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15706. start.fromBufferAttribute( positionAttribute, i );
  15707. end.fromBufferAttribute( positionAttribute, i + 1 );
  15708. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15709. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15710. }
  15711. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15712. } else {
  15713. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15714. }
  15715. } else if ( geometry.isGeometry ) {
  15716. var vertices = geometry.vertices;
  15717. var lineDistances = geometry.lineDistances;
  15718. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  15719. start.copy( vertices[ i ] );
  15720. end.copy( vertices[ i + 1 ] );
  15721. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15722. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15723. }
  15724. }
  15725. return this;
  15726. };
  15727. }() )
  15728. } );
  15729. /**
  15730. * @author mgreter / http://github.com/mgreter
  15731. */
  15732. function LineLoop( geometry, material ) {
  15733. Line.call( this, geometry, material );
  15734. this.type = 'LineLoop';
  15735. }
  15736. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15737. constructor: LineLoop,
  15738. isLineLoop: true,
  15739. } );
  15740. /**
  15741. * @author mrdoob / http://mrdoob.com/
  15742. * @author alteredq / http://alteredqualia.com/
  15743. *
  15744. * parameters = {
  15745. * color: <hex>,
  15746. * opacity: <float>,
  15747. * map: new THREE.Texture( <Image> ),
  15748. *
  15749. * size: <float>,
  15750. * sizeAttenuation: <bool>
  15751. *
  15752. * morphTargets: <bool>
  15753. * }
  15754. */
  15755. function PointsMaterial( parameters ) {
  15756. Material.call( this );
  15757. this.type = 'PointsMaterial';
  15758. this.color = new Color( 0xffffff );
  15759. this.map = null;
  15760. this.size = 1;
  15761. this.sizeAttenuation = true;
  15762. this.morphTargets = false;
  15763. this.lights = false;
  15764. this.setValues( parameters );
  15765. }
  15766. PointsMaterial.prototype = Object.create( Material.prototype );
  15767. PointsMaterial.prototype.constructor = PointsMaterial;
  15768. PointsMaterial.prototype.isPointsMaterial = true;
  15769. PointsMaterial.prototype.copy = function ( source ) {
  15770. Material.prototype.copy.call( this, source );
  15771. this.color.copy( source.color );
  15772. this.map = source.map;
  15773. this.size = source.size;
  15774. this.sizeAttenuation = source.sizeAttenuation;
  15775. this.morphTargets = source.morphTargets;
  15776. return this;
  15777. };
  15778. /**
  15779. * @author alteredq / http://alteredqualia.com/
  15780. */
  15781. function Points( geometry, material ) {
  15782. Object3D.call( this );
  15783. this.type = 'Points';
  15784. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15785. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15786. }
  15787. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15788. constructor: Points,
  15789. isPoints: true,
  15790. raycast: ( function () {
  15791. var inverseMatrix = new Matrix4();
  15792. var ray = new Ray();
  15793. var sphere = new Sphere();
  15794. return function raycast( raycaster, intersects ) {
  15795. var object = this;
  15796. var geometry = this.geometry;
  15797. var matrixWorld = this.matrixWorld;
  15798. var threshold = raycaster.params.Points.threshold;
  15799. // Checking boundingSphere distance to ray
  15800. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15801. sphere.copy( geometry.boundingSphere );
  15802. sphere.applyMatrix4( matrixWorld );
  15803. sphere.radius += threshold;
  15804. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15805. //
  15806. inverseMatrix.getInverse( matrixWorld );
  15807. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15808. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15809. var localThresholdSq = localThreshold * localThreshold;
  15810. var position = new Vector3();
  15811. var intersectPoint = new Vector3();
  15812. function testPoint( point, index ) {
  15813. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15814. if ( rayPointDistanceSq < localThresholdSq ) {
  15815. ray.closestPointToPoint( point, intersectPoint );
  15816. intersectPoint.applyMatrix4( matrixWorld );
  15817. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15818. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15819. intersects.push( {
  15820. distance: distance,
  15821. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15822. point: intersectPoint.clone(),
  15823. index: index,
  15824. face: null,
  15825. object: object
  15826. } );
  15827. }
  15828. }
  15829. if ( geometry.isBufferGeometry ) {
  15830. var index = geometry.index;
  15831. var attributes = geometry.attributes;
  15832. var positions = attributes.position.array;
  15833. if ( index !== null ) {
  15834. var indices = index.array;
  15835. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15836. var a = indices[ i ];
  15837. position.fromArray( positions, a * 3 );
  15838. testPoint( position, a );
  15839. }
  15840. } else {
  15841. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15842. position.fromArray( positions, i * 3 );
  15843. testPoint( position, i );
  15844. }
  15845. }
  15846. } else {
  15847. var vertices = geometry.vertices;
  15848. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15849. testPoint( vertices[ i ], i );
  15850. }
  15851. }
  15852. };
  15853. }() ),
  15854. clone: function () {
  15855. return new this.constructor( this.geometry, this.material ).copy( this );
  15856. }
  15857. } );
  15858. /**
  15859. * @author mrdoob / http://mrdoob.com/
  15860. */
  15861. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15862. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15863. this.format = format !== undefined ? format : RGBFormat;
  15864. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  15865. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  15866. this.generateMipmaps = false;
  15867. }
  15868. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15869. constructor: VideoTexture,
  15870. isVideoTexture: true,
  15871. update: function () {
  15872. var video = this.image;
  15873. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15874. this.needsUpdate = true;
  15875. }
  15876. }
  15877. } );
  15878. /**
  15879. * @author alteredq / http://alteredqualia.com/
  15880. */
  15881. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15882. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15883. this.image = { width: width, height: height };
  15884. this.mipmaps = mipmaps;
  15885. // no flipping for cube textures
  15886. // (also flipping doesn't work for compressed textures )
  15887. this.flipY = false;
  15888. // can't generate mipmaps for compressed textures
  15889. // mips must be embedded in DDS files
  15890. this.generateMipmaps = false;
  15891. }
  15892. CompressedTexture.prototype = Object.create( Texture.prototype );
  15893. CompressedTexture.prototype.constructor = CompressedTexture;
  15894. CompressedTexture.prototype.isCompressedTexture = true;
  15895. /**
  15896. * @author mrdoob / http://mrdoob.com/
  15897. */
  15898. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15899. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15900. this.needsUpdate = true;
  15901. }
  15902. CanvasTexture.prototype = Object.create( Texture.prototype );
  15903. CanvasTexture.prototype.constructor = CanvasTexture;
  15904. CanvasTexture.prototype.isCanvasTexture = true;
  15905. /**
  15906. * @author Matt DesLauriers / @mattdesl
  15907. * @author atix / arthursilber.de
  15908. */
  15909. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15910. format = format !== undefined ? format : DepthFormat;
  15911. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15912. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15913. }
  15914. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15915. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15916. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15917. this.image = { width: width, height: height };
  15918. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  15919. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  15920. this.flipY = false;
  15921. this.generateMipmaps = false;
  15922. }
  15923. DepthTexture.prototype = Object.create( Texture.prototype );
  15924. DepthTexture.prototype.constructor = DepthTexture;
  15925. DepthTexture.prototype.isDepthTexture = true;
  15926. /**
  15927. * @author mrdoob / http://mrdoob.com/
  15928. * @author Mugen87 / https://github.com/Mugen87
  15929. */
  15930. function WireframeGeometry( geometry ) {
  15931. BufferGeometry.call( this );
  15932. this.type = 'WireframeGeometry';
  15933. // buffer
  15934. var vertices = [];
  15935. // helper variables
  15936. var i, j, l, o, ol;
  15937. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  15938. var key, keys = [ 'a', 'b', 'c' ];
  15939. var vertex;
  15940. // different logic for Geometry and BufferGeometry
  15941. if ( geometry && geometry.isGeometry ) {
  15942. // create a data structure that contains all edges without duplicates
  15943. var faces = geometry.faces;
  15944. for ( i = 0, l = faces.length; i < l; i ++ ) {
  15945. var face = faces[ i ];
  15946. for ( j = 0; j < 3; j ++ ) {
  15947. edge1 = face[ keys[ j ] ];
  15948. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  15949. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15950. edge[ 1 ] = Math.max( edge1, edge2 );
  15951. key = edge[ 0 ] + ',' + edge[ 1 ];
  15952. if ( edges[ key ] === undefined ) {
  15953. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15954. }
  15955. }
  15956. }
  15957. // generate vertices
  15958. for ( key in edges ) {
  15959. e = edges[ key ];
  15960. vertex = geometry.vertices[ e.index1 ];
  15961. vertices.push( vertex.x, vertex.y, vertex.z );
  15962. vertex = geometry.vertices[ e.index2 ];
  15963. vertices.push( vertex.x, vertex.y, vertex.z );
  15964. }
  15965. } else if ( geometry && geometry.isBufferGeometry ) {
  15966. var position, indices, groups;
  15967. var group, start, count;
  15968. var index1, index2;
  15969. vertex = new Vector3();
  15970. if ( geometry.index !== null ) {
  15971. // indexed BufferGeometry
  15972. position = geometry.attributes.position;
  15973. indices = geometry.index;
  15974. groups = geometry.groups;
  15975. if ( groups.length === 0 ) {
  15976. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  15977. }
  15978. // create a data structure that contains all eges without duplicates
  15979. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  15980. group = groups[ o ];
  15981. start = group.start;
  15982. count = group.count;
  15983. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  15984. for ( j = 0; j < 3; j ++ ) {
  15985. edge1 = indices.getX( i + j );
  15986. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  15987. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15988. edge[ 1 ] = Math.max( edge1, edge2 );
  15989. key = edge[ 0 ] + ',' + edge[ 1 ];
  15990. if ( edges[ key ] === undefined ) {
  15991. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15992. }
  15993. }
  15994. }
  15995. }
  15996. // generate vertices
  15997. for ( key in edges ) {
  15998. e = edges[ key ];
  15999. vertex.fromBufferAttribute( position, e.index1 );
  16000. vertices.push( vertex.x, vertex.y, vertex.z );
  16001. vertex.fromBufferAttribute( position, e.index2 );
  16002. vertices.push( vertex.x, vertex.y, vertex.z );
  16003. }
  16004. } else {
  16005. // non-indexed BufferGeometry
  16006. position = geometry.attributes.position;
  16007. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16008. for ( j = 0; j < 3; j ++ ) {
  16009. // three edges per triangle, an edge is represented as (index1, index2)
  16010. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16011. index1 = 3 * i + j;
  16012. vertex.fromBufferAttribute( position, index1 );
  16013. vertices.push( vertex.x, vertex.y, vertex.z );
  16014. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16015. vertex.fromBufferAttribute( position, index2 );
  16016. vertices.push( vertex.x, vertex.y, vertex.z );
  16017. }
  16018. }
  16019. }
  16020. }
  16021. // build geometry
  16022. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16023. }
  16024. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16025. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16026. /**
  16027. * @author zz85 / https://github.com/zz85
  16028. * @author Mugen87 / https://github.com/Mugen87
  16029. *
  16030. * Parametric Surfaces Geometry
  16031. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16032. */
  16033. // ParametricGeometry
  16034. function ParametricGeometry( func, slices, stacks ) {
  16035. Geometry.call( this );
  16036. this.type = 'ParametricGeometry';
  16037. this.parameters = {
  16038. func: func,
  16039. slices: slices,
  16040. stacks: stacks
  16041. };
  16042. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16043. this.mergeVertices();
  16044. }
  16045. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16046. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16047. // ParametricBufferGeometry
  16048. function ParametricBufferGeometry( func, slices, stacks ) {
  16049. BufferGeometry.call( this );
  16050. this.type = 'ParametricBufferGeometry';
  16051. this.parameters = {
  16052. func: func,
  16053. slices: slices,
  16054. stacks: stacks
  16055. };
  16056. // buffers
  16057. var indices = [];
  16058. var vertices = [];
  16059. var normals = [];
  16060. var uvs = [];
  16061. var EPS = 0.00001;
  16062. var normal = new Vector3();
  16063. var p0 = new Vector3(), p1 = new Vector3();
  16064. var pu = new Vector3(), pv = new Vector3();
  16065. var i, j;
  16066. if ( func.length < 3 ) {
  16067. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16068. }
  16069. // generate vertices, normals and uvs
  16070. var sliceCount = slices + 1;
  16071. for ( i = 0; i <= stacks; i ++ ) {
  16072. var v = i / stacks;
  16073. for ( j = 0; j <= slices; j ++ ) {
  16074. var u = j / slices;
  16075. // vertex
  16076. func( u, v, p0 );
  16077. vertices.push( p0.x, p0.y, p0.z );
  16078. // normal
  16079. // approximate tangent vectors via finite differences
  16080. if ( u - EPS >= 0 ) {
  16081. func( u - EPS, v, p1 );
  16082. pu.subVectors( p0, p1 );
  16083. } else {
  16084. func( u + EPS, v, p1 );
  16085. pu.subVectors( p1, p0 );
  16086. }
  16087. if ( v - EPS >= 0 ) {
  16088. func( u, v - EPS, p1 );
  16089. pv.subVectors( p0, p1 );
  16090. } else {
  16091. func( u, v + EPS, p1 );
  16092. pv.subVectors( p1, p0 );
  16093. }
  16094. // cross product of tangent vectors returns surface normal
  16095. normal.crossVectors( pu, pv ).normalize();
  16096. normals.push( normal.x, normal.y, normal.z );
  16097. // uv
  16098. uvs.push( u, v );
  16099. }
  16100. }
  16101. // generate indices
  16102. for ( i = 0; i < stacks; i ++ ) {
  16103. for ( j = 0; j < slices; j ++ ) {
  16104. var a = i * sliceCount + j;
  16105. var b = i * sliceCount + j + 1;
  16106. var c = ( i + 1 ) * sliceCount + j + 1;
  16107. var d = ( i + 1 ) * sliceCount + j;
  16108. // faces one and two
  16109. indices.push( a, b, d );
  16110. indices.push( b, c, d );
  16111. }
  16112. }
  16113. // build geometry
  16114. this.setIndex( indices );
  16115. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16116. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16117. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16118. }
  16119. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16120. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16121. /**
  16122. * @author clockworkgeek / https://github.com/clockworkgeek
  16123. * @author timothypratley / https://github.com/timothypratley
  16124. * @author WestLangley / http://github.com/WestLangley
  16125. * @author Mugen87 / https://github.com/Mugen87
  16126. */
  16127. // PolyhedronGeometry
  16128. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16129. Geometry.call( this );
  16130. this.type = 'PolyhedronGeometry';
  16131. this.parameters = {
  16132. vertices: vertices,
  16133. indices: indices,
  16134. radius: radius,
  16135. detail: detail
  16136. };
  16137. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16138. this.mergeVertices();
  16139. }
  16140. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16141. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16142. // PolyhedronBufferGeometry
  16143. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16144. BufferGeometry.call( this );
  16145. this.type = 'PolyhedronBufferGeometry';
  16146. this.parameters = {
  16147. vertices: vertices,
  16148. indices: indices,
  16149. radius: radius,
  16150. detail: detail
  16151. };
  16152. radius = radius || 1;
  16153. detail = detail || 0;
  16154. // default buffer data
  16155. var vertexBuffer = [];
  16156. var uvBuffer = [];
  16157. // the subdivision creates the vertex buffer data
  16158. subdivide( detail );
  16159. // all vertices should lie on a conceptual sphere with a given radius
  16160. appplyRadius( radius );
  16161. // finally, create the uv data
  16162. generateUVs();
  16163. // build non-indexed geometry
  16164. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16165. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16166. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16167. if ( detail === 0 ) {
  16168. this.computeVertexNormals(); // flat normals
  16169. } else {
  16170. this.normalizeNormals(); // smooth normals
  16171. }
  16172. // helper functions
  16173. function subdivide( detail ) {
  16174. var a = new Vector3();
  16175. var b = new Vector3();
  16176. var c = new Vector3();
  16177. // iterate over all faces and apply a subdivison with the given detail value
  16178. for ( var i = 0; i < indices.length; i += 3 ) {
  16179. // get the vertices of the face
  16180. getVertexByIndex( indices[ i + 0 ], a );
  16181. getVertexByIndex( indices[ i + 1 ], b );
  16182. getVertexByIndex( indices[ i + 2 ], c );
  16183. // perform subdivision
  16184. subdivideFace( a, b, c, detail );
  16185. }
  16186. }
  16187. function subdivideFace( a, b, c, detail ) {
  16188. var cols = Math.pow( 2, detail );
  16189. // we use this multidimensional array as a data structure for creating the subdivision
  16190. var v = [];
  16191. var i, j;
  16192. // construct all of the vertices for this subdivision
  16193. for ( i = 0; i <= cols; i ++ ) {
  16194. v[ i ] = [];
  16195. var aj = a.clone().lerp( c, i / cols );
  16196. var bj = b.clone().lerp( c, i / cols );
  16197. var rows = cols - i;
  16198. for ( j = 0; j <= rows; j ++ ) {
  16199. if ( j === 0 && i === cols ) {
  16200. v[ i ][ j ] = aj;
  16201. } else {
  16202. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16203. }
  16204. }
  16205. }
  16206. // construct all of the faces
  16207. for ( i = 0; i < cols; i ++ ) {
  16208. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16209. var k = Math.floor( j / 2 );
  16210. if ( j % 2 === 0 ) {
  16211. pushVertex( v[ i ][ k + 1 ] );
  16212. pushVertex( v[ i + 1 ][ k ] );
  16213. pushVertex( v[ i ][ k ] );
  16214. } else {
  16215. pushVertex( v[ i ][ k + 1 ] );
  16216. pushVertex( v[ i + 1 ][ k + 1 ] );
  16217. pushVertex( v[ i + 1 ][ k ] );
  16218. }
  16219. }
  16220. }
  16221. }
  16222. function appplyRadius( radius ) {
  16223. var vertex = new Vector3();
  16224. // iterate over the entire buffer and apply the radius to each vertex
  16225. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16226. vertex.x = vertexBuffer[ i + 0 ];
  16227. vertex.y = vertexBuffer[ i + 1 ];
  16228. vertex.z = vertexBuffer[ i + 2 ];
  16229. vertex.normalize().multiplyScalar( radius );
  16230. vertexBuffer[ i + 0 ] = vertex.x;
  16231. vertexBuffer[ i + 1 ] = vertex.y;
  16232. vertexBuffer[ i + 2 ] = vertex.z;
  16233. }
  16234. }
  16235. function generateUVs() {
  16236. var vertex = new Vector3();
  16237. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16238. vertex.x = vertexBuffer[ i + 0 ];
  16239. vertex.y = vertexBuffer[ i + 1 ];
  16240. vertex.z = vertexBuffer[ i + 2 ];
  16241. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16242. var v = inclination( vertex ) / Math.PI + 0.5;
  16243. uvBuffer.push( u, 1 - v );
  16244. }
  16245. correctUVs();
  16246. correctSeam();
  16247. }
  16248. function correctSeam() {
  16249. // handle case when face straddles the seam, see #3269
  16250. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16251. // uv data of a single face
  16252. var x0 = uvBuffer[ i + 0 ];
  16253. var x1 = uvBuffer[ i + 2 ];
  16254. var x2 = uvBuffer[ i + 4 ];
  16255. var max = Math.max( x0, x1, x2 );
  16256. var min = Math.min( x0, x1, x2 );
  16257. // 0.9 is somewhat arbitrary
  16258. if ( max > 0.9 && min < 0.1 ) {
  16259. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16260. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16261. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16262. }
  16263. }
  16264. }
  16265. function pushVertex( vertex ) {
  16266. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16267. }
  16268. function getVertexByIndex( index, vertex ) {
  16269. var stride = index * 3;
  16270. vertex.x = vertices[ stride + 0 ];
  16271. vertex.y = vertices[ stride + 1 ];
  16272. vertex.z = vertices[ stride + 2 ];
  16273. }
  16274. function correctUVs() {
  16275. var a = new Vector3();
  16276. var b = new Vector3();
  16277. var c = new Vector3();
  16278. var centroid = new Vector3();
  16279. var uvA = new Vector2();
  16280. var uvB = new Vector2();
  16281. var uvC = new Vector2();
  16282. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16283. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16284. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16285. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16286. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16287. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16288. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16289. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16290. var azi = azimuth( centroid );
  16291. correctUV( uvA, j + 0, a, azi );
  16292. correctUV( uvB, j + 2, b, azi );
  16293. correctUV( uvC, j + 4, c, azi );
  16294. }
  16295. }
  16296. function correctUV( uv, stride, vector, azimuth ) {
  16297. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16298. uvBuffer[ stride ] = uv.x - 1;
  16299. }
  16300. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16301. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16302. }
  16303. }
  16304. // Angle around the Y axis, counter-clockwise when looking from above.
  16305. function azimuth( vector ) {
  16306. return Math.atan2( vector.z, - vector.x );
  16307. }
  16308. // Angle above the XZ plane.
  16309. function inclination( vector ) {
  16310. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16311. }
  16312. }
  16313. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16314. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16315. /**
  16316. * @author timothypratley / https://github.com/timothypratley
  16317. * @author Mugen87 / https://github.com/Mugen87
  16318. */
  16319. // TetrahedronGeometry
  16320. function TetrahedronGeometry( radius, detail ) {
  16321. Geometry.call( this );
  16322. this.type = 'TetrahedronGeometry';
  16323. this.parameters = {
  16324. radius: radius,
  16325. detail: detail
  16326. };
  16327. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16328. this.mergeVertices();
  16329. }
  16330. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16331. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16332. // TetrahedronBufferGeometry
  16333. function TetrahedronBufferGeometry( radius, detail ) {
  16334. var vertices = [
  16335. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16336. ];
  16337. var indices = [
  16338. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16339. ];
  16340. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16341. this.type = 'TetrahedronBufferGeometry';
  16342. this.parameters = {
  16343. radius: radius,
  16344. detail: detail
  16345. };
  16346. }
  16347. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16348. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16349. /**
  16350. * @author timothypratley / https://github.com/timothypratley
  16351. * @author Mugen87 / https://github.com/Mugen87
  16352. */
  16353. // OctahedronGeometry
  16354. function OctahedronGeometry( radius, detail ) {
  16355. Geometry.call( this );
  16356. this.type = 'OctahedronGeometry';
  16357. this.parameters = {
  16358. radius: radius,
  16359. detail: detail
  16360. };
  16361. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16362. this.mergeVertices();
  16363. }
  16364. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16365. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16366. // OctahedronBufferGeometry
  16367. function OctahedronBufferGeometry( radius, detail ) {
  16368. var vertices = [
  16369. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16370. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16371. ];
  16372. var indices = [
  16373. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16374. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16375. 1, 3, 4, 1, 4, 2
  16376. ];
  16377. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16378. this.type = 'OctahedronBufferGeometry';
  16379. this.parameters = {
  16380. radius: radius,
  16381. detail: detail
  16382. };
  16383. }
  16384. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16385. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16386. /**
  16387. * @author timothypratley / https://github.com/timothypratley
  16388. * @author Mugen87 / https://github.com/Mugen87
  16389. */
  16390. // IcosahedronGeometry
  16391. function IcosahedronGeometry( radius, detail ) {
  16392. Geometry.call( this );
  16393. this.type = 'IcosahedronGeometry';
  16394. this.parameters = {
  16395. radius: radius,
  16396. detail: detail
  16397. };
  16398. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16399. this.mergeVertices();
  16400. }
  16401. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16402. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16403. // IcosahedronBufferGeometry
  16404. function IcosahedronBufferGeometry( radius, detail ) {
  16405. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16406. var vertices = [
  16407. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16408. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16409. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16410. ];
  16411. var indices = [
  16412. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16413. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16414. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16415. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16416. ];
  16417. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16418. this.type = 'IcosahedronBufferGeometry';
  16419. this.parameters = {
  16420. radius: radius,
  16421. detail: detail
  16422. };
  16423. }
  16424. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16425. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16426. /**
  16427. * @author Abe Pazos / https://hamoid.com
  16428. * @author Mugen87 / https://github.com/Mugen87
  16429. */
  16430. // DodecahedronGeometry
  16431. function DodecahedronGeometry( radius, detail ) {
  16432. Geometry.call( this );
  16433. this.type = 'DodecahedronGeometry';
  16434. this.parameters = {
  16435. radius: radius,
  16436. detail: detail
  16437. };
  16438. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16439. this.mergeVertices();
  16440. }
  16441. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16442. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16443. // DodecahedronBufferGeometry
  16444. function DodecahedronBufferGeometry( radius, detail ) {
  16445. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16446. var r = 1 / t;
  16447. var vertices = [
  16448. // (±1, ±1, ±1)
  16449. - 1, - 1, - 1, - 1, - 1, 1,
  16450. - 1, 1, - 1, - 1, 1, 1,
  16451. 1, - 1, - 1, 1, - 1, 1,
  16452. 1, 1, - 1, 1, 1, 1,
  16453. // (0, ±1/φ, ±φ)
  16454. 0, - r, - t, 0, - r, t,
  16455. 0, r, - t, 0, r, t,
  16456. // (±1/φ, ±φ, 0)
  16457. - r, - t, 0, - r, t, 0,
  16458. r, - t, 0, r, t, 0,
  16459. // (±φ, 0, ±1/φ)
  16460. - t, 0, - r, t, 0, - r,
  16461. - t, 0, r, t, 0, r
  16462. ];
  16463. var indices = [
  16464. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16465. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16466. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16467. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16468. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16469. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16470. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16471. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16472. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16473. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16474. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16475. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16476. ];
  16477. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16478. this.type = 'DodecahedronBufferGeometry';
  16479. this.parameters = {
  16480. radius: radius,
  16481. detail: detail
  16482. };
  16483. }
  16484. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16485. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16486. /**
  16487. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16488. * @author WestLangley / https://github.com/WestLangley
  16489. * @author zz85 / https://github.com/zz85
  16490. * @author miningold / https://github.com/miningold
  16491. * @author jonobr1 / https://github.com/jonobr1
  16492. * @author Mugen87 / https://github.com/Mugen87
  16493. *
  16494. */
  16495. // TubeGeometry
  16496. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16497. Geometry.call( this );
  16498. this.type = 'TubeGeometry';
  16499. this.parameters = {
  16500. path: path,
  16501. tubularSegments: tubularSegments,
  16502. radius: radius,
  16503. radialSegments: radialSegments,
  16504. closed: closed
  16505. };
  16506. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16507. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16508. // expose internals
  16509. this.tangents = bufferGeometry.tangents;
  16510. this.normals = bufferGeometry.normals;
  16511. this.binormals = bufferGeometry.binormals;
  16512. // create geometry
  16513. this.fromBufferGeometry( bufferGeometry );
  16514. this.mergeVertices();
  16515. }
  16516. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16517. TubeGeometry.prototype.constructor = TubeGeometry;
  16518. // TubeBufferGeometry
  16519. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16520. BufferGeometry.call( this );
  16521. this.type = 'TubeBufferGeometry';
  16522. this.parameters = {
  16523. path: path,
  16524. tubularSegments: tubularSegments,
  16525. radius: radius,
  16526. radialSegments: radialSegments,
  16527. closed: closed
  16528. };
  16529. tubularSegments = tubularSegments || 64;
  16530. radius = radius || 1;
  16531. radialSegments = radialSegments || 8;
  16532. closed = closed || false;
  16533. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16534. // expose internals
  16535. this.tangents = frames.tangents;
  16536. this.normals = frames.normals;
  16537. this.binormals = frames.binormals;
  16538. // helper variables
  16539. var vertex = new Vector3();
  16540. var normal = new Vector3();
  16541. var uv = new Vector2();
  16542. var P = new Vector3();
  16543. var i, j;
  16544. // buffer
  16545. var vertices = [];
  16546. var normals = [];
  16547. var uvs = [];
  16548. var indices = [];
  16549. // create buffer data
  16550. generateBufferData();
  16551. // build geometry
  16552. this.setIndex( indices );
  16553. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16554. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16555. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16556. // functions
  16557. function generateBufferData() {
  16558. for ( i = 0; i < tubularSegments; i ++ ) {
  16559. generateSegment( i );
  16560. }
  16561. // if the geometry is not closed, generate the last row of vertices and normals
  16562. // at the regular position on the given path
  16563. //
  16564. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16565. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16566. // uvs are generated in a separate function.
  16567. // this makes it easy compute correct values for closed geometries
  16568. generateUVs();
  16569. // finally create faces
  16570. generateIndices();
  16571. }
  16572. function generateSegment( i ) {
  16573. // we use getPointAt to sample evenly distributed points from the given path
  16574. P = path.getPointAt( i / tubularSegments, P );
  16575. // retrieve corresponding normal and binormal
  16576. var N = frames.normals[ i ];
  16577. var B = frames.binormals[ i ];
  16578. // generate normals and vertices for the current segment
  16579. for ( j = 0; j <= radialSegments; j ++ ) {
  16580. var v = j / radialSegments * Math.PI * 2;
  16581. var sin = Math.sin( v );
  16582. var cos = - Math.cos( v );
  16583. // normal
  16584. normal.x = ( cos * N.x + sin * B.x );
  16585. normal.y = ( cos * N.y + sin * B.y );
  16586. normal.z = ( cos * N.z + sin * B.z );
  16587. normal.normalize();
  16588. normals.push( normal.x, normal.y, normal.z );
  16589. // vertex
  16590. vertex.x = P.x + radius * normal.x;
  16591. vertex.y = P.y + radius * normal.y;
  16592. vertex.z = P.z + radius * normal.z;
  16593. vertices.push( vertex.x, vertex.y, vertex.z );
  16594. }
  16595. }
  16596. function generateIndices() {
  16597. for ( j = 1; j <= tubularSegments; j ++ ) {
  16598. for ( i = 1; i <= radialSegments; i ++ ) {
  16599. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16600. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16601. var c = ( radialSegments + 1 ) * j + i;
  16602. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16603. // faces
  16604. indices.push( a, b, d );
  16605. indices.push( b, c, d );
  16606. }
  16607. }
  16608. }
  16609. function generateUVs() {
  16610. for ( i = 0; i <= tubularSegments; i ++ ) {
  16611. for ( j = 0; j <= radialSegments; j ++ ) {
  16612. uv.x = i / tubularSegments;
  16613. uv.y = j / radialSegments;
  16614. uvs.push( uv.x, uv.y );
  16615. }
  16616. }
  16617. }
  16618. }
  16619. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16620. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16621. TubeBufferGeometry.prototype.toJSON = function () {
  16622. var data = BufferGeometry.prototype.toJSON.call( this );
  16623. data.path = this.parameters.path.toJSON();
  16624. return data;
  16625. };
  16626. /**
  16627. * @author oosmoxiecode
  16628. * @author Mugen87 / https://github.com/Mugen87
  16629. *
  16630. * based on http://www.blackpawn.com/texts/pqtorus/
  16631. */
  16632. // TorusKnotGeometry
  16633. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16634. Geometry.call( this );
  16635. this.type = 'TorusKnotGeometry';
  16636. this.parameters = {
  16637. radius: radius,
  16638. tube: tube,
  16639. tubularSegments: tubularSegments,
  16640. radialSegments: radialSegments,
  16641. p: p,
  16642. q: q
  16643. };
  16644. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16645. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16646. this.mergeVertices();
  16647. }
  16648. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16649. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16650. // TorusKnotBufferGeometry
  16651. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16652. BufferGeometry.call( this );
  16653. this.type = 'TorusKnotBufferGeometry';
  16654. this.parameters = {
  16655. radius: radius,
  16656. tube: tube,
  16657. tubularSegments: tubularSegments,
  16658. radialSegments: radialSegments,
  16659. p: p,
  16660. q: q
  16661. };
  16662. radius = radius || 1;
  16663. tube = tube || 0.4;
  16664. tubularSegments = Math.floor( tubularSegments ) || 64;
  16665. radialSegments = Math.floor( radialSegments ) || 8;
  16666. p = p || 2;
  16667. q = q || 3;
  16668. // buffers
  16669. var indices = [];
  16670. var vertices = [];
  16671. var normals = [];
  16672. var uvs = [];
  16673. // helper variables
  16674. var i, j;
  16675. var vertex = new Vector3();
  16676. var normal = new Vector3();
  16677. var P1 = new Vector3();
  16678. var P2 = new Vector3();
  16679. var B = new Vector3();
  16680. var T = new Vector3();
  16681. var N = new Vector3();
  16682. // generate vertices, normals and uvs
  16683. for ( i = 0; i <= tubularSegments; ++ i ) {
  16684. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  16685. var u = i / tubularSegments * p * Math.PI * 2;
  16686. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  16687. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  16688. calculatePositionOnCurve( u, p, q, radius, P1 );
  16689. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  16690. // calculate orthonormal basis
  16691. T.subVectors( P2, P1 );
  16692. N.addVectors( P2, P1 );
  16693. B.crossVectors( T, N );
  16694. N.crossVectors( B, T );
  16695. // normalize B, N. T can be ignored, we don't use it
  16696. B.normalize();
  16697. N.normalize();
  16698. for ( j = 0; j <= radialSegments; ++ j ) {
  16699. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  16700. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  16701. var v = j / radialSegments * Math.PI * 2;
  16702. var cx = - tube * Math.cos( v );
  16703. var cy = tube * Math.sin( v );
  16704. // now calculate the final vertex position.
  16705. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  16706. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  16707. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  16708. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  16709. vertices.push( vertex.x, vertex.y, vertex.z );
  16710. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  16711. normal.subVectors( vertex, P1 ).normalize();
  16712. normals.push( normal.x, normal.y, normal.z );
  16713. // uv
  16714. uvs.push( i / tubularSegments );
  16715. uvs.push( j / radialSegments );
  16716. }
  16717. }
  16718. // generate indices
  16719. for ( j = 1; j <= tubularSegments; j ++ ) {
  16720. for ( i = 1; i <= radialSegments; i ++ ) {
  16721. // indices
  16722. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16723. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16724. var c = ( radialSegments + 1 ) * j + i;
  16725. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16726. // faces
  16727. indices.push( a, b, d );
  16728. indices.push( b, c, d );
  16729. }
  16730. }
  16731. // build geometry
  16732. this.setIndex( indices );
  16733. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16734. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16735. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16736. // this function calculates the current position on the torus curve
  16737. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16738. var cu = Math.cos( u );
  16739. var su = Math.sin( u );
  16740. var quOverP = q / p * u;
  16741. var cs = Math.cos( quOverP );
  16742. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16743. position.y = radius * ( 2 + cs ) * su * 0.5;
  16744. position.z = radius * Math.sin( quOverP ) * 0.5;
  16745. }
  16746. }
  16747. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16748. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16749. /**
  16750. * @author oosmoxiecode
  16751. * @author mrdoob / http://mrdoob.com/
  16752. * @author Mugen87 / https://github.com/Mugen87
  16753. */
  16754. // TorusGeometry
  16755. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16756. Geometry.call( this );
  16757. this.type = 'TorusGeometry';
  16758. this.parameters = {
  16759. radius: radius,
  16760. tube: tube,
  16761. radialSegments: radialSegments,
  16762. tubularSegments: tubularSegments,
  16763. arc: arc
  16764. };
  16765. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16766. this.mergeVertices();
  16767. }
  16768. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16769. TorusGeometry.prototype.constructor = TorusGeometry;
  16770. // TorusBufferGeometry
  16771. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16772. BufferGeometry.call( this );
  16773. this.type = 'TorusBufferGeometry';
  16774. this.parameters = {
  16775. radius: radius,
  16776. tube: tube,
  16777. radialSegments: radialSegments,
  16778. tubularSegments: tubularSegments,
  16779. arc: arc
  16780. };
  16781. radius = radius || 1;
  16782. tube = tube || 0.4;
  16783. radialSegments = Math.floor( radialSegments ) || 8;
  16784. tubularSegments = Math.floor( tubularSegments ) || 6;
  16785. arc = arc || Math.PI * 2;
  16786. // buffers
  16787. var indices = [];
  16788. var vertices = [];
  16789. var normals = [];
  16790. var uvs = [];
  16791. // helper variables
  16792. var center = new Vector3();
  16793. var vertex = new Vector3();
  16794. var normal = new Vector3();
  16795. var j, i;
  16796. // generate vertices, normals and uvs
  16797. for ( j = 0; j <= radialSegments; j ++ ) {
  16798. for ( i = 0; i <= tubularSegments; i ++ ) {
  16799. var u = i / tubularSegments * arc;
  16800. var v = j / radialSegments * Math.PI * 2;
  16801. // vertex
  16802. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16803. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16804. vertex.z = tube * Math.sin( v );
  16805. vertices.push( vertex.x, vertex.y, vertex.z );
  16806. // normal
  16807. center.x = radius * Math.cos( u );
  16808. center.y = radius * Math.sin( u );
  16809. normal.subVectors( vertex, center ).normalize();
  16810. normals.push( normal.x, normal.y, normal.z );
  16811. // uv
  16812. uvs.push( i / tubularSegments );
  16813. uvs.push( j / radialSegments );
  16814. }
  16815. }
  16816. // generate indices
  16817. for ( j = 1; j <= radialSegments; j ++ ) {
  16818. for ( i = 1; i <= tubularSegments; i ++ ) {
  16819. // indices
  16820. var a = ( tubularSegments + 1 ) * j + i - 1;
  16821. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16822. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16823. var d = ( tubularSegments + 1 ) * j + i;
  16824. // faces
  16825. indices.push( a, b, d );
  16826. indices.push( b, c, d );
  16827. }
  16828. }
  16829. // build geometry
  16830. this.setIndex( indices );
  16831. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16832. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16833. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16834. }
  16835. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16836. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16837. /**
  16838. * @author Mugen87 / https://github.com/Mugen87
  16839. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16840. */
  16841. var Earcut = {
  16842. triangulate: function ( data, holeIndices, dim ) {
  16843. dim = dim || 2;
  16844. var hasHoles = holeIndices && holeIndices.length,
  16845. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16846. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16847. triangles = [];
  16848. if ( ! outerNode ) return triangles;
  16849. var minX, minY, maxX, maxY, x, y, invSize;
  16850. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16851. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16852. if ( data.length > 80 * dim ) {
  16853. minX = maxX = data[ 0 ];
  16854. minY = maxY = data[ 1 ];
  16855. for ( var i = dim; i < outerLen; i += dim ) {
  16856. x = data[ i ];
  16857. y = data[ i + 1 ];
  16858. if ( x < minX ) minX = x;
  16859. if ( y < minY ) minY = y;
  16860. if ( x > maxX ) maxX = x;
  16861. if ( y > maxY ) maxY = y;
  16862. }
  16863. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16864. invSize = Math.max( maxX - minX, maxY - minY );
  16865. invSize = invSize !== 0 ? 1 / invSize : 0;
  16866. }
  16867. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16868. return triangles;
  16869. }
  16870. };
  16871. // create a circular doubly linked list from polygon points in the specified winding order
  16872. function linkedList( data, start, end, dim, clockwise ) {
  16873. var i, last;
  16874. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16875. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16876. } else {
  16877. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16878. }
  16879. if ( last && equals( last, last.next ) ) {
  16880. removeNode( last );
  16881. last = last.next;
  16882. }
  16883. return last;
  16884. }
  16885. // eliminate colinear or duplicate points
  16886. function filterPoints( start, end ) {
  16887. if ( ! start ) return start;
  16888. if ( ! end ) end = start;
  16889. var p = start, again;
  16890. do {
  16891. again = false;
  16892. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16893. removeNode( p );
  16894. p = end = p.prev;
  16895. if ( p === p.next ) break;
  16896. again = true;
  16897. } else {
  16898. p = p.next;
  16899. }
  16900. } while ( again || p !== end );
  16901. return end;
  16902. }
  16903. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16904. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16905. if ( ! ear ) return;
  16906. // interlink polygon nodes in z-order
  16907. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16908. var stop = ear, prev, next;
  16909. // iterate through ears, slicing them one by one
  16910. while ( ear.prev !== ear.next ) {
  16911. prev = ear.prev;
  16912. next = ear.next;
  16913. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16914. // cut off the triangle
  16915. triangles.push( prev.i / dim );
  16916. triangles.push( ear.i / dim );
  16917. triangles.push( next.i / dim );
  16918. removeNode( ear );
  16919. // skipping the next vertice leads to less sliver triangles
  16920. ear = next.next;
  16921. stop = next.next;
  16922. continue;
  16923. }
  16924. ear = next;
  16925. // if we looped through the whole remaining polygon and can't find any more ears
  16926. if ( ear === stop ) {
  16927. // try filtering points and slicing again
  16928. if ( ! pass ) {
  16929. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16930. // if this didn't work, try curing all small self-intersections locally
  16931. } else if ( pass === 1 ) {
  16932. ear = cureLocalIntersections( ear, triangles, dim );
  16933. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16934. // as a last resort, try splitting the remaining polygon into two
  16935. } else if ( pass === 2 ) {
  16936. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16937. }
  16938. break;
  16939. }
  16940. }
  16941. }
  16942. // check whether a polygon node forms a valid ear with adjacent nodes
  16943. function isEar( ear ) {
  16944. var a = ear.prev,
  16945. b = ear,
  16946. c = ear.next;
  16947. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16948. // now make sure we don't have other points inside the potential ear
  16949. var p = ear.next.next;
  16950. while ( p !== ear.prev ) {
  16951. 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 ) {
  16952. return false;
  16953. }
  16954. p = p.next;
  16955. }
  16956. return true;
  16957. }
  16958. function isEarHashed( ear, minX, minY, invSize ) {
  16959. var a = ear.prev,
  16960. b = ear,
  16961. c = ear.next;
  16962. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16963. // triangle bbox; min & max are calculated like this for speed
  16964. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  16965. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  16966. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  16967. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  16968. // z-order range for the current triangle bbox;
  16969. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  16970. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  16971. // first look for points inside the triangle in increasing z-order
  16972. var p = ear.nextZ;
  16973. while ( p && p.z <= maxZ ) {
  16974. if ( p !== ear.prev && p !== ear.next &&
  16975. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16976. area( p.prev, p, p.next ) >= 0 ) return false;
  16977. p = p.nextZ;
  16978. }
  16979. // then look for points in decreasing z-order
  16980. p = ear.prevZ;
  16981. while ( p && p.z >= minZ ) {
  16982. if ( p !== ear.prev && p !== ear.next &&
  16983. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16984. area( p.prev, p, p.next ) >= 0 ) return false;
  16985. p = p.prevZ;
  16986. }
  16987. return true;
  16988. }
  16989. // go through all polygon nodes and cure small local self-intersections
  16990. function cureLocalIntersections( start, triangles, dim ) {
  16991. var p = start;
  16992. do {
  16993. var a = p.prev, b = p.next.next;
  16994. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  16995. triangles.push( a.i / dim );
  16996. triangles.push( p.i / dim );
  16997. triangles.push( b.i / dim );
  16998. // remove two nodes involved
  16999. removeNode( p );
  17000. removeNode( p.next );
  17001. p = start = b;
  17002. }
  17003. p = p.next;
  17004. } while ( p !== start );
  17005. return p;
  17006. }
  17007. // try splitting polygon into two and triangulate them independently
  17008. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17009. // look for a valid diagonal that divides the polygon into two
  17010. var a = start;
  17011. do {
  17012. var b = a.next.next;
  17013. while ( b !== a.prev ) {
  17014. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17015. // split the polygon in two by the diagonal
  17016. var c = splitPolygon( a, b );
  17017. // filter colinear points around the cuts
  17018. a = filterPoints( a, a.next );
  17019. c = filterPoints( c, c.next );
  17020. // run earcut on each half
  17021. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17022. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17023. return;
  17024. }
  17025. b = b.next;
  17026. }
  17027. a = a.next;
  17028. } while ( a !== start );
  17029. }
  17030. // link every hole into the outer loop, producing a single-ring polygon without holes
  17031. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17032. var queue = [], i, len, start, end, list;
  17033. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17034. start = holeIndices[ i ] * dim;
  17035. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17036. list = linkedList( data, start, end, dim, false );
  17037. if ( list === list.next ) list.steiner = true;
  17038. queue.push( getLeftmost( list ) );
  17039. }
  17040. queue.sort( compareX );
  17041. // process holes from left to right
  17042. for ( i = 0; i < queue.length; i ++ ) {
  17043. eliminateHole( queue[ i ], outerNode );
  17044. outerNode = filterPoints( outerNode, outerNode.next );
  17045. }
  17046. return outerNode;
  17047. }
  17048. function compareX( a, b ) {
  17049. return a.x - b.x;
  17050. }
  17051. // find a bridge between vertices that connects hole with an outer ring and and link it
  17052. function eliminateHole( hole, outerNode ) {
  17053. outerNode = findHoleBridge( hole, outerNode );
  17054. if ( outerNode ) {
  17055. var b = splitPolygon( outerNode, hole );
  17056. filterPoints( b, b.next );
  17057. }
  17058. }
  17059. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17060. function findHoleBridge( hole, outerNode ) {
  17061. var p = outerNode,
  17062. hx = hole.x,
  17063. hy = hole.y,
  17064. qx = - Infinity,
  17065. m;
  17066. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17067. // segment's endpoint with lesser x will be potential connection point
  17068. do {
  17069. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17070. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17071. if ( x <= hx && x > qx ) {
  17072. qx = x;
  17073. if ( x === hx ) {
  17074. if ( hy === p.y ) return p;
  17075. if ( hy === p.next.y ) return p.next;
  17076. }
  17077. m = p.x < p.next.x ? p : p.next;
  17078. }
  17079. }
  17080. p = p.next;
  17081. } while ( p !== outerNode );
  17082. if ( ! m ) return null;
  17083. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17084. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17085. // if there are no points found, we have a valid connection;
  17086. // otherwise choose the point of the minimum angle with the ray as connection point
  17087. var stop = m,
  17088. mx = m.x,
  17089. my = m.y,
  17090. tanMin = Infinity,
  17091. tan;
  17092. p = m.next;
  17093. while ( p !== stop ) {
  17094. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17095. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17096. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17097. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17098. m = p;
  17099. tanMin = tan;
  17100. }
  17101. }
  17102. p = p.next;
  17103. }
  17104. return m;
  17105. }
  17106. // interlink polygon nodes in z-order
  17107. function indexCurve( start, minX, minY, invSize ) {
  17108. var p = start;
  17109. do {
  17110. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17111. p.prevZ = p.prev;
  17112. p.nextZ = p.next;
  17113. p = p.next;
  17114. } while ( p !== start );
  17115. p.prevZ.nextZ = null;
  17116. p.prevZ = null;
  17117. sortLinked( p );
  17118. }
  17119. // Simon Tatham's linked list merge sort algorithm
  17120. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17121. function sortLinked( list ) {
  17122. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  17123. do {
  17124. p = list;
  17125. list = null;
  17126. tail = null;
  17127. numMerges = 0;
  17128. while ( p ) {
  17129. numMerges ++;
  17130. q = p;
  17131. pSize = 0;
  17132. for ( i = 0; i < inSize; i ++ ) {
  17133. pSize ++;
  17134. q = q.nextZ;
  17135. if ( ! q ) break;
  17136. }
  17137. qSize = inSize;
  17138. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17139. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17140. e = p;
  17141. p = p.nextZ;
  17142. pSize --;
  17143. } else {
  17144. e = q;
  17145. q = q.nextZ;
  17146. qSize --;
  17147. }
  17148. if ( tail ) tail.nextZ = e;
  17149. else list = e;
  17150. e.prevZ = tail;
  17151. tail = e;
  17152. }
  17153. p = q;
  17154. }
  17155. tail.nextZ = null;
  17156. inSize *= 2;
  17157. } while ( numMerges > 1 );
  17158. return list;
  17159. }
  17160. // z-order of a point given coords and inverse of the longer side of data bbox
  17161. function zOrder( x, y, minX, minY, invSize ) {
  17162. // coords are transformed into non-negative 15-bit integer range
  17163. x = 32767 * ( x - minX ) * invSize;
  17164. y = 32767 * ( y - minY ) * invSize;
  17165. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17166. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17167. x = ( x | ( x << 2 ) ) & 0x33333333;
  17168. x = ( x | ( x << 1 ) ) & 0x55555555;
  17169. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17170. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17171. y = ( y | ( y << 2 ) ) & 0x33333333;
  17172. y = ( y | ( y << 1 ) ) & 0x55555555;
  17173. return x | ( y << 1 );
  17174. }
  17175. // find the leftmost node of a polygon ring
  17176. function getLeftmost( start ) {
  17177. var p = start, leftmost = start;
  17178. do {
  17179. if ( p.x < leftmost.x ) leftmost = p;
  17180. p = p.next;
  17181. } while ( p !== start );
  17182. return leftmost;
  17183. }
  17184. // check if a point lies within a convex triangle
  17185. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17186. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17187. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17188. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17189. }
  17190. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17191. function isValidDiagonal( a, b ) {
  17192. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17193. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17194. }
  17195. // signed area of a triangle
  17196. function area( p, q, r ) {
  17197. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17198. }
  17199. // check if two points are equal
  17200. function equals( p1, p2 ) {
  17201. return p1.x === p2.x && p1.y === p2.y;
  17202. }
  17203. // check if two segments intersect
  17204. function intersects( p1, q1, p2, q2 ) {
  17205. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  17206. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17207. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17208. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17209. }
  17210. // check if a polygon diagonal intersects any polygon segments
  17211. function intersectsPolygon( a, b ) {
  17212. var p = a;
  17213. do {
  17214. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17215. intersects( p, p.next, a, b ) ) {
  17216. return true;
  17217. }
  17218. p = p.next;
  17219. } while ( p !== a );
  17220. return false;
  17221. }
  17222. // check if a polygon diagonal is locally inside the polygon
  17223. function locallyInside( a, b ) {
  17224. return area( a.prev, a, a.next ) < 0 ?
  17225. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17226. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17227. }
  17228. // check if the middle point of a polygon diagonal is inside the polygon
  17229. function middleInside( a, b ) {
  17230. var p = a,
  17231. inside = false,
  17232. px = ( a.x + b.x ) / 2,
  17233. py = ( a.y + b.y ) / 2;
  17234. do {
  17235. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17236. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  17237. inside = ! inside;
  17238. }
  17239. p = p.next;
  17240. } while ( p !== a );
  17241. return inside;
  17242. }
  17243. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17244. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17245. function splitPolygon( a, b ) {
  17246. var a2 = new Node( a.i, a.x, a.y ),
  17247. b2 = new Node( b.i, b.x, b.y ),
  17248. an = a.next,
  17249. bp = b.prev;
  17250. a.next = b;
  17251. b.prev = a;
  17252. a2.next = an;
  17253. an.prev = a2;
  17254. b2.next = a2;
  17255. a2.prev = b2;
  17256. bp.next = b2;
  17257. b2.prev = bp;
  17258. return b2;
  17259. }
  17260. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17261. function insertNode( i, x, y, last ) {
  17262. var p = new Node( i, x, y );
  17263. if ( ! last ) {
  17264. p.prev = p;
  17265. p.next = p;
  17266. } else {
  17267. p.next = last.next;
  17268. p.prev = last;
  17269. last.next.prev = p;
  17270. last.next = p;
  17271. }
  17272. return p;
  17273. }
  17274. function removeNode( p ) {
  17275. p.next.prev = p.prev;
  17276. p.prev.next = p.next;
  17277. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17278. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17279. }
  17280. function Node( i, x, y ) {
  17281. // vertice index in coordinates array
  17282. this.i = i;
  17283. // vertex coordinates
  17284. this.x = x;
  17285. this.y = y;
  17286. // previous and next vertice nodes in a polygon ring
  17287. this.prev = null;
  17288. this.next = null;
  17289. // z-order curve value
  17290. this.z = null;
  17291. // previous and next nodes in z-order
  17292. this.prevZ = null;
  17293. this.nextZ = null;
  17294. // indicates whether this is a steiner point
  17295. this.steiner = false;
  17296. }
  17297. function signedArea( data, start, end, dim ) {
  17298. var sum = 0;
  17299. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17300. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17301. j = i;
  17302. }
  17303. return sum;
  17304. }
  17305. /**
  17306. * @author zz85 / http://www.lab4games.net/zz85/blog
  17307. */
  17308. var ShapeUtils = {
  17309. // calculate area of the contour polygon
  17310. area: function ( contour ) {
  17311. var n = contour.length;
  17312. var a = 0.0;
  17313. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17314. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17315. }
  17316. return a * 0.5;
  17317. },
  17318. isClockWise: function ( pts ) {
  17319. return ShapeUtils.area( pts ) < 0;
  17320. },
  17321. triangulateShape: function ( contour, holes ) {
  17322. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17323. var holeIndices = []; // array of hole indices
  17324. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17325. removeDupEndPts( contour );
  17326. addContour( vertices, contour );
  17327. //
  17328. var holeIndex = contour.length;
  17329. holes.forEach( removeDupEndPts );
  17330. for ( var i = 0; i < holes.length; i ++ ) {
  17331. holeIndices.push( holeIndex );
  17332. holeIndex += holes[ i ].length;
  17333. addContour( vertices, holes[ i ] );
  17334. }
  17335. //
  17336. var triangles = Earcut.triangulate( vertices, holeIndices );
  17337. //
  17338. for ( var i = 0; i < triangles.length; i += 3 ) {
  17339. faces.push( triangles.slice( i, i + 3 ) );
  17340. }
  17341. return faces;
  17342. }
  17343. };
  17344. function removeDupEndPts( points ) {
  17345. var l = points.length;
  17346. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17347. points.pop();
  17348. }
  17349. }
  17350. function addContour( vertices, contour ) {
  17351. for ( var i = 0; i < contour.length; i ++ ) {
  17352. vertices.push( contour[ i ].x );
  17353. vertices.push( contour[ i ].y );
  17354. }
  17355. }
  17356. /**
  17357. * @author zz85 / http://www.lab4games.net/zz85/blog
  17358. *
  17359. * Creates extruded geometry from a path shape.
  17360. *
  17361. * parameters = {
  17362. *
  17363. * curveSegments: <int>, // number of points on the curves
  17364. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17365. * depth: <float>, // Depth to extrude the shape
  17366. *
  17367. * bevelEnabled: <bool>, // turn on bevel
  17368. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17369. * bevelSize: <float>, // how far from shape outline is bevel
  17370. * bevelSegments: <int>, // number of bevel layers
  17371. *
  17372. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17373. *
  17374. * UVGenerator: <Object> // object that provides UV generator functions
  17375. *
  17376. * }
  17377. */
  17378. // ExtrudeGeometry
  17379. function ExtrudeGeometry( shapes, options ) {
  17380. Geometry.call( this );
  17381. this.type = 'ExtrudeGeometry';
  17382. this.parameters = {
  17383. shapes: shapes,
  17384. options: options
  17385. };
  17386. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17387. this.mergeVertices();
  17388. }
  17389. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17390. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17391. ExtrudeGeometry.prototype.toJSON = function () {
  17392. var data = Geometry.prototype.toJSON.call( this );
  17393. var shapes = this.parameters.shapes;
  17394. var options = this.parameters.options;
  17395. return toJSON( shapes, options, data );
  17396. };
  17397. // ExtrudeBufferGeometry
  17398. function ExtrudeBufferGeometry( shapes, options ) {
  17399. BufferGeometry.call( this );
  17400. this.type = 'ExtrudeBufferGeometry';
  17401. this.parameters = {
  17402. shapes: shapes,
  17403. options: options
  17404. };
  17405. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17406. var scope = this;
  17407. var verticesArray = [];
  17408. var uvArray = [];
  17409. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17410. var shape = shapes[ i ];
  17411. addShape( shape );
  17412. }
  17413. // build geometry
  17414. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17415. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17416. this.computeVertexNormals();
  17417. // functions
  17418. function addShape( shape ) {
  17419. var placeholder = [];
  17420. // options
  17421. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17422. var steps = options.steps !== undefined ? options.steps : 1;
  17423. var depth = options.depth !== undefined ? options.depth : 100;
  17424. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17425. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17426. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17427. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17428. var extrudePath = options.extrudePath;
  17429. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17430. // deprecated options
  17431. if ( options.amount !== undefined ) {
  17432. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17433. depth = options.amount;
  17434. }
  17435. //
  17436. var extrudePts, extrudeByPath = false;
  17437. var splineTube, binormal, normal, position2;
  17438. if ( extrudePath ) {
  17439. extrudePts = extrudePath.getSpacedPoints( steps );
  17440. extrudeByPath = true;
  17441. bevelEnabled = false; // bevels not supported for path extrusion
  17442. // SETUP TNB variables
  17443. // TODO1 - have a .isClosed in spline?
  17444. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17445. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17446. binormal = new Vector3();
  17447. normal = new Vector3();
  17448. position2 = new Vector3();
  17449. }
  17450. // Safeguards if bevels are not enabled
  17451. if ( ! bevelEnabled ) {
  17452. bevelSegments = 0;
  17453. bevelThickness = 0;
  17454. bevelSize = 0;
  17455. }
  17456. // Variables initialization
  17457. var ahole, h, hl; // looping of holes
  17458. var shapePoints = shape.extractPoints( curveSegments );
  17459. var vertices = shapePoints.shape;
  17460. var holes = shapePoints.holes;
  17461. var reverse = ! ShapeUtils.isClockWise( vertices );
  17462. if ( reverse ) {
  17463. vertices = vertices.reverse();
  17464. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17465. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17466. ahole = holes[ h ];
  17467. if ( ShapeUtils.isClockWise( ahole ) ) {
  17468. holes[ h ] = ahole.reverse();
  17469. }
  17470. }
  17471. }
  17472. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17473. /* Vertices */
  17474. var contour = vertices; // vertices has all points but contour has only points of circumference
  17475. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17476. ahole = holes[ h ];
  17477. vertices = vertices.concat( ahole );
  17478. }
  17479. function scalePt2( pt, vec, size ) {
  17480. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17481. return vec.clone().multiplyScalar( size ).add( pt );
  17482. }
  17483. var b, bs, t, z,
  17484. vert, vlen = vertices.length,
  17485. face, flen = faces.length;
  17486. // Find directions for point movement
  17487. function getBevelVec( inPt, inPrev, inNext ) {
  17488. // computes for inPt the corresponding point inPt' on a new contour
  17489. // shifted by 1 unit (length of normalized vector) to the left
  17490. // if we walk along contour clockwise, this new contour is outside the old one
  17491. //
  17492. // inPt' is the intersection of the two lines parallel to the two
  17493. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17494. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17495. // good reading for geometry algorithms (here: line-line intersection)
  17496. // http://geomalgorithms.com/a05-_intersect-1.html
  17497. var v_prev_x = inPt.x - inPrev.x,
  17498. v_prev_y = inPt.y - inPrev.y;
  17499. var v_next_x = inNext.x - inPt.x,
  17500. v_next_y = inNext.y - inPt.y;
  17501. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17502. // check for collinear edges
  17503. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17504. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17505. // not collinear
  17506. // length of vectors for normalizing
  17507. var v_prev_len = Math.sqrt( v_prev_lensq );
  17508. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17509. // shift adjacent points by unit vectors to the left
  17510. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17511. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17512. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17513. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17514. // scaling factor for v_prev to intersection point
  17515. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17516. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17517. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17518. // vector from inPt to intersection point
  17519. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17520. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17521. // Don't normalize!, otherwise sharp corners become ugly
  17522. // but prevent crazy spikes
  17523. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17524. if ( v_trans_lensq <= 2 ) {
  17525. return new Vector2( v_trans_x, v_trans_y );
  17526. } else {
  17527. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17528. }
  17529. } else {
  17530. // handle special case of collinear edges
  17531. var direction_eq = false; // assumes: opposite
  17532. if ( v_prev_x > Number.EPSILON ) {
  17533. if ( v_next_x > Number.EPSILON ) {
  17534. direction_eq = true;
  17535. }
  17536. } else {
  17537. if ( v_prev_x < - Number.EPSILON ) {
  17538. if ( v_next_x < - Number.EPSILON ) {
  17539. direction_eq = true;
  17540. }
  17541. } else {
  17542. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17543. direction_eq = true;
  17544. }
  17545. }
  17546. }
  17547. if ( direction_eq ) {
  17548. // console.log("Warning: lines are a straight sequence");
  17549. v_trans_x = - v_prev_y;
  17550. v_trans_y = v_prev_x;
  17551. shrink_by = Math.sqrt( v_prev_lensq );
  17552. } else {
  17553. // console.log("Warning: lines are a straight spike");
  17554. v_trans_x = v_prev_x;
  17555. v_trans_y = v_prev_y;
  17556. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17557. }
  17558. }
  17559. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17560. }
  17561. var contourMovements = [];
  17562. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17563. if ( j === il ) j = 0;
  17564. if ( k === il ) k = 0;
  17565. // (j)---(i)---(k)
  17566. // console.log('i,j,k', i, j , k)
  17567. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17568. }
  17569. var holesMovements = [],
  17570. oneHoleMovements, verticesMovements = contourMovements.concat();
  17571. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17572. ahole = holes[ h ];
  17573. oneHoleMovements = [];
  17574. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17575. if ( j === il ) j = 0;
  17576. if ( k === il ) k = 0;
  17577. // (j)---(i)---(k)
  17578. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17579. }
  17580. holesMovements.push( oneHoleMovements );
  17581. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17582. }
  17583. // Loop bevelSegments, 1 for the front, 1 for the back
  17584. for ( b = 0; b < bevelSegments; b ++ ) {
  17585. //for ( b = bevelSegments; b > 0; b -- ) {
  17586. t = b / bevelSegments;
  17587. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17588. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17589. // contract shape
  17590. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17591. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17592. v( vert.x, vert.y, - z );
  17593. }
  17594. // expand holes
  17595. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17596. ahole = holes[ h ];
  17597. oneHoleMovements = holesMovements[ h ];
  17598. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17599. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17600. v( vert.x, vert.y, - z );
  17601. }
  17602. }
  17603. }
  17604. bs = bevelSize;
  17605. // Back facing vertices
  17606. for ( i = 0; i < vlen; i ++ ) {
  17607. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17608. if ( ! extrudeByPath ) {
  17609. v( vert.x, vert.y, 0 );
  17610. } else {
  17611. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17612. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17613. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17614. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17615. v( position2.x, position2.y, position2.z );
  17616. }
  17617. }
  17618. // Add stepped vertices...
  17619. // Including front facing vertices
  17620. var s;
  17621. for ( s = 1; s <= steps; s ++ ) {
  17622. for ( i = 0; i < vlen; i ++ ) {
  17623. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17624. if ( ! extrudeByPath ) {
  17625. v( vert.x, vert.y, depth / steps * s );
  17626. } else {
  17627. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17628. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17629. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17630. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17631. v( position2.x, position2.y, position2.z );
  17632. }
  17633. }
  17634. }
  17635. // Add bevel segments planes
  17636. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17637. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17638. t = b / bevelSegments;
  17639. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17640. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17641. // contract shape
  17642. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17643. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17644. v( vert.x, vert.y, depth + z );
  17645. }
  17646. // expand holes
  17647. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17648. ahole = holes[ h ];
  17649. oneHoleMovements = holesMovements[ h ];
  17650. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17651. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17652. if ( ! extrudeByPath ) {
  17653. v( vert.x, vert.y, depth + z );
  17654. } else {
  17655. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17656. }
  17657. }
  17658. }
  17659. }
  17660. /* Faces */
  17661. // Top and bottom faces
  17662. buildLidFaces();
  17663. // Sides faces
  17664. buildSideFaces();
  17665. ///// Internal functions
  17666. function buildLidFaces() {
  17667. var start = verticesArray.length / 3;
  17668. if ( bevelEnabled ) {
  17669. var layer = 0; // steps + 1
  17670. var offset = vlen * layer;
  17671. // Bottom faces
  17672. for ( i = 0; i < flen; i ++ ) {
  17673. face = faces[ i ];
  17674. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17675. }
  17676. layer = steps + bevelSegments * 2;
  17677. offset = vlen * layer;
  17678. // Top faces
  17679. for ( i = 0; i < flen; i ++ ) {
  17680. face = faces[ i ];
  17681. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17682. }
  17683. } else {
  17684. // Bottom faces
  17685. for ( i = 0; i < flen; i ++ ) {
  17686. face = faces[ i ];
  17687. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17688. }
  17689. // Top faces
  17690. for ( i = 0; i < flen; i ++ ) {
  17691. face = faces[ i ];
  17692. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17693. }
  17694. }
  17695. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17696. }
  17697. // Create faces for the z-sides of the shape
  17698. function buildSideFaces() {
  17699. var start = verticesArray.length / 3;
  17700. var layeroffset = 0;
  17701. sidewalls( contour, layeroffset );
  17702. layeroffset += contour.length;
  17703. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17704. ahole = holes[ h ];
  17705. sidewalls( ahole, layeroffset );
  17706. //, true
  17707. layeroffset += ahole.length;
  17708. }
  17709. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17710. }
  17711. function sidewalls( contour, layeroffset ) {
  17712. var j, k;
  17713. i = contour.length;
  17714. while ( -- i >= 0 ) {
  17715. j = i;
  17716. k = i - 1;
  17717. if ( k < 0 ) k = contour.length - 1;
  17718. //console.log('b', i,j, i-1, k,vertices.length);
  17719. var s = 0,
  17720. sl = steps + bevelSegments * 2;
  17721. for ( s = 0; s < sl; s ++ ) {
  17722. var slen1 = vlen * s;
  17723. var slen2 = vlen * ( s + 1 );
  17724. var a = layeroffset + j + slen1,
  17725. b = layeroffset + k + slen1,
  17726. c = layeroffset + k + slen2,
  17727. d = layeroffset + j + slen2;
  17728. f4( a, b, c, d );
  17729. }
  17730. }
  17731. }
  17732. function v( x, y, z ) {
  17733. placeholder.push( x );
  17734. placeholder.push( y );
  17735. placeholder.push( z );
  17736. }
  17737. function f3( a, b, c ) {
  17738. addVertex( a );
  17739. addVertex( b );
  17740. addVertex( c );
  17741. var nextIndex = verticesArray.length / 3;
  17742. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17743. addUV( uvs[ 0 ] );
  17744. addUV( uvs[ 1 ] );
  17745. addUV( uvs[ 2 ] );
  17746. }
  17747. function f4( a, b, c, d ) {
  17748. addVertex( a );
  17749. addVertex( b );
  17750. addVertex( d );
  17751. addVertex( b );
  17752. addVertex( c );
  17753. addVertex( d );
  17754. var nextIndex = verticesArray.length / 3;
  17755. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17756. addUV( uvs[ 0 ] );
  17757. addUV( uvs[ 1 ] );
  17758. addUV( uvs[ 3 ] );
  17759. addUV( uvs[ 1 ] );
  17760. addUV( uvs[ 2 ] );
  17761. addUV( uvs[ 3 ] );
  17762. }
  17763. function addVertex( index ) {
  17764. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17765. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17766. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17767. }
  17768. function addUV( vector2 ) {
  17769. uvArray.push( vector2.x );
  17770. uvArray.push( vector2.y );
  17771. }
  17772. }
  17773. }
  17774. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17775. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17776. ExtrudeBufferGeometry.prototype.toJSON = function () {
  17777. var data = BufferGeometry.prototype.toJSON.call( this );
  17778. var shapes = this.parameters.shapes;
  17779. var options = this.parameters.options;
  17780. return toJSON( shapes, options, data );
  17781. };
  17782. //
  17783. var WorldUVGenerator = {
  17784. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17785. var a_x = vertices[ indexA * 3 ];
  17786. var a_y = vertices[ indexA * 3 + 1 ];
  17787. var b_x = vertices[ indexB * 3 ];
  17788. var b_y = vertices[ indexB * 3 + 1 ];
  17789. var c_x = vertices[ indexC * 3 ];
  17790. var c_y = vertices[ indexC * 3 + 1 ];
  17791. return [
  17792. new Vector2( a_x, a_y ),
  17793. new Vector2( b_x, b_y ),
  17794. new Vector2( c_x, c_y )
  17795. ];
  17796. },
  17797. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17798. var a_x = vertices[ indexA * 3 ];
  17799. var a_y = vertices[ indexA * 3 + 1 ];
  17800. var a_z = vertices[ indexA * 3 + 2 ];
  17801. var b_x = vertices[ indexB * 3 ];
  17802. var b_y = vertices[ indexB * 3 + 1 ];
  17803. var b_z = vertices[ indexB * 3 + 2 ];
  17804. var c_x = vertices[ indexC * 3 ];
  17805. var c_y = vertices[ indexC * 3 + 1 ];
  17806. var c_z = vertices[ indexC * 3 + 2 ];
  17807. var d_x = vertices[ indexD * 3 ];
  17808. var d_y = vertices[ indexD * 3 + 1 ];
  17809. var d_z = vertices[ indexD * 3 + 2 ];
  17810. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17811. return [
  17812. new Vector2( a_x, 1 - a_z ),
  17813. new Vector2( b_x, 1 - b_z ),
  17814. new Vector2( c_x, 1 - c_z ),
  17815. new Vector2( d_x, 1 - d_z )
  17816. ];
  17817. } else {
  17818. return [
  17819. new Vector2( a_y, 1 - a_z ),
  17820. new Vector2( b_y, 1 - b_z ),
  17821. new Vector2( c_y, 1 - c_z ),
  17822. new Vector2( d_y, 1 - d_z )
  17823. ];
  17824. }
  17825. }
  17826. };
  17827. function toJSON( shapes, options, data ) {
  17828. //
  17829. data.shapes = [];
  17830. if ( Array.isArray( shapes ) ) {
  17831. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17832. var shape = shapes[ i ];
  17833. data.shapes.push( shape.uuid );
  17834. }
  17835. } else {
  17836. data.shapes.push( shapes.uuid );
  17837. }
  17838. //
  17839. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17840. return data;
  17841. }
  17842. /**
  17843. * @author zz85 / http://www.lab4games.net/zz85/blog
  17844. * @author alteredq / http://alteredqualia.com/
  17845. *
  17846. * Text = 3D Text
  17847. *
  17848. * parameters = {
  17849. * font: <THREE.Font>, // font
  17850. *
  17851. * size: <float>, // size of the text
  17852. * height: <float>, // thickness to extrude text
  17853. * curveSegments: <int>, // number of points on the curves
  17854. *
  17855. * bevelEnabled: <bool>, // turn on bevel
  17856. * bevelThickness: <float>, // how deep into text bevel goes
  17857. * bevelSize: <float> // how far from text outline is bevel
  17858. * }
  17859. */
  17860. // TextGeometry
  17861. function TextGeometry( text, parameters ) {
  17862. Geometry.call( this );
  17863. this.type = 'TextGeometry';
  17864. this.parameters = {
  17865. text: text,
  17866. parameters: parameters
  17867. };
  17868. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17869. this.mergeVertices();
  17870. }
  17871. TextGeometry.prototype = Object.create( Geometry.prototype );
  17872. TextGeometry.prototype.constructor = TextGeometry;
  17873. // TextBufferGeometry
  17874. function TextBufferGeometry( text, parameters ) {
  17875. parameters = parameters || {};
  17876. var font = parameters.font;
  17877. if ( ! ( font && font.isFont ) ) {
  17878. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17879. return new Geometry();
  17880. }
  17881. var shapes = font.generateShapes( text, parameters.size );
  17882. // translate parameters to ExtrudeGeometry API
  17883. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17884. // defaults
  17885. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17886. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17887. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17888. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17889. this.type = 'TextBufferGeometry';
  17890. }
  17891. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17892. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17893. /**
  17894. * @author mrdoob / http://mrdoob.com/
  17895. * @author benaadams / https://twitter.com/ben_a_adams
  17896. * @author Mugen87 / https://github.com/Mugen87
  17897. */
  17898. // SphereGeometry
  17899. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17900. Geometry.call( this );
  17901. this.type = 'SphereGeometry';
  17902. this.parameters = {
  17903. radius: radius,
  17904. widthSegments: widthSegments,
  17905. heightSegments: heightSegments,
  17906. phiStart: phiStart,
  17907. phiLength: phiLength,
  17908. thetaStart: thetaStart,
  17909. thetaLength: thetaLength
  17910. };
  17911. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17912. this.mergeVertices();
  17913. }
  17914. SphereGeometry.prototype = Object.create( Geometry.prototype );
  17915. SphereGeometry.prototype.constructor = SphereGeometry;
  17916. // SphereBufferGeometry
  17917. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17918. BufferGeometry.call( this );
  17919. this.type = 'SphereBufferGeometry';
  17920. this.parameters = {
  17921. radius: radius,
  17922. widthSegments: widthSegments,
  17923. heightSegments: heightSegments,
  17924. phiStart: phiStart,
  17925. phiLength: phiLength,
  17926. thetaStart: thetaStart,
  17927. thetaLength: thetaLength
  17928. };
  17929. radius = radius || 1;
  17930. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17931. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17932. phiStart = phiStart !== undefined ? phiStart : 0;
  17933. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  17934. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17935. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  17936. var thetaEnd = thetaStart + thetaLength;
  17937. var ix, iy;
  17938. var index = 0;
  17939. var grid = [];
  17940. var vertex = new Vector3();
  17941. var normal = new Vector3();
  17942. // buffers
  17943. var indices = [];
  17944. var vertices = [];
  17945. var normals = [];
  17946. var uvs = [];
  17947. // generate vertices, normals and uvs
  17948. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  17949. var verticesRow = [];
  17950. var v = iy / heightSegments;
  17951. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  17952. var u = ix / widthSegments;
  17953. // vertex
  17954. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17955. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  17956. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17957. vertices.push( vertex.x, vertex.y, vertex.z );
  17958. // normal
  17959. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  17960. normals.push( normal.x, normal.y, normal.z );
  17961. // uv
  17962. uvs.push( u, 1 - v );
  17963. verticesRow.push( index ++ );
  17964. }
  17965. grid.push( verticesRow );
  17966. }
  17967. // indices
  17968. for ( iy = 0; iy < heightSegments; iy ++ ) {
  17969. for ( ix = 0; ix < widthSegments; ix ++ ) {
  17970. var a = grid[ iy ][ ix + 1 ];
  17971. var b = grid[ iy ][ ix ];
  17972. var c = grid[ iy + 1 ][ ix ];
  17973. var d = grid[ iy + 1 ][ ix + 1 ];
  17974. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  17975. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  17976. }
  17977. }
  17978. // build geometry
  17979. this.setIndex( indices );
  17980. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17981. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17982. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17983. }
  17984. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17985. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  17986. /**
  17987. * @author Kaleb Murphy
  17988. * @author Mugen87 / https://github.com/Mugen87
  17989. */
  17990. // RingGeometry
  17991. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17992. Geometry.call( this );
  17993. this.type = 'RingGeometry';
  17994. this.parameters = {
  17995. innerRadius: innerRadius,
  17996. outerRadius: outerRadius,
  17997. thetaSegments: thetaSegments,
  17998. phiSegments: phiSegments,
  17999. thetaStart: thetaStart,
  18000. thetaLength: thetaLength
  18001. };
  18002. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18003. this.mergeVertices();
  18004. }
  18005. RingGeometry.prototype = Object.create( Geometry.prototype );
  18006. RingGeometry.prototype.constructor = RingGeometry;
  18007. // RingBufferGeometry
  18008. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18009. BufferGeometry.call( this );
  18010. this.type = 'RingBufferGeometry';
  18011. this.parameters = {
  18012. innerRadius: innerRadius,
  18013. outerRadius: outerRadius,
  18014. thetaSegments: thetaSegments,
  18015. phiSegments: phiSegments,
  18016. thetaStart: thetaStart,
  18017. thetaLength: thetaLength
  18018. };
  18019. innerRadius = innerRadius || 0.5;
  18020. outerRadius = outerRadius || 1;
  18021. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18022. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18023. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18024. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18025. // buffers
  18026. var indices = [];
  18027. var vertices = [];
  18028. var normals = [];
  18029. var uvs = [];
  18030. // some helper variables
  18031. var segment;
  18032. var radius = innerRadius;
  18033. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18034. var vertex = new Vector3();
  18035. var uv = new Vector2();
  18036. var j, i;
  18037. // generate vertices, normals and uvs
  18038. for ( j = 0; j <= phiSegments; j ++ ) {
  18039. for ( i = 0; i <= thetaSegments; i ++ ) {
  18040. // values are generate from the inside of the ring to the outside
  18041. segment = thetaStart + i / thetaSegments * thetaLength;
  18042. // vertex
  18043. vertex.x = radius * Math.cos( segment );
  18044. vertex.y = radius * Math.sin( segment );
  18045. vertices.push( vertex.x, vertex.y, vertex.z );
  18046. // normal
  18047. normals.push( 0, 0, 1 );
  18048. // uv
  18049. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18050. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18051. uvs.push( uv.x, uv.y );
  18052. }
  18053. // increase the radius for next row of vertices
  18054. radius += radiusStep;
  18055. }
  18056. // indices
  18057. for ( j = 0; j < phiSegments; j ++ ) {
  18058. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18059. for ( i = 0; i < thetaSegments; i ++ ) {
  18060. segment = i + thetaSegmentLevel;
  18061. var a = segment;
  18062. var b = segment + thetaSegments + 1;
  18063. var c = segment + thetaSegments + 2;
  18064. var d = segment + 1;
  18065. // faces
  18066. indices.push( a, b, d );
  18067. indices.push( b, c, d );
  18068. }
  18069. }
  18070. // build geometry
  18071. this.setIndex( indices );
  18072. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18073. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18074. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18075. }
  18076. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18077. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18078. /**
  18079. * @author zz85 / https://github.com/zz85
  18080. * @author bhouston / http://clara.io
  18081. * @author Mugen87 / https://github.com/Mugen87
  18082. */
  18083. // LatheGeometry
  18084. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18085. Geometry.call( this );
  18086. this.type = 'LatheGeometry';
  18087. this.parameters = {
  18088. points: points,
  18089. segments: segments,
  18090. phiStart: phiStart,
  18091. phiLength: phiLength
  18092. };
  18093. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18094. this.mergeVertices();
  18095. }
  18096. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18097. LatheGeometry.prototype.constructor = LatheGeometry;
  18098. // LatheBufferGeometry
  18099. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18100. BufferGeometry.call( this );
  18101. this.type = 'LatheBufferGeometry';
  18102. this.parameters = {
  18103. points: points,
  18104. segments: segments,
  18105. phiStart: phiStart,
  18106. phiLength: phiLength
  18107. };
  18108. segments = Math.floor( segments ) || 12;
  18109. phiStart = phiStart || 0;
  18110. phiLength = phiLength || Math.PI * 2;
  18111. // clamp phiLength so it's in range of [ 0, 2PI ]
  18112. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18113. // buffers
  18114. var indices = [];
  18115. var vertices = [];
  18116. var uvs = [];
  18117. // helper variables
  18118. var base;
  18119. var inverseSegments = 1.0 / segments;
  18120. var vertex = new Vector3();
  18121. var uv = new Vector2();
  18122. var i, j;
  18123. // generate vertices and uvs
  18124. for ( i = 0; i <= segments; i ++ ) {
  18125. var phi = phiStart + i * inverseSegments * phiLength;
  18126. var sin = Math.sin( phi );
  18127. var cos = Math.cos( phi );
  18128. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18129. // vertex
  18130. vertex.x = points[ j ].x * sin;
  18131. vertex.y = points[ j ].y;
  18132. vertex.z = points[ j ].x * cos;
  18133. vertices.push( vertex.x, vertex.y, vertex.z );
  18134. // uv
  18135. uv.x = i / segments;
  18136. uv.y = j / ( points.length - 1 );
  18137. uvs.push( uv.x, uv.y );
  18138. }
  18139. }
  18140. // indices
  18141. for ( i = 0; i < segments; i ++ ) {
  18142. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18143. base = j + i * points.length;
  18144. var a = base;
  18145. var b = base + points.length;
  18146. var c = base + points.length + 1;
  18147. var d = base + 1;
  18148. // faces
  18149. indices.push( a, b, d );
  18150. indices.push( b, c, d );
  18151. }
  18152. }
  18153. // build geometry
  18154. this.setIndex( indices );
  18155. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18156. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18157. // generate normals
  18158. this.computeVertexNormals();
  18159. // if the geometry is closed, we need to average the normals along the seam.
  18160. // because the corresponding vertices are identical (but still have different UVs).
  18161. if ( phiLength === Math.PI * 2 ) {
  18162. var normals = this.attributes.normal.array;
  18163. var n1 = new Vector3();
  18164. var n2 = new Vector3();
  18165. var n = new Vector3();
  18166. // this is the buffer offset for the last line of vertices
  18167. base = segments * points.length * 3;
  18168. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18169. // select the normal of the vertex in the first line
  18170. n1.x = normals[ j + 0 ];
  18171. n1.y = normals[ j + 1 ];
  18172. n1.z = normals[ j + 2 ];
  18173. // select the normal of the vertex in the last line
  18174. n2.x = normals[ base + j + 0 ];
  18175. n2.y = normals[ base + j + 1 ];
  18176. n2.z = normals[ base + j + 2 ];
  18177. // average normals
  18178. n.addVectors( n1, n2 ).normalize();
  18179. // assign the new values to both normals
  18180. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18181. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18182. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18183. }
  18184. }
  18185. }
  18186. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18187. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18188. /**
  18189. * @author jonobr1 / http://jonobr1.com
  18190. * @author Mugen87 / https://github.com/Mugen87
  18191. */
  18192. // ShapeGeometry
  18193. function ShapeGeometry( shapes, curveSegments ) {
  18194. Geometry.call( this );
  18195. this.type = 'ShapeGeometry';
  18196. if ( typeof curveSegments === 'object' ) {
  18197. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18198. curveSegments = curveSegments.curveSegments;
  18199. }
  18200. this.parameters = {
  18201. shapes: shapes,
  18202. curveSegments: curveSegments
  18203. };
  18204. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18205. this.mergeVertices();
  18206. }
  18207. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18208. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18209. ShapeGeometry.prototype.toJSON = function () {
  18210. var data = Geometry.prototype.toJSON.call( this );
  18211. var shapes = this.parameters.shapes;
  18212. return toJSON$1( shapes, data );
  18213. };
  18214. // ShapeBufferGeometry
  18215. function ShapeBufferGeometry( shapes, curveSegments ) {
  18216. BufferGeometry.call( this );
  18217. this.type = 'ShapeBufferGeometry';
  18218. this.parameters = {
  18219. shapes: shapes,
  18220. curveSegments: curveSegments
  18221. };
  18222. curveSegments = curveSegments || 12;
  18223. // buffers
  18224. var indices = [];
  18225. var vertices = [];
  18226. var normals = [];
  18227. var uvs = [];
  18228. // helper variables
  18229. var groupStart = 0;
  18230. var groupCount = 0;
  18231. // allow single and array values for "shapes" parameter
  18232. if ( Array.isArray( shapes ) === false ) {
  18233. addShape( shapes );
  18234. } else {
  18235. for ( var i = 0; i < shapes.length; i ++ ) {
  18236. addShape( shapes[ i ] );
  18237. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18238. groupStart += groupCount;
  18239. groupCount = 0;
  18240. }
  18241. }
  18242. // build geometry
  18243. this.setIndex( indices );
  18244. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18245. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18246. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18247. // helper functions
  18248. function addShape( shape ) {
  18249. var i, l, shapeHole;
  18250. var indexOffset = vertices.length / 3;
  18251. var points = shape.extractPoints( curveSegments );
  18252. var shapeVertices = points.shape;
  18253. var shapeHoles = points.holes;
  18254. // check direction of vertices
  18255. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18256. shapeVertices = shapeVertices.reverse();
  18257. }
  18258. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18259. shapeHole = shapeHoles[ i ];
  18260. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18261. shapeHoles[ i ] = shapeHole.reverse();
  18262. }
  18263. }
  18264. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18265. // join vertices of inner and outer paths to a single array
  18266. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18267. shapeHole = shapeHoles[ i ];
  18268. shapeVertices = shapeVertices.concat( shapeHole );
  18269. }
  18270. // vertices, normals, uvs
  18271. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18272. var vertex = shapeVertices[ i ];
  18273. vertices.push( vertex.x, vertex.y, 0 );
  18274. normals.push( 0, 0, 1 );
  18275. uvs.push( vertex.x, vertex.y ); // world uvs
  18276. }
  18277. // incides
  18278. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18279. var face = faces[ i ];
  18280. var a = face[ 0 ] + indexOffset;
  18281. var b = face[ 1 ] + indexOffset;
  18282. var c = face[ 2 ] + indexOffset;
  18283. indices.push( a, b, c );
  18284. groupCount += 3;
  18285. }
  18286. }
  18287. }
  18288. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18289. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18290. ShapeBufferGeometry.prototype.toJSON = function () {
  18291. var data = BufferGeometry.prototype.toJSON.call( this );
  18292. var shapes = this.parameters.shapes;
  18293. return toJSON$1( shapes, data );
  18294. };
  18295. //
  18296. function toJSON$1( shapes, data ) {
  18297. data.shapes = [];
  18298. if ( Array.isArray( shapes ) ) {
  18299. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18300. var shape = shapes[ i ];
  18301. data.shapes.push( shape.uuid );
  18302. }
  18303. } else {
  18304. data.shapes.push( shapes.uuid );
  18305. }
  18306. return data;
  18307. }
  18308. /**
  18309. * @author WestLangley / http://github.com/WestLangley
  18310. * @author Mugen87 / https://github.com/Mugen87
  18311. */
  18312. function EdgesGeometry( geometry, thresholdAngle ) {
  18313. BufferGeometry.call( this );
  18314. this.type = 'EdgesGeometry';
  18315. this.parameters = {
  18316. thresholdAngle: thresholdAngle
  18317. };
  18318. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18319. // buffer
  18320. var vertices = [];
  18321. // helper variables
  18322. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18323. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18324. var key, keys = [ 'a', 'b', 'c' ];
  18325. // prepare source geometry
  18326. var geometry2;
  18327. if ( geometry.isBufferGeometry ) {
  18328. geometry2 = new Geometry();
  18329. geometry2.fromBufferGeometry( geometry );
  18330. } else {
  18331. geometry2 = geometry.clone();
  18332. }
  18333. geometry2.mergeVertices();
  18334. geometry2.computeFaceNormals();
  18335. var sourceVertices = geometry2.vertices;
  18336. var faces = geometry2.faces;
  18337. // now create a data structure where each entry represents an edge with its adjoining faces
  18338. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18339. var face = faces[ i ];
  18340. for ( var j = 0; j < 3; j ++ ) {
  18341. edge1 = face[ keys[ j ] ];
  18342. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18343. edge[ 0 ] = Math.min( edge1, edge2 );
  18344. edge[ 1 ] = Math.max( edge1, edge2 );
  18345. key = edge[ 0 ] + ',' + edge[ 1 ];
  18346. if ( edges[ key ] === undefined ) {
  18347. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18348. } else {
  18349. edges[ key ].face2 = i;
  18350. }
  18351. }
  18352. }
  18353. // generate vertices
  18354. for ( key in edges ) {
  18355. var e = edges[ key ];
  18356. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18357. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18358. var vertex = sourceVertices[ e.index1 ];
  18359. vertices.push( vertex.x, vertex.y, vertex.z );
  18360. vertex = sourceVertices[ e.index2 ];
  18361. vertices.push( vertex.x, vertex.y, vertex.z );
  18362. }
  18363. }
  18364. // build geometry
  18365. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18366. }
  18367. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18368. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18369. /**
  18370. * @author mrdoob / http://mrdoob.com/
  18371. * @author Mugen87 / https://github.com/Mugen87
  18372. */
  18373. // CylinderGeometry
  18374. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18375. Geometry.call( this );
  18376. this.type = 'CylinderGeometry';
  18377. this.parameters = {
  18378. radiusTop: radiusTop,
  18379. radiusBottom: radiusBottom,
  18380. height: height,
  18381. radialSegments: radialSegments,
  18382. heightSegments: heightSegments,
  18383. openEnded: openEnded,
  18384. thetaStart: thetaStart,
  18385. thetaLength: thetaLength
  18386. };
  18387. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18388. this.mergeVertices();
  18389. }
  18390. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18391. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18392. // CylinderBufferGeometry
  18393. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18394. BufferGeometry.call( this );
  18395. this.type = 'CylinderBufferGeometry';
  18396. this.parameters = {
  18397. radiusTop: radiusTop,
  18398. radiusBottom: radiusBottom,
  18399. height: height,
  18400. radialSegments: radialSegments,
  18401. heightSegments: heightSegments,
  18402. openEnded: openEnded,
  18403. thetaStart: thetaStart,
  18404. thetaLength: thetaLength
  18405. };
  18406. var scope = this;
  18407. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18408. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18409. height = height || 1;
  18410. radialSegments = Math.floor( radialSegments ) || 8;
  18411. heightSegments = Math.floor( heightSegments ) || 1;
  18412. openEnded = openEnded !== undefined ? openEnded : false;
  18413. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18414. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18415. // buffers
  18416. var indices = [];
  18417. var vertices = [];
  18418. var normals = [];
  18419. var uvs = [];
  18420. // helper variables
  18421. var index = 0;
  18422. var indexArray = [];
  18423. var halfHeight = height / 2;
  18424. var groupStart = 0;
  18425. // generate geometry
  18426. generateTorso();
  18427. if ( openEnded === false ) {
  18428. if ( radiusTop > 0 ) generateCap( true );
  18429. if ( radiusBottom > 0 ) generateCap( false );
  18430. }
  18431. // build geometry
  18432. this.setIndex( indices );
  18433. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18434. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18435. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18436. function generateTorso() {
  18437. var x, y;
  18438. var normal = new Vector3();
  18439. var vertex = new Vector3();
  18440. var groupCount = 0;
  18441. // this will be used to calculate the normal
  18442. var slope = ( radiusBottom - radiusTop ) / height;
  18443. // generate vertices, normals and uvs
  18444. for ( y = 0; y <= heightSegments; y ++ ) {
  18445. var indexRow = [];
  18446. var v = y / heightSegments;
  18447. // calculate the radius of the current row
  18448. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18449. for ( x = 0; x <= radialSegments; x ++ ) {
  18450. var u = x / radialSegments;
  18451. var theta = u * thetaLength + thetaStart;
  18452. var sinTheta = Math.sin( theta );
  18453. var cosTheta = Math.cos( theta );
  18454. // vertex
  18455. vertex.x = radius * sinTheta;
  18456. vertex.y = - v * height + halfHeight;
  18457. vertex.z = radius * cosTheta;
  18458. vertices.push( vertex.x, vertex.y, vertex.z );
  18459. // normal
  18460. normal.set( sinTheta, slope, cosTheta ).normalize();
  18461. normals.push( normal.x, normal.y, normal.z );
  18462. // uv
  18463. uvs.push( u, 1 - v );
  18464. // save index of vertex in respective row
  18465. indexRow.push( index ++ );
  18466. }
  18467. // now save vertices of the row in our index array
  18468. indexArray.push( indexRow );
  18469. }
  18470. // generate indices
  18471. for ( x = 0; x < radialSegments; x ++ ) {
  18472. for ( y = 0; y < heightSegments; y ++ ) {
  18473. // we use the index array to access the correct indices
  18474. var a = indexArray[ y ][ x ];
  18475. var b = indexArray[ y + 1 ][ x ];
  18476. var c = indexArray[ y + 1 ][ x + 1 ];
  18477. var d = indexArray[ y ][ x + 1 ];
  18478. // faces
  18479. indices.push( a, b, d );
  18480. indices.push( b, c, d );
  18481. // update group counter
  18482. groupCount += 6;
  18483. }
  18484. }
  18485. // add a group to the geometry. this will ensure multi material support
  18486. scope.addGroup( groupStart, groupCount, 0 );
  18487. // calculate new start value for groups
  18488. groupStart += groupCount;
  18489. }
  18490. function generateCap( top ) {
  18491. var x, centerIndexStart, centerIndexEnd;
  18492. var uv = new Vector2();
  18493. var vertex = new Vector3();
  18494. var groupCount = 0;
  18495. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18496. var sign = ( top === true ) ? 1 : - 1;
  18497. // save the index of the first center vertex
  18498. centerIndexStart = index;
  18499. // first we generate the center vertex data of the cap.
  18500. // because the geometry needs one set of uvs per face,
  18501. // we must generate a center vertex per face/segment
  18502. for ( x = 1; x <= radialSegments; x ++ ) {
  18503. // vertex
  18504. vertices.push( 0, halfHeight * sign, 0 );
  18505. // normal
  18506. normals.push( 0, sign, 0 );
  18507. // uv
  18508. uvs.push( 0.5, 0.5 );
  18509. // increase index
  18510. index ++;
  18511. }
  18512. // save the index of the last center vertex
  18513. centerIndexEnd = index;
  18514. // now we generate the surrounding vertices, normals and uvs
  18515. for ( x = 0; x <= radialSegments; x ++ ) {
  18516. var u = x / radialSegments;
  18517. var theta = u * thetaLength + thetaStart;
  18518. var cosTheta = Math.cos( theta );
  18519. var sinTheta = Math.sin( theta );
  18520. // vertex
  18521. vertex.x = radius * sinTheta;
  18522. vertex.y = halfHeight * sign;
  18523. vertex.z = radius * cosTheta;
  18524. vertices.push( vertex.x, vertex.y, vertex.z );
  18525. // normal
  18526. normals.push( 0, sign, 0 );
  18527. // uv
  18528. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18529. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18530. uvs.push( uv.x, uv.y );
  18531. // increase index
  18532. index ++;
  18533. }
  18534. // generate indices
  18535. for ( x = 0; x < radialSegments; x ++ ) {
  18536. var c = centerIndexStart + x;
  18537. var i = centerIndexEnd + x;
  18538. if ( top === true ) {
  18539. // face top
  18540. indices.push( i, i + 1, c );
  18541. } else {
  18542. // face bottom
  18543. indices.push( i + 1, i, c );
  18544. }
  18545. groupCount += 3;
  18546. }
  18547. // add a group to the geometry. this will ensure multi material support
  18548. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18549. // calculate new start value for groups
  18550. groupStart += groupCount;
  18551. }
  18552. }
  18553. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18554. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18555. /**
  18556. * @author abelnation / http://github.com/abelnation
  18557. */
  18558. // ConeGeometry
  18559. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18560. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18561. this.type = 'ConeGeometry';
  18562. this.parameters = {
  18563. radius: radius,
  18564. height: height,
  18565. radialSegments: radialSegments,
  18566. heightSegments: heightSegments,
  18567. openEnded: openEnded,
  18568. thetaStart: thetaStart,
  18569. thetaLength: thetaLength
  18570. };
  18571. }
  18572. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18573. ConeGeometry.prototype.constructor = ConeGeometry;
  18574. // ConeBufferGeometry
  18575. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18576. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18577. this.type = 'ConeBufferGeometry';
  18578. this.parameters = {
  18579. radius: radius,
  18580. height: height,
  18581. radialSegments: radialSegments,
  18582. heightSegments: heightSegments,
  18583. openEnded: openEnded,
  18584. thetaStart: thetaStart,
  18585. thetaLength: thetaLength
  18586. };
  18587. }
  18588. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18589. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18590. /**
  18591. * @author benaadams / https://twitter.com/ben_a_adams
  18592. * @author Mugen87 / https://github.com/Mugen87
  18593. * @author hughes
  18594. */
  18595. // CircleGeometry
  18596. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18597. Geometry.call( this );
  18598. this.type = 'CircleGeometry';
  18599. this.parameters = {
  18600. radius: radius,
  18601. segments: segments,
  18602. thetaStart: thetaStart,
  18603. thetaLength: thetaLength
  18604. };
  18605. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18606. this.mergeVertices();
  18607. }
  18608. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18609. CircleGeometry.prototype.constructor = CircleGeometry;
  18610. // CircleBufferGeometry
  18611. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18612. BufferGeometry.call( this );
  18613. this.type = 'CircleBufferGeometry';
  18614. this.parameters = {
  18615. radius: radius,
  18616. segments: segments,
  18617. thetaStart: thetaStart,
  18618. thetaLength: thetaLength
  18619. };
  18620. radius = radius || 1;
  18621. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18622. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18623. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18624. // buffers
  18625. var indices = [];
  18626. var vertices = [];
  18627. var normals = [];
  18628. var uvs = [];
  18629. // helper variables
  18630. var i, s;
  18631. var vertex = new Vector3();
  18632. var uv = new Vector2();
  18633. // center point
  18634. vertices.push( 0, 0, 0 );
  18635. normals.push( 0, 0, 1 );
  18636. uvs.push( 0.5, 0.5 );
  18637. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18638. var segment = thetaStart + s / segments * thetaLength;
  18639. // vertex
  18640. vertex.x = radius * Math.cos( segment );
  18641. vertex.y = radius * Math.sin( segment );
  18642. vertices.push( vertex.x, vertex.y, vertex.z );
  18643. // normal
  18644. normals.push( 0, 0, 1 );
  18645. // uvs
  18646. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  18647. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  18648. uvs.push( uv.x, uv.y );
  18649. }
  18650. // indices
  18651. for ( i = 1; i <= segments; i ++ ) {
  18652. indices.push( i, i + 1, 0 );
  18653. }
  18654. // build geometry
  18655. this.setIndex( indices );
  18656. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18657. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18658. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18659. }
  18660. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18661. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  18662. var Geometries = /*#__PURE__*/Object.freeze({
  18663. WireframeGeometry: WireframeGeometry,
  18664. ParametricGeometry: ParametricGeometry,
  18665. ParametricBufferGeometry: ParametricBufferGeometry,
  18666. TetrahedronGeometry: TetrahedronGeometry,
  18667. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  18668. OctahedronGeometry: OctahedronGeometry,
  18669. OctahedronBufferGeometry: OctahedronBufferGeometry,
  18670. IcosahedronGeometry: IcosahedronGeometry,
  18671. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  18672. DodecahedronGeometry: DodecahedronGeometry,
  18673. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  18674. PolyhedronGeometry: PolyhedronGeometry,
  18675. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  18676. TubeGeometry: TubeGeometry,
  18677. TubeBufferGeometry: TubeBufferGeometry,
  18678. TorusKnotGeometry: TorusKnotGeometry,
  18679. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  18680. TorusGeometry: TorusGeometry,
  18681. TorusBufferGeometry: TorusBufferGeometry,
  18682. TextGeometry: TextGeometry,
  18683. TextBufferGeometry: TextBufferGeometry,
  18684. SphereGeometry: SphereGeometry,
  18685. SphereBufferGeometry: SphereBufferGeometry,
  18686. RingGeometry: RingGeometry,
  18687. RingBufferGeometry: RingBufferGeometry,
  18688. PlaneGeometry: PlaneGeometry,
  18689. PlaneBufferGeometry: PlaneBufferGeometry,
  18690. LatheGeometry: LatheGeometry,
  18691. LatheBufferGeometry: LatheBufferGeometry,
  18692. ShapeGeometry: ShapeGeometry,
  18693. ShapeBufferGeometry: ShapeBufferGeometry,
  18694. ExtrudeGeometry: ExtrudeGeometry,
  18695. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  18696. EdgesGeometry: EdgesGeometry,
  18697. ConeGeometry: ConeGeometry,
  18698. ConeBufferGeometry: ConeBufferGeometry,
  18699. CylinderGeometry: CylinderGeometry,
  18700. CylinderBufferGeometry: CylinderBufferGeometry,
  18701. CircleGeometry: CircleGeometry,
  18702. CircleBufferGeometry: CircleBufferGeometry,
  18703. BoxGeometry: BoxGeometry,
  18704. BoxBufferGeometry: BoxBufferGeometry
  18705. });
  18706. /**
  18707. * @author mrdoob / http://mrdoob.com/
  18708. *
  18709. * parameters = {
  18710. * color: <THREE.Color>
  18711. * }
  18712. */
  18713. function ShadowMaterial( parameters ) {
  18714. Material.call( this );
  18715. this.type = 'ShadowMaterial';
  18716. this.color = new Color( 0x000000 );
  18717. this.transparent = true;
  18718. this.setValues( parameters );
  18719. }
  18720. ShadowMaterial.prototype = Object.create( Material.prototype );
  18721. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18722. ShadowMaterial.prototype.isShadowMaterial = true;
  18723. ShadowMaterial.prototype.copy = function ( source ) {
  18724. Material.prototype.copy.call( this, source );
  18725. this.color.copy( source.color );
  18726. return this;
  18727. };
  18728. /**
  18729. * @author mrdoob / http://mrdoob.com/
  18730. */
  18731. function RawShaderMaterial( parameters ) {
  18732. ShaderMaterial.call( this, parameters );
  18733. this.type = 'RawShaderMaterial';
  18734. }
  18735. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18736. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18737. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18738. /**
  18739. * @author WestLangley / http://github.com/WestLangley
  18740. *
  18741. * parameters = {
  18742. * color: <hex>,
  18743. * roughness: <float>,
  18744. * metalness: <float>,
  18745. * opacity: <float>,
  18746. *
  18747. * map: new THREE.Texture( <Image> ),
  18748. *
  18749. * lightMap: new THREE.Texture( <Image> ),
  18750. * lightMapIntensity: <float>
  18751. *
  18752. * aoMap: new THREE.Texture( <Image> ),
  18753. * aoMapIntensity: <float>
  18754. *
  18755. * emissive: <hex>,
  18756. * emissiveIntensity: <float>
  18757. * emissiveMap: new THREE.Texture( <Image> ),
  18758. *
  18759. * bumpMap: new THREE.Texture( <Image> ),
  18760. * bumpScale: <float>,
  18761. *
  18762. * normalMap: new THREE.Texture( <Image> ),
  18763. * normalMapType: THREE.TangentSpaceNormalMap,
  18764. * normalScale: <Vector2>,
  18765. *
  18766. * displacementMap: new THREE.Texture( <Image> ),
  18767. * displacementScale: <float>,
  18768. * displacementBias: <float>,
  18769. *
  18770. * roughnessMap: new THREE.Texture( <Image> ),
  18771. *
  18772. * metalnessMap: new THREE.Texture( <Image> ),
  18773. *
  18774. * alphaMap: new THREE.Texture( <Image> ),
  18775. *
  18776. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18777. * envMapIntensity: <float>
  18778. *
  18779. * refractionRatio: <float>,
  18780. *
  18781. * wireframe: <boolean>,
  18782. * wireframeLinewidth: <float>,
  18783. *
  18784. * skinning: <bool>,
  18785. * morphTargets: <bool>,
  18786. * morphNormals: <bool>
  18787. * }
  18788. */
  18789. function MeshStandardMaterial( parameters ) {
  18790. Material.call( this );
  18791. this.defines = { 'STANDARD': '' };
  18792. this.type = 'MeshStandardMaterial';
  18793. this.color = new Color( 0xffffff ); // diffuse
  18794. this.roughness = 0.5;
  18795. this.metalness = 0.5;
  18796. this.map = null;
  18797. this.lightMap = null;
  18798. this.lightMapIntensity = 1.0;
  18799. this.aoMap = null;
  18800. this.aoMapIntensity = 1.0;
  18801. this.emissive = new Color( 0x000000 );
  18802. this.emissiveIntensity = 1.0;
  18803. this.emissiveMap = null;
  18804. this.bumpMap = null;
  18805. this.bumpScale = 1;
  18806. this.normalMap = null;
  18807. this.normalMapType = TangentSpaceNormalMap;
  18808. this.normalScale = new Vector2( 1, 1 );
  18809. this.displacementMap = null;
  18810. this.displacementScale = 1;
  18811. this.displacementBias = 0;
  18812. this.roughnessMap = null;
  18813. this.metalnessMap = null;
  18814. this.alphaMap = null;
  18815. this.envMap = null;
  18816. this.envMapIntensity = 1.0;
  18817. this.refractionRatio = 0.98;
  18818. this.wireframe = false;
  18819. this.wireframeLinewidth = 1;
  18820. this.wireframeLinecap = 'round';
  18821. this.wireframeLinejoin = 'round';
  18822. this.skinning = false;
  18823. this.morphTargets = false;
  18824. this.morphNormals = false;
  18825. this.setValues( parameters );
  18826. }
  18827. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18828. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18829. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18830. MeshStandardMaterial.prototype.copy = function ( source ) {
  18831. Material.prototype.copy.call( this, source );
  18832. this.defines = { 'STANDARD': '' };
  18833. this.color.copy( source.color );
  18834. this.roughness = source.roughness;
  18835. this.metalness = source.metalness;
  18836. this.map = source.map;
  18837. this.lightMap = source.lightMap;
  18838. this.lightMapIntensity = source.lightMapIntensity;
  18839. this.aoMap = source.aoMap;
  18840. this.aoMapIntensity = source.aoMapIntensity;
  18841. this.emissive.copy( source.emissive );
  18842. this.emissiveMap = source.emissiveMap;
  18843. this.emissiveIntensity = source.emissiveIntensity;
  18844. this.bumpMap = source.bumpMap;
  18845. this.bumpScale = source.bumpScale;
  18846. this.normalMap = source.normalMap;
  18847. this.normalMapType = source.normalMapType;
  18848. this.normalScale.copy( source.normalScale );
  18849. this.displacementMap = source.displacementMap;
  18850. this.displacementScale = source.displacementScale;
  18851. this.displacementBias = source.displacementBias;
  18852. this.roughnessMap = source.roughnessMap;
  18853. this.metalnessMap = source.metalnessMap;
  18854. this.alphaMap = source.alphaMap;
  18855. this.envMap = source.envMap;
  18856. this.envMapIntensity = source.envMapIntensity;
  18857. this.refractionRatio = source.refractionRatio;
  18858. this.wireframe = source.wireframe;
  18859. this.wireframeLinewidth = source.wireframeLinewidth;
  18860. this.wireframeLinecap = source.wireframeLinecap;
  18861. this.wireframeLinejoin = source.wireframeLinejoin;
  18862. this.skinning = source.skinning;
  18863. this.morphTargets = source.morphTargets;
  18864. this.morphNormals = source.morphNormals;
  18865. return this;
  18866. };
  18867. /**
  18868. * @author WestLangley / http://github.com/WestLangley
  18869. *
  18870. * parameters = {
  18871. * reflectivity: <float>
  18872. * clearCoat: <float>
  18873. * clearCoatRoughness: <float>
  18874. * }
  18875. */
  18876. function MeshPhysicalMaterial( parameters ) {
  18877. MeshStandardMaterial.call( this );
  18878. this.defines = { 'PHYSICAL': '' };
  18879. this.type = 'MeshPhysicalMaterial';
  18880. this.reflectivity = 0.5; // maps to F0 = 0.04
  18881. this.clearCoat = 0.0;
  18882. this.clearCoatRoughness = 0.0;
  18883. this.setValues( parameters );
  18884. }
  18885. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18886. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18887. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18888. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18889. MeshStandardMaterial.prototype.copy.call( this, source );
  18890. this.defines = { 'PHYSICAL': '' };
  18891. this.reflectivity = source.reflectivity;
  18892. this.clearCoat = source.clearCoat;
  18893. this.clearCoatRoughness = source.clearCoatRoughness;
  18894. return this;
  18895. };
  18896. /**
  18897. * @author mrdoob / http://mrdoob.com/
  18898. * @author alteredq / http://alteredqualia.com/
  18899. *
  18900. * parameters = {
  18901. * color: <hex>,
  18902. * specular: <hex>,
  18903. * shininess: <float>,
  18904. * opacity: <float>,
  18905. *
  18906. * map: new THREE.Texture( <Image> ),
  18907. *
  18908. * lightMap: new THREE.Texture( <Image> ),
  18909. * lightMapIntensity: <float>
  18910. *
  18911. * aoMap: new THREE.Texture( <Image> ),
  18912. * aoMapIntensity: <float>
  18913. *
  18914. * emissive: <hex>,
  18915. * emissiveIntensity: <float>
  18916. * emissiveMap: new THREE.Texture( <Image> ),
  18917. *
  18918. * bumpMap: new THREE.Texture( <Image> ),
  18919. * bumpScale: <float>,
  18920. *
  18921. * normalMap: new THREE.Texture( <Image> ),
  18922. * normalMapType: THREE.TangentSpaceNormalMap,
  18923. * normalScale: <Vector2>,
  18924. *
  18925. * displacementMap: new THREE.Texture( <Image> ),
  18926. * displacementScale: <float>,
  18927. * displacementBias: <float>,
  18928. *
  18929. * specularMap: new THREE.Texture( <Image> ),
  18930. *
  18931. * alphaMap: new THREE.Texture( <Image> ),
  18932. *
  18933. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18934. * combine: THREE.Multiply,
  18935. * reflectivity: <float>,
  18936. * refractionRatio: <float>,
  18937. *
  18938. * wireframe: <boolean>,
  18939. * wireframeLinewidth: <float>,
  18940. *
  18941. * skinning: <bool>,
  18942. * morphTargets: <bool>,
  18943. * morphNormals: <bool>
  18944. * }
  18945. */
  18946. function MeshPhongMaterial( parameters ) {
  18947. Material.call( this );
  18948. this.type = 'MeshPhongMaterial';
  18949. this.color = new Color( 0xffffff ); // diffuse
  18950. this.specular = new Color( 0x111111 );
  18951. this.shininess = 30;
  18952. this.map = null;
  18953. this.lightMap = null;
  18954. this.lightMapIntensity = 1.0;
  18955. this.aoMap = null;
  18956. this.aoMapIntensity = 1.0;
  18957. this.emissive = new Color( 0x000000 );
  18958. this.emissiveIntensity = 1.0;
  18959. this.emissiveMap = null;
  18960. this.bumpMap = null;
  18961. this.bumpScale = 1;
  18962. this.normalMap = null;
  18963. this.normalMapType = TangentSpaceNormalMap;
  18964. this.normalScale = new Vector2( 1, 1 );
  18965. this.displacementMap = null;
  18966. this.displacementScale = 1;
  18967. this.displacementBias = 0;
  18968. this.specularMap = null;
  18969. this.alphaMap = null;
  18970. this.envMap = null;
  18971. this.combine = MultiplyOperation;
  18972. this.reflectivity = 1;
  18973. this.refractionRatio = 0.98;
  18974. this.wireframe = false;
  18975. this.wireframeLinewidth = 1;
  18976. this.wireframeLinecap = 'round';
  18977. this.wireframeLinejoin = 'round';
  18978. this.skinning = false;
  18979. this.morphTargets = false;
  18980. this.morphNormals = false;
  18981. this.setValues( parameters );
  18982. }
  18983. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  18984. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  18985. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  18986. MeshPhongMaterial.prototype.copy = function ( source ) {
  18987. Material.prototype.copy.call( this, source );
  18988. this.color.copy( source.color );
  18989. this.specular.copy( source.specular );
  18990. this.shininess = source.shininess;
  18991. this.map = source.map;
  18992. this.lightMap = source.lightMap;
  18993. this.lightMapIntensity = source.lightMapIntensity;
  18994. this.aoMap = source.aoMap;
  18995. this.aoMapIntensity = source.aoMapIntensity;
  18996. this.emissive.copy( source.emissive );
  18997. this.emissiveMap = source.emissiveMap;
  18998. this.emissiveIntensity = source.emissiveIntensity;
  18999. this.bumpMap = source.bumpMap;
  19000. this.bumpScale = source.bumpScale;
  19001. this.normalMap = source.normalMap;
  19002. this.normalMapType = source.normalMapType;
  19003. this.normalScale.copy( source.normalScale );
  19004. this.displacementMap = source.displacementMap;
  19005. this.displacementScale = source.displacementScale;
  19006. this.displacementBias = source.displacementBias;
  19007. this.specularMap = source.specularMap;
  19008. this.alphaMap = source.alphaMap;
  19009. this.envMap = source.envMap;
  19010. this.combine = source.combine;
  19011. this.reflectivity = source.reflectivity;
  19012. this.refractionRatio = source.refractionRatio;
  19013. this.wireframe = source.wireframe;
  19014. this.wireframeLinewidth = source.wireframeLinewidth;
  19015. this.wireframeLinecap = source.wireframeLinecap;
  19016. this.wireframeLinejoin = source.wireframeLinejoin;
  19017. this.skinning = source.skinning;
  19018. this.morphTargets = source.morphTargets;
  19019. this.morphNormals = source.morphNormals;
  19020. return this;
  19021. };
  19022. /**
  19023. * @author takahirox / http://github.com/takahirox
  19024. *
  19025. * parameters = {
  19026. * gradientMap: new THREE.Texture( <Image> )
  19027. * }
  19028. */
  19029. function MeshToonMaterial( parameters ) {
  19030. MeshPhongMaterial.call( this );
  19031. this.defines = { 'TOON': '' };
  19032. this.type = 'MeshToonMaterial';
  19033. this.gradientMap = null;
  19034. this.setValues( parameters );
  19035. }
  19036. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19037. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19038. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19039. MeshToonMaterial.prototype.copy = function ( source ) {
  19040. MeshPhongMaterial.prototype.copy.call( this, source );
  19041. this.gradientMap = source.gradientMap;
  19042. return this;
  19043. };
  19044. /**
  19045. * @author mrdoob / http://mrdoob.com/
  19046. * @author WestLangley / http://github.com/WestLangley
  19047. *
  19048. * parameters = {
  19049. * opacity: <float>,
  19050. *
  19051. * bumpMap: new THREE.Texture( <Image> ),
  19052. * bumpScale: <float>,
  19053. *
  19054. * normalMap: new THREE.Texture( <Image> ),
  19055. * normalMapType: THREE.TangentSpaceNormalMap,
  19056. * normalScale: <Vector2>,
  19057. *
  19058. * displacementMap: new THREE.Texture( <Image> ),
  19059. * displacementScale: <float>,
  19060. * displacementBias: <float>,
  19061. *
  19062. * wireframe: <boolean>,
  19063. * wireframeLinewidth: <float>
  19064. *
  19065. * skinning: <bool>,
  19066. * morphTargets: <bool>,
  19067. * morphNormals: <bool>
  19068. * }
  19069. */
  19070. function MeshNormalMaterial( parameters ) {
  19071. Material.call( this );
  19072. this.type = 'MeshNormalMaterial';
  19073. this.bumpMap = null;
  19074. this.bumpScale = 1;
  19075. this.normalMap = null;
  19076. this.normalMapType = TangentSpaceNormalMap;
  19077. this.normalScale = new Vector2( 1, 1 );
  19078. this.displacementMap = null;
  19079. this.displacementScale = 1;
  19080. this.displacementBias = 0;
  19081. this.wireframe = false;
  19082. this.wireframeLinewidth = 1;
  19083. this.fog = false;
  19084. this.lights = false;
  19085. this.skinning = false;
  19086. this.morphTargets = false;
  19087. this.morphNormals = false;
  19088. this.setValues( parameters );
  19089. }
  19090. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19091. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19092. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19093. MeshNormalMaterial.prototype.copy = function ( source ) {
  19094. Material.prototype.copy.call( this, source );
  19095. this.bumpMap = source.bumpMap;
  19096. this.bumpScale = source.bumpScale;
  19097. this.normalMap = source.normalMap;
  19098. this.normalMapType = source.normalMapType;
  19099. this.normalScale.copy( source.normalScale );
  19100. this.displacementMap = source.displacementMap;
  19101. this.displacementScale = source.displacementScale;
  19102. this.displacementBias = source.displacementBias;
  19103. this.wireframe = source.wireframe;
  19104. this.wireframeLinewidth = source.wireframeLinewidth;
  19105. this.skinning = source.skinning;
  19106. this.morphTargets = source.morphTargets;
  19107. this.morphNormals = source.morphNormals;
  19108. return this;
  19109. };
  19110. /**
  19111. * @author mrdoob / http://mrdoob.com/
  19112. * @author alteredq / http://alteredqualia.com/
  19113. *
  19114. * parameters = {
  19115. * color: <hex>,
  19116. * opacity: <float>,
  19117. *
  19118. * map: new THREE.Texture( <Image> ),
  19119. *
  19120. * lightMap: new THREE.Texture( <Image> ),
  19121. * lightMapIntensity: <float>
  19122. *
  19123. * aoMap: new THREE.Texture( <Image> ),
  19124. * aoMapIntensity: <float>
  19125. *
  19126. * emissive: <hex>,
  19127. * emissiveIntensity: <float>
  19128. * emissiveMap: new THREE.Texture( <Image> ),
  19129. *
  19130. * specularMap: new THREE.Texture( <Image> ),
  19131. *
  19132. * alphaMap: new THREE.Texture( <Image> ),
  19133. *
  19134. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19135. * combine: THREE.Multiply,
  19136. * reflectivity: <float>,
  19137. * refractionRatio: <float>,
  19138. *
  19139. * wireframe: <boolean>,
  19140. * wireframeLinewidth: <float>,
  19141. *
  19142. * skinning: <bool>,
  19143. * morphTargets: <bool>,
  19144. * morphNormals: <bool>
  19145. * }
  19146. */
  19147. function MeshLambertMaterial( parameters ) {
  19148. Material.call( this );
  19149. this.type = 'MeshLambertMaterial';
  19150. this.color = new Color( 0xffffff ); // diffuse
  19151. this.map = null;
  19152. this.lightMap = null;
  19153. this.lightMapIntensity = 1.0;
  19154. this.aoMap = null;
  19155. this.aoMapIntensity = 1.0;
  19156. this.emissive = new Color( 0x000000 );
  19157. this.emissiveIntensity = 1.0;
  19158. this.emissiveMap = null;
  19159. this.specularMap = null;
  19160. this.alphaMap = null;
  19161. this.envMap = null;
  19162. this.combine = MultiplyOperation;
  19163. this.reflectivity = 1;
  19164. this.refractionRatio = 0.98;
  19165. this.wireframe = false;
  19166. this.wireframeLinewidth = 1;
  19167. this.wireframeLinecap = 'round';
  19168. this.wireframeLinejoin = 'round';
  19169. this.skinning = false;
  19170. this.morphTargets = false;
  19171. this.morphNormals = false;
  19172. this.setValues( parameters );
  19173. }
  19174. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19175. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19176. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19177. MeshLambertMaterial.prototype.copy = function ( source ) {
  19178. Material.prototype.copy.call( this, source );
  19179. this.color.copy( source.color );
  19180. this.map = source.map;
  19181. this.lightMap = source.lightMap;
  19182. this.lightMapIntensity = source.lightMapIntensity;
  19183. this.aoMap = source.aoMap;
  19184. this.aoMapIntensity = source.aoMapIntensity;
  19185. this.emissive.copy( source.emissive );
  19186. this.emissiveMap = source.emissiveMap;
  19187. this.emissiveIntensity = source.emissiveIntensity;
  19188. this.specularMap = source.specularMap;
  19189. this.alphaMap = source.alphaMap;
  19190. this.envMap = source.envMap;
  19191. this.combine = source.combine;
  19192. this.reflectivity = source.reflectivity;
  19193. this.refractionRatio = source.refractionRatio;
  19194. this.wireframe = source.wireframe;
  19195. this.wireframeLinewidth = source.wireframeLinewidth;
  19196. this.wireframeLinecap = source.wireframeLinecap;
  19197. this.wireframeLinejoin = source.wireframeLinejoin;
  19198. this.skinning = source.skinning;
  19199. this.morphTargets = source.morphTargets;
  19200. this.morphNormals = source.morphNormals;
  19201. return this;
  19202. };
  19203. /**
  19204. * @author WestLangley / http://github.com/WestLangley
  19205. *
  19206. * parameters = {
  19207. * color: <hex>,
  19208. * opacity: <float>,
  19209. *
  19210. * matcap: new THREE.Texture( <Image> ),
  19211. *
  19212. * map: new THREE.Texture( <Image> ),
  19213. *
  19214. * bumpMap: new THREE.Texture( <Image> ),
  19215. * bumpScale: <float>,
  19216. *
  19217. * normalMap: new THREE.Texture( <Image> ),
  19218. * normalMapType: THREE.TangentSpaceNormalMap,
  19219. * normalScale: <Vector2>,
  19220. *
  19221. * displacementMap: new THREE.Texture( <Image> ),
  19222. * displacementScale: <float>,
  19223. * displacementBias: <float>,
  19224. *
  19225. * alphaMap: new THREE.Texture( <Image> ),
  19226. *
  19227. * skinning: <bool>,
  19228. * morphTargets: <bool>,
  19229. * morphNormals: <bool>
  19230. * }
  19231. */
  19232. function MeshMatcapMaterial( parameters ) {
  19233. Material.call( this );
  19234. this.defines = { 'MATCAP': '' };
  19235. this.type = 'MeshMatcapMaterial';
  19236. this.color = new Color( 0xffffff ); // diffuse
  19237. this.matcap = null;
  19238. this.map = null;
  19239. this.bumpMap = null;
  19240. this.bumpScale = 1;
  19241. this.normalMap = null;
  19242. this.normalMapType = TangentSpaceNormalMap;
  19243. this.normalScale = new Vector2( 1, 1 );
  19244. this.displacementMap = null;
  19245. this.displacementScale = 1;
  19246. this.displacementBias = 0;
  19247. this.alphaMap = null;
  19248. this.skinning = false;
  19249. this.morphTargets = false;
  19250. this.morphNormals = false;
  19251. this.lights = false;
  19252. this.setValues( parameters );
  19253. }
  19254. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19255. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19256. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19257. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19258. Material.prototype.copy.call( this, source );
  19259. this.defines = { 'MATCAP': '' };
  19260. this.color.copy( source.color );
  19261. this.matcap = source.matcap;
  19262. this.map = source.map;
  19263. this.bumpMap = source.bumpMap;
  19264. this.bumpScale = source.bumpScale;
  19265. this.normalMap = source.normalMap;
  19266. this.normalMapType = source.normalMapType;
  19267. this.normalScale.copy( source.normalScale );
  19268. this.displacementMap = source.displacementMap;
  19269. this.displacementScale = source.displacementScale;
  19270. this.displacementBias = source.displacementBias;
  19271. this.alphaMap = source.alphaMap;
  19272. this.skinning = source.skinning;
  19273. this.morphTargets = source.morphTargets;
  19274. this.morphNormals = source.morphNormals;
  19275. return this;
  19276. };
  19277. /**
  19278. * @author alteredq / http://alteredqualia.com/
  19279. *
  19280. * parameters = {
  19281. * color: <hex>,
  19282. * opacity: <float>,
  19283. *
  19284. * linewidth: <float>,
  19285. *
  19286. * scale: <float>,
  19287. * dashSize: <float>,
  19288. * gapSize: <float>
  19289. * }
  19290. */
  19291. function LineDashedMaterial( parameters ) {
  19292. LineBasicMaterial.call( this );
  19293. this.type = 'LineDashedMaterial';
  19294. this.scale = 1;
  19295. this.dashSize = 3;
  19296. this.gapSize = 1;
  19297. this.setValues( parameters );
  19298. }
  19299. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19300. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19301. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19302. LineDashedMaterial.prototype.copy = function ( source ) {
  19303. LineBasicMaterial.prototype.copy.call( this, source );
  19304. this.scale = source.scale;
  19305. this.dashSize = source.dashSize;
  19306. this.gapSize = source.gapSize;
  19307. return this;
  19308. };
  19309. var Materials = /*#__PURE__*/Object.freeze({
  19310. ShadowMaterial: ShadowMaterial,
  19311. SpriteMaterial: SpriteMaterial,
  19312. RawShaderMaterial: RawShaderMaterial,
  19313. ShaderMaterial: ShaderMaterial,
  19314. PointsMaterial: PointsMaterial,
  19315. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19316. MeshStandardMaterial: MeshStandardMaterial,
  19317. MeshPhongMaterial: MeshPhongMaterial,
  19318. MeshToonMaterial: MeshToonMaterial,
  19319. MeshNormalMaterial: MeshNormalMaterial,
  19320. MeshLambertMaterial: MeshLambertMaterial,
  19321. MeshDepthMaterial: MeshDepthMaterial,
  19322. MeshDistanceMaterial: MeshDistanceMaterial,
  19323. MeshBasicMaterial: MeshBasicMaterial,
  19324. MeshMatcapMaterial: MeshMatcapMaterial,
  19325. LineDashedMaterial: LineDashedMaterial,
  19326. LineBasicMaterial: LineBasicMaterial,
  19327. Material: Material
  19328. });
  19329. /**
  19330. * @author tschw
  19331. * @author Ben Houston / http://clara.io/
  19332. * @author David Sarno / http://lighthaus.us/
  19333. */
  19334. var AnimationUtils = {
  19335. // same as Array.prototype.slice, but also works on typed arrays
  19336. arraySlice: function ( array, from, to ) {
  19337. if ( AnimationUtils.isTypedArray( array ) ) {
  19338. // in ios9 array.subarray(from, undefined) will return empty array
  19339. // but array.subarray(from) or array.subarray(from, len) is correct
  19340. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19341. }
  19342. return array.slice( from, to );
  19343. },
  19344. // converts an array to a specific type
  19345. convertArray: function ( array, type, forceClone ) {
  19346. if ( ! array || // let 'undefined' and 'null' pass
  19347. ! forceClone && array.constructor === type ) return array;
  19348. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19349. return new type( array ); // create typed array
  19350. }
  19351. return Array.prototype.slice.call( array ); // create Array
  19352. },
  19353. isTypedArray: function ( object ) {
  19354. return ArrayBuffer.isView( object ) &&
  19355. ! ( object instanceof DataView );
  19356. },
  19357. // returns an array by which times and values can be sorted
  19358. getKeyframeOrder: function ( times ) {
  19359. function compareTime( i, j ) {
  19360. return times[ i ] - times[ j ];
  19361. }
  19362. var n = times.length;
  19363. var result = new Array( n );
  19364. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19365. result.sort( compareTime );
  19366. return result;
  19367. },
  19368. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19369. sortedArray: function ( values, stride, order ) {
  19370. var nValues = values.length;
  19371. var result = new values.constructor( nValues );
  19372. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19373. var srcOffset = order[ i ] * stride;
  19374. for ( var j = 0; j !== stride; ++ j ) {
  19375. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19376. }
  19377. }
  19378. return result;
  19379. },
  19380. // function for parsing AOS keyframe formats
  19381. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19382. var i = 1, key = jsonKeys[ 0 ];
  19383. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19384. key = jsonKeys[ i ++ ];
  19385. }
  19386. if ( key === undefined ) return; // no data
  19387. var value = key[ valuePropertyName ];
  19388. if ( value === undefined ) return; // no data
  19389. if ( Array.isArray( value ) ) {
  19390. do {
  19391. value = key[ valuePropertyName ];
  19392. if ( value !== undefined ) {
  19393. times.push( key.time );
  19394. values.push.apply( values, value ); // push all elements
  19395. }
  19396. key = jsonKeys[ i ++ ];
  19397. } while ( key !== undefined );
  19398. } else if ( value.toArray !== undefined ) {
  19399. // ...assume THREE.Math-ish
  19400. do {
  19401. value = key[ valuePropertyName ];
  19402. if ( value !== undefined ) {
  19403. times.push( key.time );
  19404. value.toArray( values, values.length );
  19405. }
  19406. key = jsonKeys[ i ++ ];
  19407. } while ( key !== undefined );
  19408. } else {
  19409. // otherwise push as-is
  19410. do {
  19411. value = key[ valuePropertyName ];
  19412. if ( value !== undefined ) {
  19413. times.push( key.time );
  19414. values.push( value );
  19415. }
  19416. key = jsonKeys[ i ++ ];
  19417. } while ( key !== undefined );
  19418. }
  19419. }
  19420. };
  19421. /**
  19422. * Abstract base class of interpolants over parametric samples.
  19423. *
  19424. * The parameter domain is one dimensional, typically the time or a path
  19425. * along a curve defined by the data.
  19426. *
  19427. * The sample values can have any dimensionality and derived classes may
  19428. * apply special interpretations to the data.
  19429. *
  19430. * This class provides the interval seek in a Template Method, deferring
  19431. * the actual interpolation to derived classes.
  19432. *
  19433. * Time complexity is O(1) for linear access crossing at most two points
  19434. * and O(log N) for random access, where N is the number of positions.
  19435. *
  19436. * References:
  19437. *
  19438. * http://www.oodesign.com/template-method-pattern.html
  19439. *
  19440. * @author tschw
  19441. */
  19442. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19443. this.parameterPositions = parameterPositions;
  19444. this._cachedIndex = 0;
  19445. this.resultBuffer = resultBuffer !== undefined ?
  19446. resultBuffer : new sampleValues.constructor( sampleSize );
  19447. this.sampleValues = sampleValues;
  19448. this.valueSize = sampleSize;
  19449. }
  19450. Object.assign( Interpolant.prototype, {
  19451. evaluate: function ( t ) {
  19452. var pp = this.parameterPositions,
  19453. i1 = this._cachedIndex,
  19454. t1 = pp[ i1 ],
  19455. t0 = pp[ i1 - 1 ];
  19456. validate_interval: {
  19457. seek: {
  19458. var right;
  19459. linear_scan: {
  19460. //- See http://jsperf.com/comparison-to-undefined/3
  19461. //- slower code:
  19462. //-
  19463. //- if ( t >= t1 || t1 === undefined ) {
  19464. forward_scan: if ( ! ( t < t1 ) ) {
  19465. for ( var giveUpAt = i1 + 2; ; ) {
  19466. if ( t1 === undefined ) {
  19467. if ( t < t0 ) break forward_scan;
  19468. // after end
  19469. i1 = pp.length;
  19470. this._cachedIndex = i1;
  19471. return this.afterEnd_( i1 - 1, t, t0 );
  19472. }
  19473. if ( i1 === giveUpAt ) break; // this loop
  19474. t0 = t1;
  19475. t1 = pp[ ++ i1 ];
  19476. if ( t < t1 ) {
  19477. // we have arrived at the sought interval
  19478. break seek;
  19479. }
  19480. }
  19481. // prepare binary search on the right side of the index
  19482. right = pp.length;
  19483. break linear_scan;
  19484. }
  19485. //- slower code:
  19486. //- if ( t < t0 || t0 === undefined ) {
  19487. if ( ! ( t >= t0 ) ) {
  19488. // looping?
  19489. var t1global = pp[ 1 ];
  19490. if ( t < t1global ) {
  19491. i1 = 2; // + 1, using the scan for the details
  19492. t0 = t1global;
  19493. }
  19494. // linear reverse scan
  19495. for ( var giveUpAt = i1 - 2; ; ) {
  19496. if ( t0 === undefined ) {
  19497. // before start
  19498. this._cachedIndex = 0;
  19499. return this.beforeStart_( 0, t, t1 );
  19500. }
  19501. if ( i1 === giveUpAt ) break; // this loop
  19502. t1 = t0;
  19503. t0 = pp[ -- i1 - 1 ];
  19504. if ( t >= t0 ) {
  19505. // we have arrived at the sought interval
  19506. break seek;
  19507. }
  19508. }
  19509. // prepare binary search on the left side of the index
  19510. right = i1;
  19511. i1 = 0;
  19512. break linear_scan;
  19513. }
  19514. // the interval is valid
  19515. break validate_interval;
  19516. } // linear scan
  19517. // binary search
  19518. while ( i1 < right ) {
  19519. var mid = ( i1 + right ) >>> 1;
  19520. if ( t < pp[ mid ] ) {
  19521. right = mid;
  19522. } else {
  19523. i1 = mid + 1;
  19524. }
  19525. }
  19526. t1 = pp[ i1 ];
  19527. t0 = pp[ i1 - 1 ];
  19528. // check boundary cases, again
  19529. if ( t0 === undefined ) {
  19530. this._cachedIndex = 0;
  19531. return this.beforeStart_( 0, t, t1 );
  19532. }
  19533. if ( t1 === undefined ) {
  19534. i1 = pp.length;
  19535. this._cachedIndex = i1;
  19536. return this.afterEnd_( i1 - 1, t0, t );
  19537. }
  19538. } // seek
  19539. this._cachedIndex = i1;
  19540. this.intervalChanged_( i1, t0, t1 );
  19541. } // validate_interval
  19542. return this.interpolate_( i1, t0, t, t1 );
  19543. },
  19544. settings: null, // optional, subclass-specific settings structure
  19545. // Note: The indirection allows central control of many interpolants.
  19546. // --- Protected interface
  19547. DefaultSettings_: {},
  19548. getSettings_: function () {
  19549. return this.settings || this.DefaultSettings_;
  19550. },
  19551. copySampleValue_: function ( index ) {
  19552. // copies a sample value to the result buffer
  19553. var result = this.resultBuffer,
  19554. values = this.sampleValues,
  19555. stride = this.valueSize,
  19556. offset = index * stride;
  19557. for ( var i = 0; i !== stride; ++ i ) {
  19558. result[ i ] = values[ offset + i ];
  19559. }
  19560. return result;
  19561. },
  19562. // Template methods for derived classes:
  19563. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19564. throw new Error( 'call to abstract method' );
  19565. // implementations shall return this.resultBuffer
  19566. },
  19567. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19568. // empty
  19569. }
  19570. } );
  19571. //!\ DECLARE ALIAS AFTER assign prototype !
  19572. Object.assign( Interpolant.prototype, {
  19573. //( 0, t, t0 ), returns this.resultBuffer
  19574. beforeStart_: Interpolant.prototype.copySampleValue_,
  19575. //( N-1, tN-1, t ), returns this.resultBuffer
  19576. afterEnd_: Interpolant.prototype.copySampleValue_,
  19577. } );
  19578. /**
  19579. * Fast and simple cubic spline interpolant.
  19580. *
  19581. * It was derived from a Hermitian construction setting the first derivative
  19582. * at each sample position to the linear slope between neighboring positions
  19583. * over their parameter interval.
  19584. *
  19585. * @author tschw
  19586. */
  19587. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19588. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19589. this._weightPrev = - 0;
  19590. this._offsetPrev = - 0;
  19591. this._weightNext = - 0;
  19592. this._offsetNext = - 0;
  19593. }
  19594. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19595. constructor: CubicInterpolant,
  19596. DefaultSettings_: {
  19597. endingStart: ZeroCurvatureEnding,
  19598. endingEnd: ZeroCurvatureEnding
  19599. },
  19600. intervalChanged_: function ( i1, t0, t1 ) {
  19601. var pp = this.parameterPositions,
  19602. iPrev = i1 - 2,
  19603. iNext = i1 + 1,
  19604. tPrev = pp[ iPrev ],
  19605. tNext = pp[ iNext ];
  19606. if ( tPrev === undefined ) {
  19607. switch ( this.getSettings_().endingStart ) {
  19608. case ZeroSlopeEnding:
  19609. // f'(t0) = 0
  19610. iPrev = i1;
  19611. tPrev = 2 * t0 - t1;
  19612. break;
  19613. case WrapAroundEnding:
  19614. // use the other end of the curve
  19615. iPrev = pp.length - 2;
  19616. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19617. break;
  19618. default: // ZeroCurvatureEnding
  19619. // f''(t0) = 0 a.k.a. Natural Spline
  19620. iPrev = i1;
  19621. tPrev = t1;
  19622. }
  19623. }
  19624. if ( tNext === undefined ) {
  19625. switch ( this.getSettings_().endingEnd ) {
  19626. case ZeroSlopeEnding:
  19627. // f'(tN) = 0
  19628. iNext = i1;
  19629. tNext = 2 * t1 - t0;
  19630. break;
  19631. case WrapAroundEnding:
  19632. // use the other end of the curve
  19633. iNext = 1;
  19634. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19635. break;
  19636. default: // ZeroCurvatureEnding
  19637. // f''(tN) = 0, a.k.a. Natural Spline
  19638. iNext = i1 - 1;
  19639. tNext = t0;
  19640. }
  19641. }
  19642. var halfDt = ( t1 - t0 ) * 0.5,
  19643. stride = this.valueSize;
  19644. this._weightPrev = halfDt / ( t0 - tPrev );
  19645. this._weightNext = halfDt / ( tNext - t1 );
  19646. this._offsetPrev = iPrev * stride;
  19647. this._offsetNext = iNext * stride;
  19648. },
  19649. interpolate_: function ( i1, t0, t, t1 ) {
  19650. var result = this.resultBuffer,
  19651. values = this.sampleValues,
  19652. stride = this.valueSize,
  19653. o1 = i1 * stride, o0 = o1 - stride,
  19654. oP = this._offsetPrev, oN = this._offsetNext,
  19655. wP = this._weightPrev, wN = this._weightNext,
  19656. p = ( t - t0 ) / ( t1 - t0 ),
  19657. pp = p * p,
  19658. ppp = pp * p;
  19659. // evaluate polynomials
  19660. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  19661. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19662. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19663. var sN = wN * ppp - wN * pp;
  19664. // combine data linearly
  19665. for ( var i = 0; i !== stride; ++ i ) {
  19666. result[ i ] =
  19667. sP * values[ oP + i ] +
  19668. s0 * values[ o0 + i ] +
  19669. s1 * values[ o1 + i ] +
  19670. sN * values[ oN + i ];
  19671. }
  19672. return result;
  19673. }
  19674. } );
  19675. /**
  19676. * @author tschw
  19677. */
  19678. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19679. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19680. }
  19681. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19682. constructor: LinearInterpolant,
  19683. interpolate_: function ( i1, t0, t, t1 ) {
  19684. var result = this.resultBuffer,
  19685. values = this.sampleValues,
  19686. stride = this.valueSize,
  19687. offset1 = i1 * stride,
  19688. offset0 = offset1 - stride,
  19689. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19690. weight0 = 1 - weight1;
  19691. for ( var i = 0; i !== stride; ++ i ) {
  19692. result[ i ] =
  19693. values[ offset0 + i ] * weight0 +
  19694. values[ offset1 + i ] * weight1;
  19695. }
  19696. return result;
  19697. }
  19698. } );
  19699. /**
  19700. *
  19701. * Interpolant that evaluates to the sample value at the position preceeding
  19702. * the parameter.
  19703. *
  19704. * @author tschw
  19705. */
  19706. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19707. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19708. }
  19709. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19710. constructor: DiscreteInterpolant,
  19711. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19712. return this.copySampleValue_( i1 - 1 );
  19713. }
  19714. } );
  19715. /**
  19716. *
  19717. * A timed sequence of keyframes for a specific property.
  19718. *
  19719. *
  19720. * @author Ben Houston / http://clara.io/
  19721. * @author David Sarno / http://lighthaus.us/
  19722. * @author tschw
  19723. */
  19724. function KeyframeTrack( name, times, values, interpolation ) {
  19725. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19726. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19727. this.name = name;
  19728. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19729. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19730. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19731. }
  19732. // Static methods
  19733. Object.assign( KeyframeTrack, {
  19734. // Serialization (in static context, because of constructor invocation
  19735. // and automatic invocation of .toJSON):
  19736. toJSON: function ( track ) {
  19737. var trackType = track.constructor;
  19738. var json;
  19739. // derived classes can define a static toJSON method
  19740. if ( trackType.toJSON !== undefined ) {
  19741. json = trackType.toJSON( track );
  19742. } else {
  19743. // by default, we assume the data can be serialized as-is
  19744. json = {
  19745. 'name': track.name,
  19746. 'times': AnimationUtils.convertArray( track.times, Array ),
  19747. 'values': AnimationUtils.convertArray( track.values, Array )
  19748. };
  19749. var interpolation = track.getInterpolation();
  19750. if ( interpolation !== track.DefaultInterpolation ) {
  19751. json.interpolation = interpolation;
  19752. }
  19753. }
  19754. json.type = track.ValueTypeName; // mandatory
  19755. return json;
  19756. }
  19757. } );
  19758. Object.assign( KeyframeTrack.prototype, {
  19759. constructor: KeyframeTrack,
  19760. TimeBufferType: Float32Array,
  19761. ValueBufferType: Float32Array,
  19762. DefaultInterpolation: InterpolateLinear,
  19763. InterpolantFactoryMethodDiscrete: function ( result ) {
  19764. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19765. },
  19766. InterpolantFactoryMethodLinear: function ( result ) {
  19767. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19768. },
  19769. InterpolantFactoryMethodSmooth: function ( result ) {
  19770. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19771. },
  19772. setInterpolation: function ( interpolation ) {
  19773. var factoryMethod;
  19774. switch ( interpolation ) {
  19775. case InterpolateDiscrete:
  19776. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19777. break;
  19778. case InterpolateLinear:
  19779. factoryMethod = this.InterpolantFactoryMethodLinear;
  19780. break;
  19781. case InterpolateSmooth:
  19782. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19783. break;
  19784. }
  19785. if ( factoryMethod === undefined ) {
  19786. var message = "unsupported interpolation for " +
  19787. this.ValueTypeName + " keyframe track named " + this.name;
  19788. if ( this.createInterpolant === undefined ) {
  19789. // fall back to default, unless the default itself is messed up
  19790. if ( interpolation !== this.DefaultInterpolation ) {
  19791. this.setInterpolation( this.DefaultInterpolation );
  19792. } else {
  19793. throw new Error( message ); // fatal, in this case
  19794. }
  19795. }
  19796. console.warn( 'THREE.KeyframeTrack:', message );
  19797. return this;
  19798. }
  19799. this.createInterpolant = factoryMethod;
  19800. return this;
  19801. },
  19802. getInterpolation: function () {
  19803. switch ( this.createInterpolant ) {
  19804. case this.InterpolantFactoryMethodDiscrete:
  19805. return InterpolateDiscrete;
  19806. case this.InterpolantFactoryMethodLinear:
  19807. return InterpolateLinear;
  19808. case this.InterpolantFactoryMethodSmooth:
  19809. return InterpolateSmooth;
  19810. }
  19811. },
  19812. getValueSize: function () {
  19813. return this.values.length / this.times.length;
  19814. },
  19815. // move all keyframes either forwards or backwards in time
  19816. shift: function ( timeOffset ) {
  19817. if ( timeOffset !== 0.0 ) {
  19818. var times = this.times;
  19819. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19820. times[ i ] += timeOffset;
  19821. }
  19822. }
  19823. return this;
  19824. },
  19825. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19826. scale: function ( timeScale ) {
  19827. if ( timeScale !== 1.0 ) {
  19828. var times = this.times;
  19829. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19830. times[ i ] *= timeScale;
  19831. }
  19832. }
  19833. return this;
  19834. },
  19835. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19836. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19837. trim: function ( startTime, endTime ) {
  19838. var times = this.times,
  19839. nKeys = times.length,
  19840. from = 0,
  19841. to = nKeys - 1;
  19842. while ( from !== nKeys && times[ from ] < startTime ) {
  19843. ++ from;
  19844. }
  19845. while ( to !== - 1 && times[ to ] > endTime ) {
  19846. -- to;
  19847. }
  19848. ++ to; // inclusive -> exclusive bound
  19849. if ( from !== 0 || to !== nKeys ) {
  19850. // empty tracks are forbidden, so keep at least one keyframe
  19851. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  19852. var stride = this.getValueSize();
  19853. this.times = AnimationUtils.arraySlice( times, from, to );
  19854. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19855. }
  19856. return this;
  19857. },
  19858. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19859. validate: function () {
  19860. var valid = true;
  19861. var valueSize = this.getValueSize();
  19862. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19863. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19864. valid = false;
  19865. }
  19866. var times = this.times,
  19867. values = this.values,
  19868. nKeys = times.length;
  19869. if ( nKeys === 0 ) {
  19870. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19871. valid = false;
  19872. }
  19873. var prevTime = null;
  19874. for ( var i = 0; i !== nKeys; i ++ ) {
  19875. var currTime = times[ i ];
  19876. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19877. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19878. valid = false;
  19879. break;
  19880. }
  19881. if ( prevTime !== null && prevTime > currTime ) {
  19882. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  19883. valid = false;
  19884. break;
  19885. }
  19886. prevTime = currTime;
  19887. }
  19888. if ( values !== undefined ) {
  19889. if ( AnimationUtils.isTypedArray( values ) ) {
  19890. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  19891. var value = values[ i ];
  19892. if ( isNaN( value ) ) {
  19893. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  19894. valid = false;
  19895. break;
  19896. }
  19897. }
  19898. }
  19899. }
  19900. return valid;
  19901. },
  19902. // removes equivalent sequential keys as common in morph target sequences
  19903. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  19904. optimize: function () {
  19905. var times = this.times,
  19906. values = this.values,
  19907. stride = this.getValueSize(),
  19908. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  19909. writeIndex = 1,
  19910. lastIndex = times.length - 1;
  19911. for ( var i = 1; i < lastIndex; ++ i ) {
  19912. var keep = false;
  19913. var time = times[ i ];
  19914. var timeNext = times[ i + 1 ];
  19915. // remove adjacent keyframes scheduled at the same time
  19916. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  19917. if ( ! smoothInterpolation ) {
  19918. // remove unnecessary keyframes same as their neighbors
  19919. var offset = i * stride,
  19920. offsetP = offset - stride,
  19921. offsetN = offset + stride;
  19922. for ( var j = 0; j !== stride; ++ j ) {
  19923. var value = values[ offset + j ];
  19924. if ( value !== values[ offsetP + j ] ||
  19925. value !== values[ offsetN + j ] ) {
  19926. keep = true;
  19927. break;
  19928. }
  19929. }
  19930. } else {
  19931. keep = true;
  19932. }
  19933. }
  19934. // in-place compaction
  19935. if ( keep ) {
  19936. if ( i !== writeIndex ) {
  19937. times[ writeIndex ] = times[ i ];
  19938. var readOffset = i * stride,
  19939. writeOffset = writeIndex * stride;
  19940. for ( var j = 0; j !== stride; ++ j ) {
  19941. values[ writeOffset + j ] = values[ readOffset + j ];
  19942. }
  19943. }
  19944. ++ writeIndex;
  19945. }
  19946. }
  19947. // flush last keyframe (compaction looks ahead)
  19948. if ( lastIndex > 0 ) {
  19949. times[ writeIndex ] = times[ lastIndex ];
  19950. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  19951. values[ writeOffset + j ] = values[ readOffset + j ];
  19952. }
  19953. ++ writeIndex;
  19954. }
  19955. if ( writeIndex !== times.length ) {
  19956. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  19957. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  19958. }
  19959. return this;
  19960. },
  19961. clone: function () {
  19962. var times = AnimationUtils.arraySlice( this.times, 0 );
  19963. var values = AnimationUtils.arraySlice( this.values, 0 );
  19964. var TypedKeyframeTrack = this.constructor;
  19965. var track = new TypedKeyframeTrack( this.name, times, values );
  19966. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  19967. track.createInterpolant = this.createInterpolant;
  19968. return track;
  19969. }
  19970. } );
  19971. /**
  19972. *
  19973. * A Track of Boolean keyframe values.
  19974. *
  19975. *
  19976. * @author Ben Houston / http://clara.io/
  19977. * @author David Sarno / http://lighthaus.us/
  19978. * @author tschw
  19979. */
  19980. function BooleanKeyframeTrack( name, times, values ) {
  19981. KeyframeTrack.call( this, name, times, values );
  19982. }
  19983. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19984. constructor: BooleanKeyframeTrack,
  19985. ValueTypeName: 'bool',
  19986. ValueBufferType: Array,
  19987. DefaultInterpolation: InterpolateDiscrete,
  19988. InterpolantFactoryMethodLinear: undefined,
  19989. InterpolantFactoryMethodSmooth: undefined
  19990. // Note: Actually this track could have a optimized / compressed
  19991. // representation of a single value and a custom interpolant that
  19992. // computes "firstValue ^ isOdd( index )".
  19993. } );
  19994. /**
  19995. *
  19996. * A Track of keyframe values that represent color.
  19997. *
  19998. *
  19999. * @author Ben Houston / http://clara.io/
  20000. * @author David Sarno / http://lighthaus.us/
  20001. * @author tschw
  20002. */
  20003. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20004. KeyframeTrack.call( this, name, times, values, interpolation );
  20005. }
  20006. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20007. constructor: ColorKeyframeTrack,
  20008. ValueTypeName: 'color'
  20009. // ValueBufferType is inherited
  20010. // DefaultInterpolation is inherited
  20011. // Note: Very basic implementation and nothing special yet.
  20012. // However, this is the place for color space parameterization.
  20013. } );
  20014. /**
  20015. *
  20016. * A Track of numeric keyframe values.
  20017. *
  20018. * @author Ben Houston / http://clara.io/
  20019. * @author David Sarno / http://lighthaus.us/
  20020. * @author tschw
  20021. */
  20022. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20023. KeyframeTrack.call( this, name, times, values, interpolation );
  20024. }
  20025. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20026. constructor: NumberKeyframeTrack,
  20027. ValueTypeName: 'number'
  20028. // ValueBufferType is inherited
  20029. // DefaultInterpolation is inherited
  20030. } );
  20031. /**
  20032. * Spherical linear unit quaternion interpolant.
  20033. *
  20034. * @author tschw
  20035. */
  20036. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20037. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20038. }
  20039. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20040. constructor: QuaternionLinearInterpolant,
  20041. interpolate_: function ( i1, t0, t, t1 ) {
  20042. var result = this.resultBuffer,
  20043. values = this.sampleValues,
  20044. stride = this.valueSize,
  20045. offset = i1 * stride,
  20046. alpha = ( t - t0 ) / ( t1 - t0 );
  20047. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20048. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20049. }
  20050. return result;
  20051. }
  20052. } );
  20053. /**
  20054. *
  20055. * A Track of quaternion keyframe values.
  20056. *
  20057. * @author Ben Houston / http://clara.io/
  20058. * @author David Sarno / http://lighthaus.us/
  20059. * @author tschw
  20060. */
  20061. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20062. KeyframeTrack.call( this, name, times, values, interpolation );
  20063. }
  20064. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20065. constructor: QuaternionKeyframeTrack,
  20066. ValueTypeName: 'quaternion',
  20067. // ValueBufferType is inherited
  20068. DefaultInterpolation: InterpolateLinear,
  20069. InterpolantFactoryMethodLinear: function ( result ) {
  20070. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20071. },
  20072. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20073. } );
  20074. /**
  20075. *
  20076. * A Track that interpolates Strings
  20077. *
  20078. *
  20079. * @author Ben Houston / http://clara.io/
  20080. * @author David Sarno / http://lighthaus.us/
  20081. * @author tschw
  20082. */
  20083. function StringKeyframeTrack( name, times, values, interpolation ) {
  20084. KeyframeTrack.call( this, name, times, values, interpolation );
  20085. }
  20086. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20087. constructor: StringKeyframeTrack,
  20088. ValueTypeName: 'string',
  20089. ValueBufferType: Array,
  20090. DefaultInterpolation: InterpolateDiscrete,
  20091. InterpolantFactoryMethodLinear: undefined,
  20092. InterpolantFactoryMethodSmooth: undefined
  20093. } );
  20094. /**
  20095. *
  20096. * A Track of vectored keyframe values.
  20097. *
  20098. *
  20099. * @author Ben Houston / http://clara.io/
  20100. * @author David Sarno / http://lighthaus.us/
  20101. * @author tschw
  20102. */
  20103. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20104. KeyframeTrack.call( this, name, times, values, interpolation );
  20105. }
  20106. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20107. constructor: VectorKeyframeTrack,
  20108. ValueTypeName: 'vector'
  20109. // ValueBufferType is inherited
  20110. // DefaultInterpolation is inherited
  20111. } );
  20112. /**
  20113. *
  20114. * Reusable set of Tracks that represent an animation.
  20115. *
  20116. * @author Ben Houston / http://clara.io/
  20117. * @author David Sarno / http://lighthaus.us/
  20118. */
  20119. function AnimationClip( name, duration, tracks ) {
  20120. this.name = name;
  20121. this.tracks = tracks;
  20122. this.duration = ( duration !== undefined ) ? duration : - 1;
  20123. this.uuid = _Math.generateUUID();
  20124. // this means it should figure out its duration by scanning the tracks
  20125. if ( this.duration < 0 ) {
  20126. this.resetDuration();
  20127. }
  20128. }
  20129. function getTrackTypeForValueTypeName( typeName ) {
  20130. switch ( typeName.toLowerCase() ) {
  20131. case 'scalar':
  20132. case 'double':
  20133. case 'float':
  20134. case 'number':
  20135. case 'integer':
  20136. return NumberKeyframeTrack;
  20137. case 'vector':
  20138. case 'vector2':
  20139. case 'vector3':
  20140. case 'vector4':
  20141. return VectorKeyframeTrack;
  20142. case 'color':
  20143. return ColorKeyframeTrack;
  20144. case 'quaternion':
  20145. return QuaternionKeyframeTrack;
  20146. case 'bool':
  20147. case 'boolean':
  20148. return BooleanKeyframeTrack;
  20149. case 'string':
  20150. return StringKeyframeTrack;
  20151. }
  20152. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20153. }
  20154. function parseKeyframeTrack( json ) {
  20155. if ( json.type === undefined ) {
  20156. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20157. }
  20158. var trackType = getTrackTypeForValueTypeName( json.type );
  20159. if ( json.times === undefined ) {
  20160. var times = [], values = [];
  20161. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20162. json.times = times;
  20163. json.values = values;
  20164. }
  20165. // derived classes can define a static parse method
  20166. if ( trackType.parse !== undefined ) {
  20167. return trackType.parse( json );
  20168. } else {
  20169. // by default, we assume a constructor compatible with the base
  20170. return new trackType( json.name, json.times, json.values, json.interpolation );
  20171. }
  20172. }
  20173. Object.assign( AnimationClip, {
  20174. parse: function ( json ) {
  20175. var tracks = [],
  20176. jsonTracks = json.tracks,
  20177. frameTime = 1.0 / ( json.fps || 1.0 );
  20178. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20179. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20180. }
  20181. return new AnimationClip( json.name, json.duration, tracks );
  20182. },
  20183. toJSON: function ( clip ) {
  20184. var tracks = [],
  20185. clipTracks = clip.tracks;
  20186. var json = {
  20187. 'name': clip.name,
  20188. 'duration': clip.duration,
  20189. 'tracks': tracks,
  20190. 'uuid': clip.uuid
  20191. };
  20192. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20193. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20194. }
  20195. return json;
  20196. },
  20197. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20198. var numMorphTargets = morphTargetSequence.length;
  20199. var tracks = [];
  20200. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20201. var times = [];
  20202. var values = [];
  20203. times.push(
  20204. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20205. i,
  20206. ( i + 1 ) % numMorphTargets );
  20207. values.push( 0, 1, 0 );
  20208. var order = AnimationUtils.getKeyframeOrder( times );
  20209. times = AnimationUtils.sortedArray( times, 1, order );
  20210. values = AnimationUtils.sortedArray( values, 1, order );
  20211. // if there is a key at the first frame, duplicate it as the
  20212. // last frame as well for perfect loop.
  20213. if ( ! noLoop && times[ 0 ] === 0 ) {
  20214. times.push( numMorphTargets );
  20215. values.push( values[ 0 ] );
  20216. }
  20217. tracks.push(
  20218. new NumberKeyframeTrack(
  20219. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20220. times, values
  20221. ).scale( 1.0 / fps ) );
  20222. }
  20223. return new AnimationClip( name, - 1, tracks );
  20224. },
  20225. findByName: function ( objectOrClipArray, name ) {
  20226. var clipArray = objectOrClipArray;
  20227. if ( ! Array.isArray( objectOrClipArray ) ) {
  20228. var o = objectOrClipArray;
  20229. clipArray = o.geometry && o.geometry.animations || o.animations;
  20230. }
  20231. for ( var i = 0; i < clipArray.length; i ++ ) {
  20232. if ( clipArray[ i ].name === name ) {
  20233. return clipArray[ i ];
  20234. }
  20235. }
  20236. return null;
  20237. },
  20238. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20239. var animationToMorphTargets = {};
  20240. // tested with https://regex101.com/ on trick sequences
  20241. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20242. var pattern = /^([\w-]*?)([\d]+)$/;
  20243. // sort morph target names into animation groups based
  20244. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20245. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20246. var morphTarget = morphTargets[ i ];
  20247. var parts = morphTarget.name.match( pattern );
  20248. if ( parts && parts.length > 1 ) {
  20249. var name = parts[ 1 ];
  20250. var animationMorphTargets = animationToMorphTargets[ name ];
  20251. if ( ! animationMorphTargets ) {
  20252. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20253. }
  20254. animationMorphTargets.push( morphTarget );
  20255. }
  20256. }
  20257. var clips = [];
  20258. for ( var name in animationToMorphTargets ) {
  20259. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20260. }
  20261. return clips;
  20262. },
  20263. // parse the animation.hierarchy format
  20264. parseAnimation: function ( animation, bones ) {
  20265. if ( ! animation ) {
  20266. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20267. return null;
  20268. }
  20269. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20270. // only return track if there are actually keys.
  20271. if ( animationKeys.length !== 0 ) {
  20272. var times = [];
  20273. var values = [];
  20274. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20275. // empty keys are filtered out, so check again
  20276. if ( times.length !== 0 ) {
  20277. destTracks.push( new trackType( trackName, times, values ) );
  20278. }
  20279. }
  20280. };
  20281. var tracks = [];
  20282. var clipName = animation.name || 'default';
  20283. // automatic length determination in AnimationClip.
  20284. var duration = animation.length || - 1;
  20285. var fps = animation.fps || 30;
  20286. var hierarchyTracks = animation.hierarchy || [];
  20287. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20288. var animationKeys = hierarchyTracks[ h ].keys;
  20289. // skip empty tracks
  20290. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20291. // process morph targets
  20292. if ( animationKeys[ 0 ].morphTargets ) {
  20293. // figure out all morph targets used in this track
  20294. var morphTargetNames = {};
  20295. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20296. if ( animationKeys[ k ].morphTargets ) {
  20297. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20298. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20299. }
  20300. }
  20301. }
  20302. // create a track for each morph target with all zero
  20303. // morphTargetInfluences except for the keys in which
  20304. // the morphTarget is named.
  20305. for ( var morphTargetName in morphTargetNames ) {
  20306. var times = [];
  20307. var values = [];
  20308. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20309. var animationKey = animationKeys[ k ];
  20310. times.push( animationKey.time );
  20311. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20312. }
  20313. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20314. }
  20315. duration = morphTargetNames.length * ( fps || 1.0 );
  20316. } else {
  20317. // ...assume skeletal animation
  20318. var boneName = '.bones[' + bones[ h ].name + ']';
  20319. addNonemptyTrack(
  20320. VectorKeyframeTrack, boneName + '.position',
  20321. animationKeys, 'pos', tracks );
  20322. addNonemptyTrack(
  20323. QuaternionKeyframeTrack, boneName + '.quaternion',
  20324. animationKeys, 'rot', tracks );
  20325. addNonemptyTrack(
  20326. VectorKeyframeTrack, boneName + '.scale',
  20327. animationKeys, 'scl', tracks );
  20328. }
  20329. }
  20330. if ( tracks.length === 0 ) {
  20331. return null;
  20332. }
  20333. var clip = new AnimationClip( clipName, duration, tracks );
  20334. return clip;
  20335. }
  20336. } );
  20337. Object.assign( AnimationClip.prototype, {
  20338. resetDuration: function () {
  20339. var tracks = this.tracks, duration = 0;
  20340. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20341. var track = this.tracks[ i ];
  20342. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20343. }
  20344. this.duration = duration;
  20345. return this;
  20346. },
  20347. trim: function () {
  20348. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20349. this.tracks[ i ].trim( 0, this.duration );
  20350. }
  20351. return this;
  20352. },
  20353. validate: function () {
  20354. var valid = true;
  20355. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20356. valid = valid && this.tracks[ i ].validate();
  20357. }
  20358. return valid;
  20359. },
  20360. optimize: function () {
  20361. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20362. this.tracks[ i ].optimize();
  20363. }
  20364. return this;
  20365. },
  20366. clone: function () {
  20367. var tracks = [];
  20368. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20369. tracks.push( this.tracks[ i ].clone() );
  20370. }
  20371. return new AnimationClip( this.name, this.duration, tracks );
  20372. }
  20373. } );
  20374. /**
  20375. * @author mrdoob / http://mrdoob.com/
  20376. */
  20377. var Cache = {
  20378. enabled: false,
  20379. files: {},
  20380. add: function ( key, file ) {
  20381. if ( this.enabled === false ) return;
  20382. // console.log( 'THREE.Cache', 'Adding key:', key );
  20383. this.files[ key ] = file;
  20384. },
  20385. get: function ( key ) {
  20386. if ( this.enabled === false ) return;
  20387. // console.log( 'THREE.Cache', 'Checking key:', key );
  20388. return this.files[ key ];
  20389. },
  20390. remove: function ( key ) {
  20391. delete this.files[ key ];
  20392. },
  20393. clear: function () {
  20394. this.files = {};
  20395. }
  20396. };
  20397. /**
  20398. * @author mrdoob / http://mrdoob.com/
  20399. */
  20400. function LoadingManager( onLoad, onProgress, onError ) {
  20401. var scope = this;
  20402. var isLoading = false;
  20403. var itemsLoaded = 0;
  20404. var itemsTotal = 0;
  20405. var urlModifier = undefined;
  20406. // Refer to #5689 for the reason why we don't set .onStart
  20407. // in the constructor
  20408. this.onStart = undefined;
  20409. this.onLoad = onLoad;
  20410. this.onProgress = onProgress;
  20411. this.onError = onError;
  20412. this.itemStart = function ( url ) {
  20413. itemsTotal ++;
  20414. if ( isLoading === false ) {
  20415. if ( scope.onStart !== undefined ) {
  20416. scope.onStart( url, itemsLoaded, itemsTotal );
  20417. }
  20418. }
  20419. isLoading = true;
  20420. };
  20421. this.itemEnd = function ( url ) {
  20422. itemsLoaded ++;
  20423. if ( scope.onProgress !== undefined ) {
  20424. scope.onProgress( url, itemsLoaded, itemsTotal );
  20425. }
  20426. if ( itemsLoaded === itemsTotal ) {
  20427. isLoading = false;
  20428. if ( scope.onLoad !== undefined ) {
  20429. scope.onLoad();
  20430. }
  20431. }
  20432. };
  20433. this.itemError = function ( url ) {
  20434. if ( scope.onError !== undefined ) {
  20435. scope.onError( url );
  20436. }
  20437. };
  20438. this.resolveURL = function ( url ) {
  20439. if ( urlModifier ) {
  20440. return urlModifier( url );
  20441. }
  20442. return url;
  20443. };
  20444. this.setURLModifier = function ( transform ) {
  20445. urlModifier = transform;
  20446. return this;
  20447. };
  20448. }
  20449. var DefaultLoadingManager = new LoadingManager();
  20450. /**
  20451. * @author mrdoob / http://mrdoob.com/
  20452. */
  20453. var loading = {};
  20454. function FileLoader( manager ) {
  20455. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20456. }
  20457. Object.assign( FileLoader.prototype, {
  20458. load: function ( url, onLoad, onProgress, onError ) {
  20459. if ( url === undefined ) url = '';
  20460. if ( this.path !== undefined ) url = this.path + url;
  20461. url = this.manager.resolveURL( url );
  20462. var scope = this;
  20463. var cached = Cache.get( url );
  20464. if ( cached !== undefined ) {
  20465. scope.manager.itemStart( url );
  20466. setTimeout( function () {
  20467. if ( onLoad ) onLoad( cached );
  20468. scope.manager.itemEnd( url );
  20469. }, 0 );
  20470. return cached;
  20471. }
  20472. // Check if request is duplicate
  20473. if ( loading[ url ] !== undefined ) {
  20474. loading[ url ].push( {
  20475. onLoad: onLoad,
  20476. onProgress: onProgress,
  20477. onError: onError
  20478. } );
  20479. return;
  20480. }
  20481. // Check for data: URI
  20482. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20483. var dataUriRegexResult = url.match( dataUriRegex );
  20484. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20485. if ( dataUriRegexResult ) {
  20486. var mimeType = dataUriRegexResult[ 1 ];
  20487. var isBase64 = !! dataUriRegexResult[ 2 ];
  20488. var data = dataUriRegexResult[ 3 ];
  20489. data = decodeURIComponent( data );
  20490. if ( isBase64 ) data = atob( data );
  20491. try {
  20492. var response;
  20493. var responseType = ( this.responseType || '' ).toLowerCase();
  20494. switch ( responseType ) {
  20495. case 'arraybuffer':
  20496. case 'blob':
  20497. var view = new Uint8Array( data.length );
  20498. for ( var i = 0; i < data.length; i ++ ) {
  20499. view[ i ] = data.charCodeAt( i );
  20500. }
  20501. if ( responseType === 'blob' ) {
  20502. response = new Blob( [ view.buffer ], { type: mimeType } );
  20503. } else {
  20504. response = view.buffer;
  20505. }
  20506. break;
  20507. case 'document':
  20508. var parser = new DOMParser();
  20509. response = parser.parseFromString( data, mimeType );
  20510. break;
  20511. case 'json':
  20512. response = JSON.parse( data );
  20513. break;
  20514. default: // 'text' or other
  20515. response = data;
  20516. break;
  20517. }
  20518. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20519. setTimeout( function () {
  20520. if ( onLoad ) onLoad( response );
  20521. scope.manager.itemEnd( url );
  20522. }, 0 );
  20523. } catch ( error ) {
  20524. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20525. setTimeout( function () {
  20526. if ( onError ) onError( error );
  20527. scope.manager.itemError( url );
  20528. scope.manager.itemEnd( url );
  20529. }, 0 );
  20530. }
  20531. } else {
  20532. // Initialise array for duplicate requests
  20533. loading[ url ] = [];
  20534. loading[ url ].push( {
  20535. onLoad: onLoad,
  20536. onProgress: onProgress,
  20537. onError: onError
  20538. } );
  20539. var request = new XMLHttpRequest();
  20540. request.open( 'GET', url, true );
  20541. request.addEventListener( 'load', function ( event ) {
  20542. var response = this.response;
  20543. Cache.add( url, response );
  20544. var callbacks = loading[ url ];
  20545. delete loading[ url ];
  20546. if ( this.status === 200 || this.status === 0 ) {
  20547. // Some browsers return HTTP Status 0 when using non-http protocol
  20548. // e.g. 'file://' or 'data://'. Handle as success.
  20549. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20550. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20551. var callback = callbacks[ i ];
  20552. if ( callback.onLoad ) callback.onLoad( response );
  20553. }
  20554. scope.manager.itemEnd( url );
  20555. } else {
  20556. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20557. var callback = callbacks[ i ];
  20558. if ( callback.onError ) callback.onError( event );
  20559. }
  20560. scope.manager.itemError( url );
  20561. scope.manager.itemEnd( url );
  20562. }
  20563. }, false );
  20564. request.addEventListener( 'progress', function ( event ) {
  20565. var callbacks = loading[ url ];
  20566. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20567. var callback = callbacks[ i ];
  20568. if ( callback.onProgress ) callback.onProgress( event );
  20569. }
  20570. }, false );
  20571. request.addEventListener( 'error', function ( event ) {
  20572. var callbacks = loading[ url ];
  20573. delete loading[ url ];
  20574. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20575. var callback = callbacks[ i ];
  20576. if ( callback.onError ) callback.onError( event );
  20577. }
  20578. scope.manager.itemError( url );
  20579. scope.manager.itemEnd( url );
  20580. }, false );
  20581. request.addEventListener( 'abort', function ( event ) {
  20582. var callbacks = loading[ url ];
  20583. delete loading[ url ];
  20584. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20585. var callback = callbacks[ i ];
  20586. if ( callback.onError ) callback.onError( event );
  20587. }
  20588. scope.manager.itemError( url );
  20589. scope.manager.itemEnd( url );
  20590. }, false );
  20591. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20592. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20593. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20594. for ( var header in this.requestHeader ) {
  20595. request.setRequestHeader( header, this.requestHeader[ header ] );
  20596. }
  20597. request.send( null );
  20598. }
  20599. scope.manager.itemStart( url );
  20600. return request;
  20601. },
  20602. setPath: function ( value ) {
  20603. this.path = value;
  20604. return this;
  20605. },
  20606. setResponseType: function ( value ) {
  20607. this.responseType = value;
  20608. return this;
  20609. },
  20610. setWithCredentials: function ( value ) {
  20611. this.withCredentials = value;
  20612. return this;
  20613. },
  20614. setMimeType: function ( value ) {
  20615. this.mimeType = value;
  20616. return this;
  20617. },
  20618. setRequestHeader: function ( value ) {
  20619. this.requestHeader = value;
  20620. return this;
  20621. }
  20622. } );
  20623. /**
  20624. * @author bhouston / http://clara.io/
  20625. */
  20626. function AnimationLoader( manager ) {
  20627. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20628. }
  20629. Object.assign( AnimationLoader.prototype, {
  20630. load: function ( url, onLoad, onProgress, onError ) {
  20631. var scope = this;
  20632. var loader = new FileLoader( scope.manager );
  20633. loader.setPath( scope.path );
  20634. loader.load( url, function ( text ) {
  20635. onLoad( scope.parse( JSON.parse( text ) ) );
  20636. }, onProgress, onError );
  20637. },
  20638. parse: function ( json, onLoad ) {
  20639. var animations = [];
  20640. for ( var i = 0; i < json.length; i ++ ) {
  20641. var clip = AnimationClip.parse( json[ i ] );
  20642. animations.push( clip );
  20643. }
  20644. onLoad( animations );
  20645. },
  20646. setPath: function ( value ) {
  20647. this.path = value;
  20648. return this;
  20649. }
  20650. } );
  20651. /**
  20652. * @author mrdoob / http://mrdoob.com/
  20653. *
  20654. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20655. */
  20656. function CompressedTextureLoader( manager ) {
  20657. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20658. // override in sub classes
  20659. this._parser = null;
  20660. }
  20661. Object.assign( CompressedTextureLoader.prototype, {
  20662. load: function ( url, onLoad, onProgress, onError ) {
  20663. var scope = this;
  20664. var images = [];
  20665. var texture = new CompressedTexture();
  20666. texture.image = images;
  20667. var loader = new FileLoader( this.manager );
  20668. loader.setPath( this.path );
  20669. loader.setResponseType( 'arraybuffer' );
  20670. function loadTexture( i ) {
  20671. loader.load( url[ i ], function ( buffer ) {
  20672. var texDatas = scope._parser( buffer, true );
  20673. images[ i ] = {
  20674. width: texDatas.width,
  20675. height: texDatas.height,
  20676. format: texDatas.format,
  20677. mipmaps: texDatas.mipmaps
  20678. };
  20679. loaded += 1;
  20680. if ( loaded === 6 ) {
  20681. if ( texDatas.mipmapCount === 1 )
  20682. texture.minFilter = LinearFilter;
  20683. texture.format = texDatas.format;
  20684. texture.needsUpdate = true;
  20685. if ( onLoad ) onLoad( texture );
  20686. }
  20687. }, onProgress, onError );
  20688. }
  20689. if ( Array.isArray( url ) ) {
  20690. var loaded = 0;
  20691. for ( var i = 0, il = url.length; i < il; ++ i ) {
  20692. loadTexture( i );
  20693. }
  20694. } else {
  20695. // compressed cubemap texture stored in a single DDS file
  20696. loader.load( url, function ( buffer ) {
  20697. var texDatas = scope._parser( buffer, true );
  20698. if ( texDatas.isCubemap ) {
  20699. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20700. for ( var f = 0; f < faces; f ++ ) {
  20701. images[ f ] = { mipmaps: [] };
  20702. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  20703. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20704. images[ f ].format = texDatas.format;
  20705. images[ f ].width = texDatas.width;
  20706. images[ f ].height = texDatas.height;
  20707. }
  20708. }
  20709. } else {
  20710. texture.image.width = texDatas.width;
  20711. texture.image.height = texDatas.height;
  20712. texture.mipmaps = texDatas.mipmaps;
  20713. }
  20714. if ( texDatas.mipmapCount === 1 ) {
  20715. texture.minFilter = LinearFilter;
  20716. }
  20717. texture.format = texDatas.format;
  20718. texture.needsUpdate = true;
  20719. if ( onLoad ) onLoad( texture );
  20720. }, onProgress, onError );
  20721. }
  20722. return texture;
  20723. },
  20724. setPath: function ( value ) {
  20725. this.path = value;
  20726. return this;
  20727. }
  20728. } );
  20729. /**
  20730. * @author Nikos M. / https://github.com/foo123/
  20731. *
  20732. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20733. */
  20734. function DataTextureLoader( manager ) {
  20735. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20736. // override in sub classes
  20737. this._parser = null;
  20738. }
  20739. Object.assign( DataTextureLoader.prototype, {
  20740. load: function ( url, onLoad, onProgress, onError ) {
  20741. var scope = this;
  20742. var texture = new DataTexture();
  20743. var loader = new FileLoader( this.manager );
  20744. loader.setResponseType( 'arraybuffer' );
  20745. loader.setPath( this.path );
  20746. loader.load( url, function ( buffer ) {
  20747. var texData = scope._parser( buffer );
  20748. if ( ! texData ) return;
  20749. if ( texData.image !== undefined ) {
  20750. texture.image = texData.image;
  20751. } else if ( texData.data !== undefined ) {
  20752. texture.image.width = texData.width;
  20753. texture.image.height = texData.height;
  20754. texture.image.data = texData.data;
  20755. }
  20756. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20757. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20758. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20759. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipMapLinearFilter;
  20760. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20761. if ( texData.format !== undefined ) {
  20762. texture.format = texData.format;
  20763. }
  20764. if ( texData.type !== undefined ) {
  20765. texture.type = texData.type;
  20766. }
  20767. if ( texData.mipmaps !== undefined ) {
  20768. texture.mipmaps = texData.mipmaps;
  20769. }
  20770. if ( texData.mipmapCount === 1 ) {
  20771. texture.minFilter = LinearFilter;
  20772. }
  20773. texture.needsUpdate = true;
  20774. if ( onLoad ) onLoad( texture, texData );
  20775. }, onProgress, onError );
  20776. return texture;
  20777. },
  20778. setPath: function ( value ) {
  20779. this.path = value;
  20780. return this;
  20781. }
  20782. } );
  20783. /**
  20784. * @author mrdoob / http://mrdoob.com/
  20785. */
  20786. function ImageLoader( manager ) {
  20787. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20788. }
  20789. Object.assign( ImageLoader.prototype, {
  20790. crossOrigin: 'anonymous',
  20791. load: function ( url, onLoad, onProgress, onError ) {
  20792. if ( url === undefined ) url = '';
  20793. if ( this.path !== undefined ) url = this.path + url;
  20794. url = this.manager.resolveURL( url );
  20795. var scope = this;
  20796. var cached = Cache.get( url );
  20797. if ( cached !== undefined ) {
  20798. scope.manager.itemStart( url );
  20799. setTimeout( function () {
  20800. if ( onLoad ) onLoad( cached );
  20801. scope.manager.itemEnd( url );
  20802. }, 0 );
  20803. return cached;
  20804. }
  20805. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20806. function onImageLoad() {
  20807. image.removeEventListener( 'load', onImageLoad, false );
  20808. image.removeEventListener( 'error', onImageError, false );
  20809. Cache.add( url, this );
  20810. if ( onLoad ) onLoad( this );
  20811. scope.manager.itemEnd( url );
  20812. }
  20813. function onImageError( event ) {
  20814. image.removeEventListener( 'load', onImageLoad, false );
  20815. image.removeEventListener( 'error', onImageError, false );
  20816. if ( onError ) onError( event );
  20817. scope.manager.itemError( url );
  20818. scope.manager.itemEnd( url );
  20819. }
  20820. image.addEventListener( 'load', onImageLoad, false );
  20821. image.addEventListener( 'error', onImageError, false );
  20822. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20823. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20824. }
  20825. scope.manager.itemStart( url );
  20826. image.src = url;
  20827. return image;
  20828. },
  20829. setCrossOrigin: function ( value ) {
  20830. this.crossOrigin = value;
  20831. return this;
  20832. },
  20833. setPath: function ( value ) {
  20834. this.path = value;
  20835. return this;
  20836. }
  20837. } );
  20838. /**
  20839. * @author mrdoob / http://mrdoob.com/
  20840. */
  20841. function CubeTextureLoader( manager ) {
  20842. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20843. }
  20844. Object.assign( CubeTextureLoader.prototype, {
  20845. crossOrigin: 'anonymous',
  20846. load: function ( urls, onLoad, onProgress, onError ) {
  20847. var texture = new CubeTexture();
  20848. var loader = new ImageLoader( this.manager );
  20849. loader.setCrossOrigin( this.crossOrigin );
  20850. loader.setPath( this.path );
  20851. var loaded = 0;
  20852. function loadTexture( i ) {
  20853. loader.load( urls[ i ], function ( image ) {
  20854. texture.images[ i ] = image;
  20855. loaded ++;
  20856. if ( loaded === 6 ) {
  20857. texture.needsUpdate = true;
  20858. if ( onLoad ) onLoad( texture );
  20859. }
  20860. }, undefined, onError );
  20861. }
  20862. for ( var i = 0; i < urls.length; ++ i ) {
  20863. loadTexture( i );
  20864. }
  20865. return texture;
  20866. },
  20867. setCrossOrigin: function ( value ) {
  20868. this.crossOrigin = value;
  20869. return this;
  20870. },
  20871. setPath: function ( value ) {
  20872. this.path = value;
  20873. return this;
  20874. }
  20875. } );
  20876. /**
  20877. * @author mrdoob / http://mrdoob.com/
  20878. */
  20879. function TextureLoader( manager ) {
  20880. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20881. }
  20882. Object.assign( TextureLoader.prototype, {
  20883. crossOrigin: 'anonymous',
  20884. load: function ( url, onLoad, onProgress, onError ) {
  20885. var texture = new Texture();
  20886. var loader = new ImageLoader( this.manager );
  20887. loader.setCrossOrigin( this.crossOrigin );
  20888. loader.setPath( this.path );
  20889. loader.load( url, function ( image ) {
  20890. texture.image = image;
  20891. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20892. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20893. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  20894. texture.needsUpdate = true;
  20895. if ( onLoad !== undefined ) {
  20896. onLoad( texture );
  20897. }
  20898. }, onProgress, onError );
  20899. return texture;
  20900. },
  20901. setCrossOrigin: function ( value ) {
  20902. this.crossOrigin = value;
  20903. return this;
  20904. },
  20905. setPath: function ( value ) {
  20906. this.path = value;
  20907. return this;
  20908. }
  20909. } );
  20910. /**
  20911. * @author zz85 / http://www.lab4games.net/zz85/blog
  20912. * Extensible curve object
  20913. *
  20914. * Some common of curve methods:
  20915. * .getPoint( t, optionalTarget ), .getTangent( t )
  20916. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  20917. * .getPoints(), .getSpacedPoints()
  20918. * .getLength()
  20919. * .updateArcLengths()
  20920. *
  20921. * This following curves inherit from THREE.Curve:
  20922. *
  20923. * -- 2D curves --
  20924. * THREE.ArcCurve
  20925. * THREE.CubicBezierCurve
  20926. * THREE.EllipseCurve
  20927. * THREE.LineCurve
  20928. * THREE.QuadraticBezierCurve
  20929. * THREE.SplineCurve
  20930. *
  20931. * -- 3D curves --
  20932. * THREE.CatmullRomCurve3
  20933. * THREE.CubicBezierCurve3
  20934. * THREE.LineCurve3
  20935. * THREE.QuadraticBezierCurve3
  20936. *
  20937. * A series of curves can be represented as a THREE.CurvePath.
  20938. *
  20939. **/
  20940. /**************************************************************
  20941. * Abstract Curve base class
  20942. **************************************************************/
  20943. function Curve() {
  20944. this.type = 'Curve';
  20945. this.arcLengthDivisions = 200;
  20946. }
  20947. Object.assign( Curve.prototype, {
  20948. // Virtual base class method to overwrite and implement in subclasses
  20949. // - t [0 .. 1]
  20950. getPoint: function ( /* t, optionalTarget */ ) {
  20951. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  20952. return null;
  20953. },
  20954. // Get point at relative position in curve according to arc length
  20955. // - u [0 .. 1]
  20956. getPointAt: function ( u, optionalTarget ) {
  20957. var t = this.getUtoTmapping( u );
  20958. return this.getPoint( t, optionalTarget );
  20959. },
  20960. // Get sequence of points using getPoint( t )
  20961. getPoints: function ( divisions ) {
  20962. if ( divisions === undefined ) divisions = 5;
  20963. var points = [];
  20964. for ( var d = 0; d <= divisions; d ++ ) {
  20965. points.push( this.getPoint( d / divisions ) );
  20966. }
  20967. return points;
  20968. },
  20969. // Get sequence of points using getPointAt( u )
  20970. getSpacedPoints: function ( divisions ) {
  20971. if ( divisions === undefined ) divisions = 5;
  20972. var points = [];
  20973. for ( var d = 0; d <= divisions; d ++ ) {
  20974. points.push( this.getPointAt( d / divisions ) );
  20975. }
  20976. return points;
  20977. },
  20978. // Get total curve arc length
  20979. getLength: function () {
  20980. var lengths = this.getLengths();
  20981. return lengths[ lengths.length - 1 ];
  20982. },
  20983. // Get list of cumulative segment lengths
  20984. getLengths: function ( divisions ) {
  20985. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  20986. if ( this.cacheArcLengths &&
  20987. ( this.cacheArcLengths.length === divisions + 1 ) &&
  20988. ! this.needsUpdate ) {
  20989. return this.cacheArcLengths;
  20990. }
  20991. this.needsUpdate = false;
  20992. var cache = [];
  20993. var current, last = this.getPoint( 0 );
  20994. var p, sum = 0;
  20995. cache.push( 0 );
  20996. for ( p = 1; p <= divisions; p ++ ) {
  20997. current = this.getPoint( p / divisions );
  20998. sum += current.distanceTo( last );
  20999. cache.push( sum );
  21000. last = current;
  21001. }
  21002. this.cacheArcLengths = cache;
  21003. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21004. },
  21005. updateArcLengths: function () {
  21006. this.needsUpdate = true;
  21007. this.getLengths();
  21008. },
  21009. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21010. getUtoTmapping: function ( u, distance ) {
  21011. var arcLengths = this.getLengths();
  21012. var i = 0, il = arcLengths.length;
  21013. var targetArcLength; // The targeted u distance value to get
  21014. if ( distance ) {
  21015. targetArcLength = distance;
  21016. } else {
  21017. targetArcLength = u * arcLengths[ il - 1 ];
  21018. }
  21019. // binary search for the index with largest value smaller than target u distance
  21020. var low = 0, high = il - 1, comparison;
  21021. while ( low <= high ) {
  21022. 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
  21023. comparison = arcLengths[ i ] - targetArcLength;
  21024. if ( comparison < 0 ) {
  21025. low = i + 1;
  21026. } else if ( comparison > 0 ) {
  21027. high = i - 1;
  21028. } else {
  21029. high = i;
  21030. break;
  21031. // DONE
  21032. }
  21033. }
  21034. i = high;
  21035. if ( arcLengths[ i ] === targetArcLength ) {
  21036. return i / ( il - 1 );
  21037. }
  21038. // we could get finer grain at lengths, or use simple interpolation between two points
  21039. var lengthBefore = arcLengths[ i ];
  21040. var lengthAfter = arcLengths[ i + 1 ];
  21041. var segmentLength = lengthAfter - lengthBefore;
  21042. // determine where we are between the 'before' and 'after' points
  21043. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21044. // add that fractional amount to t
  21045. var t = ( i + segmentFraction ) / ( il - 1 );
  21046. return t;
  21047. },
  21048. // Returns a unit vector tangent at t
  21049. // In case any sub curve does not implement its tangent derivation,
  21050. // 2 points a small delta apart will be used to find its gradient
  21051. // which seems to give a reasonable approximation
  21052. getTangent: function ( t ) {
  21053. var delta = 0.0001;
  21054. var t1 = t - delta;
  21055. var t2 = t + delta;
  21056. // Capping in case of danger
  21057. if ( t1 < 0 ) t1 = 0;
  21058. if ( t2 > 1 ) t2 = 1;
  21059. var pt1 = this.getPoint( t1 );
  21060. var pt2 = this.getPoint( t2 );
  21061. var vec = pt2.clone().sub( pt1 );
  21062. return vec.normalize();
  21063. },
  21064. getTangentAt: function ( u ) {
  21065. var t = this.getUtoTmapping( u );
  21066. return this.getTangent( t );
  21067. },
  21068. computeFrenetFrames: function ( segments, closed ) {
  21069. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21070. var normal = new Vector3();
  21071. var tangents = [];
  21072. var normals = [];
  21073. var binormals = [];
  21074. var vec = new Vector3();
  21075. var mat = new Matrix4();
  21076. var i, u, theta;
  21077. // compute the tangent vectors for each segment on the curve
  21078. for ( i = 0; i <= segments; i ++ ) {
  21079. u = i / segments;
  21080. tangents[ i ] = this.getTangentAt( u );
  21081. tangents[ i ].normalize();
  21082. }
  21083. // select an initial normal vector perpendicular to the first tangent vector,
  21084. // and in the direction of the minimum tangent xyz component
  21085. normals[ 0 ] = new Vector3();
  21086. binormals[ 0 ] = new Vector3();
  21087. var min = Number.MAX_VALUE;
  21088. var tx = Math.abs( tangents[ 0 ].x );
  21089. var ty = Math.abs( tangents[ 0 ].y );
  21090. var tz = Math.abs( tangents[ 0 ].z );
  21091. if ( tx <= min ) {
  21092. min = tx;
  21093. normal.set( 1, 0, 0 );
  21094. }
  21095. if ( ty <= min ) {
  21096. min = ty;
  21097. normal.set( 0, 1, 0 );
  21098. }
  21099. if ( tz <= min ) {
  21100. normal.set( 0, 0, 1 );
  21101. }
  21102. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21103. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21104. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21105. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21106. for ( i = 1; i <= segments; i ++ ) {
  21107. normals[ i ] = normals[ i - 1 ].clone();
  21108. binormals[ i ] = binormals[ i - 1 ].clone();
  21109. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21110. if ( vec.length() > Number.EPSILON ) {
  21111. vec.normalize();
  21112. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21113. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21114. }
  21115. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21116. }
  21117. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21118. if ( closed === true ) {
  21119. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21120. theta /= segments;
  21121. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21122. theta = - theta;
  21123. }
  21124. for ( i = 1; i <= segments; i ++ ) {
  21125. // twist a little...
  21126. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21127. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21128. }
  21129. }
  21130. return {
  21131. tangents: tangents,
  21132. normals: normals,
  21133. binormals: binormals
  21134. };
  21135. },
  21136. clone: function () {
  21137. return new this.constructor().copy( this );
  21138. },
  21139. copy: function ( source ) {
  21140. this.arcLengthDivisions = source.arcLengthDivisions;
  21141. return this;
  21142. },
  21143. toJSON: function () {
  21144. var data = {
  21145. metadata: {
  21146. version: 4.5,
  21147. type: 'Curve',
  21148. generator: 'Curve.toJSON'
  21149. }
  21150. };
  21151. data.arcLengthDivisions = this.arcLengthDivisions;
  21152. data.type = this.type;
  21153. return data;
  21154. },
  21155. fromJSON: function ( json ) {
  21156. this.arcLengthDivisions = json.arcLengthDivisions;
  21157. return this;
  21158. }
  21159. } );
  21160. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21161. Curve.call( this );
  21162. this.type = 'EllipseCurve';
  21163. this.aX = aX || 0;
  21164. this.aY = aY || 0;
  21165. this.xRadius = xRadius || 1;
  21166. this.yRadius = yRadius || 1;
  21167. this.aStartAngle = aStartAngle || 0;
  21168. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21169. this.aClockwise = aClockwise || false;
  21170. this.aRotation = aRotation || 0;
  21171. }
  21172. EllipseCurve.prototype = Object.create( Curve.prototype );
  21173. EllipseCurve.prototype.constructor = EllipseCurve;
  21174. EllipseCurve.prototype.isEllipseCurve = true;
  21175. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21176. var point = optionalTarget || new Vector2();
  21177. var twoPi = Math.PI * 2;
  21178. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21179. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21180. // ensures that deltaAngle is 0 .. 2 PI
  21181. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21182. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21183. if ( deltaAngle < Number.EPSILON ) {
  21184. if ( samePoints ) {
  21185. deltaAngle = 0;
  21186. } else {
  21187. deltaAngle = twoPi;
  21188. }
  21189. }
  21190. if ( this.aClockwise === true && ! samePoints ) {
  21191. if ( deltaAngle === twoPi ) {
  21192. deltaAngle = - twoPi;
  21193. } else {
  21194. deltaAngle = deltaAngle - twoPi;
  21195. }
  21196. }
  21197. var angle = this.aStartAngle + t * deltaAngle;
  21198. var x = this.aX + this.xRadius * Math.cos( angle );
  21199. var y = this.aY + this.yRadius * Math.sin( angle );
  21200. if ( this.aRotation !== 0 ) {
  21201. var cos = Math.cos( this.aRotation );
  21202. var sin = Math.sin( this.aRotation );
  21203. var tx = x - this.aX;
  21204. var ty = y - this.aY;
  21205. // Rotate the point about the center of the ellipse.
  21206. x = tx * cos - ty * sin + this.aX;
  21207. y = tx * sin + ty * cos + this.aY;
  21208. }
  21209. return point.set( x, y );
  21210. };
  21211. EllipseCurve.prototype.copy = function ( source ) {
  21212. Curve.prototype.copy.call( this, source );
  21213. this.aX = source.aX;
  21214. this.aY = source.aY;
  21215. this.xRadius = source.xRadius;
  21216. this.yRadius = source.yRadius;
  21217. this.aStartAngle = source.aStartAngle;
  21218. this.aEndAngle = source.aEndAngle;
  21219. this.aClockwise = source.aClockwise;
  21220. this.aRotation = source.aRotation;
  21221. return this;
  21222. };
  21223. EllipseCurve.prototype.toJSON = function () {
  21224. var data = Curve.prototype.toJSON.call( this );
  21225. data.aX = this.aX;
  21226. data.aY = this.aY;
  21227. data.xRadius = this.xRadius;
  21228. data.yRadius = this.yRadius;
  21229. data.aStartAngle = this.aStartAngle;
  21230. data.aEndAngle = this.aEndAngle;
  21231. data.aClockwise = this.aClockwise;
  21232. data.aRotation = this.aRotation;
  21233. return data;
  21234. };
  21235. EllipseCurve.prototype.fromJSON = function ( json ) {
  21236. Curve.prototype.fromJSON.call( this, json );
  21237. this.aX = json.aX;
  21238. this.aY = json.aY;
  21239. this.xRadius = json.xRadius;
  21240. this.yRadius = json.yRadius;
  21241. this.aStartAngle = json.aStartAngle;
  21242. this.aEndAngle = json.aEndAngle;
  21243. this.aClockwise = json.aClockwise;
  21244. this.aRotation = json.aRotation;
  21245. return this;
  21246. };
  21247. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21248. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21249. this.type = 'ArcCurve';
  21250. }
  21251. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21252. ArcCurve.prototype.constructor = ArcCurve;
  21253. ArcCurve.prototype.isArcCurve = true;
  21254. /**
  21255. * @author zz85 https://github.com/zz85
  21256. *
  21257. * Centripetal CatmullRom Curve - which is useful for avoiding
  21258. * cusps and self-intersections in non-uniform catmull rom curves.
  21259. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21260. *
  21261. * curve.type accepts centripetal(default), chordal and catmullrom
  21262. * curve.tension is used for catmullrom which defaults to 0.5
  21263. */
  21264. /*
  21265. Based on an optimized c++ solution in
  21266. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21267. - http://ideone.com/NoEbVM
  21268. This CubicPoly class could be used for reusing some variables and calculations,
  21269. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21270. which can be placed in CurveUtils.
  21271. */
  21272. function CubicPoly() {
  21273. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21274. /*
  21275. * Compute coefficients for a cubic polynomial
  21276. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21277. * such that
  21278. * p(0) = x0, p(1) = x1
  21279. * and
  21280. * p'(0) = t0, p'(1) = t1.
  21281. */
  21282. function init( x0, x1, t0, t1 ) {
  21283. c0 = x0;
  21284. c1 = t0;
  21285. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21286. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21287. }
  21288. return {
  21289. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21290. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21291. },
  21292. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21293. // compute tangents when parameterized in [t1,t2]
  21294. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21295. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21296. // rescale tangents for parametrization in [0,1]
  21297. t1 *= dt1;
  21298. t2 *= dt1;
  21299. init( x1, x2, t1, t2 );
  21300. },
  21301. calc: function ( t ) {
  21302. var t2 = t * t;
  21303. var t3 = t2 * t;
  21304. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21305. }
  21306. };
  21307. }
  21308. //
  21309. var tmp = new Vector3();
  21310. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21311. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21312. Curve.call( this );
  21313. this.type = 'CatmullRomCurve3';
  21314. this.points = points || [];
  21315. this.closed = closed || false;
  21316. this.curveType = curveType || 'centripetal';
  21317. this.tension = tension || 0.5;
  21318. }
  21319. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21320. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21321. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21322. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21323. var point = optionalTarget || new Vector3();
  21324. var points = this.points;
  21325. var l = points.length;
  21326. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21327. var intPoint = Math.floor( p );
  21328. var weight = p - intPoint;
  21329. if ( this.closed ) {
  21330. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21331. } else if ( weight === 0 && intPoint === l - 1 ) {
  21332. intPoint = l - 2;
  21333. weight = 1;
  21334. }
  21335. var p0, p1, p2, p3; // 4 points
  21336. if ( this.closed || intPoint > 0 ) {
  21337. p0 = points[ ( intPoint - 1 ) % l ];
  21338. } else {
  21339. // extrapolate first point
  21340. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21341. p0 = tmp;
  21342. }
  21343. p1 = points[ intPoint % l ];
  21344. p2 = points[ ( intPoint + 1 ) % l ];
  21345. if ( this.closed || intPoint + 2 < l ) {
  21346. p3 = points[ ( intPoint + 2 ) % l ];
  21347. } else {
  21348. // extrapolate last point
  21349. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21350. p3 = tmp;
  21351. }
  21352. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21353. // init Centripetal / Chordal Catmull-Rom
  21354. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21355. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21356. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21357. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21358. // safety check for repeated points
  21359. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21360. if ( dt0 < 1e-4 ) dt0 = dt1;
  21361. if ( dt2 < 1e-4 ) dt2 = dt1;
  21362. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21363. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21364. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21365. } else if ( this.curveType === 'catmullrom' ) {
  21366. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21367. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21368. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21369. }
  21370. point.set(
  21371. px.calc( weight ),
  21372. py.calc( weight ),
  21373. pz.calc( weight )
  21374. );
  21375. return point;
  21376. };
  21377. CatmullRomCurve3.prototype.copy = function ( source ) {
  21378. Curve.prototype.copy.call( this, source );
  21379. this.points = [];
  21380. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21381. var point = source.points[ i ];
  21382. this.points.push( point.clone() );
  21383. }
  21384. this.closed = source.closed;
  21385. this.curveType = source.curveType;
  21386. this.tension = source.tension;
  21387. return this;
  21388. };
  21389. CatmullRomCurve3.prototype.toJSON = function () {
  21390. var data = Curve.prototype.toJSON.call( this );
  21391. data.points = [];
  21392. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21393. var point = this.points[ i ];
  21394. data.points.push( point.toArray() );
  21395. }
  21396. data.closed = this.closed;
  21397. data.curveType = this.curveType;
  21398. data.tension = this.tension;
  21399. return data;
  21400. };
  21401. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21402. Curve.prototype.fromJSON.call( this, json );
  21403. this.points = [];
  21404. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21405. var point = json.points[ i ];
  21406. this.points.push( new Vector3().fromArray( point ) );
  21407. }
  21408. this.closed = json.closed;
  21409. this.curveType = json.curveType;
  21410. this.tension = json.tension;
  21411. return this;
  21412. };
  21413. /**
  21414. * @author zz85 / http://www.lab4games.net/zz85/blog
  21415. *
  21416. * Bezier Curves formulas obtained from
  21417. * http://en.wikipedia.org/wiki/Bézier_curve
  21418. */
  21419. function CatmullRom( t, p0, p1, p2, p3 ) {
  21420. var v0 = ( p2 - p0 ) * 0.5;
  21421. var v1 = ( p3 - p1 ) * 0.5;
  21422. var t2 = t * t;
  21423. var t3 = t * t2;
  21424. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21425. }
  21426. //
  21427. function QuadraticBezierP0( t, p ) {
  21428. var k = 1 - t;
  21429. return k * k * p;
  21430. }
  21431. function QuadraticBezierP1( t, p ) {
  21432. return 2 * ( 1 - t ) * t * p;
  21433. }
  21434. function QuadraticBezierP2( t, p ) {
  21435. return t * t * p;
  21436. }
  21437. function QuadraticBezier( t, p0, p1, p2 ) {
  21438. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21439. QuadraticBezierP2( t, p2 );
  21440. }
  21441. //
  21442. function CubicBezierP0( t, p ) {
  21443. var k = 1 - t;
  21444. return k * k * k * p;
  21445. }
  21446. function CubicBezierP1( t, p ) {
  21447. var k = 1 - t;
  21448. return 3 * k * k * t * p;
  21449. }
  21450. function CubicBezierP2( t, p ) {
  21451. return 3 * ( 1 - t ) * t * t * p;
  21452. }
  21453. function CubicBezierP3( t, p ) {
  21454. return t * t * t * p;
  21455. }
  21456. function CubicBezier( t, p0, p1, p2, p3 ) {
  21457. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21458. CubicBezierP3( t, p3 );
  21459. }
  21460. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21461. Curve.call( this );
  21462. this.type = 'CubicBezierCurve';
  21463. this.v0 = v0 || new Vector2();
  21464. this.v1 = v1 || new Vector2();
  21465. this.v2 = v2 || new Vector2();
  21466. this.v3 = v3 || new Vector2();
  21467. }
  21468. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21469. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21470. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21471. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21472. var point = optionalTarget || new Vector2();
  21473. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21474. point.set(
  21475. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21476. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21477. );
  21478. return point;
  21479. };
  21480. CubicBezierCurve.prototype.copy = function ( source ) {
  21481. Curve.prototype.copy.call( this, source );
  21482. this.v0.copy( source.v0 );
  21483. this.v1.copy( source.v1 );
  21484. this.v2.copy( source.v2 );
  21485. this.v3.copy( source.v3 );
  21486. return this;
  21487. };
  21488. CubicBezierCurve.prototype.toJSON = function () {
  21489. var data = Curve.prototype.toJSON.call( this );
  21490. data.v0 = this.v0.toArray();
  21491. data.v1 = this.v1.toArray();
  21492. data.v2 = this.v2.toArray();
  21493. data.v3 = this.v3.toArray();
  21494. return data;
  21495. };
  21496. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21497. Curve.prototype.fromJSON.call( this, json );
  21498. this.v0.fromArray( json.v0 );
  21499. this.v1.fromArray( json.v1 );
  21500. this.v2.fromArray( json.v2 );
  21501. this.v3.fromArray( json.v3 );
  21502. return this;
  21503. };
  21504. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21505. Curve.call( this );
  21506. this.type = 'CubicBezierCurve3';
  21507. this.v0 = v0 || new Vector3();
  21508. this.v1 = v1 || new Vector3();
  21509. this.v2 = v2 || new Vector3();
  21510. this.v3 = v3 || new Vector3();
  21511. }
  21512. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21513. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21514. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21515. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21516. var point = optionalTarget || new Vector3();
  21517. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21518. point.set(
  21519. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21520. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21521. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21522. );
  21523. return point;
  21524. };
  21525. CubicBezierCurve3.prototype.copy = function ( source ) {
  21526. Curve.prototype.copy.call( this, source );
  21527. this.v0.copy( source.v0 );
  21528. this.v1.copy( source.v1 );
  21529. this.v2.copy( source.v2 );
  21530. this.v3.copy( source.v3 );
  21531. return this;
  21532. };
  21533. CubicBezierCurve3.prototype.toJSON = function () {
  21534. var data = Curve.prototype.toJSON.call( this );
  21535. data.v0 = this.v0.toArray();
  21536. data.v1 = this.v1.toArray();
  21537. data.v2 = this.v2.toArray();
  21538. data.v3 = this.v3.toArray();
  21539. return data;
  21540. };
  21541. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21542. Curve.prototype.fromJSON.call( this, json );
  21543. this.v0.fromArray( json.v0 );
  21544. this.v1.fromArray( json.v1 );
  21545. this.v2.fromArray( json.v2 );
  21546. this.v3.fromArray( json.v3 );
  21547. return this;
  21548. };
  21549. function LineCurve( v1, v2 ) {
  21550. Curve.call( this );
  21551. this.type = 'LineCurve';
  21552. this.v1 = v1 || new Vector2();
  21553. this.v2 = v2 || new Vector2();
  21554. }
  21555. LineCurve.prototype = Object.create( Curve.prototype );
  21556. LineCurve.prototype.constructor = LineCurve;
  21557. LineCurve.prototype.isLineCurve = true;
  21558. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21559. var point = optionalTarget || new Vector2();
  21560. if ( t === 1 ) {
  21561. point.copy( this.v2 );
  21562. } else {
  21563. point.copy( this.v2 ).sub( this.v1 );
  21564. point.multiplyScalar( t ).add( this.v1 );
  21565. }
  21566. return point;
  21567. };
  21568. // Line curve is linear, so we can overwrite default getPointAt
  21569. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21570. return this.getPoint( u, optionalTarget );
  21571. };
  21572. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21573. var tangent = this.v2.clone().sub( this.v1 );
  21574. return tangent.normalize();
  21575. };
  21576. LineCurve.prototype.copy = function ( source ) {
  21577. Curve.prototype.copy.call( this, source );
  21578. this.v1.copy( source.v1 );
  21579. this.v2.copy( source.v2 );
  21580. return this;
  21581. };
  21582. LineCurve.prototype.toJSON = function () {
  21583. var data = Curve.prototype.toJSON.call( this );
  21584. data.v1 = this.v1.toArray();
  21585. data.v2 = this.v2.toArray();
  21586. return data;
  21587. };
  21588. LineCurve.prototype.fromJSON = function ( json ) {
  21589. Curve.prototype.fromJSON.call( this, json );
  21590. this.v1.fromArray( json.v1 );
  21591. this.v2.fromArray( json.v2 );
  21592. return this;
  21593. };
  21594. function LineCurve3( v1, v2 ) {
  21595. Curve.call( this );
  21596. this.type = 'LineCurve3';
  21597. this.v1 = v1 || new Vector3();
  21598. this.v2 = v2 || new Vector3();
  21599. }
  21600. LineCurve3.prototype = Object.create( Curve.prototype );
  21601. LineCurve3.prototype.constructor = LineCurve3;
  21602. LineCurve3.prototype.isLineCurve3 = true;
  21603. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21604. var point = optionalTarget || new Vector3();
  21605. if ( t === 1 ) {
  21606. point.copy( this.v2 );
  21607. } else {
  21608. point.copy( this.v2 ).sub( this.v1 );
  21609. point.multiplyScalar( t ).add( this.v1 );
  21610. }
  21611. return point;
  21612. };
  21613. // Line curve is linear, so we can overwrite default getPointAt
  21614. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21615. return this.getPoint( u, optionalTarget );
  21616. };
  21617. LineCurve3.prototype.copy = function ( source ) {
  21618. Curve.prototype.copy.call( this, source );
  21619. this.v1.copy( source.v1 );
  21620. this.v2.copy( source.v2 );
  21621. return this;
  21622. };
  21623. LineCurve3.prototype.toJSON = function () {
  21624. var data = Curve.prototype.toJSON.call( this );
  21625. data.v1 = this.v1.toArray();
  21626. data.v2 = this.v2.toArray();
  21627. return data;
  21628. };
  21629. LineCurve3.prototype.fromJSON = function ( json ) {
  21630. Curve.prototype.fromJSON.call( this, json );
  21631. this.v1.fromArray( json.v1 );
  21632. this.v2.fromArray( json.v2 );
  21633. return this;
  21634. };
  21635. function QuadraticBezierCurve( v0, v1, v2 ) {
  21636. Curve.call( this );
  21637. this.type = 'QuadraticBezierCurve';
  21638. this.v0 = v0 || new Vector2();
  21639. this.v1 = v1 || new Vector2();
  21640. this.v2 = v2 || new Vector2();
  21641. }
  21642. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21643. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21644. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21645. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21646. var point = optionalTarget || new Vector2();
  21647. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21648. point.set(
  21649. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21650. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21651. );
  21652. return point;
  21653. };
  21654. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21655. Curve.prototype.copy.call( this, source );
  21656. this.v0.copy( source.v0 );
  21657. this.v1.copy( source.v1 );
  21658. this.v2.copy( source.v2 );
  21659. return this;
  21660. };
  21661. QuadraticBezierCurve.prototype.toJSON = function () {
  21662. var data = Curve.prototype.toJSON.call( this );
  21663. data.v0 = this.v0.toArray();
  21664. data.v1 = this.v1.toArray();
  21665. data.v2 = this.v2.toArray();
  21666. return data;
  21667. };
  21668. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21669. Curve.prototype.fromJSON.call( this, json );
  21670. this.v0.fromArray( json.v0 );
  21671. this.v1.fromArray( json.v1 );
  21672. this.v2.fromArray( json.v2 );
  21673. return this;
  21674. };
  21675. function QuadraticBezierCurve3( v0, v1, v2 ) {
  21676. Curve.call( this );
  21677. this.type = 'QuadraticBezierCurve3';
  21678. this.v0 = v0 || new Vector3();
  21679. this.v1 = v1 || new Vector3();
  21680. this.v2 = v2 || new Vector3();
  21681. }
  21682. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21683. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21684. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21685. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21686. var point = optionalTarget || new Vector3();
  21687. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21688. point.set(
  21689. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21690. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21691. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21692. );
  21693. return point;
  21694. };
  21695. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21696. Curve.prototype.copy.call( this, source );
  21697. this.v0.copy( source.v0 );
  21698. this.v1.copy( source.v1 );
  21699. this.v2.copy( source.v2 );
  21700. return this;
  21701. };
  21702. QuadraticBezierCurve3.prototype.toJSON = function () {
  21703. var data = Curve.prototype.toJSON.call( this );
  21704. data.v0 = this.v0.toArray();
  21705. data.v1 = this.v1.toArray();
  21706. data.v2 = this.v2.toArray();
  21707. return data;
  21708. };
  21709. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21710. Curve.prototype.fromJSON.call( this, json );
  21711. this.v0.fromArray( json.v0 );
  21712. this.v1.fromArray( json.v1 );
  21713. this.v2.fromArray( json.v2 );
  21714. return this;
  21715. };
  21716. function SplineCurve( points /* array of Vector2 */ ) {
  21717. Curve.call( this );
  21718. this.type = 'SplineCurve';
  21719. this.points = points || [];
  21720. }
  21721. SplineCurve.prototype = Object.create( Curve.prototype );
  21722. SplineCurve.prototype.constructor = SplineCurve;
  21723. SplineCurve.prototype.isSplineCurve = true;
  21724. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21725. var point = optionalTarget || new Vector2();
  21726. var points = this.points;
  21727. var p = ( points.length - 1 ) * t;
  21728. var intPoint = Math.floor( p );
  21729. var weight = p - intPoint;
  21730. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21731. var p1 = points[ intPoint ];
  21732. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21733. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21734. point.set(
  21735. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21736. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21737. );
  21738. return point;
  21739. };
  21740. SplineCurve.prototype.copy = function ( source ) {
  21741. Curve.prototype.copy.call( this, source );
  21742. this.points = [];
  21743. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21744. var point = source.points[ i ];
  21745. this.points.push( point.clone() );
  21746. }
  21747. return this;
  21748. };
  21749. SplineCurve.prototype.toJSON = function () {
  21750. var data = Curve.prototype.toJSON.call( this );
  21751. data.points = [];
  21752. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21753. var point = this.points[ i ];
  21754. data.points.push( point.toArray() );
  21755. }
  21756. return data;
  21757. };
  21758. SplineCurve.prototype.fromJSON = function ( json ) {
  21759. Curve.prototype.fromJSON.call( this, json );
  21760. this.points = [];
  21761. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21762. var point = json.points[ i ];
  21763. this.points.push( new Vector2().fromArray( point ) );
  21764. }
  21765. return this;
  21766. };
  21767. var Curves = /*#__PURE__*/Object.freeze({
  21768. ArcCurve: ArcCurve,
  21769. CatmullRomCurve3: CatmullRomCurve3,
  21770. CubicBezierCurve: CubicBezierCurve,
  21771. CubicBezierCurve3: CubicBezierCurve3,
  21772. EllipseCurve: EllipseCurve,
  21773. LineCurve: LineCurve,
  21774. LineCurve3: LineCurve3,
  21775. QuadraticBezierCurve: QuadraticBezierCurve,
  21776. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21777. SplineCurve: SplineCurve
  21778. });
  21779. /**
  21780. * @author zz85 / http://www.lab4games.net/zz85/blog
  21781. *
  21782. **/
  21783. /**************************************************************
  21784. * Curved Path - a curve path is simply a array of connected
  21785. * curves, but retains the api of a curve
  21786. **************************************************************/
  21787. function CurvePath() {
  21788. Curve.call( this );
  21789. this.type = 'CurvePath';
  21790. this.curves = [];
  21791. this.autoClose = false; // Automatically closes the path
  21792. }
  21793. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21794. constructor: CurvePath,
  21795. add: function ( curve ) {
  21796. this.curves.push( curve );
  21797. },
  21798. closePath: function () {
  21799. // Add a line curve if start and end of lines are not connected
  21800. var startPoint = this.curves[ 0 ].getPoint( 0 );
  21801. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21802. if ( ! startPoint.equals( endPoint ) ) {
  21803. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21804. }
  21805. },
  21806. // To get accurate point with reference to
  21807. // entire path distance at time t,
  21808. // following has to be done:
  21809. // 1. Length of each sub path have to be known
  21810. // 2. Locate and identify type of curve
  21811. // 3. Get t for the curve
  21812. // 4. Return curve.getPointAt(t')
  21813. getPoint: function ( t ) {
  21814. var d = t * this.getLength();
  21815. var curveLengths = this.getCurveLengths();
  21816. var i = 0;
  21817. // To think about boundaries points.
  21818. while ( i < curveLengths.length ) {
  21819. if ( curveLengths[ i ] >= d ) {
  21820. var diff = curveLengths[ i ] - d;
  21821. var curve = this.curves[ i ];
  21822. var segmentLength = curve.getLength();
  21823. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21824. return curve.getPointAt( u );
  21825. }
  21826. i ++;
  21827. }
  21828. return null;
  21829. // loop where sum != 0, sum > d , sum+1 <d
  21830. },
  21831. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21832. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21833. // getPoint() depends on getLength
  21834. getLength: function () {
  21835. var lens = this.getCurveLengths();
  21836. return lens[ lens.length - 1 ];
  21837. },
  21838. // cacheLengths must be recalculated.
  21839. updateArcLengths: function () {
  21840. this.needsUpdate = true;
  21841. this.cacheLengths = null;
  21842. this.getCurveLengths();
  21843. },
  21844. // Compute lengths and cache them
  21845. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21846. getCurveLengths: function () {
  21847. // We use cache values if curves and cache array are same length
  21848. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21849. return this.cacheLengths;
  21850. }
  21851. // Get length of sub-curve
  21852. // Push sums into cached array
  21853. var lengths = [], sums = 0;
  21854. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21855. sums += this.curves[ i ].getLength();
  21856. lengths.push( sums );
  21857. }
  21858. this.cacheLengths = lengths;
  21859. return lengths;
  21860. },
  21861. getSpacedPoints: function ( divisions ) {
  21862. if ( divisions === undefined ) divisions = 40;
  21863. var points = [];
  21864. for ( var i = 0; i <= divisions; i ++ ) {
  21865. points.push( this.getPoint( i / divisions ) );
  21866. }
  21867. if ( this.autoClose ) {
  21868. points.push( points[ 0 ] );
  21869. }
  21870. return points;
  21871. },
  21872. getPoints: function ( divisions ) {
  21873. divisions = divisions || 12;
  21874. var points = [], last;
  21875. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21876. var curve = curves[ i ];
  21877. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21878. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21879. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21880. : divisions;
  21881. var pts = curve.getPoints( resolution );
  21882. for ( var j = 0; j < pts.length; j ++ ) {
  21883. var point = pts[ j ];
  21884. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21885. points.push( point );
  21886. last = point;
  21887. }
  21888. }
  21889. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21890. points.push( points[ 0 ] );
  21891. }
  21892. return points;
  21893. },
  21894. copy: function ( source ) {
  21895. Curve.prototype.copy.call( this, source );
  21896. this.curves = [];
  21897. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  21898. var curve = source.curves[ i ];
  21899. this.curves.push( curve.clone() );
  21900. }
  21901. this.autoClose = source.autoClose;
  21902. return this;
  21903. },
  21904. toJSON: function () {
  21905. var data = Curve.prototype.toJSON.call( this );
  21906. data.autoClose = this.autoClose;
  21907. data.curves = [];
  21908. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21909. var curve = this.curves[ i ];
  21910. data.curves.push( curve.toJSON() );
  21911. }
  21912. return data;
  21913. },
  21914. fromJSON: function ( json ) {
  21915. Curve.prototype.fromJSON.call( this, json );
  21916. this.autoClose = json.autoClose;
  21917. this.curves = [];
  21918. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  21919. var curve = json.curves[ i ];
  21920. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  21921. }
  21922. return this;
  21923. }
  21924. } );
  21925. /**
  21926. * @author zz85 / http://www.lab4games.net/zz85/blog
  21927. * Creates free form 2d path using series of points, lines or curves.
  21928. **/
  21929. function Path( points ) {
  21930. CurvePath.call( this );
  21931. this.type = 'Path';
  21932. this.currentPoint = new Vector2();
  21933. if ( points ) {
  21934. this.setFromPoints( points );
  21935. }
  21936. }
  21937. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  21938. constructor: Path,
  21939. setFromPoints: function ( points ) {
  21940. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  21941. for ( var i = 1, l = points.length; i < l; i ++ ) {
  21942. this.lineTo( points[ i ].x, points[ i ].y );
  21943. }
  21944. },
  21945. moveTo: function ( x, y ) {
  21946. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21947. },
  21948. lineTo: function ( x, y ) {
  21949. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  21950. this.curves.push( curve );
  21951. this.currentPoint.set( x, y );
  21952. },
  21953. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21954. var curve = new QuadraticBezierCurve(
  21955. this.currentPoint.clone(),
  21956. new Vector2( aCPx, aCPy ),
  21957. new Vector2( aX, aY )
  21958. );
  21959. this.curves.push( curve );
  21960. this.currentPoint.set( aX, aY );
  21961. },
  21962. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21963. var curve = new CubicBezierCurve(
  21964. this.currentPoint.clone(),
  21965. new Vector2( aCP1x, aCP1y ),
  21966. new Vector2( aCP2x, aCP2y ),
  21967. new Vector2( aX, aY )
  21968. );
  21969. this.curves.push( curve );
  21970. this.currentPoint.set( aX, aY );
  21971. },
  21972. splineThru: function ( pts /*Array of Vector*/ ) {
  21973. var npts = [ this.currentPoint.clone() ].concat( pts );
  21974. var curve = new SplineCurve( npts );
  21975. this.curves.push( curve );
  21976. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21977. },
  21978. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21979. var x0 = this.currentPoint.x;
  21980. var y0 = this.currentPoint.y;
  21981. this.absarc( aX + x0, aY + y0, aRadius,
  21982. aStartAngle, aEndAngle, aClockwise );
  21983. },
  21984. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21985. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21986. },
  21987. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21988. var x0 = this.currentPoint.x;
  21989. var y0 = this.currentPoint.y;
  21990. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21991. },
  21992. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21993. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21994. if ( this.curves.length > 0 ) {
  21995. // if a previous curve is present, attempt to join
  21996. var firstPoint = curve.getPoint( 0 );
  21997. if ( ! firstPoint.equals( this.currentPoint ) ) {
  21998. this.lineTo( firstPoint.x, firstPoint.y );
  21999. }
  22000. }
  22001. this.curves.push( curve );
  22002. var lastPoint = curve.getPoint( 1 );
  22003. this.currentPoint.copy( lastPoint );
  22004. },
  22005. copy: function ( source ) {
  22006. CurvePath.prototype.copy.call( this, source );
  22007. this.currentPoint.copy( source.currentPoint );
  22008. return this;
  22009. },
  22010. toJSON: function () {
  22011. var data = CurvePath.prototype.toJSON.call( this );
  22012. data.currentPoint = this.currentPoint.toArray();
  22013. return data;
  22014. },
  22015. fromJSON: function ( json ) {
  22016. CurvePath.prototype.fromJSON.call( this, json );
  22017. this.currentPoint.fromArray( json.currentPoint );
  22018. return this;
  22019. }
  22020. } );
  22021. /**
  22022. * @author zz85 / http://www.lab4games.net/zz85/blog
  22023. * Defines a 2d shape plane using paths.
  22024. **/
  22025. // STEP 1 Create a path.
  22026. // STEP 2 Turn path into shape.
  22027. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22028. // STEP 3a - Extract points from each shape, turn to vertices
  22029. // STEP 3b - Triangulate each shape, add faces.
  22030. function Shape( points ) {
  22031. Path.call( this, points );
  22032. this.uuid = _Math.generateUUID();
  22033. this.type = 'Shape';
  22034. this.holes = [];
  22035. }
  22036. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22037. constructor: Shape,
  22038. getPointsHoles: function ( divisions ) {
  22039. var holesPts = [];
  22040. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22041. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22042. }
  22043. return holesPts;
  22044. },
  22045. // get points of shape and holes (keypoints based on segments parameter)
  22046. extractPoints: function ( divisions ) {
  22047. return {
  22048. shape: this.getPoints( divisions ),
  22049. holes: this.getPointsHoles( divisions )
  22050. };
  22051. },
  22052. copy: function ( source ) {
  22053. Path.prototype.copy.call( this, source );
  22054. this.holes = [];
  22055. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22056. var hole = source.holes[ i ];
  22057. this.holes.push( hole.clone() );
  22058. }
  22059. return this;
  22060. },
  22061. toJSON: function () {
  22062. var data = Path.prototype.toJSON.call( this );
  22063. data.uuid = this.uuid;
  22064. data.holes = [];
  22065. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22066. var hole = this.holes[ i ];
  22067. data.holes.push( hole.toJSON() );
  22068. }
  22069. return data;
  22070. },
  22071. fromJSON: function ( json ) {
  22072. Path.prototype.fromJSON.call( this, json );
  22073. this.uuid = json.uuid;
  22074. this.holes = [];
  22075. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22076. var hole = json.holes[ i ];
  22077. this.holes.push( new Path().fromJSON( hole ) );
  22078. }
  22079. return this;
  22080. }
  22081. } );
  22082. /**
  22083. * @author mrdoob / http://mrdoob.com/
  22084. * @author alteredq / http://alteredqualia.com/
  22085. */
  22086. function Light( color, intensity ) {
  22087. Object3D.call( this );
  22088. this.type = 'Light';
  22089. this.color = new Color( color );
  22090. this.intensity = intensity !== undefined ? intensity : 1;
  22091. this.receiveShadow = undefined;
  22092. }
  22093. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22094. constructor: Light,
  22095. isLight: true,
  22096. copy: function ( source ) {
  22097. Object3D.prototype.copy.call( this, source );
  22098. this.color.copy( source.color );
  22099. this.intensity = source.intensity;
  22100. return this;
  22101. },
  22102. toJSON: function ( meta ) {
  22103. var data = Object3D.prototype.toJSON.call( this, meta );
  22104. data.object.color = this.color.getHex();
  22105. data.object.intensity = this.intensity;
  22106. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22107. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22108. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22109. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22110. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22111. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22112. return data;
  22113. }
  22114. } );
  22115. /**
  22116. * @author alteredq / http://alteredqualia.com/
  22117. */
  22118. function HemisphereLight( skyColor, groundColor, intensity ) {
  22119. Light.call( this, skyColor, intensity );
  22120. this.type = 'HemisphereLight';
  22121. this.castShadow = undefined;
  22122. this.position.copy( Object3D.DefaultUp );
  22123. this.updateMatrix();
  22124. this.groundColor = new Color( groundColor );
  22125. }
  22126. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22127. constructor: HemisphereLight,
  22128. isHemisphereLight: true,
  22129. copy: function ( source ) {
  22130. Light.prototype.copy.call( this, source );
  22131. this.groundColor.copy( source.groundColor );
  22132. return this;
  22133. }
  22134. } );
  22135. /**
  22136. * @author mrdoob / http://mrdoob.com/
  22137. */
  22138. function LightShadow( camera ) {
  22139. this.camera = camera;
  22140. this.bias = 0;
  22141. this.radius = 1;
  22142. this.mapSize = new Vector2( 512, 512 );
  22143. this.map = null;
  22144. this.matrix = new Matrix4();
  22145. }
  22146. Object.assign( LightShadow.prototype, {
  22147. copy: function ( source ) {
  22148. this.camera = source.camera.clone();
  22149. this.bias = source.bias;
  22150. this.radius = source.radius;
  22151. this.mapSize.copy( source.mapSize );
  22152. return this;
  22153. },
  22154. clone: function () {
  22155. return new this.constructor().copy( this );
  22156. },
  22157. toJSON: function () {
  22158. var object = {};
  22159. if ( this.bias !== 0 ) object.bias = this.bias;
  22160. if ( this.radius !== 1 ) object.radius = this.radius;
  22161. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22162. object.camera = this.camera.toJSON( false ).object;
  22163. delete object.camera.matrix;
  22164. return object;
  22165. }
  22166. } );
  22167. /**
  22168. * @author mrdoob / http://mrdoob.com/
  22169. */
  22170. function SpotLightShadow() {
  22171. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22172. }
  22173. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22174. constructor: SpotLightShadow,
  22175. isSpotLightShadow: true,
  22176. update: function ( light ) {
  22177. var camera = this.camera;
  22178. var fov = _Math.RAD2DEG * 2 * light.angle;
  22179. var aspect = this.mapSize.width / this.mapSize.height;
  22180. var far = light.distance || camera.far;
  22181. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22182. camera.fov = fov;
  22183. camera.aspect = aspect;
  22184. camera.far = far;
  22185. camera.updateProjectionMatrix();
  22186. }
  22187. }
  22188. } );
  22189. /**
  22190. * @author alteredq / http://alteredqualia.com/
  22191. */
  22192. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22193. Light.call( this, color, intensity );
  22194. this.type = 'SpotLight';
  22195. this.position.copy( Object3D.DefaultUp );
  22196. this.updateMatrix();
  22197. this.target = new Object3D();
  22198. Object.defineProperty( this, 'power', {
  22199. get: function () {
  22200. // intensity = power per solid angle.
  22201. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22202. return this.intensity * Math.PI;
  22203. },
  22204. set: function ( power ) {
  22205. // intensity = power per solid angle.
  22206. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22207. this.intensity = power / Math.PI;
  22208. }
  22209. } );
  22210. this.distance = ( distance !== undefined ) ? distance : 0;
  22211. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22212. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22213. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22214. this.shadow = new SpotLightShadow();
  22215. }
  22216. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22217. constructor: SpotLight,
  22218. isSpotLight: true,
  22219. copy: function ( source ) {
  22220. Light.prototype.copy.call( this, source );
  22221. this.distance = source.distance;
  22222. this.angle = source.angle;
  22223. this.penumbra = source.penumbra;
  22224. this.decay = source.decay;
  22225. this.target = source.target.clone();
  22226. this.shadow = source.shadow.clone();
  22227. return this;
  22228. }
  22229. } );
  22230. /**
  22231. * @author mrdoob / http://mrdoob.com/
  22232. */
  22233. function PointLight( color, intensity, distance, decay ) {
  22234. Light.call( this, color, intensity );
  22235. this.type = 'PointLight';
  22236. Object.defineProperty( this, 'power', {
  22237. get: function () {
  22238. // intensity = power per solid angle.
  22239. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22240. return this.intensity * 4 * Math.PI;
  22241. },
  22242. set: function ( power ) {
  22243. // intensity = power per solid angle.
  22244. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22245. this.intensity = power / ( 4 * Math.PI );
  22246. }
  22247. } );
  22248. this.distance = ( distance !== undefined ) ? distance : 0;
  22249. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22250. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22251. }
  22252. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22253. constructor: PointLight,
  22254. isPointLight: true,
  22255. copy: function ( source ) {
  22256. Light.prototype.copy.call( this, source );
  22257. this.distance = source.distance;
  22258. this.decay = source.decay;
  22259. this.shadow = source.shadow.clone();
  22260. return this;
  22261. }
  22262. } );
  22263. /**
  22264. * @author alteredq / http://alteredqualia.com/
  22265. * @author arose / http://github.com/arose
  22266. */
  22267. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22268. Camera.call( this );
  22269. this.type = 'OrthographicCamera';
  22270. this.zoom = 1;
  22271. this.view = null;
  22272. this.left = ( left !== undefined ) ? left : - 1;
  22273. this.right = ( right !== undefined ) ? right : 1;
  22274. this.top = ( top !== undefined ) ? top : 1;
  22275. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22276. this.near = ( near !== undefined ) ? near : 0.1;
  22277. this.far = ( far !== undefined ) ? far : 2000;
  22278. this.updateProjectionMatrix();
  22279. }
  22280. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22281. constructor: OrthographicCamera,
  22282. isOrthographicCamera: true,
  22283. copy: function ( source, recursive ) {
  22284. Camera.prototype.copy.call( this, source, recursive );
  22285. this.left = source.left;
  22286. this.right = source.right;
  22287. this.top = source.top;
  22288. this.bottom = source.bottom;
  22289. this.near = source.near;
  22290. this.far = source.far;
  22291. this.zoom = source.zoom;
  22292. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22293. return this;
  22294. },
  22295. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22296. if ( this.view === null ) {
  22297. this.view = {
  22298. enabled: true,
  22299. fullWidth: 1,
  22300. fullHeight: 1,
  22301. offsetX: 0,
  22302. offsetY: 0,
  22303. width: 1,
  22304. height: 1
  22305. };
  22306. }
  22307. this.view.enabled = true;
  22308. this.view.fullWidth = fullWidth;
  22309. this.view.fullHeight = fullHeight;
  22310. this.view.offsetX = x;
  22311. this.view.offsetY = y;
  22312. this.view.width = width;
  22313. this.view.height = height;
  22314. this.updateProjectionMatrix();
  22315. },
  22316. clearViewOffset: function () {
  22317. if ( this.view !== null ) {
  22318. this.view.enabled = false;
  22319. }
  22320. this.updateProjectionMatrix();
  22321. },
  22322. updateProjectionMatrix: function () {
  22323. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22324. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22325. var cx = ( this.right + this.left ) / 2;
  22326. var cy = ( this.top + this.bottom ) / 2;
  22327. var left = cx - dx;
  22328. var right = cx + dx;
  22329. var top = cy + dy;
  22330. var bottom = cy - dy;
  22331. if ( this.view !== null && this.view.enabled ) {
  22332. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22333. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22334. var scaleW = ( this.right - this.left ) / this.view.width;
  22335. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22336. left += scaleW * ( this.view.offsetX / zoomW );
  22337. right = left + scaleW * ( this.view.width / zoomW );
  22338. top -= scaleH * ( this.view.offsetY / zoomH );
  22339. bottom = top - scaleH * ( this.view.height / zoomH );
  22340. }
  22341. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22342. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22343. },
  22344. toJSON: function ( meta ) {
  22345. var data = Object3D.prototype.toJSON.call( this, meta );
  22346. data.object.zoom = this.zoom;
  22347. data.object.left = this.left;
  22348. data.object.right = this.right;
  22349. data.object.top = this.top;
  22350. data.object.bottom = this.bottom;
  22351. data.object.near = this.near;
  22352. data.object.far = this.far;
  22353. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22354. return data;
  22355. }
  22356. } );
  22357. /**
  22358. * @author mrdoob / http://mrdoob.com/
  22359. */
  22360. function DirectionalLightShadow( ) {
  22361. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22362. }
  22363. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22364. constructor: DirectionalLightShadow
  22365. } );
  22366. /**
  22367. * @author mrdoob / http://mrdoob.com/
  22368. * @author alteredq / http://alteredqualia.com/
  22369. */
  22370. function DirectionalLight( color, intensity ) {
  22371. Light.call( this, color, intensity );
  22372. this.type = 'DirectionalLight';
  22373. this.position.copy( Object3D.DefaultUp );
  22374. this.updateMatrix();
  22375. this.target = new Object3D();
  22376. this.shadow = new DirectionalLightShadow();
  22377. }
  22378. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22379. constructor: DirectionalLight,
  22380. isDirectionalLight: true,
  22381. copy: function ( source ) {
  22382. Light.prototype.copy.call( this, source );
  22383. this.target = source.target.clone();
  22384. this.shadow = source.shadow.clone();
  22385. return this;
  22386. }
  22387. } );
  22388. /**
  22389. * @author mrdoob / http://mrdoob.com/
  22390. */
  22391. function AmbientLight( color, intensity ) {
  22392. Light.call( this, color, intensity );
  22393. this.type = 'AmbientLight';
  22394. this.castShadow = undefined;
  22395. }
  22396. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22397. constructor: AmbientLight,
  22398. isAmbientLight: true
  22399. } );
  22400. /**
  22401. * @author abelnation / http://github.com/abelnation
  22402. */
  22403. function RectAreaLight( color, intensity, width, height ) {
  22404. Light.call( this, color, intensity );
  22405. this.type = 'RectAreaLight';
  22406. this.width = ( width !== undefined ) ? width : 10;
  22407. this.height = ( height !== undefined ) ? height : 10;
  22408. }
  22409. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22410. constructor: RectAreaLight,
  22411. isRectAreaLight: true,
  22412. copy: function ( source ) {
  22413. Light.prototype.copy.call( this, source );
  22414. this.width = source.width;
  22415. this.height = source.height;
  22416. return this;
  22417. },
  22418. toJSON: function ( meta ) {
  22419. var data = Light.prototype.toJSON.call( this, meta );
  22420. data.object.width = this.width;
  22421. data.object.height = this.height;
  22422. return data;
  22423. }
  22424. } );
  22425. /**
  22426. * @author mrdoob / http://mrdoob.com/
  22427. */
  22428. function MaterialLoader( manager ) {
  22429. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22430. this.textures = {};
  22431. }
  22432. Object.assign( MaterialLoader.prototype, {
  22433. load: function ( url, onLoad, onProgress, onError ) {
  22434. var scope = this;
  22435. var loader = new FileLoader( scope.manager );
  22436. loader.setPath( scope.path );
  22437. loader.load( url, function ( text ) {
  22438. onLoad( scope.parse( JSON.parse( text ) ) );
  22439. }, onProgress, onError );
  22440. },
  22441. parse: function ( json ) {
  22442. var textures = this.textures;
  22443. function getTexture( name ) {
  22444. if ( textures[ name ] === undefined ) {
  22445. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22446. }
  22447. return textures[ name ];
  22448. }
  22449. var material = new Materials[ json.type ]();
  22450. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22451. if ( json.name !== undefined ) material.name = json.name;
  22452. if ( json.color !== undefined ) material.color.setHex( json.color );
  22453. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22454. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22455. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22456. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22457. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22458. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22459. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22460. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22461. if ( json.fog !== undefined ) material.fog = json.fog;
  22462. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22463. if ( json.blending !== undefined ) material.blending = json.blending;
  22464. if ( json.combine !== undefined ) material.combine = json.combine;
  22465. if ( json.side !== undefined ) material.side = json.side;
  22466. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22467. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22468. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22469. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22470. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22471. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22472. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22473. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22474. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22475. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22476. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22477. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22478. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22479. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22480. if ( json.scale !== undefined ) material.scale = json.scale;
  22481. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22482. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22483. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22484. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22485. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22486. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22487. if ( json.visible !== undefined ) material.visible = json.visible;
  22488. if ( json.userData !== undefined ) material.userData = json.userData;
  22489. // Shader Material
  22490. if ( json.uniforms !== undefined ) {
  22491. for ( var name in json.uniforms ) {
  22492. var uniform = json.uniforms[ name ];
  22493. material.uniforms[ name ] = {};
  22494. switch ( uniform.type ) {
  22495. case 't':
  22496. material.uniforms[ name ].value = getTexture( uniform.value );
  22497. break;
  22498. case 'c':
  22499. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22500. break;
  22501. case 'v2':
  22502. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22503. break;
  22504. case 'v3':
  22505. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22506. break;
  22507. case 'v4':
  22508. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22509. break;
  22510. case 'm3':
  22511. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22512. case 'm4':
  22513. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22514. break;
  22515. default:
  22516. material.uniforms[ name ].value = uniform.value;
  22517. }
  22518. }
  22519. }
  22520. if ( json.defines !== undefined ) material.defines = json.defines;
  22521. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22522. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22523. if ( json.extensions !== undefined ) {
  22524. for ( var key in json.extensions ) {
  22525. material.extensions[ key ] = json.extensions[ key ];
  22526. }
  22527. }
  22528. // Deprecated
  22529. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22530. // for PointsMaterial
  22531. if ( json.size !== undefined ) material.size = json.size;
  22532. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22533. // maps
  22534. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22535. if ( json.alphaMap !== undefined ) {
  22536. material.alphaMap = getTexture( json.alphaMap );
  22537. material.transparent = true;
  22538. }
  22539. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22540. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22541. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22542. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22543. if ( json.normalScale !== undefined ) {
  22544. var normalScale = json.normalScale;
  22545. if ( Array.isArray( normalScale ) === false ) {
  22546. // Blender exporter used to export a scalar. See #7459
  22547. normalScale = [ normalScale, normalScale ];
  22548. }
  22549. material.normalScale = new Vector2().fromArray( normalScale );
  22550. }
  22551. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22552. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22553. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22554. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22555. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22556. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22557. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22558. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22559. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22560. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22561. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22562. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22563. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22564. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22565. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22566. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22567. return material;
  22568. },
  22569. setPath: function ( value ) {
  22570. this.path = value;
  22571. return this;
  22572. },
  22573. setTextures: function ( value ) {
  22574. this.textures = value;
  22575. return this;
  22576. }
  22577. } );
  22578. /**
  22579. * @author Don McCurdy / https://www.donmccurdy.com
  22580. */
  22581. var LoaderUtils = {
  22582. decodeText: function ( array ) {
  22583. if ( typeof TextDecoder !== 'undefined' ) {
  22584. return new TextDecoder().decode( array );
  22585. }
  22586. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22587. // throws a "maximum call stack size exceeded" error for large arrays.
  22588. var s = '';
  22589. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22590. // Implicitly assumes little-endian.
  22591. s += String.fromCharCode( array[ i ] );
  22592. }
  22593. // Merges multi-byte utf-8 characters.
  22594. return decodeURIComponent( escape( s ) );
  22595. },
  22596. extractUrlBase: function ( url ) {
  22597. var index = url.lastIndexOf( '/' );
  22598. if ( index === - 1 ) return './';
  22599. return url.substr( 0, index + 1 );
  22600. }
  22601. };
  22602. /**
  22603. * @author mrdoob / http://mrdoob.com/
  22604. */
  22605. function BufferGeometryLoader( manager ) {
  22606. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22607. }
  22608. Object.assign( BufferGeometryLoader.prototype, {
  22609. load: function ( url, onLoad, onProgress, onError ) {
  22610. var scope = this;
  22611. var loader = new FileLoader( scope.manager );
  22612. loader.setPath( scope.path );
  22613. loader.load( url, function ( text ) {
  22614. onLoad( scope.parse( JSON.parse( text ) ) );
  22615. }, onProgress, onError );
  22616. },
  22617. parse: function ( json ) {
  22618. var geometry = new BufferGeometry();
  22619. var index = json.data.index;
  22620. if ( index !== undefined ) {
  22621. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  22622. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22623. }
  22624. var attributes = json.data.attributes;
  22625. for ( var key in attributes ) {
  22626. var attribute = attributes[ key ];
  22627. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22628. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22629. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22630. geometry.addAttribute( key, bufferAttribute );
  22631. }
  22632. var morphAttributes = json.data.morphAttributes;
  22633. if ( morphAttributes ) {
  22634. for ( var key in morphAttributes ) {
  22635. var attributeArray = morphAttributes[ key ];
  22636. var array = [];
  22637. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  22638. var attribute = attributeArray[ i ];
  22639. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22640. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22641. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22642. array.push( bufferAttribute );
  22643. }
  22644. geometry.morphAttributes[ key ] = array;
  22645. }
  22646. }
  22647. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22648. if ( groups !== undefined ) {
  22649. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  22650. var group = groups[ i ];
  22651. geometry.addGroup( group.start, group.count, group.materialIndex );
  22652. }
  22653. }
  22654. var boundingSphere = json.data.boundingSphere;
  22655. if ( boundingSphere !== undefined ) {
  22656. var center = new Vector3();
  22657. if ( boundingSphere.center !== undefined ) {
  22658. center.fromArray( boundingSphere.center );
  22659. }
  22660. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22661. }
  22662. if ( json.name ) geometry.name = json.name;
  22663. if ( json.userData ) geometry.userData = json.userData;
  22664. return geometry;
  22665. },
  22666. setPath: function ( value ) {
  22667. this.path = value;
  22668. return this;
  22669. }
  22670. } );
  22671. var TYPED_ARRAYS = {
  22672. Int8Array: Int8Array,
  22673. Uint8Array: Uint8Array,
  22674. // Workaround for IE11 pre KB2929437. See #11440
  22675. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  22676. Int16Array: Int16Array,
  22677. Uint16Array: Uint16Array,
  22678. Int32Array: Int32Array,
  22679. Uint32Array: Uint32Array,
  22680. Float32Array: Float32Array,
  22681. Float64Array: Float64Array
  22682. };
  22683. /**
  22684. * @author mrdoob / http://mrdoob.com/
  22685. */
  22686. function ObjectLoader( manager ) {
  22687. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22688. this.resourcePath = '';
  22689. }
  22690. Object.assign( ObjectLoader.prototype, {
  22691. crossOrigin: 'anonymous',
  22692. load: function ( url, onLoad, onProgress, onError ) {
  22693. var scope = this;
  22694. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22695. this.resourcePath = this.resourcePath || path;
  22696. var loader = new FileLoader( scope.manager );
  22697. loader.setPath( this.path );
  22698. loader.load( url, function ( text ) {
  22699. var json = null;
  22700. try {
  22701. json = JSON.parse( text );
  22702. } catch ( error ) {
  22703. if ( onError !== undefined ) onError( error );
  22704. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22705. return;
  22706. }
  22707. var metadata = json.metadata;
  22708. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22709. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22710. return;
  22711. }
  22712. scope.parse( json, onLoad );
  22713. }, onProgress, onError );
  22714. },
  22715. setPath: function ( value ) {
  22716. this.path = value;
  22717. return this;
  22718. },
  22719. setResourcePath: function ( value ) {
  22720. this.resourcePath = value;
  22721. return this;
  22722. },
  22723. setCrossOrigin: function ( value ) {
  22724. this.crossOrigin = value;
  22725. return this;
  22726. },
  22727. parse: function ( json, onLoad ) {
  22728. var shapes = this.parseShape( json.shapes );
  22729. var geometries = this.parseGeometries( json.geometries, shapes );
  22730. var images = this.parseImages( json.images, function () {
  22731. if ( onLoad !== undefined ) onLoad( object );
  22732. } );
  22733. var textures = this.parseTextures( json.textures, images );
  22734. var materials = this.parseMaterials( json.materials, textures );
  22735. var object = this.parseObject( json.object, geometries, materials );
  22736. if ( json.animations ) {
  22737. object.animations = this.parseAnimations( json.animations );
  22738. }
  22739. if ( json.images === undefined || json.images.length === 0 ) {
  22740. if ( onLoad !== undefined ) onLoad( object );
  22741. }
  22742. return object;
  22743. },
  22744. parseShape: function ( json ) {
  22745. var shapes = {};
  22746. if ( json !== undefined ) {
  22747. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22748. var shape = new Shape().fromJSON( json[ i ] );
  22749. shapes[ shape.uuid ] = shape;
  22750. }
  22751. }
  22752. return shapes;
  22753. },
  22754. parseGeometries: function ( json, shapes ) {
  22755. var geometries = {};
  22756. if ( json !== undefined ) {
  22757. var bufferGeometryLoader = new BufferGeometryLoader();
  22758. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22759. var geometry;
  22760. var data = json[ i ];
  22761. switch ( data.type ) {
  22762. case 'PlaneGeometry':
  22763. case 'PlaneBufferGeometry':
  22764. geometry = new Geometries[ data.type ](
  22765. data.width,
  22766. data.height,
  22767. data.widthSegments,
  22768. data.heightSegments
  22769. );
  22770. break;
  22771. case 'BoxGeometry':
  22772. case 'BoxBufferGeometry':
  22773. case 'CubeGeometry': // backwards compatible
  22774. geometry = new Geometries[ data.type ](
  22775. data.width,
  22776. data.height,
  22777. data.depth,
  22778. data.widthSegments,
  22779. data.heightSegments,
  22780. data.depthSegments
  22781. );
  22782. break;
  22783. case 'CircleGeometry':
  22784. case 'CircleBufferGeometry':
  22785. geometry = new Geometries[ data.type ](
  22786. data.radius,
  22787. data.segments,
  22788. data.thetaStart,
  22789. data.thetaLength
  22790. );
  22791. break;
  22792. case 'CylinderGeometry':
  22793. case 'CylinderBufferGeometry':
  22794. geometry = new Geometries[ data.type ](
  22795. data.radiusTop,
  22796. data.radiusBottom,
  22797. data.height,
  22798. data.radialSegments,
  22799. data.heightSegments,
  22800. data.openEnded,
  22801. data.thetaStart,
  22802. data.thetaLength
  22803. );
  22804. break;
  22805. case 'ConeGeometry':
  22806. case 'ConeBufferGeometry':
  22807. geometry = new Geometries[ data.type ](
  22808. data.radius,
  22809. data.height,
  22810. data.radialSegments,
  22811. data.heightSegments,
  22812. data.openEnded,
  22813. data.thetaStart,
  22814. data.thetaLength
  22815. );
  22816. break;
  22817. case 'SphereGeometry':
  22818. case 'SphereBufferGeometry':
  22819. geometry = new Geometries[ data.type ](
  22820. data.radius,
  22821. data.widthSegments,
  22822. data.heightSegments,
  22823. data.phiStart,
  22824. data.phiLength,
  22825. data.thetaStart,
  22826. data.thetaLength
  22827. );
  22828. break;
  22829. case 'DodecahedronGeometry':
  22830. case 'DodecahedronBufferGeometry':
  22831. case 'IcosahedronGeometry':
  22832. case 'IcosahedronBufferGeometry':
  22833. case 'OctahedronGeometry':
  22834. case 'OctahedronBufferGeometry':
  22835. case 'TetrahedronGeometry':
  22836. case 'TetrahedronBufferGeometry':
  22837. geometry = new Geometries[ data.type ](
  22838. data.radius,
  22839. data.detail
  22840. );
  22841. break;
  22842. case 'RingGeometry':
  22843. case 'RingBufferGeometry':
  22844. geometry = new Geometries[ data.type ](
  22845. data.innerRadius,
  22846. data.outerRadius,
  22847. data.thetaSegments,
  22848. data.phiSegments,
  22849. data.thetaStart,
  22850. data.thetaLength
  22851. );
  22852. break;
  22853. case 'TorusGeometry':
  22854. case 'TorusBufferGeometry':
  22855. geometry = new Geometries[ data.type ](
  22856. data.radius,
  22857. data.tube,
  22858. data.radialSegments,
  22859. data.tubularSegments,
  22860. data.arc
  22861. );
  22862. break;
  22863. case 'TorusKnotGeometry':
  22864. case 'TorusKnotBufferGeometry':
  22865. geometry = new Geometries[ data.type ](
  22866. data.radius,
  22867. data.tube,
  22868. data.tubularSegments,
  22869. data.radialSegments,
  22870. data.p,
  22871. data.q
  22872. );
  22873. break;
  22874. case 'TubeGeometry':
  22875. case 'TubeBufferGeometry':
  22876. // This only works for built-in curves (e.g. CatmullRomCurve3).
  22877. // User defined curves or instances of CurvePath will not be deserialized.
  22878. geometry = new Geometries[ data.type ](
  22879. new Curves[ data.path.type ]().fromJSON( data.path ),
  22880. data.tubularSegments,
  22881. data.radius,
  22882. data.radialSegments,
  22883. data.closed
  22884. );
  22885. break;
  22886. case 'LatheGeometry':
  22887. case 'LatheBufferGeometry':
  22888. geometry = new Geometries[ data.type ](
  22889. data.points,
  22890. data.segments,
  22891. data.phiStart,
  22892. data.phiLength
  22893. );
  22894. break;
  22895. case 'PolyhedronGeometry':
  22896. case 'PolyhedronBufferGeometry':
  22897. geometry = new Geometries[ data.type ](
  22898. data.vertices,
  22899. data.indices,
  22900. data.radius,
  22901. data.details
  22902. );
  22903. break;
  22904. case 'ShapeGeometry':
  22905. case 'ShapeBufferGeometry':
  22906. var geometryShapes = [];
  22907. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22908. var shape = shapes[ data.shapes[ j ] ];
  22909. geometryShapes.push( shape );
  22910. }
  22911. geometry = new Geometries[ data.type ](
  22912. geometryShapes,
  22913. data.curveSegments
  22914. );
  22915. break;
  22916. case 'ExtrudeGeometry':
  22917. case 'ExtrudeBufferGeometry':
  22918. var geometryShapes = [];
  22919. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22920. var shape = shapes[ data.shapes[ j ] ];
  22921. geometryShapes.push( shape );
  22922. }
  22923. var extrudePath = data.options.extrudePath;
  22924. if ( extrudePath !== undefined ) {
  22925. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  22926. }
  22927. geometry = new Geometries[ data.type ](
  22928. geometryShapes,
  22929. data.options
  22930. );
  22931. break;
  22932. case 'BufferGeometry':
  22933. geometry = bufferGeometryLoader.parse( data );
  22934. break;
  22935. case 'Geometry':
  22936. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  22937. var geometryLoader = new THREE.LegacyJSONLoader();
  22938. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  22939. } else {
  22940. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  22941. }
  22942. break;
  22943. default:
  22944. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  22945. continue;
  22946. }
  22947. geometry.uuid = data.uuid;
  22948. if ( data.name !== undefined ) geometry.name = data.name;
  22949. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  22950. geometries[ data.uuid ] = geometry;
  22951. }
  22952. }
  22953. return geometries;
  22954. },
  22955. parseMaterials: function ( json, textures ) {
  22956. var cache = {}; // MultiMaterial
  22957. var materials = {};
  22958. if ( json !== undefined ) {
  22959. var loader = new MaterialLoader();
  22960. loader.setTextures( textures );
  22961. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22962. var data = json[ i ];
  22963. if ( data.type === 'MultiMaterial' ) {
  22964. // Deprecated
  22965. var array = [];
  22966. for ( var j = 0; j < data.materials.length; j ++ ) {
  22967. var material = data.materials[ j ];
  22968. if ( cache[ material.uuid ] === undefined ) {
  22969. cache[ material.uuid ] = loader.parse( material );
  22970. }
  22971. array.push( cache[ material.uuid ] );
  22972. }
  22973. materials[ data.uuid ] = array;
  22974. } else {
  22975. if ( cache[ data.uuid ] === undefined ) {
  22976. cache[ data.uuid ] = loader.parse( data );
  22977. }
  22978. materials[ data.uuid ] = cache[ data.uuid ];
  22979. }
  22980. }
  22981. }
  22982. return materials;
  22983. },
  22984. parseAnimations: function ( json ) {
  22985. var animations = [];
  22986. for ( var i = 0; i < json.length; i ++ ) {
  22987. var data = json[ i ];
  22988. var clip = AnimationClip.parse( data );
  22989. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  22990. animations.push( clip );
  22991. }
  22992. return animations;
  22993. },
  22994. parseImages: function ( json, onLoad ) {
  22995. var scope = this;
  22996. var images = {};
  22997. function loadImage( url ) {
  22998. scope.manager.itemStart( url );
  22999. return loader.load( url, function () {
  23000. scope.manager.itemEnd( url );
  23001. }, undefined, function () {
  23002. scope.manager.itemError( url );
  23003. scope.manager.itemEnd( url );
  23004. } );
  23005. }
  23006. if ( json !== undefined && json.length > 0 ) {
  23007. var manager = new LoadingManager( onLoad );
  23008. var loader = new ImageLoader( manager );
  23009. loader.setCrossOrigin( this.crossOrigin );
  23010. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23011. var image = json[ i ];
  23012. var url = image.url;
  23013. if ( Array.isArray( url ) ) {
  23014. // load array of images e.g CubeTexture
  23015. images[ image.uuid ] = [];
  23016. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23017. var currentUrl = url[ j ];
  23018. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23019. images[ image.uuid ].push( loadImage( path ) );
  23020. }
  23021. } else {
  23022. // load single image
  23023. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23024. images[ image.uuid ] = loadImage( path );
  23025. }
  23026. }
  23027. }
  23028. return images;
  23029. },
  23030. parseTextures: function ( json, images ) {
  23031. function parseConstant( value, type ) {
  23032. if ( typeof value === 'number' ) return value;
  23033. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23034. return type[ value ];
  23035. }
  23036. var textures = {};
  23037. if ( json !== undefined ) {
  23038. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23039. var data = json[ i ];
  23040. if ( data.image === undefined ) {
  23041. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23042. }
  23043. if ( images[ data.image ] === undefined ) {
  23044. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23045. }
  23046. var texture;
  23047. if ( Array.isArray( images[ data.image ] ) ) {
  23048. texture = new CubeTexture( images[ data.image ] );
  23049. } else {
  23050. texture = new Texture( images[ data.image ] );
  23051. }
  23052. texture.needsUpdate = true;
  23053. texture.uuid = data.uuid;
  23054. if ( data.name !== undefined ) texture.name = data.name;
  23055. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23056. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23057. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23058. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23059. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23060. if ( data.wrap !== undefined ) {
  23061. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23062. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23063. }
  23064. if ( data.format !== undefined ) texture.format = data.format;
  23065. if ( data.type !== undefined ) texture.type = data.type;
  23066. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23067. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23068. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23069. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23070. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23071. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23072. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23073. textures[ data.uuid ] = texture;
  23074. }
  23075. }
  23076. return textures;
  23077. },
  23078. parseObject: function ( data, geometries, materials ) {
  23079. var object;
  23080. function getGeometry( name ) {
  23081. if ( geometries[ name ] === undefined ) {
  23082. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23083. }
  23084. return geometries[ name ];
  23085. }
  23086. function getMaterial( name ) {
  23087. if ( name === undefined ) return undefined;
  23088. if ( Array.isArray( name ) ) {
  23089. var array = [];
  23090. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23091. var uuid = name[ i ];
  23092. if ( materials[ uuid ] === undefined ) {
  23093. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23094. }
  23095. array.push( materials[ uuid ] );
  23096. }
  23097. return array;
  23098. }
  23099. if ( materials[ name ] === undefined ) {
  23100. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23101. }
  23102. return materials[ name ];
  23103. }
  23104. switch ( data.type ) {
  23105. case 'Scene':
  23106. object = new Scene();
  23107. if ( data.background !== undefined ) {
  23108. if ( Number.isInteger( data.background ) ) {
  23109. object.background = new Color( data.background );
  23110. }
  23111. }
  23112. if ( data.fog !== undefined ) {
  23113. if ( data.fog.type === 'Fog' ) {
  23114. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23115. } else if ( data.fog.type === 'FogExp2' ) {
  23116. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23117. }
  23118. }
  23119. break;
  23120. case 'PerspectiveCamera':
  23121. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23122. if ( data.focus !== undefined ) object.focus = data.focus;
  23123. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23124. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23125. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23126. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23127. break;
  23128. case 'OrthographicCamera':
  23129. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23130. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23131. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23132. break;
  23133. case 'AmbientLight':
  23134. object = new AmbientLight( data.color, data.intensity );
  23135. break;
  23136. case 'DirectionalLight':
  23137. object = new DirectionalLight( data.color, data.intensity );
  23138. break;
  23139. case 'PointLight':
  23140. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23141. break;
  23142. case 'RectAreaLight':
  23143. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23144. break;
  23145. case 'SpotLight':
  23146. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23147. break;
  23148. case 'HemisphereLight':
  23149. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23150. break;
  23151. case 'SkinnedMesh':
  23152. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23153. case 'Mesh':
  23154. var geometry = getGeometry( data.geometry );
  23155. var material = getMaterial( data.material );
  23156. if ( geometry.bones && geometry.bones.length > 0 ) {
  23157. object = new SkinnedMesh( geometry, material );
  23158. } else {
  23159. object = new Mesh( geometry, material );
  23160. }
  23161. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23162. break;
  23163. case 'LOD':
  23164. object = new LOD();
  23165. break;
  23166. case 'Line':
  23167. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23168. break;
  23169. case 'LineLoop':
  23170. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23171. break;
  23172. case 'LineSegments':
  23173. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23174. break;
  23175. case 'PointCloud':
  23176. case 'Points':
  23177. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23178. break;
  23179. case 'Sprite':
  23180. object = new Sprite( getMaterial( data.material ) );
  23181. break;
  23182. case 'Group':
  23183. object = new Group();
  23184. break;
  23185. default:
  23186. object = new Object3D();
  23187. }
  23188. object.uuid = data.uuid;
  23189. if ( data.name !== undefined ) object.name = data.name;
  23190. if ( data.matrix !== undefined ) {
  23191. object.matrix.fromArray( data.matrix );
  23192. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23193. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23194. } else {
  23195. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23196. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23197. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23198. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23199. }
  23200. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23201. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23202. if ( data.shadow ) {
  23203. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23204. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23205. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23206. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23207. }
  23208. if ( data.visible !== undefined ) object.visible = data.visible;
  23209. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23210. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23211. if ( data.userData !== undefined ) object.userData = data.userData;
  23212. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23213. if ( data.children !== undefined ) {
  23214. var children = data.children;
  23215. for ( var i = 0; i < children.length; i ++ ) {
  23216. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23217. }
  23218. }
  23219. if ( data.type === 'LOD' ) {
  23220. var levels = data.levels;
  23221. for ( var l = 0; l < levels.length; l ++ ) {
  23222. var level = levels[ l ];
  23223. var child = object.getObjectByProperty( 'uuid', level.object );
  23224. if ( child !== undefined ) {
  23225. object.addLevel( child, level.distance );
  23226. }
  23227. }
  23228. }
  23229. return object;
  23230. }
  23231. } );
  23232. var TEXTURE_MAPPING = {
  23233. UVMapping: UVMapping,
  23234. CubeReflectionMapping: CubeReflectionMapping,
  23235. CubeRefractionMapping: CubeRefractionMapping,
  23236. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23237. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23238. SphericalReflectionMapping: SphericalReflectionMapping,
  23239. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23240. CubeUVRefractionMapping: CubeUVRefractionMapping
  23241. };
  23242. var TEXTURE_WRAPPING = {
  23243. RepeatWrapping: RepeatWrapping,
  23244. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23245. MirroredRepeatWrapping: MirroredRepeatWrapping
  23246. };
  23247. var TEXTURE_FILTER = {
  23248. NearestFilter: NearestFilter,
  23249. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  23250. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  23251. LinearFilter: LinearFilter,
  23252. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  23253. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  23254. };
  23255. /**
  23256. * @author thespite / http://clicktorelease.com/
  23257. */
  23258. function ImageBitmapLoader( manager ) {
  23259. if ( typeof createImageBitmap === 'undefined' ) {
  23260. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23261. }
  23262. if ( typeof fetch === 'undefined' ) {
  23263. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23264. }
  23265. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23266. this.options = undefined;
  23267. }
  23268. ImageBitmapLoader.prototype = {
  23269. constructor: ImageBitmapLoader,
  23270. setOptions: function setOptions( options ) {
  23271. this.options = options;
  23272. return this;
  23273. },
  23274. load: function ( url, onLoad, onProgress, onError ) {
  23275. if ( url === undefined ) url = '';
  23276. if ( this.path !== undefined ) url = this.path + url;
  23277. url = this.manager.resolveURL( url );
  23278. var scope = this;
  23279. var cached = Cache.get( url );
  23280. if ( cached !== undefined ) {
  23281. scope.manager.itemStart( url );
  23282. setTimeout( function () {
  23283. if ( onLoad ) onLoad( cached );
  23284. scope.manager.itemEnd( url );
  23285. }, 0 );
  23286. return cached;
  23287. }
  23288. fetch( url ).then( function ( res ) {
  23289. return res.blob();
  23290. } ).then( function ( blob ) {
  23291. return createImageBitmap( blob, scope.options );
  23292. } ).then( function ( imageBitmap ) {
  23293. Cache.add( url, imageBitmap );
  23294. if ( onLoad ) onLoad( imageBitmap );
  23295. scope.manager.itemEnd( url );
  23296. } ).catch( function ( e ) {
  23297. if ( onError ) onError( e );
  23298. scope.manager.itemError( url );
  23299. scope.manager.itemEnd( url );
  23300. } );
  23301. scope.manager.itemStart( url );
  23302. },
  23303. setCrossOrigin: function ( /* value */ ) {
  23304. return this;
  23305. },
  23306. setPath: function ( value ) {
  23307. this.path = value;
  23308. return this;
  23309. }
  23310. };
  23311. /**
  23312. * @author zz85 / http://www.lab4games.net/zz85/blog
  23313. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23314. **/
  23315. function ShapePath() {
  23316. this.type = 'ShapePath';
  23317. this.color = new Color();
  23318. this.subPaths = [];
  23319. this.currentPath = null;
  23320. }
  23321. Object.assign( ShapePath.prototype, {
  23322. moveTo: function ( x, y ) {
  23323. this.currentPath = new Path();
  23324. this.subPaths.push( this.currentPath );
  23325. this.currentPath.moveTo( x, y );
  23326. },
  23327. lineTo: function ( x, y ) {
  23328. this.currentPath.lineTo( x, y );
  23329. },
  23330. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23331. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23332. },
  23333. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23334. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23335. },
  23336. splineThru: function ( pts ) {
  23337. this.currentPath.splineThru( pts );
  23338. },
  23339. toShapes: function ( isCCW, noHoles ) {
  23340. function toShapesNoHoles( inSubpaths ) {
  23341. var shapes = [];
  23342. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23343. var tmpPath = inSubpaths[ i ];
  23344. var tmpShape = new Shape();
  23345. tmpShape.curves = tmpPath.curves;
  23346. shapes.push( tmpShape );
  23347. }
  23348. return shapes;
  23349. }
  23350. function isPointInsidePolygon( inPt, inPolygon ) {
  23351. var polyLen = inPolygon.length;
  23352. // inPt on polygon contour => immediate success or
  23353. // toggling of inside/outside at every single! intersection point of an edge
  23354. // with the horizontal line through inPt, left of inPt
  23355. // not counting lowerY endpoints of edges and whole edges on that line
  23356. var inside = false;
  23357. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23358. var edgeLowPt = inPolygon[ p ];
  23359. var edgeHighPt = inPolygon[ q ];
  23360. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23361. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23362. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23363. // not parallel
  23364. if ( edgeDy < 0 ) {
  23365. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23366. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23367. }
  23368. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23369. if ( inPt.y === edgeLowPt.y ) {
  23370. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23371. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23372. } else {
  23373. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23374. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23375. if ( perpEdge < 0 ) continue;
  23376. inside = ! inside; // true intersection left of inPt
  23377. }
  23378. } else {
  23379. // parallel or collinear
  23380. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23381. // edge lies on the same horizontal line as inPt
  23382. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23383. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23384. // continue;
  23385. }
  23386. }
  23387. return inside;
  23388. }
  23389. var isClockWise = ShapeUtils.isClockWise;
  23390. var subPaths = this.subPaths;
  23391. if ( subPaths.length === 0 ) return [];
  23392. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23393. var solid, tmpPath, tmpShape, shapes = [];
  23394. if ( subPaths.length === 1 ) {
  23395. tmpPath = subPaths[ 0 ];
  23396. tmpShape = new Shape();
  23397. tmpShape.curves = tmpPath.curves;
  23398. shapes.push( tmpShape );
  23399. return shapes;
  23400. }
  23401. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23402. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23403. // console.log("Holes first", holesFirst);
  23404. var betterShapeHoles = [];
  23405. var newShapes = [];
  23406. var newShapeHoles = [];
  23407. var mainIdx = 0;
  23408. var tmpPoints;
  23409. newShapes[ mainIdx ] = undefined;
  23410. newShapeHoles[ mainIdx ] = [];
  23411. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23412. tmpPath = subPaths[ i ];
  23413. tmpPoints = tmpPath.getPoints();
  23414. solid = isClockWise( tmpPoints );
  23415. solid = isCCW ? ! solid : solid;
  23416. if ( solid ) {
  23417. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23418. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23419. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23420. if ( holesFirst ) mainIdx ++;
  23421. newShapeHoles[ mainIdx ] = [];
  23422. //console.log('cw', i);
  23423. } else {
  23424. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23425. //console.log('ccw', i);
  23426. }
  23427. }
  23428. // only Holes? -> probably all Shapes with wrong orientation
  23429. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23430. if ( newShapes.length > 1 ) {
  23431. var ambiguous = false;
  23432. var toChange = [];
  23433. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23434. betterShapeHoles[ sIdx ] = [];
  23435. }
  23436. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23437. var sho = newShapeHoles[ sIdx ];
  23438. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23439. var ho = sho[ hIdx ];
  23440. var hole_unassigned = true;
  23441. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23442. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23443. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23444. if ( hole_unassigned ) {
  23445. hole_unassigned = false;
  23446. betterShapeHoles[ s2Idx ].push( ho );
  23447. } else {
  23448. ambiguous = true;
  23449. }
  23450. }
  23451. }
  23452. if ( hole_unassigned ) {
  23453. betterShapeHoles[ sIdx ].push( ho );
  23454. }
  23455. }
  23456. }
  23457. // console.log("ambiguous: ", ambiguous);
  23458. if ( toChange.length > 0 ) {
  23459. // console.log("to change: ", toChange);
  23460. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23461. }
  23462. }
  23463. var tmpHoles;
  23464. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23465. tmpShape = newShapes[ i ].s;
  23466. shapes.push( tmpShape );
  23467. tmpHoles = newShapeHoles[ i ];
  23468. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23469. tmpShape.holes.push( tmpHoles[ j ].h );
  23470. }
  23471. }
  23472. //console.log("shape", shapes);
  23473. return shapes;
  23474. }
  23475. } );
  23476. /**
  23477. * @author zz85 / http://www.lab4games.net/zz85/blog
  23478. * @author mrdoob / http://mrdoob.com/
  23479. */
  23480. function Font( data ) {
  23481. this.type = 'Font';
  23482. this.data = data;
  23483. }
  23484. Object.assign( Font.prototype, {
  23485. isFont: true,
  23486. generateShapes: function ( text, size ) {
  23487. if ( size === undefined ) size = 100;
  23488. var shapes = [];
  23489. var paths = createPaths( text, size, this.data );
  23490. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23491. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23492. }
  23493. return shapes;
  23494. }
  23495. } );
  23496. function createPaths( text, size, data ) {
  23497. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23498. var scale = size / data.resolution;
  23499. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23500. var paths = [];
  23501. var offsetX = 0, offsetY = 0;
  23502. for ( var i = 0; i < chars.length; i ++ ) {
  23503. var char = chars[ i ];
  23504. if ( char === '\n' ) {
  23505. offsetX = 0;
  23506. offsetY -= line_height;
  23507. } else {
  23508. var ret = createPath( char, scale, offsetX, offsetY, data );
  23509. offsetX += ret.offsetX;
  23510. paths.push( ret.path );
  23511. }
  23512. }
  23513. return paths;
  23514. }
  23515. function createPath( char, scale, offsetX, offsetY, data ) {
  23516. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23517. if ( ! glyph ) return;
  23518. var path = new ShapePath();
  23519. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23520. if ( glyph.o ) {
  23521. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23522. for ( var i = 0, l = outline.length; i < l; ) {
  23523. var action = outline[ i ++ ];
  23524. switch ( action ) {
  23525. case 'm': // moveTo
  23526. x = outline[ i ++ ] * scale + offsetX;
  23527. y = outline[ i ++ ] * scale + offsetY;
  23528. path.moveTo( x, y );
  23529. break;
  23530. case 'l': // lineTo
  23531. x = outline[ i ++ ] * scale + offsetX;
  23532. y = outline[ i ++ ] * scale + offsetY;
  23533. path.lineTo( x, y );
  23534. break;
  23535. case 'q': // quadraticCurveTo
  23536. cpx = outline[ i ++ ] * scale + offsetX;
  23537. cpy = outline[ i ++ ] * scale + offsetY;
  23538. cpx1 = outline[ i ++ ] * scale + offsetX;
  23539. cpy1 = outline[ i ++ ] * scale + offsetY;
  23540. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23541. break;
  23542. case 'b': // bezierCurveTo
  23543. cpx = outline[ i ++ ] * scale + offsetX;
  23544. cpy = outline[ i ++ ] * scale + offsetY;
  23545. cpx1 = outline[ i ++ ] * scale + offsetX;
  23546. cpy1 = outline[ i ++ ] * scale + offsetY;
  23547. cpx2 = outline[ i ++ ] * scale + offsetX;
  23548. cpy2 = outline[ i ++ ] * scale + offsetY;
  23549. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23550. break;
  23551. }
  23552. }
  23553. }
  23554. return { offsetX: glyph.ha * scale, path: path };
  23555. }
  23556. /**
  23557. * @author mrdoob / http://mrdoob.com/
  23558. */
  23559. function FontLoader( manager ) {
  23560. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23561. }
  23562. Object.assign( FontLoader.prototype, {
  23563. load: function ( url, onLoad, onProgress, onError ) {
  23564. var scope = this;
  23565. var loader = new FileLoader( this.manager );
  23566. loader.setPath( this.path );
  23567. loader.load( url, function ( text ) {
  23568. var json;
  23569. try {
  23570. json = JSON.parse( text );
  23571. } catch ( e ) {
  23572. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23573. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23574. }
  23575. var font = scope.parse( json );
  23576. if ( onLoad ) onLoad( font );
  23577. }, onProgress, onError );
  23578. },
  23579. parse: function ( json ) {
  23580. return new Font( json );
  23581. },
  23582. setPath: function ( value ) {
  23583. this.path = value;
  23584. return this;
  23585. }
  23586. } );
  23587. /**
  23588. * @author alteredq / http://alteredqualia.com/
  23589. */
  23590. function Loader() {}
  23591. Loader.Handlers = {
  23592. handlers: [],
  23593. add: function ( regex, loader ) {
  23594. this.handlers.push( regex, loader );
  23595. },
  23596. get: function ( file ) {
  23597. var handlers = this.handlers;
  23598. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  23599. var regex = handlers[ i ];
  23600. var loader = handlers[ i + 1 ];
  23601. if ( regex.test( file ) ) {
  23602. return loader;
  23603. }
  23604. }
  23605. return null;
  23606. }
  23607. };
  23608. Object.assign( Loader.prototype, {
  23609. crossOrigin: 'anonymous',
  23610. onLoadStart: function () {},
  23611. onLoadProgress: function () {},
  23612. onLoadComplete: function () {},
  23613. initMaterials: function ( materials, texturePath, crossOrigin ) {
  23614. var array = [];
  23615. for ( var i = 0; i < materials.length; ++ i ) {
  23616. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  23617. }
  23618. return array;
  23619. },
  23620. createMaterial: ( function () {
  23621. var BlendingMode = {
  23622. NoBlending: NoBlending,
  23623. NormalBlending: NormalBlending,
  23624. AdditiveBlending: AdditiveBlending,
  23625. SubtractiveBlending: SubtractiveBlending,
  23626. MultiplyBlending: MultiplyBlending,
  23627. CustomBlending: CustomBlending
  23628. };
  23629. var color = new Color();
  23630. var textureLoader = new TextureLoader();
  23631. var materialLoader = new MaterialLoader();
  23632. return function createMaterial( m, texturePath, crossOrigin ) {
  23633. // convert from old material format
  23634. var textures = {};
  23635. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  23636. var fullPath = texturePath + path;
  23637. var loader = Loader.Handlers.get( fullPath );
  23638. var texture;
  23639. if ( loader !== null ) {
  23640. texture = loader.load( fullPath );
  23641. } else {
  23642. textureLoader.setCrossOrigin( crossOrigin );
  23643. texture = textureLoader.load( fullPath );
  23644. }
  23645. if ( repeat !== undefined ) {
  23646. texture.repeat.fromArray( repeat );
  23647. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  23648. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  23649. }
  23650. if ( offset !== undefined ) {
  23651. texture.offset.fromArray( offset );
  23652. }
  23653. if ( wrap !== undefined ) {
  23654. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  23655. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  23656. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  23657. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  23658. }
  23659. if ( anisotropy !== undefined ) {
  23660. texture.anisotropy = anisotropy;
  23661. }
  23662. var uuid = _Math.generateUUID();
  23663. textures[ uuid ] = texture;
  23664. return uuid;
  23665. }
  23666. //
  23667. var json = {
  23668. uuid: _Math.generateUUID(),
  23669. type: 'MeshLambertMaterial'
  23670. };
  23671. for ( var name in m ) {
  23672. var value = m[ name ];
  23673. switch ( name ) {
  23674. case 'DbgColor':
  23675. case 'DbgIndex':
  23676. case 'opticalDensity':
  23677. case 'illumination':
  23678. break;
  23679. case 'DbgName':
  23680. json.name = value;
  23681. break;
  23682. case 'blending':
  23683. json.blending = BlendingMode[ value ];
  23684. break;
  23685. case 'colorAmbient':
  23686. case 'mapAmbient':
  23687. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  23688. break;
  23689. case 'colorDiffuse':
  23690. json.color = color.fromArray( value ).getHex();
  23691. break;
  23692. case 'colorSpecular':
  23693. json.specular = color.fromArray( value ).getHex();
  23694. break;
  23695. case 'colorEmissive':
  23696. json.emissive = color.fromArray( value ).getHex();
  23697. break;
  23698. case 'specularCoef':
  23699. json.shininess = value;
  23700. break;
  23701. case 'shading':
  23702. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  23703. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  23704. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  23705. break;
  23706. case 'mapDiffuse':
  23707. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  23708. break;
  23709. case 'mapDiffuseRepeat':
  23710. case 'mapDiffuseOffset':
  23711. case 'mapDiffuseWrap':
  23712. case 'mapDiffuseAnisotropy':
  23713. break;
  23714. case 'mapEmissive':
  23715. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  23716. break;
  23717. case 'mapEmissiveRepeat':
  23718. case 'mapEmissiveOffset':
  23719. case 'mapEmissiveWrap':
  23720. case 'mapEmissiveAnisotropy':
  23721. break;
  23722. case 'mapLight':
  23723. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  23724. break;
  23725. case 'mapLightRepeat':
  23726. case 'mapLightOffset':
  23727. case 'mapLightWrap':
  23728. case 'mapLightAnisotropy':
  23729. break;
  23730. case 'mapAO':
  23731. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  23732. break;
  23733. case 'mapAORepeat':
  23734. case 'mapAOOffset':
  23735. case 'mapAOWrap':
  23736. case 'mapAOAnisotropy':
  23737. break;
  23738. case 'mapBump':
  23739. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  23740. break;
  23741. case 'mapBumpScale':
  23742. json.bumpScale = value;
  23743. break;
  23744. case 'mapBumpRepeat':
  23745. case 'mapBumpOffset':
  23746. case 'mapBumpWrap':
  23747. case 'mapBumpAnisotropy':
  23748. break;
  23749. case 'mapNormal':
  23750. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  23751. break;
  23752. case 'mapNormalFactor':
  23753. json.normalScale = value;
  23754. break;
  23755. case 'mapNormalRepeat':
  23756. case 'mapNormalOffset':
  23757. case 'mapNormalWrap':
  23758. case 'mapNormalAnisotropy':
  23759. break;
  23760. case 'mapSpecular':
  23761. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  23762. break;
  23763. case 'mapSpecularRepeat':
  23764. case 'mapSpecularOffset':
  23765. case 'mapSpecularWrap':
  23766. case 'mapSpecularAnisotropy':
  23767. break;
  23768. case 'mapMetalness':
  23769. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  23770. break;
  23771. case 'mapMetalnessRepeat':
  23772. case 'mapMetalnessOffset':
  23773. case 'mapMetalnessWrap':
  23774. case 'mapMetalnessAnisotropy':
  23775. break;
  23776. case 'mapRoughness':
  23777. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  23778. break;
  23779. case 'mapRoughnessRepeat':
  23780. case 'mapRoughnessOffset':
  23781. case 'mapRoughnessWrap':
  23782. case 'mapRoughnessAnisotropy':
  23783. break;
  23784. case 'mapAlpha':
  23785. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  23786. break;
  23787. case 'mapAlphaRepeat':
  23788. case 'mapAlphaOffset':
  23789. case 'mapAlphaWrap':
  23790. case 'mapAlphaAnisotropy':
  23791. break;
  23792. case 'flipSided':
  23793. json.side = BackSide;
  23794. break;
  23795. case 'doubleSided':
  23796. json.side = DoubleSide;
  23797. break;
  23798. case 'transparency':
  23799. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  23800. json.opacity = value;
  23801. break;
  23802. case 'depthTest':
  23803. case 'depthWrite':
  23804. case 'colorWrite':
  23805. case 'opacity':
  23806. case 'reflectivity':
  23807. case 'transparent':
  23808. case 'visible':
  23809. case 'wireframe':
  23810. json[ name ] = value;
  23811. break;
  23812. case 'vertexColors':
  23813. if ( value === true ) json.vertexColors = VertexColors;
  23814. if ( value === 'face' ) json.vertexColors = FaceColors;
  23815. break;
  23816. default:
  23817. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  23818. break;
  23819. }
  23820. }
  23821. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  23822. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  23823. if ( json.opacity < 1 ) json.transparent = true;
  23824. materialLoader.setTextures( textures );
  23825. return materialLoader.parse( json );
  23826. };
  23827. } )()
  23828. } );
  23829. /**
  23830. * @author mrdoob / http://mrdoob.com/
  23831. */
  23832. var context;
  23833. var AudioContext = {
  23834. getContext: function () {
  23835. if ( context === undefined ) {
  23836. context = new ( window.AudioContext || window.webkitAudioContext )();
  23837. }
  23838. return context;
  23839. },
  23840. setContext: function ( value ) {
  23841. context = value;
  23842. }
  23843. };
  23844. /**
  23845. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23846. */
  23847. function AudioLoader( manager ) {
  23848. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23849. }
  23850. Object.assign( AudioLoader.prototype, {
  23851. load: function ( url, onLoad, onProgress, onError ) {
  23852. var loader = new FileLoader( this.manager );
  23853. loader.setResponseType( 'arraybuffer' );
  23854. loader.setPath( this.path );
  23855. loader.load( url, function ( buffer ) {
  23856. // Create a copy of the buffer. The `decodeAudioData` method
  23857. // detaches the buffer when complete, preventing reuse.
  23858. var bufferCopy = buffer.slice( 0 );
  23859. var context = AudioContext.getContext();
  23860. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  23861. onLoad( audioBuffer );
  23862. } );
  23863. }, onProgress, onError );
  23864. },
  23865. setPath: function ( value ) {
  23866. this.path = value;
  23867. return this;
  23868. }
  23869. } );
  23870. /**
  23871. * @author mrdoob / http://mrdoob.com/
  23872. */
  23873. function StereoCamera() {
  23874. this.type = 'StereoCamera';
  23875. this.aspect = 1;
  23876. this.eyeSep = 0.064;
  23877. this.cameraL = new PerspectiveCamera();
  23878. this.cameraL.layers.enable( 1 );
  23879. this.cameraL.matrixAutoUpdate = false;
  23880. this.cameraR = new PerspectiveCamera();
  23881. this.cameraR.layers.enable( 2 );
  23882. this.cameraR.matrixAutoUpdate = false;
  23883. }
  23884. Object.assign( StereoCamera.prototype, {
  23885. update: ( function () {
  23886. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  23887. var eyeRight = new Matrix4();
  23888. var eyeLeft = new Matrix4();
  23889. return function update( camera ) {
  23890. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  23891. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  23892. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  23893. if ( needsUpdate ) {
  23894. instance = this;
  23895. focus = camera.focus;
  23896. fov = camera.fov;
  23897. aspect = camera.aspect * this.aspect;
  23898. near = camera.near;
  23899. far = camera.far;
  23900. zoom = camera.zoom;
  23901. // Off-axis stereoscopic effect based on
  23902. // http://paulbourke.net/stereographics/stereorender/
  23903. var projectionMatrix = camera.projectionMatrix.clone();
  23904. eyeSep = this.eyeSep / 2;
  23905. var eyeSepOnProjection = eyeSep * near / focus;
  23906. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  23907. var xmin, xmax;
  23908. // translate xOffset
  23909. eyeLeft.elements[ 12 ] = - eyeSep;
  23910. eyeRight.elements[ 12 ] = eyeSep;
  23911. // for left eye
  23912. xmin = - ymax * aspect + eyeSepOnProjection;
  23913. xmax = ymax * aspect + eyeSepOnProjection;
  23914. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23915. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23916. this.cameraL.projectionMatrix.copy( projectionMatrix );
  23917. // for right eye
  23918. xmin = - ymax * aspect - eyeSepOnProjection;
  23919. xmax = ymax * aspect - eyeSepOnProjection;
  23920. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23921. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23922. this.cameraR.projectionMatrix.copy( projectionMatrix );
  23923. }
  23924. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  23925. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  23926. };
  23927. } )()
  23928. } );
  23929. /**
  23930. * Camera for rendering cube maps
  23931. * - renders scene into axis-aligned cube
  23932. *
  23933. * @author alteredq / http://alteredqualia.com/
  23934. */
  23935. function CubeCamera( near, far, cubeResolution, options ) {
  23936. Object3D.call( this );
  23937. this.type = 'CubeCamera';
  23938. var fov = 90, aspect = 1;
  23939. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  23940. cameraPX.up.set( 0, - 1, 0 );
  23941. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  23942. this.add( cameraPX );
  23943. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  23944. cameraNX.up.set( 0, - 1, 0 );
  23945. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  23946. this.add( cameraNX );
  23947. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  23948. cameraPY.up.set( 0, 0, 1 );
  23949. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  23950. this.add( cameraPY );
  23951. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  23952. cameraNY.up.set( 0, 0, - 1 );
  23953. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  23954. this.add( cameraNY );
  23955. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  23956. cameraPZ.up.set( 0, - 1, 0 );
  23957. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  23958. this.add( cameraPZ );
  23959. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  23960. cameraNZ.up.set( 0, - 1, 0 );
  23961. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  23962. this.add( cameraNZ );
  23963. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  23964. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  23965. this.renderTarget.texture.name = "CubeCamera";
  23966. this.update = function ( renderer, scene ) {
  23967. if ( this.parent === null ) this.updateMatrixWorld();
  23968. var currentRenderTarget = renderer.getRenderTarget();
  23969. var renderTarget = this.renderTarget;
  23970. var generateMipmaps = renderTarget.texture.generateMipmaps;
  23971. renderTarget.texture.generateMipmaps = false;
  23972. renderer.setRenderTarget( renderTarget, 0 );
  23973. renderer.render( scene, cameraPX );
  23974. renderer.setRenderTarget( renderTarget, 1 );
  23975. renderer.render( scene, cameraNX );
  23976. renderer.setRenderTarget( renderTarget, 2 );
  23977. renderer.render( scene, cameraPY );
  23978. renderer.setRenderTarget( renderTarget, 3 );
  23979. renderer.render( scene, cameraNY );
  23980. renderer.setRenderTarget( renderTarget, 4 );
  23981. renderer.render( scene, cameraPZ );
  23982. renderTarget.texture.generateMipmaps = generateMipmaps;
  23983. renderer.setRenderTarget( renderTarget, 5 );
  23984. renderer.render( scene, cameraNZ );
  23985. renderer.setRenderTarget( currentRenderTarget );
  23986. };
  23987. this.clear = function ( renderer, color, depth, stencil ) {
  23988. var currentRenderTarget = renderer.getRenderTarget();
  23989. var renderTarget = this.renderTarget;
  23990. for ( var i = 0; i < 6; i ++ ) {
  23991. renderer.setRenderTarget( renderTarget, i );
  23992. renderer.clear( color, depth, stencil );
  23993. }
  23994. renderer.setRenderTarget( currentRenderTarget );
  23995. };
  23996. }
  23997. CubeCamera.prototype = Object.create( Object3D.prototype );
  23998. CubeCamera.prototype.constructor = CubeCamera;
  23999. /**
  24000. * @author alteredq / http://alteredqualia.com/
  24001. */
  24002. function Clock( autoStart ) {
  24003. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24004. this.startTime = 0;
  24005. this.oldTime = 0;
  24006. this.elapsedTime = 0;
  24007. this.running = false;
  24008. }
  24009. Object.assign( Clock.prototype, {
  24010. start: function () {
  24011. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24012. this.oldTime = this.startTime;
  24013. this.elapsedTime = 0;
  24014. this.running = true;
  24015. },
  24016. stop: function () {
  24017. this.getElapsedTime();
  24018. this.running = false;
  24019. this.autoStart = false;
  24020. },
  24021. getElapsedTime: function () {
  24022. this.getDelta();
  24023. return this.elapsedTime;
  24024. },
  24025. getDelta: function () {
  24026. var diff = 0;
  24027. if ( this.autoStart && ! this.running ) {
  24028. this.start();
  24029. return 0;
  24030. }
  24031. if ( this.running ) {
  24032. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24033. diff = ( newTime - this.oldTime ) / 1000;
  24034. this.oldTime = newTime;
  24035. this.elapsedTime += diff;
  24036. }
  24037. return diff;
  24038. }
  24039. } );
  24040. /**
  24041. * @author mrdoob / http://mrdoob.com/
  24042. */
  24043. function AudioListener() {
  24044. Object3D.call( this );
  24045. this.type = 'AudioListener';
  24046. this.context = AudioContext.getContext();
  24047. this.gain = this.context.createGain();
  24048. this.gain.connect( this.context.destination );
  24049. this.filter = null;
  24050. this.timeDelta = 0;
  24051. }
  24052. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24053. constructor: AudioListener,
  24054. getInput: function () {
  24055. return this.gain;
  24056. },
  24057. removeFilter: function ( ) {
  24058. if ( this.filter !== null ) {
  24059. this.gain.disconnect( this.filter );
  24060. this.filter.disconnect( this.context.destination );
  24061. this.gain.connect( this.context.destination );
  24062. this.filter = null;
  24063. }
  24064. return this;
  24065. },
  24066. getFilter: function () {
  24067. return this.filter;
  24068. },
  24069. setFilter: function ( value ) {
  24070. if ( this.filter !== null ) {
  24071. this.gain.disconnect( this.filter );
  24072. this.filter.disconnect( this.context.destination );
  24073. } else {
  24074. this.gain.disconnect( this.context.destination );
  24075. }
  24076. this.filter = value;
  24077. this.gain.connect( this.filter );
  24078. this.filter.connect( this.context.destination );
  24079. return this;
  24080. },
  24081. getMasterVolume: function () {
  24082. return this.gain.gain.value;
  24083. },
  24084. setMasterVolume: function ( value ) {
  24085. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24086. return this;
  24087. },
  24088. updateMatrixWorld: ( function () {
  24089. var position = new Vector3();
  24090. var quaternion = new Quaternion();
  24091. var scale = new Vector3();
  24092. var orientation = new Vector3();
  24093. var clock = new Clock();
  24094. return function updateMatrixWorld( force ) {
  24095. Object3D.prototype.updateMatrixWorld.call( this, force );
  24096. var listener = this.context.listener;
  24097. var up = this.up;
  24098. this.timeDelta = clock.getDelta();
  24099. this.matrixWorld.decompose( position, quaternion, scale );
  24100. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24101. if ( listener.positionX ) {
  24102. // code path for Chrome (see #14393)
  24103. var endTime = this.context.currentTime + this.timeDelta;
  24104. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24105. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24106. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24107. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24108. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24109. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24110. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24111. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24112. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24113. } else {
  24114. listener.setPosition( position.x, position.y, position.z );
  24115. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24116. }
  24117. };
  24118. } )()
  24119. } );
  24120. /**
  24121. * @author mrdoob / http://mrdoob.com/
  24122. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24123. */
  24124. function Audio( listener ) {
  24125. Object3D.call( this );
  24126. this.type = 'Audio';
  24127. this.listener = listener;
  24128. this.context = listener.context;
  24129. this.gain = this.context.createGain();
  24130. this.gain.connect( listener.getInput() );
  24131. this.autoplay = false;
  24132. this.buffer = null;
  24133. this.detune = 0;
  24134. this.loop = false;
  24135. this.startTime = 0;
  24136. this.offset = 0;
  24137. this.playbackRate = 1;
  24138. this.isPlaying = false;
  24139. this.hasPlaybackControl = true;
  24140. this.sourceType = 'empty';
  24141. this.filters = [];
  24142. }
  24143. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24144. constructor: Audio,
  24145. getOutput: function () {
  24146. return this.gain;
  24147. },
  24148. setNodeSource: function ( audioNode ) {
  24149. this.hasPlaybackControl = false;
  24150. this.sourceType = 'audioNode';
  24151. this.source = audioNode;
  24152. this.connect();
  24153. return this;
  24154. },
  24155. setMediaElementSource: function ( mediaElement ) {
  24156. this.hasPlaybackControl = false;
  24157. this.sourceType = 'mediaNode';
  24158. this.source = this.context.createMediaElementSource( mediaElement );
  24159. this.connect();
  24160. return this;
  24161. },
  24162. setBuffer: function ( audioBuffer ) {
  24163. this.buffer = audioBuffer;
  24164. this.sourceType = 'buffer';
  24165. if ( this.autoplay ) this.play();
  24166. return this;
  24167. },
  24168. play: function () {
  24169. if ( this.isPlaying === true ) {
  24170. console.warn( 'THREE.Audio: Audio is already playing.' );
  24171. return;
  24172. }
  24173. if ( this.hasPlaybackControl === false ) {
  24174. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24175. return;
  24176. }
  24177. var source = this.context.createBufferSource();
  24178. source.buffer = this.buffer;
  24179. source.loop = this.loop;
  24180. source.onended = this.onEnded.bind( this );
  24181. this.startTime = this.context.currentTime;
  24182. source.start( this.startTime, this.offset );
  24183. this.isPlaying = true;
  24184. this.source = source;
  24185. this.setDetune( this.detune );
  24186. this.setPlaybackRate( this.playbackRate );
  24187. return this.connect();
  24188. },
  24189. pause: function () {
  24190. if ( this.hasPlaybackControl === false ) {
  24191. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24192. return;
  24193. }
  24194. if ( this.isPlaying === true ) {
  24195. this.source.stop();
  24196. this.source.onended = null;
  24197. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24198. this.isPlaying = false;
  24199. }
  24200. return this;
  24201. },
  24202. stop: function () {
  24203. if ( this.hasPlaybackControl === false ) {
  24204. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24205. return;
  24206. }
  24207. this.source.stop();
  24208. this.source.onended = null;
  24209. this.offset = 0;
  24210. this.isPlaying = false;
  24211. return this;
  24212. },
  24213. connect: function () {
  24214. if ( this.filters.length > 0 ) {
  24215. this.source.connect( this.filters[ 0 ] );
  24216. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24217. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24218. }
  24219. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24220. } else {
  24221. this.source.connect( this.getOutput() );
  24222. }
  24223. return this;
  24224. },
  24225. disconnect: function () {
  24226. if ( this.filters.length > 0 ) {
  24227. this.source.disconnect( this.filters[ 0 ] );
  24228. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24229. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24230. }
  24231. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24232. } else {
  24233. this.source.disconnect( this.getOutput() );
  24234. }
  24235. return this;
  24236. },
  24237. getFilters: function () {
  24238. return this.filters;
  24239. },
  24240. setFilters: function ( value ) {
  24241. if ( ! value ) value = [];
  24242. if ( this.isPlaying === true ) {
  24243. this.disconnect();
  24244. this.filters = value;
  24245. this.connect();
  24246. } else {
  24247. this.filters = value;
  24248. }
  24249. return this;
  24250. },
  24251. setDetune: function ( value ) {
  24252. this.detune = value;
  24253. if ( this.source.detune === undefined ) return; // only set detune when available
  24254. if ( this.isPlaying === true ) {
  24255. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24256. }
  24257. return this;
  24258. },
  24259. getDetune: function () {
  24260. return this.detune;
  24261. },
  24262. getFilter: function () {
  24263. return this.getFilters()[ 0 ];
  24264. },
  24265. setFilter: function ( filter ) {
  24266. return this.setFilters( filter ? [ filter ] : [] );
  24267. },
  24268. setPlaybackRate: function ( value ) {
  24269. if ( this.hasPlaybackControl === false ) {
  24270. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24271. return;
  24272. }
  24273. this.playbackRate = value;
  24274. if ( this.isPlaying === true ) {
  24275. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24276. }
  24277. return this;
  24278. },
  24279. getPlaybackRate: function () {
  24280. return this.playbackRate;
  24281. },
  24282. onEnded: function () {
  24283. this.isPlaying = false;
  24284. },
  24285. getLoop: function () {
  24286. if ( this.hasPlaybackControl === false ) {
  24287. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24288. return false;
  24289. }
  24290. return this.loop;
  24291. },
  24292. setLoop: function ( value ) {
  24293. if ( this.hasPlaybackControl === false ) {
  24294. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24295. return;
  24296. }
  24297. this.loop = value;
  24298. if ( this.isPlaying === true ) {
  24299. this.source.loop = this.loop;
  24300. }
  24301. return this;
  24302. },
  24303. getVolume: function () {
  24304. return this.gain.gain.value;
  24305. },
  24306. setVolume: function ( value ) {
  24307. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24308. return this;
  24309. }
  24310. } );
  24311. /**
  24312. * @author mrdoob / http://mrdoob.com/
  24313. */
  24314. function PositionalAudio( listener ) {
  24315. Audio.call( this, listener );
  24316. this.panner = this.context.createPanner();
  24317. this.panner.connect( this.gain );
  24318. }
  24319. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24320. constructor: PositionalAudio,
  24321. getOutput: function () {
  24322. return this.panner;
  24323. },
  24324. getRefDistance: function () {
  24325. return this.panner.refDistance;
  24326. },
  24327. setRefDistance: function ( value ) {
  24328. this.panner.refDistance = value;
  24329. return this;
  24330. },
  24331. getRolloffFactor: function () {
  24332. return this.panner.rolloffFactor;
  24333. },
  24334. setRolloffFactor: function ( value ) {
  24335. this.panner.rolloffFactor = value;
  24336. return this;
  24337. },
  24338. getDistanceModel: function () {
  24339. return this.panner.distanceModel;
  24340. },
  24341. setDistanceModel: function ( value ) {
  24342. this.panner.distanceModel = value;
  24343. return this;
  24344. },
  24345. getMaxDistance: function () {
  24346. return this.panner.maxDistance;
  24347. },
  24348. setMaxDistance: function ( value ) {
  24349. this.panner.maxDistance = value;
  24350. return this;
  24351. },
  24352. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24353. this.panner.coneInnerAngle = coneInnerAngle;
  24354. this.panner.coneOuterAngle = coneOuterAngle;
  24355. this.panner.coneOuterGain = coneOuterGain;
  24356. return this;
  24357. },
  24358. updateMatrixWorld: ( function () {
  24359. var position = new Vector3();
  24360. var quaternion = new Quaternion();
  24361. var scale = new Vector3();
  24362. var orientation = new Vector3();
  24363. return function updateMatrixWorld( force ) {
  24364. Object3D.prototype.updateMatrixWorld.call( this, force );
  24365. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24366. this.matrixWorld.decompose( position, quaternion, scale );
  24367. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24368. var panner = this.panner;
  24369. if ( panner.positionX ) {
  24370. // code path for Chrome and Firefox (see #14393)
  24371. var endTime = this.context.currentTime + this.listener.timeDelta;
  24372. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24373. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24374. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24375. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24376. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24377. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24378. } else {
  24379. panner.setPosition( position.x, position.y, position.z );
  24380. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24381. }
  24382. };
  24383. } )()
  24384. } );
  24385. /**
  24386. * @author mrdoob / http://mrdoob.com/
  24387. */
  24388. function AudioAnalyser( audio, fftSize ) {
  24389. this.analyser = audio.context.createAnalyser();
  24390. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24391. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24392. audio.getOutput().connect( this.analyser );
  24393. }
  24394. Object.assign( AudioAnalyser.prototype, {
  24395. getFrequencyData: function () {
  24396. this.analyser.getByteFrequencyData( this.data );
  24397. return this.data;
  24398. },
  24399. getAverageFrequency: function () {
  24400. var value = 0, data = this.getFrequencyData();
  24401. for ( var i = 0; i < data.length; i ++ ) {
  24402. value += data[ i ];
  24403. }
  24404. return value / data.length;
  24405. }
  24406. } );
  24407. /**
  24408. *
  24409. * Buffered scene graph property that allows weighted accumulation.
  24410. *
  24411. *
  24412. * @author Ben Houston / http://clara.io/
  24413. * @author David Sarno / http://lighthaus.us/
  24414. * @author tschw
  24415. */
  24416. function PropertyMixer( binding, typeName, valueSize ) {
  24417. this.binding = binding;
  24418. this.valueSize = valueSize;
  24419. var bufferType = Float64Array,
  24420. mixFunction;
  24421. switch ( typeName ) {
  24422. case 'quaternion':
  24423. mixFunction = this._slerp;
  24424. break;
  24425. case 'string':
  24426. case 'bool':
  24427. bufferType = Array;
  24428. mixFunction = this._select;
  24429. break;
  24430. default:
  24431. mixFunction = this._lerp;
  24432. }
  24433. this.buffer = new bufferType( valueSize * 4 );
  24434. // layout: [ incoming | accu0 | accu1 | orig ]
  24435. //
  24436. // interpolators can use .buffer as their .result
  24437. // the data then goes to 'incoming'
  24438. //
  24439. // 'accu0' and 'accu1' are used frame-interleaved for
  24440. // the cumulative result and are compared to detect
  24441. // changes
  24442. //
  24443. // 'orig' stores the original state of the property
  24444. this._mixBufferRegion = mixFunction;
  24445. this.cumulativeWeight = 0;
  24446. this.useCount = 0;
  24447. this.referenceCount = 0;
  24448. }
  24449. Object.assign( PropertyMixer.prototype, {
  24450. // accumulate data in the 'incoming' region into 'accu<i>'
  24451. accumulate: function ( accuIndex, weight ) {
  24452. // note: happily accumulating nothing when weight = 0, the caller knows
  24453. // the weight and shouldn't have made the call in the first place
  24454. var buffer = this.buffer,
  24455. stride = this.valueSize,
  24456. offset = accuIndex * stride + stride,
  24457. currentWeight = this.cumulativeWeight;
  24458. if ( currentWeight === 0 ) {
  24459. // accuN := incoming * weight
  24460. for ( var i = 0; i !== stride; ++ i ) {
  24461. buffer[ offset + i ] = buffer[ i ];
  24462. }
  24463. currentWeight = weight;
  24464. } else {
  24465. // accuN := accuN + incoming * weight
  24466. currentWeight += weight;
  24467. var mix = weight / currentWeight;
  24468. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24469. }
  24470. this.cumulativeWeight = currentWeight;
  24471. },
  24472. // apply the state of 'accu<i>' to the binding when accus differ
  24473. apply: function ( accuIndex ) {
  24474. var stride = this.valueSize,
  24475. buffer = this.buffer,
  24476. offset = accuIndex * stride + stride,
  24477. weight = this.cumulativeWeight,
  24478. binding = this.binding;
  24479. this.cumulativeWeight = 0;
  24480. if ( weight < 1 ) {
  24481. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24482. var originalValueOffset = stride * 3;
  24483. this._mixBufferRegion(
  24484. buffer, offset, originalValueOffset, 1 - weight, stride );
  24485. }
  24486. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  24487. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24488. // value has changed -> update scene graph
  24489. binding.setValue( buffer, offset );
  24490. break;
  24491. }
  24492. }
  24493. },
  24494. // remember the state of the bound property and copy it to both accus
  24495. saveOriginalState: function () {
  24496. var binding = this.binding;
  24497. var buffer = this.buffer,
  24498. stride = this.valueSize,
  24499. originalValueOffset = stride * 3;
  24500. binding.getValue( buffer, originalValueOffset );
  24501. // accu[0..1] := orig -- initially detect changes against the original
  24502. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24503. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24504. }
  24505. this.cumulativeWeight = 0;
  24506. },
  24507. // apply the state previously taken via 'saveOriginalState' to the binding
  24508. restoreOriginalState: function () {
  24509. var originalValueOffset = this.valueSize * 3;
  24510. this.binding.setValue( this.buffer, originalValueOffset );
  24511. },
  24512. // mix functions
  24513. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24514. if ( t >= 0.5 ) {
  24515. for ( var i = 0; i !== stride; ++ i ) {
  24516. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24517. }
  24518. }
  24519. },
  24520. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24521. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24522. },
  24523. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24524. var s = 1 - t;
  24525. for ( var i = 0; i !== stride; ++ i ) {
  24526. var j = dstOffset + i;
  24527. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24528. }
  24529. }
  24530. } );
  24531. /**
  24532. *
  24533. * A reference to a real property in the scene graph.
  24534. *
  24535. *
  24536. * @author Ben Houston / http://clara.io/
  24537. * @author David Sarno / http://lighthaus.us/
  24538. * @author tschw
  24539. */
  24540. // Characters [].:/ are reserved for track binding syntax.
  24541. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24542. function Composite( targetGroup, path, optionalParsedPath ) {
  24543. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24544. this._targetGroup = targetGroup;
  24545. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24546. }
  24547. Object.assign( Composite.prototype, {
  24548. getValue: function ( array, offset ) {
  24549. this.bind(); // bind all binding
  24550. var firstValidIndex = this._targetGroup.nCachedObjects_,
  24551. binding = this._bindings[ firstValidIndex ];
  24552. // and only call .getValue on the first
  24553. if ( binding !== undefined ) binding.getValue( array, offset );
  24554. },
  24555. setValue: function ( array, offset ) {
  24556. var bindings = this._bindings;
  24557. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24558. bindings[ i ].setValue( array, offset );
  24559. }
  24560. },
  24561. bind: function () {
  24562. var bindings = this._bindings;
  24563. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24564. bindings[ i ].bind();
  24565. }
  24566. },
  24567. unbind: function () {
  24568. var bindings = this._bindings;
  24569. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24570. bindings[ i ].unbind();
  24571. }
  24572. }
  24573. } );
  24574. function PropertyBinding( rootNode, path, parsedPath ) {
  24575. this.path = path;
  24576. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24577. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24578. this.rootNode = rootNode;
  24579. }
  24580. Object.assign( PropertyBinding, {
  24581. Composite: Composite,
  24582. create: function ( root, path, parsedPath ) {
  24583. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24584. return new PropertyBinding( root, path, parsedPath );
  24585. } else {
  24586. return new PropertyBinding.Composite( root, path, parsedPath );
  24587. }
  24588. },
  24589. /**
  24590. * Replaces spaces with underscores and removes unsupported characters from
  24591. * node names, to ensure compatibility with parseTrackName().
  24592. *
  24593. * @param {string} name Node name to be sanitized.
  24594. * @return {string}
  24595. */
  24596. sanitizeNodeName: ( function () {
  24597. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  24598. return function sanitizeNodeName( name ) {
  24599. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  24600. };
  24601. }() ),
  24602. parseTrackName: function () {
  24603. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24604. // only latin characters, and the unicode \p{L} is not yet supported. So
  24605. // instead, we exclude reserved characters and match everything else.
  24606. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  24607. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24608. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24609. // be matched to parse the rest of the track name.
  24610. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  24611. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24612. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  24613. // Object on target node, and accessor. May not contain reserved
  24614. // characters. Accessor may contain any character except closing bracket.
  24615. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  24616. // Property and accessor. May not contain reserved characters. Accessor may
  24617. // contain any non-bracket characters.
  24618. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  24619. var trackRe = new RegExp( ''
  24620. + '^'
  24621. + directoryRe
  24622. + nodeRe
  24623. + objectRe
  24624. + propertyRe
  24625. + '$'
  24626. );
  24627. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24628. return function parseTrackName( trackName ) {
  24629. var matches = trackRe.exec( trackName );
  24630. if ( ! matches ) {
  24631. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24632. }
  24633. var results = {
  24634. // directoryName: matches[ 1 ], // (tschw) currently unused
  24635. nodeName: matches[ 2 ],
  24636. objectName: matches[ 3 ],
  24637. objectIndex: matches[ 4 ],
  24638. propertyName: matches[ 5 ], // required
  24639. propertyIndex: matches[ 6 ]
  24640. };
  24641. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24642. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24643. var objectName = results.nodeName.substring( lastDot + 1 );
  24644. // Object names must be checked against a whitelist. Otherwise, there
  24645. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24646. // 'bar' could be the objectName, or part of a nodeName (which can
  24647. // include '.' characters).
  24648. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24649. results.nodeName = results.nodeName.substring( 0, lastDot );
  24650. results.objectName = objectName;
  24651. }
  24652. }
  24653. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24654. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24655. }
  24656. return results;
  24657. };
  24658. }(),
  24659. findNode: function ( root, nodeName ) {
  24660. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24661. return root;
  24662. }
  24663. // search into skeleton bones.
  24664. if ( root.skeleton ) {
  24665. var bone = root.skeleton.getBoneByName( nodeName );
  24666. if ( bone !== undefined ) {
  24667. return bone;
  24668. }
  24669. }
  24670. // search into node subtree.
  24671. if ( root.children ) {
  24672. var searchNodeSubtree = function ( children ) {
  24673. for ( var i = 0; i < children.length; i ++ ) {
  24674. var childNode = children[ i ];
  24675. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24676. return childNode;
  24677. }
  24678. var result = searchNodeSubtree( childNode.children );
  24679. if ( result ) return result;
  24680. }
  24681. return null;
  24682. };
  24683. var subTreeNode = searchNodeSubtree( root.children );
  24684. if ( subTreeNode ) {
  24685. return subTreeNode;
  24686. }
  24687. }
  24688. return null;
  24689. }
  24690. } );
  24691. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24692. // these are used to "bind" a nonexistent property
  24693. _getValue_unavailable: function () {},
  24694. _setValue_unavailable: function () {},
  24695. BindingType: {
  24696. Direct: 0,
  24697. EntireArray: 1,
  24698. ArrayElement: 2,
  24699. HasFromToArray: 3
  24700. },
  24701. Versioning: {
  24702. None: 0,
  24703. NeedsUpdate: 1,
  24704. MatrixWorldNeedsUpdate: 2
  24705. },
  24706. GetterByBindingType: [
  24707. function getValue_direct( buffer, offset ) {
  24708. buffer[ offset ] = this.node[ this.propertyName ];
  24709. },
  24710. function getValue_array( buffer, offset ) {
  24711. var source = this.resolvedProperty;
  24712. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  24713. buffer[ offset ++ ] = source[ i ];
  24714. }
  24715. },
  24716. function getValue_arrayElement( buffer, offset ) {
  24717. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  24718. },
  24719. function getValue_toArray( buffer, offset ) {
  24720. this.resolvedProperty.toArray( buffer, offset );
  24721. }
  24722. ],
  24723. SetterByBindingTypeAndVersioning: [
  24724. [
  24725. // Direct
  24726. function setValue_direct( buffer, offset ) {
  24727. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24728. },
  24729. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  24730. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24731. this.targetObject.needsUpdate = true;
  24732. },
  24733. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24734. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24735. this.targetObject.matrixWorldNeedsUpdate = true;
  24736. }
  24737. ], [
  24738. // EntireArray
  24739. function setValue_array( buffer, offset ) {
  24740. var dest = this.resolvedProperty;
  24741. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24742. dest[ i ] = buffer[ offset ++ ];
  24743. }
  24744. },
  24745. function setValue_array_setNeedsUpdate( buffer, offset ) {
  24746. var dest = this.resolvedProperty;
  24747. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24748. dest[ i ] = buffer[ offset ++ ];
  24749. }
  24750. this.targetObject.needsUpdate = true;
  24751. },
  24752. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24753. var dest = this.resolvedProperty;
  24754. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24755. dest[ i ] = buffer[ offset ++ ];
  24756. }
  24757. this.targetObject.matrixWorldNeedsUpdate = true;
  24758. }
  24759. ], [
  24760. // ArrayElement
  24761. function setValue_arrayElement( buffer, offset ) {
  24762. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24763. },
  24764. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  24765. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24766. this.targetObject.needsUpdate = true;
  24767. },
  24768. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24769. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24770. this.targetObject.matrixWorldNeedsUpdate = true;
  24771. }
  24772. ], [
  24773. // HasToFromArray
  24774. function setValue_fromArray( buffer, offset ) {
  24775. this.resolvedProperty.fromArray( buffer, offset );
  24776. },
  24777. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  24778. this.resolvedProperty.fromArray( buffer, offset );
  24779. this.targetObject.needsUpdate = true;
  24780. },
  24781. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24782. this.resolvedProperty.fromArray( buffer, offset );
  24783. this.targetObject.matrixWorldNeedsUpdate = true;
  24784. }
  24785. ]
  24786. ],
  24787. getValue: function getValue_unbound( targetArray, offset ) {
  24788. this.bind();
  24789. this.getValue( targetArray, offset );
  24790. // Note: This class uses a State pattern on a per-method basis:
  24791. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  24792. // prototype version of these methods with one that represents
  24793. // the bound state. When the property is not found, the methods
  24794. // become no-ops.
  24795. },
  24796. setValue: function getValue_unbound( sourceArray, offset ) {
  24797. this.bind();
  24798. this.setValue( sourceArray, offset );
  24799. },
  24800. // create getter / setter pair for a property in the scene graph
  24801. bind: function () {
  24802. var targetObject = this.node,
  24803. parsedPath = this.parsedPath,
  24804. objectName = parsedPath.objectName,
  24805. propertyName = parsedPath.propertyName,
  24806. propertyIndex = parsedPath.propertyIndex;
  24807. if ( ! targetObject ) {
  24808. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  24809. this.node = targetObject;
  24810. }
  24811. // set fail state so we can just 'return' on error
  24812. this.getValue = this._getValue_unavailable;
  24813. this.setValue = this._setValue_unavailable;
  24814. // ensure there is a value node
  24815. if ( ! targetObject ) {
  24816. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  24817. return;
  24818. }
  24819. if ( objectName ) {
  24820. var objectIndex = parsedPath.objectIndex;
  24821. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  24822. switch ( objectName ) {
  24823. case 'materials':
  24824. if ( ! targetObject.material ) {
  24825. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  24826. return;
  24827. }
  24828. if ( ! targetObject.material.materials ) {
  24829. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  24830. return;
  24831. }
  24832. targetObject = targetObject.material.materials;
  24833. break;
  24834. case 'bones':
  24835. if ( ! targetObject.skeleton ) {
  24836. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  24837. return;
  24838. }
  24839. // potential future optimization: skip this if propertyIndex is already an integer
  24840. // and convert the integer string to a true integer.
  24841. targetObject = targetObject.skeleton.bones;
  24842. // support resolving morphTarget names into indices.
  24843. for ( var i = 0; i < targetObject.length; i ++ ) {
  24844. if ( targetObject[ i ].name === objectIndex ) {
  24845. objectIndex = i;
  24846. break;
  24847. }
  24848. }
  24849. break;
  24850. default:
  24851. if ( targetObject[ objectName ] === undefined ) {
  24852. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  24853. return;
  24854. }
  24855. targetObject = targetObject[ objectName ];
  24856. }
  24857. if ( objectIndex !== undefined ) {
  24858. if ( targetObject[ objectIndex ] === undefined ) {
  24859. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  24860. return;
  24861. }
  24862. targetObject = targetObject[ objectIndex ];
  24863. }
  24864. }
  24865. // resolve property
  24866. var nodeProperty = targetObject[ propertyName ];
  24867. if ( nodeProperty === undefined ) {
  24868. var nodeName = parsedPath.nodeName;
  24869. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  24870. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  24871. return;
  24872. }
  24873. // determine versioning scheme
  24874. var versioning = this.Versioning.None;
  24875. this.targetObject = targetObject;
  24876. if ( targetObject.needsUpdate !== undefined ) { // material
  24877. versioning = this.Versioning.NeedsUpdate;
  24878. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  24879. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  24880. }
  24881. // determine how the property gets bound
  24882. var bindingType = this.BindingType.Direct;
  24883. if ( propertyIndex !== undefined ) {
  24884. // access a sub element of the property array (only primitives are supported right now)
  24885. if ( propertyName === "morphTargetInfluences" ) {
  24886. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  24887. // support resolving morphTarget names into indices.
  24888. if ( ! targetObject.geometry ) {
  24889. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  24890. return;
  24891. }
  24892. if ( targetObject.geometry.isBufferGeometry ) {
  24893. if ( ! targetObject.geometry.morphAttributes ) {
  24894. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  24895. return;
  24896. }
  24897. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  24898. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  24899. propertyIndex = i;
  24900. break;
  24901. }
  24902. }
  24903. } else {
  24904. if ( ! targetObject.geometry.morphTargets ) {
  24905. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  24906. return;
  24907. }
  24908. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  24909. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  24910. propertyIndex = i;
  24911. break;
  24912. }
  24913. }
  24914. }
  24915. }
  24916. bindingType = this.BindingType.ArrayElement;
  24917. this.resolvedProperty = nodeProperty;
  24918. this.propertyIndex = propertyIndex;
  24919. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  24920. // must use copy for Object3D.Euler/Quaternion
  24921. bindingType = this.BindingType.HasFromToArray;
  24922. this.resolvedProperty = nodeProperty;
  24923. } else if ( Array.isArray( nodeProperty ) ) {
  24924. bindingType = this.BindingType.EntireArray;
  24925. this.resolvedProperty = nodeProperty;
  24926. } else {
  24927. this.propertyName = propertyName;
  24928. }
  24929. // select getter / setter
  24930. this.getValue = this.GetterByBindingType[ bindingType ];
  24931. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  24932. },
  24933. unbind: function () {
  24934. this.node = null;
  24935. // back to the prototype version of getValue / setValue
  24936. // note: avoiding to mutate the shape of 'this' via 'delete'
  24937. this.getValue = this._getValue_unbound;
  24938. this.setValue = this._setValue_unbound;
  24939. }
  24940. } );
  24941. //!\ DECLARE ALIAS AFTER assign prototype !
  24942. Object.assign( PropertyBinding.prototype, {
  24943. // initial state of these methods that calls 'bind'
  24944. _getValue_unbound: PropertyBinding.prototype.getValue,
  24945. _setValue_unbound: PropertyBinding.prototype.setValue,
  24946. } );
  24947. /**
  24948. *
  24949. * A group of objects that receives a shared animation state.
  24950. *
  24951. * Usage:
  24952. *
  24953. * - Add objects you would otherwise pass as 'root' to the
  24954. * constructor or the .clipAction method of AnimationMixer.
  24955. *
  24956. * - Instead pass this object as 'root'.
  24957. *
  24958. * - You can also add and remove objects later when the mixer
  24959. * is running.
  24960. *
  24961. * Note:
  24962. *
  24963. * Objects of this class appear as one object to the mixer,
  24964. * so cache control of the individual objects must be done
  24965. * on the group.
  24966. *
  24967. * Limitation:
  24968. *
  24969. * - The animated properties must be compatible among the
  24970. * all objects in the group.
  24971. *
  24972. * - A single property can either be controlled through a
  24973. * target group or directly, but not both.
  24974. *
  24975. * @author tschw
  24976. */
  24977. function AnimationObjectGroup() {
  24978. this.uuid = _Math.generateUUID();
  24979. // cached objects followed by the active ones
  24980. this._objects = Array.prototype.slice.call( arguments );
  24981. this.nCachedObjects_ = 0; // threshold
  24982. // note: read by PropertyBinding.Composite
  24983. var indices = {};
  24984. this._indicesByUUID = indices; // for bookkeeping
  24985. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24986. indices[ arguments[ i ].uuid ] = i;
  24987. }
  24988. this._paths = []; // inside: string
  24989. this._parsedPaths = []; // inside: { we don't care, here }
  24990. this._bindings = []; // inside: Array< PropertyBinding >
  24991. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  24992. var scope = this;
  24993. this.stats = {
  24994. objects: {
  24995. get total() {
  24996. return scope._objects.length;
  24997. },
  24998. get inUse() {
  24999. return this.total - scope.nCachedObjects_;
  25000. }
  25001. },
  25002. get bindingsPerObject() {
  25003. return scope._bindings.length;
  25004. }
  25005. };
  25006. }
  25007. Object.assign( AnimationObjectGroup.prototype, {
  25008. isAnimationObjectGroup: true,
  25009. add: function () {
  25010. var objects = this._objects,
  25011. nObjects = objects.length,
  25012. nCachedObjects = this.nCachedObjects_,
  25013. indicesByUUID = this._indicesByUUID,
  25014. paths = this._paths,
  25015. parsedPaths = this._parsedPaths,
  25016. bindings = this._bindings,
  25017. nBindings = bindings.length,
  25018. knownObject = undefined;
  25019. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25020. var object = arguments[ i ],
  25021. uuid = object.uuid,
  25022. index = indicesByUUID[ uuid ];
  25023. if ( index === undefined ) {
  25024. // unknown object -> add it to the ACTIVE region
  25025. index = nObjects ++;
  25026. indicesByUUID[ uuid ] = index;
  25027. objects.push( object );
  25028. // accounting is done, now do the same for all bindings
  25029. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25030. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25031. }
  25032. } else if ( index < nCachedObjects ) {
  25033. knownObject = objects[ index ];
  25034. // move existing object to the ACTIVE region
  25035. var firstActiveIndex = -- nCachedObjects,
  25036. lastCachedObject = objects[ firstActiveIndex ];
  25037. indicesByUUID[ lastCachedObject.uuid ] = index;
  25038. objects[ index ] = lastCachedObject;
  25039. indicesByUUID[ uuid ] = firstActiveIndex;
  25040. objects[ firstActiveIndex ] = object;
  25041. // accounting is done, now do the same for all bindings
  25042. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25043. var bindingsForPath = bindings[ j ],
  25044. lastCached = bindingsForPath[ firstActiveIndex ],
  25045. binding = bindingsForPath[ index ];
  25046. bindingsForPath[ index ] = lastCached;
  25047. if ( binding === undefined ) {
  25048. // since we do not bother to create new bindings
  25049. // for objects that are cached, the binding may
  25050. // or may not exist
  25051. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25052. }
  25053. bindingsForPath[ firstActiveIndex ] = binding;
  25054. }
  25055. } else if ( objects[ index ] !== knownObject ) {
  25056. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25057. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25058. } // else the object is already where we want it to be
  25059. } // for arguments
  25060. this.nCachedObjects_ = nCachedObjects;
  25061. },
  25062. remove: function () {
  25063. var objects = this._objects,
  25064. nCachedObjects = this.nCachedObjects_,
  25065. indicesByUUID = this._indicesByUUID,
  25066. bindings = this._bindings,
  25067. nBindings = bindings.length;
  25068. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25069. var object = arguments[ i ],
  25070. uuid = object.uuid,
  25071. index = indicesByUUID[ uuid ];
  25072. if ( index !== undefined && index >= nCachedObjects ) {
  25073. // move existing object into the CACHED region
  25074. var lastCachedIndex = nCachedObjects ++,
  25075. firstActiveObject = objects[ lastCachedIndex ];
  25076. indicesByUUID[ firstActiveObject.uuid ] = index;
  25077. objects[ index ] = firstActiveObject;
  25078. indicesByUUID[ uuid ] = lastCachedIndex;
  25079. objects[ lastCachedIndex ] = object;
  25080. // accounting is done, now do the same for all bindings
  25081. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25082. var bindingsForPath = bindings[ j ],
  25083. firstActive = bindingsForPath[ lastCachedIndex ],
  25084. binding = bindingsForPath[ index ];
  25085. bindingsForPath[ index ] = firstActive;
  25086. bindingsForPath[ lastCachedIndex ] = binding;
  25087. }
  25088. }
  25089. } // for arguments
  25090. this.nCachedObjects_ = nCachedObjects;
  25091. },
  25092. // remove & forget
  25093. uncache: function () {
  25094. var objects = this._objects,
  25095. nObjects = objects.length,
  25096. nCachedObjects = this.nCachedObjects_,
  25097. indicesByUUID = this._indicesByUUID,
  25098. bindings = this._bindings,
  25099. nBindings = bindings.length;
  25100. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25101. var object = arguments[ i ],
  25102. uuid = object.uuid,
  25103. index = indicesByUUID[ uuid ];
  25104. if ( index !== undefined ) {
  25105. delete indicesByUUID[ uuid ];
  25106. if ( index < nCachedObjects ) {
  25107. // object is cached, shrink the CACHED region
  25108. var firstActiveIndex = -- nCachedObjects,
  25109. lastCachedObject = objects[ firstActiveIndex ],
  25110. lastIndex = -- nObjects,
  25111. lastObject = objects[ lastIndex ];
  25112. // last cached object takes this object's place
  25113. indicesByUUID[ lastCachedObject.uuid ] = index;
  25114. objects[ index ] = lastCachedObject;
  25115. // last object goes to the activated slot and pop
  25116. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25117. objects[ firstActiveIndex ] = lastObject;
  25118. objects.pop();
  25119. // accounting is done, now do the same for all bindings
  25120. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25121. var bindingsForPath = bindings[ j ],
  25122. lastCached = bindingsForPath[ firstActiveIndex ],
  25123. last = bindingsForPath[ lastIndex ];
  25124. bindingsForPath[ index ] = lastCached;
  25125. bindingsForPath[ firstActiveIndex ] = last;
  25126. bindingsForPath.pop();
  25127. }
  25128. } else {
  25129. // object is active, just swap with the last and pop
  25130. var lastIndex = -- nObjects,
  25131. lastObject = objects[ lastIndex ];
  25132. indicesByUUID[ lastObject.uuid ] = index;
  25133. objects[ index ] = lastObject;
  25134. objects.pop();
  25135. // accounting is done, now do the same for all bindings
  25136. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25137. var bindingsForPath = bindings[ j ];
  25138. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25139. bindingsForPath.pop();
  25140. }
  25141. } // cached or active
  25142. } // if object is known
  25143. } // for arguments
  25144. this.nCachedObjects_ = nCachedObjects;
  25145. },
  25146. // Internal interface used by befriended PropertyBinding.Composite:
  25147. subscribe_: function ( path, parsedPath ) {
  25148. // returns an array of bindings for the given path that is changed
  25149. // according to the contained objects in the group
  25150. var indicesByPath = this._bindingsIndicesByPath,
  25151. index = indicesByPath[ path ],
  25152. bindings = this._bindings;
  25153. if ( index !== undefined ) return bindings[ index ];
  25154. var paths = this._paths,
  25155. parsedPaths = this._parsedPaths,
  25156. objects = this._objects,
  25157. nObjects = objects.length,
  25158. nCachedObjects = this.nCachedObjects_,
  25159. bindingsForPath = new Array( nObjects );
  25160. index = bindings.length;
  25161. indicesByPath[ path ] = index;
  25162. paths.push( path );
  25163. parsedPaths.push( parsedPath );
  25164. bindings.push( bindingsForPath );
  25165. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25166. var object = objects[ i ];
  25167. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25168. }
  25169. return bindingsForPath;
  25170. },
  25171. unsubscribe_: function ( path ) {
  25172. // tells the group to forget about a property path and no longer
  25173. // update the array previously obtained with 'subscribe_'
  25174. var indicesByPath = this._bindingsIndicesByPath,
  25175. index = indicesByPath[ path ];
  25176. if ( index !== undefined ) {
  25177. var paths = this._paths,
  25178. parsedPaths = this._parsedPaths,
  25179. bindings = this._bindings,
  25180. lastBindingsIndex = bindings.length - 1,
  25181. lastBindings = bindings[ lastBindingsIndex ],
  25182. lastBindingsPath = path[ lastBindingsIndex ];
  25183. indicesByPath[ lastBindingsPath ] = index;
  25184. bindings[ index ] = lastBindings;
  25185. bindings.pop();
  25186. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25187. parsedPaths.pop();
  25188. paths[ index ] = paths[ lastBindingsIndex ];
  25189. paths.pop();
  25190. }
  25191. }
  25192. } );
  25193. /**
  25194. *
  25195. * Action provided by AnimationMixer for scheduling clip playback on specific
  25196. * objects.
  25197. *
  25198. * @author Ben Houston / http://clara.io/
  25199. * @author David Sarno / http://lighthaus.us/
  25200. * @author tschw
  25201. *
  25202. */
  25203. function AnimationAction( mixer, clip, localRoot ) {
  25204. this._mixer = mixer;
  25205. this._clip = clip;
  25206. this._localRoot = localRoot || null;
  25207. var tracks = clip.tracks,
  25208. nTracks = tracks.length,
  25209. interpolants = new Array( nTracks );
  25210. var interpolantSettings = {
  25211. endingStart: ZeroCurvatureEnding,
  25212. endingEnd: ZeroCurvatureEnding
  25213. };
  25214. for ( var i = 0; i !== nTracks; ++ i ) {
  25215. var interpolant = tracks[ i ].createInterpolant( null );
  25216. interpolants[ i ] = interpolant;
  25217. interpolant.settings = interpolantSettings;
  25218. }
  25219. this._interpolantSettings = interpolantSettings;
  25220. this._interpolants = interpolants; // bound by the mixer
  25221. // inside: PropertyMixer (managed by the mixer)
  25222. this._propertyBindings = new Array( nTracks );
  25223. this._cacheIndex = null; // for the memory manager
  25224. this._byClipCacheIndex = null; // for the memory manager
  25225. this._timeScaleInterpolant = null;
  25226. this._weightInterpolant = null;
  25227. this.loop = LoopRepeat;
  25228. this._loopCount = - 1;
  25229. // global mixer time when the action is to be started
  25230. // it's set back to 'null' upon start of the action
  25231. this._startTime = null;
  25232. // scaled local time of the action
  25233. // gets clamped or wrapped to 0..clip.duration according to loop
  25234. this.time = 0;
  25235. this.timeScale = 1;
  25236. this._effectiveTimeScale = 1;
  25237. this.weight = 1;
  25238. this._effectiveWeight = 1;
  25239. this.repetitions = Infinity; // no. of repetitions when looping
  25240. this.paused = false; // true -> zero effective time scale
  25241. this.enabled = true; // false -> zero effective weight
  25242. this.clampWhenFinished = false;// keep feeding the last frame?
  25243. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25244. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25245. }
  25246. Object.assign( AnimationAction.prototype, {
  25247. // State & Scheduling
  25248. play: function () {
  25249. this._mixer._activateAction( this );
  25250. return this;
  25251. },
  25252. stop: function () {
  25253. this._mixer._deactivateAction( this );
  25254. return this.reset();
  25255. },
  25256. reset: function () {
  25257. this.paused = false;
  25258. this.enabled = true;
  25259. this.time = 0; // restart clip
  25260. this._loopCount = - 1;// forget previous loops
  25261. this._startTime = null;// forget scheduling
  25262. return this.stopFading().stopWarping();
  25263. },
  25264. isRunning: function () {
  25265. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25266. this._startTime === null && this._mixer._isActiveAction( this );
  25267. },
  25268. // return true when play has been called
  25269. isScheduled: function () {
  25270. return this._mixer._isActiveAction( this );
  25271. },
  25272. startAt: function ( time ) {
  25273. this._startTime = time;
  25274. return this;
  25275. },
  25276. setLoop: function ( mode, repetitions ) {
  25277. this.loop = mode;
  25278. this.repetitions = repetitions;
  25279. return this;
  25280. },
  25281. // Weight
  25282. // set the weight stopping any scheduled fading
  25283. // although .enabled = false yields an effective weight of zero, this
  25284. // method does *not* change .enabled, because it would be confusing
  25285. setEffectiveWeight: function ( weight ) {
  25286. this.weight = weight;
  25287. // note: same logic as when updated at runtime
  25288. this._effectiveWeight = this.enabled ? weight : 0;
  25289. return this.stopFading();
  25290. },
  25291. // return the weight considering fading and .enabled
  25292. getEffectiveWeight: function () {
  25293. return this._effectiveWeight;
  25294. },
  25295. fadeIn: function ( duration ) {
  25296. return this._scheduleFading( duration, 0, 1 );
  25297. },
  25298. fadeOut: function ( duration ) {
  25299. return this._scheduleFading( duration, 1, 0 );
  25300. },
  25301. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25302. fadeOutAction.fadeOut( duration );
  25303. this.fadeIn( duration );
  25304. if ( warp ) {
  25305. var fadeInDuration = this._clip.duration,
  25306. fadeOutDuration = fadeOutAction._clip.duration,
  25307. startEndRatio = fadeOutDuration / fadeInDuration,
  25308. endStartRatio = fadeInDuration / fadeOutDuration;
  25309. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25310. this.warp( endStartRatio, 1.0, duration );
  25311. }
  25312. return this;
  25313. },
  25314. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25315. return fadeInAction.crossFadeFrom( this, duration, warp );
  25316. },
  25317. stopFading: function () {
  25318. var weightInterpolant = this._weightInterpolant;
  25319. if ( weightInterpolant !== null ) {
  25320. this._weightInterpolant = null;
  25321. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25322. }
  25323. return this;
  25324. },
  25325. // Time Scale Control
  25326. // set the time scale stopping any scheduled warping
  25327. // although .paused = true yields an effective time scale of zero, this
  25328. // method does *not* change .paused, because it would be confusing
  25329. setEffectiveTimeScale: function ( timeScale ) {
  25330. this.timeScale = timeScale;
  25331. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25332. return this.stopWarping();
  25333. },
  25334. // return the time scale considering warping and .paused
  25335. getEffectiveTimeScale: function () {
  25336. return this._effectiveTimeScale;
  25337. },
  25338. setDuration: function ( duration ) {
  25339. this.timeScale = this._clip.duration / duration;
  25340. return this.stopWarping();
  25341. },
  25342. syncWith: function ( action ) {
  25343. this.time = action.time;
  25344. this.timeScale = action.timeScale;
  25345. return this.stopWarping();
  25346. },
  25347. halt: function ( duration ) {
  25348. return this.warp( this._effectiveTimeScale, 0, duration );
  25349. },
  25350. warp: function ( startTimeScale, endTimeScale, duration ) {
  25351. var mixer = this._mixer, now = mixer.time,
  25352. interpolant = this._timeScaleInterpolant,
  25353. timeScale = this.timeScale;
  25354. if ( interpolant === null ) {
  25355. interpolant = mixer._lendControlInterpolant();
  25356. this._timeScaleInterpolant = interpolant;
  25357. }
  25358. var times = interpolant.parameterPositions,
  25359. values = interpolant.sampleValues;
  25360. times[ 0 ] = now;
  25361. times[ 1 ] = now + duration;
  25362. values[ 0 ] = startTimeScale / timeScale;
  25363. values[ 1 ] = endTimeScale / timeScale;
  25364. return this;
  25365. },
  25366. stopWarping: function () {
  25367. var timeScaleInterpolant = this._timeScaleInterpolant;
  25368. if ( timeScaleInterpolant !== null ) {
  25369. this._timeScaleInterpolant = null;
  25370. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25371. }
  25372. return this;
  25373. },
  25374. // Object Accessors
  25375. getMixer: function () {
  25376. return this._mixer;
  25377. },
  25378. getClip: function () {
  25379. return this._clip;
  25380. },
  25381. getRoot: function () {
  25382. return this._localRoot || this._mixer._root;
  25383. },
  25384. // Interna
  25385. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25386. // called by the mixer
  25387. if ( ! this.enabled ) {
  25388. // call ._updateWeight() to update ._effectiveWeight
  25389. this._updateWeight( time );
  25390. return;
  25391. }
  25392. var startTime = this._startTime;
  25393. if ( startTime !== null ) {
  25394. // check for scheduled start of action
  25395. var timeRunning = ( time - startTime ) * timeDirection;
  25396. if ( timeRunning < 0 || timeDirection === 0 ) {
  25397. return; // yet to come / don't decide when delta = 0
  25398. }
  25399. // start
  25400. this._startTime = null; // unschedule
  25401. deltaTime = timeDirection * timeRunning;
  25402. }
  25403. // apply time scale and advance time
  25404. deltaTime *= this._updateTimeScale( time );
  25405. var clipTime = this._updateTime( deltaTime );
  25406. // note: _updateTime may disable the action resulting in
  25407. // an effective weight of 0
  25408. var weight = this._updateWeight( time );
  25409. if ( weight > 0 ) {
  25410. var interpolants = this._interpolants;
  25411. var propertyMixers = this._propertyBindings;
  25412. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25413. interpolants[ j ].evaluate( clipTime );
  25414. propertyMixers[ j ].accumulate( accuIndex, weight );
  25415. }
  25416. }
  25417. },
  25418. _updateWeight: function ( time ) {
  25419. var weight = 0;
  25420. if ( this.enabled ) {
  25421. weight = this.weight;
  25422. var interpolant = this._weightInterpolant;
  25423. if ( interpolant !== null ) {
  25424. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25425. weight *= interpolantValue;
  25426. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25427. this.stopFading();
  25428. if ( interpolantValue === 0 ) {
  25429. // faded out, disable
  25430. this.enabled = false;
  25431. }
  25432. }
  25433. }
  25434. }
  25435. this._effectiveWeight = weight;
  25436. return weight;
  25437. },
  25438. _updateTimeScale: function ( time ) {
  25439. var timeScale = 0;
  25440. if ( ! this.paused ) {
  25441. timeScale = this.timeScale;
  25442. var interpolant = this._timeScaleInterpolant;
  25443. if ( interpolant !== null ) {
  25444. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25445. timeScale *= interpolantValue;
  25446. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25447. this.stopWarping();
  25448. if ( timeScale === 0 ) {
  25449. // motion has halted, pause
  25450. this.paused = true;
  25451. } else {
  25452. // warp done - apply final time scale
  25453. this.timeScale = timeScale;
  25454. }
  25455. }
  25456. }
  25457. }
  25458. this._effectiveTimeScale = timeScale;
  25459. return timeScale;
  25460. },
  25461. _updateTime: function ( deltaTime ) {
  25462. var time = this.time + deltaTime;
  25463. var duration = this._clip.duration;
  25464. var loop = this.loop;
  25465. var loopCount = this._loopCount;
  25466. var pingPong = ( loop === LoopPingPong );
  25467. if ( deltaTime === 0 ) {
  25468. if ( loopCount === - 1 ) return time;
  25469. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25470. }
  25471. if ( loop === LoopOnce ) {
  25472. if ( loopCount === - 1 ) {
  25473. // just started
  25474. this._loopCount = 0;
  25475. this._setEndings( true, true, false );
  25476. }
  25477. handle_stop: {
  25478. if ( time >= duration ) {
  25479. time = duration;
  25480. } else if ( time < 0 ) {
  25481. time = 0;
  25482. } else break handle_stop;
  25483. if ( this.clampWhenFinished ) this.paused = true;
  25484. else this.enabled = false;
  25485. this._mixer.dispatchEvent( {
  25486. type: 'finished', action: this,
  25487. direction: deltaTime < 0 ? - 1 : 1
  25488. } );
  25489. }
  25490. } else { // repetitive Repeat or PingPong
  25491. if ( loopCount === - 1 ) {
  25492. // just started
  25493. if ( deltaTime >= 0 ) {
  25494. loopCount = 0;
  25495. this._setEndings( true, this.repetitions === 0, pingPong );
  25496. } else {
  25497. // when looping in reverse direction, the initial
  25498. // transition through zero counts as a repetition,
  25499. // so leave loopCount at -1
  25500. this._setEndings( this.repetitions === 0, true, pingPong );
  25501. }
  25502. }
  25503. if ( time >= duration || time < 0 ) {
  25504. // wrap around
  25505. var loopDelta = Math.floor( time / duration ); // signed
  25506. time -= duration * loopDelta;
  25507. loopCount += Math.abs( loopDelta );
  25508. var pending = this.repetitions - loopCount;
  25509. if ( pending <= 0 ) {
  25510. // have to stop (switch state, clamp time, fire event)
  25511. if ( this.clampWhenFinished ) this.paused = true;
  25512. else this.enabled = false;
  25513. time = deltaTime > 0 ? duration : 0;
  25514. this._mixer.dispatchEvent( {
  25515. type: 'finished', action: this,
  25516. direction: deltaTime > 0 ? 1 : - 1
  25517. } );
  25518. } else {
  25519. // keep running
  25520. if ( pending === 1 ) {
  25521. // entering the last round
  25522. var atStart = deltaTime < 0;
  25523. this._setEndings( atStart, ! atStart, pingPong );
  25524. } else {
  25525. this._setEndings( false, false, pingPong );
  25526. }
  25527. this._loopCount = loopCount;
  25528. this._mixer.dispatchEvent( {
  25529. type: 'loop', action: this, loopDelta: loopDelta
  25530. } );
  25531. }
  25532. }
  25533. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25534. // invert time for the "pong round"
  25535. this.time = time;
  25536. return duration - time;
  25537. }
  25538. }
  25539. this.time = time;
  25540. return time;
  25541. },
  25542. _setEndings: function ( atStart, atEnd, pingPong ) {
  25543. var settings = this._interpolantSettings;
  25544. if ( pingPong ) {
  25545. settings.endingStart = ZeroSlopeEnding;
  25546. settings.endingEnd = ZeroSlopeEnding;
  25547. } else {
  25548. // assuming for LoopOnce atStart == atEnd == true
  25549. if ( atStart ) {
  25550. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25551. } else {
  25552. settings.endingStart = WrapAroundEnding;
  25553. }
  25554. if ( atEnd ) {
  25555. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25556. } else {
  25557. settings.endingEnd = WrapAroundEnding;
  25558. }
  25559. }
  25560. },
  25561. _scheduleFading: function ( duration, weightNow, weightThen ) {
  25562. var mixer = this._mixer, now = mixer.time,
  25563. interpolant = this._weightInterpolant;
  25564. if ( interpolant === null ) {
  25565. interpolant = mixer._lendControlInterpolant();
  25566. this._weightInterpolant = interpolant;
  25567. }
  25568. var times = interpolant.parameterPositions,
  25569. values = interpolant.sampleValues;
  25570. times[ 0 ] = now;
  25571. values[ 0 ] = weightNow;
  25572. times[ 1 ] = now + duration;
  25573. values[ 1 ] = weightThen;
  25574. return this;
  25575. }
  25576. } );
  25577. /**
  25578. *
  25579. * Player for AnimationClips.
  25580. *
  25581. *
  25582. * @author Ben Houston / http://clara.io/
  25583. * @author David Sarno / http://lighthaus.us/
  25584. * @author tschw
  25585. */
  25586. function AnimationMixer( root ) {
  25587. this._root = root;
  25588. this._initMemoryManager();
  25589. this._accuIndex = 0;
  25590. this.time = 0;
  25591. this.timeScale = 1.0;
  25592. }
  25593. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  25594. constructor: AnimationMixer,
  25595. _bindAction: function ( action, prototypeAction ) {
  25596. var root = action._localRoot || this._root,
  25597. tracks = action._clip.tracks,
  25598. nTracks = tracks.length,
  25599. bindings = action._propertyBindings,
  25600. interpolants = action._interpolants,
  25601. rootUuid = root.uuid,
  25602. bindingsByRoot = this._bindingsByRootAndName,
  25603. bindingsByName = bindingsByRoot[ rootUuid ];
  25604. if ( bindingsByName === undefined ) {
  25605. bindingsByName = {};
  25606. bindingsByRoot[ rootUuid ] = bindingsByName;
  25607. }
  25608. for ( var i = 0; i !== nTracks; ++ i ) {
  25609. var track = tracks[ i ],
  25610. trackName = track.name,
  25611. binding = bindingsByName[ trackName ];
  25612. if ( binding !== undefined ) {
  25613. bindings[ i ] = binding;
  25614. } else {
  25615. binding = bindings[ i ];
  25616. if ( binding !== undefined ) {
  25617. // existing binding, make sure the cache knows
  25618. if ( binding._cacheIndex === null ) {
  25619. ++ binding.referenceCount;
  25620. this._addInactiveBinding( binding, rootUuid, trackName );
  25621. }
  25622. continue;
  25623. }
  25624. var path = prototypeAction && prototypeAction.
  25625. _propertyBindings[ i ].binding.parsedPath;
  25626. binding = new PropertyMixer(
  25627. PropertyBinding.create( root, trackName, path ),
  25628. track.ValueTypeName, track.getValueSize() );
  25629. ++ binding.referenceCount;
  25630. this._addInactiveBinding( binding, rootUuid, trackName );
  25631. bindings[ i ] = binding;
  25632. }
  25633. interpolants[ i ].resultBuffer = binding.buffer;
  25634. }
  25635. },
  25636. _activateAction: function ( action ) {
  25637. if ( ! this._isActiveAction( action ) ) {
  25638. if ( action._cacheIndex === null ) {
  25639. // this action has been forgotten by the cache, but the user
  25640. // appears to be still using it -> rebind
  25641. var rootUuid = ( action._localRoot || this._root ).uuid,
  25642. clipUuid = action._clip.uuid,
  25643. actionsForClip = this._actionsByClip[ clipUuid ];
  25644. this._bindAction( action,
  25645. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25646. this._addInactiveAction( action, clipUuid, rootUuid );
  25647. }
  25648. var bindings = action._propertyBindings;
  25649. // increment reference counts / sort out state
  25650. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25651. var binding = bindings[ i ];
  25652. if ( binding.useCount ++ === 0 ) {
  25653. this._lendBinding( binding );
  25654. binding.saveOriginalState();
  25655. }
  25656. }
  25657. this._lendAction( action );
  25658. }
  25659. },
  25660. _deactivateAction: function ( action ) {
  25661. if ( this._isActiveAction( action ) ) {
  25662. var bindings = action._propertyBindings;
  25663. // decrement reference counts / sort out state
  25664. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25665. var binding = bindings[ i ];
  25666. if ( -- binding.useCount === 0 ) {
  25667. binding.restoreOriginalState();
  25668. this._takeBackBinding( binding );
  25669. }
  25670. }
  25671. this._takeBackAction( action );
  25672. }
  25673. },
  25674. // Memory manager
  25675. _initMemoryManager: function () {
  25676. this._actions = []; // 'nActiveActions' followed by inactive ones
  25677. this._nActiveActions = 0;
  25678. this._actionsByClip = {};
  25679. // inside:
  25680. // {
  25681. // knownActions: Array< AnimationAction > - used as prototypes
  25682. // actionByRoot: AnimationAction - lookup
  25683. // }
  25684. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25685. this._nActiveBindings = 0;
  25686. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25687. this._controlInterpolants = []; // same game as above
  25688. this._nActiveControlInterpolants = 0;
  25689. var scope = this;
  25690. this.stats = {
  25691. actions: {
  25692. get total() {
  25693. return scope._actions.length;
  25694. },
  25695. get inUse() {
  25696. return scope._nActiveActions;
  25697. }
  25698. },
  25699. bindings: {
  25700. get total() {
  25701. return scope._bindings.length;
  25702. },
  25703. get inUse() {
  25704. return scope._nActiveBindings;
  25705. }
  25706. },
  25707. controlInterpolants: {
  25708. get total() {
  25709. return scope._controlInterpolants.length;
  25710. },
  25711. get inUse() {
  25712. return scope._nActiveControlInterpolants;
  25713. }
  25714. }
  25715. };
  25716. },
  25717. // Memory management for AnimationAction objects
  25718. _isActiveAction: function ( action ) {
  25719. var index = action._cacheIndex;
  25720. return index !== null && index < this._nActiveActions;
  25721. },
  25722. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  25723. var actions = this._actions,
  25724. actionsByClip = this._actionsByClip,
  25725. actionsForClip = actionsByClip[ clipUuid ];
  25726. if ( actionsForClip === undefined ) {
  25727. actionsForClip = {
  25728. knownActions: [ action ],
  25729. actionByRoot: {}
  25730. };
  25731. action._byClipCacheIndex = 0;
  25732. actionsByClip[ clipUuid ] = actionsForClip;
  25733. } else {
  25734. var knownActions = actionsForClip.knownActions;
  25735. action._byClipCacheIndex = knownActions.length;
  25736. knownActions.push( action );
  25737. }
  25738. action._cacheIndex = actions.length;
  25739. actions.push( action );
  25740. actionsForClip.actionByRoot[ rootUuid ] = action;
  25741. },
  25742. _removeInactiveAction: function ( action ) {
  25743. var actions = this._actions,
  25744. lastInactiveAction = actions[ actions.length - 1 ],
  25745. cacheIndex = action._cacheIndex;
  25746. lastInactiveAction._cacheIndex = cacheIndex;
  25747. actions[ cacheIndex ] = lastInactiveAction;
  25748. actions.pop();
  25749. action._cacheIndex = null;
  25750. var clipUuid = action._clip.uuid,
  25751. actionsByClip = this._actionsByClip,
  25752. actionsForClip = actionsByClip[ clipUuid ],
  25753. knownActionsForClip = actionsForClip.knownActions,
  25754. lastKnownAction =
  25755. knownActionsForClip[ knownActionsForClip.length - 1 ],
  25756. byClipCacheIndex = action._byClipCacheIndex;
  25757. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  25758. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  25759. knownActionsForClip.pop();
  25760. action._byClipCacheIndex = null;
  25761. var actionByRoot = actionsForClip.actionByRoot,
  25762. rootUuid = ( action._localRoot || this._root ).uuid;
  25763. delete actionByRoot[ rootUuid ];
  25764. if ( knownActionsForClip.length === 0 ) {
  25765. delete actionsByClip[ clipUuid ];
  25766. }
  25767. this._removeInactiveBindingsForAction( action );
  25768. },
  25769. _removeInactiveBindingsForAction: function ( action ) {
  25770. var bindings = action._propertyBindings;
  25771. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25772. var binding = bindings[ i ];
  25773. if ( -- binding.referenceCount === 0 ) {
  25774. this._removeInactiveBinding( binding );
  25775. }
  25776. }
  25777. },
  25778. _lendAction: function ( action ) {
  25779. // [ active actions | inactive actions ]
  25780. // [ active actions >| inactive actions ]
  25781. // s a
  25782. // <-swap->
  25783. // a s
  25784. var actions = this._actions,
  25785. prevIndex = action._cacheIndex,
  25786. lastActiveIndex = this._nActiveActions ++,
  25787. firstInactiveAction = actions[ lastActiveIndex ];
  25788. action._cacheIndex = lastActiveIndex;
  25789. actions[ lastActiveIndex ] = action;
  25790. firstInactiveAction._cacheIndex = prevIndex;
  25791. actions[ prevIndex ] = firstInactiveAction;
  25792. },
  25793. _takeBackAction: function ( action ) {
  25794. // [ active actions | inactive actions ]
  25795. // [ active actions |< inactive actions ]
  25796. // a s
  25797. // <-swap->
  25798. // s a
  25799. var actions = this._actions,
  25800. prevIndex = action._cacheIndex,
  25801. firstInactiveIndex = -- this._nActiveActions,
  25802. lastActiveAction = actions[ firstInactiveIndex ];
  25803. action._cacheIndex = firstInactiveIndex;
  25804. actions[ firstInactiveIndex ] = action;
  25805. lastActiveAction._cacheIndex = prevIndex;
  25806. actions[ prevIndex ] = lastActiveAction;
  25807. },
  25808. // Memory management for PropertyMixer objects
  25809. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  25810. var bindingsByRoot = this._bindingsByRootAndName,
  25811. bindingByName = bindingsByRoot[ rootUuid ],
  25812. bindings = this._bindings;
  25813. if ( bindingByName === undefined ) {
  25814. bindingByName = {};
  25815. bindingsByRoot[ rootUuid ] = bindingByName;
  25816. }
  25817. bindingByName[ trackName ] = binding;
  25818. binding._cacheIndex = bindings.length;
  25819. bindings.push( binding );
  25820. },
  25821. _removeInactiveBinding: function ( binding ) {
  25822. var bindings = this._bindings,
  25823. propBinding = binding.binding,
  25824. rootUuid = propBinding.rootNode.uuid,
  25825. trackName = propBinding.path,
  25826. bindingsByRoot = this._bindingsByRootAndName,
  25827. bindingByName = bindingsByRoot[ rootUuid ],
  25828. lastInactiveBinding = bindings[ bindings.length - 1 ],
  25829. cacheIndex = binding._cacheIndex;
  25830. lastInactiveBinding._cacheIndex = cacheIndex;
  25831. bindings[ cacheIndex ] = lastInactiveBinding;
  25832. bindings.pop();
  25833. delete bindingByName[ trackName ];
  25834. remove_empty_map: {
  25835. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  25836. delete bindingsByRoot[ rootUuid ];
  25837. }
  25838. },
  25839. _lendBinding: function ( binding ) {
  25840. var bindings = this._bindings,
  25841. prevIndex = binding._cacheIndex,
  25842. lastActiveIndex = this._nActiveBindings ++,
  25843. firstInactiveBinding = bindings[ lastActiveIndex ];
  25844. binding._cacheIndex = lastActiveIndex;
  25845. bindings[ lastActiveIndex ] = binding;
  25846. firstInactiveBinding._cacheIndex = prevIndex;
  25847. bindings[ prevIndex ] = firstInactiveBinding;
  25848. },
  25849. _takeBackBinding: function ( binding ) {
  25850. var bindings = this._bindings,
  25851. prevIndex = binding._cacheIndex,
  25852. firstInactiveIndex = -- this._nActiveBindings,
  25853. lastActiveBinding = bindings[ firstInactiveIndex ];
  25854. binding._cacheIndex = firstInactiveIndex;
  25855. bindings[ firstInactiveIndex ] = binding;
  25856. lastActiveBinding._cacheIndex = prevIndex;
  25857. bindings[ prevIndex ] = lastActiveBinding;
  25858. },
  25859. // Memory management of Interpolants for weight and time scale
  25860. _lendControlInterpolant: function () {
  25861. var interpolants = this._controlInterpolants,
  25862. lastActiveIndex = this._nActiveControlInterpolants ++,
  25863. interpolant = interpolants[ lastActiveIndex ];
  25864. if ( interpolant === undefined ) {
  25865. interpolant = new LinearInterpolant(
  25866. new Float32Array( 2 ), new Float32Array( 2 ),
  25867. 1, this._controlInterpolantsResultBuffer );
  25868. interpolant.__cacheIndex = lastActiveIndex;
  25869. interpolants[ lastActiveIndex ] = interpolant;
  25870. }
  25871. return interpolant;
  25872. },
  25873. _takeBackControlInterpolant: function ( interpolant ) {
  25874. var interpolants = this._controlInterpolants,
  25875. prevIndex = interpolant.__cacheIndex,
  25876. firstInactiveIndex = -- this._nActiveControlInterpolants,
  25877. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  25878. interpolant.__cacheIndex = firstInactiveIndex;
  25879. interpolants[ firstInactiveIndex ] = interpolant;
  25880. lastActiveInterpolant.__cacheIndex = prevIndex;
  25881. interpolants[ prevIndex ] = lastActiveInterpolant;
  25882. },
  25883. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  25884. // return an action for a clip optionally using a custom root target
  25885. // object (this method allocates a lot of dynamic memory in case a
  25886. // previously unknown clip/root combination is specified)
  25887. clipAction: function ( clip, optionalRoot ) {
  25888. var root = optionalRoot || this._root,
  25889. rootUuid = root.uuid,
  25890. clipObject = typeof clip === 'string' ?
  25891. AnimationClip.findByName( root, clip ) : clip,
  25892. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  25893. actionsForClip = this._actionsByClip[ clipUuid ],
  25894. prototypeAction = null;
  25895. if ( actionsForClip !== undefined ) {
  25896. var existingAction =
  25897. actionsForClip.actionByRoot[ rootUuid ];
  25898. if ( existingAction !== undefined ) {
  25899. return existingAction;
  25900. }
  25901. // we know the clip, so we don't have to parse all
  25902. // the bindings again but can just copy
  25903. prototypeAction = actionsForClip.knownActions[ 0 ];
  25904. // also, take the clip from the prototype action
  25905. if ( clipObject === null )
  25906. clipObject = prototypeAction._clip;
  25907. }
  25908. // clip must be known when specified via string
  25909. if ( clipObject === null ) return null;
  25910. // allocate all resources required to run it
  25911. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  25912. this._bindAction( newAction, prototypeAction );
  25913. // and make the action known to the memory manager
  25914. this._addInactiveAction( newAction, clipUuid, rootUuid );
  25915. return newAction;
  25916. },
  25917. // get an existing action
  25918. existingAction: function ( clip, optionalRoot ) {
  25919. var root = optionalRoot || this._root,
  25920. rootUuid = root.uuid,
  25921. clipObject = typeof clip === 'string' ?
  25922. AnimationClip.findByName( root, clip ) : clip,
  25923. clipUuid = clipObject ? clipObject.uuid : clip,
  25924. actionsForClip = this._actionsByClip[ clipUuid ];
  25925. if ( actionsForClip !== undefined ) {
  25926. return actionsForClip.actionByRoot[ rootUuid ] || null;
  25927. }
  25928. return null;
  25929. },
  25930. // deactivates all previously scheduled actions
  25931. stopAllAction: function () {
  25932. var actions = this._actions,
  25933. nActions = this._nActiveActions,
  25934. bindings = this._bindings,
  25935. nBindings = this._nActiveBindings;
  25936. this._nActiveActions = 0;
  25937. this._nActiveBindings = 0;
  25938. for ( var i = 0; i !== nActions; ++ i ) {
  25939. actions[ i ].reset();
  25940. }
  25941. for ( var i = 0; i !== nBindings; ++ i ) {
  25942. bindings[ i ].useCount = 0;
  25943. }
  25944. return this;
  25945. },
  25946. // advance the time and update apply the animation
  25947. update: function ( deltaTime ) {
  25948. deltaTime *= this.timeScale;
  25949. var actions = this._actions,
  25950. nActions = this._nActiveActions,
  25951. time = this.time += deltaTime,
  25952. timeDirection = Math.sign( deltaTime ),
  25953. accuIndex = this._accuIndex ^= 1;
  25954. // run active actions
  25955. for ( var i = 0; i !== nActions; ++ i ) {
  25956. var action = actions[ i ];
  25957. action._update( time, deltaTime, timeDirection, accuIndex );
  25958. }
  25959. // update scene graph
  25960. var bindings = this._bindings,
  25961. nBindings = this._nActiveBindings;
  25962. for ( var i = 0; i !== nBindings; ++ i ) {
  25963. bindings[ i ].apply( accuIndex );
  25964. }
  25965. return this;
  25966. },
  25967. // return this mixer's root target object
  25968. getRoot: function () {
  25969. return this._root;
  25970. },
  25971. // free all resources specific to a particular clip
  25972. uncacheClip: function ( clip ) {
  25973. var actions = this._actions,
  25974. clipUuid = clip.uuid,
  25975. actionsByClip = this._actionsByClip,
  25976. actionsForClip = actionsByClip[ clipUuid ];
  25977. if ( actionsForClip !== undefined ) {
  25978. // note: just calling _removeInactiveAction would mess up the
  25979. // iteration state and also require updating the state we can
  25980. // just throw away
  25981. var actionsToRemove = actionsForClip.knownActions;
  25982. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  25983. var action = actionsToRemove[ i ];
  25984. this._deactivateAction( action );
  25985. var cacheIndex = action._cacheIndex,
  25986. lastInactiveAction = actions[ actions.length - 1 ];
  25987. action._cacheIndex = null;
  25988. action._byClipCacheIndex = null;
  25989. lastInactiveAction._cacheIndex = cacheIndex;
  25990. actions[ cacheIndex ] = lastInactiveAction;
  25991. actions.pop();
  25992. this._removeInactiveBindingsForAction( action );
  25993. }
  25994. delete actionsByClip[ clipUuid ];
  25995. }
  25996. },
  25997. // free all resources specific to a particular root target object
  25998. uncacheRoot: function ( root ) {
  25999. var rootUuid = root.uuid,
  26000. actionsByClip = this._actionsByClip;
  26001. for ( var clipUuid in actionsByClip ) {
  26002. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26003. action = actionByRoot[ rootUuid ];
  26004. if ( action !== undefined ) {
  26005. this._deactivateAction( action );
  26006. this._removeInactiveAction( action );
  26007. }
  26008. }
  26009. var bindingsByRoot = this._bindingsByRootAndName,
  26010. bindingByName = bindingsByRoot[ rootUuid ];
  26011. if ( bindingByName !== undefined ) {
  26012. for ( var trackName in bindingByName ) {
  26013. var binding = bindingByName[ trackName ];
  26014. binding.restoreOriginalState();
  26015. this._removeInactiveBinding( binding );
  26016. }
  26017. }
  26018. },
  26019. // remove a targeted clip from the cache
  26020. uncacheAction: function ( clip, optionalRoot ) {
  26021. var action = this.existingAction( clip, optionalRoot );
  26022. if ( action !== null ) {
  26023. this._deactivateAction( action );
  26024. this._removeInactiveAction( action );
  26025. }
  26026. }
  26027. } );
  26028. /**
  26029. * @author mrdoob / http://mrdoob.com/
  26030. */
  26031. function Uniform( value ) {
  26032. if ( typeof value === 'string' ) {
  26033. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26034. value = arguments[ 1 ];
  26035. }
  26036. this.value = value;
  26037. }
  26038. Uniform.prototype.clone = function () {
  26039. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26040. };
  26041. /**
  26042. * @author benaadams / https://twitter.com/ben_a_adams
  26043. */
  26044. function InstancedBufferGeometry() {
  26045. BufferGeometry.call( this );
  26046. this.type = 'InstancedBufferGeometry';
  26047. this.maxInstancedCount = undefined;
  26048. }
  26049. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  26050. constructor: InstancedBufferGeometry,
  26051. isInstancedBufferGeometry: true,
  26052. copy: function ( source ) {
  26053. BufferGeometry.prototype.copy.call( this, source );
  26054. this.maxInstancedCount = source.maxInstancedCount;
  26055. return this;
  26056. },
  26057. clone: function () {
  26058. return new this.constructor().copy( this );
  26059. }
  26060. } );
  26061. /**
  26062. * @author benaadams / https://twitter.com/ben_a_adams
  26063. */
  26064. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26065. InterleavedBuffer.call( this, array, stride );
  26066. this.meshPerAttribute = meshPerAttribute || 1;
  26067. }
  26068. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26069. constructor: InstancedInterleavedBuffer,
  26070. isInstancedInterleavedBuffer: true,
  26071. copy: function ( source ) {
  26072. InterleavedBuffer.prototype.copy.call( this, source );
  26073. this.meshPerAttribute = source.meshPerAttribute;
  26074. return this;
  26075. }
  26076. } );
  26077. /**
  26078. * @author benaadams / https://twitter.com/ben_a_adams
  26079. */
  26080. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  26081. if ( typeof ( normalized ) === 'number' ) {
  26082. meshPerAttribute = normalized;
  26083. normalized = false;
  26084. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  26085. }
  26086. BufferAttribute.call( this, array, itemSize, normalized );
  26087. this.meshPerAttribute = meshPerAttribute || 1;
  26088. }
  26089. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  26090. constructor: InstancedBufferAttribute,
  26091. isInstancedBufferAttribute: true,
  26092. copy: function ( source ) {
  26093. BufferAttribute.prototype.copy.call( this, source );
  26094. this.meshPerAttribute = source.meshPerAttribute;
  26095. return this;
  26096. }
  26097. } );
  26098. /**
  26099. * @author mrdoob / http://mrdoob.com/
  26100. * @author bhouston / http://clara.io/
  26101. * @author stephomi / http://stephaneginier.com/
  26102. */
  26103. function Raycaster( origin, direction, near, far ) {
  26104. this.ray = new Ray( origin, direction );
  26105. // direction is assumed to be normalized (for accurate distance calculations)
  26106. this.near = near || 0;
  26107. this.far = far || Infinity;
  26108. this.params = {
  26109. Mesh: {},
  26110. Line: {},
  26111. LOD: {},
  26112. Points: { threshold: 1 },
  26113. Sprite: {}
  26114. };
  26115. Object.defineProperties( this.params, {
  26116. PointCloud: {
  26117. get: function () {
  26118. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26119. return this.Points;
  26120. }
  26121. }
  26122. } );
  26123. }
  26124. function ascSort( a, b ) {
  26125. return a.distance - b.distance;
  26126. }
  26127. function intersectObject( object, raycaster, intersects, recursive ) {
  26128. if ( object.visible === false ) return;
  26129. object.raycast( raycaster, intersects );
  26130. if ( recursive === true ) {
  26131. var children = object.children;
  26132. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26133. intersectObject( children[ i ], raycaster, intersects, true );
  26134. }
  26135. }
  26136. }
  26137. Object.assign( Raycaster.prototype, {
  26138. linePrecision: 1,
  26139. set: function ( origin, direction ) {
  26140. // direction is assumed to be normalized (for accurate distance calculations)
  26141. this.ray.set( origin, direction );
  26142. },
  26143. setFromCamera: function ( coords, camera ) {
  26144. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26145. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26146. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26147. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26148. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26149. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26150. } else {
  26151. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26152. }
  26153. },
  26154. intersectObject: function ( object, recursive, optionalTarget ) {
  26155. var intersects = optionalTarget || [];
  26156. intersectObject( object, this, intersects, recursive );
  26157. intersects.sort( ascSort );
  26158. return intersects;
  26159. },
  26160. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26161. var intersects = optionalTarget || [];
  26162. if ( Array.isArray( objects ) === false ) {
  26163. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26164. return intersects;
  26165. }
  26166. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26167. intersectObject( objects[ i ], this, intersects, recursive );
  26168. }
  26169. intersects.sort( ascSort );
  26170. return intersects;
  26171. }
  26172. } );
  26173. /**
  26174. * @author bhouston / http://clara.io
  26175. * @author WestLangley / http://github.com/WestLangley
  26176. *
  26177. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26178. *
  26179. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26180. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26181. */
  26182. function Spherical( radius, phi, theta ) {
  26183. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26184. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26185. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26186. return this;
  26187. }
  26188. Object.assign( Spherical.prototype, {
  26189. set: function ( radius, phi, theta ) {
  26190. this.radius = radius;
  26191. this.phi = phi;
  26192. this.theta = theta;
  26193. return this;
  26194. },
  26195. clone: function () {
  26196. return new this.constructor().copy( this );
  26197. },
  26198. copy: function ( other ) {
  26199. this.radius = other.radius;
  26200. this.phi = other.phi;
  26201. this.theta = other.theta;
  26202. return this;
  26203. },
  26204. // restrict phi to be betwee EPS and PI-EPS
  26205. makeSafe: function () {
  26206. var EPS = 0.000001;
  26207. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26208. return this;
  26209. },
  26210. setFromVector3: function ( v ) {
  26211. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26212. },
  26213. setFromCartesianCoords: function ( x, y, z ) {
  26214. this.radius = Math.sqrt( x * x + y * y + z * z );
  26215. if ( this.radius === 0 ) {
  26216. this.theta = 0;
  26217. this.phi = 0;
  26218. } else {
  26219. this.theta = Math.atan2( x, z );
  26220. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26221. }
  26222. return this;
  26223. }
  26224. } );
  26225. /**
  26226. * @author Mugen87 / https://github.com/Mugen87
  26227. *
  26228. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26229. *
  26230. */
  26231. function Cylindrical( radius, theta, y ) {
  26232. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26233. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26234. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26235. return this;
  26236. }
  26237. Object.assign( Cylindrical.prototype, {
  26238. set: function ( radius, theta, y ) {
  26239. this.radius = radius;
  26240. this.theta = theta;
  26241. this.y = y;
  26242. return this;
  26243. },
  26244. clone: function () {
  26245. return new this.constructor().copy( this );
  26246. },
  26247. copy: function ( other ) {
  26248. this.radius = other.radius;
  26249. this.theta = other.theta;
  26250. this.y = other.y;
  26251. return this;
  26252. },
  26253. setFromVector3: function ( v ) {
  26254. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26255. },
  26256. setFromCartesianCoords: function ( x, y, z ) {
  26257. this.radius = Math.sqrt( x * x + z * z );
  26258. this.theta = Math.atan2( x, z );
  26259. this.y = y;
  26260. return this;
  26261. }
  26262. } );
  26263. /**
  26264. * @author bhouston / http://clara.io
  26265. */
  26266. function Box2( min, max ) {
  26267. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26268. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26269. }
  26270. Object.assign( Box2.prototype, {
  26271. set: function ( min, max ) {
  26272. this.min.copy( min );
  26273. this.max.copy( max );
  26274. return this;
  26275. },
  26276. setFromPoints: function ( points ) {
  26277. this.makeEmpty();
  26278. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26279. this.expandByPoint( points[ i ] );
  26280. }
  26281. return this;
  26282. },
  26283. setFromCenterAndSize: function () {
  26284. var v1 = new Vector2();
  26285. return function setFromCenterAndSize( center, size ) {
  26286. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26287. this.min.copy( center ).sub( halfSize );
  26288. this.max.copy( center ).add( halfSize );
  26289. return this;
  26290. };
  26291. }(),
  26292. clone: function () {
  26293. return new this.constructor().copy( this );
  26294. },
  26295. copy: function ( box ) {
  26296. this.min.copy( box.min );
  26297. this.max.copy( box.max );
  26298. return this;
  26299. },
  26300. makeEmpty: function () {
  26301. this.min.x = this.min.y = + Infinity;
  26302. this.max.x = this.max.y = - Infinity;
  26303. return this;
  26304. },
  26305. isEmpty: function () {
  26306. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26307. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26308. },
  26309. getCenter: function ( target ) {
  26310. if ( target === undefined ) {
  26311. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26312. target = new Vector2();
  26313. }
  26314. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26315. },
  26316. getSize: function ( target ) {
  26317. if ( target === undefined ) {
  26318. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26319. target = new Vector2();
  26320. }
  26321. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26322. },
  26323. expandByPoint: function ( point ) {
  26324. this.min.min( point );
  26325. this.max.max( point );
  26326. return this;
  26327. },
  26328. expandByVector: function ( vector ) {
  26329. this.min.sub( vector );
  26330. this.max.add( vector );
  26331. return this;
  26332. },
  26333. expandByScalar: function ( scalar ) {
  26334. this.min.addScalar( - scalar );
  26335. this.max.addScalar( scalar );
  26336. return this;
  26337. },
  26338. containsPoint: function ( point ) {
  26339. return point.x < this.min.x || point.x > this.max.x ||
  26340. point.y < this.min.y || point.y > this.max.y ? false : true;
  26341. },
  26342. containsBox: function ( box ) {
  26343. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26344. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26345. },
  26346. getParameter: function ( point, target ) {
  26347. // This can potentially have a divide by zero if the box
  26348. // has a size dimension of 0.
  26349. if ( target === undefined ) {
  26350. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26351. target = new Vector2();
  26352. }
  26353. return target.set(
  26354. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26355. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26356. );
  26357. },
  26358. intersectsBox: function ( box ) {
  26359. // using 4 splitting planes to rule out intersections
  26360. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26361. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26362. },
  26363. clampPoint: function ( point, target ) {
  26364. if ( target === undefined ) {
  26365. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26366. target = new Vector2();
  26367. }
  26368. return target.copy( point ).clamp( this.min, this.max );
  26369. },
  26370. distanceToPoint: function () {
  26371. var v1 = new Vector2();
  26372. return function distanceToPoint( point ) {
  26373. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26374. return clampedPoint.sub( point ).length();
  26375. };
  26376. }(),
  26377. intersect: function ( box ) {
  26378. this.min.max( box.min );
  26379. this.max.min( box.max );
  26380. return this;
  26381. },
  26382. union: function ( box ) {
  26383. this.min.min( box.min );
  26384. this.max.max( box.max );
  26385. return this;
  26386. },
  26387. translate: function ( offset ) {
  26388. this.min.add( offset );
  26389. this.max.add( offset );
  26390. return this;
  26391. },
  26392. equals: function ( box ) {
  26393. return box.min.equals( this.min ) && box.max.equals( this.max );
  26394. }
  26395. } );
  26396. /**
  26397. * @author bhouston / http://clara.io
  26398. */
  26399. function Line3( start, end ) {
  26400. this.start = ( start !== undefined ) ? start : new Vector3();
  26401. this.end = ( end !== undefined ) ? end : new Vector3();
  26402. }
  26403. Object.assign( Line3.prototype, {
  26404. set: function ( start, end ) {
  26405. this.start.copy( start );
  26406. this.end.copy( end );
  26407. return this;
  26408. },
  26409. clone: function () {
  26410. return new this.constructor().copy( this );
  26411. },
  26412. copy: function ( line ) {
  26413. this.start.copy( line.start );
  26414. this.end.copy( line.end );
  26415. return this;
  26416. },
  26417. getCenter: function ( target ) {
  26418. if ( target === undefined ) {
  26419. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26420. target = new Vector3();
  26421. }
  26422. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26423. },
  26424. delta: function ( target ) {
  26425. if ( target === undefined ) {
  26426. console.warn( 'THREE.Line3: .delta() target is now required' );
  26427. target = new Vector3();
  26428. }
  26429. return target.subVectors( this.end, this.start );
  26430. },
  26431. distanceSq: function () {
  26432. return this.start.distanceToSquared( this.end );
  26433. },
  26434. distance: function () {
  26435. return this.start.distanceTo( this.end );
  26436. },
  26437. at: function ( t, target ) {
  26438. if ( target === undefined ) {
  26439. console.warn( 'THREE.Line3: .at() target is now required' );
  26440. target = new Vector3();
  26441. }
  26442. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26443. },
  26444. closestPointToPointParameter: function () {
  26445. var startP = new Vector3();
  26446. var startEnd = new Vector3();
  26447. return function closestPointToPointParameter( point, clampToLine ) {
  26448. startP.subVectors( point, this.start );
  26449. startEnd.subVectors( this.end, this.start );
  26450. var startEnd2 = startEnd.dot( startEnd );
  26451. var startEnd_startP = startEnd.dot( startP );
  26452. var t = startEnd_startP / startEnd2;
  26453. if ( clampToLine ) {
  26454. t = _Math.clamp( t, 0, 1 );
  26455. }
  26456. return t;
  26457. };
  26458. }(),
  26459. closestPointToPoint: function ( point, clampToLine, target ) {
  26460. var t = this.closestPointToPointParameter( point, clampToLine );
  26461. if ( target === undefined ) {
  26462. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26463. target = new Vector3();
  26464. }
  26465. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26466. },
  26467. applyMatrix4: function ( matrix ) {
  26468. this.start.applyMatrix4( matrix );
  26469. this.end.applyMatrix4( matrix );
  26470. return this;
  26471. },
  26472. equals: function ( line ) {
  26473. return line.start.equals( this.start ) && line.end.equals( this.end );
  26474. }
  26475. } );
  26476. /**
  26477. * @author alteredq / http://alteredqualia.com/
  26478. */
  26479. function ImmediateRenderObject( material ) {
  26480. Object3D.call( this );
  26481. this.material = material;
  26482. this.render = function ( /* renderCallback */ ) {};
  26483. }
  26484. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26485. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26486. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26487. /**
  26488. * @author mrdoob / http://mrdoob.com/
  26489. * @author WestLangley / http://github.com/WestLangley
  26490. */
  26491. function VertexNormalsHelper( object, size, hex, linewidth ) {
  26492. this.object = object;
  26493. this.size = ( size !== undefined ) ? size : 1;
  26494. var color = ( hex !== undefined ) ? hex : 0xff0000;
  26495. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26496. //
  26497. var nNormals = 0;
  26498. var objGeometry = this.object.geometry;
  26499. if ( objGeometry && objGeometry.isGeometry ) {
  26500. nNormals = objGeometry.faces.length * 3;
  26501. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26502. nNormals = objGeometry.attributes.normal.count;
  26503. }
  26504. //
  26505. var geometry = new BufferGeometry();
  26506. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26507. geometry.addAttribute( 'position', positions );
  26508. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26509. //
  26510. this.matrixAutoUpdate = false;
  26511. this.update();
  26512. }
  26513. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26514. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  26515. VertexNormalsHelper.prototype.update = ( function () {
  26516. var v1 = new Vector3();
  26517. var v2 = new Vector3();
  26518. var normalMatrix = new Matrix3();
  26519. return function update() {
  26520. var keys = [ 'a', 'b', 'c' ];
  26521. this.object.updateMatrixWorld( true );
  26522. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26523. var matrixWorld = this.object.matrixWorld;
  26524. var position = this.geometry.attributes.position;
  26525. //
  26526. var objGeometry = this.object.geometry;
  26527. if ( objGeometry && objGeometry.isGeometry ) {
  26528. var vertices = objGeometry.vertices;
  26529. var faces = objGeometry.faces;
  26530. var idx = 0;
  26531. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26532. var face = faces[ i ];
  26533. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26534. var vertex = vertices[ face[ keys[ j ] ] ];
  26535. var normal = face.vertexNormals[ j ];
  26536. v1.copy( vertex ).applyMatrix4( matrixWorld );
  26537. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26538. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26539. idx = idx + 1;
  26540. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26541. idx = idx + 1;
  26542. }
  26543. }
  26544. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26545. var objPos = objGeometry.attributes.position;
  26546. var objNorm = objGeometry.attributes.normal;
  26547. var idx = 0;
  26548. // for simplicity, ignore index and drawcalls, and render every normal
  26549. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  26550. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  26551. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  26552. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26553. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26554. idx = idx + 1;
  26555. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26556. idx = idx + 1;
  26557. }
  26558. }
  26559. position.needsUpdate = true;
  26560. };
  26561. }() );
  26562. /**
  26563. * @author alteredq / http://alteredqualia.com/
  26564. * @author mrdoob / http://mrdoob.com/
  26565. * @author WestLangley / http://github.com/WestLangley
  26566. */
  26567. function SpotLightHelper( light, color ) {
  26568. Object3D.call( this );
  26569. this.light = light;
  26570. this.light.updateMatrixWorld();
  26571. this.matrix = light.matrixWorld;
  26572. this.matrixAutoUpdate = false;
  26573. this.color = color;
  26574. var geometry = new BufferGeometry();
  26575. var positions = [
  26576. 0, 0, 0, 0, 0, 1,
  26577. 0, 0, 0, 1, 0, 1,
  26578. 0, 0, 0, - 1, 0, 1,
  26579. 0, 0, 0, 0, 1, 1,
  26580. 0, 0, 0, 0, - 1, 1
  26581. ];
  26582. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26583. var p1 = ( i / l ) * Math.PI * 2;
  26584. var p2 = ( j / l ) * Math.PI * 2;
  26585. positions.push(
  26586. Math.cos( p1 ), Math.sin( p1 ), 1,
  26587. Math.cos( p2 ), Math.sin( p2 ), 1
  26588. );
  26589. }
  26590. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26591. var material = new LineBasicMaterial( { fog: false } );
  26592. this.cone = new LineSegments( geometry, material );
  26593. this.add( this.cone );
  26594. this.update();
  26595. }
  26596. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  26597. SpotLightHelper.prototype.constructor = SpotLightHelper;
  26598. SpotLightHelper.prototype.dispose = function () {
  26599. this.cone.geometry.dispose();
  26600. this.cone.material.dispose();
  26601. };
  26602. SpotLightHelper.prototype.update = function () {
  26603. var vector = new Vector3();
  26604. return function update() {
  26605. this.light.updateMatrixWorld();
  26606. var coneLength = this.light.distance ? this.light.distance : 1000;
  26607. var coneWidth = coneLength * Math.tan( this.light.angle );
  26608. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26609. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  26610. this.cone.lookAt( vector );
  26611. if ( this.color !== undefined ) {
  26612. this.cone.material.color.set( this.color );
  26613. } else {
  26614. this.cone.material.color.copy( this.light.color );
  26615. }
  26616. };
  26617. }();
  26618. /**
  26619. * @author Sean Griffin / http://twitter.com/sgrif
  26620. * @author Michael Guerrero / http://realitymeltdown.com
  26621. * @author mrdoob / http://mrdoob.com/
  26622. * @author ikerr / http://verold.com
  26623. * @author Mugen87 / https://github.com/Mugen87
  26624. */
  26625. function getBoneList( object ) {
  26626. var boneList = [];
  26627. if ( object && object.isBone ) {
  26628. boneList.push( object );
  26629. }
  26630. for ( var i = 0; i < object.children.length; i ++ ) {
  26631. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  26632. }
  26633. return boneList;
  26634. }
  26635. function SkeletonHelper( object ) {
  26636. var bones = getBoneList( object );
  26637. var geometry = new BufferGeometry();
  26638. var vertices = [];
  26639. var colors = [];
  26640. var color1 = new Color( 0, 0, 1 );
  26641. var color2 = new Color( 0, 1, 0 );
  26642. for ( var i = 0; i < bones.length; i ++ ) {
  26643. var bone = bones[ i ];
  26644. if ( bone.parent && bone.parent.isBone ) {
  26645. vertices.push( 0, 0, 0 );
  26646. vertices.push( 0, 0, 0 );
  26647. colors.push( color1.r, color1.g, color1.b );
  26648. colors.push( color2.r, color2.g, color2.b );
  26649. }
  26650. }
  26651. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26652. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26653. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  26654. LineSegments.call( this, geometry, material );
  26655. this.root = object;
  26656. this.bones = bones;
  26657. this.matrix = object.matrixWorld;
  26658. this.matrixAutoUpdate = false;
  26659. }
  26660. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  26661. SkeletonHelper.prototype.constructor = SkeletonHelper;
  26662. SkeletonHelper.prototype.updateMatrixWorld = function () {
  26663. var vector = new Vector3();
  26664. var boneMatrix = new Matrix4();
  26665. var matrixWorldInv = new Matrix4();
  26666. return function updateMatrixWorld( force ) {
  26667. var bones = this.bones;
  26668. var geometry = this.geometry;
  26669. var position = geometry.getAttribute( 'position' );
  26670. matrixWorldInv.getInverse( this.root.matrixWorld );
  26671. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  26672. var bone = bones[ i ];
  26673. if ( bone.parent && bone.parent.isBone ) {
  26674. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  26675. vector.setFromMatrixPosition( boneMatrix );
  26676. position.setXYZ( j, vector.x, vector.y, vector.z );
  26677. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  26678. vector.setFromMatrixPosition( boneMatrix );
  26679. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  26680. j += 2;
  26681. }
  26682. }
  26683. geometry.getAttribute( 'position' ).needsUpdate = true;
  26684. Object3D.prototype.updateMatrixWorld.call( this, force );
  26685. };
  26686. }();
  26687. /**
  26688. * @author alteredq / http://alteredqualia.com/
  26689. * @author mrdoob / http://mrdoob.com/
  26690. */
  26691. function PointLightHelper( light, sphereSize, color ) {
  26692. this.light = light;
  26693. this.light.updateMatrixWorld();
  26694. this.color = color;
  26695. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  26696. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26697. Mesh.call( this, geometry, material );
  26698. this.matrix = this.light.matrixWorld;
  26699. this.matrixAutoUpdate = false;
  26700. this.update();
  26701. /*
  26702. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  26703. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  26704. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  26705. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  26706. var d = light.distance;
  26707. if ( d === 0.0 ) {
  26708. this.lightDistance.visible = false;
  26709. } else {
  26710. this.lightDistance.scale.set( d, d, d );
  26711. }
  26712. this.add( this.lightDistance );
  26713. */
  26714. }
  26715. PointLightHelper.prototype = Object.create( Mesh.prototype );
  26716. PointLightHelper.prototype.constructor = PointLightHelper;
  26717. PointLightHelper.prototype.dispose = function () {
  26718. this.geometry.dispose();
  26719. this.material.dispose();
  26720. };
  26721. PointLightHelper.prototype.update = function () {
  26722. if ( this.color !== undefined ) {
  26723. this.material.color.set( this.color );
  26724. } else {
  26725. this.material.color.copy( this.light.color );
  26726. }
  26727. /*
  26728. var d = this.light.distance;
  26729. if ( d === 0.0 ) {
  26730. this.lightDistance.visible = false;
  26731. } else {
  26732. this.lightDistance.visible = true;
  26733. this.lightDistance.scale.set( d, d, d );
  26734. }
  26735. */
  26736. };
  26737. /**
  26738. * @author abelnation / http://github.com/abelnation
  26739. * @author Mugen87 / http://github.com/Mugen87
  26740. * @author WestLangley / http://github.com/WestLangley
  26741. *
  26742. * This helper must be added as a child of the light
  26743. */
  26744. function RectAreaLightHelper( light, color ) {
  26745. this.type = 'RectAreaLightHelper';
  26746. this.light = light;
  26747. this.color = color; // optional hardwired color for the helper
  26748. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  26749. var geometry = new BufferGeometry();
  26750. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26751. geometry.computeBoundingSphere();
  26752. var material = new LineBasicMaterial( { fog: false } );
  26753. Line.call( this, geometry, material );
  26754. //
  26755. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  26756. var geometry2 = new BufferGeometry();
  26757. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  26758. geometry2.computeBoundingSphere();
  26759. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  26760. this.update();
  26761. }
  26762. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  26763. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  26764. RectAreaLightHelper.prototype.update = function () {
  26765. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  26766. if ( this.color !== undefined ) {
  26767. this.material.color.set( this.color );
  26768. this.children[ 0 ].material.color.set( this.color );
  26769. } else {
  26770. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  26771. // prevent hue shift
  26772. var c = this.material.color;
  26773. var max = Math.max( c.r, c.g, c.b );
  26774. if ( max > 1 ) c.multiplyScalar( 1 / max );
  26775. this.children[ 0 ].material.color.copy( this.material.color );
  26776. }
  26777. };
  26778. RectAreaLightHelper.prototype.dispose = function () {
  26779. this.geometry.dispose();
  26780. this.material.dispose();
  26781. this.children[ 0 ].geometry.dispose();
  26782. this.children[ 0 ].material.dispose();
  26783. };
  26784. /**
  26785. * @author alteredq / http://alteredqualia.com/
  26786. * @author mrdoob / http://mrdoob.com/
  26787. * @author Mugen87 / https://github.com/Mugen87
  26788. */
  26789. function HemisphereLightHelper( light, size, color ) {
  26790. Object3D.call( this );
  26791. this.light = light;
  26792. this.light.updateMatrixWorld();
  26793. this.matrix = light.matrixWorld;
  26794. this.matrixAutoUpdate = false;
  26795. this.color = color;
  26796. var geometry = new OctahedronBufferGeometry( size );
  26797. geometry.rotateY( Math.PI * 0.5 );
  26798. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26799. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  26800. var position = geometry.getAttribute( 'position' );
  26801. var colors = new Float32Array( position.count * 3 );
  26802. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  26803. this.add( new Mesh( geometry, this.material ) );
  26804. this.update();
  26805. }
  26806. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  26807. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  26808. HemisphereLightHelper.prototype.dispose = function () {
  26809. this.children[ 0 ].geometry.dispose();
  26810. this.children[ 0 ].material.dispose();
  26811. };
  26812. HemisphereLightHelper.prototype.update = function () {
  26813. var vector = new Vector3();
  26814. var color1 = new Color();
  26815. var color2 = new Color();
  26816. return function update() {
  26817. var mesh = this.children[ 0 ];
  26818. if ( this.color !== undefined ) {
  26819. this.material.color.set( this.color );
  26820. } else {
  26821. var colors = mesh.geometry.getAttribute( 'color' );
  26822. color1.copy( this.light.color );
  26823. color2.copy( this.light.groundColor );
  26824. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  26825. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  26826. colors.setXYZ( i, color.r, color.g, color.b );
  26827. }
  26828. colors.needsUpdate = true;
  26829. }
  26830. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  26831. };
  26832. }();
  26833. /**
  26834. * @author mrdoob / http://mrdoob.com/
  26835. */
  26836. function GridHelper( size, divisions, color1, color2 ) {
  26837. size = size || 10;
  26838. divisions = divisions || 10;
  26839. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26840. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26841. var center = divisions / 2;
  26842. var step = size / divisions;
  26843. var halfSize = size / 2;
  26844. var vertices = [], colors = [];
  26845. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  26846. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  26847. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  26848. var color = i === center ? color1 : color2;
  26849. color.toArray( colors, j ); j += 3;
  26850. color.toArray( colors, j ); j += 3;
  26851. color.toArray( colors, j ); j += 3;
  26852. color.toArray( colors, j ); j += 3;
  26853. }
  26854. var geometry = new BufferGeometry();
  26855. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26856. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26857. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26858. LineSegments.call( this, geometry, material );
  26859. }
  26860. GridHelper.prototype = Object.create( LineSegments.prototype );
  26861. GridHelper.prototype.constructor = GridHelper;
  26862. /**
  26863. * @author mrdoob / http://mrdoob.com/
  26864. * @author Mugen87 / http://github.com/Mugen87
  26865. * @author Hectate / http://www.github.com/Hectate
  26866. */
  26867. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  26868. radius = radius || 10;
  26869. radials = radials || 16;
  26870. circles = circles || 8;
  26871. divisions = divisions || 64;
  26872. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26873. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26874. var vertices = [];
  26875. var colors = [];
  26876. var x, z;
  26877. var v, i, j, r, color;
  26878. // create the radials
  26879. for ( i = 0; i <= radials; i ++ ) {
  26880. v = ( i / radials ) * ( Math.PI * 2 );
  26881. x = Math.sin( v ) * radius;
  26882. z = Math.cos( v ) * radius;
  26883. vertices.push( 0, 0, 0 );
  26884. vertices.push( x, 0, z );
  26885. color = ( i & 1 ) ? color1 : color2;
  26886. colors.push( color.r, color.g, color.b );
  26887. colors.push( color.r, color.g, color.b );
  26888. }
  26889. // create the circles
  26890. for ( i = 0; i <= circles; i ++ ) {
  26891. color = ( i & 1 ) ? color1 : color2;
  26892. r = radius - ( radius / circles * i );
  26893. for ( j = 0; j < divisions; j ++ ) {
  26894. // first vertex
  26895. v = ( j / divisions ) * ( Math.PI * 2 );
  26896. x = Math.sin( v ) * r;
  26897. z = Math.cos( v ) * r;
  26898. vertices.push( x, 0, z );
  26899. colors.push( color.r, color.g, color.b );
  26900. // second vertex
  26901. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  26902. x = Math.sin( v ) * r;
  26903. z = Math.cos( v ) * r;
  26904. vertices.push( x, 0, z );
  26905. colors.push( color.r, color.g, color.b );
  26906. }
  26907. }
  26908. var geometry = new BufferGeometry();
  26909. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26910. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26911. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26912. LineSegments.call( this, geometry, material );
  26913. }
  26914. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  26915. PolarGridHelper.prototype.constructor = PolarGridHelper;
  26916. /**
  26917. * @author Mugen87 / http://github.com/Mugen87
  26918. */
  26919. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  26920. this.audio = audio;
  26921. this.range = range || 1;
  26922. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  26923. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  26924. var geometry = new BufferGeometry();
  26925. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  26926. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  26927. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  26928. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  26929. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  26930. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  26931. this.update();
  26932. }
  26933. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  26934. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  26935. PositionalAudioHelper.prototype.update = function () {
  26936. var audio = this.audio;
  26937. var range = this.range;
  26938. var divisionsInnerAngle = this.divisionsInnerAngle;
  26939. var divisionsOuterAngle = this.divisionsOuterAngle;
  26940. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  26941. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  26942. var halfConeInnerAngle = coneInnerAngle / 2;
  26943. var halfConeOuterAngle = coneOuterAngle / 2;
  26944. var start = 0;
  26945. var count = 0;
  26946. var i, stride;
  26947. var geometry = this.geometry;
  26948. var positionAttribute = geometry.attributes.position;
  26949. geometry.clearGroups();
  26950. //
  26951. function generateSegment( from, to, divisions, materialIndex ) {
  26952. var step = ( to - from ) / divisions;
  26953. positionAttribute.setXYZ( start, 0, 0, 0 );
  26954. count ++;
  26955. for ( i = from; i < to; i += step ) {
  26956. stride = start + count;
  26957. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  26958. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  26959. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  26960. count += 3;
  26961. }
  26962. geometry.addGroup( start, count, materialIndex );
  26963. start += count;
  26964. count = 0;
  26965. }
  26966. //
  26967. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  26968. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  26969. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  26970. //
  26971. positionAttribute.needsUpdate = true;
  26972. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  26973. };
  26974. PositionalAudioHelper.prototype.dispose = function () {
  26975. this.geometry.dispose();
  26976. this.material[ 0 ].dispose();
  26977. this.material[ 1 ].dispose();
  26978. };
  26979. /**
  26980. * @author mrdoob / http://mrdoob.com/
  26981. * @author WestLangley / http://github.com/WestLangley
  26982. */
  26983. function FaceNormalsHelper( object, size, hex, linewidth ) {
  26984. // FaceNormalsHelper only supports THREE.Geometry
  26985. this.object = object;
  26986. this.size = ( size !== undefined ) ? size : 1;
  26987. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26988. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26989. //
  26990. var nNormals = 0;
  26991. var objGeometry = this.object.geometry;
  26992. if ( objGeometry && objGeometry.isGeometry ) {
  26993. nNormals = objGeometry.faces.length;
  26994. } else {
  26995. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  26996. }
  26997. //
  26998. var geometry = new BufferGeometry();
  26999. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27000. geometry.addAttribute( 'position', positions );
  27001. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27002. //
  27003. this.matrixAutoUpdate = false;
  27004. this.update();
  27005. }
  27006. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27007. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27008. FaceNormalsHelper.prototype.update = ( function () {
  27009. var v1 = new Vector3();
  27010. var v2 = new Vector3();
  27011. var normalMatrix = new Matrix3();
  27012. return function update() {
  27013. this.object.updateMatrixWorld( true );
  27014. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27015. var matrixWorld = this.object.matrixWorld;
  27016. var position = this.geometry.attributes.position;
  27017. //
  27018. var objGeometry = this.object.geometry;
  27019. var vertices = objGeometry.vertices;
  27020. var faces = objGeometry.faces;
  27021. var idx = 0;
  27022. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27023. var face = faces[ i ];
  27024. var normal = face.normal;
  27025. v1.copy( vertices[ face.a ] )
  27026. .add( vertices[ face.b ] )
  27027. .add( vertices[ face.c ] )
  27028. .divideScalar( 3 )
  27029. .applyMatrix4( matrixWorld );
  27030. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27031. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27032. idx = idx + 1;
  27033. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27034. idx = idx + 1;
  27035. }
  27036. position.needsUpdate = true;
  27037. };
  27038. }() );
  27039. /**
  27040. * @author alteredq / http://alteredqualia.com/
  27041. * @author mrdoob / http://mrdoob.com/
  27042. * @author WestLangley / http://github.com/WestLangley
  27043. */
  27044. function DirectionalLightHelper( light, size, color ) {
  27045. Object3D.call( this );
  27046. this.light = light;
  27047. this.light.updateMatrixWorld();
  27048. this.matrix = light.matrixWorld;
  27049. this.matrixAutoUpdate = false;
  27050. this.color = color;
  27051. if ( size === undefined ) size = 1;
  27052. var geometry = new BufferGeometry();
  27053. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27054. - size, size, 0,
  27055. size, size, 0,
  27056. size, - size, 0,
  27057. - size, - size, 0,
  27058. - size, size, 0
  27059. ], 3 ) );
  27060. var material = new LineBasicMaterial( { fog: false } );
  27061. this.lightPlane = new Line( geometry, material );
  27062. this.add( this.lightPlane );
  27063. geometry = new BufferGeometry();
  27064. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27065. this.targetLine = new Line( geometry, material );
  27066. this.add( this.targetLine );
  27067. this.update();
  27068. }
  27069. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27070. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27071. DirectionalLightHelper.prototype.dispose = function () {
  27072. this.lightPlane.geometry.dispose();
  27073. this.lightPlane.material.dispose();
  27074. this.targetLine.geometry.dispose();
  27075. this.targetLine.material.dispose();
  27076. };
  27077. DirectionalLightHelper.prototype.update = function () {
  27078. var v1 = new Vector3();
  27079. var v2 = new Vector3();
  27080. var v3 = new Vector3();
  27081. return function update() {
  27082. v1.setFromMatrixPosition( this.light.matrixWorld );
  27083. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27084. v3.subVectors( v2, v1 );
  27085. this.lightPlane.lookAt( v2 );
  27086. if ( this.color !== undefined ) {
  27087. this.lightPlane.material.color.set( this.color );
  27088. this.targetLine.material.color.set( this.color );
  27089. } else {
  27090. this.lightPlane.material.color.copy( this.light.color );
  27091. this.targetLine.material.color.copy( this.light.color );
  27092. }
  27093. this.targetLine.lookAt( v2 );
  27094. this.targetLine.scale.z = v3.length();
  27095. };
  27096. }();
  27097. /**
  27098. * @author alteredq / http://alteredqualia.com/
  27099. * @author Mugen87 / https://github.com/Mugen87
  27100. *
  27101. * - shows frustum, line of sight and up of the camera
  27102. * - suitable for fast updates
  27103. * - based on frustum visualization in lightgl.js shadowmap example
  27104. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27105. */
  27106. function CameraHelper( camera ) {
  27107. var geometry = new BufferGeometry();
  27108. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27109. var vertices = [];
  27110. var colors = [];
  27111. var pointMap = {};
  27112. // colors
  27113. var colorFrustum = new Color( 0xffaa00 );
  27114. var colorCone = new Color( 0xff0000 );
  27115. var colorUp = new Color( 0x00aaff );
  27116. var colorTarget = new Color( 0xffffff );
  27117. var colorCross = new Color( 0x333333 );
  27118. // near
  27119. addLine( 'n1', 'n2', colorFrustum );
  27120. addLine( 'n2', 'n4', colorFrustum );
  27121. addLine( 'n4', 'n3', colorFrustum );
  27122. addLine( 'n3', 'n1', colorFrustum );
  27123. // far
  27124. addLine( 'f1', 'f2', colorFrustum );
  27125. addLine( 'f2', 'f4', colorFrustum );
  27126. addLine( 'f4', 'f3', colorFrustum );
  27127. addLine( 'f3', 'f1', colorFrustum );
  27128. // sides
  27129. addLine( 'n1', 'f1', colorFrustum );
  27130. addLine( 'n2', 'f2', colorFrustum );
  27131. addLine( 'n3', 'f3', colorFrustum );
  27132. addLine( 'n4', 'f4', colorFrustum );
  27133. // cone
  27134. addLine( 'p', 'n1', colorCone );
  27135. addLine( 'p', 'n2', colorCone );
  27136. addLine( 'p', 'n3', colorCone );
  27137. addLine( 'p', 'n4', colorCone );
  27138. // up
  27139. addLine( 'u1', 'u2', colorUp );
  27140. addLine( 'u2', 'u3', colorUp );
  27141. addLine( 'u3', 'u1', colorUp );
  27142. // target
  27143. addLine( 'c', 't', colorTarget );
  27144. addLine( 'p', 'c', colorCross );
  27145. // cross
  27146. addLine( 'cn1', 'cn2', colorCross );
  27147. addLine( 'cn3', 'cn4', colorCross );
  27148. addLine( 'cf1', 'cf2', colorCross );
  27149. addLine( 'cf3', 'cf4', colorCross );
  27150. function addLine( a, b, color ) {
  27151. addPoint( a, color );
  27152. addPoint( b, color );
  27153. }
  27154. function addPoint( id, color ) {
  27155. vertices.push( 0, 0, 0 );
  27156. colors.push( color.r, color.g, color.b );
  27157. if ( pointMap[ id ] === undefined ) {
  27158. pointMap[ id ] = [];
  27159. }
  27160. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27161. }
  27162. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27163. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27164. LineSegments.call( this, geometry, material );
  27165. this.camera = camera;
  27166. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27167. this.matrix = camera.matrixWorld;
  27168. this.matrixAutoUpdate = false;
  27169. this.pointMap = pointMap;
  27170. this.update();
  27171. }
  27172. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27173. CameraHelper.prototype.constructor = CameraHelper;
  27174. CameraHelper.prototype.update = function () {
  27175. var geometry, pointMap;
  27176. var vector = new Vector3();
  27177. var camera = new Camera();
  27178. function setPoint( point, x, y, z ) {
  27179. vector.set( x, y, z ).unproject( camera );
  27180. var points = pointMap[ point ];
  27181. if ( points !== undefined ) {
  27182. var position = geometry.getAttribute( 'position' );
  27183. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27184. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27185. }
  27186. }
  27187. }
  27188. return function update() {
  27189. geometry = this.geometry;
  27190. pointMap = this.pointMap;
  27191. var w = 1, h = 1;
  27192. // we need just camera projection matrix
  27193. // world matrix must be identity
  27194. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  27195. // center / target
  27196. setPoint( 'c', 0, 0, - 1 );
  27197. setPoint( 't', 0, 0, 1 );
  27198. // near
  27199. setPoint( 'n1', - w, - h, - 1 );
  27200. setPoint( 'n2', w, - h, - 1 );
  27201. setPoint( 'n3', - w, h, - 1 );
  27202. setPoint( 'n4', w, h, - 1 );
  27203. // far
  27204. setPoint( 'f1', - w, - h, 1 );
  27205. setPoint( 'f2', w, - h, 1 );
  27206. setPoint( 'f3', - w, h, 1 );
  27207. setPoint( 'f4', w, h, 1 );
  27208. // up
  27209. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27210. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27211. setPoint( 'u3', 0, h * 2, - 1 );
  27212. // cross
  27213. setPoint( 'cf1', - w, 0, 1 );
  27214. setPoint( 'cf2', w, 0, 1 );
  27215. setPoint( 'cf3', 0, - h, 1 );
  27216. setPoint( 'cf4', 0, h, 1 );
  27217. setPoint( 'cn1', - w, 0, - 1 );
  27218. setPoint( 'cn2', w, 0, - 1 );
  27219. setPoint( 'cn3', 0, - h, - 1 );
  27220. setPoint( 'cn4', 0, h, - 1 );
  27221. geometry.getAttribute( 'position' ).needsUpdate = true;
  27222. };
  27223. }();
  27224. /**
  27225. * @author mrdoob / http://mrdoob.com/
  27226. * @author Mugen87 / http://github.com/Mugen87
  27227. */
  27228. function BoxHelper( object, color ) {
  27229. this.object = object;
  27230. if ( color === undefined ) color = 0xffff00;
  27231. 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 ] );
  27232. var positions = new Float32Array( 8 * 3 );
  27233. var geometry = new BufferGeometry();
  27234. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27235. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27236. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27237. this.matrixAutoUpdate = false;
  27238. this.update();
  27239. }
  27240. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27241. BoxHelper.prototype.constructor = BoxHelper;
  27242. BoxHelper.prototype.update = ( function () {
  27243. var box = new Box3();
  27244. return function update( object ) {
  27245. if ( object !== undefined ) {
  27246. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27247. }
  27248. if ( this.object !== undefined ) {
  27249. box.setFromObject( this.object );
  27250. }
  27251. if ( box.isEmpty() ) return;
  27252. var min = box.min;
  27253. var max = box.max;
  27254. /*
  27255. 5____4
  27256. 1/___0/|
  27257. | 6__|_7
  27258. 2/___3/
  27259. 0: max.x, max.y, max.z
  27260. 1: min.x, max.y, max.z
  27261. 2: min.x, min.y, max.z
  27262. 3: max.x, min.y, max.z
  27263. 4: max.x, max.y, min.z
  27264. 5: min.x, max.y, min.z
  27265. 6: min.x, min.y, min.z
  27266. 7: max.x, min.y, min.z
  27267. */
  27268. var position = this.geometry.attributes.position;
  27269. var array = position.array;
  27270. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27271. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27272. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27273. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27274. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27275. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27276. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27277. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27278. position.needsUpdate = true;
  27279. this.geometry.computeBoundingSphere();
  27280. };
  27281. } )();
  27282. BoxHelper.prototype.setFromObject = function ( object ) {
  27283. this.object = object;
  27284. this.update();
  27285. return this;
  27286. };
  27287. BoxHelper.prototype.copy = function ( source ) {
  27288. LineSegments.prototype.copy.call( this, source );
  27289. this.object = source.object;
  27290. return this;
  27291. };
  27292. BoxHelper.prototype.clone = function () {
  27293. return new this.constructor().copy( this );
  27294. };
  27295. /**
  27296. * @author WestLangley / http://github.com/WestLangley
  27297. */
  27298. function Box3Helper( box, hex ) {
  27299. this.type = 'Box3Helper';
  27300. this.box = box;
  27301. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27302. 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 ] );
  27303. 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 ];
  27304. var geometry = new BufferGeometry();
  27305. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27306. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27307. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27308. this.geometry.computeBoundingSphere();
  27309. }
  27310. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27311. Box3Helper.prototype.constructor = Box3Helper;
  27312. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27313. var box = this.box;
  27314. if ( box.isEmpty() ) return;
  27315. box.getCenter( this.position );
  27316. box.getSize( this.scale );
  27317. this.scale.multiplyScalar( 0.5 );
  27318. Object3D.prototype.updateMatrixWorld.call( this, force );
  27319. };
  27320. /**
  27321. * @author WestLangley / http://github.com/WestLangley
  27322. */
  27323. function PlaneHelper( plane, size, hex ) {
  27324. this.type = 'PlaneHelper';
  27325. this.plane = plane;
  27326. this.size = ( size === undefined ) ? 1 : size;
  27327. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27328. 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 ];
  27329. var geometry = new BufferGeometry();
  27330. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27331. geometry.computeBoundingSphere();
  27332. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27333. //
  27334. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27335. var geometry2 = new BufferGeometry();
  27336. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27337. geometry2.computeBoundingSphere();
  27338. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27339. }
  27340. PlaneHelper.prototype = Object.create( Line.prototype );
  27341. PlaneHelper.prototype.constructor = PlaneHelper;
  27342. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27343. var scale = - this.plane.constant;
  27344. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27345. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27346. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27347. this.lookAt( this.plane.normal );
  27348. Object3D.prototype.updateMatrixWorld.call( this, force );
  27349. };
  27350. /**
  27351. * @author WestLangley / http://github.com/WestLangley
  27352. * @author zz85 / http://github.com/zz85
  27353. * @author bhouston / http://clara.io
  27354. *
  27355. * Creates an arrow for visualizing directions
  27356. *
  27357. * Parameters:
  27358. * dir - Vector3
  27359. * origin - Vector3
  27360. * length - Number
  27361. * color - color in hex value
  27362. * headLength - Number
  27363. * headWidth - Number
  27364. */
  27365. var lineGeometry, coneGeometry;
  27366. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27367. // dir is assumed to be normalized
  27368. Object3D.call( this );
  27369. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  27370. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  27371. if ( length === undefined ) length = 1;
  27372. if ( color === undefined ) color = 0xffff00;
  27373. if ( headLength === undefined ) headLength = 0.2 * length;
  27374. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27375. if ( lineGeometry === undefined ) {
  27376. lineGeometry = new BufferGeometry();
  27377. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27378. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  27379. coneGeometry.translate( 0, - 0.5, 0 );
  27380. }
  27381. this.position.copy( origin );
  27382. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  27383. this.line.matrixAutoUpdate = false;
  27384. this.add( this.line );
  27385. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  27386. this.cone.matrixAutoUpdate = false;
  27387. this.add( this.cone );
  27388. this.setDirection( dir );
  27389. this.setLength( length, headLength, headWidth );
  27390. }
  27391. ArrowHelper.prototype = Object.create( Object3D.prototype );
  27392. ArrowHelper.prototype.constructor = ArrowHelper;
  27393. ArrowHelper.prototype.setDirection = ( function () {
  27394. var axis = new Vector3();
  27395. var radians;
  27396. return function setDirection( dir ) {
  27397. // dir is assumed to be normalized
  27398. if ( dir.y > 0.99999 ) {
  27399. this.quaternion.set( 0, 0, 0, 1 );
  27400. } else if ( dir.y < - 0.99999 ) {
  27401. this.quaternion.set( 1, 0, 0, 0 );
  27402. } else {
  27403. axis.set( dir.z, 0, - dir.x ).normalize();
  27404. radians = Math.acos( dir.y );
  27405. this.quaternion.setFromAxisAngle( axis, radians );
  27406. }
  27407. };
  27408. }() );
  27409. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  27410. if ( headLength === undefined ) headLength = 0.2 * length;
  27411. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27412. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  27413. this.line.updateMatrix();
  27414. this.cone.scale.set( headWidth, headLength, headWidth );
  27415. this.cone.position.y = length;
  27416. this.cone.updateMatrix();
  27417. };
  27418. ArrowHelper.prototype.setColor = function ( color ) {
  27419. this.line.material.color.copy( color );
  27420. this.cone.material.color.copy( color );
  27421. };
  27422. ArrowHelper.prototype.copy = function ( source ) {
  27423. Object3D.prototype.copy.call( this, source, false );
  27424. this.line.copy( source.line );
  27425. this.cone.copy( source.cone );
  27426. return this;
  27427. };
  27428. ArrowHelper.prototype.clone = function () {
  27429. return new this.constructor().copy( this );
  27430. };
  27431. /**
  27432. * @author sroucheray / http://sroucheray.org/
  27433. * @author mrdoob / http://mrdoob.com/
  27434. */
  27435. function AxesHelper( size ) {
  27436. size = size || 1;
  27437. var vertices = [
  27438. 0, 0, 0, size, 0, 0,
  27439. 0, 0, 0, 0, size, 0,
  27440. 0, 0, 0, 0, 0, size
  27441. ];
  27442. var colors = [
  27443. 1, 0, 0, 1, 0.6, 0,
  27444. 0, 1, 0, 0.6, 1, 0,
  27445. 0, 0, 1, 0, 0.6, 1
  27446. ];
  27447. var geometry = new BufferGeometry();
  27448. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27449. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27450. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27451. LineSegments.call( this, geometry, material );
  27452. }
  27453. AxesHelper.prototype = Object.create( LineSegments.prototype );
  27454. AxesHelper.prototype.constructor = AxesHelper;
  27455. /**
  27456. * @author mrdoob / http://mrdoob.com/
  27457. */
  27458. function Face4( a, b, c, d, normal, color, materialIndex ) {
  27459. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  27460. return new Face3( a, b, c, normal, color, materialIndex );
  27461. }
  27462. var LineStrip = 0;
  27463. var LinePieces = 1;
  27464. function MeshFaceMaterial( materials ) {
  27465. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27466. return materials;
  27467. }
  27468. function MultiMaterial( materials ) {
  27469. if ( materials === undefined ) materials = [];
  27470. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27471. materials.isMultiMaterial = true;
  27472. materials.materials = materials;
  27473. materials.clone = function () {
  27474. return materials.slice();
  27475. };
  27476. return materials;
  27477. }
  27478. function PointCloud( geometry, material ) {
  27479. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27480. return new Points( geometry, material );
  27481. }
  27482. function Particle( material ) {
  27483. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27484. return new Sprite( material );
  27485. }
  27486. function ParticleSystem( geometry, material ) {
  27487. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27488. return new Points( geometry, material );
  27489. }
  27490. function PointCloudMaterial( parameters ) {
  27491. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27492. return new PointsMaterial( parameters );
  27493. }
  27494. function ParticleBasicMaterial( parameters ) {
  27495. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27496. return new PointsMaterial( parameters );
  27497. }
  27498. function ParticleSystemMaterial( parameters ) {
  27499. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27500. return new PointsMaterial( parameters );
  27501. }
  27502. function Vertex( x, y, z ) {
  27503. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27504. return new Vector3( x, y, z );
  27505. }
  27506. //
  27507. function DynamicBufferAttribute( array, itemSize ) {
  27508. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  27509. return new BufferAttribute( array, itemSize ).setDynamic( true );
  27510. }
  27511. function Int8Attribute( array, itemSize ) {
  27512. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27513. return new Int8BufferAttribute( array, itemSize );
  27514. }
  27515. function Uint8Attribute( array, itemSize ) {
  27516. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27517. return new Uint8BufferAttribute( array, itemSize );
  27518. }
  27519. function Uint8ClampedAttribute( array, itemSize ) {
  27520. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27521. return new Uint8ClampedBufferAttribute( array, itemSize );
  27522. }
  27523. function Int16Attribute( array, itemSize ) {
  27524. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27525. return new Int16BufferAttribute( array, itemSize );
  27526. }
  27527. function Uint16Attribute( array, itemSize ) {
  27528. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27529. return new Uint16BufferAttribute( array, itemSize );
  27530. }
  27531. function Int32Attribute( array, itemSize ) {
  27532. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  27533. return new Int32BufferAttribute( array, itemSize );
  27534. }
  27535. function Uint32Attribute( array, itemSize ) {
  27536. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  27537. return new Uint32BufferAttribute( array, itemSize );
  27538. }
  27539. function Float32Attribute( array, itemSize ) {
  27540. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  27541. return new Float32BufferAttribute( array, itemSize );
  27542. }
  27543. function Float64Attribute( array, itemSize ) {
  27544. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  27545. return new Float64BufferAttribute( array, itemSize );
  27546. }
  27547. //
  27548. Curve.create = function ( construct, getPoint ) {
  27549. console.log( 'THREE.Curve.create() has been deprecated' );
  27550. construct.prototype = Object.create( Curve.prototype );
  27551. construct.prototype.constructor = construct;
  27552. construct.prototype.getPoint = getPoint;
  27553. return construct;
  27554. };
  27555. //
  27556. Object.assign( CurvePath.prototype, {
  27557. createPointsGeometry: function ( divisions ) {
  27558. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27559. // generate geometry from path points (for Line or Points objects)
  27560. var pts = this.getPoints( divisions );
  27561. return this.createGeometry( pts );
  27562. },
  27563. createSpacedPointsGeometry: function ( divisions ) {
  27564. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27565. // generate geometry from equidistant sampling along the path
  27566. var pts = this.getSpacedPoints( divisions );
  27567. return this.createGeometry( pts );
  27568. },
  27569. createGeometry: function ( points ) {
  27570. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27571. var geometry = new Geometry();
  27572. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27573. var point = points[ i ];
  27574. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  27575. }
  27576. return geometry;
  27577. }
  27578. } );
  27579. //
  27580. Object.assign( Path.prototype, {
  27581. fromPoints: function ( points ) {
  27582. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  27583. this.setFromPoints( points );
  27584. }
  27585. } );
  27586. //
  27587. function ClosedSplineCurve3( points ) {
  27588. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27589. CatmullRomCurve3.call( this, points );
  27590. this.type = 'catmullrom';
  27591. this.closed = true;
  27592. }
  27593. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27594. //
  27595. function SplineCurve3( points ) {
  27596. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27597. CatmullRomCurve3.call( this, points );
  27598. this.type = 'catmullrom';
  27599. }
  27600. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27601. //
  27602. function Spline( points ) {
  27603. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  27604. CatmullRomCurve3.call( this, points );
  27605. this.type = 'catmullrom';
  27606. }
  27607. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  27608. Object.assign( Spline.prototype, {
  27609. initFromArray: function ( /* a */ ) {
  27610. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  27611. },
  27612. getControlPointsArray: function ( /* optionalTarget */ ) {
  27613. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  27614. },
  27615. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  27616. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  27617. }
  27618. } );
  27619. //
  27620. function AxisHelper( size ) {
  27621. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  27622. return new AxesHelper( size );
  27623. }
  27624. function BoundingBoxHelper( object, color ) {
  27625. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  27626. return new BoxHelper( object, color );
  27627. }
  27628. function EdgesHelper( object, hex ) {
  27629. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  27630. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27631. }
  27632. GridHelper.prototype.setColors = function () {
  27633. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  27634. };
  27635. SkeletonHelper.prototype.update = function () {
  27636. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  27637. };
  27638. function WireframeHelper( object, hex ) {
  27639. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  27640. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27641. }
  27642. //
  27643. Object.assign( Loader.prototype, {
  27644. extractUrlBase: function ( url ) {
  27645. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  27646. return LoaderUtils.extractUrlBase( url );
  27647. }
  27648. } );
  27649. function XHRLoader( manager ) {
  27650. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  27651. return new FileLoader( manager );
  27652. }
  27653. function BinaryTextureLoader( manager ) {
  27654. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  27655. return new DataTextureLoader( manager );
  27656. }
  27657. Object.assign( ObjectLoader.prototype, {
  27658. setTexturePath: function ( value ) {
  27659. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  27660. return this.setResourcePath( value );
  27661. }
  27662. } );
  27663. //
  27664. Object.assign( Box2.prototype, {
  27665. center: function ( optionalTarget ) {
  27666. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  27667. return this.getCenter( optionalTarget );
  27668. },
  27669. empty: function () {
  27670. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  27671. return this.isEmpty();
  27672. },
  27673. isIntersectionBox: function ( box ) {
  27674. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27675. return this.intersectsBox( box );
  27676. },
  27677. size: function ( optionalTarget ) {
  27678. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  27679. return this.getSize( optionalTarget );
  27680. }
  27681. } );
  27682. Object.assign( Box3.prototype, {
  27683. center: function ( optionalTarget ) {
  27684. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  27685. return this.getCenter( optionalTarget );
  27686. },
  27687. empty: function () {
  27688. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  27689. return this.isEmpty();
  27690. },
  27691. isIntersectionBox: function ( box ) {
  27692. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27693. return this.intersectsBox( box );
  27694. },
  27695. isIntersectionSphere: function ( sphere ) {
  27696. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27697. return this.intersectsSphere( sphere );
  27698. },
  27699. size: function ( optionalTarget ) {
  27700. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  27701. return this.getSize( optionalTarget );
  27702. }
  27703. } );
  27704. Line3.prototype.center = function ( optionalTarget ) {
  27705. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  27706. return this.getCenter( optionalTarget );
  27707. };
  27708. Object.assign( _Math, {
  27709. random16: function () {
  27710. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  27711. return Math.random();
  27712. },
  27713. nearestPowerOfTwo: function ( value ) {
  27714. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  27715. return _Math.floorPowerOfTwo( value );
  27716. },
  27717. nextPowerOfTwo: function ( value ) {
  27718. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  27719. return _Math.ceilPowerOfTwo( value );
  27720. }
  27721. } );
  27722. Object.assign( Matrix3.prototype, {
  27723. flattenToArrayOffset: function ( array, offset ) {
  27724. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27725. return this.toArray( array, offset );
  27726. },
  27727. multiplyVector3: function ( vector ) {
  27728. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  27729. return vector.applyMatrix3( this );
  27730. },
  27731. multiplyVector3Array: function ( /* a */ ) {
  27732. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  27733. },
  27734. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27735. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27736. return this.applyToBufferAttribute( buffer );
  27737. },
  27738. applyToVector3Array: function ( /* array, offset, length */ ) {
  27739. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  27740. }
  27741. } );
  27742. Object.assign( Matrix4.prototype, {
  27743. extractPosition: function ( m ) {
  27744. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  27745. return this.copyPosition( m );
  27746. },
  27747. flattenToArrayOffset: function ( array, offset ) {
  27748. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27749. return this.toArray( array, offset );
  27750. },
  27751. getPosition: function () {
  27752. var v1;
  27753. return function getPosition() {
  27754. if ( v1 === undefined ) v1 = new Vector3();
  27755. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  27756. return v1.setFromMatrixColumn( this, 3 );
  27757. };
  27758. }(),
  27759. setRotationFromQuaternion: function ( q ) {
  27760. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  27761. return this.makeRotationFromQuaternion( q );
  27762. },
  27763. multiplyToArray: function () {
  27764. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  27765. },
  27766. multiplyVector3: function ( vector ) {
  27767. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27768. return vector.applyMatrix4( this );
  27769. },
  27770. multiplyVector4: function ( vector ) {
  27771. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27772. return vector.applyMatrix4( this );
  27773. },
  27774. multiplyVector3Array: function ( /* a */ ) {
  27775. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  27776. },
  27777. rotateAxis: function ( v ) {
  27778. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  27779. v.transformDirection( this );
  27780. },
  27781. crossVector: function ( vector ) {
  27782. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27783. return vector.applyMatrix4( this );
  27784. },
  27785. translate: function () {
  27786. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  27787. },
  27788. rotateX: function () {
  27789. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  27790. },
  27791. rotateY: function () {
  27792. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  27793. },
  27794. rotateZ: function () {
  27795. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  27796. },
  27797. rotateByAxis: function () {
  27798. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  27799. },
  27800. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27801. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27802. return this.applyToBufferAttribute( buffer );
  27803. },
  27804. applyToVector3Array: function ( /* array, offset, length */ ) {
  27805. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  27806. },
  27807. makeFrustum: function ( left, right, bottom, top, near, far ) {
  27808. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  27809. return this.makePerspective( left, right, top, bottom, near, far );
  27810. }
  27811. } );
  27812. Plane.prototype.isIntersectionLine = function ( line ) {
  27813. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  27814. return this.intersectsLine( line );
  27815. };
  27816. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  27817. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  27818. return vector.applyQuaternion( this );
  27819. };
  27820. Object.assign( Ray.prototype, {
  27821. isIntersectionBox: function ( box ) {
  27822. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27823. return this.intersectsBox( box );
  27824. },
  27825. isIntersectionPlane: function ( plane ) {
  27826. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  27827. return this.intersectsPlane( plane );
  27828. },
  27829. isIntersectionSphere: function ( sphere ) {
  27830. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27831. return this.intersectsSphere( sphere );
  27832. }
  27833. } );
  27834. Object.assign( Triangle.prototype, {
  27835. area: function () {
  27836. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  27837. return this.getArea();
  27838. },
  27839. barycoordFromPoint: function ( point, target ) {
  27840. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27841. return this.getBarycoord( point, target );
  27842. },
  27843. midpoint: function ( target ) {
  27844. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  27845. return this.getMidpoint( target );
  27846. },
  27847. normal: function ( target ) {
  27848. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27849. return this.getNormal( target );
  27850. },
  27851. plane: function ( target ) {
  27852. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  27853. return this.getPlane( target );
  27854. }
  27855. } );
  27856. Object.assign( Triangle, {
  27857. barycoordFromPoint: function ( point, a, b, c, target ) {
  27858. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27859. return Triangle.getBarycoord( point, a, b, c, target );
  27860. },
  27861. normal: function ( a, b, c, target ) {
  27862. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27863. return Triangle.getNormal( a, b, c, target );
  27864. }
  27865. } );
  27866. Object.assign( Shape.prototype, {
  27867. extractAllPoints: function ( divisions ) {
  27868. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  27869. return this.extractPoints( divisions );
  27870. },
  27871. extrude: function ( options ) {
  27872. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  27873. return new ExtrudeGeometry( this, options );
  27874. },
  27875. makeGeometry: function ( options ) {
  27876. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  27877. return new ShapeGeometry( this, options );
  27878. }
  27879. } );
  27880. Object.assign( Vector2.prototype, {
  27881. fromAttribute: function ( attribute, index, offset ) {
  27882. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27883. return this.fromBufferAttribute( attribute, index, offset );
  27884. },
  27885. distanceToManhattan: function ( v ) {
  27886. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  27887. return this.manhattanDistanceTo( v );
  27888. },
  27889. lengthManhattan: function () {
  27890. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  27891. return this.manhattanLength();
  27892. }
  27893. } );
  27894. Object.assign( Vector3.prototype, {
  27895. setEulerFromRotationMatrix: function () {
  27896. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  27897. },
  27898. setEulerFromQuaternion: function () {
  27899. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  27900. },
  27901. getPositionFromMatrix: function ( m ) {
  27902. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  27903. return this.setFromMatrixPosition( m );
  27904. },
  27905. getScaleFromMatrix: function ( m ) {
  27906. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  27907. return this.setFromMatrixScale( m );
  27908. },
  27909. getColumnFromMatrix: function ( index, matrix ) {
  27910. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  27911. return this.setFromMatrixColumn( matrix, index );
  27912. },
  27913. applyProjection: function ( m ) {
  27914. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  27915. return this.applyMatrix4( m );
  27916. },
  27917. fromAttribute: function ( attribute, index, offset ) {
  27918. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27919. return this.fromBufferAttribute( attribute, index, offset );
  27920. },
  27921. distanceToManhattan: function ( v ) {
  27922. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  27923. return this.manhattanDistanceTo( v );
  27924. },
  27925. lengthManhattan: function () {
  27926. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  27927. return this.manhattanLength();
  27928. }
  27929. } );
  27930. Object.assign( Vector4.prototype, {
  27931. fromAttribute: function ( attribute, index, offset ) {
  27932. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27933. return this.fromBufferAttribute( attribute, index, offset );
  27934. },
  27935. lengthManhattan: function () {
  27936. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  27937. return this.manhattanLength();
  27938. }
  27939. } );
  27940. //
  27941. Object.assign( Geometry.prototype, {
  27942. computeTangents: function () {
  27943. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  27944. },
  27945. computeLineDistances: function () {
  27946. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  27947. }
  27948. } );
  27949. Object.assign( Object3D.prototype, {
  27950. getChildByName: function ( name ) {
  27951. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  27952. return this.getObjectByName( name );
  27953. },
  27954. renderDepth: function () {
  27955. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  27956. },
  27957. translate: function ( distance, axis ) {
  27958. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  27959. return this.translateOnAxis( axis, distance );
  27960. },
  27961. getWorldRotation: function () {
  27962. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  27963. }
  27964. } );
  27965. Object.defineProperties( Object3D.prototype, {
  27966. eulerOrder: {
  27967. get: function () {
  27968. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27969. return this.rotation.order;
  27970. },
  27971. set: function ( value ) {
  27972. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27973. this.rotation.order = value;
  27974. }
  27975. },
  27976. useQuaternion: {
  27977. get: function () {
  27978. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27979. },
  27980. set: function () {
  27981. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27982. }
  27983. }
  27984. } );
  27985. Object.defineProperties( LOD.prototype, {
  27986. objects: {
  27987. get: function () {
  27988. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  27989. return this.levels;
  27990. }
  27991. }
  27992. } );
  27993. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  27994. get: function () {
  27995. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27996. },
  27997. set: function () {
  27998. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27999. }
  28000. } );
  28001. SkinnedMesh.prototype.initBones = function () {
  28002. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28003. };
  28004. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28005. get: function () {
  28006. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28007. return this.arcLengthDivisions;
  28008. },
  28009. set: function ( value ) {
  28010. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28011. this.arcLengthDivisions = value;
  28012. }
  28013. } );
  28014. //
  28015. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28016. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28017. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28018. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28019. this.setFocalLength( focalLength );
  28020. };
  28021. //
  28022. Object.defineProperties( Light.prototype, {
  28023. onlyShadow: {
  28024. set: function () {
  28025. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28026. }
  28027. },
  28028. shadowCameraFov: {
  28029. set: function ( value ) {
  28030. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28031. this.shadow.camera.fov = value;
  28032. }
  28033. },
  28034. shadowCameraLeft: {
  28035. set: function ( value ) {
  28036. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28037. this.shadow.camera.left = value;
  28038. }
  28039. },
  28040. shadowCameraRight: {
  28041. set: function ( value ) {
  28042. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28043. this.shadow.camera.right = value;
  28044. }
  28045. },
  28046. shadowCameraTop: {
  28047. set: function ( value ) {
  28048. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28049. this.shadow.camera.top = value;
  28050. }
  28051. },
  28052. shadowCameraBottom: {
  28053. set: function ( value ) {
  28054. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28055. this.shadow.camera.bottom = value;
  28056. }
  28057. },
  28058. shadowCameraNear: {
  28059. set: function ( value ) {
  28060. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28061. this.shadow.camera.near = value;
  28062. }
  28063. },
  28064. shadowCameraFar: {
  28065. set: function ( value ) {
  28066. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28067. this.shadow.camera.far = value;
  28068. }
  28069. },
  28070. shadowCameraVisible: {
  28071. set: function () {
  28072. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28073. }
  28074. },
  28075. shadowBias: {
  28076. set: function ( value ) {
  28077. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28078. this.shadow.bias = value;
  28079. }
  28080. },
  28081. shadowDarkness: {
  28082. set: function () {
  28083. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28084. }
  28085. },
  28086. shadowMapWidth: {
  28087. set: function ( value ) {
  28088. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28089. this.shadow.mapSize.width = value;
  28090. }
  28091. },
  28092. shadowMapHeight: {
  28093. set: function ( value ) {
  28094. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28095. this.shadow.mapSize.height = value;
  28096. }
  28097. }
  28098. } );
  28099. //
  28100. Object.defineProperties( BufferAttribute.prototype, {
  28101. length: {
  28102. get: function () {
  28103. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28104. return this.array.length;
  28105. }
  28106. },
  28107. copyIndicesArray: function ( /* indices */ ) {
  28108. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28109. }
  28110. } );
  28111. Object.assign( BufferGeometry.prototype, {
  28112. addIndex: function ( index ) {
  28113. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28114. this.setIndex( index );
  28115. },
  28116. addDrawCall: function ( start, count, indexOffset ) {
  28117. if ( indexOffset !== undefined ) {
  28118. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28119. }
  28120. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28121. this.addGroup( start, count );
  28122. },
  28123. clearDrawCalls: function () {
  28124. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28125. this.clearGroups();
  28126. },
  28127. computeTangents: function () {
  28128. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28129. },
  28130. computeOffsets: function () {
  28131. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28132. }
  28133. } );
  28134. Object.defineProperties( BufferGeometry.prototype, {
  28135. drawcalls: {
  28136. get: function () {
  28137. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28138. return this.groups;
  28139. }
  28140. },
  28141. offsets: {
  28142. get: function () {
  28143. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28144. return this.groups;
  28145. }
  28146. }
  28147. } );
  28148. //
  28149. Object.assign( ExtrudeBufferGeometry.prototype, {
  28150. getArrays: function () {
  28151. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28152. },
  28153. addShapeList: function () {
  28154. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28155. },
  28156. addShape: function () {
  28157. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28158. }
  28159. } );
  28160. //
  28161. Object.defineProperties( Uniform.prototype, {
  28162. dynamic: {
  28163. set: function () {
  28164. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28165. }
  28166. },
  28167. onUpdate: {
  28168. value: function () {
  28169. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28170. return this;
  28171. }
  28172. }
  28173. } );
  28174. //
  28175. Object.defineProperties( Material.prototype, {
  28176. wrapAround: {
  28177. get: function () {
  28178. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28179. },
  28180. set: function () {
  28181. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28182. }
  28183. },
  28184. overdraw: {
  28185. get: function () {
  28186. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28187. },
  28188. set: function () {
  28189. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28190. }
  28191. },
  28192. wrapRGB: {
  28193. get: function () {
  28194. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28195. return new Color();
  28196. }
  28197. },
  28198. shading: {
  28199. get: function () {
  28200. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28201. },
  28202. set: function ( value ) {
  28203. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28204. this.flatShading = ( value === FlatShading );
  28205. }
  28206. }
  28207. } );
  28208. Object.defineProperties( MeshPhongMaterial.prototype, {
  28209. metal: {
  28210. get: function () {
  28211. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28212. return false;
  28213. },
  28214. set: function () {
  28215. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28216. }
  28217. }
  28218. } );
  28219. Object.defineProperties( ShaderMaterial.prototype, {
  28220. derivatives: {
  28221. get: function () {
  28222. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28223. return this.extensions.derivatives;
  28224. },
  28225. set: function ( value ) {
  28226. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28227. this.extensions.derivatives = value;
  28228. }
  28229. }
  28230. } );
  28231. //
  28232. Object.assign( WebGLRenderer.prototype, {
  28233. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28234. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28235. this.setRenderTarget( renderTarget );
  28236. this.clear( color, depth, stencil );
  28237. },
  28238. animate: function ( callback ) {
  28239. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28240. this.setAnimationLoop( callback );
  28241. },
  28242. getCurrentRenderTarget: function () {
  28243. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28244. return this.getRenderTarget();
  28245. },
  28246. getMaxAnisotropy: function () {
  28247. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28248. return this.capabilities.getMaxAnisotropy();
  28249. },
  28250. getPrecision: function () {
  28251. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28252. return this.capabilities.precision;
  28253. },
  28254. resetGLState: function () {
  28255. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28256. return this.state.reset();
  28257. },
  28258. supportsFloatTextures: function () {
  28259. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28260. return this.extensions.get( 'OES_texture_float' );
  28261. },
  28262. supportsHalfFloatTextures: function () {
  28263. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28264. return this.extensions.get( 'OES_texture_half_float' );
  28265. },
  28266. supportsStandardDerivatives: function () {
  28267. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28268. return this.extensions.get( 'OES_standard_derivatives' );
  28269. },
  28270. supportsCompressedTextureS3TC: function () {
  28271. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28272. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28273. },
  28274. supportsCompressedTexturePVRTC: function () {
  28275. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28276. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28277. },
  28278. supportsBlendMinMax: function () {
  28279. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28280. return this.extensions.get( 'EXT_blend_minmax' );
  28281. },
  28282. supportsVertexTextures: function () {
  28283. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28284. return this.capabilities.vertexTextures;
  28285. },
  28286. supportsInstancedArrays: function () {
  28287. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28288. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28289. },
  28290. enableScissorTest: function ( boolean ) {
  28291. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28292. this.setScissorTest( boolean );
  28293. },
  28294. initMaterial: function () {
  28295. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28296. },
  28297. addPrePlugin: function () {
  28298. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28299. },
  28300. addPostPlugin: function () {
  28301. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28302. },
  28303. updateShadowMap: function () {
  28304. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28305. },
  28306. setFaceCulling: function () {
  28307. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28308. }
  28309. } );
  28310. Object.defineProperties( WebGLRenderer.prototype, {
  28311. shadowMapEnabled: {
  28312. get: function () {
  28313. return this.shadowMap.enabled;
  28314. },
  28315. set: function ( value ) {
  28316. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28317. this.shadowMap.enabled = value;
  28318. }
  28319. },
  28320. shadowMapType: {
  28321. get: function () {
  28322. return this.shadowMap.type;
  28323. },
  28324. set: function ( value ) {
  28325. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28326. this.shadowMap.type = value;
  28327. }
  28328. },
  28329. shadowMapCullFace: {
  28330. get: function () {
  28331. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28332. return undefined;
  28333. },
  28334. set: function ( /* value */ ) {
  28335. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28336. }
  28337. }
  28338. } );
  28339. Object.defineProperties( WebGLShadowMap.prototype, {
  28340. cullFace: {
  28341. get: function () {
  28342. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28343. return undefined;
  28344. },
  28345. set: function ( /* cullFace */ ) {
  28346. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28347. }
  28348. },
  28349. renderReverseSided: {
  28350. get: function () {
  28351. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28352. return undefined;
  28353. },
  28354. set: function () {
  28355. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28356. }
  28357. },
  28358. renderSingleSided: {
  28359. get: function () {
  28360. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28361. return undefined;
  28362. },
  28363. set: function () {
  28364. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28365. }
  28366. }
  28367. } );
  28368. //
  28369. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  28370. activeCubeFace: {
  28371. set: function ( /* value */ ) {
  28372. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  28373. }
  28374. },
  28375. activeMipMapLevel: {
  28376. set: function ( /* value */ ) {
  28377. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  28378. }
  28379. }
  28380. } );
  28381. //
  28382. Object.defineProperties( WebGLRenderTarget.prototype, {
  28383. wrapS: {
  28384. get: function () {
  28385. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28386. return this.texture.wrapS;
  28387. },
  28388. set: function ( value ) {
  28389. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28390. this.texture.wrapS = value;
  28391. }
  28392. },
  28393. wrapT: {
  28394. get: function () {
  28395. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28396. return this.texture.wrapT;
  28397. },
  28398. set: function ( value ) {
  28399. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28400. this.texture.wrapT = value;
  28401. }
  28402. },
  28403. magFilter: {
  28404. get: function () {
  28405. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28406. return this.texture.magFilter;
  28407. },
  28408. set: function ( value ) {
  28409. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28410. this.texture.magFilter = value;
  28411. }
  28412. },
  28413. minFilter: {
  28414. get: function () {
  28415. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28416. return this.texture.minFilter;
  28417. },
  28418. set: function ( value ) {
  28419. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28420. this.texture.minFilter = value;
  28421. }
  28422. },
  28423. anisotropy: {
  28424. get: function () {
  28425. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28426. return this.texture.anisotropy;
  28427. },
  28428. set: function ( value ) {
  28429. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28430. this.texture.anisotropy = value;
  28431. }
  28432. },
  28433. offset: {
  28434. get: function () {
  28435. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28436. return this.texture.offset;
  28437. },
  28438. set: function ( value ) {
  28439. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28440. this.texture.offset = value;
  28441. }
  28442. },
  28443. repeat: {
  28444. get: function () {
  28445. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28446. return this.texture.repeat;
  28447. },
  28448. set: function ( value ) {
  28449. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28450. this.texture.repeat = value;
  28451. }
  28452. },
  28453. format: {
  28454. get: function () {
  28455. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28456. return this.texture.format;
  28457. },
  28458. set: function ( value ) {
  28459. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28460. this.texture.format = value;
  28461. }
  28462. },
  28463. type: {
  28464. get: function () {
  28465. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28466. return this.texture.type;
  28467. },
  28468. set: function ( value ) {
  28469. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28470. this.texture.type = value;
  28471. }
  28472. },
  28473. generateMipmaps: {
  28474. get: function () {
  28475. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28476. return this.texture.generateMipmaps;
  28477. },
  28478. set: function ( value ) {
  28479. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28480. this.texture.generateMipmaps = value;
  28481. }
  28482. }
  28483. } );
  28484. //
  28485. Object.defineProperties( WebVRManager.prototype, {
  28486. standing: {
  28487. set: function ( /* value */ ) {
  28488. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  28489. }
  28490. },
  28491. userHeight: {
  28492. set: function ( /* value */ ) {
  28493. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  28494. }
  28495. }
  28496. } );
  28497. //
  28498. Audio.prototype.load = function ( file ) {
  28499. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  28500. var scope = this;
  28501. var audioLoader = new AudioLoader();
  28502. audioLoader.load( file, function ( buffer ) {
  28503. scope.setBuffer( buffer );
  28504. } );
  28505. return this;
  28506. };
  28507. AudioAnalyser.prototype.getData = function () {
  28508. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  28509. return this.getFrequencyData();
  28510. };
  28511. //
  28512. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  28513. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  28514. return this.update( renderer, scene );
  28515. };
  28516. //
  28517. var GeometryUtils = {
  28518. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  28519. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  28520. var matrix;
  28521. if ( geometry2.isMesh ) {
  28522. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  28523. matrix = geometry2.matrix;
  28524. geometry2 = geometry2.geometry;
  28525. }
  28526. geometry1.merge( geometry2, matrix, materialIndexOffset );
  28527. },
  28528. center: function ( geometry ) {
  28529. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  28530. return geometry.center();
  28531. }
  28532. };
  28533. ImageUtils.crossOrigin = undefined;
  28534. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  28535. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  28536. var loader = new TextureLoader();
  28537. loader.setCrossOrigin( this.crossOrigin );
  28538. var texture = loader.load( url, onLoad, undefined, onError );
  28539. if ( mapping ) texture.mapping = mapping;
  28540. return texture;
  28541. };
  28542. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  28543. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  28544. var loader = new CubeTextureLoader();
  28545. loader.setCrossOrigin( this.crossOrigin );
  28546. var texture = loader.load( urls, onLoad, undefined, onError );
  28547. if ( mapping ) texture.mapping = mapping;
  28548. return texture;
  28549. };
  28550. ImageUtils.loadCompressedTexture = function () {
  28551. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  28552. };
  28553. ImageUtils.loadCompressedTextureCube = function () {
  28554. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  28555. };
  28556. //
  28557. function Projector() {
  28558. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  28559. this.projectVector = function ( vector, camera ) {
  28560. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  28561. vector.project( camera );
  28562. };
  28563. this.unprojectVector = function ( vector, camera ) {
  28564. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  28565. vector.unproject( camera );
  28566. };
  28567. this.pickingRay = function () {
  28568. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  28569. };
  28570. }
  28571. //
  28572. function CanvasRenderer() {
  28573. console.error( 'THREE.CanvasRenderer has been removed' );
  28574. }
  28575. //
  28576. function JSONLoader() {
  28577. console.error( 'THREE.JSONLoader has been removed.' );
  28578. }
  28579. //
  28580. var SceneUtils = {
  28581. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  28582. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28583. },
  28584. detach: function ( /* child, parent, scene */ ) {
  28585. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28586. },
  28587. attach: function ( /* child, scene, parent */ ) {
  28588. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28589. }
  28590. };
  28591. //
  28592. function LensFlare() {
  28593. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  28594. }
  28595. export { WebGLMultisampleRenderTarget, WebGLRenderTargetCube, WebGLRenderTarget, WebGLRenderer, ShaderLib, UniformsLib, UniformsUtils, ShaderChunk, FogExp2, Fog, Scene, Sprite, LOD, SkinnedMesh, Skeleton, Bone, Mesh, LineSegments, LineLoop, Line, Points, Group, VideoTexture, DataTexture, DataTexture3D, CompressedTexture, CubeTexture, CanvasTexture, DepthTexture, Texture, AnimationLoader, CompressedTextureLoader, DataTextureLoader, CubeTextureLoader, TextureLoader, ObjectLoader, MaterialLoader, BufferGeometryLoader, DefaultLoadingManager, LoadingManager, 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, PositionalAudioHelper, FaceNormalsHelper, DirectionalLightHelper, CameraHelper, BoxHelper, Box3Helper, PlaneHelper, ArrowHelper, AxesHelper, Shape, Path, ShapePath, Font, CurvePath, Curve, ImageUtils, 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, BoxGeometry as CubeGeometry, BoxBufferGeometry, ShadowMaterial, SpriteMaterial, RawShaderMaterial, ShaderMaterial, PointsMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshPhongMaterial, MeshToonMaterial, MeshNormalMaterial, MeshLambertMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshBasicMaterial, MeshMatcapMaterial, 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, ACESFilmicToneMapping, 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, RedFormat, 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, TangentSpaceNormalMap, ObjectSpaceNormalMap, 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, Projector, CanvasRenderer, JSONLoader, SceneUtils, LensFlare };