three.module.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962
  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 = '108dev';
  96. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  97. var TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  98. var CullFaceNone = 0;
  99. var CullFaceBack = 1;
  100. var CullFaceFront = 2;
  101. var CullFaceFrontBack = 3;
  102. var FrontFaceDirectionCW = 0;
  103. var FrontFaceDirectionCCW = 1;
  104. var BasicShadowMap = 0;
  105. var PCFShadowMap = 1;
  106. var PCFSoftShadowMap = 2;
  107. var FrontSide = 0;
  108. var BackSide = 1;
  109. var DoubleSide = 2;
  110. var FlatShading = 1;
  111. var SmoothShading = 2;
  112. var NoColors = 0;
  113. var FaceColors = 1;
  114. var VertexColors = 2;
  115. var NoBlending = 0;
  116. var NormalBlending = 1;
  117. var AdditiveBlending = 2;
  118. var SubtractiveBlending = 3;
  119. var MultiplyBlending = 4;
  120. var CustomBlending = 5;
  121. var AddEquation = 100;
  122. var SubtractEquation = 101;
  123. var ReverseSubtractEquation = 102;
  124. var MinEquation = 103;
  125. var MaxEquation = 104;
  126. var ZeroFactor = 200;
  127. var OneFactor = 201;
  128. var SrcColorFactor = 202;
  129. var OneMinusSrcColorFactor = 203;
  130. var SrcAlphaFactor = 204;
  131. var OneMinusSrcAlphaFactor = 205;
  132. var DstAlphaFactor = 206;
  133. var OneMinusDstAlphaFactor = 207;
  134. var DstColorFactor = 208;
  135. var OneMinusDstColorFactor = 209;
  136. var SrcAlphaSaturateFactor = 210;
  137. var NeverDepth = 0;
  138. var AlwaysDepth = 1;
  139. var LessDepth = 2;
  140. var LessEqualDepth = 3;
  141. var EqualDepth = 4;
  142. var GreaterEqualDepth = 5;
  143. var GreaterDepth = 6;
  144. var NotEqualDepth = 7;
  145. var MultiplyOperation = 0;
  146. var MixOperation = 1;
  147. var AddOperation = 2;
  148. var NoToneMapping = 0;
  149. var LinearToneMapping = 1;
  150. var ReinhardToneMapping = 2;
  151. var Uncharted2ToneMapping = 3;
  152. var CineonToneMapping = 4;
  153. var ACESFilmicToneMapping = 5;
  154. var UVMapping = 300;
  155. var CubeReflectionMapping = 301;
  156. var CubeRefractionMapping = 302;
  157. var EquirectangularReflectionMapping = 303;
  158. var EquirectangularRefractionMapping = 304;
  159. var SphericalReflectionMapping = 305;
  160. var CubeUVReflectionMapping = 306;
  161. var CubeUVRefractionMapping = 307;
  162. var RepeatWrapping = 1000;
  163. var ClampToEdgeWrapping = 1001;
  164. var MirroredRepeatWrapping = 1002;
  165. var NearestFilter = 1003;
  166. var NearestMipmapNearestFilter = 1004;
  167. var NearestMipMapNearestFilter = 1004;
  168. var NearestMipmapLinearFilter = 1005;
  169. var NearestMipMapLinearFilter = 1005;
  170. var LinearFilter = 1006;
  171. var LinearMipmapNearestFilter = 1007;
  172. var LinearMipMapNearestFilter = 1007;
  173. var LinearMipmapLinearFilter = 1008;
  174. var LinearMipMapLinearFilter = 1008;
  175. var UnsignedByteType = 1009;
  176. var ByteType = 1010;
  177. var ShortType = 1011;
  178. var UnsignedShortType = 1012;
  179. var IntType = 1013;
  180. var UnsignedIntType = 1014;
  181. var FloatType = 1015;
  182. var HalfFloatType = 1016;
  183. var UnsignedShort4444Type = 1017;
  184. var UnsignedShort5551Type = 1018;
  185. var UnsignedShort565Type = 1019;
  186. var UnsignedInt248Type = 1020;
  187. var AlphaFormat = 1021;
  188. var RGBFormat = 1022;
  189. var RGBAFormat = 1023;
  190. var LuminanceFormat = 1024;
  191. var LuminanceAlphaFormat = 1025;
  192. var RGBEFormat = RGBAFormat;
  193. var DepthFormat = 1026;
  194. var DepthStencilFormat = 1027;
  195. var RedFormat = 1028;
  196. var RGB_S3TC_DXT1_Format = 33776;
  197. var RGBA_S3TC_DXT1_Format = 33777;
  198. var RGBA_S3TC_DXT3_Format = 33778;
  199. var RGBA_S3TC_DXT5_Format = 33779;
  200. var RGB_PVRTC_4BPPV1_Format = 35840;
  201. var RGB_PVRTC_2BPPV1_Format = 35841;
  202. var RGBA_PVRTC_4BPPV1_Format = 35842;
  203. var RGBA_PVRTC_2BPPV1_Format = 35843;
  204. var RGB_ETC1_Format = 36196;
  205. var RGBA_ASTC_4x4_Format = 37808;
  206. var RGBA_ASTC_5x4_Format = 37809;
  207. var RGBA_ASTC_5x5_Format = 37810;
  208. var RGBA_ASTC_6x5_Format = 37811;
  209. var RGBA_ASTC_6x6_Format = 37812;
  210. var RGBA_ASTC_8x5_Format = 37813;
  211. var RGBA_ASTC_8x6_Format = 37814;
  212. var RGBA_ASTC_8x8_Format = 37815;
  213. var RGBA_ASTC_10x5_Format = 37816;
  214. var RGBA_ASTC_10x6_Format = 37817;
  215. var RGBA_ASTC_10x8_Format = 37818;
  216. var RGBA_ASTC_10x10_Format = 37819;
  217. var RGBA_ASTC_12x10_Format = 37820;
  218. var RGBA_ASTC_12x12_Format = 37821;
  219. var LoopOnce = 2200;
  220. var LoopRepeat = 2201;
  221. var LoopPingPong = 2202;
  222. var InterpolateDiscrete = 2300;
  223. var InterpolateLinear = 2301;
  224. var InterpolateSmooth = 2302;
  225. var ZeroCurvatureEnding = 2400;
  226. var ZeroSlopeEnding = 2401;
  227. var WrapAroundEnding = 2402;
  228. var TrianglesDrawMode = 0;
  229. var TriangleStripDrawMode = 1;
  230. var TriangleFanDrawMode = 2;
  231. var LinearEncoding = 3000;
  232. var sRGBEncoding = 3001;
  233. var GammaEncoding = 3007;
  234. var RGBEEncoding = 3002;
  235. var LogLuvEncoding = 3003;
  236. var RGBM7Encoding = 3004;
  237. var RGBM16Encoding = 3005;
  238. var RGBDEncoding = 3006;
  239. var BasicDepthPacking = 3200;
  240. var RGBADepthPacking = 3201;
  241. var TangentSpaceNormalMap = 0;
  242. var ObjectSpaceNormalMap = 1;
  243. var ZeroStencilOp = 0;
  244. var KeepStencilOp = 7680;
  245. var ReplaceStencilOp = 7681;
  246. var IncrementStencilOp = 7682;
  247. var DecrementStencilOp = 7683;
  248. var IncrementWrapStencilOp = 34055;
  249. var DecrementWrapStencilOp = 34056;
  250. var InvertStencilOp = 5386;
  251. var NeverStencilFunc = 512;
  252. var LessStencilFunc = 513;
  253. var EqualStencilFunc = 514;
  254. var LessEqualStencilFunc = 515;
  255. var GreaterStencilFunc = 516;
  256. var NotEqualStencilFunc = 517;
  257. var GreaterEqualStencilFunc = 518;
  258. var AlwaysStencilFunc = 519;
  259. /**
  260. * @author alteredq / http://alteredqualia.com/
  261. * @author mrdoob / http://mrdoob.com/
  262. */
  263. var _Math = {
  264. DEG2RAD: Math.PI / 180,
  265. RAD2DEG: 180 / Math.PI,
  266. generateUUID: ( function () {
  267. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  268. var lut = [];
  269. for ( var i = 0; i < 256; i ++ ) {
  270. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  271. }
  272. return function generateUUID() {
  273. var d0 = Math.random() * 0xffffffff | 0;
  274. var d1 = Math.random() * 0xffffffff | 0;
  275. var d2 = Math.random() * 0xffffffff | 0;
  276. var d3 = Math.random() * 0xffffffff | 0;
  277. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  278. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  279. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  280. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  281. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  282. return uuid.toUpperCase();
  283. };
  284. } )(),
  285. clamp: function ( value, min, max ) {
  286. return Math.max( min, Math.min( max, value ) );
  287. },
  288. // compute euclidian modulo of m % n
  289. // https://en.wikipedia.org/wiki/Modulo_operation
  290. euclideanModulo: function ( n, m ) {
  291. return ( ( n % m ) + m ) % m;
  292. },
  293. // Linear mapping from range <a1, a2> to range <b1, b2>
  294. mapLinear: function ( x, a1, a2, b1, b2 ) {
  295. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  296. },
  297. // https://en.wikipedia.org/wiki/Linear_interpolation
  298. lerp: function ( x, y, t ) {
  299. return ( 1 - t ) * x + t * y;
  300. },
  301. // http://en.wikipedia.org/wiki/Smoothstep
  302. smoothstep: function ( x, min, max ) {
  303. if ( x <= min ) return 0;
  304. if ( x >= max ) return 1;
  305. x = ( x - min ) / ( max - min );
  306. return x * x * ( 3 - 2 * x );
  307. },
  308. smootherstep: function ( x, min, max ) {
  309. if ( x <= min ) return 0;
  310. if ( x >= max ) return 1;
  311. x = ( x - min ) / ( max - min );
  312. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  313. },
  314. // Random integer from <low, high> interval
  315. randInt: function ( low, high ) {
  316. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  317. },
  318. // Random float from <low, high> interval
  319. randFloat: function ( low, high ) {
  320. return low + Math.random() * ( high - low );
  321. },
  322. // Random float from <-range/2, range/2> interval
  323. randFloatSpread: function ( range ) {
  324. return range * ( 0.5 - Math.random() );
  325. },
  326. degToRad: function ( degrees ) {
  327. return degrees * _Math.DEG2RAD;
  328. },
  329. radToDeg: function ( radians ) {
  330. return radians * _Math.RAD2DEG;
  331. },
  332. isPowerOfTwo: function ( value ) {
  333. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  334. },
  335. ceilPowerOfTwo: function ( value ) {
  336. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  337. },
  338. floorPowerOfTwo: function ( value ) {
  339. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  340. }
  341. };
  342. /**
  343. * @author mrdoob / http://mrdoob.com/
  344. * @author philogb / http://blog.thejit.org/
  345. * @author egraether / http://egraether.com/
  346. * @author zz85 / http://www.lab4games.net/zz85/blog
  347. */
  348. function Vector2( x, y ) {
  349. this.x = x || 0;
  350. this.y = y || 0;
  351. }
  352. Object.defineProperties( Vector2.prototype, {
  353. "width": {
  354. get: function () {
  355. return this.x;
  356. },
  357. set: function ( value ) {
  358. this.x = value;
  359. }
  360. },
  361. "height": {
  362. get: function () {
  363. return this.y;
  364. },
  365. set: function ( value ) {
  366. this.y = value;
  367. }
  368. }
  369. } );
  370. Object.assign( Vector2.prototype, {
  371. isVector2: true,
  372. set: function ( x, y ) {
  373. this.x = x;
  374. this.y = y;
  375. return this;
  376. },
  377. setScalar: function ( scalar ) {
  378. this.x = scalar;
  379. this.y = scalar;
  380. return this;
  381. },
  382. setX: function ( x ) {
  383. this.x = x;
  384. return this;
  385. },
  386. setY: function ( y ) {
  387. this.y = y;
  388. return this;
  389. },
  390. setComponent: function ( index, value ) {
  391. switch ( index ) {
  392. case 0: this.x = value; break;
  393. case 1: this.y = value; break;
  394. default: throw new Error( 'index is out of range: ' + index );
  395. }
  396. return this;
  397. },
  398. getComponent: function ( index ) {
  399. switch ( index ) {
  400. case 0: return this.x;
  401. case 1: return this.y;
  402. default: throw new Error( 'index is out of range: ' + index );
  403. }
  404. },
  405. clone: function () {
  406. return new this.constructor( this.x, this.y );
  407. },
  408. copy: function ( v ) {
  409. this.x = v.x;
  410. this.y = v.y;
  411. return this;
  412. },
  413. add: function ( v, w ) {
  414. if ( w !== undefined ) {
  415. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  416. return this.addVectors( v, w );
  417. }
  418. this.x += v.x;
  419. this.y += v.y;
  420. return this;
  421. },
  422. addScalar: function ( s ) {
  423. this.x += s;
  424. this.y += s;
  425. return this;
  426. },
  427. addVectors: function ( a, b ) {
  428. this.x = a.x + b.x;
  429. this.y = a.y + b.y;
  430. return this;
  431. },
  432. addScaledVector: function ( v, s ) {
  433. this.x += v.x * s;
  434. this.y += v.y * s;
  435. return this;
  436. },
  437. sub: function ( v, w ) {
  438. if ( w !== undefined ) {
  439. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  440. return this.subVectors( v, w );
  441. }
  442. this.x -= v.x;
  443. this.y -= v.y;
  444. return this;
  445. },
  446. subScalar: function ( s ) {
  447. this.x -= s;
  448. this.y -= s;
  449. return this;
  450. },
  451. subVectors: function ( a, b ) {
  452. this.x = a.x - b.x;
  453. this.y = a.y - b.y;
  454. return this;
  455. },
  456. multiply: function ( v ) {
  457. this.x *= v.x;
  458. this.y *= v.y;
  459. return this;
  460. },
  461. multiplyScalar: function ( scalar ) {
  462. this.x *= scalar;
  463. this.y *= scalar;
  464. return this;
  465. },
  466. divide: function ( v ) {
  467. this.x /= v.x;
  468. this.y /= v.y;
  469. return this;
  470. },
  471. divideScalar: function ( scalar ) {
  472. return this.multiplyScalar( 1 / scalar );
  473. },
  474. applyMatrix3: function ( m ) {
  475. var x = this.x, y = this.y;
  476. var e = m.elements;
  477. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  478. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  479. return this;
  480. },
  481. min: function ( v ) {
  482. this.x = Math.min( this.x, v.x );
  483. this.y = Math.min( this.y, v.y );
  484. return this;
  485. },
  486. max: function ( v ) {
  487. this.x = Math.max( this.x, v.x );
  488. this.y = Math.max( this.y, v.y );
  489. return this;
  490. },
  491. clamp: function ( min, max ) {
  492. // assumes min < max, componentwise
  493. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  494. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  495. return this;
  496. },
  497. clampScalar: function ( minVal, maxVal ) {
  498. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  499. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  500. return this;
  501. },
  502. clampLength: function ( min, max ) {
  503. var length = this.length();
  504. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  505. },
  506. floor: function () {
  507. this.x = Math.floor( this.x );
  508. this.y = Math.floor( this.y );
  509. return this;
  510. },
  511. ceil: function () {
  512. this.x = Math.ceil( this.x );
  513. this.y = Math.ceil( this.y );
  514. return this;
  515. },
  516. round: function () {
  517. this.x = Math.round( this.x );
  518. this.y = Math.round( this.y );
  519. return this;
  520. },
  521. roundToZero: function () {
  522. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  523. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  524. return this;
  525. },
  526. negate: function () {
  527. this.x = - this.x;
  528. this.y = - this.y;
  529. return this;
  530. },
  531. dot: function ( v ) {
  532. return this.x * v.x + this.y * v.y;
  533. },
  534. cross: function ( v ) {
  535. return this.x * v.y - this.y * v.x;
  536. },
  537. lengthSq: function () {
  538. return this.x * this.x + this.y * this.y;
  539. },
  540. length: function () {
  541. return Math.sqrt( this.x * this.x + this.y * this.y );
  542. },
  543. manhattanLength: function () {
  544. return Math.abs( this.x ) + Math.abs( this.y );
  545. },
  546. normalize: function () {
  547. return this.divideScalar( this.length() || 1 );
  548. },
  549. angle: function () {
  550. // computes the angle in radians with respect to the positive x-axis
  551. var angle = Math.atan2( this.y, this.x );
  552. if ( angle < 0 ) angle += 2 * Math.PI;
  553. return angle;
  554. },
  555. distanceTo: function ( v ) {
  556. return Math.sqrt( this.distanceToSquared( v ) );
  557. },
  558. distanceToSquared: function ( v ) {
  559. var dx = this.x - v.x, dy = this.y - v.y;
  560. return dx * dx + dy * dy;
  561. },
  562. manhattanDistanceTo: function ( v ) {
  563. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  564. },
  565. setLength: function ( length ) {
  566. return this.normalize().multiplyScalar( length );
  567. },
  568. lerp: function ( v, alpha ) {
  569. this.x += ( v.x - this.x ) * alpha;
  570. this.y += ( v.y - this.y ) * alpha;
  571. return this;
  572. },
  573. lerpVectors: function ( v1, v2, alpha ) {
  574. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  575. },
  576. equals: function ( v ) {
  577. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  578. },
  579. fromArray: function ( array, offset ) {
  580. if ( offset === undefined ) offset = 0;
  581. this.x = array[ offset ];
  582. this.y = array[ offset + 1 ];
  583. return this;
  584. },
  585. toArray: function ( array, offset ) {
  586. if ( array === undefined ) array = [];
  587. if ( offset === undefined ) offset = 0;
  588. array[ offset ] = this.x;
  589. array[ offset + 1 ] = this.y;
  590. return array;
  591. },
  592. fromBufferAttribute: function ( attribute, index, offset ) {
  593. if ( offset !== undefined ) {
  594. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  595. }
  596. this.x = attribute.getX( index );
  597. this.y = attribute.getY( index );
  598. return this;
  599. },
  600. rotateAround: function ( center, angle ) {
  601. var c = Math.cos( angle ), s = Math.sin( angle );
  602. var x = this.x - center.x;
  603. var y = this.y - center.y;
  604. this.x = x * c - y * s + center.x;
  605. this.y = x * s + y * c + center.y;
  606. return this;
  607. }
  608. } );
  609. /**
  610. * @author mikael emtinger / http://gomo.se/
  611. * @author alteredq / http://alteredqualia.com/
  612. * @author WestLangley / http://github.com/WestLangley
  613. * @author bhouston / http://clara.io
  614. */
  615. function Quaternion( x, y, z, w ) {
  616. this._x = x || 0;
  617. this._y = y || 0;
  618. this._z = z || 0;
  619. this._w = ( w !== undefined ) ? w : 1;
  620. }
  621. Object.assign( Quaternion, {
  622. slerp: function ( qa, qb, qm, t ) {
  623. return qm.copy( qa ).slerp( qb, t );
  624. },
  625. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  626. // fuzz-free, array-based Quaternion SLERP operation
  627. var x0 = src0[ srcOffset0 + 0 ],
  628. y0 = src0[ srcOffset0 + 1 ],
  629. z0 = src0[ srcOffset0 + 2 ],
  630. w0 = src0[ srcOffset0 + 3 ],
  631. x1 = src1[ srcOffset1 + 0 ],
  632. y1 = src1[ srcOffset1 + 1 ],
  633. z1 = src1[ srcOffset1 + 2 ],
  634. w1 = src1[ srcOffset1 + 3 ];
  635. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  636. var s = 1 - t,
  637. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  638. dir = ( cos >= 0 ? 1 : - 1 ),
  639. sqrSin = 1 - cos * cos;
  640. // Skip the Slerp for tiny steps to avoid numeric problems:
  641. if ( sqrSin > Number.EPSILON ) {
  642. var sin = Math.sqrt( sqrSin ),
  643. len = Math.atan2( sin, cos * dir );
  644. s = Math.sin( s * len ) / sin;
  645. t = Math.sin( t * len ) / sin;
  646. }
  647. var tDir = t * dir;
  648. x0 = x0 * s + x1 * tDir;
  649. y0 = y0 * s + y1 * tDir;
  650. z0 = z0 * s + z1 * tDir;
  651. w0 = w0 * s + w1 * tDir;
  652. // Normalize in case we just did a lerp:
  653. if ( s === 1 - t ) {
  654. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  655. x0 *= f;
  656. y0 *= f;
  657. z0 *= f;
  658. w0 *= f;
  659. }
  660. }
  661. dst[ dstOffset ] = x0;
  662. dst[ dstOffset + 1 ] = y0;
  663. dst[ dstOffset + 2 ] = z0;
  664. dst[ dstOffset + 3 ] = w0;
  665. }
  666. } );
  667. Object.defineProperties( Quaternion.prototype, {
  668. x: {
  669. get: function () {
  670. return this._x;
  671. },
  672. set: function ( value ) {
  673. this._x = value;
  674. this._onChangeCallback();
  675. }
  676. },
  677. y: {
  678. get: function () {
  679. return this._y;
  680. },
  681. set: function ( value ) {
  682. this._y = value;
  683. this._onChangeCallback();
  684. }
  685. },
  686. z: {
  687. get: function () {
  688. return this._z;
  689. },
  690. set: function ( value ) {
  691. this._z = value;
  692. this._onChangeCallback();
  693. }
  694. },
  695. w: {
  696. get: function () {
  697. return this._w;
  698. },
  699. set: function ( value ) {
  700. this._w = value;
  701. this._onChangeCallback();
  702. }
  703. }
  704. } );
  705. Object.assign( Quaternion.prototype, {
  706. isQuaternion: true,
  707. set: function ( x, y, z, w ) {
  708. this._x = x;
  709. this._y = y;
  710. this._z = z;
  711. this._w = w;
  712. this._onChangeCallback();
  713. return this;
  714. },
  715. clone: function () {
  716. return new this.constructor( this._x, this._y, this._z, this._w );
  717. },
  718. copy: function ( quaternion ) {
  719. this._x = quaternion.x;
  720. this._y = quaternion.y;
  721. this._z = quaternion.z;
  722. this._w = quaternion.w;
  723. this._onChangeCallback();
  724. return this;
  725. },
  726. setFromEuler: function ( euler, update ) {
  727. if ( ! ( euler && euler.isEuler ) ) {
  728. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  729. }
  730. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  731. // http://www.mathworks.com/matlabcentral/fileexchange/
  732. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  733. // content/SpinCalc.m
  734. var cos = Math.cos;
  735. var sin = Math.sin;
  736. var c1 = cos( x / 2 );
  737. var c2 = cos( y / 2 );
  738. var c3 = cos( z / 2 );
  739. var s1 = sin( x / 2 );
  740. var s2 = sin( y / 2 );
  741. var s3 = sin( z / 2 );
  742. if ( order === 'XYZ' ) {
  743. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  744. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  745. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  746. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  747. } else if ( order === 'YXZ' ) {
  748. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  749. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  750. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  751. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  752. } else if ( order === 'ZXY' ) {
  753. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  754. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  755. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  756. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  757. } else if ( order === 'ZYX' ) {
  758. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  759. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  760. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  761. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  762. } else if ( order === 'YZX' ) {
  763. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  764. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  765. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  766. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  767. } else if ( order === 'XZY' ) {
  768. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  769. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  770. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  771. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  772. }
  773. if ( update !== false ) this._onChangeCallback();
  774. return this;
  775. },
  776. setFromAxisAngle: function ( axis, angle ) {
  777. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  778. // assumes axis is normalized
  779. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  780. this._x = axis.x * s;
  781. this._y = axis.y * s;
  782. this._z = axis.z * s;
  783. this._w = Math.cos( halfAngle );
  784. this._onChangeCallback();
  785. return this;
  786. },
  787. setFromRotationMatrix: function ( m ) {
  788. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  789. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  790. var te = m.elements,
  791. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  792. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  793. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  794. trace = m11 + m22 + m33,
  795. s;
  796. if ( trace > 0 ) {
  797. s = 0.5 / Math.sqrt( trace + 1.0 );
  798. this._w = 0.25 / s;
  799. this._x = ( m32 - m23 ) * s;
  800. this._y = ( m13 - m31 ) * s;
  801. this._z = ( m21 - m12 ) * s;
  802. } else if ( m11 > m22 && m11 > m33 ) {
  803. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  804. this._w = ( m32 - m23 ) / s;
  805. this._x = 0.25 * s;
  806. this._y = ( m12 + m21 ) / s;
  807. this._z = ( m13 + m31 ) / s;
  808. } else if ( m22 > m33 ) {
  809. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  810. this._w = ( m13 - m31 ) / s;
  811. this._x = ( m12 + m21 ) / s;
  812. this._y = 0.25 * s;
  813. this._z = ( m23 + m32 ) / s;
  814. } else {
  815. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  816. this._w = ( m21 - m12 ) / s;
  817. this._x = ( m13 + m31 ) / s;
  818. this._y = ( m23 + m32 ) / s;
  819. this._z = 0.25 * s;
  820. }
  821. this._onChangeCallback();
  822. return this;
  823. },
  824. setFromUnitVectors: function ( vFrom, vTo ) {
  825. // assumes direction vectors vFrom and vTo are normalized
  826. var EPS = 0.000001;
  827. var r = vFrom.dot( vTo ) + 1;
  828. if ( r < EPS ) {
  829. r = 0;
  830. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  831. this._x = - vFrom.y;
  832. this._y = vFrom.x;
  833. this._z = 0;
  834. this._w = r;
  835. } else {
  836. this._x = 0;
  837. this._y = - vFrom.z;
  838. this._z = vFrom.y;
  839. this._w = r;
  840. }
  841. } else {
  842. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  843. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  844. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  845. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  846. this._w = r;
  847. }
  848. return this.normalize();
  849. },
  850. angleTo: function ( q ) {
  851. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  852. },
  853. rotateTowards: function ( q, step ) {
  854. var angle = this.angleTo( q );
  855. if ( angle === 0 ) return this;
  856. var t = Math.min( 1, step / angle );
  857. this.slerp( q, t );
  858. return this;
  859. },
  860. inverse: function () {
  861. // quaternion is assumed to have unit length
  862. return this.conjugate();
  863. },
  864. conjugate: function () {
  865. this._x *= - 1;
  866. this._y *= - 1;
  867. this._z *= - 1;
  868. this._onChangeCallback();
  869. return this;
  870. },
  871. dot: function ( v ) {
  872. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  873. },
  874. lengthSq: function () {
  875. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  876. },
  877. length: function () {
  878. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  879. },
  880. normalize: function () {
  881. var l = this.length();
  882. if ( l === 0 ) {
  883. this._x = 0;
  884. this._y = 0;
  885. this._z = 0;
  886. this._w = 1;
  887. } else {
  888. l = 1 / l;
  889. this._x = this._x * l;
  890. this._y = this._y * l;
  891. this._z = this._z * l;
  892. this._w = this._w * l;
  893. }
  894. this._onChangeCallback();
  895. return this;
  896. },
  897. multiply: function ( q, p ) {
  898. if ( p !== undefined ) {
  899. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  900. return this.multiplyQuaternions( q, p );
  901. }
  902. return this.multiplyQuaternions( this, q );
  903. },
  904. premultiply: function ( q ) {
  905. return this.multiplyQuaternions( q, this );
  906. },
  907. multiplyQuaternions: function ( a, b ) {
  908. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  909. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  910. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  911. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  912. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  913. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  914. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  915. this._onChangeCallback();
  916. return this;
  917. },
  918. slerp: function ( qb, t ) {
  919. if ( t === 0 ) return this;
  920. if ( t === 1 ) return this.copy( qb );
  921. var x = this._x, y = this._y, z = this._z, w = this._w;
  922. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  923. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  924. if ( cosHalfTheta < 0 ) {
  925. this._w = - qb._w;
  926. this._x = - qb._x;
  927. this._y = - qb._y;
  928. this._z = - qb._z;
  929. cosHalfTheta = - cosHalfTheta;
  930. } else {
  931. this.copy( qb );
  932. }
  933. if ( cosHalfTheta >= 1.0 ) {
  934. this._w = w;
  935. this._x = x;
  936. this._y = y;
  937. this._z = z;
  938. return this;
  939. }
  940. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  941. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  942. var s = 1 - t;
  943. this._w = s * w + t * this._w;
  944. this._x = s * x + t * this._x;
  945. this._y = s * y + t * this._y;
  946. this._z = s * z + t * this._z;
  947. this.normalize();
  948. this._onChangeCallback();
  949. return this;
  950. }
  951. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  952. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  953. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  954. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  955. this._w = ( w * ratioA + this._w * ratioB );
  956. this._x = ( x * ratioA + this._x * ratioB );
  957. this._y = ( y * ratioA + this._y * ratioB );
  958. this._z = ( z * ratioA + this._z * ratioB );
  959. this._onChangeCallback();
  960. return this;
  961. },
  962. equals: function ( quaternion ) {
  963. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  964. },
  965. fromArray: function ( array, offset ) {
  966. if ( offset === undefined ) offset = 0;
  967. this._x = array[ offset ];
  968. this._y = array[ offset + 1 ];
  969. this._z = array[ offset + 2 ];
  970. this._w = array[ offset + 3 ];
  971. this._onChangeCallback();
  972. return this;
  973. },
  974. toArray: function ( array, offset ) {
  975. if ( array === undefined ) array = [];
  976. if ( offset === undefined ) offset = 0;
  977. array[ offset ] = this._x;
  978. array[ offset + 1 ] = this._y;
  979. array[ offset + 2 ] = this._z;
  980. array[ offset + 3 ] = this._w;
  981. return array;
  982. },
  983. _onChange: function ( callback ) {
  984. this._onChangeCallback = callback;
  985. return this;
  986. },
  987. _onChangeCallback: function () {}
  988. } );
  989. /**
  990. * @author mrdoob / http://mrdoob.com/
  991. * @author kile / http://kile.stravaganza.org/
  992. * @author philogb / http://blog.thejit.org/
  993. * @author mikael emtinger / http://gomo.se/
  994. * @author egraether / http://egraether.com/
  995. * @author WestLangley / http://github.com/WestLangley
  996. */
  997. function Vector3( x, y, z ) {
  998. this.x = x || 0;
  999. this.y = y || 0;
  1000. this.z = z || 0;
  1001. }
  1002. Object.assign( Vector3.prototype, {
  1003. isVector3: true,
  1004. set: function ( x, y, z ) {
  1005. this.x = x;
  1006. this.y = y;
  1007. this.z = z;
  1008. return this;
  1009. },
  1010. setScalar: function ( scalar ) {
  1011. this.x = scalar;
  1012. this.y = scalar;
  1013. this.z = scalar;
  1014. return this;
  1015. },
  1016. setX: function ( x ) {
  1017. this.x = x;
  1018. return this;
  1019. },
  1020. setY: function ( y ) {
  1021. this.y = y;
  1022. return this;
  1023. },
  1024. setZ: function ( z ) {
  1025. this.z = z;
  1026. return this;
  1027. },
  1028. setComponent: function ( index, value ) {
  1029. switch ( index ) {
  1030. case 0: this.x = value; break;
  1031. case 1: this.y = value; break;
  1032. case 2: this.z = value; break;
  1033. default: throw new Error( 'index is out of range: ' + index );
  1034. }
  1035. return this;
  1036. },
  1037. getComponent: function ( index ) {
  1038. switch ( index ) {
  1039. case 0: return this.x;
  1040. case 1: return this.y;
  1041. case 2: return this.z;
  1042. default: throw new Error( 'index is out of range: ' + index );
  1043. }
  1044. },
  1045. clone: function () {
  1046. return new this.constructor( this.x, this.y, this.z );
  1047. },
  1048. copy: function ( v ) {
  1049. this.x = v.x;
  1050. this.y = v.y;
  1051. this.z = v.z;
  1052. return this;
  1053. },
  1054. add: function ( v, w ) {
  1055. if ( w !== undefined ) {
  1056. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1057. return this.addVectors( v, w );
  1058. }
  1059. this.x += v.x;
  1060. this.y += v.y;
  1061. this.z += v.z;
  1062. return this;
  1063. },
  1064. addScalar: function ( s ) {
  1065. this.x += s;
  1066. this.y += s;
  1067. this.z += s;
  1068. return this;
  1069. },
  1070. addVectors: function ( a, b ) {
  1071. this.x = a.x + b.x;
  1072. this.y = a.y + b.y;
  1073. this.z = a.z + b.z;
  1074. return this;
  1075. },
  1076. addScaledVector: function ( v, s ) {
  1077. this.x += v.x * s;
  1078. this.y += v.y * s;
  1079. this.z += v.z * s;
  1080. return this;
  1081. },
  1082. sub: function ( v, w ) {
  1083. if ( w !== undefined ) {
  1084. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1085. return this.subVectors( v, w );
  1086. }
  1087. this.x -= v.x;
  1088. this.y -= v.y;
  1089. this.z -= v.z;
  1090. return this;
  1091. },
  1092. subScalar: function ( s ) {
  1093. this.x -= s;
  1094. this.y -= s;
  1095. this.z -= s;
  1096. return this;
  1097. },
  1098. subVectors: function ( a, b ) {
  1099. this.x = a.x - b.x;
  1100. this.y = a.y - b.y;
  1101. this.z = a.z - b.z;
  1102. return this;
  1103. },
  1104. multiply: function ( v, w ) {
  1105. if ( w !== undefined ) {
  1106. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1107. return this.multiplyVectors( v, w );
  1108. }
  1109. this.x *= v.x;
  1110. this.y *= v.y;
  1111. this.z *= v.z;
  1112. return this;
  1113. },
  1114. multiplyScalar: function ( scalar ) {
  1115. this.x *= scalar;
  1116. this.y *= scalar;
  1117. this.z *= scalar;
  1118. return this;
  1119. },
  1120. multiplyVectors: function ( a, b ) {
  1121. this.x = a.x * b.x;
  1122. this.y = a.y * b.y;
  1123. this.z = a.z * b.z;
  1124. return this;
  1125. },
  1126. applyEuler: function () {
  1127. var quaternion = new Quaternion();
  1128. return function applyEuler( euler ) {
  1129. if ( ! ( euler && euler.isEuler ) ) {
  1130. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1131. }
  1132. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1133. };
  1134. }(),
  1135. applyAxisAngle: function () {
  1136. var quaternion = new Quaternion();
  1137. return function applyAxisAngle( axis, angle ) {
  1138. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1139. };
  1140. }(),
  1141. applyMatrix3: function ( m ) {
  1142. var x = this.x, y = this.y, z = this.z;
  1143. var e = m.elements;
  1144. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1145. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1146. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1147. return this;
  1148. },
  1149. applyMatrix4: function ( m ) {
  1150. var x = this.x, y = this.y, z = this.z;
  1151. var e = m.elements;
  1152. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1153. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1154. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1155. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1156. return this;
  1157. },
  1158. applyQuaternion: function ( q ) {
  1159. var x = this.x, y = this.y, z = this.z;
  1160. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1161. // calculate quat * vector
  1162. var ix = qw * x + qy * z - qz * y;
  1163. var iy = qw * y + qz * x - qx * z;
  1164. var iz = qw * z + qx * y - qy * x;
  1165. var iw = - qx * x - qy * y - qz * z;
  1166. // calculate result * inverse quat
  1167. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1168. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1169. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1170. return this;
  1171. },
  1172. project: function ( camera ) {
  1173. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1174. },
  1175. unproject: function ( camera ) {
  1176. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1177. },
  1178. transformDirection: function ( m ) {
  1179. // input: THREE.Matrix4 affine matrix
  1180. // vector interpreted as a direction
  1181. var x = this.x, y = this.y, z = this.z;
  1182. var e = m.elements;
  1183. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1184. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1185. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1186. return this.normalize();
  1187. },
  1188. divide: function ( v ) {
  1189. this.x /= v.x;
  1190. this.y /= v.y;
  1191. this.z /= v.z;
  1192. return this;
  1193. },
  1194. divideScalar: function ( scalar ) {
  1195. return this.multiplyScalar( 1 / scalar );
  1196. },
  1197. min: function ( v ) {
  1198. this.x = Math.min( this.x, v.x );
  1199. this.y = Math.min( this.y, v.y );
  1200. this.z = Math.min( this.z, v.z );
  1201. return this;
  1202. },
  1203. max: function ( v ) {
  1204. this.x = Math.max( this.x, v.x );
  1205. this.y = Math.max( this.y, v.y );
  1206. this.z = Math.max( this.z, v.z );
  1207. return this;
  1208. },
  1209. clamp: function ( min, max ) {
  1210. // assumes min < max, componentwise
  1211. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1212. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1213. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1214. return this;
  1215. },
  1216. clampScalar: function ( minVal, maxVal ) {
  1217. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1218. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1219. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1220. return this;
  1221. },
  1222. clampLength: function ( min, max ) {
  1223. var length = this.length();
  1224. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1225. },
  1226. floor: function () {
  1227. this.x = Math.floor( this.x );
  1228. this.y = Math.floor( this.y );
  1229. this.z = Math.floor( this.z );
  1230. return this;
  1231. },
  1232. ceil: function () {
  1233. this.x = Math.ceil( this.x );
  1234. this.y = Math.ceil( this.y );
  1235. this.z = Math.ceil( this.z );
  1236. return this;
  1237. },
  1238. round: function () {
  1239. this.x = Math.round( this.x );
  1240. this.y = Math.round( this.y );
  1241. this.z = Math.round( this.z );
  1242. return this;
  1243. },
  1244. roundToZero: function () {
  1245. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1246. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1247. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1248. return this;
  1249. },
  1250. negate: function () {
  1251. this.x = - this.x;
  1252. this.y = - this.y;
  1253. this.z = - this.z;
  1254. return this;
  1255. },
  1256. dot: function ( v ) {
  1257. return this.x * v.x + this.y * v.y + this.z * v.z;
  1258. },
  1259. // TODO lengthSquared?
  1260. lengthSq: function () {
  1261. return this.x * this.x + this.y * this.y + this.z * this.z;
  1262. },
  1263. length: function () {
  1264. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1265. },
  1266. manhattanLength: function () {
  1267. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1268. },
  1269. normalize: function () {
  1270. return this.divideScalar( this.length() || 1 );
  1271. },
  1272. setLength: function ( length ) {
  1273. return this.normalize().multiplyScalar( length );
  1274. },
  1275. lerp: function ( v, alpha ) {
  1276. this.x += ( v.x - this.x ) * alpha;
  1277. this.y += ( v.y - this.y ) * alpha;
  1278. this.z += ( v.z - this.z ) * alpha;
  1279. return this;
  1280. },
  1281. lerpVectors: function ( v1, v2, alpha ) {
  1282. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1283. },
  1284. cross: function ( v, w ) {
  1285. if ( w !== undefined ) {
  1286. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1287. return this.crossVectors( v, w );
  1288. }
  1289. return this.crossVectors( this, v );
  1290. },
  1291. crossVectors: function ( a, b ) {
  1292. var ax = a.x, ay = a.y, az = a.z;
  1293. var bx = b.x, by = b.y, bz = b.z;
  1294. this.x = ay * bz - az * by;
  1295. this.y = az * bx - ax * bz;
  1296. this.z = ax * by - ay * bx;
  1297. return this;
  1298. },
  1299. projectOnVector: function ( vector ) {
  1300. var scalar = vector.dot( this ) / vector.lengthSq();
  1301. return this.copy( vector ).multiplyScalar( scalar );
  1302. },
  1303. projectOnPlane: function () {
  1304. var v1 = new Vector3();
  1305. return function projectOnPlane( planeNormal ) {
  1306. v1.copy( this ).projectOnVector( planeNormal );
  1307. return this.sub( v1 );
  1308. };
  1309. }(),
  1310. reflect: function () {
  1311. // reflect incident vector off plane orthogonal to normal
  1312. // normal is assumed to have unit length
  1313. var v1 = new Vector3();
  1314. return function reflect( normal ) {
  1315. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1316. };
  1317. }(),
  1318. angleTo: function ( v ) {
  1319. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1320. // clamp, to handle numerical problems
  1321. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1322. },
  1323. distanceTo: function ( v ) {
  1324. return Math.sqrt( this.distanceToSquared( v ) );
  1325. },
  1326. distanceToSquared: function ( v ) {
  1327. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1328. return dx * dx + dy * dy + dz * dz;
  1329. },
  1330. manhattanDistanceTo: function ( v ) {
  1331. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1332. },
  1333. setFromSpherical: function ( s ) {
  1334. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1335. },
  1336. setFromSphericalCoords: function ( radius, phi, theta ) {
  1337. var sinPhiRadius = Math.sin( phi ) * radius;
  1338. this.x = sinPhiRadius * Math.sin( theta );
  1339. this.y = Math.cos( phi ) * radius;
  1340. this.z = sinPhiRadius * Math.cos( theta );
  1341. return this;
  1342. },
  1343. setFromCylindrical: function ( c ) {
  1344. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1345. },
  1346. setFromCylindricalCoords: function ( radius, theta, y ) {
  1347. this.x = radius * Math.sin( theta );
  1348. this.y = y;
  1349. this.z = radius * Math.cos( theta );
  1350. return this;
  1351. },
  1352. setFromMatrixPosition: function ( m ) {
  1353. var e = m.elements;
  1354. this.x = e[ 12 ];
  1355. this.y = e[ 13 ];
  1356. this.z = e[ 14 ];
  1357. return this;
  1358. },
  1359. setFromMatrixScale: function ( m ) {
  1360. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1361. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1362. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1363. this.x = sx;
  1364. this.y = sy;
  1365. this.z = sz;
  1366. return this;
  1367. },
  1368. setFromMatrixColumn: function ( m, index ) {
  1369. return this.fromArray( m.elements, index * 4 );
  1370. },
  1371. equals: function ( v ) {
  1372. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1373. },
  1374. fromArray: function ( array, offset ) {
  1375. if ( offset === undefined ) offset = 0;
  1376. this.x = array[ offset ];
  1377. this.y = array[ offset + 1 ];
  1378. this.z = array[ offset + 2 ];
  1379. return this;
  1380. },
  1381. toArray: function ( array, offset ) {
  1382. if ( array === undefined ) array = [];
  1383. if ( offset === undefined ) offset = 0;
  1384. array[ offset ] = this.x;
  1385. array[ offset + 1 ] = this.y;
  1386. array[ offset + 2 ] = this.z;
  1387. return array;
  1388. },
  1389. fromBufferAttribute: function ( attribute, index, offset ) {
  1390. if ( offset !== undefined ) {
  1391. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1392. }
  1393. this.x = attribute.getX( index );
  1394. this.y = attribute.getY( index );
  1395. this.z = attribute.getZ( index );
  1396. return this;
  1397. }
  1398. } );
  1399. /**
  1400. * @author alteredq / http://alteredqualia.com/
  1401. * @author WestLangley / http://github.com/WestLangley
  1402. * @author bhouston / http://clara.io
  1403. * @author tschw
  1404. */
  1405. var _vector;
  1406. function Matrix3() {
  1407. this.elements = [
  1408. 1, 0, 0,
  1409. 0, 1, 0,
  1410. 0, 0, 1
  1411. ];
  1412. if ( arguments.length > 0 ) {
  1413. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1414. }
  1415. }
  1416. Object.assign( Matrix3.prototype, {
  1417. isMatrix3: true,
  1418. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1419. var te = this.elements;
  1420. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1421. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1422. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1423. return this;
  1424. },
  1425. identity: function () {
  1426. this.set(
  1427. 1, 0, 0,
  1428. 0, 1, 0,
  1429. 0, 0, 1
  1430. );
  1431. return this;
  1432. },
  1433. clone: function () {
  1434. return new this.constructor().fromArray( this.elements );
  1435. },
  1436. copy: function ( m ) {
  1437. var te = this.elements;
  1438. var me = m.elements;
  1439. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1440. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1441. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1442. return this;
  1443. },
  1444. setFromMatrix4: function ( m ) {
  1445. var me = m.elements;
  1446. this.set(
  1447. me[ 0 ], me[ 4 ], me[ 8 ],
  1448. me[ 1 ], me[ 5 ], me[ 9 ],
  1449. me[ 2 ], me[ 6 ], me[ 10 ]
  1450. );
  1451. return this;
  1452. },
  1453. applyToBufferAttribute: function ( attribute ) {
  1454. if ( _vector === undefined ) _vector = new Vector3();
  1455. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1456. _vector.x = attribute.getX( i );
  1457. _vector.y = attribute.getY( i );
  1458. _vector.z = attribute.getZ( i );
  1459. _vector.applyMatrix3( this );
  1460. attribute.setXYZ( i, _vector.x, _vector.y, _vector.z );
  1461. }
  1462. return attribute;
  1463. },
  1464. multiply: function ( m ) {
  1465. return this.multiplyMatrices( this, m );
  1466. },
  1467. premultiply: function ( m ) {
  1468. return this.multiplyMatrices( m, this );
  1469. },
  1470. multiplyMatrices: function ( a, b ) {
  1471. var ae = a.elements;
  1472. var be = b.elements;
  1473. var te = this.elements;
  1474. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1475. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1476. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1477. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1478. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1479. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1480. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1481. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1482. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1483. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1484. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1485. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1486. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1487. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1488. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1489. return this;
  1490. },
  1491. multiplyScalar: function ( s ) {
  1492. var te = this.elements;
  1493. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1494. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1495. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1496. return this;
  1497. },
  1498. determinant: function () {
  1499. var te = this.elements;
  1500. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1501. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1502. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1503. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1504. },
  1505. getInverse: function ( matrix, throwOnDegenerate ) {
  1506. if ( matrix && matrix.isMatrix4 ) {
  1507. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1508. }
  1509. var me = matrix.elements,
  1510. te = this.elements,
  1511. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1512. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1513. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1514. t11 = n33 * n22 - n32 * n23,
  1515. t12 = n32 * n13 - n33 * n12,
  1516. t13 = n23 * n12 - n22 * n13,
  1517. det = n11 * t11 + n21 * t12 + n31 * t13;
  1518. if ( det === 0 ) {
  1519. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1520. if ( throwOnDegenerate === true ) {
  1521. throw new Error( msg );
  1522. } else {
  1523. console.warn( msg );
  1524. }
  1525. return this.identity();
  1526. }
  1527. var detInv = 1 / det;
  1528. te[ 0 ] = t11 * detInv;
  1529. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1530. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1531. te[ 3 ] = t12 * detInv;
  1532. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1533. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1534. te[ 6 ] = t13 * detInv;
  1535. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1536. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1537. return this;
  1538. },
  1539. transpose: function () {
  1540. var tmp, m = this.elements;
  1541. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1542. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1543. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1544. return this;
  1545. },
  1546. getNormalMatrix: function ( matrix4 ) {
  1547. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1548. },
  1549. transposeIntoArray: function ( r ) {
  1550. var m = this.elements;
  1551. r[ 0 ] = m[ 0 ];
  1552. r[ 1 ] = m[ 3 ];
  1553. r[ 2 ] = m[ 6 ];
  1554. r[ 3 ] = m[ 1 ];
  1555. r[ 4 ] = m[ 4 ];
  1556. r[ 5 ] = m[ 7 ];
  1557. r[ 6 ] = m[ 2 ];
  1558. r[ 7 ] = m[ 5 ];
  1559. r[ 8 ] = m[ 8 ];
  1560. return this;
  1561. },
  1562. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1563. var c = Math.cos( rotation );
  1564. var s = Math.sin( rotation );
  1565. this.set(
  1566. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1567. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1568. 0, 0, 1
  1569. );
  1570. },
  1571. scale: function ( sx, sy ) {
  1572. var te = this.elements;
  1573. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1574. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1575. return this;
  1576. },
  1577. rotate: function ( theta ) {
  1578. var c = Math.cos( theta );
  1579. var s = Math.sin( theta );
  1580. var te = this.elements;
  1581. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1582. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1583. te[ 0 ] = c * a11 + s * a21;
  1584. te[ 3 ] = c * a12 + s * a22;
  1585. te[ 6 ] = c * a13 + s * a23;
  1586. te[ 1 ] = - s * a11 + c * a21;
  1587. te[ 4 ] = - s * a12 + c * a22;
  1588. te[ 7 ] = - s * a13 + c * a23;
  1589. return this;
  1590. },
  1591. translate: function ( tx, ty ) {
  1592. var te = this.elements;
  1593. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1594. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1595. return this;
  1596. },
  1597. equals: function ( matrix ) {
  1598. var te = this.elements;
  1599. var me = matrix.elements;
  1600. for ( var i = 0; i < 9; i ++ ) {
  1601. if ( te[ i ] !== me[ i ] ) return false;
  1602. }
  1603. return true;
  1604. },
  1605. fromArray: function ( array, offset ) {
  1606. if ( offset === undefined ) offset = 0;
  1607. for ( var i = 0; i < 9; i ++ ) {
  1608. this.elements[ i ] = array[ i + offset ];
  1609. }
  1610. return this;
  1611. },
  1612. toArray: function ( array, offset ) {
  1613. if ( array === undefined ) array = [];
  1614. if ( offset === undefined ) offset = 0;
  1615. var te = this.elements;
  1616. array[ offset ] = te[ 0 ];
  1617. array[ offset + 1 ] = te[ 1 ];
  1618. array[ offset + 2 ] = te[ 2 ];
  1619. array[ offset + 3 ] = te[ 3 ];
  1620. array[ offset + 4 ] = te[ 4 ];
  1621. array[ offset + 5 ] = te[ 5 ];
  1622. array[ offset + 6 ] = te[ 6 ];
  1623. array[ offset + 7 ] = te[ 7 ];
  1624. array[ offset + 8 ] = te[ 8 ];
  1625. return array;
  1626. }
  1627. } );
  1628. /**
  1629. * @author mrdoob / http://mrdoob.com/
  1630. * @author alteredq / http://alteredqualia.com/
  1631. * @author szimek / https://github.com/szimek/
  1632. */
  1633. var _canvas;
  1634. var ImageUtils = {
  1635. getDataURL: function ( image ) {
  1636. var canvas;
  1637. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1638. return image.src;
  1639. } else if ( image instanceof HTMLCanvasElement ) {
  1640. canvas = image;
  1641. } else {
  1642. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1643. _canvas.width = image.width;
  1644. _canvas.height = image.height;
  1645. var context = _canvas.getContext( '2d' );
  1646. if ( image instanceof ImageData ) {
  1647. context.putImageData( image, 0, 0 );
  1648. } else {
  1649. context.drawImage( image, 0, 0, image.width, image.height );
  1650. }
  1651. canvas = _canvas;
  1652. }
  1653. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1654. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1655. } else {
  1656. return canvas.toDataURL( 'image/png' );
  1657. }
  1658. }
  1659. };
  1660. /**
  1661. * @author mrdoob / http://mrdoob.com/
  1662. * @author alteredq / http://alteredqualia.com/
  1663. * @author szimek / https://github.com/szimek/
  1664. */
  1665. var textureId = 0;
  1666. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1667. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1668. this.uuid = _Math.generateUUID();
  1669. this.name = '';
  1670. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1671. this.mipmaps = [];
  1672. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1673. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1674. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1675. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1676. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1677. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1678. this.format = format !== undefined ? format : RGBAFormat;
  1679. this.type = type !== undefined ? type : UnsignedByteType;
  1680. this.offset = new Vector2( 0, 0 );
  1681. this.repeat = new Vector2( 1, 1 );
  1682. this.center = new Vector2( 0, 0 );
  1683. this.rotation = 0;
  1684. this.matrixAutoUpdate = true;
  1685. this.matrix = new Matrix3();
  1686. this.generateMipmaps = true;
  1687. this.premultiplyAlpha = false;
  1688. this.flipY = true;
  1689. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1690. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1691. //
  1692. // Also changing the encoding after already used by a Material will not automatically make the Material
  1693. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1694. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1695. this.version = 0;
  1696. this.onUpdate = null;
  1697. }
  1698. Texture.DEFAULT_IMAGE = undefined;
  1699. Texture.DEFAULT_MAPPING = UVMapping;
  1700. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1701. constructor: Texture,
  1702. isTexture: true,
  1703. updateMatrix: function () {
  1704. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1705. },
  1706. clone: function () {
  1707. return new this.constructor().copy( this );
  1708. },
  1709. copy: function ( source ) {
  1710. this.name = source.name;
  1711. this.image = source.image;
  1712. this.mipmaps = source.mipmaps.slice( 0 );
  1713. this.mapping = source.mapping;
  1714. this.wrapS = source.wrapS;
  1715. this.wrapT = source.wrapT;
  1716. this.magFilter = source.magFilter;
  1717. this.minFilter = source.minFilter;
  1718. this.anisotropy = source.anisotropy;
  1719. this.format = source.format;
  1720. this.type = source.type;
  1721. this.offset.copy( source.offset );
  1722. this.repeat.copy( source.repeat );
  1723. this.center.copy( source.center );
  1724. this.rotation = source.rotation;
  1725. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1726. this.matrix.copy( source.matrix );
  1727. this.generateMipmaps = source.generateMipmaps;
  1728. this.premultiplyAlpha = source.premultiplyAlpha;
  1729. this.flipY = source.flipY;
  1730. this.unpackAlignment = source.unpackAlignment;
  1731. this.encoding = source.encoding;
  1732. return this;
  1733. },
  1734. toJSON: function ( meta ) {
  1735. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1736. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1737. return meta.textures[ this.uuid ];
  1738. }
  1739. var output = {
  1740. metadata: {
  1741. version: 4.5,
  1742. type: 'Texture',
  1743. generator: 'Texture.toJSON'
  1744. },
  1745. uuid: this.uuid,
  1746. name: this.name,
  1747. mapping: this.mapping,
  1748. repeat: [ this.repeat.x, this.repeat.y ],
  1749. offset: [ this.offset.x, this.offset.y ],
  1750. center: [ this.center.x, this.center.y ],
  1751. rotation: this.rotation,
  1752. wrap: [ this.wrapS, this.wrapT ],
  1753. format: this.format,
  1754. type: this.type,
  1755. encoding: this.encoding,
  1756. minFilter: this.minFilter,
  1757. magFilter: this.magFilter,
  1758. anisotropy: this.anisotropy,
  1759. flipY: this.flipY,
  1760. premultiplyAlpha: this.premultiplyAlpha,
  1761. unpackAlignment: this.unpackAlignment
  1762. };
  1763. if ( this.image !== undefined ) {
  1764. // TODO: Move to THREE.Image
  1765. var image = this.image;
  1766. if ( image.uuid === undefined ) {
  1767. image.uuid = _Math.generateUUID(); // UGH
  1768. }
  1769. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1770. var url;
  1771. if ( Array.isArray( image ) ) {
  1772. // process array of images e.g. CubeTexture
  1773. url = [];
  1774. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1775. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1776. }
  1777. } else {
  1778. // process single image
  1779. url = ImageUtils.getDataURL( image );
  1780. }
  1781. meta.images[ image.uuid ] = {
  1782. uuid: image.uuid,
  1783. url: url
  1784. };
  1785. }
  1786. output.image = image.uuid;
  1787. }
  1788. if ( ! isRootObject ) {
  1789. meta.textures[ this.uuid ] = output;
  1790. }
  1791. return output;
  1792. },
  1793. dispose: function () {
  1794. this.dispatchEvent( { type: 'dispose' } );
  1795. },
  1796. transformUv: function ( uv ) {
  1797. if ( this.mapping !== UVMapping ) return uv;
  1798. uv.applyMatrix3( this.matrix );
  1799. if ( uv.x < 0 || uv.x > 1 ) {
  1800. switch ( this.wrapS ) {
  1801. case RepeatWrapping:
  1802. uv.x = uv.x - Math.floor( uv.x );
  1803. break;
  1804. case ClampToEdgeWrapping:
  1805. uv.x = uv.x < 0 ? 0 : 1;
  1806. break;
  1807. case MirroredRepeatWrapping:
  1808. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1809. uv.x = Math.ceil( uv.x ) - uv.x;
  1810. } else {
  1811. uv.x = uv.x - Math.floor( uv.x );
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. if ( uv.y < 0 || uv.y > 1 ) {
  1817. switch ( this.wrapT ) {
  1818. case RepeatWrapping:
  1819. uv.y = uv.y - Math.floor( uv.y );
  1820. break;
  1821. case ClampToEdgeWrapping:
  1822. uv.y = uv.y < 0 ? 0 : 1;
  1823. break;
  1824. case MirroredRepeatWrapping:
  1825. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1826. uv.y = Math.ceil( uv.y ) - uv.y;
  1827. } else {
  1828. uv.y = uv.y - Math.floor( uv.y );
  1829. }
  1830. break;
  1831. }
  1832. }
  1833. if ( this.flipY ) {
  1834. uv.y = 1 - uv.y;
  1835. }
  1836. return uv;
  1837. }
  1838. } );
  1839. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1840. set: function ( value ) {
  1841. if ( value === true ) this.version ++;
  1842. }
  1843. } );
  1844. /**
  1845. * @author supereggbert / http://www.paulbrunt.co.uk/
  1846. * @author philogb / http://blog.thejit.org/
  1847. * @author mikael emtinger / http://gomo.se/
  1848. * @author egraether / http://egraether.com/
  1849. * @author WestLangley / http://github.com/WestLangley
  1850. */
  1851. function Vector4( x, y, z, w ) {
  1852. this.x = x || 0;
  1853. this.y = y || 0;
  1854. this.z = z || 0;
  1855. this.w = ( w !== undefined ) ? w : 1;
  1856. }
  1857. Object.defineProperties( Vector4.prototype, {
  1858. "width": {
  1859. get: function () {
  1860. return this.z;
  1861. },
  1862. set: function ( value ) {
  1863. this.z = value;
  1864. }
  1865. },
  1866. "height": {
  1867. get: function () {
  1868. return this.w;
  1869. },
  1870. set: function ( value ) {
  1871. this.w = value;
  1872. }
  1873. }
  1874. } );
  1875. Object.assign( Vector4.prototype, {
  1876. isVector4: true,
  1877. set: function ( x, y, z, w ) {
  1878. this.x = x;
  1879. this.y = y;
  1880. this.z = z;
  1881. this.w = w;
  1882. return this;
  1883. },
  1884. setScalar: function ( scalar ) {
  1885. this.x = scalar;
  1886. this.y = scalar;
  1887. this.z = scalar;
  1888. this.w = scalar;
  1889. return this;
  1890. },
  1891. setX: function ( x ) {
  1892. this.x = x;
  1893. return this;
  1894. },
  1895. setY: function ( y ) {
  1896. this.y = y;
  1897. return this;
  1898. },
  1899. setZ: function ( z ) {
  1900. this.z = z;
  1901. return this;
  1902. },
  1903. setW: function ( w ) {
  1904. this.w = w;
  1905. return this;
  1906. },
  1907. setComponent: function ( index, value ) {
  1908. switch ( index ) {
  1909. case 0: this.x = value; break;
  1910. case 1: this.y = value; break;
  1911. case 2: this.z = value; break;
  1912. case 3: this.w = value; break;
  1913. default: throw new Error( 'index is out of range: ' + index );
  1914. }
  1915. return this;
  1916. },
  1917. getComponent: function ( index ) {
  1918. switch ( index ) {
  1919. case 0: return this.x;
  1920. case 1: return this.y;
  1921. case 2: return this.z;
  1922. case 3: return this.w;
  1923. default: throw new Error( 'index is out of range: ' + index );
  1924. }
  1925. },
  1926. clone: function () {
  1927. return new this.constructor( this.x, this.y, this.z, this.w );
  1928. },
  1929. copy: function ( v ) {
  1930. this.x = v.x;
  1931. this.y = v.y;
  1932. this.z = v.z;
  1933. this.w = ( v.w !== undefined ) ? v.w : 1;
  1934. return this;
  1935. },
  1936. add: function ( v, w ) {
  1937. if ( w !== undefined ) {
  1938. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1939. return this.addVectors( v, w );
  1940. }
  1941. this.x += v.x;
  1942. this.y += v.y;
  1943. this.z += v.z;
  1944. this.w += v.w;
  1945. return this;
  1946. },
  1947. addScalar: function ( s ) {
  1948. this.x += s;
  1949. this.y += s;
  1950. this.z += s;
  1951. this.w += s;
  1952. return this;
  1953. },
  1954. addVectors: function ( a, b ) {
  1955. this.x = a.x + b.x;
  1956. this.y = a.y + b.y;
  1957. this.z = a.z + b.z;
  1958. this.w = a.w + b.w;
  1959. return this;
  1960. },
  1961. addScaledVector: function ( v, s ) {
  1962. this.x += v.x * s;
  1963. this.y += v.y * s;
  1964. this.z += v.z * s;
  1965. this.w += v.w * s;
  1966. return this;
  1967. },
  1968. sub: function ( v, w ) {
  1969. if ( w !== undefined ) {
  1970. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1971. return this.subVectors( v, w );
  1972. }
  1973. this.x -= v.x;
  1974. this.y -= v.y;
  1975. this.z -= v.z;
  1976. this.w -= v.w;
  1977. return this;
  1978. },
  1979. subScalar: function ( s ) {
  1980. this.x -= s;
  1981. this.y -= s;
  1982. this.z -= s;
  1983. this.w -= s;
  1984. return this;
  1985. },
  1986. subVectors: function ( a, b ) {
  1987. this.x = a.x - b.x;
  1988. this.y = a.y - b.y;
  1989. this.z = a.z - b.z;
  1990. this.w = a.w - b.w;
  1991. return this;
  1992. },
  1993. multiplyScalar: function ( scalar ) {
  1994. this.x *= scalar;
  1995. this.y *= scalar;
  1996. this.z *= scalar;
  1997. this.w *= scalar;
  1998. return this;
  1999. },
  2000. applyMatrix4: function ( m ) {
  2001. var x = this.x, y = this.y, z = this.z, w = this.w;
  2002. var e = m.elements;
  2003. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2004. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2005. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2006. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2007. return this;
  2008. },
  2009. divideScalar: function ( scalar ) {
  2010. return this.multiplyScalar( 1 / scalar );
  2011. },
  2012. setAxisAngleFromQuaternion: function ( q ) {
  2013. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2014. // q is assumed to be normalized
  2015. this.w = 2 * Math.acos( q.w );
  2016. var s = Math.sqrt( 1 - q.w * q.w );
  2017. if ( s < 0.0001 ) {
  2018. this.x = 1;
  2019. this.y = 0;
  2020. this.z = 0;
  2021. } else {
  2022. this.x = q.x / s;
  2023. this.y = q.y / s;
  2024. this.z = q.z / s;
  2025. }
  2026. return this;
  2027. },
  2028. setAxisAngleFromRotationMatrix: function ( m ) {
  2029. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2030. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2031. var angle, x, y, z, // variables for result
  2032. epsilon = 0.01, // margin to allow for rounding errors
  2033. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2034. te = m.elements,
  2035. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2036. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2037. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2038. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2039. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2040. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2041. // singularity found
  2042. // first check for identity matrix which must have +1 for all terms
  2043. // in leading diagonal and zero in other terms
  2044. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2045. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2046. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2047. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2048. // this singularity is identity matrix so angle = 0
  2049. this.set( 1, 0, 0, 0 );
  2050. return this; // zero angle, arbitrary axis
  2051. }
  2052. // otherwise this singularity is angle = 180
  2053. angle = Math.PI;
  2054. var xx = ( m11 + 1 ) / 2;
  2055. var yy = ( m22 + 1 ) / 2;
  2056. var zz = ( m33 + 1 ) / 2;
  2057. var xy = ( m12 + m21 ) / 4;
  2058. var xz = ( m13 + m31 ) / 4;
  2059. var yz = ( m23 + m32 ) / 4;
  2060. if ( ( xx > yy ) && ( xx > zz ) ) {
  2061. // m11 is the largest diagonal term
  2062. if ( xx < epsilon ) {
  2063. x = 0;
  2064. y = 0.707106781;
  2065. z = 0.707106781;
  2066. } else {
  2067. x = Math.sqrt( xx );
  2068. y = xy / x;
  2069. z = xz / x;
  2070. }
  2071. } else if ( yy > zz ) {
  2072. // m22 is the largest diagonal term
  2073. if ( yy < epsilon ) {
  2074. x = 0.707106781;
  2075. y = 0;
  2076. z = 0.707106781;
  2077. } else {
  2078. y = Math.sqrt( yy );
  2079. x = xy / y;
  2080. z = yz / y;
  2081. }
  2082. } else {
  2083. // m33 is the largest diagonal term so base result on this
  2084. if ( zz < epsilon ) {
  2085. x = 0.707106781;
  2086. y = 0.707106781;
  2087. z = 0;
  2088. } else {
  2089. z = Math.sqrt( zz );
  2090. x = xz / z;
  2091. y = yz / z;
  2092. }
  2093. }
  2094. this.set( x, y, z, angle );
  2095. return this; // return 180 deg rotation
  2096. }
  2097. // as we have reached here there are no singularities so we can handle normally
  2098. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2099. ( m13 - m31 ) * ( m13 - m31 ) +
  2100. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2101. if ( Math.abs( s ) < 0.001 ) s = 1;
  2102. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2103. // caught by singularity test above, but I've left it in just in case
  2104. this.x = ( m32 - m23 ) / s;
  2105. this.y = ( m13 - m31 ) / s;
  2106. this.z = ( m21 - m12 ) / s;
  2107. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2108. return this;
  2109. },
  2110. min: function ( v ) {
  2111. this.x = Math.min( this.x, v.x );
  2112. this.y = Math.min( this.y, v.y );
  2113. this.z = Math.min( this.z, v.z );
  2114. this.w = Math.min( this.w, v.w );
  2115. return this;
  2116. },
  2117. max: function ( v ) {
  2118. this.x = Math.max( this.x, v.x );
  2119. this.y = Math.max( this.y, v.y );
  2120. this.z = Math.max( this.z, v.z );
  2121. this.w = Math.max( this.w, v.w );
  2122. return this;
  2123. },
  2124. clamp: function ( min, max ) {
  2125. // assumes min < max, componentwise
  2126. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2127. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2128. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2129. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2130. return this;
  2131. },
  2132. clampScalar: function ( minVal, maxVal ) {
  2133. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2134. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2135. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2136. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  2137. return this;
  2138. },
  2139. clampLength: function ( min, max ) {
  2140. var length = this.length();
  2141. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2142. },
  2143. floor: function () {
  2144. this.x = Math.floor( this.x );
  2145. this.y = Math.floor( this.y );
  2146. this.z = Math.floor( this.z );
  2147. this.w = Math.floor( this.w );
  2148. return this;
  2149. },
  2150. ceil: function () {
  2151. this.x = Math.ceil( this.x );
  2152. this.y = Math.ceil( this.y );
  2153. this.z = Math.ceil( this.z );
  2154. this.w = Math.ceil( this.w );
  2155. return this;
  2156. },
  2157. round: function () {
  2158. this.x = Math.round( this.x );
  2159. this.y = Math.round( this.y );
  2160. this.z = Math.round( this.z );
  2161. this.w = Math.round( this.w );
  2162. return this;
  2163. },
  2164. roundToZero: function () {
  2165. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2166. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2167. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2168. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2169. return this;
  2170. },
  2171. negate: function () {
  2172. this.x = - this.x;
  2173. this.y = - this.y;
  2174. this.z = - this.z;
  2175. this.w = - this.w;
  2176. return this;
  2177. },
  2178. dot: function ( v ) {
  2179. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2180. },
  2181. lengthSq: function () {
  2182. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2183. },
  2184. length: function () {
  2185. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2186. },
  2187. manhattanLength: function () {
  2188. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2189. },
  2190. normalize: function () {
  2191. return this.divideScalar( this.length() || 1 );
  2192. },
  2193. setLength: function ( length ) {
  2194. return this.normalize().multiplyScalar( length );
  2195. },
  2196. lerp: function ( v, alpha ) {
  2197. this.x += ( v.x - this.x ) * alpha;
  2198. this.y += ( v.y - this.y ) * alpha;
  2199. this.z += ( v.z - this.z ) * alpha;
  2200. this.w += ( v.w - this.w ) * alpha;
  2201. return this;
  2202. },
  2203. lerpVectors: function ( v1, v2, alpha ) {
  2204. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2205. },
  2206. equals: function ( v ) {
  2207. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2208. },
  2209. fromArray: function ( array, offset ) {
  2210. if ( offset === undefined ) offset = 0;
  2211. this.x = array[ offset ];
  2212. this.y = array[ offset + 1 ];
  2213. this.z = array[ offset + 2 ];
  2214. this.w = array[ offset + 3 ];
  2215. return this;
  2216. },
  2217. toArray: function ( array, offset ) {
  2218. if ( array === undefined ) array = [];
  2219. if ( offset === undefined ) offset = 0;
  2220. array[ offset ] = this.x;
  2221. array[ offset + 1 ] = this.y;
  2222. array[ offset + 2 ] = this.z;
  2223. array[ offset + 3 ] = this.w;
  2224. return array;
  2225. },
  2226. fromBufferAttribute: function ( attribute, index, offset ) {
  2227. if ( offset !== undefined ) {
  2228. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2229. }
  2230. this.x = attribute.getX( index );
  2231. this.y = attribute.getY( index );
  2232. this.z = attribute.getZ( index );
  2233. this.w = attribute.getW( index );
  2234. return this;
  2235. }
  2236. } );
  2237. /**
  2238. * @author szimek / https://github.com/szimek/
  2239. * @author alteredq / http://alteredqualia.com/
  2240. * @author Marius Kintel / https://github.com/kintel
  2241. */
  2242. /*
  2243. In options, we can specify:
  2244. * Texture parameters for an auto-generated target texture
  2245. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2246. */
  2247. function WebGLRenderTarget( width, height, options ) {
  2248. this.width = width;
  2249. this.height = height;
  2250. this.scissor = new Vector4( 0, 0, width, height );
  2251. this.scissorTest = false;
  2252. this.viewport = new Vector4( 0, 0, width, height );
  2253. options = options || {};
  2254. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2255. this.texture.image = {};
  2256. this.texture.image.width = width;
  2257. this.texture.image.height = height;
  2258. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2259. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2260. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2261. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2262. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2263. }
  2264. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2265. constructor: WebGLRenderTarget,
  2266. isWebGLRenderTarget: true,
  2267. setSize: function ( width, height ) {
  2268. if ( this.width !== width || this.height !== height ) {
  2269. this.width = width;
  2270. this.height = height;
  2271. this.texture.image.width = width;
  2272. this.texture.image.height = height;
  2273. this.dispose();
  2274. }
  2275. this.viewport.set( 0, 0, width, height );
  2276. this.scissor.set( 0, 0, width, height );
  2277. },
  2278. clone: function () {
  2279. return new this.constructor().copy( this );
  2280. },
  2281. copy: function ( source ) {
  2282. this.width = source.width;
  2283. this.height = source.height;
  2284. this.viewport.copy( source.viewport );
  2285. this.texture = source.texture.clone();
  2286. this.depthBuffer = source.depthBuffer;
  2287. this.stencilBuffer = source.stencilBuffer;
  2288. this.depthTexture = source.depthTexture;
  2289. return this;
  2290. },
  2291. dispose: function () {
  2292. this.dispatchEvent( { type: 'dispose' } );
  2293. }
  2294. } );
  2295. /**
  2296. * @author Mugen87 / https://github.com/Mugen87
  2297. * @author Matt DesLauriers / @mattdesl
  2298. */
  2299. function WebGLMultisampleRenderTarget( width, height, options ) {
  2300. WebGLRenderTarget.call( this, width, height, options );
  2301. this.samples = 4;
  2302. }
  2303. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2304. constructor: WebGLMultisampleRenderTarget,
  2305. isWebGLMultisampleRenderTarget: true,
  2306. copy: function ( source ) {
  2307. WebGLRenderTarget.prototype.copy.call( this, source );
  2308. this.samples = source.samples;
  2309. return this;
  2310. }
  2311. } );
  2312. /**
  2313. * @author mrdoob / http://mrdoob.com/
  2314. * @author supereggbert / http://www.paulbrunt.co.uk/
  2315. * @author philogb / http://blog.thejit.org/
  2316. * @author jordi_ros / http://plattsoft.com
  2317. * @author D1plo1d / http://github.com/D1plo1d
  2318. * @author alteredq / http://alteredqualia.com/
  2319. * @author mikael emtinger / http://gomo.se/
  2320. * @author timknip / http://www.floorplanner.com/
  2321. * @author bhouston / http://clara.io
  2322. * @author WestLangley / http://github.com/WestLangley
  2323. */
  2324. function Matrix4() {
  2325. this.elements = [
  2326. 1, 0, 0, 0,
  2327. 0, 1, 0, 0,
  2328. 0, 0, 1, 0,
  2329. 0, 0, 0, 1
  2330. ];
  2331. if ( arguments.length > 0 ) {
  2332. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2333. }
  2334. }
  2335. Object.assign( Matrix4.prototype, {
  2336. isMatrix4: true,
  2337. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2338. var te = this.elements;
  2339. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2340. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2341. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2342. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2343. return this;
  2344. },
  2345. identity: function () {
  2346. this.set(
  2347. 1, 0, 0, 0,
  2348. 0, 1, 0, 0,
  2349. 0, 0, 1, 0,
  2350. 0, 0, 0, 1
  2351. );
  2352. return this;
  2353. },
  2354. clone: function () {
  2355. return new Matrix4().fromArray( this.elements );
  2356. },
  2357. copy: function ( m ) {
  2358. var te = this.elements;
  2359. var me = m.elements;
  2360. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2361. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2362. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2363. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2364. return this;
  2365. },
  2366. copyPosition: function ( m ) {
  2367. var te = this.elements, me = m.elements;
  2368. te[ 12 ] = me[ 12 ];
  2369. te[ 13 ] = me[ 13 ];
  2370. te[ 14 ] = me[ 14 ];
  2371. return this;
  2372. },
  2373. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2374. xAxis.setFromMatrixColumn( this, 0 );
  2375. yAxis.setFromMatrixColumn( this, 1 );
  2376. zAxis.setFromMatrixColumn( this, 2 );
  2377. return this;
  2378. },
  2379. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2380. this.set(
  2381. xAxis.x, yAxis.x, zAxis.x, 0,
  2382. xAxis.y, yAxis.y, zAxis.y, 0,
  2383. xAxis.z, yAxis.z, zAxis.z, 0,
  2384. 0, 0, 0, 1
  2385. );
  2386. return this;
  2387. },
  2388. extractRotation: function () {
  2389. var v1 = new Vector3();
  2390. return function extractRotation( m ) {
  2391. // this method does not support reflection matrices
  2392. var te = this.elements;
  2393. var me = m.elements;
  2394. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2395. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2396. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2397. te[ 0 ] = me[ 0 ] * scaleX;
  2398. te[ 1 ] = me[ 1 ] * scaleX;
  2399. te[ 2 ] = me[ 2 ] * scaleX;
  2400. te[ 3 ] = 0;
  2401. te[ 4 ] = me[ 4 ] * scaleY;
  2402. te[ 5 ] = me[ 5 ] * scaleY;
  2403. te[ 6 ] = me[ 6 ] * scaleY;
  2404. te[ 7 ] = 0;
  2405. te[ 8 ] = me[ 8 ] * scaleZ;
  2406. te[ 9 ] = me[ 9 ] * scaleZ;
  2407. te[ 10 ] = me[ 10 ] * scaleZ;
  2408. te[ 11 ] = 0;
  2409. te[ 12 ] = 0;
  2410. te[ 13 ] = 0;
  2411. te[ 14 ] = 0;
  2412. te[ 15 ] = 1;
  2413. return this;
  2414. };
  2415. }(),
  2416. makeRotationFromEuler: function ( euler ) {
  2417. if ( ! ( euler && euler.isEuler ) ) {
  2418. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2419. }
  2420. var te = this.elements;
  2421. var x = euler.x, y = euler.y, z = euler.z;
  2422. var a = Math.cos( x ), b = Math.sin( x );
  2423. var c = Math.cos( y ), d = Math.sin( y );
  2424. var e = Math.cos( z ), f = Math.sin( z );
  2425. if ( euler.order === 'XYZ' ) {
  2426. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2427. te[ 0 ] = c * e;
  2428. te[ 4 ] = - c * f;
  2429. te[ 8 ] = d;
  2430. te[ 1 ] = af + be * d;
  2431. te[ 5 ] = ae - bf * d;
  2432. te[ 9 ] = - b * c;
  2433. te[ 2 ] = bf - ae * d;
  2434. te[ 6 ] = be + af * d;
  2435. te[ 10 ] = a * c;
  2436. } else if ( euler.order === 'YXZ' ) {
  2437. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2438. te[ 0 ] = ce + df * b;
  2439. te[ 4 ] = de * b - cf;
  2440. te[ 8 ] = a * d;
  2441. te[ 1 ] = a * f;
  2442. te[ 5 ] = a * e;
  2443. te[ 9 ] = - b;
  2444. te[ 2 ] = cf * b - de;
  2445. te[ 6 ] = df + ce * b;
  2446. te[ 10 ] = a * c;
  2447. } else if ( euler.order === 'ZXY' ) {
  2448. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2449. te[ 0 ] = ce - df * b;
  2450. te[ 4 ] = - a * f;
  2451. te[ 8 ] = de + cf * b;
  2452. te[ 1 ] = cf + de * b;
  2453. te[ 5 ] = a * e;
  2454. te[ 9 ] = df - ce * b;
  2455. te[ 2 ] = - a * d;
  2456. te[ 6 ] = b;
  2457. te[ 10 ] = a * c;
  2458. } else if ( euler.order === 'ZYX' ) {
  2459. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2460. te[ 0 ] = c * e;
  2461. te[ 4 ] = be * d - af;
  2462. te[ 8 ] = ae * d + bf;
  2463. te[ 1 ] = c * f;
  2464. te[ 5 ] = bf * d + ae;
  2465. te[ 9 ] = af * d - be;
  2466. te[ 2 ] = - d;
  2467. te[ 6 ] = b * c;
  2468. te[ 10 ] = a * c;
  2469. } else if ( euler.order === 'YZX' ) {
  2470. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2471. te[ 0 ] = c * e;
  2472. te[ 4 ] = bd - ac * f;
  2473. te[ 8 ] = bc * f + ad;
  2474. te[ 1 ] = f;
  2475. te[ 5 ] = a * e;
  2476. te[ 9 ] = - b * e;
  2477. te[ 2 ] = - d * e;
  2478. te[ 6 ] = ad * f + bc;
  2479. te[ 10 ] = ac - bd * f;
  2480. } else if ( euler.order === 'XZY' ) {
  2481. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2482. te[ 0 ] = c * e;
  2483. te[ 4 ] = - f;
  2484. te[ 8 ] = d * e;
  2485. te[ 1 ] = ac * f + bd;
  2486. te[ 5 ] = a * e;
  2487. te[ 9 ] = ad * f - bc;
  2488. te[ 2 ] = bc * f - ad;
  2489. te[ 6 ] = b * e;
  2490. te[ 10 ] = bd * f + ac;
  2491. }
  2492. // bottom row
  2493. te[ 3 ] = 0;
  2494. te[ 7 ] = 0;
  2495. te[ 11 ] = 0;
  2496. // last column
  2497. te[ 12 ] = 0;
  2498. te[ 13 ] = 0;
  2499. te[ 14 ] = 0;
  2500. te[ 15 ] = 1;
  2501. return this;
  2502. },
  2503. makeRotationFromQuaternion: function () {
  2504. var zero = new Vector3( 0, 0, 0 );
  2505. var one = new Vector3( 1, 1, 1 );
  2506. return function makeRotationFromQuaternion( q ) {
  2507. return this.compose( zero, q, one );
  2508. };
  2509. }(),
  2510. lookAt: function () {
  2511. var x = new Vector3();
  2512. var y = new Vector3();
  2513. var z = new Vector3();
  2514. return function lookAt( eye, target, up ) {
  2515. var te = this.elements;
  2516. z.subVectors( eye, target );
  2517. if ( z.lengthSq() === 0 ) {
  2518. // eye and target are in the same position
  2519. z.z = 1;
  2520. }
  2521. z.normalize();
  2522. x.crossVectors( up, z );
  2523. if ( x.lengthSq() === 0 ) {
  2524. // up and z are parallel
  2525. if ( Math.abs( up.z ) === 1 ) {
  2526. z.x += 0.0001;
  2527. } else {
  2528. z.z += 0.0001;
  2529. }
  2530. z.normalize();
  2531. x.crossVectors( up, z );
  2532. }
  2533. x.normalize();
  2534. y.crossVectors( z, x );
  2535. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2536. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2537. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2538. return this;
  2539. };
  2540. }(),
  2541. multiply: function ( m, n ) {
  2542. if ( n !== undefined ) {
  2543. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2544. return this.multiplyMatrices( m, n );
  2545. }
  2546. return this.multiplyMatrices( this, m );
  2547. },
  2548. premultiply: function ( m ) {
  2549. return this.multiplyMatrices( m, this );
  2550. },
  2551. multiplyMatrices: function ( a, b ) {
  2552. var ae = a.elements;
  2553. var be = b.elements;
  2554. var te = this.elements;
  2555. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2556. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2557. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2558. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2559. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2560. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2561. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2562. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2563. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2564. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2565. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2566. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2567. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2568. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2569. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2570. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2571. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2572. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2573. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2574. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2575. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2576. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2577. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2578. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2579. return this;
  2580. },
  2581. multiplyScalar: function ( s ) {
  2582. var te = this.elements;
  2583. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2584. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2585. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2586. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2587. return this;
  2588. },
  2589. applyToBufferAttribute: function () {
  2590. var v1 = new Vector3();
  2591. return function applyToBufferAttribute( attribute ) {
  2592. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2593. v1.x = attribute.getX( i );
  2594. v1.y = attribute.getY( i );
  2595. v1.z = attribute.getZ( i );
  2596. v1.applyMatrix4( this );
  2597. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2598. }
  2599. return attribute;
  2600. };
  2601. }(),
  2602. determinant: function () {
  2603. var te = this.elements;
  2604. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2605. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2606. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2607. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2608. //TODO: make this more efficient
  2609. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2610. return (
  2611. n41 * (
  2612. + n14 * n23 * n32
  2613. - n13 * n24 * n32
  2614. - n14 * n22 * n33
  2615. + n12 * n24 * n33
  2616. + n13 * n22 * n34
  2617. - n12 * n23 * n34
  2618. ) +
  2619. n42 * (
  2620. + n11 * n23 * n34
  2621. - n11 * n24 * n33
  2622. + n14 * n21 * n33
  2623. - n13 * n21 * n34
  2624. + n13 * n24 * n31
  2625. - n14 * n23 * n31
  2626. ) +
  2627. n43 * (
  2628. + n11 * n24 * n32
  2629. - n11 * n22 * n34
  2630. - n14 * n21 * n32
  2631. + n12 * n21 * n34
  2632. + n14 * n22 * n31
  2633. - n12 * n24 * n31
  2634. ) +
  2635. n44 * (
  2636. - n13 * n22 * n31
  2637. - n11 * n23 * n32
  2638. + n11 * n22 * n33
  2639. + n13 * n21 * n32
  2640. - n12 * n21 * n33
  2641. + n12 * n23 * n31
  2642. )
  2643. );
  2644. },
  2645. transpose: function () {
  2646. var te = this.elements;
  2647. var tmp;
  2648. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2649. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2650. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2651. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2652. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2653. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2654. return this;
  2655. },
  2656. setPosition: function ( x, y, z ) {
  2657. var te = this.elements;
  2658. if ( x.isVector3 ) {
  2659. te[ 12 ] = x.x;
  2660. te[ 13 ] = x.y;
  2661. te[ 14 ] = x.z;
  2662. } else {
  2663. te[ 12 ] = x;
  2664. te[ 13 ] = y;
  2665. te[ 14 ] = z;
  2666. }
  2667. return this;
  2668. },
  2669. getInverse: function ( m, throwOnDegenerate ) {
  2670. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2671. var te = this.elements,
  2672. me = m.elements,
  2673. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2674. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2675. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2676. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2677. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2678. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2679. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2680. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2681. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2682. if ( det === 0 ) {
  2683. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  2684. if ( throwOnDegenerate === true ) {
  2685. throw new Error( msg );
  2686. } else {
  2687. console.warn( msg );
  2688. }
  2689. return this.identity();
  2690. }
  2691. var detInv = 1 / det;
  2692. te[ 0 ] = t11 * detInv;
  2693. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2694. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2695. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2696. te[ 4 ] = t12 * detInv;
  2697. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2698. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2699. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2700. te[ 8 ] = t13 * detInv;
  2701. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2702. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2703. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2704. te[ 12 ] = t14 * detInv;
  2705. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2706. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2707. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2708. return this;
  2709. },
  2710. scale: function ( v ) {
  2711. var te = this.elements;
  2712. var x = v.x, y = v.y, z = v.z;
  2713. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2714. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2715. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2716. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2717. return this;
  2718. },
  2719. getMaxScaleOnAxis: function () {
  2720. var te = this.elements;
  2721. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2722. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2723. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2724. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2725. },
  2726. makeTranslation: function ( x, y, z ) {
  2727. this.set(
  2728. 1, 0, 0, x,
  2729. 0, 1, 0, y,
  2730. 0, 0, 1, z,
  2731. 0, 0, 0, 1
  2732. );
  2733. return this;
  2734. },
  2735. makeRotationX: function ( theta ) {
  2736. var c = Math.cos( theta ), s = Math.sin( theta );
  2737. this.set(
  2738. 1, 0, 0, 0,
  2739. 0, c, - s, 0,
  2740. 0, s, c, 0,
  2741. 0, 0, 0, 1
  2742. );
  2743. return this;
  2744. },
  2745. makeRotationY: function ( theta ) {
  2746. var c = Math.cos( theta ), s = Math.sin( theta );
  2747. this.set(
  2748. c, 0, s, 0,
  2749. 0, 1, 0, 0,
  2750. - s, 0, c, 0,
  2751. 0, 0, 0, 1
  2752. );
  2753. return this;
  2754. },
  2755. makeRotationZ: function ( theta ) {
  2756. var c = Math.cos( theta ), s = Math.sin( theta );
  2757. this.set(
  2758. c, - s, 0, 0,
  2759. s, c, 0, 0,
  2760. 0, 0, 1, 0,
  2761. 0, 0, 0, 1
  2762. );
  2763. return this;
  2764. },
  2765. makeRotationAxis: function ( axis, angle ) {
  2766. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2767. var c = Math.cos( angle );
  2768. var s = Math.sin( angle );
  2769. var t = 1 - c;
  2770. var x = axis.x, y = axis.y, z = axis.z;
  2771. var tx = t * x, ty = t * y;
  2772. this.set(
  2773. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2774. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2775. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2776. 0, 0, 0, 1
  2777. );
  2778. return this;
  2779. },
  2780. makeScale: function ( x, y, z ) {
  2781. this.set(
  2782. x, 0, 0, 0,
  2783. 0, y, 0, 0,
  2784. 0, 0, z, 0,
  2785. 0, 0, 0, 1
  2786. );
  2787. return this;
  2788. },
  2789. makeShear: function ( x, y, z ) {
  2790. this.set(
  2791. 1, y, z, 0,
  2792. x, 1, z, 0,
  2793. x, y, 1, 0,
  2794. 0, 0, 0, 1
  2795. );
  2796. return this;
  2797. },
  2798. compose: function ( position, quaternion, scale ) {
  2799. var te = this.elements;
  2800. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2801. var x2 = x + x, y2 = y + y, z2 = z + z;
  2802. var xx = x * x2, xy = x * y2, xz = x * z2;
  2803. var yy = y * y2, yz = y * z2, zz = z * z2;
  2804. var wx = w * x2, wy = w * y2, wz = w * z2;
  2805. var sx = scale.x, sy = scale.y, sz = scale.z;
  2806. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2807. te[ 1 ] = ( xy + wz ) * sx;
  2808. te[ 2 ] = ( xz - wy ) * sx;
  2809. te[ 3 ] = 0;
  2810. te[ 4 ] = ( xy - wz ) * sy;
  2811. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2812. te[ 6 ] = ( yz + wx ) * sy;
  2813. te[ 7 ] = 0;
  2814. te[ 8 ] = ( xz + wy ) * sz;
  2815. te[ 9 ] = ( yz - wx ) * sz;
  2816. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2817. te[ 11 ] = 0;
  2818. te[ 12 ] = position.x;
  2819. te[ 13 ] = position.y;
  2820. te[ 14 ] = position.z;
  2821. te[ 15 ] = 1;
  2822. return this;
  2823. },
  2824. decompose: function () {
  2825. var vector = new Vector3();
  2826. var matrix = new Matrix4();
  2827. return function decompose( position, quaternion, scale ) {
  2828. var te = this.elements;
  2829. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2830. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2831. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2832. // if determine is negative, we need to invert one scale
  2833. var det = this.determinant();
  2834. if ( det < 0 ) sx = - sx;
  2835. position.x = te[ 12 ];
  2836. position.y = te[ 13 ];
  2837. position.z = te[ 14 ];
  2838. // scale the rotation part
  2839. matrix.copy( this );
  2840. var invSX = 1 / sx;
  2841. var invSY = 1 / sy;
  2842. var invSZ = 1 / sz;
  2843. matrix.elements[ 0 ] *= invSX;
  2844. matrix.elements[ 1 ] *= invSX;
  2845. matrix.elements[ 2 ] *= invSX;
  2846. matrix.elements[ 4 ] *= invSY;
  2847. matrix.elements[ 5 ] *= invSY;
  2848. matrix.elements[ 6 ] *= invSY;
  2849. matrix.elements[ 8 ] *= invSZ;
  2850. matrix.elements[ 9 ] *= invSZ;
  2851. matrix.elements[ 10 ] *= invSZ;
  2852. quaternion.setFromRotationMatrix( matrix );
  2853. scale.x = sx;
  2854. scale.y = sy;
  2855. scale.z = sz;
  2856. return this;
  2857. };
  2858. }(),
  2859. makePerspective: function ( left, right, top, bottom, near, far ) {
  2860. if ( far === undefined ) {
  2861. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2862. }
  2863. var te = this.elements;
  2864. var x = 2 * near / ( right - left );
  2865. var y = 2 * near / ( top - bottom );
  2866. var a = ( right + left ) / ( right - left );
  2867. var b = ( top + bottom ) / ( top - bottom );
  2868. var c = - ( far + near ) / ( far - near );
  2869. var d = - 2 * far * near / ( far - near );
  2870. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2871. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2872. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2873. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2874. return this;
  2875. },
  2876. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2877. var te = this.elements;
  2878. var w = 1.0 / ( right - left );
  2879. var h = 1.0 / ( top - bottom );
  2880. var p = 1.0 / ( far - near );
  2881. var x = ( right + left ) * w;
  2882. var y = ( top + bottom ) * h;
  2883. var z = ( far + near ) * p;
  2884. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2885. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2886. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2887. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2888. return this;
  2889. },
  2890. equals: function ( matrix ) {
  2891. var te = this.elements;
  2892. var me = matrix.elements;
  2893. for ( var i = 0; i < 16; i ++ ) {
  2894. if ( te[ i ] !== me[ i ] ) return false;
  2895. }
  2896. return true;
  2897. },
  2898. fromArray: function ( array, offset ) {
  2899. if ( offset === undefined ) offset = 0;
  2900. for ( var i = 0; i < 16; i ++ ) {
  2901. this.elements[ i ] = array[ i + offset ];
  2902. }
  2903. return this;
  2904. },
  2905. toArray: function ( array, offset ) {
  2906. if ( array === undefined ) array = [];
  2907. if ( offset === undefined ) offset = 0;
  2908. var te = this.elements;
  2909. array[ offset ] = te[ 0 ];
  2910. array[ offset + 1 ] = te[ 1 ];
  2911. array[ offset + 2 ] = te[ 2 ];
  2912. array[ offset + 3 ] = te[ 3 ];
  2913. array[ offset + 4 ] = te[ 4 ];
  2914. array[ offset + 5 ] = te[ 5 ];
  2915. array[ offset + 6 ] = te[ 6 ];
  2916. array[ offset + 7 ] = te[ 7 ];
  2917. array[ offset + 8 ] = te[ 8 ];
  2918. array[ offset + 9 ] = te[ 9 ];
  2919. array[ offset + 10 ] = te[ 10 ];
  2920. array[ offset + 11 ] = te[ 11 ];
  2921. array[ offset + 12 ] = te[ 12 ];
  2922. array[ offset + 13 ] = te[ 13 ];
  2923. array[ offset + 14 ] = te[ 14 ];
  2924. array[ offset + 15 ] = te[ 15 ];
  2925. return array;
  2926. }
  2927. } );
  2928. /**
  2929. * @author mrdoob / http://mrdoob.com/
  2930. * @author WestLangley / http://github.com/WestLangley
  2931. * @author bhouston / http://clara.io
  2932. */
  2933. var _matrix, _quaternion;
  2934. function Euler( x, y, z, order ) {
  2935. this._x = x || 0;
  2936. this._y = y || 0;
  2937. this._z = z || 0;
  2938. this._order = order || Euler.DefaultOrder;
  2939. }
  2940. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2941. Euler.DefaultOrder = 'XYZ';
  2942. Object.defineProperties( Euler.prototype, {
  2943. x: {
  2944. get: function () {
  2945. return this._x;
  2946. },
  2947. set: function ( value ) {
  2948. this._x = value;
  2949. this._onChangeCallback();
  2950. }
  2951. },
  2952. y: {
  2953. get: function () {
  2954. return this._y;
  2955. },
  2956. set: function ( value ) {
  2957. this._y = value;
  2958. this._onChangeCallback();
  2959. }
  2960. },
  2961. z: {
  2962. get: function () {
  2963. return this._z;
  2964. },
  2965. set: function ( value ) {
  2966. this._z = value;
  2967. this._onChangeCallback();
  2968. }
  2969. },
  2970. order: {
  2971. get: function () {
  2972. return this._order;
  2973. },
  2974. set: function ( value ) {
  2975. this._order = value;
  2976. this._onChangeCallback();
  2977. }
  2978. }
  2979. } );
  2980. Object.assign( Euler.prototype, {
  2981. isEuler: true,
  2982. set: function ( x, y, z, order ) {
  2983. this._x = x;
  2984. this._y = y;
  2985. this._z = z;
  2986. this._order = order || this._order;
  2987. this._onChangeCallback();
  2988. return this;
  2989. },
  2990. clone: function () {
  2991. return new this.constructor( this._x, this._y, this._z, this._order );
  2992. },
  2993. copy: function ( euler ) {
  2994. this._x = euler._x;
  2995. this._y = euler._y;
  2996. this._z = euler._z;
  2997. this._order = euler._order;
  2998. this._onChangeCallback();
  2999. return this;
  3000. },
  3001. setFromRotationMatrix: function ( m, order, update ) {
  3002. var clamp = _Math.clamp;
  3003. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3004. var te = m.elements;
  3005. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3006. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3007. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3008. order = order || this._order;
  3009. if ( order === 'XYZ' ) {
  3010. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3011. if ( Math.abs( m13 ) < 0.9999999 ) {
  3012. this._x = Math.atan2( - m23, m33 );
  3013. this._z = Math.atan2( - m12, m11 );
  3014. } else {
  3015. this._x = Math.atan2( m32, m22 );
  3016. this._z = 0;
  3017. }
  3018. } else if ( order === 'YXZ' ) {
  3019. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3020. if ( Math.abs( m23 ) < 0.9999999 ) {
  3021. this._y = Math.atan2( m13, m33 );
  3022. this._z = Math.atan2( m21, m22 );
  3023. } else {
  3024. this._y = Math.atan2( - m31, m11 );
  3025. this._z = 0;
  3026. }
  3027. } else if ( order === 'ZXY' ) {
  3028. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3029. if ( Math.abs( m32 ) < 0.9999999 ) {
  3030. this._y = Math.atan2( - m31, m33 );
  3031. this._z = Math.atan2( - m12, m22 );
  3032. } else {
  3033. this._y = 0;
  3034. this._z = Math.atan2( m21, m11 );
  3035. }
  3036. } else if ( order === 'ZYX' ) {
  3037. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3038. if ( Math.abs( m31 ) < 0.9999999 ) {
  3039. this._x = Math.atan2( m32, m33 );
  3040. this._z = Math.atan2( m21, m11 );
  3041. } else {
  3042. this._x = 0;
  3043. this._z = Math.atan2( - m12, m22 );
  3044. }
  3045. } else if ( order === 'YZX' ) {
  3046. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3047. if ( Math.abs( m21 ) < 0.9999999 ) {
  3048. this._x = Math.atan2( - m23, m22 );
  3049. this._y = Math.atan2( - m31, m11 );
  3050. } else {
  3051. this._x = 0;
  3052. this._y = Math.atan2( m13, m33 );
  3053. }
  3054. } else if ( order === 'XZY' ) {
  3055. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3056. if ( Math.abs( m12 ) < 0.9999999 ) {
  3057. this._x = Math.atan2( m32, m22 );
  3058. this._y = Math.atan2( m13, m11 );
  3059. } else {
  3060. this._x = Math.atan2( - m23, m33 );
  3061. this._y = 0;
  3062. }
  3063. } else {
  3064. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  3065. }
  3066. this._order = order;
  3067. if ( update !== false ) this._onChangeCallback();
  3068. return this;
  3069. },
  3070. setFromQuaternion: function ( q, order, update ) {
  3071. if ( _matrix === undefined ) _matrix = new Matrix4();
  3072. _matrix.makeRotationFromQuaternion( q );
  3073. return this.setFromRotationMatrix( _matrix, order, update );
  3074. },
  3075. setFromVector3: function ( v, order ) {
  3076. return this.set( v.x, v.y, v.z, order || this._order );
  3077. },
  3078. reorder: function ( newOrder ) {
  3079. // WARNING: this discards revolution information -bhouston
  3080. if ( _quaternion === undefined ) _quaternion = new Quaternion();
  3081. _quaternion.setFromEuler( this );
  3082. return this.setFromQuaternion( _quaternion, newOrder );
  3083. },
  3084. equals: function ( euler ) {
  3085. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3086. },
  3087. fromArray: function ( array ) {
  3088. this._x = array[ 0 ];
  3089. this._y = array[ 1 ];
  3090. this._z = array[ 2 ];
  3091. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3092. this._onChangeCallback();
  3093. return this;
  3094. },
  3095. toArray: function ( array, offset ) {
  3096. if ( array === undefined ) array = [];
  3097. if ( offset === undefined ) offset = 0;
  3098. array[ offset ] = this._x;
  3099. array[ offset + 1 ] = this._y;
  3100. array[ offset + 2 ] = this._z;
  3101. array[ offset + 3 ] = this._order;
  3102. return array;
  3103. },
  3104. toVector3: function ( optionalResult ) {
  3105. if ( optionalResult ) {
  3106. return optionalResult.set( this._x, this._y, this._z );
  3107. } else {
  3108. return new Vector3( this._x, this._y, this._z );
  3109. }
  3110. },
  3111. _onChange: function ( callback ) {
  3112. this._onChangeCallback = callback;
  3113. return this;
  3114. },
  3115. _onChangeCallback: function () {}
  3116. } );
  3117. /**
  3118. * @author mrdoob / http://mrdoob.com/
  3119. */
  3120. function Layers() {
  3121. this.mask = 1 | 0;
  3122. }
  3123. Object.assign( Layers.prototype, {
  3124. set: function ( channel ) {
  3125. this.mask = 1 << channel | 0;
  3126. },
  3127. enable: function ( channel ) {
  3128. this.mask |= 1 << channel | 0;
  3129. },
  3130. toggle: function ( channel ) {
  3131. this.mask ^= 1 << channel | 0;
  3132. },
  3133. disable: function ( channel ) {
  3134. this.mask &= ~ ( 1 << channel | 0 );
  3135. },
  3136. test: function ( layers ) {
  3137. return ( this.mask & layers.mask ) !== 0;
  3138. }
  3139. } );
  3140. /**
  3141. * @author mrdoob / http://mrdoob.com/
  3142. * @author mikael emtinger / http://gomo.se/
  3143. * @author alteredq / http://alteredqualia.com/
  3144. * @author WestLangley / http://github.com/WestLangley
  3145. * @author elephantatwork / www.elephantatwork.ch
  3146. */
  3147. var object3DId = 0;
  3148. function Object3D() {
  3149. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  3150. this.uuid = _Math.generateUUID();
  3151. this.name = '';
  3152. this.type = 'Object3D';
  3153. this.parent = null;
  3154. this.children = [];
  3155. this.up = Object3D.DefaultUp.clone();
  3156. var position = new Vector3();
  3157. var rotation = new Euler();
  3158. var quaternion = new Quaternion();
  3159. var scale = new Vector3( 1, 1, 1 );
  3160. function onRotationChange() {
  3161. quaternion.setFromEuler( rotation, false );
  3162. }
  3163. function onQuaternionChange() {
  3164. rotation.setFromQuaternion( quaternion, undefined, false );
  3165. }
  3166. rotation._onChange( onRotationChange );
  3167. quaternion._onChange( onQuaternionChange );
  3168. Object.defineProperties( this, {
  3169. position: {
  3170. configurable: true,
  3171. enumerable: true,
  3172. value: position
  3173. },
  3174. rotation: {
  3175. configurable: true,
  3176. enumerable: true,
  3177. value: rotation
  3178. },
  3179. quaternion: {
  3180. configurable: true,
  3181. enumerable: true,
  3182. value: quaternion
  3183. },
  3184. scale: {
  3185. configurable: true,
  3186. enumerable: true,
  3187. value: scale
  3188. },
  3189. modelViewMatrix: {
  3190. value: new Matrix4()
  3191. },
  3192. normalMatrix: {
  3193. value: new Matrix3()
  3194. }
  3195. } );
  3196. this.matrix = new Matrix4();
  3197. this.matrixWorld = new Matrix4();
  3198. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3199. this.matrixWorldNeedsUpdate = false;
  3200. this.layers = new Layers();
  3201. this.visible = true;
  3202. this.castShadow = false;
  3203. this.receiveShadow = false;
  3204. this.frustumCulled = true;
  3205. this.renderOrder = 0;
  3206. this.userData = {};
  3207. }
  3208. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3209. Object3D.DefaultMatrixAutoUpdate = true;
  3210. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3211. constructor: Object3D,
  3212. isObject3D: true,
  3213. onBeforeRender: function () {},
  3214. onAfterRender: function () {},
  3215. applyMatrix: function ( matrix ) {
  3216. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3217. this.matrix.premultiply( matrix );
  3218. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3219. },
  3220. applyQuaternion: function ( q ) {
  3221. this.quaternion.premultiply( q );
  3222. return this;
  3223. },
  3224. setRotationFromAxisAngle: function ( axis, angle ) {
  3225. // assumes axis is normalized
  3226. this.quaternion.setFromAxisAngle( axis, angle );
  3227. },
  3228. setRotationFromEuler: function ( euler ) {
  3229. this.quaternion.setFromEuler( euler, true );
  3230. },
  3231. setRotationFromMatrix: function ( m ) {
  3232. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3233. this.quaternion.setFromRotationMatrix( m );
  3234. },
  3235. setRotationFromQuaternion: function ( q ) {
  3236. // assumes q is normalized
  3237. this.quaternion.copy( q );
  3238. },
  3239. rotateOnAxis: function () {
  3240. // rotate object on axis in object space
  3241. // axis is assumed to be normalized
  3242. var q1 = new Quaternion();
  3243. return function rotateOnAxis( axis, angle ) {
  3244. q1.setFromAxisAngle( axis, angle );
  3245. this.quaternion.multiply( q1 );
  3246. return this;
  3247. };
  3248. }(),
  3249. rotateOnWorldAxis: function () {
  3250. // rotate object on axis in world space
  3251. // axis is assumed to be normalized
  3252. // method assumes no rotated parent
  3253. var q1 = new Quaternion();
  3254. return function rotateOnWorldAxis( axis, angle ) {
  3255. q1.setFromAxisAngle( axis, angle );
  3256. this.quaternion.premultiply( q1 );
  3257. return this;
  3258. };
  3259. }(),
  3260. rotateX: function () {
  3261. var v1 = new Vector3( 1, 0, 0 );
  3262. return function rotateX( angle ) {
  3263. return this.rotateOnAxis( v1, angle );
  3264. };
  3265. }(),
  3266. rotateY: function () {
  3267. var v1 = new Vector3( 0, 1, 0 );
  3268. return function rotateY( angle ) {
  3269. return this.rotateOnAxis( v1, angle );
  3270. };
  3271. }(),
  3272. rotateZ: function () {
  3273. var v1 = new Vector3( 0, 0, 1 );
  3274. return function rotateZ( angle ) {
  3275. return this.rotateOnAxis( v1, angle );
  3276. };
  3277. }(),
  3278. translateOnAxis: function () {
  3279. // translate object by distance along axis in object space
  3280. // axis is assumed to be normalized
  3281. var v1 = new Vector3();
  3282. return function translateOnAxis( axis, distance ) {
  3283. v1.copy( axis ).applyQuaternion( this.quaternion );
  3284. this.position.add( v1.multiplyScalar( distance ) );
  3285. return this;
  3286. };
  3287. }(),
  3288. translateX: function () {
  3289. var v1 = new Vector3( 1, 0, 0 );
  3290. return function translateX( distance ) {
  3291. return this.translateOnAxis( v1, distance );
  3292. };
  3293. }(),
  3294. translateY: function () {
  3295. var v1 = new Vector3( 0, 1, 0 );
  3296. return function translateY( distance ) {
  3297. return this.translateOnAxis( v1, distance );
  3298. };
  3299. }(),
  3300. translateZ: function () {
  3301. var v1 = new Vector3( 0, 0, 1 );
  3302. return function translateZ( distance ) {
  3303. return this.translateOnAxis( v1, distance );
  3304. };
  3305. }(),
  3306. localToWorld: function ( vector ) {
  3307. return vector.applyMatrix4( this.matrixWorld );
  3308. },
  3309. worldToLocal: function () {
  3310. var m1 = new Matrix4();
  3311. return function worldToLocal( vector ) {
  3312. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  3313. };
  3314. }(),
  3315. lookAt: function () {
  3316. // This method does not support objects having non-uniformly-scaled parent(s)
  3317. var q1 = new Quaternion();
  3318. var m1 = new Matrix4();
  3319. var target = new Vector3();
  3320. var position = new Vector3();
  3321. return function lookAt( x, y, z ) {
  3322. if ( x.isVector3 ) {
  3323. target.copy( x );
  3324. } else {
  3325. target.set( x, y, z );
  3326. }
  3327. var parent = this.parent;
  3328. this.updateWorldMatrix( true, false );
  3329. position.setFromMatrixPosition( this.matrixWorld );
  3330. if ( this.isCamera || this.isLight ) {
  3331. m1.lookAt( position, target, this.up );
  3332. } else {
  3333. m1.lookAt( target, position, this.up );
  3334. }
  3335. this.quaternion.setFromRotationMatrix( m1 );
  3336. if ( parent ) {
  3337. m1.extractRotation( parent.matrixWorld );
  3338. q1.setFromRotationMatrix( m1 );
  3339. this.quaternion.premultiply( q1.inverse() );
  3340. }
  3341. };
  3342. }(),
  3343. add: function ( object ) {
  3344. if ( arguments.length > 1 ) {
  3345. for ( var i = 0; i < arguments.length; i ++ ) {
  3346. this.add( arguments[ i ] );
  3347. }
  3348. return this;
  3349. }
  3350. if ( object === this ) {
  3351. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3352. return this;
  3353. }
  3354. if ( ( object && object.isObject3D ) ) {
  3355. if ( object.parent !== null ) {
  3356. object.parent.remove( object );
  3357. }
  3358. object.parent = this;
  3359. this.children.push( object );
  3360. object.dispatchEvent( { type: 'added' } );
  3361. } else {
  3362. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3363. }
  3364. return this;
  3365. },
  3366. remove: function ( object ) {
  3367. if ( arguments.length > 1 ) {
  3368. for ( var i = 0; i < arguments.length; i ++ ) {
  3369. this.remove( arguments[ i ] );
  3370. }
  3371. return this;
  3372. }
  3373. var index = this.children.indexOf( object );
  3374. if ( index !== - 1 ) {
  3375. object.parent = null;
  3376. this.children.splice( index, 1 );
  3377. object.dispatchEvent( { type: 'removed' } );
  3378. }
  3379. return this;
  3380. },
  3381. attach: function () {
  3382. // adds object as a child of this, while maintaining the object's world transform
  3383. var m = new Matrix4();
  3384. return function attach( object ) {
  3385. this.updateWorldMatrix( true, false );
  3386. m.getInverse( this.matrixWorld );
  3387. if ( object.parent !== null ) {
  3388. object.parent.updateWorldMatrix( true, false );
  3389. m.multiply( object.parent.matrixWorld );
  3390. }
  3391. object.applyMatrix( m );
  3392. object.updateWorldMatrix( false, false );
  3393. this.add( object );
  3394. return this;
  3395. };
  3396. }(),
  3397. getObjectById: function ( id ) {
  3398. return this.getObjectByProperty( 'id', id );
  3399. },
  3400. getObjectByName: function ( name ) {
  3401. return this.getObjectByProperty( 'name', name );
  3402. },
  3403. getObjectByProperty: function ( name, value ) {
  3404. if ( this[ name ] === value ) return this;
  3405. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3406. var child = this.children[ i ];
  3407. var object = child.getObjectByProperty( name, value );
  3408. if ( object !== undefined ) {
  3409. return object;
  3410. }
  3411. }
  3412. return undefined;
  3413. },
  3414. getWorldPosition: function ( target ) {
  3415. if ( target === undefined ) {
  3416. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3417. target = new Vector3();
  3418. }
  3419. this.updateMatrixWorld( true );
  3420. return target.setFromMatrixPosition( this.matrixWorld );
  3421. },
  3422. getWorldQuaternion: function () {
  3423. var position = new Vector3();
  3424. var scale = new Vector3();
  3425. return function getWorldQuaternion( target ) {
  3426. if ( target === undefined ) {
  3427. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3428. target = new Quaternion();
  3429. }
  3430. this.updateMatrixWorld( true );
  3431. this.matrixWorld.decompose( position, target, scale );
  3432. return target;
  3433. };
  3434. }(),
  3435. getWorldScale: function () {
  3436. var position = new Vector3();
  3437. var quaternion = new Quaternion();
  3438. return function getWorldScale( target ) {
  3439. if ( target === undefined ) {
  3440. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3441. target = new Vector3();
  3442. }
  3443. this.updateMatrixWorld( true );
  3444. this.matrixWorld.decompose( position, quaternion, target );
  3445. return target;
  3446. };
  3447. }(),
  3448. getWorldDirection: function ( target ) {
  3449. if ( target === undefined ) {
  3450. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3451. target = new Vector3();
  3452. }
  3453. this.updateMatrixWorld( true );
  3454. var e = this.matrixWorld.elements;
  3455. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3456. },
  3457. raycast: function () {},
  3458. traverse: function ( callback ) {
  3459. callback( this );
  3460. var children = this.children;
  3461. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3462. children[ i ].traverse( callback );
  3463. }
  3464. },
  3465. traverseVisible: function ( callback ) {
  3466. if ( this.visible === false ) return;
  3467. callback( this );
  3468. var children = this.children;
  3469. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3470. children[ i ].traverseVisible( callback );
  3471. }
  3472. },
  3473. traverseAncestors: function ( callback ) {
  3474. var parent = this.parent;
  3475. if ( parent !== null ) {
  3476. callback( parent );
  3477. parent.traverseAncestors( callback );
  3478. }
  3479. },
  3480. updateMatrix: function () {
  3481. this.matrix.compose( this.position, this.quaternion, this.scale );
  3482. this.matrixWorldNeedsUpdate = true;
  3483. },
  3484. updateMatrixWorld: function ( force ) {
  3485. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3486. if ( this.matrixWorldNeedsUpdate || force ) {
  3487. if ( this.parent === null ) {
  3488. this.matrixWorld.copy( this.matrix );
  3489. } else {
  3490. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3491. }
  3492. this.matrixWorldNeedsUpdate = false;
  3493. force = true;
  3494. }
  3495. // update children
  3496. var children = this.children;
  3497. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3498. children[ i ].updateMatrixWorld( force );
  3499. }
  3500. },
  3501. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3502. var parent = this.parent;
  3503. if ( updateParents === true && parent !== null ) {
  3504. parent.updateWorldMatrix( true, false );
  3505. }
  3506. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3507. if ( this.parent === null ) {
  3508. this.matrixWorld.copy( this.matrix );
  3509. } else {
  3510. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3511. }
  3512. // update children
  3513. if ( updateChildren === true ) {
  3514. var children = this.children;
  3515. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3516. children[ i ].updateWorldMatrix( false, true );
  3517. }
  3518. }
  3519. },
  3520. toJSON: function ( meta ) {
  3521. // meta is a string when called from JSON.stringify
  3522. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3523. var output = {};
  3524. // meta is a hash used to collect geometries, materials.
  3525. // not providing it implies that this is the root object
  3526. // being serialized.
  3527. if ( isRootObject ) {
  3528. // initialize meta obj
  3529. meta = {
  3530. geometries: {},
  3531. materials: {},
  3532. textures: {},
  3533. images: {},
  3534. shapes: {}
  3535. };
  3536. output.metadata = {
  3537. version: 4.5,
  3538. type: 'Object',
  3539. generator: 'Object3D.toJSON'
  3540. };
  3541. }
  3542. // standard Object3D serialization
  3543. var object = {};
  3544. object.uuid = this.uuid;
  3545. object.type = this.type;
  3546. if ( this.name !== '' ) object.name = this.name;
  3547. if ( this.castShadow === true ) object.castShadow = true;
  3548. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3549. if ( this.visible === false ) object.visible = false;
  3550. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3551. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3552. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3553. object.layers = this.layers.mask;
  3554. object.matrix = this.matrix.toArray();
  3555. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3556. // object specific properties
  3557. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  3558. //
  3559. function serialize( library, element ) {
  3560. if ( library[ element.uuid ] === undefined ) {
  3561. library[ element.uuid ] = element.toJSON( meta );
  3562. }
  3563. return element.uuid;
  3564. }
  3565. if ( this.isMesh || this.isLine || this.isPoints ) {
  3566. object.geometry = serialize( meta.geometries, this.geometry );
  3567. var parameters = this.geometry.parameters;
  3568. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3569. var shapes = parameters.shapes;
  3570. if ( Array.isArray( shapes ) ) {
  3571. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3572. var shape = shapes[ i ];
  3573. serialize( meta.shapes, shape );
  3574. }
  3575. } else {
  3576. serialize( meta.shapes, shapes );
  3577. }
  3578. }
  3579. }
  3580. if ( this.material !== undefined ) {
  3581. if ( Array.isArray( this.material ) ) {
  3582. var uuids = [];
  3583. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  3584. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3585. }
  3586. object.material = uuids;
  3587. } else {
  3588. object.material = serialize( meta.materials, this.material );
  3589. }
  3590. }
  3591. //
  3592. if ( this.children.length > 0 ) {
  3593. object.children = [];
  3594. for ( var i = 0; i < this.children.length; i ++ ) {
  3595. object.children.push( this.children[ i ].toJSON( meta ).object );
  3596. }
  3597. }
  3598. if ( isRootObject ) {
  3599. var geometries = extractFromCache( meta.geometries );
  3600. var materials = extractFromCache( meta.materials );
  3601. var textures = extractFromCache( meta.textures );
  3602. var images = extractFromCache( meta.images );
  3603. var shapes = extractFromCache( meta.shapes );
  3604. if ( geometries.length > 0 ) output.geometries = geometries;
  3605. if ( materials.length > 0 ) output.materials = materials;
  3606. if ( textures.length > 0 ) output.textures = textures;
  3607. if ( images.length > 0 ) output.images = images;
  3608. if ( shapes.length > 0 ) output.shapes = shapes;
  3609. }
  3610. output.object = object;
  3611. return output;
  3612. // extract data from the cache hash
  3613. // remove metadata on each item
  3614. // and return as array
  3615. function extractFromCache( cache ) {
  3616. var values = [];
  3617. for ( var key in cache ) {
  3618. var data = cache[ key ];
  3619. delete data.metadata;
  3620. values.push( data );
  3621. }
  3622. return values;
  3623. }
  3624. },
  3625. clone: function ( recursive ) {
  3626. return new this.constructor().copy( this, recursive );
  3627. },
  3628. copy: function ( source, recursive ) {
  3629. if ( recursive === undefined ) recursive = true;
  3630. this.name = source.name;
  3631. this.up.copy( source.up );
  3632. this.position.copy( source.position );
  3633. this.quaternion.copy( source.quaternion );
  3634. this.scale.copy( source.scale );
  3635. this.matrix.copy( source.matrix );
  3636. this.matrixWorld.copy( source.matrixWorld );
  3637. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3638. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3639. this.layers.mask = source.layers.mask;
  3640. this.visible = source.visible;
  3641. this.castShadow = source.castShadow;
  3642. this.receiveShadow = source.receiveShadow;
  3643. this.frustumCulled = source.frustumCulled;
  3644. this.renderOrder = source.renderOrder;
  3645. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3646. if ( recursive === true ) {
  3647. for ( var i = 0; i < source.children.length; i ++ ) {
  3648. var child = source.children[ i ];
  3649. this.add( child.clone() );
  3650. }
  3651. }
  3652. return this;
  3653. }
  3654. } );
  3655. /**
  3656. * @author mrdoob / http://mrdoob.com/
  3657. */
  3658. function Scene() {
  3659. Object3D.call( this );
  3660. this.type = 'Scene';
  3661. this.background = null;
  3662. this.fog = null;
  3663. this.overrideMaterial = null;
  3664. this.autoUpdate = true; // checked by the renderer
  3665. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3666. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3667. }
  3668. }
  3669. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3670. constructor: Scene,
  3671. isScene: true,
  3672. copy: function ( source, recursive ) {
  3673. Object3D.prototype.copy.call( this, source, recursive );
  3674. if ( source.background !== null ) this.background = source.background.clone();
  3675. if ( source.fog !== null ) this.fog = source.fog.clone();
  3676. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3677. this.autoUpdate = source.autoUpdate;
  3678. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3679. return this;
  3680. },
  3681. toJSON: function ( meta ) {
  3682. var data = Object3D.prototype.toJSON.call( this, meta );
  3683. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3684. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3685. return data;
  3686. },
  3687. dispose: function () {
  3688. this.dispatchEvent( { type: 'dispose' } );
  3689. }
  3690. } );
  3691. /**
  3692. * @author bhouston / http://clara.io
  3693. * @author WestLangley / http://github.com/WestLangley
  3694. */
  3695. function Box3( min, max ) {
  3696. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3697. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3698. }
  3699. Object.assign( Box3.prototype, {
  3700. isBox3: true,
  3701. set: function ( min, max ) {
  3702. this.min.copy( min );
  3703. this.max.copy( max );
  3704. return this;
  3705. },
  3706. setFromArray: function ( array ) {
  3707. var minX = + Infinity;
  3708. var minY = + Infinity;
  3709. var minZ = + Infinity;
  3710. var maxX = - Infinity;
  3711. var maxY = - Infinity;
  3712. var maxZ = - Infinity;
  3713. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3714. var x = array[ i ];
  3715. var y = array[ i + 1 ];
  3716. var z = array[ i + 2 ];
  3717. if ( x < minX ) minX = x;
  3718. if ( y < minY ) minY = y;
  3719. if ( z < minZ ) minZ = z;
  3720. if ( x > maxX ) maxX = x;
  3721. if ( y > maxY ) maxY = y;
  3722. if ( z > maxZ ) maxZ = z;
  3723. }
  3724. this.min.set( minX, minY, minZ );
  3725. this.max.set( maxX, maxY, maxZ );
  3726. return this;
  3727. },
  3728. setFromBufferAttribute: function ( attribute ) {
  3729. var minX = + Infinity;
  3730. var minY = + Infinity;
  3731. var minZ = + Infinity;
  3732. var maxX = - Infinity;
  3733. var maxY = - Infinity;
  3734. var maxZ = - Infinity;
  3735. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3736. var x = attribute.getX( i );
  3737. var y = attribute.getY( i );
  3738. var z = attribute.getZ( i );
  3739. if ( x < minX ) minX = x;
  3740. if ( y < minY ) minY = y;
  3741. if ( z < minZ ) minZ = z;
  3742. if ( x > maxX ) maxX = x;
  3743. if ( y > maxY ) maxY = y;
  3744. if ( z > maxZ ) maxZ = z;
  3745. }
  3746. this.min.set( minX, minY, minZ );
  3747. this.max.set( maxX, maxY, maxZ );
  3748. return this;
  3749. },
  3750. setFromPoints: function ( points ) {
  3751. this.makeEmpty();
  3752. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3753. this.expandByPoint( points[ i ] );
  3754. }
  3755. return this;
  3756. },
  3757. setFromCenterAndSize: function () {
  3758. var v1 = new Vector3();
  3759. return function setFromCenterAndSize( center, size ) {
  3760. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  3761. this.min.copy( center ).sub( halfSize );
  3762. this.max.copy( center ).add( halfSize );
  3763. return this;
  3764. };
  3765. }(),
  3766. setFromObject: function ( object ) {
  3767. this.makeEmpty();
  3768. return this.expandByObject( object );
  3769. },
  3770. clone: function () {
  3771. return new this.constructor().copy( this );
  3772. },
  3773. copy: function ( box ) {
  3774. this.min.copy( box.min );
  3775. this.max.copy( box.max );
  3776. return this;
  3777. },
  3778. makeEmpty: function () {
  3779. this.min.x = this.min.y = this.min.z = + Infinity;
  3780. this.max.x = this.max.y = this.max.z = - Infinity;
  3781. return this;
  3782. },
  3783. isEmpty: function () {
  3784. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3785. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3786. },
  3787. getCenter: function ( target ) {
  3788. if ( target === undefined ) {
  3789. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3790. target = new Vector3();
  3791. }
  3792. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3793. },
  3794. getSize: function ( target ) {
  3795. if ( target === undefined ) {
  3796. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3797. target = new Vector3();
  3798. }
  3799. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3800. },
  3801. expandByPoint: function ( point ) {
  3802. this.min.min( point );
  3803. this.max.max( point );
  3804. return this;
  3805. },
  3806. expandByVector: function ( vector ) {
  3807. this.min.sub( vector );
  3808. this.max.add( vector );
  3809. return this;
  3810. },
  3811. expandByScalar: function ( scalar ) {
  3812. this.min.addScalar( - scalar );
  3813. this.max.addScalar( scalar );
  3814. return this;
  3815. },
  3816. expandByObject: function () {
  3817. // Computes the world-axis-aligned bounding box of an object (including its children),
  3818. // accounting for both the object's, and children's, world transforms
  3819. var scope, i, l;
  3820. var v1 = new Vector3();
  3821. function traverse( node ) {
  3822. var geometry = node.geometry;
  3823. if ( geometry !== undefined ) {
  3824. if ( geometry.isGeometry ) {
  3825. var vertices = geometry.vertices;
  3826. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3827. v1.copy( vertices[ i ] );
  3828. v1.applyMatrix4( node.matrixWorld );
  3829. scope.expandByPoint( v1 );
  3830. }
  3831. } else if ( geometry.isBufferGeometry ) {
  3832. var attribute = geometry.attributes.position;
  3833. if ( attribute !== undefined ) {
  3834. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3835. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  3836. scope.expandByPoint( v1 );
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. return function expandByObject( object ) {
  3843. scope = this;
  3844. object.updateMatrixWorld( true );
  3845. object.traverse( traverse );
  3846. return this;
  3847. };
  3848. }(),
  3849. containsPoint: function ( point ) {
  3850. return point.x < this.min.x || point.x > this.max.x ||
  3851. point.y < this.min.y || point.y > this.max.y ||
  3852. point.z < this.min.z || point.z > this.max.z ? false : true;
  3853. },
  3854. containsBox: function ( box ) {
  3855. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3856. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3857. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3858. },
  3859. getParameter: function ( point, target ) {
  3860. // This can potentially have a divide by zero if the box
  3861. // has a size dimension of 0.
  3862. if ( target === undefined ) {
  3863. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3864. target = new Vector3();
  3865. }
  3866. return target.set(
  3867. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3868. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3869. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3870. );
  3871. },
  3872. intersectsBox: function ( box ) {
  3873. // using 6 splitting planes to rule out intersections.
  3874. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3875. box.max.y < this.min.y || box.min.y > this.max.y ||
  3876. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3877. },
  3878. intersectsSphere: ( function () {
  3879. var closestPoint = new Vector3();
  3880. return function intersectsSphere( sphere ) {
  3881. // Find the point on the AABB closest to the sphere center.
  3882. this.clampPoint( sphere.center, closestPoint );
  3883. // If that point is inside the sphere, the AABB and sphere intersect.
  3884. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3885. };
  3886. } )(),
  3887. intersectsPlane: function ( plane ) {
  3888. // We compute the minimum and maximum dot product values. If those values
  3889. // are on the same side (back or front) of the plane, then there is no intersection.
  3890. var min, max;
  3891. if ( plane.normal.x > 0 ) {
  3892. min = plane.normal.x * this.min.x;
  3893. max = plane.normal.x * this.max.x;
  3894. } else {
  3895. min = plane.normal.x * this.max.x;
  3896. max = plane.normal.x * this.min.x;
  3897. }
  3898. if ( plane.normal.y > 0 ) {
  3899. min += plane.normal.y * this.min.y;
  3900. max += plane.normal.y * this.max.y;
  3901. } else {
  3902. min += plane.normal.y * this.max.y;
  3903. max += plane.normal.y * this.min.y;
  3904. }
  3905. if ( plane.normal.z > 0 ) {
  3906. min += plane.normal.z * this.min.z;
  3907. max += plane.normal.z * this.max.z;
  3908. } else {
  3909. min += plane.normal.z * this.max.z;
  3910. max += plane.normal.z * this.min.z;
  3911. }
  3912. return ( min <= - plane.constant && max >= - plane.constant );
  3913. },
  3914. intersectsTriangle: ( function () {
  3915. // triangle centered vertices
  3916. var v0 = new Vector3();
  3917. var v1 = new Vector3();
  3918. var v2 = new Vector3();
  3919. // triangle edge vectors
  3920. var f0 = new Vector3();
  3921. var f1 = new Vector3();
  3922. var f2 = new Vector3();
  3923. var testAxis = new Vector3();
  3924. var center = new Vector3();
  3925. var extents = new Vector3();
  3926. var triangleNormal = new Vector3();
  3927. function satForAxes( axes ) {
  3928. var i, j;
  3929. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3930. testAxis.fromArray( axes, i );
  3931. // project the aabb onto the seperating axis
  3932. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3933. // project all 3 vertices of the triangle onto the seperating axis
  3934. var p0 = v0.dot( testAxis );
  3935. var p1 = v1.dot( testAxis );
  3936. var p2 = v2.dot( testAxis );
  3937. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3938. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3939. // points of the projected triangle are outside the projected half-length of the aabb
  3940. // the axis is seperating and we can exit
  3941. return false;
  3942. }
  3943. }
  3944. return true;
  3945. }
  3946. return function intersectsTriangle( triangle ) {
  3947. if ( this.isEmpty() ) {
  3948. return false;
  3949. }
  3950. // compute box center and extents
  3951. this.getCenter( center );
  3952. extents.subVectors( this.max, center );
  3953. // translate triangle to aabb origin
  3954. v0.subVectors( triangle.a, center );
  3955. v1.subVectors( triangle.b, center );
  3956. v2.subVectors( triangle.c, center );
  3957. // compute edge vectors for triangle
  3958. f0.subVectors( v1, v0 );
  3959. f1.subVectors( v2, v1 );
  3960. f2.subVectors( v0, v2 );
  3961. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3962. // 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
  3963. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3964. var axes = [
  3965. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3966. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3967. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3968. ];
  3969. if ( ! satForAxes( axes ) ) {
  3970. return false;
  3971. }
  3972. // test 3 face normals from the aabb
  3973. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3974. if ( ! satForAxes( axes ) ) {
  3975. return false;
  3976. }
  3977. // finally testing the face normal of the triangle
  3978. // use already existing triangle edge vectors here
  3979. triangleNormal.crossVectors( f0, f1 );
  3980. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3981. return satForAxes( axes );
  3982. };
  3983. } )(),
  3984. clampPoint: function ( point, target ) {
  3985. if ( target === undefined ) {
  3986. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3987. target = new Vector3();
  3988. }
  3989. return target.copy( point ).clamp( this.min, this.max );
  3990. },
  3991. distanceToPoint: function () {
  3992. var v1 = new Vector3();
  3993. return function distanceToPoint( point ) {
  3994. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3995. return clampedPoint.sub( point ).length();
  3996. };
  3997. }(),
  3998. getBoundingSphere: function () {
  3999. var v1 = new Vector3();
  4000. return function getBoundingSphere( target ) {
  4001. if ( target === undefined ) {
  4002. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  4003. //target = new Sphere(); // removed to avoid cyclic dependency
  4004. }
  4005. this.getCenter( target.center );
  4006. target.radius = this.getSize( v1 ).length() * 0.5;
  4007. return target;
  4008. };
  4009. }(),
  4010. intersect: function ( box ) {
  4011. this.min.max( box.min );
  4012. this.max.min( box.max );
  4013. // 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.
  4014. if ( this.isEmpty() ) this.makeEmpty();
  4015. return this;
  4016. },
  4017. union: function ( box ) {
  4018. this.min.min( box.min );
  4019. this.max.max( box.max );
  4020. return this;
  4021. },
  4022. applyMatrix4: function () {
  4023. var points = [
  4024. new Vector3(),
  4025. new Vector3(),
  4026. new Vector3(),
  4027. new Vector3(),
  4028. new Vector3(),
  4029. new Vector3(),
  4030. new Vector3(),
  4031. new Vector3()
  4032. ];
  4033. return function applyMatrix4( matrix ) {
  4034. // transform of empty box is an empty box.
  4035. if ( this.isEmpty() ) return this;
  4036. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4037. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4038. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4039. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4040. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4041. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4042. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4043. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4044. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4045. this.setFromPoints( points );
  4046. return this;
  4047. };
  4048. }(),
  4049. translate: function ( offset ) {
  4050. this.min.add( offset );
  4051. this.max.add( offset );
  4052. return this;
  4053. },
  4054. equals: function ( box ) {
  4055. return box.min.equals( this.min ) && box.max.equals( this.max );
  4056. }
  4057. } );
  4058. /**
  4059. * @author bhouston / http://clara.io
  4060. * @author mrdoob / http://mrdoob.com/
  4061. */
  4062. var _box;
  4063. function Sphere( center, radius ) {
  4064. this.center = ( center !== undefined ) ? center : new Vector3();
  4065. this.radius = ( radius !== undefined ) ? radius : 0;
  4066. }
  4067. Object.assign( Sphere.prototype, {
  4068. set: function ( center, radius ) {
  4069. this.center.copy( center );
  4070. this.radius = radius;
  4071. return this;
  4072. },
  4073. setFromPoints: function ( points, optionalCenter ) {
  4074. if ( _box === undefined ) _box = new Box3();
  4075. var center = this.center;
  4076. if ( optionalCenter !== undefined ) {
  4077. center.copy( optionalCenter );
  4078. } else {
  4079. _box.setFromPoints( points ).getCenter( center );
  4080. }
  4081. var maxRadiusSq = 0;
  4082. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4083. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4084. }
  4085. this.radius = Math.sqrt( maxRadiusSq );
  4086. return this;
  4087. },
  4088. clone: function () {
  4089. return new this.constructor().copy( this );
  4090. },
  4091. copy: function ( sphere ) {
  4092. this.center.copy( sphere.center );
  4093. this.radius = sphere.radius;
  4094. return this;
  4095. },
  4096. empty: function () {
  4097. return ( this.radius <= 0 );
  4098. },
  4099. containsPoint: function ( point ) {
  4100. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4101. },
  4102. distanceToPoint: function ( point ) {
  4103. return ( point.distanceTo( this.center ) - this.radius );
  4104. },
  4105. intersectsSphere: function ( sphere ) {
  4106. var radiusSum = this.radius + sphere.radius;
  4107. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4108. },
  4109. intersectsBox: function ( box ) {
  4110. return box.intersectsSphere( this );
  4111. },
  4112. intersectsPlane: function ( plane ) {
  4113. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4114. },
  4115. clampPoint: function ( point, target ) {
  4116. var deltaLengthSq = this.center.distanceToSquared( point );
  4117. if ( target === undefined ) {
  4118. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4119. target = new Vector3();
  4120. }
  4121. target.copy( point );
  4122. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4123. target.sub( this.center ).normalize();
  4124. target.multiplyScalar( this.radius ).add( this.center );
  4125. }
  4126. return target;
  4127. },
  4128. getBoundingBox: function ( target ) {
  4129. if ( target === undefined ) {
  4130. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4131. target = new Box3();
  4132. }
  4133. target.set( this.center, this.center );
  4134. target.expandByScalar( this.radius );
  4135. return target;
  4136. },
  4137. applyMatrix4: function ( matrix ) {
  4138. this.center.applyMatrix4( matrix );
  4139. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4140. return this;
  4141. },
  4142. translate: function ( offset ) {
  4143. this.center.add( offset );
  4144. return this;
  4145. },
  4146. equals: function ( sphere ) {
  4147. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4148. }
  4149. } );
  4150. /**
  4151. * @author bhouston / http://clara.io
  4152. */
  4153. function Ray( origin, direction ) {
  4154. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4155. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  4156. }
  4157. Object.assign( Ray.prototype, {
  4158. set: function ( origin, direction ) {
  4159. this.origin.copy( origin );
  4160. this.direction.copy( direction );
  4161. return this;
  4162. },
  4163. clone: function () {
  4164. return new this.constructor().copy( this );
  4165. },
  4166. copy: function ( ray ) {
  4167. this.origin.copy( ray.origin );
  4168. this.direction.copy( ray.direction );
  4169. return this;
  4170. },
  4171. at: function ( t, target ) {
  4172. if ( target === undefined ) {
  4173. console.warn( 'THREE.Ray: .at() target is now required' );
  4174. target = new Vector3();
  4175. }
  4176. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4177. },
  4178. lookAt: function ( v ) {
  4179. this.direction.copy( v ).sub( this.origin ).normalize();
  4180. return this;
  4181. },
  4182. recast: function () {
  4183. var v1 = new Vector3();
  4184. return function recast( t ) {
  4185. this.origin.copy( this.at( t, v1 ) );
  4186. return this;
  4187. };
  4188. }(),
  4189. closestPointToPoint: function ( point, target ) {
  4190. if ( target === undefined ) {
  4191. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4192. target = new Vector3();
  4193. }
  4194. target.subVectors( point, this.origin );
  4195. var directionDistance = target.dot( this.direction );
  4196. if ( directionDistance < 0 ) {
  4197. return target.copy( this.origin );
  4198. }
  4199. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4200. },
  4201. distanceToPoint: function ( point ) {
  4202. return Math.sqrt( this.distanceSqToPoint( point ) );
  4203. },
  4204. distanceSqToPoint: function () {
  4205. var v1 = new Vector3();
  4206. return function distanceSqToPoint( point ) {
  4207. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  4208. // point behind the ray
  4209. if ( directionDistance < 0 ) {
  4210. return this.origin.distanceToSquared( point );
  4211. }
  4212. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4213. return v1.distanceToSquared( point );
  4214. };
  4215. }(),
  4216. distanceSqToSegment: function () {
  4217. var segCenter = new Vector3();
  4218. var segDir = new Vector3();
  4219. var diff = new Vector3();
  4220. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4221. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4222. // It returns the min distance between the ray and the segment
  4223. // defined by v0 and v1
  4224. // It can also set two optional targets :
  4225. // - The closest point on the ray
  4226. // - The closest point on the segment
  4227. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4228. segDir.copy( v1 ).sub( v0 ).normalize();
  4229. diff.copy( this.origin ).sub( segCenter );
  4230. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4231. var a01 = - this.direction.dot( segDir );
  4232. var b0 = diff.dot( this.direction );
  4233. var b1 = - diff.dot( segDir );
  4234. var c = diff.lengthSq();
  4235. var det = Math.abs( 1 - a01 * a01 );
  4236. var s0, s1, sqrDist, extDet;
  4237. if ( det > 0 ) {
  4238. // The ray and segment are not parallel.
  4239. s0 = a01 * b1 - b0;
  4240. s1 = a01 * b0 - b1;
  4241. extDet = segExtent * det;
  4242. if ( s0 >= 0 ) {
  4243. if ( s1 >= - extDet ) {
  4244. if ( s1 <= extDet ) {
  4245. // region 0
  4246. // Minimum at interior points of ray and segment.
  4247. var invDet = 1 / det;
  4248. s0 *= invDet;
  4249. s1 *= invDet;
  4250. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4251. } else {
  4252. // region 1
  4253. s1 = segExtent;
  4254. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4255. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4256. }
  4257. } else {
  4258. // region 5
  4259. s1 = - segExtent;
  4260. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4261. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4262. }
  4263. } else {
  4264. if ( s1 <= - extDet ) {
  4265. // region 4
  4266. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4267. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4268. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4269. } else if ( s1 <= extDet ) {
  4270. // region 3
  4271. s0 = 0;
  4272. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4273. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4274. } else {
  4275. // region 2
  4276. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4277. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4278. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4279. }
  4280. }
  4281. } else {
  4282. // Ray and segment are parallel.
  4283. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4284. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4285. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4286. }
  4287. if ( optionalPointOnRay ) {
  4288. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4289. }
  4290. if ( optionalPointOnSegment ) {
  4291. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  4292. }
  4293. return sqrDist;
  4294. };
  4295. }(),
  4296. intersectSphere: function () {
  4297. var v1 = new Vector3();
  4298. return function intersectSphere( sphere, target ) {
  4299. v1.subVectors( sphere.center, this.origin );
  4300. var tca = v1.dot( this.direction );
  4301. var d2 = v1.dot( v1 ) - tca * tca;
  4302. var radius2 = sphere.radius * sphere.radius;
  4303. if ( d2 > radius2 ) return null;
  4304. var thc = Math.sqrt( radius2 - d2 );
  4305. // t0 = first intersect point - entrance on front of sphere
  4306. var t0 = tca - thc;
  4307. // t1 = second intersect point - exit point on back of sphere
  4308. var t1 = tca + thc;
  4309. // test to see if both t0 and t1 are behind the ray - if so, return null
  4310. if ( t0 < 0 && t1 < 0 ) return null;
  4311. // test to see if t0 is behind the ray:
  4312. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4313. // in order to always return an intersect point that is in front of the ray.
  4314. if ( t0 < 0 ) return this.at( t1, target );
  4315. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4316. return this.at( t0, target );
  4317. };
  4318. }(),
  4319. intersectsSphere: function ( sphere ) {
  4320. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4321. },
  4322. distanceToPlane: function ( plane ) {
  4323. var denominator = plane.normal.dot( this.direction );
  4324. if ( denominator === 0 ) {
  4325. // line is coplanar, return origin
  4326. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4327. return 0;
  4328. }
  4329. // Null is preferable to undefined since undefined means.... it is undefined
  4330. return null;
  4331. }
  4332. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4333. // Return if the ray never intersects the plane
  4334. return t >= 0 ? t : null;
  4335. },
  4336. intersectPlane: function ( plane, target ) {
  4337. var t = this.distanceToPlane( plane );
  4338. if ( t === null ) {
  4339. return null;
  4340. }
  4341. return this.at( t, target );
  4342. },
  4343. intersectsPlane: function ( plane ) {
  4344. // check if the ray lies on the plane first
  4345. var distToPoint = plane.distanceToPoint( this.origin );
  4346. if ( distToPoint === 0 ) {
  4347. return true;
  4348. }
  4349. var denominator = plane.normal.dot( this.direction );
  4350. if ( denominator * distToPoint < 0 ) {
  4351. return true;
  4352. }
  4353. // ray origin is behind the plane (and is pointing behind it)
  4354. return false;
  4355. },
  4356. intersectBox: function ( box, target ) {
  4357. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4358. var invdirx = 1 / this.direction.x,
  4359. invdiry = 1 / this.direction.y,
  4360. invdirz = 1 / this.direction.z;
  4361. var origin = this.origin;
  4362. if ( invdirx >= 0 ) {
  4363. tmin = ( box.min.x - origin.x ) * invdirx;
  4364. tmax = ( box.max.x - origin.x ) * invdirx;
  4365. } else {
  4366. tmin = ( box.max.x - origin.x ) * invdirx;
  4367. tmax = ( box.min.x - origin.x ) * invdirx;
  4368. }
  4369. if ( invdiry >= 0 ) {
  4370. tymin = ( box.min.y - origin.y ) * invdiry;
  4371. tymax = ( box.max.y - origin.y ) * invdiry;
  4372. } else {
  4373. tymin = ( box.max.y - origin.y ) * invdiry;
  4374. tymax = ( box.min.y - origin.y ) * invdiry;
  4375. }
  4376. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4377. // These lines also handle the case where tmin or tmax is NaN
  4378. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4379. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4380. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4381. if ( invdirz >= 0 ) {
  4382. tzmin = ( box.min.z - origin.z ) * invdirz;
  4383. tzmax = ( box.max.z - origin.z ) * invdirz;
  4384. } else {
  4385. tzmin = ( box.max.z - origin.z ) * invdirz;
  4386. tzmax = ( box.min.z - origin.z ) * invdirz;
  4387. }
  4388. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4389. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4390. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4391. //return point closest to the ray (positive side)
  4392. if ( tmax < 0 ) return null;
  4393. return this.at( tmin >= 0 ? tmin : tmax, target );
  4394. },
  4395. intersectsBox: ( function () {
  4396. var v = new Vector3();
  4397. return function intersectsBox( box ) {
  4398. return this.intersectBox( box, v ) !== null;
  4399. };
  4400. } )(),
  4401. intersectTriangle: function () {
  4402. // Compute the offset origin, edges, and normal.
  4403. var diff = new Vector3();
  4404. var edge1 = new Vector3();
  4405. var edge2 = new Vector3();
  4406. var normal = new Vector3();
  4407. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  4408. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4409. edge1.subVectors( b, a );
  4410. edge2.subVectors( c, a );
  4411. normal.crossVectors( edge1, edge2 );
  4412. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4413. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4414. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4415. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4416. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4417. var DdN = this.direction.dot( normal );
  4418. var sign;
  4419. if ( DdN > 0 ) {
  4420. if ( backfaceCulling ) return null;
  4421. sign = 1;
  4422. } else if ( DdN < 0 ) {
  4423. sign = - 1;
  4424. DdN = - DdN;
  4425. } else {
  4426. return null;
  4427. }
  4428. diff.subVectors( this.origin, a );
  4429. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  4430. // b1 < 0, no intersection
  4431. if ( DdQxE2 < 0 ) {
  4432. return null;
  4433. }
  4434. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  4435. // b2 < 0, no intersection
  4436. if ( DdE1xQ < 0 ) {
  4437. return null;
  4438. }
  4439. // b1+b2 > 1, no intersection
  4440. if ( DdQxE2 + DdE1xQ > DdN ) {
  4441. return null;
  4442. }
  4443. // Line intersects triangle, check if ray does.
  4444. var QdN = - sign * diff.dot( normal );
  4445. // t < 0, no intersection
  4446. if ( QdN < 0 ) {
  4447. return null;
  4448. }
  4449. // Ray intersects triangle.
  4450. return this.at( QdN / DdN, target );
  4451. };
  4452. }(),
  4453. applyMatrix4: function ( matrix4 ) {
  4454. this.origin.applyMatrix4( matrix4 );
  4455. this.direction.transformDirection( matrix4 );
  4456. return this;
  4457. },
  4458. equals: function ( ray ) {
  4459. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4460. }
  4461. } );
  4462. /**
  4463. * @author bhouston / http://clara.io
  4464. * @author mrdoob / http://mrdoob.com/
  4465. */
  4466. function Triangle( a, b, c ) {
  4467. this.a = ( a !== undefined ) ? a : new Vector3();
  4468. this.b = ( b !== undefined ) ? b : new Vector3();
  4469. this.c = ( c !== undefined ) ? c : new Vector3();
  4470. }
  4471. Object.assign( Triangle, {
  4472. getNormal: function () {
  4473. var v0 = new Vector3();
  4474. return function getNormal( a, b, c, target ) {
  4475. if ( target === undefined ) {
  4476. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4477. target = new Vector3();
  4478. }
  4479. target.subVectors( c, b );
  4480. v0.subVectors( a, b );
  4481. target.cross( v0 );
  4482. var targetLengthSq = target.lengthSq();
  4483. if ( targetLengthSq > 0 ) {
  4484. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4485. }
  4486. return target.set( 0, 0, 0 );
  4487. };
  4488. }(),
  4489. // static/instance method to calculate barycentric coordinates
  4490. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4491. getBarycoord: function () {
  4492. var v0 = new Vector3();
  4493. var v1 = new Vector3();
  4494. var v2 = new Vector3();
  4495. return function getBarycoord( point, a, b, c, target ) {
  4496. v0.subVectors( c, a );
  4497. v1.subVectors( b, a );
  4498. v2.subVectors( point, a );
  4499. var dot00 = v0.dot( v0 );
  4500. var dot01 = v0.dot( v1 );
  4501. var dot02 = v0.dot( v2 );
  4502. var dot11 = v1.dot( v1 );
  4503. var dot12 = v1.dot( v2 );
  4504. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4505. if ( target === undefined ) {
  4506. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4507. target = new Vector3();
  4508. }
  4509. // collinear or singular triangle
  4510. if ( denom === 0 ) {
  4511. // arbitrary location outside of triangle?
  4512. // not sure if this is the best idea, maybe should be returning undefined
  4513. return target.set( - 2, - 1, - 1 );
  4514. }
  4515. var invDenom = 1 / denom;
  4516. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4517. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4518. // barycentric coordinates must always sum to 1
  4519. return target.set( 1 - u - v, v, u );
  4520. };
  4521. }(),
  4522. containsPoint: function () {
  4523. var v1 = new Vector3();
  4524. return function containsPoint( point, a, b, c ) {
  4525. Triangle.getBarycoord( point, a, b, c, v1 );
  4526. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  4527. };
  4528. }(),
  4529. getUV: function () {
  4530. var barycoord = new Vector3();
  4531. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4532. this.getBarycoord( point, p1, p2, p3, barycoord );
  4533. target.set( 0, 0 );
  4534. target.addScaledVector( uv1, barycoord.x );
  4535. target.addScaledVector( uv2, barycoord.y );
  4536. target.addScaledVector( uv3, barycoord.z );
  4537. return target;
  4538. };
  4539. }(),
  4540. isFrontFacing: function () {
  4541. var v0 = new Vector3();
  4542. var v1 = new Vector3();
  4543. return function isFrontFacing( a, b, c, direction ) {
  4544. v0.subVectors( c, b );
  4545. v1.subVectors( a, b );
  4546. // strictly front facing
  4547. return ( v0.cross( v1 ).dot( direction ) < 0 ) ? true : false;
  4548. };
  4549. }()
  4550. } );
  4551. Object.assign( Triangle.prototype, {
  4552. set: function ( a, b, c ) {
  4553. this.a.copy( a );
  4554. this.b.copy( b );
  4555. this.c.copy( c );
  4556. return this;
  4557. },
  4558. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4559. this.a.copy( points[ i0 ] );
  4560. this.b.copy( points[ i1 ] );
  4561. this.c.copy( points[ i2 ] );
  4562. return this;
  4563. },
  4564. clone: function () {
  4565. return new this.constructor().copy( this );
  4566. },
  4567. copy: function ( triangle ) {
  4568. this.a.copy( triangle.a );
  4569. this.b.copy( triangle.b );
  4570. this.c.copy( triangle.c );
  4571. return this;
  4572. },
  4573. getArea: function () {
  4574. var v0 = new Vector3();
  4575. var v1 = new Vector3();
  4576. return function getArea() {
  4577. v0.subVectors( this.c, this.b );
  4578. v1.subVectors( this.a, this.b );
  4579. return v0.cross( v1 ).length() * 0.5;
  4580. };
  4581. }(),
  4582. getMidpoint: function ( target ) {
  4583. if ( target === undefined ) {
  4584. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4585. target = new Vector3();
  4586. }
  4587. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4588. },
  4589. getNormal: function ( target ) {
  4590. return Triangle.getNormal( this.a, this.b, this.c, target );
  4591. },
  4592. getPlane: function ( target ) {
  4593. if ( target === undefined ) {
  4594. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4595. target = new Vector3();
  4596. }
  4597. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4598. },
  4599. getBarycoord: function ( point, target ) {
  4600. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4601. },
  4602. getUV: function ( point, uv1, uv2, uv3, target ) {
  4603. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4604. },
  4605. containsPoint: function ( point ) {
  4606. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4607. },
  4608. isFrontFacing: function ( direction ) {
  4609. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4610. },
  4611. intersectsBox: function ( box ) {
  4612. return box.intersectsTriangle( this );
  4613. },
  4614. closestPointToPoint: function () {
  4615. var vab = new Vector3();
  4616. var vac = new Vector3();
  4617. var vbc = new Vector3();
  4618. var vap = new Vector3();
  4619. var vbp = new Vector3();
  4620. var vcp = new Vector3();
  4621. return function closestPointToPoint( p, target ) {
  4622. if ( target === undefined ) {
  4623. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4624. target = new Vector3();
  4625. }
  4626. var a = this.a, b = this.b, c = this.c;
  4627. var v, w;
  4628. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4629. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4630. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4631. // basically, we're distinguishing which of the voronoi regions of the triangle
  4632. // the point lies in with the minimum amount of redundant computation.
  4633. vab.subVectors( b, a );
  4634. vac.subVectors( c, a );
  4635. vap.subVectors( p, a );
  4636. var d1 = vab.dot( vap );
  4637. var d2 = vac.dot( vap );
  4638. if ( d1 <= 0 && d2 <= 0 ) {
  4639. // vertex region of A; barycentric coords (1, 0, 0)
  4640. return target.copy( a );
  4641. }
  4642. vbp.subVectors( p, b );
  4643. var d3 = vab.dot( vbp );
  4644. var d4 = vac.dot( vbp );
  4645. if ( d3 >= 0 && d4 <= d3 ) {
  4646. // vertex region of B; barycentric coords (0, 1, 0)
  4647. return target.copy( b );
  4648. }
  4649. var vc = d1 * d4 - d3 * d2;
  4650. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4651. v = d1 / ( d1 - d3 );
  4652. // edge region of AB; barycentric coords (1-v, v, 0)
  4653. return target.copy( a ).addScaledVector( vab, v );
  4654. }
  4655. vcp.subVectors( p, c );
  4656. var d5 = vab.dot( vcp );
  4657. var d6 = vac.dot( vcp );
  4658. if ( d6 >= 0 && d5 <= d6 ) {
  4659. // vertex region of C; barycentric coords (0, 0, 1)
  4660. return target.copy( c );
  4661. }
  4662. var vb = d5 * d2 - d1 * d6;
  4663. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4664. w = d2 / ( d2 - d6 );
  4665. // edge region of AC; barycentric coords (1-w, 0, w)
  4666. return target.copy( a ).addScaledVector( vac, w );
  4667. }
  4668. var va = d3 * d6 - d5 * d4;
  4669. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4670. vbc.subVectors( c, b );
  4671. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4672. // edge region of BC; barycentric coords (0, 1-w, w)
  4673. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  4674. }
  4675. // face region
  4676. var denom = 1 / ( va + vb + vc );
  4677. // u = va * denom
  4678. v = vb * denom;
  4679. w = vc * denom;
  4680. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  4681. };
  4682. }(),
  4683. equals: function ( triangle ) {
  4684. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4685. }
  4686. } );
  4687. /**
  4688. * @author mrdoob / http://mrdoob.com/
  4689. */
  4690. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4691. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4692. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4693. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4694. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4695. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4696. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4697. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4698. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4699. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4700. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4701. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4702. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4703. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4704. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4705. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4706. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4707. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4708. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4709. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4710. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4711. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4712. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4713. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4714. function Color( r, g, b ) {
  4715. if ( g === undefined && b === undefined ) {
  4716. // r is THREE.Color, hex or string
  4717. return this.set( r );
  4718. }
  4719. return this.setRGB( r, g, b );
  4720. }
  4721. function hue2rgb( p, q, t ) {
  4722. if ( t < 0 ) t += 1;
  4723. if ( t > 1 ) t -= 1;
  4724. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4725. if ( t < 1 / 2 ) return q;
  4726. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4727. return p;
  4728. }
  4729. function SRGBToLinear( c ) {
  4730. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4731. }
  4732. function LinearToSRGB( c ) {
  4733. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4734. }
  4735. Object.assign( Color.prototype, {
  4736. isColor: true,
  4737. r: 1, g: 1, b: 1,
  4738. set: function ( value ) {
  4739. if ( value && value.isColor ) {
  4740. this.copy( value );
  4741. } else if ( typeof value === 'number' ) {
  4742. this.setHex( value );
  4743. } else if ( typeof value === 'string' ) {
  4744. this.setStyle( value );
  4745. }
  4746. return this;
  4747. },
  4748. setScalar: function ( scalar ) {
  4749. this.r = scalar;
  4750. this.g = scalar;
  4751. this.b = scalar;
  4752. return this;
  4753. },
  4754. setHex: function ( hex ) {
  4755. hex = Math.floor( hex );
  4756. this.r = ( hex >> 16 & 255 ) / 255;
  4757. this.g = ( hex >> 8 & 255 ) / 255;
  4758. this.b = ( hex & 255 ) / 255;
  4759. return this;
  4760. },
  4761. setRGB: function ( r, g, b ) {
  4762. this.r = r;
  4763. this.g = g;
  4764. this.b = b;
  4765. return this;
  4766. },
  4767. setHSL: function ( h, s, l ) {
  4768. // h,s,l ranges are in 0.0 - 1.0
  4769. h = _Math.euclideanModulo( h, 1 );
  4770. s = _Math.clamp( s, 0, 1 );
  4771. l = _Math.clamp( l, 0, 1 );
  4772. if ( s === 0 ) {
  4773. this.r = this.g = this.b = l;
  4774. } else {
  4775. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4776. var q = ( 2 * l ) - p;
  4777. this.r = hue2rgb( q, p, h + 1 / 3 );
  4778. this.g = hue2rgb( q, p, h );
  4779. this.b = hue2rgb( q, p, h - 1 / 3 );
  4780. }
  4781. return this;
  4782. },
  4783. setStyle: function ( style ) {
  4784. function handleAlpha( string ) {
  4785. if ( string === undefined ) return;
  4786. if ( parseFloat( string ) < 1 ) {
  4787. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4788. }
  4789. }
  4790. var m;
  4791. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4792. // rgb / hsl
  4793. var color;
  4794. var name = m[ 1 ];
  4795. var components = m[ 2 ];
  4796. switch ( name ) {
  4797. case 'rgb':
  4798. case 'rgba':
  4799. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4800. // rgb(255,0,0) rgba(255,0,0,0.5)
  4801. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4802. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4803. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4804. handleAlpha( color[ 5 ] );
  4805. return this;
  4806. }
  4807. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4808. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4809. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4810. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4811. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4812. handleAlpha( color[ 5 ] );
  4813. return this;
  4814. }
  4815. break;
  4816. case 'hsl':
  4817. case 'hsla':
  4818. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4819. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4820. var h = parseFloat( color[ 1 ] ) / 360;
  4821. var s = parseInt( color[ 2 ], 10 ) / 100;
  4822. var l = parseInt( color[ 3 ], 10 ) / 100;
  4823. handleAlpha( color[ 5 ] );
  4824. return this.setHSL( h, s, l );
  4825. }
  4826. break;
  4827. }
  4828. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4829. // hex color
  4830. var hex = m[ 1 ];
  4831. var size = hex.length;
  4832. if ( size === 3 ) {
  4833. // #ff0
  4834. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4835. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4836. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4837. return this;
  4838. } else if ( size === 6 ) {
  4839. // #ff0000
  4840. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4841. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4842. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4843. return this;
  4844. }
  4845. }
  4846. if ( style && style.length > 0 ) {
  4847. // color keywords
  4848. var hex = ColorKeywords[ style ];
  4849. if ( hex !== undefined ) {
  4850. // red
  4851. this.setHex( hex );
  4852. } else {
  4853. // unknown color
  4854. console.warn( 'THREE.Color: Unknown color ' + style );
  4855. }
  4856. }
  4857. return this;
  4858. },
  4859. clone: function () {
  4860. return new this.constructor( this.r, this.g, this.b );
  4861. },
  4862. copy: function ( color ) {
  4863. this.r = color.r;
  4864. this.g = color.g;
  4865. this.b = color.b;
  4866. return this;
  4867. },
  4868. copyGammaToLinear: function ( color, gammaFactor ) {
  4869. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4870. this.r = Math.pow( color.r, gammaFactor );
  4871. this.g = Math.pow( color.g, gammaFactor );
  4872. this.b = Math.pow( color.b, gammaFactor );
  4873. return this;
  4874. },
  4875. copyLinearToGamma: function ( color, gammaFactor ) {
  4876. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4877. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4878. this.r = Math.pow( color.r, safeInverse );
  4879. this.g = Math.pow( color.g, safeInverse );
  4880. this.b = Math.pow( color.b, safeInverse );
  4881. return this;
  4882. },
  4883. convertGammaToLinear: function ( gammaFactor ) {
  4884. this.copyGammaToLinear( this, gammaFactor );
  4885. return this;
  4886. },
  4887. convertLinearToGamma: function ( gammaFactor ) {
  4888. this.copyLinearToGamma( this, gammaFactor );
  4889. return this;
  4890. },
  4891. copySRGBToLinear: function ( color ) {
  4892. this.r = SRGBToLinear( color.r );
  4893. this.g = SRGBToLinear( color.g );
  4894. this.b = SRGBToLinear( color.b );
  4895. return this;
  4896. },
  4897. copyLinearToSRGB: function ( color ) {
  4898. this.r = LinearToSRGB( color.r );
  4899. this.g = LinearToSRGB( color.g );
  4900. this.b = LinearToSRGB( color.b );
  4901. return this;
  4902. },
  4903. convertSRGBToLinear: function () {
  4904. this.copySRGBToLinear( this );
  4905. return this;
  4906. },
  4907. convertLinearToSRGB: function () {
  4908. this.copyLinearToSRGB( this );
  4909. return this;
  4910. },
  4911. getHex: function () {
  4912. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4913. },
  4914. getHexString: function () {
  4915. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4916. },
  4917. getHSL: function ( target ) {
  4918. // h,s,l ranges are in 0.0 - 1.0
  4919. if ( target === undefined ) {
  4920. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4921. target = { h: 0, s: 0, l: 0 };
  4922. }
  4923. var r = this.r, g = this.g, b = this.b;
  4924. var max = Math.max( r, g, b );
  4925. var min = Math.min( r, g, b );
  4926. var hue, saturation;
  4927. var lightness = ( min + max ) / 2.0;
  4928. if ( min === max ) {
  4929. hue = 0;
  4930. saturation = 0;
  4931. } else {
  4932. var delta = max - min;
  4933. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4934. switch ( max ) {
  4935. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4936. case g: hue = ( b - r ) / delta + 2; break;
  4937. case b: hue = ( r - g ) / delta + 4; break;
  4938. }
  4939. hue /= 6;
  4940. }
  4941. target.h = hue;
  4942. target.s = saturation;
  4943. target.l = lightness;
  4944. return target;
  4945. },
  4946. getStyle: function () {
  4947. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4948. },
  4949. offsetHSL: function () {
  4950. var hsl = {};
  4951. return function ( h, s, l ) {
  4952. this.getHSL( hsl );
  4953. hsl.h += h; hsl.s += s; hsl.l += l;
  4954. this.setHSL( hsl.h, hsl.s, hsl.l );
  4955. return this;
  4956. };
  4957. }(),
  4958. add: function ( color ) {
  4959. this.r += color.r;
  4960. this.g += color.g;
  4961. this.b += color.b;
  4962. return this;
  4963. },
  4964. addColors: function ( color1, color2 ) {
  4965. this.r = color1.r + color2.r;
  4966. this.g = color1.g + color2.g;
  4967. this.b = color1.b + color2.b;
  4968. return this;
  4969. },
  4970. addScalar: function ( s ) {
  4971. this.r += s;
  4972. this.g += s;
  4973. this.b += s;
  4974. return this;
  4975. },
  4976. sub: function ( color ) {
  4977. this.r = Math.max( 0, this.r - color.r );
  4978. this.g = Math.max( 0, this.g - color.g );
  4979. this.b = Math.max( 0, this.b - color.b );
  4980. return this;
  4981. },
  4982. multiply: function ( color ) {
  4983. this.r *= color.r;
  4984. this.g *= color.g;
  4985. this.b *= color.b;
  4986. return this;
  4987. },
  4988. multiplyScalar: function ( s ) {
  4989. this.r *= s;
  4990. this.g *= s;
  4991. this.b *= s;
  4992. return this;
  4993. },
  4994. lerp: function ( color, alpha ) {
  4995. this.r += ( color.r - this.r ) * alpha;
  4996. this.g += ( color.g - this.g ) * alpha;
  4997. this.b += ( color.b - this.b ) * alpha;
  4998. return this;
  4999. },
  5000. lerpHSL: function () {
  5001. var hslA = { h: 0, s: 0, l: 0 };
  5002. var hslB = { h: 0, s: 0, l: 0 };
  5003. return function lerpHSL( color, alpha ) {
  5004. this.getHSL( hslA );
  5005. color.getHSL( hslB );
  5006. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  5007. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  5008. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  5009. this.setHSL( h, s, l );
  5010. return this;
  5011. };
  5012. }(),
  5013. equals: function ( c ) {
  5014. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5015. },
  5016. fromArray: function ( array, offset ) {
  5017. if ( offset === undefined ) offset = 0;
  5018. this.r = array[ offset ];
  5019. this.g = array[ offset + 1 ];
  5020. this.b = array[ offset + 2 ];
  5021. return this;
  5022. },
  5023. toArray: function ( array, offset ) {
  5024. if ( array === undefined ) array = [];
  5025. if ( offset === undefined ) offset = 0;
  5026. array[ offset ] = this.r;
  5027. array[ offset + 1 ] = this.g;
  5028. array[ offset + 2 ] = this.b;
  5029. return array;
  5030. },
  5031. toJSON: function () {
  5032. return this.getHex();
  5033. }
  5034. } );
  5035. /**
  5036. * @author mrdoob / http://mrdoob.com/
  5037. * @author alteredq / http://alteredqualia.com/
  5038. */
  5039. function Face3( a, b, c, normal, color, materialIndex ) {
  5040. this.a = a;
  5041. this.b = b;
  5042. this.c = c;
  5043. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5044. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5045. this.color = ( color && color.isColor ) ? color : new Color();
  5046. this.vertexColors = Array.isArray( color ) ? color : [];
  5047. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5048. }
  5049. Object.assign( Face3.prototype, {
  5050. clone: function () {
  5051. return new this.constructor().copy( this );
  5052. },
  5053. copy: function ( source ) {
  5054. this.a = source.a;
  5055. this.b = source.b;
  5056. this.c = source.c;
  5057. this.normal.copy( source.normal );
  5058. this.color.copy( source.color );
  5059. this.materialIndex = source.materialIndex;
  5060. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5061. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5062. }
  5063. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5064. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5065. }
  5066. return this;
  5067. }
  5068. } );
  5069. /**
  5070. * @author mrdoob / http://mrdoob.com/
  5071. * @author alteredq / http://alteredqualia.com/
  5072. */
  5073. var materialId = 0;
  5074. function Material() {
  5075. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5076. this.uuid = _Math.generateUUID();
  5077. this.name = '';
  5078. this.type = 'Material';
  5079. this.fog = true;
  5080. this.lights = true;
  5081. this.blending = NormalBlending;
  5082. this.side = FrontSide;
  5083. this.flatShading = false;
  5084. this.vertexTangents = false;
  5085. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  5086. this.opacity = 1;
  5087. this.transparent = false;
  5088. this.blendSrc = SrcAlphaFactor;
  5089. this.blendDst = OneMinusSrcAlphaFactor;
  5090. this.blendEquation = AddEquation;
  5091. this.blendSrcAlpha = null;
  5092. this.blendDstAlpha = null;
  5093. this.blendEquationAlpha = null;
  5094. this.depthFunc = LessEqualDepth;
  5095. this.depthTest = true;
  5096. this.depthWrite = true;
  5097. this.stencilFunc = AlwaysStencilFunc;
  5098. this.stencilRef = 0;
  5099. this.stencilMask = 0xff;
  5100. this.stencilFail = KeepStencilOp;
  5101. this.stencilZFail = KeepStencilOp;
  5102. this.stencilZPass = KeepStencilOp;
  5103. this.stencilWrite = false;
  5104. this.clippingPlanes = null;
  5105. this.clipIntersection = false;
  5106. this.clipShadows = false;
  5107. this.shadowSide = null;
  5108. this.colorWrite = true;
  5109. this.precision = null; // override the renderer's default precision for this material
  5110. this.polygonOffset = false;
  5111. this.polygonOffsetFactor = 0;
  5112. this.polygonOffsetUnits = 0;
  5113. this.dithering = false;
  5114. this.alphaTest = 0;
  5115. this.premultipliedAlpha = false;
  5116. this.visible = true;
  5117. this.userData = {};
  5118. this.needsUpdate = true;
  5119. }
  5120. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5121. constructor: Material,
  5122. isMaterial: true,
  5123. onBeforeCompile: function () {},
  5124. setValues: function ( values ) {
  5125. if ( values === undefined ) return;
  5126. for ( var key in values ) {
  5127. var newValue = values[ key ];
  5128. if ( newValue === undefined ) {
  5129. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5130. continue;
  5131. }
  5132. // for backward compatability if shading is set in the constructor
  5133. if ( key === 'shading' ) {
  5134. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5135. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5136. continue;
  5137. }
  5138. var currentValue = this[ key ];
  5139. if ( currentValue === undefined ) {
  5140. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5141. continue;
  5142. }
  5143. if ( currentValue && currentValue.isColor ) {
  5144. currentValue.set( newValue );
  5145. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5146. currentValue.copy( newValue );
  5147. } else {
  5148. this[ key ] = newValue;
  5149. }
  5150. }
  5151. },
  5152. toJSON: function ( meta ) {
  5153. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5154. if ( isRoot ) {
  5155. meta = {
  5156. textures: {},
  5157. images: {}
  5158. };
  5159. }
  5160. var data = {
  5161. metadata: {
  5162. version: 4.5,
  5163. type: 'Material',
  5164. generator: 'Material.toJSON'
  5165. }
  5166. };
  5167. // standard Material serialization
  5168. data.uuid = this.uuid;
  5169. data.type = this.type;
  5170. if ( this.name !== '' ) data.name = this.name;
  5171. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5172. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5173. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5174. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5175. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5176. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5177. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5178. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  5179. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  5180. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5181. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5182. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5183. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5184. if ( this.aoMap && this.aoMap.isTexture ) {
  5185. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5186. data.aoMapIntensity = this.aoMapIntensity;
  5187. }
  5188. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5189. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5190. data.bumpScale = this.bumpScale;
  5191. }
  5192. if ( this.normalMap && this.normalMap.isTexture ) {
  5193. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5194. data.normalMapType = this.normalMapType;
  5195. data.normalScale = this.normalScale.toArray();
  5196. }
  5197. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5198. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5199. data.displacementScale = this.displacementScale;
  5200. data.displacementBias = this.displacementBias;
  5201. }
  5202. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5203. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5204. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5205. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5206. if ( this.envMap && this.envMap.isTexture ) {
  5207. data.envMap = this.envMap.toJSON( meta ).uuid;
  5208. data.reflectivity = this.reflectivity; // Scale behind envMap
  5209. data.refractionRatio = this.refractionRatio;
  5210. if ( this.combine !== undefined ) data.combine = this.combine;
  5211. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5212. }
  5213. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5214. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5215. }
  5216. if ( this.size !== undefined ) data.size = this.size;
  5217. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5218. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5219. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5220. if ( this.side !== FrontSide ) data.side = this.side;
  5221. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  5222. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5223. if ( this.transparent === true ) data.transparent = this.transparent;
  5224. data.depthFunc = this.depthFunc;
  5225. data.depthTest = this.depthTest;
  5226. data.depthWrite = this.depthWrite;
  5227. data.stencilWrite = this.stencilWrite;
  5228. data.stencilFunc = this.stencilFunc;
  5229. data.stencilRef = this.stencilRef;
  5230. data.stencilMask = this.stencilMask;
  5231. data.stencilFail = this.stencilFail;
  5232. data.stencilZFail = this.stencilZFail;
  5233. data.stencilZPass = this.stencilZPass;
  5234. // rotation (SpriteMaterial)
  5235. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5236. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5237. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5238. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5239. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5240. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5241. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5242. if ( this.scale !== undefined ) data.scale = this.scale;
  5243. if ( this.dithering === true ) data.dithering = true;
  5244. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5245. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5246. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5247. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5248. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5249. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5250. if ( this.morphTargets === true ) data.morphTargets = true;
  5251. if ( this.morphNormals === true ) data.morphNormals = true;
  5252. if ( this.skinning === true ) data.skinning = true;
  5253. if ( this.visible === false ) data.visible = false;
  5254. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5255. // TODO: Copied from Object3D.toJSON
  5256. function extractFromCache( cache ) {
  5257. var values = [];
  5258. for ( var key in cache ) {
  5259. var data = cache[ key ];
  5260. delete data.metadata;
  5261. values.push( data );
  5262. }
  5263. return values;
  5264. }
  5265. if ( isRoot ) {
  5266. var textures = extractFromCache( meta.textures );
  5267. var images = extractFromCache( meta.images );
  5268. if ( textures.length > 0 ) data.textures = textures;
  5269. if ( images.length > 0 ) data.images = images;
  5270. }
  5271. return data;
  5272. },
  5273. clone: function () {
  5274. return new this.constructor().copy( this );
  5275. },
  5276. copy: function ( source ) {
  5277. this.name = source.name;
  5278. this.fog = source.fog;
  5279. this.lights = source.lights;
  5280. this.blending = source.blending;
  5281. this.side = source.side;
  5282. this.flatShading = source.flatShading;
  5283. this.vertexColors = source.vertexColors;
  5284. this.opacity = source.opacity;
  5285. this.transparent = source.transparent;
  5286. this.blendSrc = source.blendSrc;
  5287. this.blendDst = source.blendDst;
  5288. this.blendEquation = source.blendEquation;
  5289. this.blendSrcAlpha = source.blendSrcAlpha;
  5290. this.blendDstAlpha = source.blendDstAlpha;
  5291. this.blendEquationAlpha = source.blendEquationAlpha;
  5292. this.depthFunc = source.depthFunc;
  5293. this.depthTest = source.depthTest;
  5294. this.depthWrite = source.depthWrite;
  5295. this.stencilWrite = source.stencilWrite;
  5296. this.stencilFunc = source.stencilFunc;
  5297. this.stencilRef = source.stencilRef;
  5298. this.stencilMask = source.stencilMask;
  5299. this.stencilFail = source.stencilFail;
  5300. this.stencilZFail = source.stencilZFail;
  5301. this.stencilZPass = source.stencilZPass;
  5302. this.colorWrite = source.colorWrite;
  5303. this.precision = source.precision;
  5304. this.polygonOffset = source.polygonOffset;
  5305. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5306. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5307. this.dithering = source.dithering;
  5308. this.alphaTest = source.alphaTest;
  5309. this.premultipliedAlpha = source.premultipliedAlpha;
  5310. this.visible = source.visible;
  5311. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5312. this.clipShadows = source.clipShadows;
  5313. this.clipIntersection = source.clipIntersection;
  5314. var srcPlanes = source.clippingPlanes,
  5315. dstPlanes = null;
  5316. if ( srcPlanes !== null ) {
  5317. var n = srcPlanes.length;
  5318. dstPlanes = new Array( n );
  5319. for ( var i = 0; i !== n; ++ i )
  5320. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5321. }
  5322. this.clippingPlanes = dstPlanes;
  5323. this.shadowSide = source.shadowSide;
  5324. return this;
  5325. },
  5326. dispose: function () {
  5327. this.dispatchEvent( { type: 'dispose' } );
  5328. }
  5329. } );
  5330. /**
  5331. * @author mrdoob / http://mrdoob.com/
  5332. * @author alteredq / http://alteredqualia.com/
  5333. *
  5334. * parameters = {
  5335. * color: <hex>,
  5336. * opacity: <float>,
  5337. * map: new THREE.Texture( <Image> ),
  5338. *
  5339. * lightMap: new THREE.Texture( <Image> ),
  5340. * lightMapIntensity: <float>
  5341. *
  5342. * aoMap: new THREE.Texture( <Image> ),
  5343. * aoMapIntensity: <float>
  5344. *
  5345. * specularMap: new THREE.Texture( <Image> ),
  5346. *
  5347. * alphaMap: new THREE.Texture( <Image> ),
  5348. *
  5349. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5350. * combine: THREE.Multiply,
  5351. * reflectivity: <float>,
  5352. * refractionRatio: <float>,
  5353. *
  5354. * depthTest: <bool>,
  5355. * depthWrite: <bool>,
  5356. *
  5357. * wireframe: <boolean>,
  5358. * wireframeLinewidth: <float>,
  5359. *
  5360. * skinning: <bool>,
  5361. * morphTargets: <bool>
  5362. * }
  5363. */
  5364. function MeshBasicMaterial( parameters ) {
  5365. Material.call( this );
  5366. this.type = 'MeshBasicMaterial';
  5367. this.color = new Color( 0xffffff ); // emissive
  5368. this.map = null;
  5369. this.lightMap = null;
  5370. this.lightMapIntensity = 1.0;
  5371. this.aoMap = null;
  5372. this.aoMapIntensity = 1.0;
  5373. this.specularMap = null;
  5374. this.alphaMap = null;
  5375. this.envMap = null;
  5376. this.combine = MultiplyOperation;
  5377. this.reflectivity = 1;
  5378. this.refractionRatio = 0.98;
  5379. this.wireframe = false;
  5380. this.wireframeLinewidth = 1;
  5381. this.wireframeLinecap = 'round';
  5382. this.wireframeLinejoin = 'round';
  5383. this.skinning = false;
  5384. this.morphTargets = false;
  5385. this.lights = false;
  5386. this.setValues( parameters );
  5387. }
  5388. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5389. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5390. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5391. MeshBasicMaterial.prototype.copy = function ( source ) {
  5392. Material.prototype.copy.call( this, source );
  5393. this.color.copy( source.color );
  5394. this.map = source.map;
  5395. this.lightMap = source.lightMap;
  5396. this.lightMapIntensity = source.lightMapIntensity;
  5397. this.aoMap = source.aoMap;
  5398. this.aoMapIntensity = source.aoMapIntensity;
  5399. this.specularMap = source.specularMap;
  5400. this.alphaMap = source.alphaMap;
  5401. this.envMap = source.envMap;
  5402. this.combine = source.combine;
  5403. this.reflectivity = source.reflectivity;
  5404. this.refractionRatio = source.refractionRatio;
  5405. this.wireframe = source.wireframe;
  5406. this.wireframeLinewidth = source.wireframeLinewidth;
  5407. this.wireframeLinecap = source.wireframeLinecap;
  5408. this.wireframeLinejoin = source.wireframeLinejoin;
  5409. this.skinning = source.skinning;
  5410. this.morphTargets = source.morphTargets;
  5411. return this;
  5412. };
  5413. /**
  5414. * @author mrdoob / http://mrdoob.com/
  5415. */
  5416. function BufferAttribute( array, itemSize, normalized ) {
  5417. if ( Array.isArray( array ) ) {
  5418. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5419. }
  5420. this.name = '';
  5421. this.array = array;
  5422. this.itemSize = itemSize;
  5423. this.count = array !== undefined ? array.length / itemSize : 0;
  5424. this.normalized = normalized === true;
  5425. this.dynamic = false;
  5426. this.updateRange = { offset: 0, count: - 1 };
  5427. this.version = 0;
  5428. }
  5429. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5430. set: function ( value ) {
  5431. if ( value === true ) this.version ++;
  5432. }
  5433. } );
  5434. Object.assign( BufferAttribute.prototype, {
  5435. isBufferAttribute: true,
  5436. onUploadCallback: function () {},
  5437. setArray: function ( array ) {
  5438. if ( Array.isArray( array ) ) {
  5439. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5440. }
  5441. this.count = array !== undefined ? array.length / this.itemSize : 0;
  5442. this.array = array;
  5443. return this;
  5444. },
  5445. setDynamic: function ( value ) {
  5446. this.dynamic = value;
  5447. return this;
  5448. },
  5449. copy: function ( source ) {
  5450. this.name = source.name;
  5451. this.array = new source.array.constructor( source.array );
  5452. this.itemSize = source.itemSize;
  5453. this.count = source.count;
  5454. this.normalized = source.normalized;
  5455. this.dynamic = source.dynamic;
  5456. return this;
  5457. },
  5458. copyAt: function ( index1, attribute, index2 ) {
  5459. index1 *= this.itemSize;
  5460. index2 *= attribute.itemSize;
  5461. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5462. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5463. }
  5464. return this;
  5465. },
  5466. copyArray: function ( array ) {
  5467. this.array.set( array );
  5468. return this;
  5469. },
  5470. copyColorsArray: function ( colors ) {
  5471. var array = this.array, offset = 0;
  5472. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5473. var color = colors[ i ];
  5474. if ( color === undefined ) {
  5475. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5476. color = new Color();
  5477. }
  5478. array[ offset ++ ] = color.r;
  5479. array[ offset ++ ] = color.g;
  5480. array[ offset ++ ] = color.b;
  5481. }
  5482. return this;
  5483. },
  5484. copyVector2sArray: function ( vectors ) {
  5485. var array = this.array, offset = 0;
  5486. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5487. var vector = vectors[ i ];
  5488. if ( vector === undefined ) {
  5489. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5490. vector = new Vector2();
  5491. }
  5492. array[ offset ++ ] = vector.x;
  5493. array[ offset ++ ] = vector.y;
  5494. }
  5495. return this;
  5496. },
  5497. copyVector3sArray: function ( vectors ) {
  5498. var array = this.array, offset = 0;
  5499. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5500. var vector = vectors[ i ];
  5501. if ( vector === undefined ) {
  5502. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5503. vector = new Vector3();
  5504. }
  5505. array[ offset ++ ] = vector.x;
  5506. array[ offset ++ ] = vector.y;
  5507. array[ offset ++ ] = vector.z;
  5508. }
  5509. return this;
  5510. },
  5511. copyVector4sArray: function ( vectors ) {
  5512. var array = this.array, offset = 0;
  5513. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5514. var vector = vectors[ i ];
  5515. if ( vector === undefined ) {
  5516. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5517. vector = new Vector4();
  5518. }
  5519. array[ offset ++ ] = vector.x;
  5520. array[ offset ++ ] = vector.y;
  5521. array[ offset ++ ] = vector.z;
  5522. array[ offset ++ ] = vector.w;
  5523. }
  5524. return this;
  5525. },
  5526. set: function ( value, offset ) {
  5527. if ( offset === undefined ) offset = 0;
  5528. this.array.set( value, offset );
  5529. return this;
  5530. },
  5531. getX: function ( index ) {
  5532. return this.array[ index * this.itemSize ];
  5533. },
  5534. setX: function ( index, x ) {
  5535. this.array[ index * this.itemSize ] = x;
  5536. return this;
  5537. },
  5538. getY: function ( index ) {
  5539. return this.array[ index * this.itemSize + 1 ];
  5540. },
  5541. setY: function ( index, y ) {
  5542. this.array[ index * this.itemSize + 1 ] = y;
  5543. return this;
  5544. },
  5545. getZ: function ( index ) {
  5546. return this.array[ index * this.itemSize + 2 ];
  5547. },
  5548. setZ: function ( index, z ) {
  5549. this.array[ index * this.itemSize + 2 ] = z;
  5550. return this;
  5551. },
  5552. getW: function ( index ) {
  5553. return this.array[ index * this.itemSize + 3 ];
  5554. },
  5555. setW: function ( index, w ) {
  5556. this.array[ index * this.itemSize + 3 ] = w;
  5557. return this;
  5558. },
  5559. setXY: function ( index, x, y ) {
  5560. index *= this.itemSize;
  5561. this.array[ index + 0 ] = x;
  5562. this.array[ index + 1 ] = y;
  5563. return this;
  5564. },
  5565. setXYZ: function ( index, x, y, z ) {
  5566. index *= this.itemSize;
  5567. this.array[ index + 0 ] = x;
  5568. this.array[ index + 1 ] = y;
  5569. this.array[ index + 2 ] = z;
  5570. return this;
  5571. },
  5572. setXYZW: function ( index, x, y, z, w ) {
  5573. index *= this.itemSize;
  5574. this.array[ index + 0 ] = x;
  5575. this.array[ index + 1 ] = y;
  5576. this.array[ index + 2 ] = z;
  5577. this.array[ index + 3 ] = w;
  5578. return this;
  5579. },
  5580. onUpload: function ( callback ) {
  5581. this.onUploadCallback = callback;
  5582. return this;
  5583. },
  5584. clone: function () {
  5585. return new this.constructor( this.array, this.itemSize ).copy( this );
  5586. },
  5587. toJSON: function () {
  5588. return {
  5589. itemSize: this.itemSize,
  5590. type: this.array.constructor.name,
  5591. array: Array.prototype.slice.call( this.array ),
  5592. normalized: this.normalized
  5593. };
  5594. }
  5595. } );
  5596. //
  5597. function Int8BufferAttribute( array, itemSize, normalized ) {
  5598. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5599. }
  5600. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5601. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5602. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5603. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5604. }
  5605. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5606. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5607. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5608. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5609. }
  5610. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5611. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5612. function Int16BufferAttribute( array, itemSize, normalized ) {
  5613. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5614. }
  5615. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5616. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5617. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5618. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5619. }
  5620. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5621. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5622. function Int32BufferAttribute( array, itemSize, normalized ) {
  5623. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5624. }
  5625. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5626. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5627. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5628. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5629. }
  5630. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5631. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5632. function Float32BufferAttribute( array, itemSize, normalized ) {
  5633. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5634. }
  5635. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5636. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5637. function Float64BufferAttribute( array, itemSize, normalized ) {
  5638. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5639. }
  5640. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5641. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5642. /**
  5643. * @author mrdoob / http://mrdoob.com/
  5644. */
  5645. function DirectGeometry() {
  5646. this.vertices = [];
  5647. this.normals = [];
  5648. this.colors = [];
  5649. this.uvs = [];
  5650. this.uvs2 = [];
  5651. this.groups = [];
  5652. this.morphTargets = {};
  5653. this.skinWeights = [];
  5654. this.skinIndices = [];
  5655. // this.lineDistances = [];
  5656. this.boundingBox = null;
  5657. this.boundingSphere = null;
  5658. // update flags
  5659. this.verticesNeedUpdate = false;
  5660. this.normalsNeedUpdate = false;
  5661. this.colorsNeedUpdate = false;
  5662. this.uvsNeedUpdate = false;
  5663. this.groupsNeedUpdate = false;
  5664. }
  5665. Object.assign( DirectGeometry.prototype, {
  5666. computeGroups: function ( geometry ) {
  5667. var group;
  5668. var groups = [];
  5669. var materialIndex = undefined;
  5670. var faces = geometry.faces;
  5671. for ( var i = 0; i < faces.length; i ++ ) {
  5672. var face = faces[ i ];
  5673. // materials
  5674. if ( face.materialIndex !== materialIndex ) {
  5675. materialIndex = face.materialIndex;
  5676. if ( group !== undefined ) {
  5677. group.count = ( i * 3 ) - group.start;
  5678. groups.push( group );
  5679. }
  5680. group = {
  5681. start: i * 3,
  5682. materialIndex: materialIndex
  5683. };
  5684. }
  5685. }
  5686. if ( group !== undefined ) {
  5687. group.count = ( i * 3 ) - group.start;
  5688. groups.push( group );
  5689. }
  5690. this.groups = groups;
  5691. },
  5692. fromGeometry: function ( geometry ) {
  5693. var faces = geometry.faces;
  5694. var vertices = geometry.vertices;
  5695. var faceVertexUvs = geometry.faceVertexUvs;
  5696. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5697. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5698. // morphs
  5699. var morphTargets = geometry.morphTargets;
  5700. var morphTargetsLength = morphTargets.length;
  5701. var morphTargetsPosition;
  5702. if ( morphTargetsLength > 0 ) {
  5703. morphTargetsPosition = [];
  5704. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5705. morphTargetsPosition[ i ] = {
  5706. name: morphTargets[ i ].name,
  5707. data: []
  5708. };
  5709. }
  5710. this.morphTargets.position = morphTargetsPosition;
  5711. }
  5712. var morphNormals = geometry.morphNormals;
  5713. var morphNormalsLength = morphNormals.length;
  5714. var morphTargetsNormal;
  5715. if ( morphNormalsLength > 0 ) {
  5716. morphTargetsNormal = [];
  5717. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5718. morphTargetsNormal[ i ] = {
  5719. name: morphNormals[ i ].name,
  5720. data: []
  5721. };
  5722. }
  5723. this.morphTargets.normal = morphTargetsNormal;
  5724. }
  5725. // skins
  5726. var skinIndices = geometry.skinIndices;
  5727. var skinWeights = geometry.skinWeights;
  5728. var hasSkinIndices = skinIndices.length === vertices.length;
  5729. var hasSkinWeights = skinWeights.length === vertices.length;
  5730. //
  5731. if ( vertices.length > 0 && faces.length === 0 ) {
  5732. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5733. }
  5734. for ( var i = 0; i < faces.length; i ++ ) {
  5735. var face = faces[ i ];
  5736. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5737. var vertexNormals = face.vertexNormals;
  5738. if ( vertexNormals.length === 3 ) {
  5739. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5740. } else {
  5741. var normal = face.normal;
  5742. this.normals.push( normal, normal, normal );
  5743. }
  5744. var vertexColors = face.vertexColors;
  5745. if ( vertexColors.length === 3 ) {
  5746. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5747. } else {
  5748. var color = face.color;
  5749. this.colors.push( color, color, color );
  5750. }
  5751. if ( hasFaceVertexUv === true ) {
  5752. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5753. if ( vertexUvs !== undefined ) {
  5754. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5755. } else {
  5756. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5757. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5758. }
  5759. }
  5760. if ( hasFaceVertexUv2 === true ) {
  5761. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5762. if ( vertexUvs !== undefined ) {
  5763. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5764. } else {
  5765. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5766. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5767. }
  5768. }
  5769. // morphs
  5770. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5771. var morphTarget = morphTargets[ j ].vertices;
  5772. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5773. }
  5774. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5775. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5776. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5777. }
  5778. // skins
  5779. if ( hasSkinIndices ) {
  5780. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5781. }
  5782. if ( hasSkinWeights ) {
  5783. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5784. }
  5785. }
  5786. this.computeGroups( geometry );
  5787. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5788. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5789. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5790. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5791. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5792. if ( geometry.boundingSphere !== null ) {
  5793. this.boundingSphere = geometry.boundingSphere.clone();
  5794. }
  5795. if ( geometry.boundingBox !== null ) {
  5796. this.boundingBox = geometry.boundingBox.clone();
  5797. }
  5798. return this;
  5799. }
  5800. } );
  5801. /**
  5802. * @author mrdoob / http://mrdoob.com/
  5803. */
  5804. function arrayMax( array ) {
  5805. if ( array.length === 0 ) return - Infinity;
  5806. var max = array[ 0 ];
  5807. for ( var i = 1, l = array.length; i < l; ++ i ) {
  5808. if ( array[ i ] > max ) max = array[ i ];
  5809. }
  5810. return max;
  5811. }
  5812. /**
  5813. * @author alteredq / http://alteredqualia.com/
  5814. * @author mrdoob / http://mrdoob.com/
  5815. */
  5816. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5817. function BufferGeometry() {
  5818. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  5819. this.uuid = _Math.generateUUID();
  5820. this.name = '';
  5821. this.type = 'BufferGeometry';
  5822. this.index = null;
  5823. this.attributes = {};
  5824. this.morphAttributes = {};
  5825. this.groups = [];
  5826. this.boundingBox = null;
  5827. this.boundingSphere = null;
  5828. this.drawRange = { start: 0, count: Infinity };
  5829. this.userData = {};
  5830. }
  5831. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5832. constructor: BufferGeometry,
  5833. isBufferGeometry: true,
  5834. getIndex: function () {
  5835. return this.index;
  5836. },
  5837. setIndex: function ( index ) {
  5838. if ( Array.isArray( index ) ) {
  5839. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5840. } else {
  5841. this.index = index;
  5842. }
  5843. },
  5844. addAttribute: function ( name, attribute ) {
  5845. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  5846. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  5847. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  5848. }
  5849. if ( name === 'index' ) {
  5850. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  5851. this.setIndex( attribute );
  5852. return this;
  5853. }
  5854. this.attributes[ name ] = attribute;
  5855. return this;
  5856. },
  5857. getAttribute: function ( name ) {
  5858. return this.attributes[ name ];
  5859. },
  5860. removeAttribute: function ( name ) {
  5861. delete this.attributes[ name ];
  5862. return this;
  5863. },
  5864. addGroup: function ( start, count, materialIndex ) {
  5865. this.groups.push( {
  5866. start: start,
  5867. count: count,
  5868. materialIndex: materialIndex !== undefined ? materialIndex : 0
  5869. } );
  5870. },
  5871. clearGroups: function () {
  5872. this.groups = [];
  5873. },
  5874. setDrawRange: function ( start, count ) {
  5875. this.drawRange.start = start;
  5876. this.drawRange.count = count;
  5877. },
  5878. applyMatrix: function ( matrix ) {
  5879. var position = this.attributes.position;
  5880. if ( position !== undefined ) {
  5881. matrix.applyToBufferAttribute( position );
  5882. position.needsUpdate = true;
  5883. }
  5884. var normal = this.attributes.normal;
  5885. if ( normal !== undefined ) {
  5886. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5887. normalMatrix.applyToBufferAttribute( normal );
  5888. normal.needsUpdate = true;
  5889. }
  5890. var tangent = this.attributes.tangent;
  5891. if ( tangent !== undefined ) {
  5892. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5893. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  5894. normalMatrix.applyToBufferAttribute( tangent );
  5895. tangent.needsUpdate = true;
  5896. }
  5897. if ( this.boundingBox !== null ) {
  5898. this.computeBoundingBox();
  5899. }
  5900. if ( this.boundingSphere !== null ) {
  5901. this.computeBoundingSphere();
  5902. }
  5903. return this;
  5904. },
  5905. rotateX: function () {
  5906. // rotate geometry around world x-axis
  5907. var m1 = new Matrix4();
  5908. return function rotateX( angle ) {
  5909. m1.makeRotationX( angle );
  5910. this.applyMatrix( m1 );
  5911. return this;
  5912. };
  5913. }(),
  5914. rotateY: function () {
  5915. // rotate geometry around world y-axis
  5916. var m1 = new Matrix4();
  5917. return function rotateY( angle ) {
  5918. m1.makeRotationY( angle );
  5919. this.applyMatrix( m1 );
  5920. return this;
  5921. };
  5922. }(),
  5923. rotateZ: function () {
  5924. // rotate geometry around world z-axis
  5925. var m1 = new Matrix4();
  5926. return function rotateZ( angle ) {
  5927. m1.makeRotationZ( angle );
  5928. this.applyMatrix( m1 );
  5929. return this;
  5930. };
  5931. }(),
  5932. translate: function () {
  5933. // translate geometry
  5934. var m1 = new Matrix4();
  5935. return function translate( x, y, z ) {
  5936. m1.makeTranslation( x, y, z );
  5937. this.applyMatrix( m1 );
  5938. return this;
  5939. };
  5940. }(),
  5941. scale: function () {
  5942. // scale geometry
  5943. var m1 = new Matrix4();
  5944. return function scale( x, y, z ) {
  5945. m1.makeScale( x, y, z );
  5946. this.applyMatrix( m1 );
  5947. return this;
  5948. };
  5949. }(),
  5950. lookAt: function () {
  5951. var obj = new Object3D();
  5952. return function lookAt( vector ) {
  5953. obj.lookAt( vector );
  5954. obj.updateMatrix();
  5955. this.applyMatrix( obj.matrix );
  5956. };
  5957. }(),
  5958. center: function () {
  5959. var offset = new Vector3();
  5960. return function center() {
  5961. this.computeBoundingBox();
  5962. this.boundingBox.getCenter( offset ).negate();
  5963. this.translate( offset.x, offset.y, offset.z );
  5964. return this;
  5965. };
  5966. }(),
  5967. setFromObject: function ( object ) {
  5968. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5969. var geometry = object.geometry;
  5970. if ( object.isPoints || object.isLine ) {
  5971. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5972. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  5973. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5974. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5975. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  5976. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  5977. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  5978. }
  5979. if ( geometry.boundingSphere !== null ) {
  5980. this.boundingSphere = geometry.boundingSphere.clone();
  5981. }
  5982. if ( geometry.boundingBox !== null ) {
  5983. this.boundingBox = geometry.boundingBox.clone();
  5984. }
  5985. } else if ( object.isMesh ) {
  5986. if ( geometry && geometry.isGeometry ) {
  5987. this.fromGeometry( geometry );
  5988. }
  5989. }
  5990. return this;
  5991. },
  5992. setFromPoints: function ( points ) {
  5993. var position = [];
  5994. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5995. var point = points[ i ];
  5996. position.push( point.x, point.y, point.z || 0 );
  5997. }
  5998. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  5999. return this;
  6000. },
  6001. updateFromObject: function ( object ) {
  6002. var geometry = object.geometry;
  6003. if ( object.isMesh ) {
  6004. var direct = geometry.__directGeometry;
  6005. if ( geometry.elementsNeedUpdate === true ) {
  6006. direct = undefined;
  6007. geometry.elementsNeedUpdate = false;
  6008. }
  6009. if ( direct === undefined ) {
  6010. return this.fromGeometry( geometry );
  6011. }
  6012. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6013. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6014. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6015. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6016. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6017. geometry.verticesNeedUpdate = false;
  6018. geometry.normalsNeedUpdate = false;
  6019. geometry.colorsNeedUpdate = false;
  6020. geometry.uvsNeedUpdate = false;
  6021. geometry.groupsNeedUpdate = false;
  6022. geometry = direct;
  6023. }
  6024. var attribute;
  6025. if ( geometry.verticesNeedUpdate === true ) {
  6026. attribute = this.attributes.position;
  6027. if ( attribute !== undefined ) {
  6028. attribute.copyVector3sArray( geometry.vertices );
  6029. attribute.needsUpdate = true;
  6030. }
  6031. geometry.verticesNeedUpdate = false;
  6032. }
  6033. if ( geometry.normalsNeedUpdate === true ) {
  6034. attribute = this.attributes.normal;
  6035. if ( attribute !== undefined ) {
  6036. attribute.copyVector3sArray( geometry.normals );
  6037. attribute.needsUpdate = true;
  6038. }
  6039. geometry.normalsNeedUpdate = false;
  6040. }
  6041. if ( geometry.colorsNeedUpdate === true ) {
  6042. attribute = this.attributes.color;
  6043. if ( attribute !== undefined ) {
  6044. attribute.copyColorsArray( geometry.colors );
  6045. attribute.needsUpdate = true;
  6046. }
  6047. geometry.colorsNeedUpdate = false;
  6048. }
  6049. if ( geometry.uvsNeedUpdate ) {
  6050. attribute = this.attributes.uv;
  6051. if ( attribute !== undefined ) {
  6052. attribute.copyVector2sArray( geometry.uvs );
  6053. attribute.needsUpdate = true;
  6054. }
  6055. geometry.uvsNeedUpdate = false;
  6056. }
  6057. if ( geometry.lineDistancesNeedUpdate ) {
  6058. attribute = this.attributes.lineDistance;
  6059. if ( attribute !== undefined ) {
  6060. attribute.copyArray( geometry.lineDistances );
  6061. attribute.needsUpdate = true;
  6062. }
  6063. geometry.lineDistancesNeedUpdate = false;
  6064. }
  6065. if ( geometry.groupsNeedUpdate ) {
  6066. geometry.computeGroups( object.geometry );
  6067. this.groups = geometry.groups;
  6068. geometry.groupsNeedUpdate = false;
  6069. }
  6070. return this;
  6071. },
  6072. fromGeometry: function ( geometry ) {
  6073. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6074. return this.fromDirectGeometry( geometry.__directGeometry );
  6075. },
  6076. fromDirectGeometry: function ( geometry ) {
  6077. var positions = new Float32Array( geometry.vertices.length * 3 );
  6078. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6079. if ( geometry.normals.length > 0 ) {
  6080. var normals = new Float32Array( geometry.normals.length * 3 );
  6081. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6082. }
  6083. if ( geometry.colors.length > 0 ) {
  6084. var colors = new Float32Array( geometry.colors.length * 3 );
  6085. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6086. }
  6087. if ( geometry.uvs.length > 0 ) {
  6088. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6089. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6090. }
  6091. if ( geometry.uvs2.length > 0 ) {
  6092. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6093. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6094. }
  6095. // groups
  6096. this.groups = geometry.groups;
  6097. // morphs
  6098. for ( var name in geometry.morphTargets ) {
  6099. var array = [];
  6100. var morphTargets = geometry.morphTargets[ name ];
  6101. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6102. var morphTarget = morphTargets[ i ];
  6103. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6104. attribute.name = morphTarget.name;
  6105. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6106. }
  6107. this.morphAttributes[ name ] = array;
  6108. }
  6109. // skinning
  6110. if ( geometry.skinIndices.length > 0 ) {
  6111. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6112. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6113. }
  6114. if ( geometry.skinWeights.length > 0 ) {
  6115. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6116. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6117. }
  6118. //
  6119. if ( geometry.boundingSphere !== null ) {
  6120. this.boundingSphere = geometry.boundingSphere.clone();
  6121. }
  6122. if ( geometry.boundingBox !== null ) {
  6123. this.boundingBox = geometry.boundingBox.clone();
  6124. }
  6125. return this;
  6126. },
  6127. computeBoundingBox: function () {
  6128. var box = new Box3();
  6129. return function computeBoundingBox() {
  6130. if ( this.boundingBox === null ) {
  6131. this.boundingBox = new Box3();
  6132. }
  6133. var position = this.attributes.position;
  6134. var morphAttributesPosition = this.morphAttributes.position;
  6135. if ( position !== undefined ) {
  6136. this.boundingBox.setFromBufferAttribute( position );
  6137. // process morph attributes if present
  6138. if ( morphAttributesPosition ) {
  6139. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6140. var morphAttribute = morphAttributesPosition[ i ];
  6141. box.setFromBufferAttribute( morphAttribute );
  6142. this.boundingBox.expandByPoint( box.min );
  6143. this.boundingBox.expandByPoint( box.max );
  6144. }
  6145. }
  6146. } else {
  6147. this.boundingBox.makeEmpty();
  6148. }
  6149. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6150. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6151. }
  6152. };
  6153. }(),
  6154. computeBoundingSphere: function () {
  6155. var box = new Box3();
  6156. var boxMorphTargets = new Box3();
  6157. var vector = new Vector3();
  6158. return function computeBoundingSphere() {
  6159. if ( this.boundingSphere === null ) {
  6160. this.boundingSphere = new Sphere();
  6161. }
  6162. var position = this.attributes.position;
  6163. var morphAttributesPosition = this.morphAttributes.position;
  6164. if ( position ) {
  6165. // first, find the center of the bounding sphere
  6166. var center = this.boundingSphere.center;
  6167. box.setFromBufferAttribute( position );
  6168. // process morph attributes if present
  6169. if ( morphAttributesPosition ) {
  6170. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6171. var morphAttribute = morphAttributesPosition[ i ];
  6172. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6173. box.expandByPoint( boxMorphTargets.min );
  6174. box.expandByPoint( boxMorphTargets.max );
  6175. }
  6176. }
  6177. box.getCenter( center );
  6178. // second, try to find a boundingSphere with a radius smaller than the
  6179. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6180. var maxRadiusSq = 0;
  6181. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6182. vector.fromBufferAttribute( position, i );
  6183. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6184. }
  6185. // process morph attributes if present
  6186. if ( morphAttributesPosition ) {
  6187. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6188. var morphAttribute = morphAttributesPosition[ i ];
  6189. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6190. vector.fromBufferAttribute( morphAttribute, j );
  6191. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6192. }
  6193. }
  6194. }
  6195. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6196. if ( isNaN( this.boundingSphere.radius ) ) {
  6197. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6198. }
  6199. }
  6200. };
  6201. }(),
  6202. computeFaceNormals: function () {
  6203. // backwards compatibility
  6204. },
  6205. computeVertexNormals: function () {
  6206. var index = this.index;
  6207. var attributes = this.attributes;
  6208. if ( attributes.position ) {
  6209. var positions = attributes.position.array;
  6210. if ( attributes.normal === undefined ) {
  6211. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6212. } else {
  6213. // reset existing normals to zero
  6214. var array = attributes.normal.array;
  6215. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6216. array[ i ] = 0;
  6217. }
  6218. }
  6219. var normals = attributes.normal.array;
  6220. var vA, vB, vC;
  6221. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6222. var cb = new Vector3(), ab = new Vector3();
  6223. // indexed elements
  6224. if ( index ) {
  6225. var indices = index.array;
  6226. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  6227. vA = indices[ i + 0 ] * 3;
  6228. vB = indices[ i + 1 ] * 3;
  6229. vC = indices[ i + 2 ] * 3;
  6230. pA.fromArray( positions, vA );
  6231. pB.fromArray( positions, vB );
  6232. pC.fromArray( positions, vC );
  6233. cb.subVectors( pC, pB );
  6234. ab.subVectors( pA, pB );
  6235. cb.cross( ab );
  6236. normals[ vA ] += cb.x;
  6237. normals[ vA + 1 ] += cb.y;
  6238. normals[ vA + 2 ] += cb.z;
  6239. normals[ vB ] += cb.x;
  6240. normals[ vB + 1 ] += cb.y;
  6241. normals[ vB + 2 ] += cb.z;
  6242. normals[ vC ] += cb.x;
  6243. normals[ vC + 1 ] += cb.y;
  6244. normals[ vC + 2 ] += cb.z;
  6245. }
  6246. } else {
  6247. // non-indexed elements (unconnected triangle soup)
  6248. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6249. pA.fromArray( positions, i );
  6250. pB.fromArray( positions, i + 3 );
  6251. pC.fromArray( positions, i + 6 );
  6252. cb.subVectors( pC, pB );
  6253. ab.subVectors( pA, pB );
  6254. cb.cross( ab );
  6255. normals[ i ] = cb.x;
  6256. normals[ i + 1 ] = cb.y;
  6257. normals[ i + 2 ] = cb.z;
  6258. normals[ i + 3 ] = cb.x;
  6259. normals[ i + 4 ] = cb.y;
  6260. normals[ i + 5 ] = cb.z;
  6261. normals[ i + 6 ] = cb.x;
  6262. normals[ i + 7 ] = cb.y;
  6263. normals[ i + 8 ] = cb.z;
  6264. }
  6265. }
  6266. this.normalizeNormals();
  6267. attributes.normal.needsUpdate = true;
  6268. }
  6269. },
  6270. merge: function ( geometry, offset ) {
  6271. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6272. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6273. return;
  6274. }
  6275. if ( offset === undefined ) {
  6276. offset = 0;
  6277. console.warn(
  6278. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6279. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6280. );
  6281. }
  6282. var attributes = this.attributes;
  6283. for ( var key in attributes ) {
  6284. if ( geometry.attributes[ key ] === undefined ) continue;
  6285. var attribute1 = attributes[ key ];
  6286. var attributeArray1 = attribute1.array;
  6287. var attribute2 = geometry.attributes[ key ];
  6288. var attributeArray2 = attribute2.array;
  6289. var attributeOffset = attribute2.itemSize * offset;
  6290. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6291. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6292. attributeArray1[ j ] = attributeArray2[ i ];
  6293. }
  6294. }
  6295. return this;
  6296. },
  6297. normalizeNormals: function () {
  6298. var vector = new Vector3();
  6299. return function normalizeNormals() {
  6300. var normals = this.attributes.normal;
  6301. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6302. vector.x = normals.getX( i );
  6303. vector.y = normals.getY( i );
  6304. vector.z = normals.getZ( i );
  6305. vector.normalize();
  6306. normals.setXYZ( i, vector.x, vector.y, vector.z );
  6307. }
  6308. };
  6309. }(),
  6310. toNonIndexed: function () {
  6311. function convertBufferAttribute( attribute, indices ) {
  6312. var array = attribute.array;
  6313. var itemSize = attribute.itemSize;
  6314. var array2 = new array.constructor( indices.length * itemSize );
  6315. var index = 0, index2 = 0;
  6316. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6317. index = indices[ i ] * itemSize;
  6318. for ( var j = 0; j < itemSize; j ++ ) {
  6319. array2[ index2 ++ ] = array[ index ++ ];
  6320. }
  6321. }
  6322. return new BufferAttribute( array2, itemSize );
  6323. }
  6324. //
  6325. if ( this.index === null ) {
  6326. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6327. return this;
  6328. }
  6329. var geometry2 = new BufferGeometry();
  6330. var indices = this.index.array;
  6331. var attributes = this.attributes;
  6332. // attributes
  6333. for ( var name in attributes ) {
  6334. var attribute = attributes[ name ];
  6335. var newAttribute = convertBufferAttribute( attribute, indices );
  6336. geometry2.addAttribute( name, newAttribute );
  6337. }
  6338. // morph attributes
  6339. var morphAttributes = this.morphAttributes;
  6340. for ( name in morphAttributes ) {
  6341. var morphArray = [];
  6342. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6343. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6344. var attribute = morphAttribute[ i ];
  6345. var newAttribute = convertBufferAttribute( attribute, indices );
  6346. morphArray.push( newAttribute );
  6347. }
  6348. geometry2.morphAttributes[ name ] = morphArray;
  6349. }
  6350. // groups
  6351. var groups = this.groups;
  6352. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6353. var group = groups[ i ];
  6354. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6355. }
  6356. return geometry2;
  6357. },
  6358. toJSON: function () {
  6359. var data = {
  6360. metadata: {
  6361. version: 4.5,
  6362. type: 'BufferGeometry',
  6363. generator: 'BufferGeometry.toJSON'
  6364. }
  6365. };
  6366. // standard BufferGeometry serialization
  6367. data.uuid = this.uuid;
  6368. data.type = this.type;
  6369. if ( this.name !== '' ) data.name = this.name;
  6370. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6371. if ( this.parameters !== undefined ) {
  6372. var parameters = this.parameters;
  6373. for ( var key in parameters ) {
  6374. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6375. }
  6376. return data;
  6377. }
  6378. data.data = { attributes: {} };
  6379. var index = this.index;
  6380. if ( index !== null ) {
  6381. data.data.index = {
  6382. type: index.array.constructor.name,
  6383. array: Array.prototype.slice.call( index.array )
  6384. };
  6385. }
  6386. var attributes = this.attributes;
  6387. for ( var key in attributes ) {
  6388. var attribute = attributes[ key ];
  6389. var attributeData = attribute.toJSON();
  6390. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6391. data.data.attributes[ key ] = attributeData;
  6392. }
  6393. var morphAttributes = {};
  6394. var hasMorphAttributes = false;
  6395. for ( var key in this.morphAttributes ) {
  6396. var attributeArray = this.morphAttributes[ key ];
  6397. var array = [];
  6398. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6399. var attribute = attributeArray[ i ];
  6400. var attributeData = attribute.toJSON();
  6401. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6402. array.push( attributeData );
  6403. }
  6404. if ( array.length > 0 ) {
  6405. morphAttributes[ key ] = array;
  6406. hasMorphAttributes = true;
  6407. }
  6408. }
  6409. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  6410. var groups = this.groups;
  6411. if ( groups.length > 0 ) {
  6412. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6413. }
  6414. var boundingSphere = this.boundingSphere;
  6415. if ( boundingSphere !== null ) {
  6416. data.data.boundingSphere = {
  6417. center: boundingSphere.center.toArray(),
  6418. radius: boundingSphere.radius
  6419. };
  6420. }
  6421. return data;
  6422. },
  6423. clone: function () {
  6424. /*
  6425. // Handle primitives
  6426. var parameters = this.parameters;
  6427. if ( parameters !== undefined ) {
  6428. var values = [];
  6429. for ( var key in parameters ) {
  6430. values.push( parameters[ key ] );
  6431. }
  6432. var geometry = Object.create( this.constructor.prototype );
  6433. this.constructor.apply( geometry, values );
  6434. return geometry;
  6435. }
  6436. return new this.constructor().copy( this );
  6437. */
  6438. return new BufferGeometry().copy( this );
  6439. },
  6440. copy: function ( source ) {
  6441. var name, i, l;
  6442. // reset
  6443. this.index = null;
  6444. this.attributes = {};
  6445. this.morphAttributes = {};
  6446. this.groups = [];
  6447. this.boundingBox = null;
  6448. this.boundingSphere = null;
  6449. // name
  6450. this.name = source.name;
  6451. // index
  6452. var index = source.index;
  6453. if ( index !== null ) {
  6454. this.setIndex( index.clone() );
  6455. }
  6456. // attributes
  6457. var attributes = source.attributes;
  6458. for ( name in attributes ) {
  6459. var attribute = attributes[ name ];
  6460. this.addAttribute( name, attribute.clone() );
  6461. }
  6462. // morph attributes
  6463. var morphAttributes = source.morphAttributes;
  6464. for ( name in morphAttributes ) {
  6465. var array = [];
  6466. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6467. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6468. array.push( morphAttribute[ i ].clone() );
  6469. }
  6470. this.morphAttributes[ name ] = array;
  6471. }
  6472. // groups
  6473. var groups = source.groups;
  6474. for ( i = 0, l = groups.length; i < l; i ++ ) {
  6475. var group = groups[ i ];
  6476. this.addGroup( group.start, group.count, group.materialIndex );
  6477. }
  6478. // bounding box
  6479. var boundingBox = source.boundingBox;
  6480. if ( boundingBox !== null ) {
  6481. this.boundingBox = boundingBox.clone();
  6482. }
  6483. // bounding sphere
  6484. var boundingSphere = source.boundingSphere;
  6485. if ( boundingSphere !== null ) {
  6486. this.boundingSphere = boundingSphere.clone();
  6487. }
  6488. // draw range
  6489. this.drawRange.start = source.drawRange.start;
  6490. this.drawRange.count = source.drawRange.count;
  6491. // user data
  6492. this.userData = source.userData;
  6493. return this;
  6494. },
  6495. dispose: function () {
  6496. this.dispatchEvent( { type: 'dispose' } );
  6497. }
  6498. } );
  6499. /**
  6500. * @author mrdoob / http://mrdoob.com/
  6501. * @author alteredq / http://alteredqualia.com/
  6502. * @author mikael emtinger / http://gomo.se/
  6503. * @author jonobr1 / http://jonobr1.com/
  6504. */
  6505. function Mesh( geometry, material ) {
  6506. Object3D.call( this );
  6507. this.type = 'Mesh';
  6508. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6509. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  6510. this.drawMode = TrianglesDrawMode;
  6511. this.updateMorphTargets();
  6512. }
  6513. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6514. constructor: Mesh,
  6515. isMesh: true,
  6516. setDrawMode: function ( value ) {
  6517. this.drawMode = value;
  6518. },
  6519. copy: function ( source ) {
  6520. Object3D.prototype.copy.call( this, source );
  6521. this.drawMode = source.drawMode;
  6522. if ( source.morphTargetInfluences !== undefined ) {
  6523. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6524. }
  6525. if ( source.morphTargetDictionary !== undefined ) {
  6526. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6527. }
  6528. return this;
  6529. },
  6530. updateMorphTargets: function () {
  6531. var geometry = this.geometry;
  6532. var m, ml, name;
  6533. if ( geometry.isBufferGeometry ) {
  6534. var morphAttributes = geometry.morphAttributes;
  6535. var keys = Object.keys( morphAttributes );
  6536. if ( keys.length > 0 ) {
  6537. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6538. if ( morphAttribute !== undefined ) {
  6539. this.morphTargetInfluences = [];
  6540. this.morphTargetDictionary = {};
  6541. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6542. name = morphAttribute[ m ].name || String( m );
  6543. this.morphTargetInfluences.push( 0 );
  6544. this.morphTargetDictionary[ name ] = m;
  6545. }
  6546. }
  6547. }
  6548. } else {
  6549. var morphTargets = geometry.morphTargets;
  6550. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6551. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6552. }
  6553. }
  6554. },
  6555. raycast: ( function () {
  6556. var inverseMatrix = new Matrix4();
  6557. var ray = new Ray();
  6558. var sphere = new Sphere();
  6559. var vA = new Vector3();
  6560. var vB = new Vector3();
  6561. var vC = new Vector3();
  6562. var tempA = new Vector3();
  6563. var tempB = new Vector3();
  6564. var tempC = new Vector3();
  6565. var morphA = new Vector3();
  6566. var morphB = new Vector3();
  6567. var morphC = new Vector3();
  6568. var uvA = new Vector2();
  6569. var uvB = new Vector2();
  6570. var uvC = new Vector2();
  6571. var intersectionPoint = new Vector3();
  6572. var intersectionPointWorld = new Vector3();
  6573. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6574. var intersect;
  6575. if ( material.side === BackSide ) {
  6576. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6577. } else {
  6578. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6579. }
  6580. if ( intersect === null ) return null;
  6581. intersectionPointWorld.copy( point );
  6582. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6583. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  6584. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6585. return {
  6586. distance: distance,
  6587. point: intersectionPointWorld.clone(),
  6588. object: object
  6589. };
  6590. }
  6591. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c ) {
  6592. vA.fromBufferAttribute( position, a );
  6593. vB.fromBufferAttribute( position, b );
  6594. vC.fromBufferAttribute( position, c );
  6595. var morphInfluences = object.morphTargetInfluences;
  6596. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6597. morphA.set( 0, 0, 0 );
  6598. morphB.set( 0, 0, 0 );
  6599. morphC.set( 0, 0, 0 );
  6600. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6601. var influence = morphInfluences[ i ];
  6602. var morphAttribute = morphPosition[ i ];
  6603. if ( influence === 0 ) continue;
  6604. tempA.fromBufferAttribute( morphAttribute, a );
  6605. tempB.fromBufferAttribute( morphAttribute, b );
  6606. tempC.fromBufferAttribute( morphAttribute, c );
  6607. morphA.addScaledVector( tempA.sub( vA ), influence );
  6608. morphB.addScaledVector( tempB.sub( vB ), influence );
  6609. morphC.addScaledVector( tempC.sub( vC ), influence );
  6610. }
  6611. vA.add( morphA );
  6612. vB.add( morphB );
  6613. vC.add( morphC );
  6614. }
  6615. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  6616. if ( intersection ) {
  6617. if ( uv ) {
  6618. uvA.fromBufferAttribute( uv, a );
  6619. uvB.fromBufferAttribute( uv, b );
  6620. uvC.fromBufferAttribute( uv, c );
  6621. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  6622. }
  6623. if ( uv2 ) {
  6624. uvA.fromBufferAttribute( uv2, a );
  6625. uvB.fromBufferAttribute( uv2, b );
  6626. uvC.fromBufferAttribute( uv2, c );
  6627. intersection.uv2 = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  6628. }
  6629. var face = new Face3( a, b, c );
  6630. Triangle.getNormal( vA, vB, vC, face.normal );
  6631. intersection.face = face;
  6632. }
  6633. return intersection;
  6634. }
  6635. return function raycast( raycaster, intersects ) {
  6636. var geometry = this.geometry;
  6637. var material = this.material;
  6638. var matrixWorld = this.matrixWorld;
  6639. if ( material === undefined ) return;
  6640. // Checking boundingSphere distance to ray
  6641. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6642. sphere.copy( geometry.boundingSphere );
  6643. sphere.applyMatrix4( matrixWorld );
  6644. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  6645. //
  6646. inverseMatrix.getInverse( matrixWorld );
  6647. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  6648. // Check boundingBox before continuing
  6649. if ( geometry.boundingBox !== null ) {
  6650. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6651. }
  6652. var intersection;
  6653. if ( geometry.isBufferGeometry ) {
  6654. var a, b, c;
  6655. var index = geometry.index;
  6656. var position = geometry.attributes.position;
  6657. var morphPosition = geometry.morphAttributes.position;
  6658. var uv = geometry.attributes.uv;
  6659. var uv2 = geometry.attributes.uv2;
  6660. var groups = geometry.groups;
  6661. var drawRange = geometry.drawRange;
  6662. var i, j, il, jl;
  6663. var group, groupMaterial;
  6664. var start, end;
  6665. if ( index !== null ) {
  6666. // indexed buffer geometry
  6667. if ( Array.isArray( material ) ) {
  6668. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6669. group = groups[ i ];
  6670. groupMaterial = material[ group.materialIndex ];
  6671. start = Math.max( group.start, drawRange.start );
  6672. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6673. for ( j = start, jl = end; j < jl; j += 3 ) {
  6674. a = index.getX( j );
  6675. b = index.getX( j + 1 );
  6676. c = index.getX( j + 2 );
  6677. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6678. if ( intersection ) {
  6679. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6680. intersection.face.materialIndex = group.materialIndex;
  6681. intersects.push( intersection );
  6682. }
  6683. }
  6684. }
  6685. } else {
  6686. start = Math.max( 0, drawRange.start );
  6687. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6688. for ( i = start, il = end; i < il; i += 3 ) {
  6689. a = index.getX( i );
  6690. b = index.getX( i + 1 );
  6691. c = index.getX( i + 2 );
  6692. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6693. if ( intersection ) {
  6694. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6695. intersects.push( intersection );
  6696. }
  6697. }
  6698. }
  6699. } else if ( position !== undefined ) {
  6700. // non-indexed buffer geometry
  6701. if ( Array.isArray( material ) ) {
  6702. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6703. group = groups[ i ];
  6704. groupMaterial = material[ group.materialIndex ];
  6705. start = Math.max( group.start, drawRange.start );
  6706. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6707. for ( j = start, jl = end; j < jl; j += 3 ) {
  6708. a = j;
  6709. b = j + 1;
  6710. c = j + 2;
  6711. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6712. if ( intersection ) {
  6713. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6714. intersection.face.materialIndex = group.materialIndex;
  6715. intersects.push( intersection );
  6716. }
  6717. }
  6718. }
  6719. } else {
  6720. start = Math.max( 0, drawRange.start );
  6721. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6722. for ( i = start, il = end; i < il; i += 3 ) {
  6723. a = i;
  6724. b = i + 1;
  6725. c = i + 2;
  6726. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6727. if ( intersection ) {
  6728. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6729. intersects.push( intersection );
  6730. }
  6731. }
  6732. }
  6733. }
  6734. } else if ( geometry.isGeometry ) {
  6735. var fvA, fvB, fvC;
  6736. var isMultiMaterial = Array.isArray( material );
  6737. var vertices = geometry.vertices;
  6738. var faces = geometry.faces;
  6739. var uvs;
  6740. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6741. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6742. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6743. var face = faces[ f ];
  6744. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6745. if ( faceMaterial === undefined ) continue;
  6746. fvA = vertices[ face.a ];
  6747. fvB = vertices[ face.b ];
  6748. fvC = vertices[ face.c ];
  6749. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  6750. if ( intersection ) {
  6751. if ( uvs && uvs[ f ] ) {
  6752. var uvs_f = uvs[ f ];
  6753. uvA.copy( uvs_f[ 0 ] );
  6754. uvB.copy( uvs_f[ 1 ] );
  6755. uvC.copy( uvs_f[ 2 ] );
  6756. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  6757. }
  6758. intersection.face = face;
  6759. intersection.faceIndex = f;
  6760. intersects.push( intersection );
  6761. }
  6762. }
  6763. }
  6764. };
  6765. }() ),
  6766. clone: function () {
  6767. return new this.constructor( this.geometry, this.material ).copy( this );
  6768. }
  6769. } );
  6770. /**
  6771. * @author mrdoob / http://mrdoob.com/
  6772. * @author kile / http://kile.stravaganza.org/
  6773. * @author alteredq / http://alteredqualia.com/
  6774. * @author mikael emtinger / http://gomo.se/
  6775. * @author zz85 / http://www.lab4games.net/zz85/blog
  6776. * @author bhouston / http://clara.io
  6777. */
  6778. var geometryId = 0; // Geometry uses even numbers as Id
  6779. function Geometry() {
  6780. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6781. this.uuid = _Math.generateUUID();
  6782. this.name = '';
  6783. this.type = 'Geometry';
  6784. this.vertices = [];
  6785. this.colors = [];
  6786. this.faces = [];
  6787. this.faceVertexUvs = [[]];
  6788. this.morphTargets = [];
  6789. this.morphNormals = [];
  6790. this.skinWeights = [];
  6791. this.skinIndices = [];
  6792. this.lineDistances = [];
  6793. this.boundingBox = null;
  6794. this.boundingSphere = null;
  6795. // update flags
  6796. this.elementsNeedUpdate = false;
  6797. this.verticesNeedUpdate = false;
  6798. this.uvsNeedUpdate = false;
  6799. this.normalsNeedUpdate = false;
  6800. this.colorsNeedUpdate = false;
  6801. this.lineDistancesNeedUpdate = false;
  6802. this.groupsNeedUpdate = false;
  6803. }
  6804. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6805. constructor: Geometry,
  6806. isGeometry: true,
  6807. applyMatrix: function ( matrix ) {
  6808. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6809. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6810. var vertex = this.vertices[ i ];
  6811. vertex.applyMatrix4( matrix );
  6812. }
  6813. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6814. var face = this.faces[ i ];
  6815. face.normal.applyMatrix3( normalMatrix ).normalize();
  6816. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6817. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6818. }
  6819. }
  6820. if ( this.boundingBox !== null ) {
  6821. this.computeBoundingBox();
  6822. }
  6823. if ( this.boundingSphere !== null ) {
  6824. this.computeBoundingSphere();
  6825. }
  6826. this.verticesNeedUpdate = true;
  6827. this.normalsNeedUpdate = true;
  6828. return this;
  6829. },
  6830. rotateX: function () {
  6831. // rotate geometry around world x-axis
  6832. var m1 = new Matrix4();
  6833. return function rotateX( angle ) {
  6834. m1.makeRotationX( angle );
  6835. this.applyMatrix( m1 );
  6836. return this;
  6837. };
  6838. }(),
  6839. rotateY: function () {
  6840. // rotate geometry around world y-axis
  6841. var m1 = new Matrix4();
  6842. return function rotateY( angle ) {
  6843. m1.makeRotationY( angle );
  6844. this.applyMatrix( m1 );
  6845. return this;
  6846. };
  6847. }(),
  6848. rotateZ: function () {
  6849. // rotate geometry around world z-axis
  6850. var m1 = new Matrix4();
  6851. return function rotateZ( angle ) {
  6852. m1.makeRotationZ( angle );
  6853. this.applyMatrix( m1 );
  6854. return this;
  6855. };
  6856. }(),
  6857. translate: function () {
  6858. // translate geometry
  6859. var m1 = new Matrix4();
  6860. return function translate( x, y, z ) {
  6861. m1.makeTranslation( x, y, z );
  6862. this.applyMatrix( m1 );
  6863. return this;
  6864. };
  6865. }(),
  6866. scale: function () {
  6867. // scale geometry
  6868. var m1 = new Matrix4();
  6869. return function scale( x, y, z ) {
  6870. m1.makeScale( x, y, z );
  6871. this.applyMatrix( m1 );
  6872. return this;
  6873. };
  6874. }(),
  6875. lookAt: function () {
  6876. var obj = new Object3D();
  6877. return function lookAt( vector ) {
  6878. obj.lookAt( vector );
  6879. obj.updateMatrix();
  6880. this.applyMatrix( obj.matrix );
  6881. };
  6882. }(),
  6883. fromBufferGeometry: function ( geometry ) {
  6884. var scope = this;
  6885. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6886. var attributes = geometry.attributes;
  6887. var positions = attributes.position.array;
  6888. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6889. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6890. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6891. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6892. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6893. for ( var i = 0; i < positions.length; i += 3 ) {
  6894. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  6895. if ( colors !== undefined ) {
  6896. scope.colors.push( new Color().fromArray( colors, i ) );
  6897. }
  6898. }
  6899. function addFace( a, b, c, materialIndex ) {
  6900. var vertexColors = ( colors === undefined ) ? [] : [
  6901. scope.colors[ a ].clone(),
  6902. scope.colors[ b ].clone(),
  6903. scope.colors[ c ].clone() ];
  6904. var vertexNormals = ( normals === undefined ) ? [] : [
  6905. new Vector3().fromArray( normals, a * 3 ),
  6906. new Vector3().fromArray( normals, b * 3 ),
  6907. new Vector3().fromArray( normals, c * 3 )
  6908. ];
  6909. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6910. scope.faces.push( face );
  6911. if ( uvs !== undefined ) {
  6912. scope.faceVertexUvs[ 0 ].push( [
  6913. new Vector2().fromArray( uvs, a * 2 ),
  6914. new Vector2().fromArray( uvs, b * 2 ),
  6915. new Vector2().fromArray( uvs, c * 2 )
  6916. ] );
  6917. }
  6918. if ( uvs2 !== undefined ) {
  6919. scope.faceVertexUvs[ 1 ].push( [
  6920. new Vector2().fromArray( uvs2, a * 2 ),
  6921. new Vector2().fromArray( uvs2, b * 2 ),
  6922. new Vector2().fromArray( uvs2, c * 2 )
  6923. ] );
  6924. }
  6925. }
  6926. var groups = geometry.groups;
  6927. if ( groups.length > 0 ) {
  6928. for ( var i = 0; i < groups.length; i ++ ) {
  6929. var group = groups[ i ];
  6930. var start = group.start;
  6931. var count = group.count;
  6932. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6933. if ( indices !== undefined ) {
  6934. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6935. } else {
  6936. addFace( j, j + 1, j + 2, group.materialIndex );
  6937. }
  6938. }
  6939. }
  6940. } else {
  6941. if ( indices !== undefined ) {
  6942. for ( var i = 0; i < indices.length; i += 3 ) {
  6943. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6944. }
  6945. } else {
  6946. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6947. addFace( i, i + 1, i + 2 );
  6948. }
  6949. }
  6950. }
  6951. this.computeFaceNormals();
  6952. if ( geometry.boundingBox !== null ) {
  6953. this.boundingBox = geometry.boundingBox.clone();
  6954. }
  6955. if ( geometry.boundingSphere !== null ) {
  6956. this.boundingSphere = geometry.boundingSphere.clone();
  6957. }
  6958. return this;
  6959. },
  6960. center: function () {
  6961. var offset = new Vector3();
  6962. return function center() {
  6963. this.computeBoundingBox();
  6964. this.boundingBox.getCenter( offset ).negate();
  6965. this.translate( offset.x, offset.y, offset.z );
  6966. return this;
  6967. };
  6968. }(),
  6969. normalize: function () {
  6970. this.computeBoundingSphere();
  6971. var center = this.boundingSphere.center;
  6972. var radius = this.boundingSphere.radius;
  6973. var s = radius === 0 ? 1 : 1.0 / radius;
  6974. var matrix = new Matrix4();
  6975. matrix.set(
  6976. s, 0, 0, - s * center.x,
  6977. 0, s, 0, - s * center.y,
  6978. 0, 0, s, - s * center.z,
  6979. 0, 0, 0, 1
  6980. );
  6981. this.applyMatrix( matrix );
  6982. return this;
  6983. },
  6984. computeFaceNormals: function () {
  6985. var cb = new Vector3(), ab = new Vector3();
  6986. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6987. var face = this.faces[ f ];
  6988. var vA = this.vertices[ face.a ];
  6989. var vB = this.vertices[ face.b ];
  6990. var vC = this.vertices[ face.c ];
  6991. cb.subVectors( vC, vB );
  6992. ab.subVectors( vA, vB );
  6993. cb.cross( ab );
  6994. cb.normalize();
  6995. face.normal.copy( cb );
  6996. }
  6997. },
  6998. computeVertexNormals: function ( areaWeighted ) {
  6999. if ( areaWeighted === undefined ) areaWeighted = true;
  7000. var v, vl, f, fl, face, vertices;
  7001. vertices = new Array( this.vertices.length );
  7002. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7003. vertices[ v ] = new Vector3();
  7004. }
  7005. if ( areaWeighted ) {
  7006. // vertex normals weighted by triangle areas
  7007. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7008. var vA, vB, vC;
  7009. var cb = new Vector3(), ab = new Vector3();
  7010. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7011. face = this.faces[ f ];
  7012. vA = this.vertices[ face.a ];
  7013. vB = this.vertices[ face.b ];
  7014. vC = this.vertices[ face.c ];
  7015. cb.subVectors( vC, vB );
  7016. ab.subVectors( vA, vB );
  7017. cb.cross( ab );
  7018. vertices[ face.a ].add( cb );
  7019. vertices[ face.b ].add( cb );
  7020. vertices[ face.c ].add( cb );
  7021. }
  7022. } else {
  7023. this.computeFaceNormals();
  7024. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7025. face = this.faces[ f ];
  7026. vertices[ face.a ].add( face.normal );
  7027. vertices[ face.b ].add( face.normal );
  7028. vertices[ face.c ].add( face.normal );
  7029. }
  7030. }
  7031. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7032. vertices[ v ].normalize();
  7033. }
  7034. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7035. face = this.faces[ f ];
  7036. var vertexNormals = face.vertexNormals;
  7037. if ( vertexNormals.length === 3 ) {
  7038. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7039. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7040. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7041. } else {
  7042. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7043. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7044. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7045. }
  7046. }
  7047. if ( this.faces.length > 0 ) {
  7048. this.normalsNeedUpdate = true;
  7049. }
  7050. },
  7051. computeFlatVertexNormals: function () {
  7052. var f, fl, face;
  7053. this.computeFaceNormals();
  7054. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7055. face = this.faces[ f ];
  7056. var vertexNormals = face.vertexNormals;
  7057. if ( vertexNormals.length === 3 ) {
  7058. vertexNormals[ 0 ].copy( face.normal );
  7059. vertexNormals[ 1 ].copy( face.normal );
  7060. vertexNormals[ 2 ].copy( face.normal );
  7061. } else {
  7062. vertexNormals[ 0 ] = face.normal.clone();
  7063. vertexNormals[ 1 ] = face.normal.clone();
  7064. vertexNormals[ 2 ] = face.normal.clone();
  7065. }
  7066. }
  7067. if ( this.faces.length > 0 ) {
  7068. this.normalsNeedUpdate = true;
  7069. }
  7070. },
  7071. computeMorphNormals: function () {
  7072. var i, il, f, fl, face;
  7073. // save original normals
  7074. // - create temp variables on first access
  7075. // otherwise just copy (for faster repeated calls)
  7076. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7077. face = this.faces[ f ];
  7078. if ( ! face.__originalFaceNormal ) {
  7079. face.__originalFaceNormal = face.normal.clone();
  7080. } else {
  7081. face.__originalFaceNormal.copy( face.normal );
  7082. }
  7083. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7084. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7085. if ( ! face.__originalVertexNormals[ i ] ) {
  7086. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7087. } else {
  7088. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7089. }
  7090. }
  7091. }
  7092. // use temp geometry to compute face and vertex normals for each morph
  7093. var tmpGeo = new Geometry();
  7094. tmpGeo.faces = this.faces;
  7095. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7096. // create on first access
  7097. if ( ! this.morphNormals[ i ] ) {
  7098. this.morphNormals[ i ] = {};
  7099. this.morphNormals[ i ].faceNormals = [];
  7100. this.morphNormals[ i ].vertexNormals = [];
  7101. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7102. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7103. var faceNormal, vertexNormals;
  7104. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7105. faceNormal = new Vector3();
  7106. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7107. dstNormalsFace.push( faceNormal );
  7108. dstNormalsVertex.push( vertexNormals );
  7109. }
  7110. }
  7111. var morphNormals = this.morphNormals[ i ];
  7112. // set vertices to morph target
  7113. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7114. // compute morph normals
  7115. tmpGeo.computeFaceNormals();
  7116. tmpGeo.computeVertexNormals();
  7117. // store morph normals
  7118. var faceNormal, vertexNormals;
  7119. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7120. face = this.faces[ f ];
  7121. faceNormal = morphNormals.faceNormals[ f ];
  7122. vertexNormals = morphNormals.vertexNormals[ f ];
  7123. faceNormal.copy( face.normal );
  7124. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7125. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7126. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7127. }
  7128. }
  7129. // restore original normals
  7130. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7131. face = this.faces[ f ];
  7132. face.normal = face.__originalFaceNormal;
  7133. face.vertexNormals = face.__originalVertexNormals;
  7134. }
  7135. },
  7136. computeBoundingBox: function () {
  7137. if ( this.boundingBox === null ) {
  7138. this.boundingBox = new Box3();
  7139. }
  7140. this.boundingBox.setFromPoints( this.vertices );
  7141. },
  7142. computeBoundingSphere: function () {
  7143. if ( this.boundingSphere === null ) {
  7144. this.boundingSphere = new Sphere();
  7145. }
  7146. this.boundingSphere.setFromPoints( this.vertices );
  7147. },
  7148. merge: function ( geometry, matrix, materialIndexOffset ) {
  7149. if ( ! ( geometry && geometry.isGeometry ) ) {
  7150. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7151. return;
  7152. }
  7153. var normalMatrix,
  7154. vertexOffset = this.vertices.length,
  7155. vertices1 = this.vertices,
  7156. vertices2 = geometry.vertices,
  7157. faces1 = this.faces,
  7158. faces2 = geometry.faces,
  7159. colors1 = this.colors,
  7160. colors2 = geometry.colors;
  7161. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7162. if ( matrix !== undefined ) {
  7163. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7164. }
  7165. // vertices
  7166. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7167. var vertex = vertices2[ i ];
  7168. var vertexCopy = vertex.clone();
  7169. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7170. vertices1.push( vertexCopy );
  7171. }
  7172. // colors
  7173. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7174. colors1.push( colors2[ i ].clone() );
  7175. }
  7176. // faces
  7177. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7178. var face = faces2[ i ], faceCopy, normal, color,
  7179. faceVertexNormals = face.vertexNormals,
  7180. faceVertexColors = face.vertexColors;
  7181. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7182. faceCopy.normal.copy( face.normal );
  7183. if ( normalMatrix !== undefined ) {
  7184. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7185. }
  7186. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7187. normal = faceVertexNormals[ j ].clone();
  7188. if ( normalMatrix !== undefined ) {
  7189. normal.applyMatrix3( normalMatrix ).normalize();
  7190. }
  7191. faceCopy.vertexNormals.push( normal );
  7192. }
  7193. faceCopy.color.copy( face.color );
  7194. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7195. color = faceVertexColors[ j ];
  7196. faceCopy.vertexColors.push( color.clone() );
  7197. }
  7198. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7199. faces1.push( faceCopy );
  7200. }
  7201. // uvs
  7202. for ( var i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7203. var faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7204. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7205. for ( var j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7206. var uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7207. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7208. uvsCopy.push( uvs2[ k ].clone() );
  7209. }
  7210. this.faceVertexUvs[ i ].push( uvsCopy );
  7211. }
  7212. }
  7213. },
  7214. mergeMesh: function ( mesh ) {
  7215. if ( ! ( mesh && mesh.isMesh ) ) {
  7216. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7217. return;
  7218. }
  7219. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7220. this.merge( mesh.geometry, mesh.matrix );
  7221. },
  7222. /*
  7223. * Checks for duplicate vertices with hashmap.
  7224. * Duplicated vertices are removed
  7225. * and faces' vertices are updated.
  7226. */
  7227. mergeVertices: function () {
  7228. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7229. var unique = [], changes = [];
  7230. var v, key;
  7231. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7232. var precision = Math.pow( 10, precisionPoints );
  7233. var i, il, face;
  7234. var indices, j, jl;
  7235. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7236. v = this.vertices[ i ];
  7237. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7238. if ( verticesMap[ key ] === undefined ) {
  7239. verticesMap[ key ] = i;
  7240. unique.push( this.vertices[ i ] );
  7241. changes[ i ] = unique.length - 1;
  7242. } else {
  7243. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7244. changes[ i ] = changes[ verticesMap[ key ] ];
  7245. }
  7246. }
  7247. // if faces are completely degenerate after merging vertices, we
  7248. // have to remove them from the geometry.
  7249. var faceIndicesToRemove = [];
  7250. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7251. face = this.faces[ i ];
  7252. face.a = changes[ face.a ];
  7253. face.b = changes[ face.b ];
  7254. face.c = changes[ face.c ];
  7255. indices = [ face.a, face.b, face.c ];
  7256. // if any duplicate vertices are found in a Face3
  7257. // we have to remove the face as nothing can be saved
  7258. for ( var n = 0; n < 3; n ++ ) {
  7259. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7260. faceIndicesToRemove.push( i );
  7261. break;
  7262. }
  7263. }
  7264. }
  7265. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7266. var idx = faceIndicesToRemove[ i ];
  7267. this.faces.splice( idx, 1 );
  7268. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7269. this.faceVertexUvs[ j ].splice( idx, 1 );
  7270. }
  7271. }
  7272. // Use unique set of vertices
  7273. var diff = this.vertices.length - unique.length;
  7274. this.vertices = unique;
  7275. return diff;
  7276. },
  7277. setFromPoints: function ( points ) {
  7278. this.vertices = [];
  7279. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7280. var point = points[ i ];
  7281. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7282. }
  7283. return this;
  7284. },
  7285. sortFacesByMaterialIndex: function () {
  7286. var faces = this.faces;
  7287. var length = faces.length;
  7288. // tag faces
  7289. for ( var i = 0; i < length; i ++ ) {
  7290. faces[ i ]._id = i;
  7291. }
  7292. // sort faces
  7293. function materialIndexSort( a, b ) {
  7294. return a.materialIndex - b.materialIndex;
  7295. }
  7296. faces.sort( materialIndexSort );
  7297. // sort uvs
  7298. var uvs1 = this.faceVertexUvs[ 0 ];
  7299. var uvs2 = this.faceVertexUvs[ 1 ];
  7300. var newUvs1, newUvs2;
  7301. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7302. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7303. for ( var i = 0; i < length; i ++ ) {
  7304. var id = faces[ i ]._id;
  7305. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7306. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7307. }
  7308. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7309. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7310. },
  7311. toJSON: function () {
  7312. var data = {
  7313. metadata: {
  7314. version: 4.5,
  7315. type: 'Geometry',
  7316. generator: 'Geometry.toJSON'
  7317. }
  7318. };
  7319. // standard Geometry serialization
  7320. data.uuid = this.uuid;
  7321. data.type = this.type;
  7322. if ( this.name !== '' ) data.name = this.name;
  7323. if ( this.parameters !== undefined ) {
  7324. var parameters = this.parameters;
  7325. for ( var key in parameters ) {
  7326. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7327. }
  7328. return data;
  7329. }
  7330. var vertices = [];
  7331. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7332. var vertex = this.vertices[ i ];
  7333. vertices.push( vertex.x, vertex.y, vertex.z );
  7334. }
  7335. var faces = [];
  7336. var normals = [];
  7337. var normalsHash = {};
  7338. var colors = [];
  7339. var colorsHash = {};
  7340. var uvs = [];
  7341. var uvsHash = {};
  7342. for ( var i = 0; i < this.faces.length; i ++ ) {
  7343. var face = this.faces[ i ];
  7344. var hasMaterial = true;
  7345. var hasFaceUv = false; // deprecated
  7346. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7347. var hasFaceNormal = face.normal.length() > 0;
  7348. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7349. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7350. var hasFaceVertexColor = face.vertexColors.length > 0;
  7351. var faceType = 0;
  7352. faceType = setBit( faceType, 0, 0 ); // isQuad
  7353. faceType = setBit( faceType, 1, hasMaterial );
  7354. faceType = setBit( faceType, 2, hasFaceUv );
  7355. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7356. faceType = setBit( faceType, 4, hasFaceNormal );
  7357. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7358. faceType = setBit( faceType, 6, hasFaceColor );
  7359. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7360. faces.push( faceType );
  7361. faces.push( face.a, face.b, face.c );
  7362. faces.push( face.materialIndex );
  7363. if ( hasFaceVertexUv ) {
  7364. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7365. faces.push(
  7366. getUvIndex( faceVertexUvs[ 0 ] ),
  7367. getUvIndex( faceVertexUvs[ 1 ] ),
  7368. getUvIndex( faceVertexUvs[ 2 ] )
  7369. );
  7370. }
  7371. if ( hasFaceNormal ) {
  7372. faces.push( getNormalIndex( face.normal ) );
  7373. }
  7374. if ( hasFaceVertexNormal ) {
  7375. var vertexNormals = face.vertexNormals;
  7376. faces.push(
  7377. getNormalIndex( vertexNormals[ 0 ] ),
  7378. getNormalIndex( vertexNormals[ 1 ] ),
  7379. getNormalIndex( vertexNormals[ 2 ] )
  7380. );
  7381. }
  7382. if ( hasFaceColor ) {
  7383. faces.push( getColorIndex( face.color ) );
  7384. }
  7385. if ( hasFaceVertexColor ) {
  7386. var vertexColors = face.vertexColors;
  7387. faces.push(
  7388. getColorIndex( vertexColors[ 0 ] ),
  7389. getColorIndex( vertexColors[ 1 ] ),
  7390. getColorIndex( vertexColors[ 2 ] )
  7391. );
  7392. }
  7393. }
  7394. function setBit( value, position, enabled ) {
  7395. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7396. }
  7397. function getNormalIndex( normal ) {
  7398. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7399. if ( normalsHash[ hash ] !== undefined ) {
  7400. return normalsHash[ hash ];
  7401. }
  7402. normalsHash[ hash ] = normals.length / 3;
  7403. normals.push( normal.x, normal.y, normal.z );
  7404. return normalsHash[ hash ];
  7405. }
  7406. function getColorIndex( color ) {
  7407. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7408. if ( colorsHash[ hash ] !== undefined ) {
  7409. return colorsHash[ hash ];
  7410. }
  7411. colorsHash[ hash ] = colors.length;
  7412. colors.push( color.getHex() );
  7413. return colorsHash[ hash ];
  7414. }
  7415. function getUvIndex( uv ) {
  7416. var hash = uv.x.toString() + uv.y.toString();
  7417. if ( uvsHash[ hash ] !== undefined ) {
  7418. return uvsHash[ hash ];
  7419. }
  7420. uvsHash[ hash ] = uvs.length / 2;
  7421. uvs.push( uv.x, uv.y );
  7422. return uvsHash[ hash ];
  7423. }
  7424. data.data = {};
  7425. data.data.vertices = vertices;
  7426. data.data.normals = normals;
  7427. if ( colors.length > 0 ) data.data.colors = colors;
  7428. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7429. data.data.faces = faces;
  7430. return data;
  7431. },
  7432. clone: function () {
  7433. /*
  7434. // Handle primitives
  7435. var parameters = this.parameters;
  7436. if ( parameters !== undefined ) {
  7437. var values = [];
  7438. for ( var key in parameters ) {
  7439. values.push( parameters[ key ] );
  7440. }
  7441. var geometry = Object.create( this.constructor.prototype );
  7442. this.constructor.apply( geometry, values );
  7443. return geometry;
  7444. }
  7445. return new this.constructor().copy( this );
  7446. */
  7447. return new Geometry().copy( this );
  7448. },
  7449. copy: function ( source ) {
  7450. var i, il, j, jl, k, kl;
  7451. // reset
  7452. this.vertices = [];
  7453. this.colors = [];
  7454. this.faces = [];
  7455. this.faceVertexUvs = [[]];
  7456. this.morphTargets = [];
  7457. this.morphNormals = [];
  7458. this.skinWeights = [];
  7459. this.skinIndices = [];
  7460. this.lineDistances = [];
  7461. this.boundingBox = null;
  7462. this.boundingSphere = null;
  7463. // name
  7464. this.name = source.name;
  7465. // vertices
  7466. var vertices = source.vertices;
  7467. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7468. this.vertices.push( vertices[ i ].clone() );
  7469. }
  7470. // colors
  7471. var colors = source.colors;
  7472. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7473. this.colors.push( colors[ i ].clone() );
  7474. }
  7475. // faces
  7476. var faces = source.faces;
  7477. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7478. this.faces.push( faces[ i ].clone() );
  7479. }
  7480. // face vertex uvs
  7481. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7482. var faceVertexUvs = source.faceVertexUvs[ i ];
  7483. if ( this.faceVertexUvs[ i ] === undefined ) {
  7484. this.faceVertexUvs[ i ] = [];
  7485. }
  7486. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7487. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7488. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7489. var uv = uvs[ k ];
  7490. uvsCopy.push( uv.clone() );
  7491. }
  7492. this.faceVertexUvs[ i ].push( uvsCopy );
  7493. }
  7494. }
  7495. // morph targets
  7496. var morphTargets = source.morphTargets;
  7497. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7498. var morphTarget = {};
  7499. morphTarget.name = morphTargets[ i ].name;
  7500. // vertices
  7501. if ( morphTargets[ i ].vertices !== undefined ) {
  7502. morphTarget.vertices = [];
  7503. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7504. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7505. }
  7506. }
  7507. // normals
  7508. if ( morphTargets[ i ].normals !== undefined ) {
  7509. morphTarget.normals = [];
  7510. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7511. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7512. }
  7513. }
  7514. this.morphTargets.push( morphTarget );
  7515. }
  7516. // morph normals
  7517. var morphNormals = source.morphNormals;
  7518. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7519. var morphNormal = {};
  7520. // vertex normals
  7521. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7522. morphNormal.vertexNormals = [];
  7523. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7524. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7525. var destVertexNormal = {};
  7526. destVertexNormal.a = srcVertexNormal.a.clone();
  7527. destVertexNormal.b = srcVertexNormal.b.clone();
  7528. destVertexNormal.c = srcVertexNormal.c.clone();
  7529. morphNormal.vertexNormals.push( destVertexNormal );
  7530. }
  7531. }
  7532. // face normals
  7533. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7534. morphNormal.faceNormals = [];
  7535. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7536. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7537. }
  7538. }
  7539. this.morphNormals.push( morphNormal );
  7540. }
  7541. // skin weights
  7542. var skinWeights = source.skinWeights;
  7543. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7544. this.skinWeights.push( skinWeights[ i ].clone() );
  7545. }
  7546. // skin indices
  7547. var skinIndices = source.skinIndices;
  7548. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7549. this.skinIndices.push( skinIndices[ i ].clone() );
  7550. }
  7551. // line distances
  7552. var lineDistances = source.lineDistances;
  7553. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7554. this.lineDistances.push( lineDistances[ i ] );
  7555. }
  7556. // bounding box
  7557. var boundingBox = source.boundingBox;
  7558. if ( boundingBox !== null ) {
  7559. this.boundingBox = boundingBox.clone();
  7560. }
  7561. // bounding sphere
  7562. var boundingSphere = source.boundingSphere;
  7563. if ( boundingSphere !== null ) {
  7564. this.boundingSphere = boundingSphere.clone();
  7565. }
  7566. // update flags
  7567. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7568. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7569. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7570. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7571. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7572. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7573. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7574. return this;
  7575. },
  7576. dispose: function () {
  7577. this.dispatchEvent( { type: 'dispose' } );
  7578. }
  7579. } );
  7580. /**
  7581. * @author mrdoob / http://mrdoob.com/
  7582. * @author Mugen87 / https://github.com/Mugen87
  7583. */
  7584. // BoxGeometry
  7585. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7586. Geometry.call( this );
  7587. this.type = 'BoxGeometry';
  7588. this.parameters = {
  7589. width: width,
  7590. height: height,
  7591. depth: depth,
  7592. widthSegments: widthSegments,
  7593. heightSegments: heightSegments,
  7594. depthSegments: depthSegments
  7595. };
  7596. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7597. this.mergeVertices();
  7598. }
  7599. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7600. BoxGeometry.prototype.constructor = BoxGeometry;
  7601. // BoxBufferGeometry
  7602. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7603. BufferGeometry.call( this );
  7604. this.type = 'BoxBufferGeometry';
  7605. this.parameters = {
  7606. width: width,
  7607. height: height,
  7608. depth: depth,
  7609. widthSegments: widthSegments,
  7610. heightSegments: heightSegments,
  7611. depthSegments: depthSegments
  7612. };
  7613. var scope = this;
  7614. width = width || 1;
  7615. height = height || 1;
  7616. depth = depth || 1;
  7617. // segments
  7618. widthSegments = Math.floor( widthSegments ) || 1;
  7619. heightSegments = Math.floor( heightSegments ) || 1;
  7620. depthSegments = Math.floor( depthSegments ) || 1;
  7621. // buffers
  7622. var indices = [];
  7623. var vertices = [];
  7624. var normals = [];
  7625. var uvs = [];
  7626. // helper variables
  7627. var numberOfVertices = 0;
  7628. var groupStart = 0;
  7629. // build each side of the box geometry
  7630. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7631. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7632. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7633. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7634. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7635. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7636. // build geometry
  7637. this.setIndex( indices );
  7638. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7639. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7640. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7641. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7642. var segmentWidth = width / gridX;
  7643. var segmentHeight = height / gridY;
  7644. var widthHalf = width / 2;
  7645. var heightHalf = height / 2;
  7646. var depthHalf = depth / 2;
  7647. var gridX1 = gridX + 1;
  7648. var gridY1 = gridY + 1;
  7649. var vertexCounter = 0;
  7650. var groupCount = 0;
  7651. var ix, iy;
  7652. var vector = new Vector3();
  7653. // generate vertices, normals and uvs
  7654. for ( iy = 0; iy < gridY1; iy ++ ) {
  7655. var y = iy * segmentHeight - heightHalf;
  7656. for ( ix = 0; ix < gridX1; ix ++ ) {
  7657. var x = ix * segmentWidth - widthHalf;
  7658. // set values to correct vector component
  7659. vector[ u ] = x * udir;
  7660. vector[ v ] = y * vdir;
  7661. vector[ w ] = depthHalf;
  7662. // now apply vector to vertex buffer
  7663. vertices.push( vector.x, vector.y, vector.z );
  7664. // set values to correct vector component
  7665. vector[ u ] = 0;
  7666. vector[ v ] = 0;
  7667. vector[ w ] = depth > 0 ? 1 : - 1;
  7668. // now apply vector to normal buffer
  7669. normals.push( vector.x, vector.y, vector.z );
  7670. // uvs
  7671. uvs.push( ix / gridX );
  7672. uvs.push( 1 - ( iy / gridY ) );
  7673. // counters
  7674. vertexCounter += 1;
  7675. }
  7676. }
  7677. // indices
  7678. // 1. you need three indices to draw a single face
  7679. // 2. a single segment consists of two faces
  7680. // 3. so we need to generate six (2*3) indices per segment
  7681. for ( iy = 0; iy < gridY; iy ++ ) {
  7682. for ( ix = 0; ix < gridX; ix ++ ) {
  7683. var a = numberOfVertices + ix + gridX1 * iy;
  7684. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7685. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7686. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7687. // faces
  7688. indices.push( a, b, d );
  7689. indices.push( b, c, d );
  7690. // increase counter
  7691. groupCount += 6;
  7692. }
  7693. }
  7694. // add a group to the geometry. this will ensure multi material support
  7695. scope.addGroup( groupStart, groupCount, materialIndex );
  7696. // calculate new start value for groups
  7697. groupStart += groupCount;
  7698. // update total number of vertices
  7699. numberOfVertices += vertexCounter;
  7700. }
  7701. }
  7702. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7703. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7704. /**
  7705. * Uniform Utilities
  7706. */
  7707. function cloneUniforms( src ) {
  7708. var dst = {};
  7709. for ( var u in src ) {
  7710. dst[ u ] = {};
  7711. for ( var p in src[ u ] ) {
  7712. var property = src[ u ][ p ];
  7713. if ( property && ( property.isColor ||
  7714. property.isMatrix3 || property.isMatrix4 ||
  7715. property.isVector2 || property.isVector3 || property.isVector4 ||
  7716. property.isTexture ) ) {
  7717. dst[ u ][ p ] = property.clone();
  7718. } else if ( Array.isArray( property ) ) {
  7719. dst[ u ][ p ] = property.slice();
  7720. } else {
  7721. dst[ u ][ p ] = property;
  7722. }
  7723. }
  7724. }
  7725. return dst;
  7726. }
  7727. function mergeUniforms( uniforms ) {
  7728. var merged = {};
  7729. for ( var u = 0; u < uniforms.length; u ++ ) {
  7730. var tmp = cloneUniforms( uniforms[ u ] );
  7731. for ( var p in tmp ) {
  7732. merged[ p ] = tmp[ p ];
  7733. }
  7734. }
  7735. return merged;
  7736. }
  7737. // Legacy
  7738. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7739. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7740. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7741. /**
  7742. * @author alteredq / http://alteredqualia.com/
  7743. *
  7744. * parameters = {
  7745. * defines: { "label" : "value" },
  7746. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7747. *
  7748. * fragmentShader: <string>,
  7749. * vertexShader: <string>,
  7750. *
  7751. * wireframe: <boolean>,
  7752. * wireframeLinewidth: <float>,
  7753. *
  7754. * lights: <bool>,
  7755. *
  7756. * skinning: <bool>,
  7757. * morphTargets: <bool>,
  7758. * morphNormals: <bool>
  7759. * }
  7760. */
  7761. function ShaderMaterial( parameters ) {
  7762. Material.call( this );
  7763. this.type = 'ShaderMaterial';
  7764. this.defines = {};
  7765. this.uniforms = {};
  7766. this.vertexShader = default_vertex;
  7767. this.fragmentShader = default_fragment;
  7768. this.linewidth = 1;
  7769. this.wireframe = false;
  7770. this.wireframeLinewidth = 1;
  7771. this.fog = false; // set to use scene fog
  7772. this.lights = false; // set to use scene lights
  7773. this.clipping = false; // set to use user-defined clipping planes
  7774. this.skinning = false; // set to use skinning attribute streams
  7775. this.morphTargets = false; // set to use morph targets
  7776. this.morphNormals = false; // set to use morph normals
  7777. this.extensions = {
  7778. derivatives: false, // set to use derivatives
  7779. fragDepth: false, // set to use fragment depth values
  7780. drawBuffers: false, // set to use draw buffers
  7781. shaderTextureLOD: false // set to use shader texture LOD
  7782. };
  7783. // When rendered geometry doesn't include these attributes but the material does,
  7784. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7785. this.defaultAttributeValues = {
  7786. 'color': [ 1, 1, 1 ],
  7787. 'uv': [ 0, 0 ],
  7788. 'uv2': [ 0, 0 ]
  7789. };
  7790. this.index0AttributeName = undefined;
  7791. this.uniformsNeedUpdate = false;
  7792. if ( parameters !== undefined ) {
  7793. if ( parameters.attributes !== undefined ) {
  7794. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7795. }
  7796. this.setValues( parameters );
  7797. }
  7798. }
  7799. ShaderMaterial.prototype = Object.create( Material.prototype );
  7800. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7801. ShaderMaterial.prototype.isShaderMaterial = true;
  7802. ShaderMaterial.prototype.copy = function ( source ) {
  7803. Material.prototype.copy.call( this, source );
  7804. this.fragmentShader = source.fragmentShader;
  7805. this.vertexShader = source.vertexShader;
  7806. this.uniforms = cloneUniforms( source.uniforms );
  7807. this.defines = Object.assign( {}, source.defines );
  7808. this.wireframe = source.wireframe;
  7809. this.wireframeLinewidth = source.wireframeLinewidth;
  7810. this.lights = source.lights;
  7811. this.clipping = source.clipping;
  7812. this.skinning = source.skinning;
  7813. this.morphTargets = source.morphTargets;
  7814. this.morphNormals = source.morphNormals;
  7815. this.extensions = source.extensions;
  7816. return this;
  7817. };
  7818. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7819. var data = Material.prototype.toJSON.call( this, meta );
  7820. data.uniforms = {};
  7821. for ( var name in this.uniforms ) {
  7822. var uniform = this.uniforms[ name ];
  7823. var value = uniform.value;
  7824. if ( value && value.isTexture ) {
  7825. data.uniforms[ name ] = {
  7826. type: 't',
  7827. value: value.toJSON( meta ).uuid
  7828. };
  7829. } else if ( value && value.isColor ) {
  7830. data.uniforms[ name ] = {
  7831. type: 'c',
  7832. value: value.getHex()
  7833. };
  7834. } else if ( value && value.isVector2 ) {
  7835. data.uniforms[ name ] = {
  7836. type: 'v2',
  7837. value: value.toArray()
  7838. };
  7839. } else if ( value && value.isVector3 ) {
  7840. data.uniforms[ name ] = {
  7841. type: 'v3',
  7842. value: value.toArray()
  7843. };
  7844. } else if ( value && value.isVector4 ) {
  7845. data.uniforms[ name ] = {
  7846. type: 'v4',
  7847. value: value.toArray()
  7848. };
  7849. } else if ( value && value.isMatrix3 ) {
  7850. data.uniforms[ name ] = {
  7851. type: 'm3',
  7852. value: value.toArray()
  7853. };
  7854. } else if ( value && value.isMatrix4 ) {
  7855. data.uniforms[ name ] = {
  7856. type: 'm4',
  7857. value: value.toArray()
  7858. };
  7859. } else {
  7860. data.uniforms[ name ] = {
  7861. value: value
  7862. };
  7863. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7864. }
  7865. }
  7866. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7867. data.vertexShader = this.vertexShader;
  7868. data.fragmentShader = this.fragmentShader;
  7869. var extensions = {};
  7870. for ( var key in this.extensions ) {
  7871. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7872. }
  7873. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7874. return data;
  7875. };
  7876. /**
  7877. * @author mrdoob / http://mrdoob.com/
  7878. * @author mikael emtinger / http://gomo.se/
  7879. * @author WestLangley / http://github.com/WestLangley
  7880. */
  7881. function Camera() {
  7882. Object3D.call( this );
  7883. this.type = 'Camera';
  7884. this.matrixWorldInverse = new Matrix4();
  7885. this.projectionMatrix = new Matrix4();
  7886. this.projectionMatrixInverse = new Matrix4();
  7887. }
  7888. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7889. constructor: Camera,
  7890. isCamera: true,
  7891. copy: function ( source, recursive ) {
  7892. Object3D.prototype.copy.call( this, source, recursive );
  7893. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7894. this.projectionMatrix.copy( source.projectionMatrix );
  7895. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7896. return this;
  7897. },
  7898. getWorldDirection: function ( target ) {
  7899. if ( target === undefined ) {
  7900. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7901. target = new Vector3();
  7902. }
  7903. this.updateMatrixWorld( true );
  7904. var e = this.matrixWorld.elements;
  7905. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7906. },
  7907. updateMatrixWorld: function ( force ) {
  7908. Object3D.prototype.updateMatrixWorld.call( this, force );
  7909. this.matrixWorldInverse.getInverse( this.matrixWorld );
  7910. },
  7911. clone: function () {
  7912. return new this.constructor().copy( this );
  7913. }
  7914. } );
  7915. /**
  7916. * @author mrdoob / http://mrdoob.com/
  7917. * @author greggman / http://games.greggman.com/
  7918. * @author zz85 / http://www.lab4games.net/zz85/blog
  7919. * @author tschw
  7920. */
  7921. function PerspectiveCamera( fov, aspect, near, far ) {
  7922. Camera.call( this );
  7923. this.type = 'PerspectiveCamera';
  7924. this.fov = fov !== undefined ? fov : 50;
  7925. this.zoom = 1;
  7926. this.near = near !== undefined ? near : 0.1;
  7927. this.far = far !== undefined ? far : 2000;
  7928. this.focus = 10;
  7929. this.aspect = aspect !== undefined ? aspect : 1;
  7930. this.view = null;
  7931. this.filmGauge = 35; // width of the film (default in millimeters)
  7932. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7933. this.updateProjectionMatrix();
  7934. }
  7935. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7936. constructor: PerspectiveCamera,
  7937. isPerspectiveCamera: true,
  7938. copy: function ( source, recursive ) {
  7939. Camera.prototype.copy.call( this, source, recursive );
  7940. this.fov = source.fov;
  7941. this.zoom = source.zoom;
  7942. this.near = source.near;
  7943. this.far = source.far;
  7944. this.focus = source.focus;
  7945. this.aspect = source.aspect;
  7946. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7947. this.filmGauge = source.filmGauge;
  7948. this.filmOffset = source.filmOffset;
  7949. return this;
  7950. },
  7951. /**
  7952. * Sets the FOV by focal length in respect to the current .filmGauge.
  7953. *
  7954. * The default film gauge is 35, so that the focal length can be specified for
  7955. * a 35mm (full frame) camera.
  7956. *
  7957. * Values for focal length and film gauge must have the same unit.
  7958. */
  7959. setFocalLength: function ( focalLength ) {
  7960. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7961. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7962. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7963. this.updateProjectionMatrix();
  7964. },
  7965. /**
  7966. * Calculates the focal length from the current .fov and .filmGauge.
  7967. */
  7968. getFocalLength: function () {
  7969. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  7970. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7971. },
  7972. getEffectiveFOV: function () {
  7973. return _Math.RAD2DEG * 2 * Math.atan(
  7974. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7975. },
  7976. getFilmWidth: function () {
  7977. // film not completely covered in portrait format (aspect < 1)
  7978. return this.filmGauge * Math.min( this.aspect, 1 );
  7979. },
  7980. getFilmHeight: function () {
  7981. // film not completely covered in landscape format (aspect > 1)
  7982. return this.filmGauge / Math.max( this.aspect, 1 );
  7983. },
  7984. /**
  7985. * Sets an offset in a larger frustum. This is useful for multi-window or
  7986. * multi-monitor/multi-machine setups.
  7987. *
  7988. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7989. * the monitors are in grid like this
  7990. *
  7991. * +---+---+---+
  7992. * | A | B | C |
  7993. * +---+---+---+
  7994. * | D | E | F |
  7995. * +---+---+---+
  7996. *
  7997. * then for each monitor you would call it like this
  7998. *
  7999. * var w = 1920;
  8000. * var h = 1080;
  8001. * var fullWidth = w * 3;
  8002. * var fullHeight = h * 2;
  8003. *
  8004. * --A--
  8005. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8006. * --B--
  8007. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8008. * --C--
  8009. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8010. * --D--
  8011. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8012. * --E--
  8013. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8014. * --F--
  8015. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8016. *
  8017. * Note there is no reason monitors have to be the same size or in a grid.
  8018. */
  8019. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  8020. this.aspect = fullWidth / fullHeight;
  8021. if ( this.view === null ) {
  8022. this.view = {
  8023. enabled: true,
  8024. fullWidth: 1,
  8025. fullHeight: 1,
  8026. offsetX: 0,
  8027. offsetY: 0,
  8028. width: 1,
  8029. height: 1
  8030. };
  8031. }
  8032. this.view.enabled = true;
  8033. this.view.fullWidth = fullWidth;
  8034. this.view.fullHeight = fullHeight;
  8035. this.view.offsetX = x;
  8036. this.view.offsetY = y;
  8037. this.view.width = width;
  8038. this.view.height = height;
  8039. this.updateProjectionMatrix();
  8040. },
  8041. clearViewOffset: function () {
  8042. if ( this.view !== null ) {
  8043. this.view.enabled = false;
  8044. }
  8045. this.updateProjectionMatrix();
  8046. },
  8047. updateProjectionMatrix: function () {
  8048. var near = this.near,
  8049. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8050. height = 2 * top,
  8051. width = this.aspect * height,
  8052. left = - 0.5 * width,
  8053. view = this.view;
  8054. if ( this.view !== null && this.view.enabled ) {
  8055. var fullWidth = view.fullWidth,
  8056. fullHeight = view.fullHeight;
  8057. left += view.offsetX * width / fullWidth;
  8058. top -= view.offsetY * height / fullHeight;
  8059. width *= view.width / fullWidth;
  8060. height *= view.height / fullHeight;
  8061. }
  8062. var skew = this.filmOffset;
  8063. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8064. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8065. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8066. },
  8067. toJSON: function ( meta ) {
  8068. var data = Object3D.prototype.toJSON.call( this, meta );
  8069. data.object.fov = this.fov;
  8070. data.object.zoom = this.zoom;
  8071. data.object.near = this.near;
  8072. data.object.far = this.far;
  8073. data.object.focus = this.focus;
  8074. data.object.aspect = this.aspect;
  8075. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8076. data.object.filmGauge = this.filmGauge;
  8077. data.object.filmOffset = this.filmOffset;
  8078. return data;
  8079. }
  8080. } );
  8081. /**
  8082. * Camera for rendering cube maps
  8083. * - renders scene into axis-aligned cube
  8084. *
  8085. * @author alteredq / http://alteredqualia.com/
  8086. */
  8087. var fov = 90, aspect = 1;
  8088. function CubeCamera( near, far, cubeResolution, options ) {
  8089. Object3D.call( this );
  8090. this.type = 'CubeCamera';
  8091. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8092. cameraPX.up.set( 0, - 1, 0 );
  8093. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8094. this.add( cameraPX );
  8095. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8096. cameraNX.up.set( 0, - 1, 0 );
  8097. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8098. this.add( cameraNX );
  8099. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8100. cameraPY.up.set( 0, 0, 1 );
  8101. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8102. this.add( cameraPY );
  8103. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8104. cameraNY.up.set( 0, 0, - 1 );
  8105. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8106. this.add( cameraNY );
  8107. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8108. cameraPZ.up.set( 0, - 1, 0 );
  8109. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8110. this.add( cameraPZ );
  8111. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8112. cameraNZ.up.set( 0, - 1, 0 );
  8113. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8114. this.add( cameraNZ );
  8115. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  8116. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  8117. this.renderTarget.texture.name = "CubeCamera";
  8118. this.update = function ( renderer, scene ) {
  8119. if ( this.parent === null ) this.updateMatrixWorld();
  8120. var currentRenderTarget = renderer.getRenderTarget();
  8121. var renderTarget = this.renderTarget;
  8122. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8123. renderTarget.texture.generateMipmaps = false;
  8124. renderer.setRenderTarget( renderTarget, 0 );
  8125. renderer.render( scene, cameraPX );
  8126. renderer.setRenderTarget( renderTarget, 1 );
  8127. renderer.render( scene, cameraNX );
  8128. renderer.setRenderTarget( renderTarget, 2 );
  8129. renderer.render( scene, cameraPY );
  8130. renderer.setRenderTarget( renderTarget, 3 );
  8131. renderer.render( scene, cameraNY );
  8132. renderer.setRenderTarget( renderTarget, 4 );
  8133. renderer.render( scene, cameraPZ );
  8134. renderTarget.texture.generateMipmaps = generateMipmaps;
  8135. renderer.setRenderTarget( renderTarget, 5 );
  8136. renderer.render( scene, cameraNZ );
  8137. renderer.setRenderTarget( currentRenderTarget );
  8138. };
  8139. this.clear = function ( renderer, color, depth, stencil ) {
  8140. var currentRenderTarget = renderer.getRenderTarget();
  8141. var renderTarget = this.renderTarget;
  8142. for ( var i = 0; i < 6; i ++ ) {
  8143. renderer.setRenderTarget( renderTarget, i );
  8144. renderer.clear( color, depth, stencil );
  8145. }
  8146. renderer.setRenderTarget( currentRenderTarget );
  8147. };
  8148. }
  8149. CubeCamera.prototype = Object.create( Object3D.prototype );
  8150. CubeCamera.prototype.constructor = CubeCamera;
  8151. /**
  8152. * @author alteredq / http://alteredqualia.com
  8153. * @author WestLangley / http://github.com/WestLangley
  8154. */
  8155. function WebGLRenderTargetCube( width, height, options ) {
  8156. WebGLRenderTarget.call( this, width, height, options );
  8157. }
  8158. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  8159. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  8160. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  8161. WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8162. this.texture.type = texture.type;
  8163. this.texture.format = texture.format;
  8164. this.texture.encoding = texture.encoding;
  8165. var scene = new Scene();
  8166. var shader = {
  8167. uniforms: {
  8168. tEquirect: { value: null },
  8169. },
  8170. vertexShader: [
  8171. "varying vec3 vWorldDirection;",
  8172. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8173. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8174. "}",
  8175. "void main() {",
  8176. " vWorldDirection = transformDirection( position, modelMatrix );",
  8177. " #include <begin_vertex>",
  8178. " #include <project_vertex>",
  8179. "}"
  8180. ].join( '\n' ),
  8181. fragmentShader: [
  8182. "uniform sampler2D tEquirect;",
  8183. "varying vec3 vWorldDirection;",
  8184. "#define RECIPROCAL_PI 0.31830988618",
  8185. "#define RECIPROCAL_PI2 0.15915494",
  8186. "void main() {",
  8187. " vec3 direction = normalize( vWorldDirection );",
  8188. " vec2 sampleUV;",
  8189. " sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
  8190. " sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  8191. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8192. "}"
  8193. ].join( '\n' ),
  8194. };
  8195. var material = new ShaderMaterial( {
  8196. type: 'CubemapFromEquirect',
  8197. uniforms: cloneUniforms( shader.uniforms ),
  8198. vertexShader: shader.vertexShader,
  8199. fragmentShader: shader.fragmentShader,
  8200. side: BackSide,
  8201. blending: NoBlending
  8202. } );
  8203. material.uniforms.tEquirect.value = texture;
  8204. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8205. scene.add( mesh );
  8206. var camera = new CubeCamera( 1, 10, 1 );
  8207. camera.renderTarget = this;
  8208. camera.renderTarget.texture.name = 'CubeCameraTexture';
  8209. camera.update( renderer, scene );
  8210. mesh.geometry.dispose();
  8211. mesh.material.dispose();
  8212. return this;
  8213. };
  8214. /**
  8215. * @author alteredq / http://alteredqualia.com/
  8216. */
  8217. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8218. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8219. this.image = { data: data, width: width, height: height };
  8220. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8221. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8222. this.generateMipmaps = false;
  8223. this.flipY = false;
  8224. this.unpackAlignment = 1;
  8225. }
  8226. DataTexture.prototype = Object.create( Texture.prototype );
  8227. DataTexture.prototype.constructor = DataTexture;
  8228. DataTexture.prototype.isDataTexture = true;
  8229. /**
  8230. * @author bhouston / http://clara.io
  8231. */
  8232. function Plane( normal, constant ) {
  8233. // normal is assumed to be normalized
  8234. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  8235. this.constant = ( constant !== undefined ) ? constant : 0;
  8236. }
  8237. Object.assign( Plane.prototype, {
  8238. isPlane: true,
  8239. set: function ( normal, constant ) {
  8240. this.normal.copy( normal );
  8241. this.constant = constant;
  8242. return this;
  8243. },
  8244. setComponents: function ( x, y, z, w ) {
  8245. this.normal.set( x, y, z );
  8246. this.constant = w;
  8247. return this;
  8248. },
  8249. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  8250. this.normal.copy( normal );
  8251. this.constant = - point.dot( this.normal );
  8252. return this;
  8253. },
  8254. setFromCoplanarPoints: function () {
  8255. var v1 = new Vector3();
  8256. var v2 = new Vector3();
  8257. return function setFromCoplanarPoints( a, b, c ) {
  8258. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  8259. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8260. this.setFromNormalAndCoplanarPoint( normal, a );
  8261. return this;
  8262. };
  8263. }(),
  8264. clone: function () {
  8265. return new this.constructor().copy( this );
  8266. },
  8267. copy: function ( plane ) {
  8268. this.normal.copy( plane.normal );
  8269. this.constant = plane.constant;
  8270. return this;
  8271. },
  8272. normalize: function () {
  8273. // Note: will lead to a divide by zero if the plane is invalid.
  8274. var inverseNormalLength = 1.0 / this.normal.length();
  8275. this.normal.multiplyScalar( inverseNormalLength );
  8276. this.constant *= inverseNormalLength;
  8277. return this;
  8278. },
  8279. negate: function () {
  8280. this.constant *= - 1;
  8281. this.normal.negate();
  8282. return this;
  8283. },
  8284. distanceToPoint: function ( point ) {
  8285. return this.normal.dot( point ) + this.constant;
  8286. },
  8287. distanceToSphere: function ( sphere ) {
  8288. return this.distanceToPoint( sphere.center ) - sphere.radius;
  8289. },
  8290. projectPoint: function ( point, target ) {
  8291. if ( target === undefined ) {
  8292. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  8293. target = new Vector3();
  8294. }
  8295. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  8296. },
  8297. intersectLine: function () {
  8298. var v1 = new Vector3();
  8299. return function intersectLine( line, target ) {
  8300. if ( target === undefined ) {
  8301. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  8302. target = new Vector3();
  8303. }
  8304. var direction = line.delta( v1 );
  8305. var denominator = this.normal.dot( direction );
  8306. if ( denominator === 0 ) {
  8307. // line is coplanar, return origin
  8308. if ( this.distanceToPoint( line.start ) === 0 ) {
  8309. return target.copy( line.start );
  8310. }
  8311. // Unsure if this is the correct method to handle this case.
  8312. return undefined;
  8313. }
  8314. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  8315. if ( t < 0 || t > 1 ) {
  8316. return undefined;
  8317. }
  8318. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  8319. };
  8320. }(),
  8321. intersectsLine: function ( line ) {
  8322. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  8323. var startSign = this.distanceToPoint( line.start );
  8324. var endSign = this.distanceToPoint( line.end );
  8325. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  8326. },
  8327. intersectsBox: function ( box ) {
  8328. return box.intersectsPlane( this );
  8329. },
  8330. intersectsSphere: function ( sphere ) {
  8331. return sphere.intersectsPlane( this );
  8332. },
  8333. coplanarPoint: function ( target ) {
  8334. if ( target === undefined ) {
  8335. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  8336. target = new Vector3();
  8337. }
  8338. return target.copy( this.normal ).multiplyScalar( - this.constant );
  8339. },
  8340. applyMatrix4: function () {
  8341. var v1 = new Vector3();
  8342. var m1 = new Matrix3();
  8343. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  8344. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  8345. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  8346. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  8347. this.constant = - referencePoint.dot( normal );
  8348. return this;
  8349. };
  8350. }(),
  8351. translate: function ( offset ) {
  8352. this.constant -= offset.dot( this.normal );
  8353. return this;
  8354. },
  8355. equals: function ( plane ) {
  8356. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  8357. }
  8358. } );
  8359. /**
  8360. * @author mrdoob / http://mrdoob.com/
  8361. * @author alteredq / http://alteredqualia.com/
  8362. * @author bhouston / http://clara.io
  8363. */
  8364. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8365. this.planes = [
  8366. ( p0 !== undefined ) ? p0 : new Plane(),
  8367. ( p1 !== undefined ) ? p1 : new Plane(),
  8368. ( p2 !== undefined ) ? p2 : new Plane(),
  8369. ( p3 !== undefined ) ? p3 : new Plane(),
  8370. ( p4 !== undefined ) ? p4 : new Plane(),
  8371. ( p5 !== undefined ) ? p5 : new Plane()
  8372. ];
  8373. }
  8374. Object.assign( Frustum.prototype, {
  8375. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8376. var planes = this.planes;
  8377. planes[ 0 ].copy( p0 );
  8378. planes[ 1 ].copy( p1 );
  8379. planes[ 2 ].copy( p2 );
  8380. planes[ 3 ].copy( p3 );
  8381. planes[ 4 ].copy( p4 );
  8382. planes[ 5 ].copy( p5 );
  8383. return this;
  8384. },
  8385. clone: function () {
  8386. return new this.constructor().copy( this );
  8387. },
  8388. copy: function ( frustum ) {
  8389. var planes = this.planes;
  8390. for ( var i = 0; i < 6; i ++ ) {
  8391. planes[ i ].copy( frustum.planes[ i ] );
  8392. }
  8393. return this;
  8394. },
  8395. setFromMatrix: function ( m ) {
  8396. var planes = this.planes;
  8397. var me = m.elements;
  8398. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8399. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8400. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8401. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8402. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8403. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8404. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8405. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8406. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8407. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8408. return this;
  8409. },
  8410. intersectsObject: function () {
  8411. var sphere = new Sphere();
  8412. return function intersectsObject( object ) {
  8413. var geometry = object.geometry;
  8414. if ( geometry.boundingSphere === null )
  8415. geometry.computeBoundingSphere();
  8416. sphere.copy( geometry.boundingSphere )
  8417. .applyMatrix4( object.matrixWorld );
  8418. return this.intersectsSphere( sphere );
  8419. };
  8420. }(),
  8421. intersectsSprite: function () {
  8422. var sphere = new Sphere();
  8423. return function intersectsSprite( sprite ) {
  8424. sphere.center.set( 0, 0, 0 );
  8425. sphere.radius = 0.7071067811865476;
  8426. sphere.applyMatrix4( sprite.matrixWorld );
  8427. return this.intersectsSphere( sphere );
  8428. };
  8429. }(),
  8430. intersectsSphere: function ( sphere ) {
  8431. var planes = this.planes;
  8432. var center = sphere.center;
  8433. var negRadius = - sphere.radius;
  8434. for ( var i = 0; i < 6; i ++ ) {
  8435. var distance = planes[ i ].distanceToPoint( center );
  8436. if ( distance < negRadius ) {
  8437. return false;
  8438. }
  8439. }
  8440. return true;
  8441. },
  8442. intersectsBox: function () {
  8443. var p = new Vector3();
  8444. return function intersectsBox( box ) {
  8445. var planes = this.planes;
  8446. for ( var i = 0; i < 6; i ++ ) {
  8447. var plane = planes[ i ];
  8448. // corner at max distance
  8449. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8450. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8451. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8452. if ( plane.distanceToPoint( p ) < 0 ) {
  8453. return false;
  8454. }
  8455. }
  8456. return true;
  8457. };
  8458. }(),
  8459. containsPoint: function ( point ) {
  8460. var planes = this.planes;
  8461. for ( var i = 0; i < 6; i ++ ) {
  8462. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8463. return false;
  8464. }
  8465. }
  8466. return true;
  8467. }
  8468. } );
  8469. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8470. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8471. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8472. 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";
  8473. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8474. var begin_vertex = "vec3 transformed = vec3( position );";
  8475. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8476. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in 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_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}";
  8477. 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";
  8478. 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";
  8479. 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";
  8480. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  8481. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  8482. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8483. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8484. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8485. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8486. 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}";
  8487. 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";
  8488. 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";
  8489. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8490. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  8491. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8492. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8493. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8494. 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}";
  8495. 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";
  8496. 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";
  8497. 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";
  8498. 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";
  8499. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8500. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8501. 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";
  8502. 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";
  8503. 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";
  8504. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  8505. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8506. 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";
  8507. var lights_pars_begin = "uniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t\tfloat shadowCameraNear;\n\t\tfloat shadowCameraFar;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  8508. 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";
  8509. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8510. 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)";
  8511. 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";
  8512. 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 * ( 1.0 - ( singleScattering + multiScattering ) );\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}";
  8513. 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\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearCoatRadiance = vec3( 0.0 );\n#endif";
  8514. 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";
  8515. 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";
  8516. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  8517. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  8518. 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";
  8519. 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";
  8520. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8521. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8522. 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";
  8523. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  8524. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8525. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8526. 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";
  8527. 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";
  8528. 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";
  8529. 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";
  8530. 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";
  8531. 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";
  8532. 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}";
  8533. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8534. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  8535. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8536. 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";
  8537. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8538. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8539. 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\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
  8540. 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";
  8541. 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";
  8542. 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}";
  8543. 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";
  8544. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  8545. 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";
  8546. 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";
  8547. 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";
  8548. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8549. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8550. 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}";
  8551. 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";
  8552. 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";
  8553. 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";
  8554. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8555. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  8556. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  8557. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  8558. 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}";
  8559. 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}";
  8560. 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}";
  8561. 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}";
  8562. 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}";
  8563. 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}";
  8564. 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}";
  8565. 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}";
  8566. 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}";
  8567. 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}";
  8568. 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}";
  8569. 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}";
  8570. 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}";
  8571. 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}";
  8572. 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}";
  8573. 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}";
  8574. 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}";
  8575. 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}";
  8576. 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}";
  8577. 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}";
  8578. 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}";
  8579. 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}";
  8580. 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>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  8581. 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>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  8582. 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}";
  8583. 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}";
  8584. 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}";
  8585. 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}";
  8586. 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}";
  8587. 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}";
  8588. var ShaderChunk = {
  8589. alphamap_fragment: alphamap_fragment,
  8590. alphamap_pars_fragment: alphamap_pars_fragment,
  8591. alphatest_fragment: alphatest_fragment,
  8592. aomap_fragment: aomap_fragment,
  8593. aomap_pars_fragment: aomap_pars_fragment,
  8594. begin_vertex: begin_vertex,
  8595. beginnormal_vertex: beginnormal_vertex,
  8596. bsdfs: bsdfs,
  8597. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8598. clipping_planes_fragment: clipping_planes_fragment,
  8599. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8600. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8601. clipping_planes_vertex: clipping_planes_vertex,
  8602. color_fragment: color_fragment,
  8603. color_pars_fragment: color_pars_fragment,
  8604. color_pars_vertex: color_pars_vertex,
  8605. color_vertex: color_vertex,
  8606. common: common,
  8607. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8608. defaultnormal_vertex: defaultnormal_vertex,
  8609. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8610. displacementmap_vertex: displacementmap_vertex,
  8611. emissivemap_fragment: emissivemap_fragment,
  8612. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8613. encodings_fragment: encodings_fragment,
  8614. encodings_pars_fragment: encodings_pars_fragment,
  8615. envmap_fragment: envmap_fragment,
  8616. envmap_pars_fragment: envmap_pars_fragment,
  8617. envmap_pars_vertex: envmap_pars_vertex,
  8618. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8619. envmap_vertex: envmap_vertex,
  8620. fog_vertex: fog_vertex,
  8621. fog_pars_vertex: fog_pars_vertex,
  8622. fog_fragment: fog_fragment,
  8623. fog_pars_fragment: fog_pars_fragment,
  8624. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8625. lightmap_fragment: lightmap_fragment,
  8626. lightmap_pars_fragment: lightmap_pars_fragment,
  8627. lights_lambert_vertex: lights_lambert_vertex,
  8628. lights_pars_begin: lights_pars_begin,
  8629. lights_phong_fragment: lights_phong_fragment,
  8630. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8631. lights_physical_fragment: lights_physical_fragment,
  8632. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8633. lights_fragment_begin: lights_fragment_begin,
  8634. lights_fragment_maps: lights_fragment_maps,
  8635. lights_fragment_end: lights_fragment_end,
  8636. logdepthbuf_fragment: logdepthbuf_fragment,
  8637. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8638. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8639. logdepthbuf_vertex: logdepthbuf_vertex,
  8640. map_fragment: map_fragment,
  8641. map_pars_fragment: map_pars_fragment,
  8642. map_particle_fragment: map_particle_fragment,
  8643. map_particle_pars_fragment: map_particle_pars_fragment,
  8644. metalnessmap_fragment: metalnessmap_fragment,
  8645. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8646. morphnormal_vertex: morphnormal_vertex,
  8647. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8648. morphtarget_vertex: morphtarget_vertex,
  8649. normal_fragment_begin: normal_fragment_begin,
  8650. normal_fragment_maps: normal_fragment_maps,
  8651. normalmap_pars_fragment: normalmap_pars_fragment,
  8652. packing: packing,
  8653. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8654. project_vertex: project_vertex,
  8655. dithering_fragment: dithering_fragment,
  8656. dithering_pars_fragment: dithering_pars_fragment,
  8657. roughnessmap_fragment: roughnessmap_fragment,
  8658. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8659. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8660. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8661. shadowmap_vertex: shadowmap_vertex,
  8662. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8663. skinbase_vertex: skinbase_vertex,
  8664. skinning_pars_vertex: skinning_pars_vertex,
  8665. skinning_vertex: skinning_vertex,
  8666. skinnormal_vertex: skinnormal_vertex,
  8667. specularmap_fragment: specularmap_fragment,
  8668. specularmap_pars_fragment: specularmap_pars_fragment,
  8669. tonemapping_fragment: tonemapping_fragment,
  8670. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8671. uv_pars_fragment: uv_pars_fragment,
  8672. uv_pars_vertex: uv_pars_vertex,
  8673. uv_vertex: uv_vertex,
  8674. uv2_pars_fragment: uv2_pars_fragment,
  8675. uv2_pars_vertex: uv2_pars_vertex,
  8676. uv2_vertex: uv2_vertex,
  8677. worldpos_vertex: worldpos_vertex,
  8678. background_frag: background_frag,
  8679. background_vert: background_vert,
  8680. cube_frag: cube_frag,
  8681. cube_vert: cube_vert,
  8682. depth_frag: depth_frag,
  8683. depth_vert: depth_vert,
  8684. distanceRGBA_frag: distanceRGBA_frag,
  8685. distanceRGBA_vert: distanceRGBA_vert,
  8686. equirect_frag: equirect_frag,
  8687. equirect_vert: equirect_vert,
  8688. linedashed_frag: linedashed_frag,
  8689. linedashed_vert: linedashed_vert,
  8690. meshbasic_frag: meshbasic_frag,
  8691. meshbasic_vert: meshbasic_vert,
  8692. meshlambert_frag: meshlambert_frag,
  8693. meshlambert_vert: meshlambert_vert,
  8694. meshmatcap_frag: meshmatcap_frag,
  8695. meshmatcap_vert: meshmatcap_vert,
  8696. meshphong_frag: meshphong_frag,
  8697. meshphong_vert: meshphong_vert,
  8698. meshphysical_frag: meshphysical_frag,
  8699. meshphysical_vert: meshphysical_vert,
  8700. normal_frag: normal_frag,
  8701. normal_vert: normal_vert,
  8702. points_frag: points_frag,
  8703. points_vert: points_vert,
  8704. shadow_frag: shadow_frag,
  8705. shadow_vert: shadow_vert,
  8706. sprite_frag: sprite_frag,
  8707. sprite_vert: sprite_vert
  8708. };
  8709. /**
  8710. * Uniforms library for shared webgl shaders
  8711. */
  8712. var UniformsLib = {
  8713. common: {
  8714. diffuse: { value: new Color( 0xeeeeee ) },
  8715. opacity: { value: 1.0 },
  8716. map: { value: null },
  8717. uvTransform: { value: new Matrix3() },
  8718. alphaMap: { value: null },
  8719. },
  8720. specularmap: {
  8721. specularMap: { value: null },
  8722. },
  8723. envmap: {
  8724. envMap: { value: null },
  8725. flipEnvMap: { value: - 1 },
  8726. reflectivity: { value: 1.0 },
  8727. refractionRatio: { value: 0.98 },
  8728. maxMipLevel: { value: 0 }
  8729. },
  8730. aomap: {
  8731. aoMap: { value: null },
  8732. aoMapIntensity: { value: 1 }
  8733. },
  8734. lightmap: {
  8735. lightMap: { value: null },
  8736. lightMapIntensity: { value: 1 }
  8737. },
  8738. emissivemap: {
  8739. emissiveMap: { value: null }
  8740. },
  8741. bumpmap: {
  8742. bumpMap: { value: null },
  8743. bumpScale: { value: 1 }
  8744. },
  8745. normalmap: {
  8746. normalMap: { value: null },
  8747. normalScale: { value: new Vector2( 1, 1 ) }
  8748. },
  8749. displacementmap: {
  8750. displacementMap: { value: null },
  8751. displacementScale: { value: 1 },
  8752. displacementBias: { value: 0 }
  8753. },
  8754. roughnessmap: {
  8755. roughnessMap: { value: null }
  8756. },
  8757. metalnessmap: {
  8758. metalnessMap: { value: null }
  8759. },
  8760. gradientmap: {
  8761. gradientMap: { value: null }
  8762. },
  8763. fog: {
  8764. fogDensity: { value: 0.00025 },
  8765. fogNear: { value: 1 },
  8766. fogFar: { value: 2000 },
  8767. fogColor: { value: new Color( 0xffffff ) }
  8768. },
  8769. lights: {
  8770. ambientLightColor: { value: [] },
  8771. lightProbe: { value: [] },
  8772. directionalLights: { value: [], properties: {
  8773. direction: {},
  8774. color: {},
  8775. shadow: {},
  8776. shadowBias: {},
  8777. shadowRadius: {},
  8778. shadowMapSize: {}
  8779. } },
  8780. directionalShadowMap: { value: [] },
  8781. directionalShadowMatrix: { value: [] },
  8782. spotLights: { value: [], properties: {
  8783. color: {},
  8784. position: {},
  8785. direction: {},
  8786. distance: {},
  8787. coneCos: {},
  8788. penumbraCos: {},
  8789. decay: {},
  8790. shadow: {},
  8791. shadowBias: {},
  8792. shadowRadius: {},
  8793. shadowMapSize: {}
  8794. } },
  8795. spotShadowMap: { value: [] },
  8796. spotShadowMatrix: { value: [] },
  8797. pointLights: { value: [], properties: {
  8798. color: {},
  8799. position: {},
  8800. decay: {},
  8801. distance: {},
  8802. shadow: {},
  8803. shadowBias: {},
  8804. shadowRadius: {},
  8805. shadowMapSize: {},
  8806. shadowCameraNear: {},
  8807. shadowCameraFar: {}
  8808. } },
  8809. pointShadowMap: { value: [] },
  8810. pointShadowMatrix: { value: [] },
  8811. hemisphereLights: { value: [], properties: {
  8812. direction: {},
  8813. skyColor: {},
  8814. groundColor: {}
  8815. } },
  8816. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8817. rectAreaLights: { value: [], properties: {
  8818. color: {},
  8819. position: {},
  8820. width: {},
  8821. height: {}
  8822. } }
  8823. },
  8824. points: {
  8825. diffuse: { value: new Color( 0xeeeeee ) },
  8826. opacity: { value: 1.0 },
  8827. size: { value: 1.0 },
  8828. scale: { value: 1.0 },
  8829. map: { value: null },
  8830. uvTransform: { value: new Matrix3() }
  8831. },
  8832. sprite: {
  8833. diffuse: { value: new Color( 0xeeeeee ) },
  8834. opacity: { value: 1.0 },
  8835. center: { value: new Vector2( 0.5, 0.5 ) },
  8836. rotation: { value: 0.0 },
  8837. map: { value: null },
  8838. uvTransform: { value: new Matrix3() }
  8839. }
  8840. };
  8841. /**
  8842. * @author alteredq / http://alteredqualia.com/
  8843. * @author mrdoob / http://mrdoob.com/
  8844. * @author mikael emtinger / http://gomo.se/
  8845. */
  8846. var ShaderLib = {
  8847. basic: {
  8848. uniforms: mergeUniforms( [
  8849. UniformsLib.common,
  8850. UniformsLib.specularmap,
  8851. UniformsLib.envmap,
  8852. UniformsLib.aomap,
  8853. UniformsLib.lightmap,
  8854. UniformsLib.fog
  8855. ] ),
  8856. vertexShader: ShaderChunk.meshbasic_vert,
  8857. fragmentShader: ShaderChunk.meshbasic_frag
  8858. },
  8859. lambert: {
  8860. uniforms: mergeUniforms( [
  8861. UniformsLib.common,
  8862. UniformsLib.specularmap,
  8863. UniformsLib.envmap,
  8864. UniformsLib.aomap,
  8865. UniformsLib.lightmap,
  8866. UniformsLib.emissivemap,
  8867. UniformsLib.fog,
  8868. UniformsLib.lights,
  8869. {
  8870. emissive: { value: new Color( 0x000000 ) }
  8871. }
  8872. ] ),
  8873. vertexShader: ShaderChunk.meshlambert_vert,
  8874. fragmentShader: ShaderChunk.meshlambert_frag
  8875. },
  8876. phong: {
  8877. uniforms: mergeUniforms( [
  8878. UniformsLib.common,
  8879. UniformsLib.specularmap,
  8880. UniformsLib.envmap,
  8881. UniformsLib.aomap,
  8882. UniformsLib.lightmap,
  8883. UniformsLib.emissivemap,
  8884. UniformsLib.bumpmap,
  8885. UniformsLib.normalmap,
  8886. UniformsLib.displacementmap,
  8887. UniformsLib.gradientmap,
  8888. UniformsLib.fog,
  8889. UniformsLib.lights,
  8890. {
  8891. emissive: { value: new Color( 0x000000 ) },
  8892. specular: { value: new Color( 0x111111 ) },
  8893. shininess: { value: 30 }
  8894. }
  8895. ] ),
  8896. vertexShader: ShaderChunk.meshphong_vert,
  8897. fragmentShader: ShaderChunk.meshphong_frag
  8898. },
  8899. standard: {
  8900. uniforms: mergeUniforms( [
  8901. UniformsLib.common,
  8902. UniformsLib.envmap,
  8903. UniformsLib.aomap,
  8904. UniformsLib.lightmap,
  8905. UniformsLib.emissivemap,
  8906. UniformsLib.bumpmap,
  8907. UniformsLib.normalmap,
  8908. UniformsLib.displacementmap,
  8909. UniformsLib.roughnessmap,
  8910. UniformsLib.metalnessmap,
  8911. UniformsLib.fog,
  8912. UniformsLib.lights,
  8913. {
  8914. emissive: { value: new Color( 0x000000 ) },
  8915. roughness: { value: 0.5 },
  8916. metalness: { value: 0.5 },
  8917. envMapIntensity: { value: 1 } // temporary
  8918. }
  8919. ] ),
  8920. vertexShader: ShaderChunk.meshphysical_vert,
  8921. fragmentShader: ShaderChunk.meshphysical_frag
  8922. },
  8923. matcap: {
  8924. uniforms: mergeUniforms( [
  8925. UniformsLib.common,
  8926. UniformsLib.bumpmap,
  8927. UniformsLib.normalmap,
  8928. UniformsLib.displacementmap,
  8929. UniformsLib.fog,
  8930. {
  8931. matcap: { value: null }
  8932. }
  8933. ] ),
  8934. vertexShader: ShaderChunk.meshmatcap_vert,
  8935. fragmentShader: ShaderChunk.meshmatcap_frag
  8936. },
  8937. points: {
  8938. uniforms: mergeUniforms( [
  8939. UniformsLib.points,
  8940. UniformsLib.fog
  8941. ] ),
  8942. vertexShader: ShaderChunk.points_vert,
  8943. fragmentShader: ShaderChunk.points_frag
  8944. },
  8945. dashed: {
  8946. uniforms: mergeUniforms( [
  8947. UniformsLib.common,
  8948. UniformsLib.fog,
  8949. {
  8950. scale: { value: 1 },
  8951. dashSize: { value: 1 },
  8952. totalSize: { value: 2 }
  8953. }
  8954. ] ),
  8955. vertexShader: ShaderChunk.linedashed_vert,
  8956. fragmentShader: ShaderChunk.linedashed_frag
  8957. },
  8958. depth: {
  8959. uniforms: mergeUniforms( [
  8960. UniformsLib.common,
  8961. UniformsLib.displacementmap
  8962. ] ),
  8963. vertexShader: ShaderChunk.depth_vert,
  8964. fragmentShader: ShaderChunk.depth_frag
  8965. },
  8966. normal: {
  8967. uniforms: mergeUniforms( [
  8968. UniformsLib.common,
  8969. UniformsLib.bumpmap,
  8970. UniformsLib.normalmap,
  8971. UniformsLib.displacementmap,
  8972. {
  8973. opacity: { value: 1.0 }
  8974. }
  8975. ] ),
  8976. vertexShader: ShaderChunk.normal_vert,
  8977. fragmentShader: ShaderChunk.normal_frag
  8978. },
  8979. sprite: {
  8980. uniforms: mergeUniforms( [
  8981. UniformsLib.sprite,
  8982. UniformsLib.fog
  8983. ] ),
  8984. vertexShader: ShaderChunk.sprite_vert,
  8985. fragmentShader: ShaderChunk.sprite_frag
  8986. },
  8987. background: {
  8988. uniforms: {
  8989. uvTransform: { value: new Matrix3() },
  8990. t2D: { value: null },
  8991. },
  8992. vertexShader: ShaderChunk.background_vert,
  8993. fragmentShader: ShaderChunk.background_frag
  8994. },
  8995. /* -------------------------------------------------------------------------
  8996. // Cube map shader
  8997. ------------------------------------------------------------------------- */
  8998. cube: {
  8999. uniforms: {
  9000. tCube: { value: null },
  9001. tFlip: { value: - 1 },
  9002. opacity: { value: 1.0 }
  9003. },
  9004. vertexShader: ShaderChunk.cube_vert,
  9005. fragmentShader: ShaderChunk.cube_frag
  9006. },
  9007. equirect: {
  9008. uniforms: {
  9009. tEquirect: { value: null },
  9010. },
  9011. vertexShader: ShaderChunk.equirect_vert,
  9012. fragmentShader: ShaderChunk.equirect_frag
  9013. },
  9014. distanceRGBA: {
  9015. uniforms: mergeUniforms( [
  9016. UniformsLib.common,
  9017. UniformsLib.displacementmap,
  9018. {
  9019. referencePosition: { value: new Vector3() },
  9020. nearDistance: { value: 1 },
  9021. farDistance: { value: 1000 }
  9022. }
  9023. ] ),
  9024. vertexShader: ShaderChunk.distanceRGBA_vert,
  9025. fragmentShader: ShaderChunk.distanceRGBA_frag
  9026. },
  9027. shadow: {
  9028. uniforms: mergeUniforms( [
  9029. UniformsLib.lights,
  9030. UniformsLib.fog,
  9031. {
  9032. color: { value: new Color( 0x00000 ) },
  9033. opacity: { value: 1.0 }
  9034. },
  9035. ] ),
  9036. vertexShader: ShaderChunk.shadow_vert,
  9037. fragmentShader: ShaderChunk.shadow_frag
  9038. }
  9039. };
  9040. ShaderLib.physical = {
  9041. uniforms: mergeUniforms( [
  9042. ShaderLib.standard.uniforms,
  9043. {
  9044. clearCoat: { value: 0 },
  9045. clearCoatRoughness: { value: 0 }
  9046. }
  9047. ] ),
  9048. vertexShader: ShaderChunk.meshphysical_vert,
  9049. fragmentShader: ShaderChunk.meshphysical_frag
  9050. };
  9051. /**
  9052. * @author mrdoob / http://mrdoob.com/
  9053. */
  9054. function WebGLAnimation() {
  9055. var context = null;
  9056. var isAnimating = false;
  9057. var animationLoop = null;
  9058. function onAnimationFrame( time, frame ) {
  9059. if ( isAnimating === false ) return;
  9060. animationLoop( time, frame );
  9061. context.requestAnimationFrame( onAnimationFrame );
  9062. }
  9063. return {
  9064. start: function () {
  9065. if ( isAnimating === true ) return;
  9066. if ( animationLoop === null ) return;
  9067. context.requestAnimationFrame( onAnimationFrame );
  9068. isAnimating = true;
  9069. },
  9070. stop: function () {
  9071. isAnimating = false;
  9072. },
  9073. setAnimationLoop: function ( callback ) {
  9074. animationLoop = callback;
  9075. },
  9076. setContext: function ( value ) {
  9077. context = value;
  9078. }
  9079. };
  9080. }
  9081. /**
  9082. * @author mrdoob / http://mrdoob.com/
  9083. */
  9084. function WebGLAttributes( gl ) {
  9085. var buffers = new WeakMap();
  9086. function createBuffer( attribute, bufferType ) {
  9087. var array = attribute.array;
  9088. var usage = attribute.dynamic ? 35048 : 35044;
  9089. var buffer = gl.createBuffer();
  9090. gl.bindBuffer( bufferType, buffer );
  9091. gl.bufferData( bufferType, array, usage );
  9092. attribute.onUploadCallback();
  9093. var type = 5126;
  9094. if ( array instanceof Float32Array ) {
  9095. type = 5126;
  9096. } else if ( array instanceof Float64Array ) {
  9097. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  9098. } else if ( array instanceof Uint16Array ) {
  9099. type = 5123;
  9100. } else if ( array instanceof Int16Array ) {
  9101. type = 5122;
  9102. } else if ( array instanceof Uint32Array ) {
  9103. type = 5125;
  9104. } else if ( array instanceof Int32Array ) {
  9105. type = 5124;
  9106. } else if ( array instanceof Int8Array ) {
  9107. type = 5120;
  9108. } else if ( array instanceof Uint8Array ) {
  9109. type = 5121;
  9110. }
  9111. return {
  9112. buffer: buffer,
  9113. type: type,
  9114. bytesPerElement: array.BYTES_PER_ELEMENT,
  9115. version: attribute.version
  9116. };
  9117. }
  9118. function updateBuffer( buffer, attribute, bufferType ) {
  9119. var array = attribute.array;
  9120. var updateRange = attribute.updateRange;
  9121. gl.bindBuffer( bufferType, buffer );
  9122. if ( attribute.dynamic === false ) {
  9123. gl.bufferData( bufferType, array, 35044 );
  9124. } else if ( updateRange.count === - 1 ) {
  9125. // Not using update ranges
  9126. gl.bufferSubData( bufferType, 0, array );
  9127. } else if ( updateRange.count === 0 ) {
  9128. 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.' );
  9129. } else {
  9130. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9131. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9132. updateRange.count = - 1; // reset range
  9133. }
  9134. }
  9135. //
  9136. function get( attribute ) {
  9137. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9138. return buffers.get( attribute );
  9139. }
  9140. function remove( attribute ) {
  9141. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9142. var data = buffers.get( attribute );
  9143. if ( data ) {
  9144. gl.deleteBuffer( data.buffer );
  9145. buffers.delete( attribute );
  9146. }
  9147. }
  9148. function update( attribute, bufferType ) {
  9149. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9150. var data = buffers.get( attribute );
  9151. if ( data === undefined ) {
  9152. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  9153. } else if ( data.version < attribute.version ) {
  9154. updateBuffer( data.buffer, attribute, bufferType );
  9155. data.version = attribute.version;
  9156. }
  9157. }
  9158. return {
  9159. get: get,
  9160. remove: remove,
  9161. update: update
  9162. };
  9163. }
  9164. /**
  9165. * @author mrdoob / http://mrdoob.com/
  9166. * @author Mugen87 / https://github.com/Mugen87
  9167. */
  9168. // PlaneGeometry
  9169. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  9170. Geometry.call( this );
  9171. this.type = 'PlaneGeometry';
  9172. this.parameters = {
  9173. width: width,
  9174. height: height,
  9175. widthSegments: widthSegments,
  9176. heightSegments: heightSegments
  9177. };
  9178. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  9179. this.mergeVertices();
  9180. }
  9181. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  9182. PlaneGeometry.prototype.constructor = PlaneGeometry;
  9183. // PlaneBufferGeometry
  9184. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  9185. BufferGeometry.call( this );
  9186. this.type = 'PlaneBufferGeometry';
  9187. this.parameters = {
  9188. width: width,
  9189. height: height,
  9190. widthSegments: widthSegments,
  9191. heightSegments: heightSegments
  9192. };
  9193. width = width || 1;
  9194. height = height || 1;
  9195. var width_half = width / 2;
  9196. var height_half = height / 2;
  9197. var gridX = Math.floor( widthSegments ) || 1;
  9198. var gridY = Math.floor( heightSegments ) || 1;
  9199. var gridX1 = gridX + 1;
  9200. var gridY1 = gridY + 1;
  9201. var segment_width = width / gridX;
  9202. var segment_height = height / gridY;
  9203. var ix, iy;
  9204. // buffers
  9205. var indices = [];
  9206. var vertices = [];
  9207. var normals = [];
  9208. var uvs = [];
  9209. // generate vertices, normals and uvs
  9210. for ( iy = 0; iy < gridY1; iy ++ ) {
  9211. var y = iy * segment_height - height_half;
  9212. for ( ix = 0; ix < gridX1; ix ++ ) {
  9213. var x = ix * segment_width - width_half;
  9214. vertices.push( x, - y, 0 );
  9215. normals.push( 0, 0, 1 );
  9216. uvs.push( ix / gridX );
  9217. uvs.push( 1 - ( iy / gridY ) );
  9218. }
  9219. }
  9220. // indices
  9221. for ( iy = 0; iy < gridY; iy ++ ) {
  9222. for ( ix = 0; ix < gridX; ix ++ ) {
  9223. var a = ix + gridX1 * iy;
  9224. var b = ix + gridX1 * ( iy + 1 );
  9225. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  9226. var d = ( ix + 1 ) + gridX1 * iy;
  9227. // faces
  9228. indices.push( a, b, d );
  9229. indices.push( b, c, d );
  9230. }
  9231. }
  9232. // build geometry
  9233. this.setIndex( indices );
  9234. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9235. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9236. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9237. }
  9238. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9239. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  9240. /**
  9241. * @author mrdoob / http://mrdoob.com/
  9242. */
  9243. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9244. var clearColor = new Color( 0x000000 );
  9245. var clearAlpha = 0;
  9246. var planeMesh;
  9247. var boxMesh;
  9248. // Store the current background texture and its `version`
  9249. // so we can recompile the material accordingly.
  9250. var currentBackground = null;
  9251. var currentBackgroundVersion = 0;
  9252. function render( renderList, scene, camera, forceClear ) {
  9253. var background = scene.background;
  9254. // Ignore background in AR
  9255. // TODO: Reconsider this.
  9256. var vr = renderer.vr;
  9257. var session = vr.getSession && vr.getSession();
  9258. if ( session && session.environmentBlendMode === 'additive' ) {
  9259. background = null;
  9260. }
  9261. if ( background === null ) {
  9262. setClear( clearColor, clearAlpha );
  9263. currentBackground = null;
  9264. currentBackgroundVersion = 0;
  9265. } else if ( background && background.isColor ) {
  9266. setClear( background, 1 );
  9267. forceClear = true;
  9268. currentBackground = null;
  9269. currentBackgroundVersion = 0;
  9270. }
  9271. if ( renderer.autoClear || forceClear ) {
  9272. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9273. }
  9274. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  9275. if ( boxMesh === undefined ) {
  9276. boxMesh = new Mesh(
  9277. new BoxBufferGeometry( 1, 1, 1 ),
  9278. new ShaderMaterial( {
  9279. type: 'BackgroundCubeMaterial',
  9280. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9281. vertexShader: ShaderLib.cube.vertexShader,
  9282. fragmentShader: ShaderLib.cube.fragmentShader,
  9283. side: BackSide,
  9284. depthTest: false,
  9285. depthWrite: false,
  9286. fog: false
  9287. } )
  9288. );
  9289. boxMesh.geometry.removeAttribute( 'normal' );
  9290. boxMesh.geometry.removeAttribute( 'uv' );
  9291. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9292. this.matrixWorld.copyPosition( camera.matrixWorld );
  9293. };
  9294. // enable code injection for non-built-in material
  9295. Object.defineProperty( boxMesh.material, 'map', {
  9296. get: function () {
  9297. return this.uniforms.tCube.value;
  9298. }
  9299. } );
  9300. objects.update( boxMesh );
  9301. }
  9302. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  9303. boxMesh.material.uniforms.tCube.value = texture;
  9304. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  9305. if ( currentBackground !== background ||
  9306. currentBackgroundVersion !== texture.version ) {
  9307. boxMesh.material.needsUpdate = true;
  9308. currentBackground = background;
  9309. currentBackgroundVersion = texture.version;
  9310. }
  9311. // push to the pre-sorted opaque render list
  9312. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9313. } else if ( background && background.isTexture ) {
  9314. if ( planeMesh === undefined ) {
  9315. planeMesh = new Mesh(
  9316. new PlaneBufferGeometry( 2, 2 ),
  9317. new ShaderMaterial( {
  9318. type: 'BackgroundMaterial',
  9319. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9320. vertexShader: ShaderLib.background.vertexShader,
  9321. fragmentShader: ShaderLib.background.fragmentShader,
  9322. side: FrontSide,
  9323. depthTest: false,
  9324. depthWrite: false,
  9325. fog: false
  9326. } )
  9327. );
  9328. planeMesh.geometry.removeAttribute( 'normal' );
  9329. // enable code injection for non-built-in material
  9330. Object.defineProperty( planeMesh.material, 'map', {
  9331. get: function () {
  9332. return this.uniforms.t2D.value;
  9333. }
  9334. } );
  9335. objects.update( planeMesh );
  9336. }
  9337. planeMesh.material.uniforms.t2D.value = background;
  9338. if ( background.matrixAutoUpdate === true ) {
  9339. background.updateMatrix();
  9340. }
  9341. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9342. if ( currentBackground !== background ||
  9343. currentBackgroundVersion !== background.version ) {
  9344. planeMesh.material.needsUpdate = true;
  9345. currentBackground = background;
  9346. currentBackgroundVersion = background.version;
  9347. }
  9348. // push to the pre-sorted opaque render list
  9349. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9350. }
  9351. }
  9352. function setClear( color, alpha ) {
  9353. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9354. }
  9355. return {
  9356. getClearColor: function () {
  9357. return clearColor;
  9358. },
  9359. setClearColor: function ( color, alpha ) {
  9360. clearColor.set( color );
  9361. clearAlpha = alpha !== undefined ? alpha : 1;
  9362. setClear( clearColor, clearAlpha );
  9363. },
  9364. getClearAlpha: function () {
  9365. return clearAlpha;
  9366. },
  9367. setClearAlpha: function ( alpha ) {
  9368. clearAlpha = alpha;
  9369. setClear( clearColor, clearAlpha );
  9370. },
  9371. render: render
  9372. };
  9373. }
  9374. /**
  9375. * @author mrdoob / http://mrdoob.com/
  9376. */
  9377. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9378. var mode;
  9379. function setMode( value ) {
  9380. mode = value;
  9381. }
  9382. function render( start, count ) {
  9383. gl.drawArrays( mode, start, count );
  9384. info.update( count, mode );
  9385. }
  9386. function renderInstances( geometry, start, count ) {
  9387. var extension;
  9388. if ( capabilities.isWebGL2 ) {
  9389. extension = gl;
  9390. } else {
  9391. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9392. if ( extension === null ) {
  9393. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9394. return;
  9395. }
  9396. }
  9397. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  9398. info.update( count, mode, geometry.maxInstancedCount );
  9399. }
  9400. //
  9401. this.setMode = setMode;
  9402. this.render = render;
  9403. this.renderInstances = renderInstances;
  9404. }
  9405. /**
  9406. * @author mrdoob / http://mrdoob.com/
  9407. */
  9408. function WebGLCapabilities( gl, extensions, parameters ) {
  9409. var maxAnisotropy;
  9410. function getMaxAnisotropy() {
  9411. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  9412. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9413. if ( extension !== null ) {
  9414. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9415. } else {
  9416. maxAnisotropy = 0;
  9417. }
  9418. return maxAnisotropy;
  9419. }
  9420. function getMaxPrecision( precision ) {
  9421. if ( precision === 'highp' ) {
  9422. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9423. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9424. return 'highp';
  9425. }
  9426. precision = 'mediump';
  9427. }
  9428. if ( precision === 'mediump' ) {
  9429. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9430. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9431. return 'mediump';
  9432. }
  9433. }
  9434. return 'lowp';
  9435. }
  9436. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  9437. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9438. var maxPrecision = getMaxPrecision( precision );
  9439. if ( maxPrecision !== precision ) {
  9440. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9441. precision = maxPrecision;
  9442. }
  9443. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9444. var maxTextures = gl.getParameter( 34930 );
  9445. var maxVertexTextures = gl.getParameter( 35660 );
  9446. var maxTextureSize = gl.getParameter( 3379 );
  9447. var maxCubemapSize = gl.getParameter( 34076 );
  9448. var maxAttributes = gl.getParameter( 34921 );
  9449. var maxVertexUniforms = gl.getParameter( 36347 );
  9450. var maxVaryings = gl.getParameter( 36348 );
  9451. var maxFragmentUniforms = gl.getParameter( 36349 );
  9452. var vertexTextures = maxVertexTextures > 0;
  9453. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9454. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9455. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9456. return {
  9457. isWebGL2: isWebGL2,
  9458. getMaxAnisotropy: getMaxAnisotropy,
  9459. getMaxPrecision: getMaxPrecision,
  9460. precision: precision,
  9461. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9462. maxTextures: maxTextures,
  9463. maxVertexTextures: maxVertexTextures,
  9464. maxTextureSize: maxTextureSize,
  9465. maxCubemapSize: maxCubemapSize,
  9466. maxAttributes: maxAttributes,
  9467. maxVertexUniforms: maxVertexUniforms,
  9468. maxVaryings: maxVaryings,
  9469. maxFragmentUniforms: maxFragmentUniforms,
  9470. vertexTextures: vertexTextures,
  9471. floatFragmentTextures: floatFragmentTextures,
  9472. floatVertexTextures: floatVertexTextures,
  9473. maxSamples: maxSamples
  9474. };
  9475. }
  9476. /**
  9477. * @author tschw
  9478. */
  9479. function WebGLClipping() {
  9480. var scope = this,
  9481. globalState = null,
  9482. numGlobalPlanes = 0,
  9483. localClippingEnabled = false,
  9484. renderingShadows = false,
  9485. plane = new Plane(),
  9486. viewNormalMatrix = new Matrix3(),
  9487. uniform = { value: null, needsUpdate: false };
  9488. this.uniform = uniform;
  9489. this.numPlanes = 0;
  9490. this.numIntersection = 0;
  9491. this.init = function ( planes, enableLocalClipping, camera ) {
  9492. var enabled =
  9493. planes.length !== 0 ||
  9494. enableLocalClipping ||
  9495. // enable state of previous frame - the clipping code has to
  9496. // run another frame in order to reset the state:
  9497. numGlobalPlanes !== 0 ||
  9498. localClippingEnabled;
  9499. localClippingEnabled = enableLocalClipping;
  9500. globalState = projectPlanes( planes, camera, 0 );
  9501. numGlobalPlanes = planes.length;
  9502. return enabled;
  9503. };
  9504. this.beginShadows = function () {
  9505. renderingShadows = true;
  9506. projectPlanes( null );
  9507. };
  9508. this.endShadows = function () {
  9509. renderingShadows = false;
  9510. resetGlobalState();
  9511. };
  9512. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9513. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9514. // there's no local clipping
  9515. if ( renderingShadows ) {
  9516. // there's no global clipping
  9517. projectPlanes( null );
  9518. } else {
  9519. resetGlobalState();
  9520. }
  9521. } else {
  9522. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9523. lGlobal = nGlobal * 4,
  9524. dstArray = cache.clippingState || null;
  9525. uniform.value = dstArray; // ensure unique state
  9526. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9527. for ( var i = 0; i !== lGlobal; ++ i ) {
  9528. dstArray[ i ] = globalState[ i ];
  9529. }
  9530. cache.clippingState = dstArray;
  9531. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9532. this.numPlanes += nGlobal;
  9533. }
  9534. };
  9535. function resetGlobalState() {
  9536. if ( uniform.value !== globalState ) {
  9537. uniform.value = globalState;
  9538. uniform.needsUpdate = numGlobalPlanes > 0;
  9539. }
  9540. scope.numPlanes = numGlobalPlanes;
  9541. scope.numIntersection = 0;
  9542. }
  9543. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9544. var nPlanes = planes !== null ? planes.length : 0,
  9545. dstArray = null;
  9546. if ( nPlanes !== 0 ) {
  9547. dstArray = uniform.value;
  9548. if ( skipTransform !== true || dstArray === null ) {
  9549. var flatSize = dstOffset + nPlanes * 4,
  9550. viewMatrix = camera.matrixWorldInverse;
  9551. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9552. if ( dstArray === null || dstArray.length < flatSize ) {
  9553. dstArray = new Float32Array( flatSize );
  9554. }
  9555. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9556. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9557. plane.normal.toArray( dstArray, i4 );
  9558. dstArray[ i4 + 3 ] = plane.constant;
  9559. }
  9560. }
  9561. uniform.value = dstArray;
  9562. uniform.needsUpdate = true;
  9563. }
  9564. scope.numPlanes = nPlanes;
  9565. return dstArray;
  9566. }
  9567. }
  9568. /**
  9569. * @author mrdoob / http://mrdoob.com/
  9570. */
  9571. function WebGLExtensions( gl ) {
  9572. var extensions = {};
  9573. return {
  9574. get: function ( name ) {
  9575. if ( extensions[ name ] !== undefined ) {
  9576. return extensions[ name ];
  9577. }
  9578. var extension;
  9579. switch ( name ) {
  9580. case 'WEBGL_depth_texture':
  9581. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9582. break;
  9583. case 'EXT_texture_filter_anisotropic':
  9584. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9585. break;
  9586. case 'WEBGL_compressed_texture_s3tc':
  9587. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9588. break;
  9589. case 'WEBGL_compressed_texture_pvrtc':
  9590. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9591. break;
  9592. default:
  9593. extension = gl.getExtension( name );
  9594. }
  9595. if ( extension === null ) {
  9596. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9597. }
  9598. extensions[ name ] = extension;
  9599. return extension;
  9600. }
  9601. };
  9602. }
  9603. /**
  9604. * @author mrdoob / http://mrdoob.com/
  9605. */
  9606. function WebGLGeometries( gl, attributes, info ) {
  9607. var geometries = {};
  9608. var wireframeAttributes = {};
  9609. function onGeometryDispose( event ) {
  9610. var geometry = event.target;
  9611. var buffergeometry = geometries[ geometry.id ];
  9612. if ( buffergeometry.index !== null ) {
  9613. attributes.remove( buffergeometry.index );
  9614. }
  9615. for ( var name in buffergeometry.attributes ) {
  9616. attributes.remove( buffergeometry.attributes[ name ] );
  9617. }
  9618. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9619. delete geometries[ geometry.id ];
  9620. var attribute = wireframeAttributes[ buffergeometry.id ];
  9621. if ( attribute ) {
  9622. attributes.remove( attribute );
  9623. delete wireframeAttributes[ buffergeometry.id ];
  9624. }
  9625. //
  9626. info.memory.geometries --;
  9627. }
  9628. function get( object, geometry ) {
  9629. var buffergeometry = geometries[ geometry.id ];
  9630. if ( buffergeometry ) return buffergeometry;
  9631. geometry.addEventListener( 'dispose', onGeometryDispose );
  9632. if ( geometry.isBufferGeometry ) {
  9633. buffergeometry = geometry;
  9634. } else if ( geometry.isGeometry ) {
  9635. if ( geometry._bufferGeometry === undefined ) {
  9636. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9637. }
  9638. buffergeometry = geometry._bufferGeometry;
  9639. }
  9640. geometries[ geometry.id ] = buffergeometry;
  9641. info.memory.geometries ++;
  9642. return buffergeometry;
  9643. }
  9644. function update( geometry ) {
  9645. var index = geometry.index;
  9646. var geometryAttributes = geometry.attributes;
  9647. if ( index !== null ) {
  9648. attributes.update( index, 34963 );
  9649. }
  9650. for ( var name in geometryAttributes ) {
  9651. attributes.update( geometryAttributes[ name ], 34962 );
  9652. }
  9653. // morph targets
  9654. var morphAttributes = geometry.morphAttributes;
  9655. for ( var name in morphAttributes ) {
  9656. var array = morphAttributes[ name ];
  9657. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9658. attributes.update( array[ i ], 34962 );
  9659. }
  9660. }
  9661. }
  9662. function updateWireframeAttribute( geometry ) {
  9663. var indices = [];
  9664. var geometryIndex = geometry.index;
  9665. var geometryPosition = geometry.attributes.position;
  9666. var version = 0;
  9667. if ( geometryIndex !== null ) {
  9668. var array = geometryIndex.array;
  9669. version = geometryIndex.version;
  9670. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9671. var a = array[ i + 0 ];
  9672. var b = array[ i + 1 ];
  9673. var c = array[ i + 2 ];
  9674. indices.push( a, b, b, c, c, a );
  9675. }
  9676. } else {
  9677. var array = geometryPosition.array;
  9678. version = geometryPosition.version;
  9679. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9680. var a = i + 0;
  9681. var b = i + 1;
  9682. var c = i + 2;
  9683. indices.push( a, b, b, c, c, a );
  9684. }
  9685. }
  9686. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9687. attribute.version = version;
  9688. attributes.update( attribute, 34963 );
  9689. //
  9690. var previousAttribute = wireframeAttributes[ geometry.id ];
  9691. if ( previousAttribute ) attributes.remove( previousAttribute );
  9692. //
  9693. wireframeAttributes[ geometry.id ] = attribute;
  9694. }
  9695. function getWireframeAttribute( geometry ) {
  9696. var currentAttribute = wireframeAttributes[ geometry.id ];
  9697. if ( currentAttribute ) {
  9698. var geometryIndex = geometry.index;
  9699. if ( geometryIndex !== null ) {
  9700. // if the attribute is obsolete, create a new one
  9701. if ( currentAttribute.version < geometryIndex.version ) {
  9702. updateWireframeAttribute( geometry );
  9703. }
  9704. }
  9705. } else {
  9706. updateWireframeAttribute( geometry );
  9707. }
  9708. return wireframeAttributes[ geometry.id ];
  9709. }
  9710. return {
  9711. get: get,
  9712. update: update,
  9713. getWireframeAttribute: getWireframeAttribute
  9714. };
  9715. }
  9716. /**
  9717. * @author mrdoob / http://mrdoob.com/
  9718. */
  9719. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9720. var mode;
  9721. function setMode( value ) {
  9722. mode = value;
  9723. }
  9724. var type, bytesPerElement;
  9725. function setIndex( value ) {
  9726. type = value.type;
  9727. bytesPerElement = value.bytesPerElement;
  9728. }
  9729. function render( start, count ) {
  9730. gl.drawElements( mode, count, type, start * bytesPerElement );
  9731. info.update( count, mode );
  9732. }
  9733. function renderInstances( geometry, start, count ) {
  9734. var extension;
  9735. if ( capabilities.isWebGL2 ) {
  9736. extension = gl;
  9737. } else {
  9738. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9739. if ( extension === null ) {
  9740. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9741. return;
  9742. }
  9743. }
  9744. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9745. info.update( count, mode, geometry.maxInstancedCount );
  9746. }
  9747. //
  9748. this.setMode = setMode;
  9749. this.setIndex = setIndex;
  9750. this.render = render;
  9751. this.renderInstances = renderInstances;
  9752. }
  9753. /**
  9754. * @author Mugen87 / https://github.com/Mugen87
  9755. */
  9756. function WebGLInfo( gl ) {
  9757. var memory = {
  9758. geometries: 0,
  9759. textures: 0
  9760. };
  9761. var render = {
  9762. frame: 0,
  9763. calls: 0,
  9764. triangles: 0,
  9765. points: 0,
  9766. lines: 0
  9767. };
  9768. function update( count, mode, instanceCount ) {
  9769. instanceCount = instanceCount || 1;
  9770. render.calls ++;
  9771. switch ( mode ) {
  9772. case 4:
  9773. render.triangles += instanceCount * ( count / 3 );
  9774. break;
  9775. case 5:
  9776. case 6:
  9777. render.triangles += instanceCount * ( count - 2 );
  9778. break;
  9779. case 1:
  9780. render.lines += instanceCount * ( count / 2 );
  9781. break;
  9782. case 3:
  9783. render.lines += instanceCount * ( count - 1 );
  9784. break;
  9785. case 2:
  9786. render.lines += instanceCount * count;
  9787. break;
  9788. case 0:
  9789. render.points += instanceCount * count;
  9790. break;
  9791. default:
  9792. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9793. break;
  9794. }
  9795. }
  9796. function reset() {
  9797. render.frame ++;
  9798. render.calls = 0;
  9799. render.triangles = 0;
  9800. render.points = 0;
  9801. render.lines = 0;
  9802. }
  9803. return {
  9804. memory: memory,
  9805. render: render,
  9806. programs: null,
  9807. autoReset: true,
  9808. reset: reset,
  9809. update: update
  9810. };
  9811. }
  9812. /**
  9813. * @author mrdoob / http://mrdoob.com/
  9814. */
  9815. function absNumericalSort( a, b ) {
  9816. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9817. }
  9818. function WebGLMorphtargets( gl ) {
  9819. var influencesList = {};
  9820. var morphInfluences = new Float32Array( 8 );
  9821. function update( object, geometry, material, program ) {
  9822. var objectInfluences = object.morphTargetInfluences;
  9823. var length = objectInfluences.length;
  9824. var influences = influencesList[ geometry.id ];
  9825. if ( influences === undefined ) {
  9826. // initialise list
  9827. influences = [];
  9828. for ( var i = 0; i < length; i ++ ) {
  9829. influences[ i ] = [ i, 0 ];
  9830. }
  9831. influencesList[ geometry.id ] = influences;
  9832. }
  9833. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9834. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9835. // Remove current morphAttributes
  9836. for ( var i = 0; i < length; i ++ ) {
  9837. var influence = influences[ i ];
  9838. if ( influence[ 1 ] !== 0 ) {
  9839. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9840. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9841. }
  9842. }
  9843. // Collect influences
  9844. for ( var i = 0; i < length; i ++ ) {
  9845. var influence = influences[ i ];
  9846. influence[ 0 ] = i;
  9847. influence[ 1 ] = objectInfluences[ i ];
  9848. }
  9849. influences.sort( absNumericalSort );
  9850. // Add morphAttributes
  9851. for ( var i = 0; i < 8; i ++ ) {
  9852. var influence = influences[ i ];
  9853. if ( influence ) {
  9854. var index = influence[ 0 ];
  9855. var value = influence[ 1 ];
  9856. if ( value ) {
  9857. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9858. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9859. morphInfluences[ i ] = value;
  9860. continue;
  9861. }
  9862. }
  9863. morphInfluences[ i ] = 0;
  9864. }
  9865. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9866. }
  9867. return {
  9868. update: update
  9869. };
  9870. }
  9871. /**
  9872. * @author mrdoob / http://mrdoob.com/
  9873. */
  9874. function WebGLObjects( geometries, info ) {
  9875. var updateList = {};
  9876. function update( object ) {
  9877. var frame = info.render.frame;
  9878. var geometry = object.geometry;
  9879. var buffergeometry = geometries.get( object, geometry );
  9880. // Update once per frame
  9881. if ( updateList[ buffergeometry.id ] !== frame ) {
  9882. if ( geometry.isGeometry ) {
  9883. buffergeometry.updateFromObject( object );
  9884. }
  9885. geometries.update( buffergeometry );
  9886. updateList[ buffergeometry.id ] = frame;
  9887. }
  9888. return buffergeometry;
  9889. }
  9890. function dispose() {
  9891. updateList = {};
  9892. }
  9893. return {
  9894. update: update,
  9895. dispose: dispose
  9896. };
  9897. }
  9898. /**
  9899. * @author mrdoob / http://mrdoob.com/
  9900. */
  9901. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9902. images = images !== undefined ? images : [];
  9903. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9904. format = format !== undefined ? format : RGBFormat;
  9905. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9906. this.flipY = false;
  9907. }
  9908. CubeTexture.prototype = Object.create( Texture.prototype );
  9909. CubeTexture.prototype.constructor = CubeTexture;
  9910. CubeTexture.prototype.isCubeTexture = true;
  9911. Object.defineProperty( CubeTexture.prototype, 'images', {
  9912. get: function () {
  9913. return this.image;
  9914. },
  9915. set: function ( value ) {
  9916. this.image = value;
  9917. }
  9918. } );
  9919. /**
  9920. * @author Takahiro https://github.com/takahirox
  9921. */
  9922. function DataTexture2DArray( data, width, height, depth ) {
  9923. Texture.call( this, null );
  9924. this.image = { data: data, width: width, height: height, depth: depth };
  9925. this.magFilter = NearestFilter;
  9926. this.minFilter = NearestFilter;
  9927. this.wrapR = ClampToEdgeWrapping;
  9928. this.generateMipmaps = false;
  9929. this.flipY = false;
  9930. }
  9931. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9932. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9933. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9934. /**
  9935. * @author Artur Trzesiok
  9936. */
  9937. function DataTexture3D( data, width, height, depth ) {
  9938. // We're going to add .setXXX() methods for setting properties later.
  9939. // Users can still set in DataTexture3D directly.
  9940. //
  9941. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9942. // texture.anisotropy = 16;
  9943. //
  9944. // See #14839
  9945. Texture.call( this, null );
  9946. this.image = { data: data, width: width, height: height, depth: depth };
  9947. this.magFilter = NearestFilter;
  9948. this.minFilter = NearestFilter;
  9949. this.wrapR = ClampToEdgeWrapping;
  9950. this.generateMipmaps = false;
  9951. this.flipY = false;
  9952. }
  9953. DataTexture3D.prototype = Object.create( Texture.prototype );
  9954. DataTexture3D.prototype.constructor = DataTexture3D;
  9955. DataTexture3D.prototype.isDataTexture3D = true;
  9956. /**
  9957. * @author tschw
  9958. * @author Mugen87 / https://github.com/Mugen87
  9959. * @author mrdoob / http://mrdoob.com/
  9960. *
  9961. * Uniforms of a program.
  9962. * Those form a tree structure with a special top-level container for the root,
  9963. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9964. *
  9965. *
  9966. * Properties of inner nodes including the top-level container:
  9967. *
  9968. * .seq - array of nested uniforms
  9969. * .map - nested uniforms by name
  9970. *
  9971. *
  9972. * Methods of all nodes except the top-level container:
  9973. *
  9974. * .setValue( gl, value, [textures] )
  9975. *
  9976. * uploads a uniform value(s)
  9977. * the 'textures' parameter is needed for sampler uniforms
  9978. *
  9979. *
  9980. * Static methods of the top-level container (textures factorizations):
  9981. *
  9982. * .upload( gl, seq, values, textures )
  9983. *
  9984. * sets uniforms in 'seq' to 'values[id].value'
  9985. *
  9986. * .seqWithValue( seq, values ) : filteredSeq
  9987. *
  9988. * filters 'seq' entries with corresponding entry in values
  9989. *
  9990. *
  9991. * Methods of the top-level container (textures factorizations):
  9992. *
  9993. * .setValue( gl, name, value, textures )
  9994. *
  9995. * sets uniform with name 'name' to 'value'
  9996. *
  9997. * .setOptional( gl, obj, prop )
  9998. *
  9999. * like .set for an optional property of the object
  10000. *
  10001. */
  10002. var emptyTexture = new Texture();
  10003. var emptyTexture2dArray = new DataTexture2DArray();
  10004. var emptyTexture3d = new DataTexture3D();
  10005. var emptyCubeTexture = new CubeTexture();
  10006. // --- Utilities ---
  10007. // Array Caches (provide typed arrays for temporary by size)
  10008. var arrayCacheF32 = [];
  10009. var arrayCacheI32 = [];
  10010. // Float32Array caches used for uploading Matrix uniforms
  10011. var mat4array = new Float32Array( 16 );
  10012. var mat3array = new Float32Array( 9 );
  10013. var mat2array = new Float32Array( 4 );
  10014. // Flattening for arrays of vectors and matrices
  10015. function flatten( array, nBlocks, blockSize ) {
  10016. var firstElem = array[ 0 ];
  10017. if ( firstElem <= 0 || firstElem > 0 ) return array;
  10018. // unoptimized: ! isNaN( firstElem )
  10019. // see http://jacksondunstan.com/articles/983
  10020. var n = nBlocks * blockSize,
  10021. r = arrayCacheF32[ n ];
  10022. if ( r === undefined ) {
  10023. r = new Float32Array( n );
  10024. arrayCacheF32[ n ] = r;
  10025. }
  10026. if ( nBlocks !== 0 ) {
  10027. firstElem.toArray( r, 0 );
  10028. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10029. offset += blockSize;
  10030. array[ i ].toArray( r, offset );
  10031. }
  10032. }
  10033. return r;
  10034. }
  10035. function arraysEqual( a, b ) {
  10036. if ( a.length !== b.length ) return false;
  10037. for ( var i = 0, l = a.length; i < l; i ++ ) {
  10038. if ( a[ i ] !== b[ i ] ) return false;
  10039. }
  10040. return true;
  10041. }
  10042. function copyArray( a, b ) {
  10043. for ( var i = 0, l = b.length; i < l; i ++ ) {
  10044. a[ i ] = b[ i ];
  10045. }
  10046. }
  10047. // Texture unit allocation
  10048. function allocTexUnits( textures, n ) {
  10049. var r = arrayCacheI32[ n ];
  10050. if ( r === undefined ) {
  10051. r = new Int32Array( n );
  10052. arrayCacheI32[ n ] = r;
  10053. }
  10054. for ( var i = 0; i !== n; ++ i )
  10055. r[ i ] = textures.allocateTextureUnit();
  10056. return r;
  10057. }
  10058. // --- Setters ---
  10059. // Note: Defining these methods externally, because they come in a bunch
  10060. // and this way their names minify.
  10061. // Single scalar
  10062. function setValueV1f( gl, v ) {
  10063. var cache = this.cache;
  10064. if ( cache[ 0 ] === v ) return;
  10065. gl.uniform1f( this.addr, v );
  10066. cache[ 0 ] = v;
  10067. }
  10068. // Single float vector (from flat array or THREE.VectorN)
  10069. function setValueV2f( gl, v ) {
  10070. var cache = this.cache;
  10071. if ( v.x !== undefined ) {
  10072. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10073. gl.uniform2f( this.addr, v.x, v.y );
  10074. cache[ 0 ] = v.x;
  10075. cache[ 1 ] = v.y;
  10076. }
  10077. } else {
  10078. if ( arraysEqual( cache, v ) ) return;
  10079. gl.uniform2fv( this.addr, v );
  10080. copyArray( cache, v );
  10081. }
  10082. }
  10083. function setValueV3f( gl, v ) {
  10084. var cache = this.cache;
  10085. if ( v.x !== undefined ) {
  10086. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10087. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10088. cache[ 0 ] = v.x;
  10089. cache[ 1 ] = v.y;
  10090. cache[ 2 ] = v.z;
  10091. }
  10092. } else if ( v.r !== undefined ) {
  10093. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10094. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10095. cache[ 0 ] = v.r;
  10096. cache[ 1 ] = v.g;
  10097. cache[ 2 ] = v.b;
  10098. }
  10099. } else {
  10100. if ( arraysEqual( cache, v ) ) return;
  10101. gl.uniform3fv( this.addr, v );
  10102. copyArray( cache, v );
  10103. }
  10104. }
  10105. function setValueV4f( gl, v ) {
  10106. var cache = this.cache;
  10107. if ( v.x !== undefined ) {
  10108. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10109. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10110. cache[ 0 ] = v.x;
  10111. cache[ 1 ] = v.y;
  10112. cache[ 2 ] = v.z;
  10113. cache[ 3 ] = v.w;
  10114. }
  10115. } else {
  10116. if ( arraysEqual( cache, v ) ) return;
  10117. gl.uniform4fv( this.addr, v );
  10118. copyArray( cache, v );
  10119. }
  10120. }
  10121. // Single matrix (from flat array or MatrixN)
  10122. function setValueM2( gl, v ) {
  10123. var cache = this.cache;
  10124. var elements = v.elements;
  10125. if ( elements === undefined ) {
  10126. if ( arraysEqual( cache, v ) ) return;
  10127. gl.uniformMatrix2fv( this.addr, false, v );
  10128. copyArray( cache, v );
  10129. } else {
  10130. if ( arraysEqual( cache, elements ) ) return;
  10131. mat2array.set( elements );
  10132. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10133. copyArray( cache, elements );
  10134. }
  10135. }
  10136. function setValueM3( gl, v ) {
  10137. var cache = this.cache;
  10138. var elements = v.elements;
  10139. if ( elements === undefined ) {
  10140. if ( arraysEqual( cache, v ) ) return;
  10141. gl.uniformMatrix3fv( this.addr, false, v );
  10142. copyArray( cache, v );
  10143. } else {
  10144. if ( arraysEqual( cache, elements ) ) return;
  10145. mat3array.set( elements );
  10146. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10147. copyArray( cache, elements );
  10148. }
  10149. }
  10150. function setValueM4( gl, v ) {
  10151. var cache = this.cache;
  10152. var elements = v.elements;
  10153. if ( elements === undefined ) {
  10154. if ( arraysEqual( cache, v ) ) return;
  10155. gl.uniformMatrix4fv( this.addr, false, v );
  10156. copyArray( cache, v );
  10157. } else {
  10158. if ( arraysEqual( cache, elements ) ) return;
  10159. mat4array.set( elements );
  10160. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10161. copyArray( cache, elements );
  10162. }
  10163. }
  10164. // Single texture (2D / Cube)
  10165. function setValueT1( gl, v, textures ) {
  10166. var cache = this.cache;
  10167. var unit = textures.allocateTextureUnit();
  10168. if ( cache[ 0 ] !== unit ) {
  10169. gl.uniform1i( this.addr, unit );
  10170. cache[ 0 ] = unit;
  10171. }
  10172. textures.safeSetTexture2D( v || emptyTexture, unit );
  10173. }
  10174. function setValueT2DArray1( gl, v, textures ) {
  10175. var cache = this.cache;
  10176. var unit = textures.allocateTextureUnit();
  10177. if ( cache[ 0 ] !== unit ) {
  10178. gl.uniform1i( this.addr, unit );
  10179. cache[ 0 ] = unit;
  10180. }
  10181. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10182. }
  10183. function setValueT3D1( gl, v, textures ) {
  10184. var cache = this.cache;
  10185. var unit = textures.allocateTextureUnit();
  10186. if ( cache[ 0 ] !== unit ) {
  10187. gl.uniform1i( this.addr, unit );
  10188. cache[ 0 ] = unit;
  10189. }
  10190. textures.setTexture3D( v || emptyTexture3d, unit );
  10191. }
  10192. function setValueT6( gl, v, textures ) {
  10193. var cache = this.cache;
  10194. var unit = textures.allocateTextureUnit();
  10195. if ( cache[ 0 ] !== unit ) {
  10196. gl.uniform1i( this.addr, unit );
  10197. cache[ 0 ] = unit;
  10198. }
  10199. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10200. }
  10201. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10202. function setValueV1i( gl, v ) {
  10203. var cache = this.cache;
  10204. if ( cache[ 0 ] === v ) return;
  10205. gl.uniform1i( this.addr, v );
  10206. cache[ 0 ] = v;
  10207. }
  10208. function setValueV2i( gl, v ) {
  10209. var cache = this.cache;
  10210. if ( arraysEqual( cache, v ) ) return;
  10211. gl.uniform2iv( this.addr, v );
  10212. copyArray( cache, v );
  10213. }
  10214. function setValueV3i( gl, v ) {
  10215. var cache = this.cache;
  10216. if ( arraysEqual( cache, v ) ) return;
  10217. gl.uniform3iv( this.addr, v );
  10218. copyArray( cache, v );
  10219. }
  10220. function setValueV4i( gl, v ) {
  10221. var cache = this.cache;
  10222. if ( arraysEqual( cache, v ) ) return;
  10223. gl.uniform4iv( this.addr, v );
  10224. copyArray( cache, v );
  10225. }
  10226. // Helper to pick the right setter for the singular case
  10227. function getSingularSetter( type ) {
  10228. switch ( type ) {
  10229. case 0x1406: return setValueV1f; // FLOAT
  10230. case 0x8b50: return setValueV2f; // _VEC2
  10231. case 0x8b51: return setValueV3f; // _VEC3
  10232. case 0x8b52: return setValueV4f; // _VEC4
  10233. case 0x8b5a: return setValueM2; // _MAT2
  10234. case 0x8b5b: return setValueM3; // _MAT3
  10235. case 0x8b5c: return setValueM4; // _MAT4
  10236. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  10237. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  10238. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  10239. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  10240. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10241. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10242. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10243. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10244. }
  10245. }
  10246. // Array of scalars
  10247. function setValueV1fArray( gl, v ) {
  10248. gl.uniform1fv( this.addr, v );
  10249. }
  10250. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10251. function setValueV1iArray( gl, v ) {
  10252. gl.uniform1iv( this.addr, v );
  10253. }
  10254. function setValueV2iArray( gl, v ) {
  10255. gl.uniform2iv( this.addr, v );
  10256. }
  10257. function setValueV3iArray( gl, v ) {
  10258. gl.uniform3iv( this.addr, v );
  10259. }
  10260. function setValueV4iArray( gl, v ) {
  10261. gl.uniform4iv( this.addr, v );
  10262. }
  10263. // Array of vectors (flat or from THREE classes)
  10264. function setValueV2fArray( gl, v ) {
  10265. var data = flatten( v, this.size, 2 );
  10266. gl.uniform2fv( this.addr, data );
  10267. }
  10268. function setValueV3fArray( gl, v ) {
  10269. var data = flatten( v, this.size, 3 );
  10270. gl.uniform3fv( this.addr, data );
  10271. }
  10272. function setValueV4fArray( gl, v ) {
  10273. var data = flatten( v, this.size, 4 );
  10274. gl.uniform4fv( this.addr, data );
  10275. }
  10276. // Array of matrices (flat or from THREE clases)
  10277. function setValueM2Array( gl, v ) {
  10278. var data = flatten( v, this.size, 4 );
  10279. gl.uniformMatrix2fv( this.addr, false, data );
  10280. }
  10281. function setValueM3Array( gl, v ) {
  10282. var data = flatten( v, this.size, 9 );
  10283. gl.uniformMatrix3fv( this.addr, false, data );
  10284. }
  10285. function setValueM4Array( gl, v ) {
  10286. var data = flatten( v, this.size, 16 );
  10287. gl.uniformMatrix4fv( this.addr, false, data );
  10288. }
  10289. // Array of textures (2D / Cube)
  10290. function setValueT1Array( gl, v, textures ) {
  10291. var n = v.length;
  10292. var units = allocTexUnits( textures, n );
  10293. gl.uniform1iv( this.addr, units );
  10294. for ( var i = 0; i !== n; ++ i ) {
  10295. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10296. }
  10297. }
  10298. function setValueT6Array( gl, v, textures ) {
  10299. var n = v.length;
  10300. var units = allocTexUnits( textures, n );
  10301. gl.uniform1iv( this.addr, units );
  10302. for ( var i = 0; i !== n; ++ i ) {
  10303. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10304. }
  10305. }
  10306. // Helper to pick the right setter for a pure (bottom-level) array
  10307. function getPureArraySetter( type ) {
  10308. switch ( type ) {
  10309. case 0x1406: return setValueV1fArray; // FLOAT
  10310. case 0x8b50: return setValueV2fArray; // _VEC2
  10311. case 0x8b51: return setValueV3fArray; // _VEC3
  10312. case 0x8b52: return setValueV4fArray; // _VEC4
  10313. case 0x8b5a: return setValueM2Array; // _MAT2
  10314. case 0x8b5b: return setValueM3Array; // _MAT3
  10315. case 0x8b5c: return setValueM4Array; // _MAT4
  10316. case 0x8b5e: return setValueT1Array; // SAMPLER_2D
  10317. case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
  10318. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10319. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10320. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10321. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10322. }
  10323. }
  10324. // --- Uniform Classes ---
  10325. function SingleUniform( id, activeInfo, addr ) {
  10326. this.id = id;
  10327. this.addr = addr;
  10328. this.cache = [];
  10329. this.setValue = getSingularSetter( activeInfo.type );
  10330. // this.path = activeInfo.name; // DEBUG
  10331. }
  10332. function PureArrayUniform( id, activeInfo, addr ) {
  10333. this.id = id;
  10334. this.addr = addr;
  10335. this.cache = [];
  10336. this.size = activeInfo.size;
  10337. this.setValue = getPureArraySetter( activeInfo.type );
  10338. // this.path = activeInfo.name; // DEBUG
  10339. }
  10340. PureArrayUniform.prototype.updateCache = function ( data ) {
  10341. var cache = this.cache;
  10342. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10343. this.cache = new Float32Array( data.length );
  10344. }
  10345. copyArray( cache, data );
  10346. };
  10347. function StructuredUniform( id ) {
  10348. this.id = id;
  10349. this.seq = [];
  10350. this.map = {};
  10351. }
  10352. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10353. var seq = this.seq;
  10354. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10355. var u = seq[ i ];
  10356. u.setValue( gl, value[ u.id ], textures );
  10357. }
  10358. };
  10359. // --- Top-level ---
  10360. // Parser - builds up the property tree from the path strings
  10361. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10362. // extracts
  10363. // - the identifier (member name or array index)
  10364. // - followed by an optional right bracket (found when array index)
  10365. // - followed by an optional left bracket or dot (type of subscript)
  10366. //
  10367. // Note: These portions can be read in a non-overlapping fashion and
  10368. // allow straightforward parsing of the hierarchy that WebGL encodes
  10369. // in the uniform names.
  10370. function addUniform( container, uniformObject ) {
  10371. container.seq.push( uniformObject );
  10372. container.map[ uniformObject.id ] = uniformObject;
  10373. }
  10374. function parseUniform( activeInfo, addr, container ) {
  10375. var path = activeInfo.name,
  10376. pathLength = path.length;
  10377. // reset RegExp object, because of the early exit of a previous run
  10378. RePathPart.lastIndex = 0;
  10379. while ( true ) {
  10380. var match = RePathPart.exec( path ),
  10381. matchEnd = RePathPart.lastIndex,
  10382. id = match[ 1 ],
  10383. idIsIndex = match[ 2 ] === ']',
  10384. subscript = match[ 3 ];
  10385. if ( idIsIndex ) id = id | 0; // convert to integer
  10386. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10387. // bare name or "pure" bottom-level array "[0]" suffix
  10388. addUniform( container, subscript === undefined ?
  10389. new SingleUniform( id, activeInfo, addr ) :
  10390. new PureArrayUniform( id, activeInfo, addr ) );
  10391. break;
  10392. } else {
  10393. // step into inner node / create it in case it doesn't exist
  10394. var map = container.map, next = map[ id ];
  10395. if ( next === undefined ) {
  10396. next = new StructuredUniform( id );
  10397. addUniform( container, next );
  10398. }
  10399. container = next;
  10400. }
  10401. }
  10402. }
  10403. // Root Container
  10404. function WebGLUniforms( gl, program ) {
  10405. this.seq = [];
  10406. this.map = {};
  10407. var n = gl.getProgramParameter( program, 35718 );
  10408. for ( var i = 0; i < n; ++ i ) {
  10409. var info = gl.getActiveUniform( program, i ),
  10410. addr = gl.getUniformLocation( program, info.name );
  10411. parseUniform( info, addr, this );
  10412. }
  10413. }
  10414. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10415. var u = this.map[ name ];
  10416. if ( u !== undefined ) u.setValue( gl, value, textures );
  10417. };
  10418. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10419. var v = object[ name ];
  10420. if ( v !== undefined ) this.setValue( gl, name, v );
  10421. };
  10422. // Static interface
  10423. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10424. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10425. var u = seq[ i ],
  10426. v = values[ u.id ];
  10427. if ( v.needsUpdate !== false ) {
  10428. // note: always updating when .needsUpdate is undefined
  10429. u.setValue( gl, v.value, textures );
  10430. }
  10431. }
  10432. };
  10433. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10434. var r = [];
  10435. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10436. var u = seq[ i ];
  10437. if ( u.id in values ) r.push( u );
  10438. }
  10439. return r;
  10440. };
  10441. /**
  10442. * @author mrdoob / http://mrdoob.com/
  10443. */
  10444. function WebGLShader( gl, type, string ) {
  10445. var shader = gl.createShader( type );
  10446. gl.shaderSource( shader, string );
  10447. gl.compileShader( shader );
  10448. return shader;
  10449. }
  10450. /**
  10451. * @author mrdoob / http://mrdoob.com/
  10452. */
  10453. var programIdCount = 0;
  10454. function addLineNumbers( string ) {
  10455. var lines = string.split( '\n' );
  10456. for ( var i = 0; i < lines.length; i ++ ) {
  10457. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10458. }
  10459. return lines.join( '\n' );
  10460. }
  10461. function getEncodingComponents( encoding ) {
  10462. switch ( encoding ) {
  10463. case LinearEncoding:
  10464. return [ 'Linear', '( value )' ];
  10465. case sRGBEncoding:
  10466. return [ 'sRGB', '( value )' ];
  10467. case RGBEEncoding:
  10468. return [ 'RGBE', '( value )' ];
  10469. case RGBM7Encoding:
  10470. return [ 'RGBM', '( value, 7.0 )' ];
  10471. case RGBM16Encoding:
  10472. return [ 'RGBM', '( value, 16.0 )' ];
  10473. case RGBDEncoding:
  10474. return [ 'RGBD', '( value, 256.0 )' ];
  10475. case GammaEncoding:
  10476. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10477. default:
  10478. throw new Error( 'unsupported encoding: ' + encoding );
  10479. }
  10480. }
  10481. function getShaderErrors( gl, shader, type ) {
  10482. var status = gl.getShaderParameter( shader, 35713 );
  10483. var log = gl.getShaderInfoLog( shader ).trim();
  10484. if ( status && log === '' ) return '';
  10485. // --enable-privileged-webgl-extension
  10486. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10487. var source = gl.getShaderSource( shader );
  10488. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10489. }
  10490. function getTexelDecodingFunction( functionName, encoding ) {
  10491. var components = getEncodingComponents( encoding );
  10492. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10493. }
  10494. function getTexelEncodingFunction( functionName, encoding ) {
  10495. var components = getEncodingComponents( encoding );
  10496. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10497. }
  10498. function getToneMappingFunction( functionName, toneMapping ) {
  10499. var toneMappingName;
  10500. switch ( toneMapping ) {
  10501. case LinearToneMapping:
  10502. toneMappingName = 'Linear';
  10503. break;
  10504. case ReinhardToneMapping:
  10505. toneMappingName = 'Reinhard';
  10506. break;
  10507. case Uncharted2ToneMapping:
  10508. toneMappingName = 'Uncharted2';
  10509. break;
  10510. case CineonToneMapping:
  10511. toneMappingName = 'OptimizedCineon';
  10512. break;
  10513. case ACESFilmicToneMapping:
  10514. toneMappingName = 'ACESFilmic';
  10515. break;
  10516. default:
  10517. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10518. }
  10519. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10520. }
  10521. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10522. extensions = extensions || {};
  10523. var chunks = [
  10524. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10525. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10526. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10527. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10528. ];
  10529. return chunks.filter( filterEmptyLine ).join( '\n' );
  10530. }
  10531. function generateDefines( defines ) {
  10532. var chunks = [];
  10533. for ( var name in defines ) {
  10534. var value = defines[ name ];
  10535. if ( value === false ) continue;
  10536. chunks.push( '#define ' + name + ' ' + value );
  10537. }
  10538. return chunks.join( '\n' );
  10539. }
  10540. function fetchAttributeLocations( gl, program ) {
  10541. var attributes = {};
  10542. var n = gl.getProgramParameter( program, 35721 );
  10543. for ( var i = 0; i < n; i ++ ) {
  10544. var info = gl.getActiveAttrib( program, i );
  10545. var name = info.name;
  10546. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10547. attributes[ name ] = gl.getAttribLocation( program, name );
  10548. }
  10549. return attributes;
  10550. }
  10551. function filterEmptyLine( string ) {
  10552. return string !== '';
  10553. }
  10554. function replaceLightNums( string, parameters ) {
  10555. return string
  10556. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10557. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10558. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10559. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10560. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10561. }
  10562. function replaceClippingPlaneNums( string, parameters ) {
  10563. return string
  10564. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10565. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10566. }
  10567. function parseIncludes( string ) {
  10568. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10569. function replace( match, include ) {
  10570. var replace = ShaderChunk[ include ];
  10571. if ( replace === undefined ) {
  10572. throw new Error( 'Can not resolve #include <' + include + '>' );
  10573. }
  10574. return parseIncludes( replace );
  10575. }
  10576. return string.replace( pattern, replace );
  10577. }
  10578. function unrollLoops( string ) {
  10579. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10580. function replace( match, start, end, snippet ) {
  10581. var unroll = '';
  10582. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10583. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10584. }
  10585. return unroll;
  10586. }
  10587. return string.replace( pattern, replace );
  10588. }
  10589. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  10590. var gl = renderer.getContext();
  10591. var defines = material.defines;
  10592. var vertexShader = shader.vertexShader;
  10593. var fragmentShader = shader.fragmentShader;
  10594. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10595. if ( parameters.shadowMapType === PCFShadowMap ) {
  10596. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10597. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10598. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10599. }
  10600. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10601. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10602. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10603. if ( parameters.envMap ) {
  10604. switch ( material.envMap.mapping ) {
  10605. case CubeReflectionMapping:
  10606. case CubeRefractionMapping:
  10607. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10608. break;
  10609. case CubeUVReflectionMapping:
  10610. case CubeUVRefractionMapping:
  10611. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10612. break;
  10613. case EquirectangularReflectionMapping:
  10614. case EquirectangularRefractionMapping:
  10615. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10616. break;
  10617. case SphericalReflectionMapping:
  10618. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10619. break;
  10620. }
  10621. switch ( material.envMap.mapping ) {
  10622. case CubeRefractionMapping:
  10623. case EquirectangularRefractionMapping:
  10624. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10625. break;
  10626. }
  10627. switch ( material.combine ) {
  10628. case MultiplyOperation:
  10629. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10630. break;
  10631. case MixOperation:
  10632. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10633. break;
  10634. case AddOperation:
  10635. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10636. break;
  10637. }
  10638. }
  10639. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10640. // console.log( 'building new program ' );
  10641. //
  10642. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10643. var customDefines = generateDefines( defines );
  10644. //
  10645. var program = gl.createProgram();
  10646. var prefixVertex, prefixFragment;
  10647. if ( material.isRawShaderMaterial ) {
  10648. prefixVertex = [
  10649. customDefines
  10650. ].filter( filterEmptyLine ).join( '\n' );
  10651. if ( prefixVertex.length > 0 ) {
  10652. prefixVertex += '\n';
  10653. }
  10654. prefixFragment = [
  10655. customExtensions,
  10656. customDefines
  10657. ].filter( filterEmptyLine ).join( '\n' );
  10658. if ( prefixFragment.length > 0 ) {
  10659. prefixFragment += '\n';
  10660. }
  10661. } else {
  10662. prefixVertex = [
  10663. 'precision ' + parameters.precision + ' float;',
  10664. 'precision ' + parameters.precision + ' int;',
  10665. '#define SHADER_NAME ' + shader.name,
  10666. customDefines,
  10667. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10668. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10669. '#define MAX_BONES ' + parameters.maxBones,
  10670. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10671. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10672. parameters.map ? '#define USE_MAP' : '',
  10673. parameters.envMap ? '#define USE_ENVMAP' : '',
  10674. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10675. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10676. parameters.aoMap ? '#define USE_AOMAP' : '',
  10677. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10678. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10679. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10680. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10681. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10682. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10683. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10684. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10685. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10686. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10687. parameters.vertexColors ? '#define USE_COLOR' : '',
  10688. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10689. parameters.skinning ? '#define USE_SKINNING' : '',
  10690. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10691. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10692. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10693. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10694. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10695. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10696. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10697. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10698. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10699. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10700. 'uniform mat4 modelMatrix;',
  10701. 'uniform mat4 modelViewMatrix;',
  10702. 'uniform mat4 projectionMatrix;',
  10703. 'uniform mat4 viewMatrix;',
  10704. 'uniform mat3 normalMatrix;',
  10705. 'uniform vec3 cameraPosition;',
  10706. 'attribute vec3 position;',
  10707. 'attribute vec3 normal;',
  10708. 'attribute vec2 uv;',
  10709. '#ifdef USE_TANGENT',
  10710. ' attribute vec4 tangent;',
  10711. '#endif',
  10712. '#ifdef USE_COLOR',
  10713. ' attribute vec3 color;',
  10714. '#endif',
  10715. '#ifdef USE_MORPHTARGETS',
  10716. ' attribute vec3 morphTarget0;',
  10717. ' attribute vec3 morphTarget1;',
  10718. ' attribute vec3 morphTarget2;',
  10719. ' attribute vec3 morphTarget3;',
  10720. ' #ifdef USE_MORPHNORMALS',
  10721. ' attribute vec3 morphNormal0;',
  10722. ' attribute vec3 morphNormal1;',
  10723. ' attribute vec3 morphNormal2;',
  10724. ' attribute vec3 morphNormal3;',
  10725. ' #else',
  10726. ' attribute vec3 morphTarget4;',
  10727. ' attribute vec3 morphTarget5;',
  10728. ' attribute vec3 morphTarget6;',
  10729. ' attribute vec3 morphTarget7;',
  10730. ' #endif',
  10731. '#endif',
  10732. '#ifdef USE_SKINNING',
  10733. ' attribute vec4 skinIndex;',
  10734. ' attribute vec4 skinWeight;',
  10735. '#endif',
  10736. '\n'
  10737. ].filter( filterEmptyLine ).join( '\n' );
  10738. prefixFragment = [
  10739. customExtensions,
  10740. 'precision ' + parameters.precision + ' float;',
  10741. 'precision ' + parameters.precision + ' int;',
  10742. '#define SHADER_NAME ' + shader.name,
  10743. customDefines,
  10744. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10745. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10746. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10747. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10748. parameters.map ? '#define USE_MAP' : '',
  10749. parameters.matcap ? '#define USE_MATCAP' : '',
  10750. parameters.envMap ? '#define USE_ENVMAP' : '',
  10751. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10752. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10753. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10754. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10755. parameters.aoMap ? '#define USE_AOMAP' : '',
  10756. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10757. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10758. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10759. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10760. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10761. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10762. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10763. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10764. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10765. parameters.vertexColors ? '#define USE_COLOR' : '',
  10766. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10767. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10768. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10769. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10770. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10771. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10772. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10773. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10774. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10775. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10776. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10777. 'uniform mat4 viewMatrix;',
  10778. 'uniform vec3 cameraPosition;',
  10779. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10780. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10781. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10782. parameters.dithering ? '#define DITHERING' : '',
  10783. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10784. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10785. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10786. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10787. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10788. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10789. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10790. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10791. '\n'
  10792. ].filter( filterEmptyLine ).join( '\n' );
  10793. }
  10794. vertexShader = parseIncludes( vertexShader );
  10795. vertexShader = replaceLightNums( vertexShader, parameters );
  10796. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10797. fragmentShader = parseIncludes( fragmentShader );
  10798. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10799. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10800. vertexShader = unrollLoops( vertexShader );
  10801. fragmentShader = unrollLoops( fragmentShader );
  10802. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10803. var isGLSL3ShaderMaterial = false;
  10804. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10805. if ( material.isShaderMaterial &&
  10806. vertexShader.match( versionRegex ) !== null &&
  10807. fragmentShader.match( versionRegex ) !== null ) {
  10808. isGLSL3ShaderMaterial = true;
  10809. vertexShader = vertexShader.replace( versionRegex, '' );
  10810. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10811. }
  10812. // GLSL 3.0 conversion
  10813. prefixVertex = [
  10814. '#version 300 es\n',
  10815. '#define attribute in',
  10816. '#define varying out',
  10817. '#define texture2D texture'
  10818. ].join( '\n' ) + '\n' + prefixVertex;
  10819. prefixFragment = [
  10820. '#version 300 es\n',
  10821. '#define varying in',
  10822. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10823. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10824. '#define gl_FragDepthEXT gl_FragDepth',
  10825. '#define texture2D texture',
  10826. '#define textureCube texture',
  10827. '#define texture2DProj textureProj',
  10828. '#define texture2DLodEXT textureLod',
  10829. '#define texture2DProjLodEXT textureProjLod',
  10830. '#define textureCubeLodEXT textureLod',
  10831. '#define texture2DGradEXT textureGrad',
  10832. '#define texture2DProjGradEXT textureProjGrad',
  10833. '#define textureCubeGradEXT textureGrad'
  10834. ].join( '\n' ) + '\n' + prefixFragment;
  10835. }
  10836. var vertexGlsl = prefixVertex + vertexShader;
  10837. var fragmentGlsl = prefixFragment + fragmentShader;
  10838. // console.log( '*VERTEX*', vertexGlsl );
  10839. // console.log( '*FRAGMENT*', fragmentGlsl );
  10840. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10841. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10842. gl.attachShader( program, glVertexShader );
  10843. gl.attachShader( program, glFragmentShader );
  10844. // Force a particular attribute to index 0.
  10845. if ( material.index0AttributeName !== undefined ) {
  10846. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10847. } else if ( parameters.morphTargets === true ) {
  10848. // programs with morphTargets displace position out of attribute 0
  10849. gl.bindAttribLocation( program, 0, 'position' );
  10850. }
  10851. gl.linkProgram( program );
  10852. // check for link errors
  10853. if ( renderer.debug.checkShaderErrors ) {
  10854. var programLog = gl.getProgramInfoLog( program ).trim();
  10855. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10856. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10857. var runnable = true;
  10858. var haveDiagnostics = true;
  10859. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10860. runnable = false;
  10861. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10862. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10863. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10864. } else if ( programLog !== '' ) {
  10865. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10866. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10867. haveDiagnostics = false;
  10868. }
  10869. if ( haveDiagnostics ) {
  10870. this.diagnostics = {
  10871. runnable: runnable,
  10872. material: material,
  10873. programLog: programLog,
  10874. vertexShader: {
  10875. log: vertexLog,
  10876. prefix: prefixVertex
  10877. },
  10878. fragmentShader: {
  10879. log: fragmentLog,
  10880. prefix: prefixFragment
  10881. }
  10882. };
  10883. }
  10884. }
  10885. // clean up
  10886. gl.deleteShader( glVertexShader );
  10887. gl.deleteShader( glFragmentShader );
  10888. // set up caching for uniform locations
  10889. var cachedUniforms;
  10890. this.getUniforms = function () {
  10891. if ( cachedUniforms === undefined ) {
  10892. cachedUniforms = new WebGLUniforms( gl, program );
  10893. }
  10894. return cachedUniforms;
  10895. };
  10896. // set up caching for attribute locations
  10897. var cachedAttributes;
  10898. this.getAttributes = function () {
  10899. if ( cachedAttributes === undefined ) {
  10900. cachedAttributes = fetchAttributeLocations( gl, program );
  10901. }
  10902. return cachedAttributes;
  10903. };
  10904. // free resource
  10905. this.destroy = function () {
  10906. gl.deleteProgram( program );
  10907. this.program = undefined;
  10908. };
  10909. //
  10910. this.name = shader.name;
  10911. this.id = programIdCount ++;
  10912. this.code = code;
  10913. this.usedTimes = 1;
  10914. this.program = program;
  10915. this.vertexShader = glVertexShader;
  10916. this.fragmentShader = glFragmentShader;
  10917. return this;
  10918. }
  10919. /**
  10920. * @author mrdoob / http://mrdoob.com/
  10921. */
  10922. function WebGLPrograms( renderer, extensions, capabilities ) {
  10923. var programs = [];
  10924. var shaderIDs = {
  10925. MeshDepthMaterial: 'depth',
  10926. MeshDistanceMaterial: 'distanceRGBA',
  10927. MeshNormalMaterial: 'normal',
  10928. MeshBasicMaterial: 'basic',
  10929. MeshLambertMaterial: 'lambert',
  10930. MeshPhongMaterial: 'phong',
  10931. MeshToonMaterial: 'phong',
  10932. MeshStandardMaterial: 'physical',
  10933. MeshPhysicalMaterial: 'physical',
  10934. MeshMatcapMaterial: 'matcap',
  10935. LineBasicMaterial: 'basic',
  10936. LineDashedMaterial: 'dashed',
  10937. PointsMaterial: 'points',
  10938. ShadowMaterial: 'shadow',
  10939. SpriteMaterial: 'sprite'
  10940. };
  10941. var parameterNames = [
  10942. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10943. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10944. "roughnessMap", "metalnessMap", "gradientMap",
  10945. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10946. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10947. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10948. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10949. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10950. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10951. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10952. ];
  10953. function allocateBones( object ) {
  10954. var skeleton = object.skeleton;
  10955. var bones = skeleton.bones;
  10956. if ( capabilities.floatVertexTextures ) {
  10957. return 1024;
  10958. } else {
  10959. // default for when object is not specified
  10960. // ( for example when prebuilding shader to be used with multiple objects )
  10961. //
  10962. // - leave some extra space for other uniforms
  10963. // - limit here is ANGLE's 254 max uniform vectors
  10964. // (up to 54 should be safe)
  10965. var nVertexUniforms = capabilities.maxVertexUniforms;
  10966. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10967. var maxBones = Math.min( nVertexMatrices, bones.length );
  10968. if ( maxBones < bones.length ) {
  10969. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10970. return 0;
  10971. }
  10972. return maxBones;
  10973. }
  10974. }
  10975. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10976. var encoding;
  10977. if ( ! map ) {
  10978. encoding = LinearEncoding;
  10979. } else if ( map.isTexture ) {
  10980. encoding = map.encoding;
  10981. } else if ( map.isWebGLRenderTarget ) {
  10982. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10983. encoding = map.texture.encoding;
  10984. }
  10985. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10986. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10987. encoding = GammaEncoding;
  10988. }
  10989. return encoding;
  10990. }
  10991. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10992. var shaderID = shaderIDs[ material.type ];
  10993. // heuristics to create shader parameters according to lights in the scene
  10994. // (not to blow over maxLights budget)
  10995. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10996. var precision = capabilities.precision;
  10997. if ( material.precision !== null ) {
  10998. precision = capabilities.getMaxPrecision( material.precision );
  10999. if ( precision !== material.precision ) {
  11000. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11001. }
  11002. }
  11003. var currentRenderTarget = renderer.getRenderTarget();
  11004. var parameters = {
  11005. shaderID: shaderID,
  11006. precision: precision,
  11007. supportsVertexTextures: capabilities.vertexTextures,
  11008. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  11009. map: !! material.map,
  11010. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  11011. matcap: !! material.matcap,
  11012. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  11013. envMap: !! material.envMap,
  11014. envMapMode: material.envMap && material.envMap.mapping,
  11015. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  11016. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  11017. lightMap: !! material.lightMap,
  11018. aoMap: !! material.aoMap,
  11019. emissiveMap: !! material.emissiveMap,
  11020. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  11021. bumpMap: !! material.bumpMap,
  11022. normalMap: !! material.normalMap,
  11023. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11024. displacementMap: !! material.displacementMap,
  11025. roughnessMap: !! material.roughnessMap,
  11026. metalnessMap: !! material.metalnessMap,
  11027. specularMap: !! material.specularMap,
  11028. alphaMap: !! material.alphaMap,
  11029. gradientMap: !! material.gradientMap,
  11030. combine: material.combine,
  11031. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11032. vertexColors: material.vertexColors,
  11033. fog: !! fog,
  11034. useFog: material.fog,
  11035. fogExp: ( fog && fog.isFogExp2 ),
  11036. flatShading: material.flatShading,
  11037. sizeAttenuation: material.sizeAttenuation,
  11038. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  11039. skinning: material.skinning && maxBones > 0,
  11040. maxBones: maxBones,
  11041. useVertexTexture: capabilities.floatVertexTextures,
  11042. morphTargets: material.morphTargets,
  11043. morphNormals: material.morphNormals,
  11044. maxMorphTargets: renderer.maxMorphTargets,
  11045. maxMorphNormals: renderer.maxMorphNormals,
  11046. numDirLights: lights.directional.length,
  11047. numPointLights: lights.point.length,
  11048. numSpotLights: lights.spot.length,
  11049. numRectAreaLights: lights.rectArea.length,
  11050. numHemiLights: lights.hemi.length,
  11051. numClippingPlanes: nClipPlanes,
  11052. numClipIntersection: nClipIntersection,
  11053. dithering: material.dithering,
  11054. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  11055. shadowMapType: renderer.shadowMap.type,
  11056. toneMapping: renderer.toneMapping,
  11057. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11058. premultipliedAlpha: material.premultipliedAlpha,
  11059. alphaTest: material.alphaTest,
  11060. doubleSided: material.side === DoubleSide,
  11061. flipSided: material.side === BackSide,
  11062. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  11063. };
  11064. return parameters;
  11065. };
  11066. this.getProgramCode = function ( material, parameters ) {
  11067. var array = [];
  11068. if ( parameters.shaderID ) {
  11069. array.push( parameters.shaderID );
  11070. } else {
  11071. array.push( material.fragmentShader );
  11072. array.push( material.vertexShader );
  11073. }
  11074. if ( material.defines !== undefined ) {
  11075. for ( var name in material.defines ) {
  11076. array.push( name );
  11077. array.push( material.defines[ name ] );
  11078. }
  11079. }
  11080. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11081. array.push( parameters[ parameterNames[ i ] ] );
  11082. }
  11083. array.push( material.onBeforeCompile.toString() );
  11084. array.push( renderer.gammaOutput );
  11085. array.push( renderer.gammaFactor );
  11086. return array.join();
  11087. };
  11088. this.acquireProgram = function ( material, shader, parameters, code ) {
  11089. var program;
  11090. // Check if code has been already compiled
  11091. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11092. var programInfo = programs[ p ];
  11093. if ( programInfo.code === code ) {
  11094. program = programInfo;
  11095. ++ program.usedTimes;
  11096. break;
  11097. }
  11098. }
  11099. if ( program === undefined ) {
  11100. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  11101. programs.push( program );
  11102. }
  11103. return program;
  11104. };
  11105. this.releaseProgram = function ( program ) {
  11106. if ( -- program.usedTimes === 0 ) {
  11107. // Remove from unordered set
  11108. var i = programs.indexOf( program );
  11109. programs[ i ] = programs[ programs.length - 1 ];
  11110. programs.pop();
  11111. // Free WebGL resources
  11112. program.destroy();
  11113. }
  11114. };
  11115. // Exposed for resource monitoring & error feedback via renderer.info:
  11116. this.programs = programs;
  11117. }
  11118. /**
  11119. * @author fordacious / fordacious.github.io
  11120. */
  11121. function WebGLProperties() {
  11122. var properties = new WeakMap();
  11123. function get( object ) {
  11124. var map = properties.get( object );
  11125. if ( map === undefined ) {
  11126. map = {};
  11127. properties.set( object, map );
  11128. }
  11129. return map;
  11130. }
  11131. function remove( object ) {
  11132. properties.delete( object );
  11133. }
  11134. function update( object, key, value ) {
  11135. properties.get( object )[ key ] = value;
  11136. }
  11137. function dispose() {
  11138. properties = new WeakMap();
  11139. }
  11140. return {
  11141. get: get,
  11142. remove: remove,
  11143. update: update,
  11144. dispose: dispose
  11145. };
  11146. }
  11147. /**
  11148. * @author mrdoob / http://mrdoob.com/
  11149. */
  11150. function painterSortStable( a, b ) {
  11151. if ( a.groupOrder !== b.groupOrder ) {
  11152. return a.groupOrder - b.groupOrder;
  11153. } else if ( a.renderOrder !== b.renderOrder ) {
  11154. return a.renderOrder - b.renderOrder;
  11155. } else if ( a.program !== b.program ) {
  11156. return a.program.id - b.program.id;
  11157. } else if ( a.material.id !== b.material.id ) {
  11158. return a.material.id - b.material.id;
  11159. } else if ( a.z !== b.z ) {
  11160. return a.z - b.z;
  11161. } else {
  11162. return a.id - b.id;
  11163. }
  11164. }
  11165. function reversePainterSortStable( a, b ) {
  11166. if ( a.groupOrder !== b.groupOrder ) {
  11167. return a.groupOrder - b.groupOrder;
  11168. } else if ( a.renderOrder !== b.renderOrder ) {
  11169. return a.renderOrder - b.renderOrder;
  11170. } else if ( a.z !== b.z ) {
  11171. return b.z - a.z;
  11172. } else {
  11173. return a.id - b.id;
  11174. }
  11175. }
  11176. function WebGLRenderList() {
  11177. var renderItems = [];
  11178. var renderItemsIndex = 0;
  11179. var opaque = [];
  11180. var transparent = [];
  11181. var defaultProgram = { id: - 1 };
  11182. function init() {
  11183. renderItemsIndex = 0;
  11184. opaque.length = 0;
  11185. transparent.length = 0;
  11186. }
  11187. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11188. var renderItem = renderItems[ renderItemsIndex ];
  11189. if ( renderItem === undefined ) {
  11190. renderItem = {
  11191. id: object.id,
  11192. object: object,
  11193. geometry: geometry,
  11194. material: material,
  11195. program: material.program || defaultProgram,
  11196. groupOrder: groupOrder,
  11197. renderOrder: object.renderOrder,
  11198. z: z,
  11199. group: group
  11200. };
  11201. renderItems[ renderItemsIndex ] = renderItem;
  11202. } else {
  11203. renderItem.id = object.id;
  11204. renderItem.object = object;
  11205. renderItem.geometry = geometry;
  11206. renderItem.material = material;
  11207. renderItem.program = material.program || defaultProgram;
  11208. renderItem.groupOrder = groupOrder;
  11209. renderItem.renderOrder = object.renderOrder;
  11210. renderItem.z = z;
  11211. renderItem.group = group;
  11212. }
  11213. renderItemsIndex ++;
  11214. return renderItem;
  11215. }
  11216. function push( object, geometry, material, groupOrder, z, group ) {
  11217. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11218. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11219. }
  11220. function unshift( object, geometry, material, groupOrder, z, group ) {
  11221. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11222. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11223. }
  11224. function sort() {
  11225. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  11226. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  11227. }
  11228. return {
  11229. opaque: opaque,
  11230. transparent: transparent,
  11231. init: init,
  11232. push: push,
  11233. unshift: unshift,
  11234. sort: sort
  11235. };
  11236. }
  11237. function WebGLRenderLists() {
  11238. var lists = {};
  11239. function onSceneDispose( event ) {
  11240. var scene = event.target;
  11241. scene.removeEventListener( 'dispose', onSceneDispose );
  11242. delete lists[ scene.id ];
  11243. }
  11244. function get( scene, camera ) {
  11245. var cameras = lists[ scene.id ];
  11246. var list;
  11247. if ( cameras === undefined ) {
  11248. list = new WebGLRenderList();
  11249. lists[ scene.id ] = {};
  11250. lists[ scene.id ][ camera.id ] = list;
  11251. scene.addEventListener( 'dispose', onSceneDispose );
  11252. } else {
  11253. list = cameras[ camera.id ];
  11254. if ( list === undefined ) {
  11255. list = new WebGLRenderList();
  11256. cameras[ camera.id ] = list;
  11257. }
  11258. }
  11259. return list;
  11260. }
  11261. function dispose() {
  11262. lists = {};
  11263. }
  11264. return {
  11265. get: get,
  11266. dispose: dispose
  11267. };
  11268. }
  11269. /**
  11270. * @author mrdoob / http://mrdoob.com/
  11271. */
  11272. function UniformsCache() {
  11273. var lights = {};
  11274. return {
  11275. get: function ( light ) {
  11276. if ( lights[ light.id ] !== undefined ) {
  11277. return lights[ light.id ];
  11278. }
  11279. var uniforms;
  11280. switch ( light.type ) {
  11281. case 'DirectionalLight':
  11282. uniforms = {
  11283. direction: new Vector3(),
  11284. color: new Color(),
  11285. shadow: false,
  11286. shadowBias: 0,
  11287. shadowRadius: 1,
  11288. shadowMapSize: new Vector2()
  11289. };
  11290. break;
  11291. case 'SpotLight':
  11292. uniforms = {
  11293. position: new Vector3(),
  11294. direction: new Vector3(),
  11295. color: new Color(),
  11296. distance: 0,
  11297. coneCos: 0,
  11298. penumbraCos: 0,
  11299. decay: 0,
  11300. shadow: false,
  11301. shadowBias: 0,
  11302. shadowRadius: 1,
  11303. shadowMapSize: new Vector2()
  11304. };
  11305. break;
  11306. case 'PointLight':
  11307. uniforms = {
  11308. position: new Vector3(),
  11309. color: new Color(),
  11310. distance: 0,
  11311. decay: 0,
  11312. shadow: false,
  11313. shadowBias: 0,
  11314. shadowRadius: 1,
  11315. shadowMapSize: new Vector2(),
  11316. shadowCameraNear: 1,
  11317. shadowCameraFar: 1000
  11318. };
  11319. break;
  11320. case 'HemisphereLight':
  11321. uniforms = {
  11322. direction: new Vector3(),
  11323. skyColor: new Color(),
  11324. groundColor: new Color()
  11325. };
  11326. break;
  11327. case 'RectAreaLight':
  11328. uniforms = {
  11329. color: new Color(),
  11330. position: new Vector3(),
  11331. halfWidth: new Vector3(),
  11332. halfHeight: new Vector3()
  11333. // TODO (abelnation): set RectAreaLight shadow uniforms
  11334. };
  11335. break;
  11336. }
  11337. lights[ light.id ] = uniforms;
  11338. return uniforms;
  11339. }
  11340. };
  11341. }
  11342. var nextVersion = 0;
  11343. function WebGLLights() {
  11344. var cache = new UniformsCache();
  11345. var state = {
  11346. version: 0,
  11347. hash: {
  11348. directionalLength: - 1,
  11349. pointLength: - 1,
  11350. spotLength: - 1,
  11351. rectAreaLength: - 1,
  11352. hemiLength: - 1,
  11353. shadowsLength: - 1,
  11354. },
  11355. ambient: [ 0, 0, 0 ],
  11356. probe: [],
  11357. directional: [],
  11358. directionalShadowMap: [],
  11359. directionalShadowMatrix: [],
  11360. spot: [],
  11361. spotShadowMap: [],
  11362. spotShadowMatrix: [],
  11363. rectArea: [],
  11364. point: [],
  11365. pointShadowMap: [],
  11366. pointShadowMatrix: [],
  11367. hemi: []
  11368. };
  11369. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11370. var vector3 = new Vector3();
  11371. var matrix4 = new Matrix4();
  11372. var matrix42 = new Matrix4();
  11373. function setup( lights, shadows, camera ) {
  11374. var r = 0, g = 0, b = 0;
  11375. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11376. var directionalLength = 0;
  11377. var pointLength = 0;
  11378. var spotLength = 0;
  11379. var rectAreaLength = 0;
  11380. var hemiLength = 0;
  11381. var viewMatrix = camera.matrixWorldInverse;
  11382. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  11383. var light = lights[ i ];
  11384. var color = light.color;
  11385. var intensity = light.intensity;
  11386. var distance = light.distance;
  11387. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11388. if ( light.isAmbientLight ) {
  11389. r += color.r * intensity;
  11390. g += color.g * intensity;
  11391. b += color.b * intensity;
  11392. } else if ( light.isLightProbe ) {
  11393. for ( var j = 0; j < 9; j ++ ) {
  11394. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11395. }
  11396. } else if ( light.isDirectionalLight ) {
  11397. var uniforms = cache.get( light );
  11398. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11399. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11400. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11401. uniforms.direction.sub( vector3 );
  11402. uniforms.direction.transformDirection( viewMatrix );
  11403. uniforms.shadow = light.castShadow;
  11404. if ( light.castShadow ) {
  11405. var shadow = light.shadow;
  11406. uniforms.shadowBias = shadow.bias;
  11407. uniforms.shadowRadius = shadow.radius;
  11408. uniforms.shadowMapSize = shadow.mapSize;
  11409. }
  11410. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11411. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11412. state.directional[ directionalLength ] = uniforms;
  11413. directionalLength ++;
  11414. } else if ( light.isSpotLight ) {
  11415. var uniforms = cache.get( light );
  11416. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11417. uniforms.position.applyMatrix4( viewMatrix );
  11418. uniforms.color.copy( color ).multiplyScalar( intensity );
  11419. uniforms.distance = distance;
  11420. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11421. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11422. uniforms.direction.sub( vector3 );
  11423. uniforms.direction.transformDirection( viewMatrix );
  11424. uniforms.coneCos = Math.cos( light.angle );
  11425. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11426. uniforms.decay = light.decay;
  11427. uniforms.shadow = light.castShadow;
  11428. if ( light.castShadow ) {
  11429. var shadow = light.shadow;
  11430. uniforms.shadowBias = shadow.bias;
  11431. uniforms.shadowRadius = shadow.radius;
  11432. uniforms.shadowMapSize = shadow.mapSize;
  11433. }
  11434. state.spotShadowMap[ spotLength ] = shadowMap;
  11435. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11436. state.spot[ spotLength ] = uniforms;
  11437. spotLength ++;
  11438. } else if ( light.isRectAreaLight ) {
  11439. var uniforms = cache.get( light );
  11440. // (a) intensity is the total visible light emitted
  11441. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11442. // (b) intensity is the brightness of the light
  11443. uniforms.color.copy( color ).multiplyScalar( intensity );
  11444. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11445. uniforms.position.applyMatrix4( viewMatrix );
  11446. // extract local rotation of light to derive width/height half vectors
  11447. matrix42.identity();
  11448. matrix4.copy( light.matrixWorld );
  11449. matrix4.premultiply( viewMatrix );
  11450. matrix42.extractRotation( matrix4 );
  11451. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11452. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11453. uniforms.halfWidth.applyMatrix4( matrix42 );
  11454. uniforms.halfHeight.applyMatrix4( matrix42 );
  11455. // TODO (abelnation): RectAreaLight distance?
  11456. // uniforms.distance = distance;
  11457. state.rectArea[ rectAreaLength ] = uniforms;
  11458. rectAreaLength ++;
  11459. } else if ( light.isPointLight ) {
  11460. var uniforms = cache.get( light );
  11461. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11462. uniforms.position.applyMatrix4( viewMatrix );
  11463. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11464. uniforms.distance = light.distance;
  11465. uniforms.decay = light.decay;
  11466. uniforms.shadow = light.castShadow;
  11467. if ( light.castShadow ) {
  11468. var shadow = light.shadow;
  11469. uniforms.shadowBias = shadow.bias;
  11470. uniforms.shadowRadius = shadow.radius;
  11471. uniforms.shadowMapSize = shadow.mapSize;
  11472. uniforms.shadowCameraNear = shadow.camera.near;
  11473. uniforms.shadowCameraFar = shadow.camera.far;
  11474. }
  11475. state.pointShadowMap[ pointLength ] = shadowMap;
  11476. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11477. state.point[ pointLength ] = uniforms;
  11478. pointLength ++;
  11479. } else if ( light.isHemisphereLight ) {
  11480. var uniforms = cache.get( light );
  11481. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11482. uniforms.direction.transformDirection( viewMatrix );
  11483. uniforms.direction.normalize();
  11484. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11485. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11486. state.hemi[ hemiLength ] = uniforms;
  11487. hemiLength ++;
  11488. }
  11489. }
  11490. state.ambient[ 0 ] = r;
  11491. state.ambient[ 1 ] = g;
  11492. state.ambient[ 2 ] = b;
  11493. var hash = state.hash;
  11494. if ( hash.directionalLength !== directionalLength ||
  11495. hash.pointLength !== pointLength ||
  11496. hash.spotLength !== spotLength ||
  11497. hash.rectAreaLength !== rectAreaLength ||
  11498. hash.hemiLength !== hemiLength ||
  11499. hash.shadowsLength !== shadows.length ) {
  11500. state.directional.length = directionalLength;
  11501. state.spot.length = spotLength;
  11502. state.rectArea.length = rectAreaLength;
  11503. state.point.length = pointLength;
  11504. state.hemi.length = hemiLength;
  11505. hash.directionalLength = directionalLength;
  11506. hash.pointLength = pointLength;
  11507. hash.spotLength = spotLength;
  11508. hash.rectAreaLength = rectAreaLength;
  11509. hash.hemiLength = hemiLength;
  11510. hash.shadowsLength = shadows.length;
  11511. state.version = nextVersion ++;
  11512. }
  11513. }
  11514. return {
  11515. setup: setup,
  11516. state: state
  11517. };
  11518. }
  11519. /**
  11520. * @author Mugen87 / https://github.com/Mugen87
  11521. */
  11522. function WebGLRenderState() {
  11523. var lights = new WebGLLights();
  11524. var lightsArray = [];
  11525. var shadowsArray = [];
  11526. function init() {
  11527. lightsArray.length = 0;
  11528. shadowsArray.length = 0;
  11529. }
  11530. function pushLight( light ) {
  11531. lightsArray.push( light );
  11532. }
  11533. function pushShadow( shadowLight ) {
  11534. shadowsArray.push( shadowLight );
  11535. }
  11536. function setupLights( camera ) {
  11537. lights.setup( lightsArray, shadowsArray, camera );
  11538. }
  11539. var state = {
  11540. lightsArray: lightsArray,
  11541. shadowsArray: shadowsArray,
  11542. lights: lights
  11543. };
  11544. return {
  11545. init: init,
  11546. state: state,
  11547. setupLights: setupLights,
  11548. pushLight: pushLight,
  11549. pushShadow: pushShadow
  11550. };
  11551. }
  11552. function WebGLRenderStates() {
  11553. var renderStates = {};
  11554. function onSceneDispose( event ) {
  11555. var scene = event.target;
  11556. scene.removeEventListener( 'dispose', onSceneDispose );
  11557. delete renderStates[ scene.id ];
  11558. }
  11559. function get( scene, camera ) {
  11560. var renderState;
  11561. if ( renderStates[ scene.id ] === undefined ) {
  11562. renderState = new WebGLRenderState();
  11563. renderStates[ scene.id ] = {};
  11564. renderStates[ scene.id ][ camera.id ] = renderState;
  11565. scene.addEventListener( 'dispose', onSceneDispose );
  11566. } else {
  11567. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11568. renderState = new WebGLRenderState();
  11569. renderStates[ scene.id ][ camera.id ] = renderState;
  11570. } else {
  11571. renderState = renderStates[ scene.id ][ camera.id ];
  11572. }
  11573. }
  11574. return renderState;
  11575. }
  11576. function dispose() {
  11577. renderStates = {};
  11578. }
  11579. return {
  11580. get: get,
  11581. dispose: dispose
  11582. };
  11583. }
  11584. /**
  11585. * @author mrdoob / http://mrdoob.com/
  11586. * @author alteredq / http://alteredqualia.com/
  11587. * @author bhouston / https://clara.io
  11588. * @author WestLangley / http://github.com/WestLangley
  11589. *
  11590. * parameters = {
  11591. *
  11592. * opacity: <float>,
  11593. *
  11594. * map: new THREE.Texture( <Image> ),
  11595. *
  11596. * alphaMap: new THREE.Texture( <Image> ),
  11597. *
  11598. * displacementMap: new THREE.Texture( <Image> ),
  11599. * displacementScale: <float>,
  11600. * displacementBias: <float>,
  11601. *
  11602. * wireframe: <boolean>,
  11603. * wireframeLinewidth: <float>
  11604. * }
  11605. */
  11606. function MeshDepthMaterial( parameters ) {
  11607. Material.call( this );
  11608. this.type = 'MeshDepthMaterial';
  11609. this.depthPacking = BasicDepthPacking;
  11610. this.skinning = false;
  11611. this.morphTargets = false;
  11612. this.map = null;
  11613. this.alphaMap = null;
  11614. this.displacementMap = null;
  11615. this.displacementScale = 1;
  11616. this.displacementBias = 0;
  11617. this.wireframe = false;
  11618. this.wireframeLinewidth = 1;
  11619. this.fog = false;
  11620. this.lights = false;
  11621. this.setValues( parameters );
  11622. }
  11623. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11624. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11625. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11626. MeshDepthMaterial.prototype.copy = function ( source ) {
  11627. Material.prototype.copy.call( this, source );
  11628. this.depthPacking = source.depthPacking;
  11629. this.skinning = source.skinning;
  11630. this.morphTargets = source.morphTargets;
  11631. this.map = source.map;
  11632. this.alphaMap = source.alphaMap;
  11633. this.displacementMap = source.displacementMap;
  11634. this.displacementScale = source.displacementScale;
  11635. this.displacementBias = source.displacementBias;
  11636. this.wireframe = source.wireframe;
  11637. this.wireframeLinewidth = source.wireframeLinewidth;
  11638. return this;
  11639. };
  11640. /**
  11641. * @author WestLangley / http://github.com/WestLangley
  11642. *
  11643. * parameters = {
  11644. *
  11645. * referencePosition: <float>,
  11646. * nearDistance: <float>,
  11647. * farDistance: <float>,
  11648. *
  11649. * skinning: <bool>,
  11650. * morphTargets: <bool>,
  11651. *
  11652. * map: new THREE.Texture( <Image> ),
  11653. *
  11654. * alphaMap: new THREE.Texture( <Image> ),
  11655. *
  11656. * displacementMap: new THREE.Texture( <Image> ),
  11657. * displacementScale: <float>,
  11658. * displacementBias: <float>
  11659. *
  11660. * }
  11661. */
  11662. function MeshDistanceMaterial( parameters ) {
  11663. Material.call( this );
  11664. this.type = 'MeshDistanceMaterial';
  11665. this.referencePosition = new Vector3();
  11666. this.nearDistance = 1;
  11667. this.farDistance = 1000;
  11668. this.skinning = false;
  11669. this.morphTargets = false;
  11670. this.map = null;
  11671. this.alphaMap = null;
  11672. this.displacementMap = null;
  11673. this.displacementScale = 1;
  11674. this.displacementBias = 0;
  11675. this.fog = false;
  11676. this.lights = false;
  11677. this.setValues( parameters );
  11678. }
  11679. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11680. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11681. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11682. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11683. Material.prototype.copy.call( this, source );
  11684. this.referencePosition.copy( source.referencePosition );
  11685. this.nearDistance = source.nearDistance;
  11686. this.farDistance = source.farDistance;
  11687. this.skinning = source.skinning;
  11688. this.morphTargets = source.morphTargets;
  11689. this.map = source.map;
  11690. this.alphaMap = source.alphaMap;
  11691. this.displacementMap = source.displacementMap;
  11692. this.displacementScale = source.displacementScale;
  11693. this.displacementBias = source.displacementBias;
  11694. return this;
  11695. };
  11696. /**
  11697. * @author alteredq / http://alteredqualia.com/
  11698. * @author mrdoob / http://mrdoob.com/
  11699. */
  11700. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11701. var _frustum = new Frustum(),
  11702. _projScreenMatrix = new Matrix4(),
  11703. _shadowMapSize = new Vector2(),
  11704. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11705. _lookTarget = new Vector3(),
  11706. _lightPositionWorld = new Vector3(),
  11707. _MorphingFlag = 1,
  11708. _SkinningFlag = 2,
  11709. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11710. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11711. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11712. _materialCache = {};
  11713. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11714. var cubeDirections = [
  11715. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11716. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11717. ];
  11718. var cubeUps = [
  11719. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11720. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11721. ];
  11722. var cube2DViewPorts = [
  11723. new Vector4(), new Vector4(), new Vector4(),
  11724. new Vector4(), new Vector4(), new Vector4()
  11725. ];
  11726. // init
  11727. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11728. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11729. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11730. var depthMaterial = new MeshDepthMaterial( {
  11731. depthPacking: RGBADepthPacking,
  11732. morphTargets: useMorphing,
  11733. skinning: useSkinning
  11734. } );
  11735. _depthMaterials[ i ] = depthMaterial;
  11736. //
  11737. var distanceMaterial = new MeshDistanceMaterial( {
  11738. morphTargets: useMorphing,
  11739. skinning: useSkinning
  11740. } );
  11741. _distanceMaterials[ i ] = distanceMaterial;
  11742. }
  11743. //
  11744. var scope = this;
  11745. this.enabled = false;
  11746. this.autoUpdate = true;
  11747. this.needsUpdate = false;
  11748. this.type = PCFShadowMap;
  11749. this.render = function ( lights, scene, camera ) {
  11750. if ( scope.enabled === false ) return;
  11751. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11752. if ( lights.length === 0 ) return;
  11753. var currentRenderTarget = _renderer.getRenderTarget();
  11754. var activeCubeFace = _renderer.getActiveCubeFace();
  11755. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11756. var _state = _renderer.state;
  11757. // Set GL state for depth map.
  11758. _state.setBlending( NoBlending );
  11759. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11760. _state.buffers.depth.setTest( true );
  11761. _state.setScissorTest( false );
  11762. // render depth map
  11763. var faceCount;
  11764. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11765. var light = lights[ i ];
  11766. var shadow = light.shadow;
  11767. var isPointLight = light && light.isPointLight;
  11768. if ( shadow === undefined ) {
  11769. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11770. continue;
  11771. }
  11772. var shadowCamera = shadow.camera;
  11773. _shadowMapSize.copy( shadow.mapSize );
  11774. _shadowMapSize.min( _maxShadowMapSize );
  11775. if ( isPointLight ) {
  11776. var vpWidth = _shadowMapSize.x;
  11777. var vpHeight = _shadowMapSize.y;
  11778. // These viewports map a cube-map onto a 2D texture with the
  11779. // following orientation:
  11780. //
  11781. // xzXZ
  11782. // y Y
  11783. //
  11784. // X - Positive x direction
  11785. // x - Negative x direction
  11786. // Y - Positive y direction
  11787. // y - Negative y direction
  11788. // Z - Positive z direction
  11789. // z - Negative z direction
  11790. // positive X
  11791. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11792. // negative X
  11793. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11794. // positive Z
  11795. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11796. // negative Z
  11797. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11798. // positive Y
  11799. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11800. // negative Y
  11801. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11802. _shadowMapSize.x *= 4.0;
  11803. _shadowMapSize.y *= 2.0;
  11804. }
  11805. if ( shadow.map === null ) {
  11806. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11807. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11808. shadow.map.texture.name = light.name + ".shadowMap";
  11809. shadowCamera.updateProjectionMatrix();
  11810. }
  11811. if ( shadow.isSpotLightShadow ) {
  11812. shadow.update( light );
  11813. }
  11814. var shadowMap = shadow.map;
  11815. var shadowMatrix = shadow.matrix;
  11816. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11817. shadowCamera.position.copy( _lightPositionWorld );
  11818. if ( isPointLight ) {
  11819. faceCount = 6;
  11820. // for point lights we set the shadow matrix to be a translation-only matrix
  11821. // equal to inverse of the light's position
  11822. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11823. } else {
  11824. faceCount = 1;
  11825. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11826. shadowCamera.lookAt( _lookTarget );
  11827. shadowCamera.updateMatrixWorld();
  11828. // compute shadow matrix
  11829. shadowMatrix.set(
  11830. 0.5, 0.0, 0.0, 0.5,
  11831. 0.0, 0.5, 0.0, 0.5,
  11832. 0.0, 0.0, 0.5, 0.5,
  11833. 0.0, 0.0, 0.0, 1.0
  11834. );
  11835. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11836. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11837. }
  11838. _renderer.setRenderTarget( shadowMap );
  11839. _renderer.clear();
  11840. // render shadow map for each cube face (if omni-directional) or
  11841. // run a single pass if not
  11842. for ( var face = 0; face < faceCount; face ++ ) {
  11843. if ( isPointLight ) {
  11844. _lookTarget.copy( shadowCamera.position );
  11845. _lookTarget.add( cubeDirections[ face ] );
  11846. shadowCamera.up.copy( cubeUps[ face ] );
  11847. shadowCamera.lookAt( _lookTarget );
  11848. shadowCamera.updateMatrixWorld();
  11849. var vpDimensions = cube2DViewPorts[ face ];
  11850. _state.viewport( vpDimensions );
  11851. }
  11852. // update camera matrices and frustum
  11853. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11854. _frustum.setFromMatrix( _projScreenMatrix );
  11855. // set object matrices & frustum culling
  11856. renderObject( scene, camera, shadowCamera, isPointLight );
  11857. }
  11858. }
  11859. scope.needsUpdate = false;
  11860. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11861. };
  11862. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11863. var geometry = object.geometry;
  11864. var result = null;
  11865. var materialVariants = _depthMaterials;
  11866. var customMaterial = object.customDepthMaterial;
  11867. if ( isPointLight ) {
  11868. materialVariants = _distanceMaterials;
  11869. customMaterial = object.customDistanceMaterial;
  11870. }
  11871. if ( ! customMaterial ) {
  11872. var useMorphing = false;
  11873. if ( material.morphTargets ) {
  11874. if ( geometry && geometry.isBufferGeometry ) {
  11875. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11876. } else if ( geometry && geometry.isGeometry ) {
  11877. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11878. }
  11879. }
  11880. if ( object.isSkinnedMesh && material.skinning === false ) {
  11881. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11882. }
  11883. var useSkinning = object.isSkinnedMesh && material.skinning;
  11884. var variantIndex = 0;
  11885. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11886. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11887. result = materialVariants[ variantIndex ];
  11888. } else {
  11889. result = customMaterial;
  11890. }
  11891. if ( _renderer.localClippingEnabled &&
  11892. material.clipShadows === true &&
  11893. material.clippingPlanes.length !== 0 ) {
  11894. // in this case we need a unique material instance reflecting the
  11895. // appropriate state
  11896. var keyA = result.uuid, keyB = material.uuid;
  11897. var materialsForVariant = _materialCache[ keyA ];
  11898. if ( materialsForVariant === undefined ) {
  11899. materialsForVariant = {};
  11900. _materialCache[ keyA ] = materialsForVariant;
  11901. }
  11902. var cachedMaterial = materialsForVariant[ keyB ];
  11903. if ( cachedMaterial === undefined ) {
  11904. cachedMaterial = result.clone();
  11905. materialsForVariant[ keyB ] = cachedMaterial;
  11906. }
  11907. result = cachedMaterial;
  11908. }
  11909. result.visible = material.visible;
  11910. result.wireframe = material.wireframe;
  11911. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11912. result.clipShadows = material.clipShadows;
  11913. result.clippingPlanes = material.clippingPlanes;
  11914. result.clipIntersection = material.clipIntersection;
  11915. result.wireframeLinewidth = material.wireframeLinewidth;
  11916. result.linewidth = material.linewidth;
  11917. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11918. result.referencePosition.copy( lightPositionWorld );
  11919. result.nearDistance = shadowCameraNear;
  11920. result.farDistance = shadowCameraFar;
  11921. }
  11922. return result;
  11923. }
  11924. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11925. if ( object.visible === false ) return;
  11926. var visible = object.layers.test( camera.layers );
  11927. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11928. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11929. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11930. var geometry = _objects.update( object );
  11931. var material = object.material;
  11932. if ( Array.isArray( material ) ) {
  11933. var groups = geometry.groups;
  11934. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11935. var group = groups[ k ];
  11936. var groupMaterial = material[ group.materialIndex ];
  11937. if ( groupMaterial && groupMaterial.visible ) {
  11938. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11939. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11940. }
  11941. }
  11942. } else if ( material.visible ) {
  11943. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11944. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11945. }
  11946. }
  11947. }
  11948. var children = object.children;
  11949. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11950. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11951. }
  11952. }
  11953. }
  11954. /**
  11955. * @author mrdoob / http://mrdoob.com/
  11956. */
  11957. function WebGLState( gl, extensions, utils, capabilities ) {
  11958. function ColorBuffer() {
  11959. var locked = false;
  11960. var color = new Vector4();
  11961. var currentColorMask = null;
  11962. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11963. return {
  11964. setMask: function ( colorMask ) {
  11965. if ( currentColorMask !== colorMask && ! locked ) {
  11966. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11967. currentColorMask = colorMask;
  11968. }
  11969. },
  11970. setLocked: function ( lock ) {
  11971. locked = lock;
  11972. },
  11973. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11974. if ( premultipliedAlpha === true ) {
  11975. r *= a; g *= a; b *= a;
  11976. }
  11977. color.set( r, g, b, a );
  11978. if ( currentColorClear.equals( color ) === false ) {
  11979. gl.clearColor( r, g, b, a );
  11980. currentColorClear.copy( color );
  11981. }
  11982. },
  11983. reset: function () {
  11984. locked = false;
  11985. currentColorMask = null;
  11986. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11987. }
  11988. };
  11989. }
  11990. function DepthBuffer() {
  11991. var locked = false;
  11992. var currentDepthMask = null;
  11993. var currentDepthFunc = null;
  11994. var currentDepthClear = null;
  11995. return {
  11996. setTest: function ( depthTest ) {
  11997. if ( depthTest ) {
  11998. enable( 2929 );
  11999. } else {
  12000. disable( 2929 );
  12001. }
  12002. },
  12003. setMask: function ( depthMask ) {
  12004. if ( currentDepthMask !== depthMask && ! locked ) {
  12005. gl.depthMask( depthMask );
  12006. currentDepthMask = depthMask;
  12007. }
  12008. },
  12009. setFunc: function ( depthFunc ) {
  12010. if ( currentDepthFunc !== depthFunc ) {
  12011. if ( depthFunc ) {
  12012. switch ( depthFunc ) {
  12013. case NeverDepth:
  12014. gl.depthFunc( 512 );
  12015. break;
  12016. case AlwaysDepth:
  12017. gl.depthFunc( 519 );
  12018. break;
  12019. case LessDepth:
  12020. gl.depthFunc( 513 );
  12021. break;
  12022. case LessEqualDepth:
  12023. gl.depthFunc( 515 );
  12024. break;
  12025. case EqualDepth:
  12026. gl.depthFunc( 514 );
  12027. break;
  12028. case GreaterEqualDepth:
  12029. gl.depthFunc( 518 );
  12030. break;
  12031. case GreaterDepth:
  12032. gl.depthFunc( 516 );
  12033. break;
  12034. case NotEqualDepth:
  12035. gl.depthFunc( 517 );
  12036. break;
  12037. default:
  12038. gl.depthFunc( 515 );
  12039. }
  12040. } else {
  12041. gl.depthFunc( 515 );
  12042. }
  12043. currentDepthFunc = depthFunc;
  12044. }
  12045. },
  12046. setLocked: function ( lock ) {
  12047. locked = lock;
  12048. },
  12049. setClear: function ( depth ) {
  12050. if ( currentDepthClear !== depth ) {
  12051. gl.clearDepth( depth );
  12052. currentDepthClear = depth;
  12053. }
  12054. },
  12055. reset: function () {
  12056. locked = false;
  12057. currentDepthMask = null;
  12058. currentDepthFunc = null;
  12059. currentDepthClear = null;
  12060. }
  12061. };
  12062. }
  12063. function StencilBuffer() {
  12064. var locked = false;
  12065. var currentStencilMask = null;
  12066. var currentStencilFunc = null;
  12067. var currentStencilRef = null;
  12068. var currentStencilFuncMask = null;
  12069. var currentStencilFail = null;
  12070. var currentStencilZFail = null;
  12071. var currentStencilZPass = null;
  12072. var currentStencilClear = null;
  12073. return {
  12074. setTest: function ( stencilTest ) {
  12075. if ( ! locked ) {
  12076. if ( stencilTest ) {
  12077. enable( 2960 );
  12078. } else {
  12079. disable( 2960 );
  12080. }
  12081. }
  12082. },
  12083. setMask: function ( stencilMask ) {
  12084. if ( currentStencilMask !== stencilMask && ! locked ) {
  12085. gl.stencilMask( stencilMask );
  12086. currentStencilMask = stencilMask;
  12087. }
  12088. },
  12089. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12090. if ( currentStencilFunc !== stencilFunc ||
  12091. currentStencilRef !== stencilRef ||
  12092. currentStencilFuncMask !== stencilMask ) {
  12093. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12094. currentStencilFunc = stencilFunc;
  12095. currentStencilRef = stencilRef;
  12096. currentStencilFuncMask = stencilMask;
  12097. }
  12098. },
  12099. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12100. if ( currentStencilFail !== stencilFail ||
  12101. currentStencilZFail !== stencilZFail ||
  12102. currentStencilZPass !== stencilZPass ) {
  12103. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12104. currentStencilFail = stencilFail;
  12105. currentStencilZFail = stencilZFail;
  12106. currentStencilZPass = stencilZPass;
  12107. }
  12108. },
  12109. setLocked: function ( lock ) {
  12110. locked = lock;
  12111. },
  12112. setClear: function ( stencil ) {
  12113. if ( currentStencilClear !== stencil ) {
  12114. gl.clearStencil( stencil );
  12115. currentStencilClear = stencil;
  12116. }
  12117. },
  12118. reset: function () {
  12119. locked = false;
  12120. currentStencilMask = null;
  12121. currentStencilFunc = null;
  12122. currentStencilRef = null;
  12123. currentStencilFuncMask = null;
  12124. currentStencilFail = null;
  12125. currentStencilZFail = null;
  12126. currentStencilZPass = null;
  12127. currentStencilClear = null;
  12128. }
  12129. };
  12130. }
  12131. //
  12132. var colorBuffer = new ColorBuffer();
  12133. var depthBuffer = new DepthBuffer();
  12134. var stencilBuffer = new StencilBuffer();
  12135. var maxVertexAttributes = gl.getParameter( 34921 );
  12136. var newAttributes = new Uint8Array( maxVertexAttributes );
  12137. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  12138. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  12139. var enabledCapabilities = {};
  12140. var compressedTextureFormats = null;
  12141. var currentProgram = null;
  12142. var currentBlendingEnabled = null;
  12143. var currentBlending = null;
  12144. var currentBlendEquation = null;
  12145. var currentBlendSrc = null;
  12146. var currentBlendDst = null;
  12147. var currentBlendEquationAlpha = null;
  12148. var currentBlendSrcAlpha = null;
  12149. var currentBlendDstAlpha = null;
  12150. var currentPremultipledAlpha = false;
  12151. var currentFlipSided = null;
  12152. var currentCullFace = null;
  12153. var currentLineWidth = null;
  12154. var currentPolygonOffsetFactor = null;
  12155. var currentPolygonOffsetUnits = null;
  12156. var maxTextures = gl.getParameter( 35661 );
  12157. var lineWidthAvailable = false;
  12158. var version = 0;
  12159. var glVersion = gl.getParameter( 7938 );
  12160. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12161. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12162. lineWidthAvailable = ( version >= 1.0 );
  12163. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12164. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12165. lineWidthAvailable = ( version >= 2.0 );
  12166. }
  12167. var currentTextureSlot = null;
  12168. var currentBoundTextures = {};
  12169. var currentScissor = new Vector4();
  12170. var currentViewport = new Vector4();
  12171. function createTexture( type, target, count ) {
  12172. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12173. var texture = gl.createTexture();
  12174. gl.bindTexture( type, texture );
  12175. gl.texParameteri( type, 10241, 9728 );
  12176. gl.texParameteri( type, 10240, 9728 );
  12177. for ( var i = 0; i < count; i ++ ) {
  12178. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12179. }
  12180. return texture;
  12181. }
  12182. var emptyTextures = {};
  12183. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12184. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12185. // init
  12186. colorBuffer.setClear( 0, 0, 0, 1 );
  12187. depthBuffer.setClear( 1 );
  12188. stencilBuffer.setClear( 0 );
  12189. enable( 2929 );
  12190. depthBuffer.setFunc( LessEqualDepth );
  12191. setFlipSided( false );
  12192. setCullFace( CullFaceBack );
  12193. enable( 2884 );
  12194. setBlending( NoBlending );
  12195. //
  12196. function initAttributes() {
  12197. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  12198. newAttributes[ i ] = 0;
  12199. }
  12200. }
  12201. function enableAttribute( attribute ) {
  12202. enableAttributeAndDivisor( attribute, 0 );
  12203. }
  12204. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  12205. newAttributes[ attribute ] = 1;
  12206. if ( enabledAttributes[ attribute ] === 0 ) {
  12207. gl.enableVertexAttribArray( attribute );
  12208. enabledAttributes[ attribute ] = 1;
  12209. }
  12210. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  12211. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  12212. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  12213. attributeDivisors[ attribute ] = meshPerAttribute;
  12214. }
  12215. }
  12216. function disableUnusedAttributes() {
  12217. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  12218. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  12219. gl.disableVertexAttribArray( i );
  12220. enabledAttributes[ i ] = 0;
  12221. }
  12222. }
  12223. }
  12224. function enable( id ) {
  12225. if ( enabledCapabilities[ id ] !== true ) {
  12226. gl.enable( id );
  12227. enabledCapabilities[ id ] = true;
  12228. }
  12229. }
  12230. function disable( id ) {
  12231. if ( enabledCapabilities[ id ] !== false ) {
  12232. gl.disable( id );
  12233. enabledCapabilities[ id ] = false;
  12234. }
  12235. }
  12236. function getCompressedTextureFormats() {
  12237. if ( compressedTextureFormats === null ) {
  12238. compressedTextureFormats = [];
  12239. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  12240. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  12241. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  12242. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  12243. var formats = gl.getParameter( 34467 );
  12244. for ( var i = 0; i < formats.length; i ++ ) {
  12245. compressedTextureFormats.push( formats[ i ] );
  12246. }
  12247. }
  12248. }
  12249. return compressedTextureFormats;
  12250. }
  12251. function useProgram( program ) {
  12252. if ( currentProgram !== program ) {
  12253. gl.useProgram( program );
  12254. currentProgram = program;
  12255. return true;
  12256. }
  12257. return false;
  12258. }
  12259. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12260. if ( blending === NoBlending ) {
  12261. if ( currentBlendingEnabled ) {
  12262. disable( 3042 );
  12263. currentBlendingEnabled = false;
  12264. }
  12265. return;
  12266. }
  12267. if ( ! currentBlendingEnabled ) {
  12268. enable( 3042 );
  12269. currentBlendingEnabled = true;
  12270. }
  12271. if ( blending !== CustomBlending ) {
  12272. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12273. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12274. gl.blendEquation( 32774 );
  12275. currentBlendEquation = AddEquation;
  12276. currentBlendEquationAlpha = AddEquation;
  12277. }
  12278. if ( premultipliedAlpha ) {
  12279. switch ( blending ) {
  12280. case NormalBlending:
  12281. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12282. break;
  12283. case AdditiveBlending:
  12284. gl.blendFunc( 1, 1 );
  12285. break;
  12286. case SubtractiveBlending:
  12287. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12288. break;
  12289. case MultiplyBlending:
  12290. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12291. break;
  12292. default:
  12293. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12294. break;
  12295. }
  12296. } else {
  12297. switch ( blending ) {
  12298. case NormalBlending:
  12299. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12300. break;
  12301. case AdditiveBlending:
  12302. gl.blendFunc( 770, 1 );
  12303. break;
  12304. case SubtractiveBlending:
  12305. gl.blendFunc( 0, 769 );
  12306. break;
  12307. case MultiplyBlending:
  12308. gl.blendFunc( 0, 768 );
  12309. break;
  12310. default:
  12311. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12312. break;
  12313. }
  12314. }
  12315. currentBlendSrc = null;
  12316. currentBlendDst = null;
  12317. currentBlendSrcAlpha = null;
  12318. currentBlendDstAlpha = null;
  12319. currentBlending = blending;
  12320. currentPremultipledAlpha = premultipliedAlpha;
  12321. }
  12322. return;
  12323. }
  12324. // custom blending
  12325. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12326. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12327. blendDstAlpha = blendDstAlpha || blendDst;
  12328. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12329. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  12330. currentBlendEquation = blendEquation;
  12331. currentBlendEquationAlpha = blendEquationAlpha;
  12332. }
  12333. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12334. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  12335. currentBlendSrc = blendSrc;
  12336. currentBlendDst = blendDst;
  12337. currentBlendSrcAlpha = blendSrcAlpha;
  12338. currentBlendDstAlpha = blendDstAlpha;
  12339. }
  12340. currentBlending = blending;
  12341. currentPremultipledAlpha = null;
  12342. }
  12343. function setMaterial( material, frontFaceCW ) {
  12344. material.side === DoubleSide
  12345. ? disable( 2884 )
  12346. : enable( 2884 );
  12347. var flipSided = ( material.side === BackSide );
  12348. if ( frontFaceCW ) flipSided = ! flipSided;
  12349. setFlipSided( flipSided );
  12350. ( material.blending === NormalBlending && material.transparent === false )
  12351. ? setBlending( NoBlending )
  12352. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12353. depthBuffer.setFunc( material.depthFunc );
  12354. depthBuffer.setTest( material.depthTest );
  12355. depthBuffer.setMask( material.depthWrite );
  12356. colorBuffer.setMask( material.colorWrite );
  12357. var stencilWrite = material.stencilWrite;
  12358. stencilBuffer.setTest( stencilWrite );
  12359. if ( stencilWrite ) {
  12360. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilMask );
  12361. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12362. }
  12363. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12364. }
  12365. //
  12366. function setFlipSided( flipSided ) {
  12367. if ( currentFlipSided !== flipSided ) {
  12368. if ( flipSided ) {
  12369. gl.frontFace( 2304 );
  12370. } else {
  12371. gl.frontFace( 2305 );
  12372. }
  12373. currentFlipSided = flipSided;
  12374. }
  12375. }
  12376. function setCullFace( cullFace ) {
  12377. if ( cullFace !== CullFaceNone ) {
  12378. enable( 2884 );
  12379. if ( cullFace !== currentCullFace ) {
  12380. if ( cullFace === CullFaceBack ) {
  12381. gl.cullFace( 1029 );
  12382. } else if ( cullFace === CullFaceFront ) {
  12383. gl.cullFace( 1028 );
  12384. } else {
  12385. gl.cullFace( 1032 );
  12386. }
  12387. }
  12388. } else {
  12389. disable( 2884 );
  12390. }
  12391. currentCullFace = cullFace;
  12392. }
  12393. function setLineWidth( width ) {
  12394. if ( width !== currentLineWidth ) {
  12395. if ( lineWidthAvailable ) gl.lineWidth( width );
  12396. currentLineWidth = width;
  12397. }
  12398. }
  12399. function setPolygonOffset( polygonOffset, factor, units ) {
  12400. if ( polygonOffset ) {
  12401. enable( 32823 );
  12402. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12403. gl.polygonOffset( factor, units );
  12404. currentPolygonOffsetFactor = factor;
  12405. currentPolygonOffsetUnits = units;
  12406. }
  12407. } else {
  12408. disable( 32823 );
  12409. }
  12410. }
  12411. function setScissorTest( scissorTest ) {
  12412. if ( scissorTest ) {
  12413. enable( 3089 );
  12414. } else {
  12415. disable( 3089 );
  12416. }
  12417. }
  12418. // texture
  12419. function activeTexture( webglSlot ) {
  12420. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12421. if ( currentTextureSlot !== webglSlot ) {
  12422. gl.activeTexture( webglSlot );
  12423. currentTextureSlot = webglSlot;
  12424. }
  12425. }
  12426. function bindTexture( webglType, webglTexture ) {
  12427. if ( currentTextureSlot === null ) {
  12428. activeTexture();
  12429. }
  12430. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12431. if ( boundTexture === undefined ) {
  12432. boundTexture = { type: undefined, texture: undefined };
  12433. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12434. }
  12435. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12436. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12437. boundTexture.type = webglType;
  12438. boundTexture.texture = webglTexture;
  12439. }
  12440. }
  12441. function compressedTexImage2D() {
  12442. try {
  12443. gl.compressedTexImage2D.apply( gl, arguments );
  12444. } catch ( error ) {
  12445. console.error( 'THREE.WebGLState:', error );
  12446. }
  12447. }
  12448. function texImage2D() {
  12449. try {
  12450. gl.texImage2D.apply( gl, arguments );
  12451. } catch ( error ) {
  12452. console.error( 'THREE.WebGLState:', error );
  12453. }
  12454. }
  12455. function texImage3D() {
  12456. try {
  12457. gl.texImage3D.apply( gl, arguments );
  12458. } catch ( error ) {
  12459. console.error( 'THREE.WebGLState:', error );
  12460. }
  12461. }
  12462. //
  12463. function scissor( scissor ) {
  12464. if ( currentScissor.equals( scissor ) === false ) {
  12465. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12466. currentScissor.copy( scissor );
  12467. }
  12468. }
  12469. function viewport( viewport ) {
  12470. if ( currentViewport.equals( viewport ) === false ) {
  12471. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12472. currentViewport.copy( viewport );
  12473. }
  12474. }
  12475. //
  12476. function reset() {
  12477. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12478. if ( enabledAttributes[ i ] === 1 ) {
  12479. gl.disableVertexAttribArray( i );
  12480. enabledAttributes[ i ] = 0;
  12481. }
  12482. }
  12483. enabledCapabilities = {};
  12484. compressedTextureFormats = null;
  12485. currentTextureSlot = null;
  12486. currentBoundTextures = {};
  12487. currentProgram = null;
  12488. currentBlending = null;
  12489. currentFlipSided = null;
  12490. currentCullFace = null;
  12491. colorBuffer.reset();
  12492. depthBuffer.reset();
  12493. stencilBuffer.reset();
  12494. }
  12495. return {
  12496. buffers: {
  12497. color: colorBuffer,
  12498. depth: depthBuffer,
  12499. stencil: stencilBuffer
  12500. },
  12501. initAttributes: initAttributes,
  12502. enableAttribute: enableAttribute,
  12503. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12504. disableUnusedAttributes: disableUnusedAttributes,
  12505. enable: enable,
  12506. disable: disable,
  12507. getCompressedTextureFormats: getCompressedTextureFormats,
  12508. useProgram: useProgram,
  12509. setBlending: setBlending,
  12510. setMaterial: setMaterial,
  12511. setFlipSided: setFlipSided,
  12512. setCullFace: setCullFace,
  12513. setLineWidth: setLineWidth,
  12514. setPolygonOffset: setPolygonOffset,
  12515. setScissorTest: setScissorTest,
  12516. activeTexture: activeTexture,
  12517. bindTexture: bindTexture,
  12518. compressedTexImage2D: compressedTexImage2D,
  12519. texImage2D: texImage2D,
  12520. texImage3D: texImage3D,
  12521. scissor: scissor,
  12522. viewport: viewport,
  12523. reset: reset
  12524. };
  12525. }
  12526. /**
  12527. * @author mrdoob / http://mrdoob.com/
  12528. */
  12529. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12530. var _videoTextures = {};
  12531. var _canvas;
  12532. //
  12533. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12534. function createCanvas( width, height ) {
  12535. // Use OffscreenCanvas when available. Specially needed in web workers
  12536. return useOffscreenCanvas ?
  12537. new OffscreenCanvas( width, height ) :
  12538. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12539. }
  12540. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12541. var scale = 1;
  12542. // handle case if texture exceeds max size
  12543. if ( image.width > maxSize || image.height > maxSize ) {
  12544. scale = maxSize / Math.max( image.width, image.height );
  12545. }
  12546. // only perform resize if necessary
  12547. if ( scale < 1 || needsPowerOfTwo === true ) {
  12548. // only perform resize for certain image types
  12549. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12550. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12551. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12552. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12553. var width = floor( scale * image.width );
  12554. var height = floor( scale * image.height );
  12555. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12556. // cube textures can't reuse the same canvas
  12557. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12558. canvas.width = width;
  12559. canvas.height = height;
  12560. var context = canvas.getContext( '2d' );
  12561. context.drawImage( image, 0, 0, width, height );
  12562. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12563. return canvas;
  12564. } else {
  12565. if ( 'data' in image ) {
  12566. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12567. }
  12568. return image;
  12569. }
  12570. }
  12571. return image;
  12572. }
  12573. function isPowerOfTwo( image ) {
  12574. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12575. }
  12576. function textureNeedsPowerOfTwo( texture ) {
  12577. if ( capabilities.isWebGL2 ) return false;
  12578. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12579. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12580. }
  12581. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12582. return texture.generateMipmaps && supportsMips &&
  12583. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12584. }
  12585. function generateMipmap( target, texture, width, height ) {
  12586. _gl.generateMipmap( target );
  12587. var textureProperties = properties.get( texture );
  12588. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12589. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12590. }
  12591. function getInternalFormat( glFormat, glType ) {
  12592. if ( ! capabilities.isWebGL2 ) return glFormat;
  12593. var internalFormat = glFormat;
  12594. if ( glFormat === 6403 ) {
  12595. if ( glType === 5126 ) internalFormat = 33326;
  12596. if ( glType === 5131 ) internalFormat = 33325;
  12597. if ( glType === 5121 ) internalFormat = 33321;
  12598. }
  12599. if ( glFormat === 6407 ) {
  12600. if ( glType === 5126 ) internalFormat = 34837;
  12601. if ( glType === 5131 ) internalFormat = 34843;
  12602. if ( glType === 5121 ) internalFormat = 32849;
  12603. }
  12604. if ( glFormat === 6408 ) {
  12605. if ( glType === 5126 ) internalFormat = 34836;
  12606. if ( glType === 5131 ) internalFormat = 34842;
  12607. if ( glType === 5121 ) internalFormat = 32856;
  12608. }
  12609. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12610. internalFormat === 34842 || internalFormat === 34836 ) {
  12611. extensions.get( 'EXT_color_buffer_float' );
  12612. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12613. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12614. }
  12615. return internalFormat;
  12616. }
  12617. // Fallback filters for non-power-of-2 textures
  12618. function filterFallback( f ) {
  12619. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12620. return 9728;
  12621. }
  12622. return 9729;
  12623. }
  12624. //
  12625. function onTextureDispose( event ) {
  12626. var texture = event.target;
  12627. texture.removeEventListener( 'dispose', onTextureDispose );
  12628. deallocateTexture( texture );
  12629. if ( texture.isVideoTexture ) {
  12630. delete _videoTextures[ texture.id ];
  12631. }
  12632. info.memory.textures --;
  12633. }
  12634. function onRenderTargetDispose( event ) {
  12635. var renderTarget = event.target;
  12636. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12637. deallocateRenderTarget( renderTarget );
  12638. info.memory.textures --;
  12639. }
  12640. //
  12641. function deallocateTexture( texture ) {
  12642. var textureProperties = properties.get( texture );
  12643. if ( textureProperties.__webglInit === undefined ) return;
  12644. _gl.deleteTexture( textureProperties.__webglTexture );
  12645. properties.remove( texture );
  12646. }
  12647. function deallocateRenderTarget( renderTarget ) {
  12648. var renderTargetProperties = properties.get( renderTarget );
  12649. var textureProperties = properties.get( renderTarget.texture );
  12650. if ( ! renderTarget ) return;
  12651. if ( textureProperties.__webglTexture !== undefined ) {
  12652. _gl.deleteTexture( textureProperties.__webglTexture );
  12653. }
  12654. if ( renderTarget.depthTexture ) {
  12655. renderTarget.depthTexture.dispose();
  12656. }
  12657. if ( renderTarget.isWebGLRenderTargetCube ) {
  12658. for ( var i = 0; i < 6; i ++ ) {
  12659. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12660. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12661. }
  12662. } else {
  12663. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12664. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12665. }
  12666. properties.remove( renderTarget.texture );
  12667. properties.remove( renderTarget );
  12668. }
  12669. //
  12670. var textureUnits = 0;
  12671. function resetTextureUnits() {
  12672. textureUnits = 0;
  12673. }
  12674. function allocateTextureUnit() {
  12675. var textureUnit = textureUnits;
  12676. if ( textureUnit >= capabilities.maxTextures ) {
  12677. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12678. }
  12679. textureUnits += 1;
  12680. return textureUnit;
  12681. }
  12682. //
  12683. function setTexture2D( texture, slot ) {
  12684. var textureProperties = properties.get( texture );
  12685. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12686. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12687. var image = texture.image;
  12688. if ( image === undefined ) {
  12689. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12690. } else if ( image.complete === false ) {
  12691. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12692. } else {
  12693. uploadTexture( textureProperties, texture, slot );
  12694. return;
  12695. }
  12696. }
  12697. state.activeTexture( 33984 + slot );
  12698. state.bindTexture( 3553, textureProperties.__webglTexture );
  12699. }
  12700. function setTexture2DArray( texture, slot ) {
  12701. var textureProperties = properties.get( texture );
  12702. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12703. uploadTexture( textureProperties, texture, slot );
  12704. return;
  12705. }
  12706. state.activeTexture( 33984 + slot );
  12707. state.bindTexture( 35866, textureProperties.__webglTexture );
  12708. }
  12709. function setTexture3D( texture, slot ) {
  12710. var textureProperties = properties.get( texture );
  12711. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12712. uploadTexture( textureProperties, texture, slot );
  12713. return;
  12714. }
  12715. state.activeTexture( 33984 + slot );
  12716. state.bindTexture( 32879, textureProperties.__webglTexture );
  12717. }
  12718. function setTextureCube( texture, slot ) {
  12719. var textureProperties = properties.get( texture );
  12720. if ( texture.image.length === 6 ) {
  12721. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12722. initTexture( textureProperties, texture );
  12723. state.activeTexture( 33984 + slot );
  12724. state.bindTexture( 34067, textureProperties.__webglTexture );
  12725. _gl.pixelStorei( 37440, texture.flipY );
  12726. var isCompressed = ( texture && texture.isCompressedTexture );
  12727. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12728. var cubeImage = [];
  12729. for ( var i = 0; i < 6; i ++ ) {
  12730. if ( ! isCompressed && ! isDataTexture ) {
  12731. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12732. } else {
  12733. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12734. }
  12735. }
  12736. var image = cubeImage[ 0 ],
  12737. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12738. glFormat = utils.convert( texture.format ),
  12739. glType = utils.convert( texture.type ),
  12740. glInternalFormat = getInternalFormat( glFormat, glType );
  12741. setTextureParameters( 34067, texture, supportsMips );
  12742. for ( var i = 0; i < 6; i ++ ) {
  12743. if ( ! isCompressed ) {
  12744. if ( isDataTexture ) {
  12745. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12746. } else {
  12747. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12748. }
  12749. } else {
  12750. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12751. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12752. mipmap = mipmaps[ j ];
  12753. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12754. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12755. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12756. } else {
  12757. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12758. }
  12759. } else {
  12760. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12761. }
  12762. }
  12763. }
  12764. }
  12765. if ( ! isCompressed ) {
  12766. textureProperties.__maxMipLevel = 0;
  12767. } else {
  12768. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12769. }
  12770. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12771. // We assume images for cube map have the same size.
  12772. generateMipmap( 34067, texture, image.width, image.height );
  12773. }
  12774. textureProperties.__version = texture.version;
  12775. if ( texture.onUpdate ) texture.onUpdate( texture );
  12776. } else {
  12777. state.activeTexture( 33984 + slot );
  12778. state.bindTexture( 34067, textureProperties.__webglTexture );
  12779. }
  12780. }
  12781. }
  12782. function setTextureCubeDynamic( texture, slot ) {
  12783. state.activeTexture( 33984 + slot );
  12784. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12785. }
  12786. function setTextureParameters( textureType, texture, supportsMips ) {
  12787. var extension;
  12788. if ( supportsMips ) {
  12789. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12790. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12791. if ( textureType === 32879 || textureType === 35866 ) {
  12792. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12793. }
  12794. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12795. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12796. } else {
  12797. _gl.texParameteri( textureType, 10242, 33071 );
  12798. _gl.texParameteri( textureType, 10243, 33071 );
  12799. if ( textureType === 32879 || textureType === 35866 ) {
  12800. _gl.texParameteri( textureType, 32882, 33071 );
  12801. }
  12802. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12803. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12804. }
  12805. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12806. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12807. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12808. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12809. }
  12810. }
  12811. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12812. if ( extension ) {
  12813. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12814. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12815. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12816. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12817. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12818. }
  12819. }
  12820. }
  12821. function initTexture( textureProperties, texture ) {
  12822. if ( textureProperties.__webglInit === undefined ) {
  12823. textureProperties.__webglInit = true;
  12824. texture.addEventListener( 'dispose', onTextureDispose );
  12825. textureProperties.__webglTexture = _gl.createTexture();
  12826. info.memory.textures ++;
  12827. }
  12828. }
  12829. function uploadTexture( textureProperties, texture, slot ) {
  12830. var textureType = 3553;
  12831. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12832. if ( texture.isDataTexture3D ) textureType = 32879;
  12833. initTexture( textureProperties, texture );
  12834. state.activeTexture( 33984 + slot );
  12835. state.bindTexture( textureType, textureProperties.__webglTexture );
  12836. _gl.pixelStorei( 37440, texture.flipY );
  12837. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12838. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12839. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12840. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12841. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12842. glFormat = utils.convert( texture.format ),
  12843. glType = utils.convert( texture.type ),
  12844. glInternalFormat = getInternalFormat( glFormat, glType );
  12845. setTextureParameters( textureType, texture, supportsMips );
  12846. var mipmap, mipmaps = texture.mipmaps;
  12847. if ( texture.isDepthTexture ) {
  12848. // populate depth texture with dummy data
  12849. glInternalFormat = 6402;
  12850. if ( texture.type === FloatType ) {
  12851. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12852. glInternalFormat = 36012;
  12853. } else if ( capabilities.isWebGL2 ) {
  12854. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12855. glInternalFormat = 33189;
  12856. }
  12857. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12858. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12859. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12860. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12861. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12862. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12863. texture.type = UnsignedShortType;
  12864. glType = utils.convert( texture.type );
  12865. }
  12866. }
  12867. // Depth stencil textures need the DEPTH_STENCIL internal format
  12868. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12869. if ( texture.format === DepthStencilFormat ) {
  12870. glInternalFormat = 34041;
  12871. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12872. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12873. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12874. if ( texture.type !== UnsignedInt248Type ) {
  12875. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12876. texture.type = UnsignedInt248Type;
  12877. glType = utils.convert( texture.type );
  12878. }
  12879. }
  12880. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12881. } else if ( texture.isDataTexture ) {
  12882. // use manually created mipmaps if available
  12883. // if there are no manual mipmaps
  12884. // set 0 level mipmap and then use GL to generate other mipmap levels
  12885. if ( mipmaps.length > 0 && supportsMips ) {
  12886. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12887. mipmap = mipmaps[ i ];
  12888. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12889. }
  12890. texture.generateMipmaps = false;
  12891. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12892. } else {
  12893. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12894. textureProperties.__maxMipLevel = 0;
  12895. }
  12896. } else if ( texture.isCompressedTexture ) {
  12897. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12898. mipmap = mipmaps[ i ];
  12899. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12900. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12901. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12902. } else {
  12903. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12904. }
  12905. } else {
  12906. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12907. }
  12908. }
  12909. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12910. } else if ( texture.isDataTexture2DArray ) {
  12911. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12912. textureProperties.__maxMipLevel = 0;
  12913. } else if ( texture.isDataTexture3D ) {
  12914. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12915. textureProperties.__maxMipLevel = 0;
  12916. } else {
  12917. // regular Texture (image, video, canvas)
  12918. // use manually created mipmaps if available
  12919. // if there are no manual mipmaps
  12920. // set 0 level mipmap and then use GL to generate other mipmap levels
  12921. if ( mipmaps.length > 0 && supportsMips ) {
  12922. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12923. mipmap = mipmaps[ i ];
  12924. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12925. }
  12926. texture.generateMipmaps = false;
  12927. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12928. } else {
  12929. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12930. textureProperties.__maxMipLevel = 0;
  12931. }
  12932. }
  12933. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12934. generateMipmap( 3553, texture, image.width, image.height );
  12935. }
  12936. textureProperties.__version = texture.version;
  12937. if ( texture.onUpdate ) texture.onUpdate( texture );
  12938. }
  12939. // Render targets
  12940. // Setup storage for target texture and bind it to correct framebuffer
  12941. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12942. var glFormat = utils.convert( renderTarget.texture.format );
  12943. var glType = utils.convert( renderTarget.texture.type );
  12944. var glInternalFormat = getInternalFormat( glFormat, glType );
  12945. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12946. _gl.bindFramebuffer( 36160, framebuffer );
  12947. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12948. _gl.bindFramebuffer( 36160, null );
  12949. }
  12950. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12951. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12952. _gl.bindRenderbuffer( 36161, renderbuffer );
  12953. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12954. if ( isMultisample ) {
  12955. var samples = getRenderTargetSamples( renderTarget );
  12956. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12957. } else {
  12958. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12959. }
  12960. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12961. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12962. if ( isMultisample ) {
  12963. var samples = getRenderTargetSamples( renderTarget );
  12964. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  12965. } else {
  12966. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12967. }
  12968. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12969. } else {
  12970. var glFormat = utils.convert( renderTarget.texture.format );
  12971. var glType = utils.convert( renderTarget.texture.type );
  12972. var glInternalFormat = getInternalFormat( glFormat, glType );
  12973. if ( isMultisample ) {
  12974. var samples = getRenderTargetSamples( renderTarget );
  12975. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12976. } else {
  12977. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12978. }
  12979. }
  12980. _gl.bindRenderbuffer( 36161, null );
  12981. }
  12982. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12983. function setupDepthTexture( framebuffer, renderTarget ) {
  12984. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12985. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12986. _gl.bindFramebuffer( 36160, framebuffer );
  12987. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12988. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12989. }
  12990. // upload an empty depth texture with framebuffer size
  12991. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12992. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12993. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12994. renderTarget.depthTexture.image.width = renderTarget.width;
  12995. renderTarget.depthTexture.image.height = renderTarget.height;
  12996. renderTarget.depthTexture.needsUpdate = true;
  12997. }
  12998. setTexture2D( renderTarget.depthTexture, 0 );
  12999. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13000. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13001. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13002. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13003. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13004. } else {
  13005. throw new Error( 'Unknown depthTexture format' );
  13006. }
  13007. }
  13008. // Setup GL resources for a non-texture depth buffer
  13009. function setupDepthRenderbuffer( renderTarget ) {
  13010. var renderTargetProperties = properties.get( renderTarget );
  13011. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13012. if ( renderTarget.depthTexture ) {
  13013. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13014. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13015. } else {
  13016. if ( isCube ) {
  13017. renderTargetProperties.__webglDepthbuffer = [];
  13018. for ( var i = 0; i < 6; i ++ ) {
  13019. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13020. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13021. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  13022. }
  13023. } else {
  13024. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13025. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13026. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  13027. }
  13028. }
  13029. _gl.bindFramebuffer( 36160, null );
  13030. }
  13031. // Set up GL resources for the render target
  13032. function setupRenderTarget( renderTarget ) {
  13033. var renderTargetProperties = properties.get( renderTarget );
  13034. var textureProperties = properties.get( renderTarget.texture );
  13035. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13036. textureProperties.__webglTexture = _gl.createTexture();
  13037. info.memory.textures ++;
  13038. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13039. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13040. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13041. // Setup framebuffer
  13042. if ( isCube ) {
  13043. renderTargetProperties.__webglFramebuffer = [];
  13044. for ( var i = 0; i < 6; i ++ ) {
  13045. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13046. }
  13047. } else {
  13048. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13049. if ( isMultisample ) {
  13050. if ( capabilities.isWebGL2 ) {
  13051. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13052. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13053. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13054. var glFormat = utils.convert( renderTarget.texture.format );
  13055. var glType = utils.convert( renderTarget.texture.type );
  13056. var glInternalFormat = getInternalFormat( glFormat, glType );
  13057. var samples = getRenderTargetSamples( renderTarget );
  13058. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13059. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13060. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13061. _gl.bindRenderbuffer( 36161, null );
  13062. if ( renderTarget.depthBuffer ) {
  13063. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13064. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13065. }
  13066. _gl.bindFramebuffer( 36160, null );
  13067. } else {
  13068. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13069. }
  13070. }
  13071. }
  13072. // Setup color buffer
  13073. if ( isCube ) {
  13074. state.bindTexture( 34067, textureProperties.__webglTexture );
  13075. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13076. for ( var i = 0; i < 6; i ++ ) {
  13077. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13078. }
  13079. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13080. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13081. }
  13082. state.bindTexture( 34067, null );
  13083. } else {
  13084. state.bindTexture( 3553, textureProperties.__webglTexture );
  13085. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13086. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13087. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13088. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13089. }
  13090. state.bindTexture( 3553, null );
  13091. }
  13092. // Setup depth and stencil buffers
  13093. if ( renderTarget.depthBuffer ) {
  13094. setupDepthRenderbuffer( renderTarget );
  13095. }
  13096. }
  13097. function updateRenderTargetMipmap( renderTarget ) {
  13098. var texture = renderTarget.texture;
  13099. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13100. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13101. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  13102. var webglTexture = properties.get( texture ).__webglTexture;
  13103. state.bindTexture( target, webglTexture );
  13104. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13105. state.bindTexture( target, null );
  13106. }
  13107. }
  13108. function updateMultisampleRenderTarget( renderTarget ) {
  13109. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13110. if ( capabilities.isWebGL2 ) {
  13111. var renderTargetProperties = properties.get( renderTarget );
  13112. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13113. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13114. var width = renderTarget.width;
  13115. var height = renderTarget.height;
  13116. var mask = 16384;
  13117. if ( renderTarget.depthBuffer ) mask |= 256;
  13118. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13119. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13120. } else {
  13121. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13122. }
  13123. }
  13124. }
  13125. function getRenderTargetSamples( renderTarget ) {
  13126. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13127. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  13128. }
  13129. function updateVideoTexture( texture ) {
  13130. var id = texture.id;
  13131. var frame = info.render.frame;
  13132. // Check the last frame we updated the VideoTexture
  13133. if ( _videoTextures[ id ] !== frame ) {
  13134. _videoTextures[ id ] = frame;
  13135. texture.update();
  13136. }
  13137. }
  13138. // backwards compatibility
  13139. var warnedTexture2D = false;
  13140. var warnedTextureCube = false;
  13141. function safeSetTexture2D( texture, slot ) {
  13142. if ( texture && texture.isWebGLRenderTarget ) {
  13143. if ( warnedTexture2D === false ) {
  13144. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13145. warnedTexture2D = true;
  13146. }
  13147. texture = texture.texture;
  13148. }
  13149. setTexture2D( texture, slot );
  13150. }
  13151. function safeSetTextureCube( texture, slot ) {
  13152. if ( texture && texture.isWebGLRenderTargetCube ) {
  13153. if ( warnedTextureCube === false ) {
  13154. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13155. warnedTextureCube = true;
  13156. }
  13157. texture = texture.texture;
  13158. }
  13159. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13160. // TODO: unify these code paths
  13161. if ( ( texture && texture.isCubeTexture ) ||
  13162. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13163. // CompressedTexture can have Array in image :/
  13164. // this function alone should take care of cube textures
  13165. setTextureCube( texture, slot );
  13166. } else {
  13167. // assumed: texture property of THREE.WebGLRenderTargetCube
  13168. setTextureCubeDynamic( texture, slot );
  13169. }
  13170. }
  13171. //
  13172. this.allocateTextureUnit = allocateTextureUnit;
  13173. this.resetTextureUnits = resetTextureUnits;
  13174. this.setTexture2D = setTexture2D;
  13175. this.setTexture2DArray = setTexture2DArray;
  13176. this.setTexture3D = setTexture3D;
  13177. this.setTextureCube = setTextureCube;
  13178. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13179. this.setupRenderTarget = setupRenderTarget;
  13180. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13181. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13182. this.safeSetTexture2D = safeSetTexture2D;
  13183. this.safeSetTextureCube = safeSetTextureCube;
  13184. }
  13185. /**
  13186. * @author thespite / http://www.twitter.com/thespite
  13187. */
  13188. function WebGLUtils( gl, extensions, capabilities ) {
  13189. function convert( p ) {
  13190. var extension;
  13191. if ( p === RepeatWrapping ) return 10497;
  13192. if ( p === ClampToEdgeWrapping ) return 33071;
  13193. if ( p === MirroredRepeatWrapping ) return 33648;
  13194. if ( p === NearestFilter ) return 9728;
  13195. if ( p === NearestMipmapNearestFilter ) return 9984;
  13196. if ( p === NearestMipmapLinearFilter ) return 9986;
  13197. if ( p === LinearFilter ) return 9729;
  13198. if ( p === LinearMipmapNearestFilter ) return 9985;
  13199. if ( p === LinearMipmapLinearFilter ) return 9987;
  13200. if ( p === UnsignedByteType ) return 5121;
  13201. if ( p === UnsignedShort4444Type ) return 32819;
  13202. if ( p === UnsignedShort5551Type ) return 32820;
  13203. if ( p === UnsignedShort565Type ) return 33635;
  13204. if ( p === ByteType ) return 5120;
  13205. if ( p === ShortType ) return 5122;
  13206. if ( p === UnsignedShortType ) return 5123;
  13207. if ( p === IntType ) return 5124;
  13208. if ( p === UnsignedIntType ) return 5125;
  13209. if ( p === FloatType ) return 5126;
  13210. if ( p === HalfFloatType ) {
  13211. if ( capabilities.isWebGL2 ) return 5131;
  13212. extension = extensions.get( 'OES_texture_half_float' );
  13213. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  13214. }
  13215. if ( p === AlphaFormat ) return 6406;
  13216. if ( p === RGBFormat ) return 6407;
  13217. if ( p === RGBAFormat ) return 6408;
  13218. if ( p === LuminanceFormat ) return 6409;
  13219. if ( p === LuminanceAlphaFormat ) return 6410;
  13220. if ( p === DepthFormat ) return 6402;
  13221. if ( p === DepthStencilFormat ) return 34041;
  13222. if ( p === RedFormat ) return 6403;
  13223. if ( p === AddEquation ) return 32774;
  13224. if ( p === SubtractEquation ) return 32778;
  13225. if ( p === ReverseSubtractEquation ) return 32779;
  13226. if ( p === ZeroFactor ) return 0;
  13227. if ( p === OneFactor ) return 1;
  13228. if ( p === SrcColorFactor ) return 768;
  13229. if ( p === OneMinusSrcColorFactor ) return 769;
  13230. if ( p === SrcAlphaFactor ) return 770;
  13231. if ( p === OneMinusSrcAlphaFactor ) return 771;
  13232. if ( p === DstAlphaFactor ) return 772;
  13233. if ( p === OneMinusDstAlphaFactor ) return 773;
  13234. if ( p === DstColorFactor ) return 774;
  13235. if ( p === OneMinusDstColorFactor ) return 775;
  13236. if ( p === SrcAlphaSaturateFactor ) return 776;
  13237. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13238. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13239. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13240. if ( extension !== null ) {
  13241. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13242. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13243. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13244. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13245. }
  13246. }
  13247. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13248. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13249. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13250. if ( extension !== null ) {
  13251. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13252. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13253. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13254. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13255. }
  13256. }
  13257. if ( p === RGB_ETC1_Format ) {
  13258. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13259. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13260. }
  13261. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13262. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13263. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13264. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13265. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  13266. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13267. if ( extension !== null ) {
  13268. return p;
  13269. }
  13270. }
  13271. if ( p === MinEquation || p === MaxEquation ) {
  13272. if ( capabilities.isWebGL2 ) {
  13273. if ( p === MinEquation ) return 32775;
  13274. if ( p === MaxEquation ) return 32776;
  13275. }
  13276. extension = extensions.get( 'EXT_blend_minmax' );
  13277. if ( extension !== null ) {
  13278. if ( p === MinEquation ) return extension.MIN_EXT;
  13279. if ( p === MaxEquation ) return extension.MAX_EXT;
  13280. }
  13281. }
  13282. if ( p === UnsignedInt248Type ) {
  13283. if ( capabilities.isWebGL2 ) return 34042;
  13284. extension = extensions.get( 'WEBGL_depth_texture' );
  13285. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  13286. }
  13287. return 0;
  13288. }
  13289. return { convert: convert };
  13290. }
  13291. /**
  13292. * @author mrdoob / http://mrdoob.com/
  13293. */
  13294. function Group() {
  13295. Object3D.call( this );
  13296. this.type = 'Group';
  13297. }
  13298. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13299. constructor: Group,
  13300. isGroup: true
  13301. } );
  13302. /**
  13303. * @author mrdoob / http://mrdoob.com/
  13304. */
  13305. function ArrayCamera( array ) {
  13306. PerspectiveCamera.call( this );
  13307. this.cameras = array || [];
  13308. }
  13309. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13310. constructor: ArrayCamera,
  13311. isArrayCamera: true
  13312. } );
  13313. /**
  13314. * @author jsantell / https://www.jsantell.com/
  13315. * @author mrdoob / http://mrdoob.com/
  13316. */
  13317. var cameraLPos = new Vector3();
  13318. var cameraRPos = new Vector3();
  13319. /**
  13320. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13321. * the cameras' projection and world matrices have already been set.
  13322. * And that near and far planes are identical for both cameras.
  13323. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13324. */
  13325. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13326. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13327. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13328. var ipd = cameraLPos.distanceTo( cameraRPos );
  13329. var projL = cameraL.projectionMatrix.elements;
  13330. var projR = cameraR.projectionMatrix.elements;
  13331. // VR systems will have identical far and near planes, and
  13332. // most likely identical top and bottom frustum extents.
  13333. // Use the left camera for these values.
  13334. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13335. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13336. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13337. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13338. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13339. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13340. var left = near * leftFov;
  13341. var right = near * rightFov;
  13342. // Calculate the new camera's position offset from the
  13343. // left camera. xOffset should be roughly half `ipd`.
  13344. var zOffset = ipd / ( - leftFov + rightFov );
  13345. var xOffset = zOffset * - leftFov;
  13346. // TODO: Better way to apply this offset?
  13347. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13348. camera.translateX( xOffset );
  13349. camera.translateZ( zOffset );
  13350. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13351. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13352. // Find the union of the frustum values of the cameras and scale
  13353. // the values so that the near plane's position does not change in world space,
  13354. // although must now be relative to the new union camera.
  13355. var near2 = near + zOffset;
  13356. var far2 = far + zOffset;
  13357. var left2 = left - xOffset;
  13358. var right2 = right + ( ipd - xOffset );
  13359. var top2 = topFov * far / far2 * near2;
  13360. var bottom2 = bottomFov * far / far2 * near2;
  13361. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13362. }
  13363. /**
  13364. * @author mrdoob / http://mrdoob.com/
  13365. */
  13366. function WebVRManager( renderer ) {
  13367. var renderWidth, renderHeight;
  13368. var scope = this;
  13369. var device = null;
  13370. var frameData = null;
  13371. var poseTarget = null;
  13372. var controllers = [];
  13373. var standingMatrix = new Matrix4();
  13374. var standingMatrixInverse = new Matrix4();
  13375. var framebufferScaleFactor = 1.0;
  13376. var referenceSpaceType = 'local-floor';
  13377. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13378. frameData = new window.VRFrameData();
  13379. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13380. }
  13381. var matrixWorldInverse = new Matrix4();
  13382. var tempQuaternion = new Quaternion();
  13383. var tempPosition = new Vector3();
  13384. var cameraL = new PerspectiveCamera();
  13385. cameraL.viewport = new Vector4();
  13386. cameraL.layers.enable( 1 );
  13387. var cameraR = new PerspectiveCamera();
  13388. cameraR.viewport = new Vector4();
  13389. cameraR.layers.enable( 2 );
  13390. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13391. cameraVR.layers.enable( 1 );
  13392. cameraVR.layers.enable( 2 );
  13393. //
  13394. function isPresenting() {
  13395. return device !== null && device.isPresenting === true;
  13396. }
  13397. var currentSize = new Vector2(), currentPixelRatio;
  13398. function onVRDisplayPresentChange() {
  13399. if ( isPresenting() ) {
  13400. var eyeParameters = device.getEyeParameters( 'left' );
  13401. renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
  13402. renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13403. currentPixelRatio = renderer.getPixelRatio();
  13404. renderer.getSize( currentSize );
  13405. renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
  13406. cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
  13407. cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
  13408. animation.start();
  13409. scope.dispatchEvent( { type: 'sessionstart' } );
  13410. } else {
  13411. if ( scope.enabled ) {
  13412. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13413. }
  13414. animation.stop();
  13415. scope.dispatchEvent( { type: 'sessionend' } );
  13416. }
  13417. }
  13418. //
  13419. var triggers = [];
  13420. function findGamepad( id ) {
  13421. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13422. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13423. var gamepad = gamepads[ i ];
  13424. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13425. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13426. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13427. gamepad.id.startsWith( 'HTC Vive Focus' ) ||
  13428. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13429. if ( j === id ) return gamepad;
  13430. j ++;
  13431. }
  13432. }
  13433. }
  13434. function updateControllers() {
  13435. for ( var i = 0; i < controllers.length; i ++ ) {
  13436. var controller = controllers[ i ];
  13437. var gamepad = findGamepad( i );
  13438. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13439. if ( gamepad.pose === null ) return;
  13440. // Pose
  13441. var pose = gamepad.pose;
  13442. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13443. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13444. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13445. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13446. controller.matrix.premultiply( standingMatrix );
  13447. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13448. controller.matrixWorldNeedsUpdate = true;
  13449. controller.visible = true;
  13450. // Trigger
  13451. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13452. if ( triggers[ i ] === undefined ) triggers[ i ] = false;
  13453. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13454. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13455. if ( triggers[ i ] === true ) {
  13456. controller.dispatchEvent( { type: 'selectstart' } );
  13457. } else {
  13458. controller.dispatchEvent( { type: 'selectend' } );
  13459. controller.dispatchEvent( { type: 'select' } );
  13460. }
  13461. }
  13462. } else {
  13463. controller.visible = false;
  13464. }
  13465. }
  13466. }
  13467. function updateViewportFromBounds( viewport, bounds ) {
  13468. if ( bounds !== null && bounds.length === 4 ) {
  13469. viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
  13470. }
  13471. }
  13472. //
  13473. this.enabled = false;
  13474. this.getController = function ( id ) {
  13475. var controller = controllers[ id ];
  13476. if ( controller === undefined ) {
  13477. controller = new Group();
  13478. controller.matrixAutoUpdate = false;
  13479. controller.visible = false;
  13480. controllers[ id ] = controller;
  13481. }
  13482. return controller;
  13483. };
  13484. this.getDevice = function () {
  13485. return device;
  13486. };
  13487. this.setDevice = function ( value ) {
  13488. if ( value !== undefined ) device = value;
  13489. animation.setContext( value );
  13490. };
  13491. this.setFramebufferScaleFactor = function ( value ) {
  13492. framebufferScaleFactor = value;
  13493. };
  13494. this.setReferenceSpaceType = function ( value ) {
  13495. referenceSpaceType = value;
  13496. };
  13497. this.setPoseTarget = function ( object ) {
  13498. if ( object !== undefined ) poseTarget = object;
  13499. };
  13500. this.getCamera = function ( camera ) {
  13501. var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
  13502. if ( isPresenting() === false ) {
  13503. camera.position.set( 0, userHeight, 0 );
  13504. camera.rotation.set( 0, 0, 0 );
  13505. return camera;
  13506. }
  13507. device.depthNear = camera.near;
  13508. device.depthFar = camera.far;
  13509. device.getFrameData( frameData );
  13510. //
  13511. if ( referenceSpaceType === 'local-floor' ) {
  13512. var stageParameters = device.stageParameters;
  13513. if ( stageParameters ) {
  13514. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13515. } else {
  13516. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13517. }
  13518. }
  13519. var pose = frameData.pose;
  13520. var poseObject = poseTarget !== null ? poseTarget : camera;
  13521. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13522. poseObject.matrix.copy( standingMatrix );
  13523. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13524. if ( pose.orientation !== null ) {
  13525. tempQuaternion.fromArray( pose.orientation );
  13526. poseObject.quaternion.multiply( tempQuaternion );
  13527. }
  13528. if ( pose.position !== null ) {
  13529. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13530. tempPosition.fromArray( pose.position );
  13531. tempPosition.applyQuaternion( tempQuaternion );
  13532. poseObject.position.add( tempPosition );
  13533. }
  13534. poseObject.updateMatrixWorld();
  13535. //
  13536. cameraL.near = camera.near;
  13537. cameraR.near = camera.near;
  13538. cameraL.far = camera.far;
  13539. cameraR.far = camera.far;
  13540. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13541. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13542. // TODO (mrdoob) Double check this code
  13543. standingMatrixInverse.getInverse( standingMatrix );
  13544. if ( referenceSpaceType === 'local-floor' ) {
  13545. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13546. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13547. }
  13548. var parent = poseObject.parent;
  13549. if ( parent !== null ) {
  13550. matrixWorldInverse.getInverse( parent.matrixWorld );
  13551. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13552. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13553. }
  13554. // envMap and Mirror needs camera.matrixWorld
  13555. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13556. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13557. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13558. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13559. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13560. //
  13561. var layers = device.getLayers();
  13562. if ( layers.length ) {
  13563. var layer = layers[ 0 ];
  13564. updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
  13565. updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
  13566. }
  13567. updateControllers();
  13568. return cameraVR;
  13569. };
  13570. this.getStandingMatrix = function () {
  13571. return standingMatrix;
  13572. };
  13573. this.isPresenting = isPresenting;
  13574. // Animation Loop
  13575. var animation = new WebGLAnimation();
  13576. this.setAnimationLoop = function ( callback ) {
  13577. animation.setAnimationLoop( callback );
  13578. if ( isPresenting() ) animation.start();
  13579. };
  13580. this.submitFrame = function () {
  13581. if ( isPresenting() ) device.submitFrame();
  13582. };
  13583. this.dispose = function () {
  13584. if ( typeof window !== 'undefined' ) {
  13585. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13586. }
  13587. };
  13588. // DEPRECATED
  13589. this.setFrameOfReferenceType = function () {
  13590. console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
  13591. };
  13592. }
  13593. Object.assign( WebVRManager.prototype, EventDispatcher.prototype );
  13594. /**
  13595. * @author mrdoob / http://mrdoob.com/
  13596. */
  13597. function WebXRManager( renderer, gl ) {
  13598. var scope = this;
  13599. var session = null;
  13600. var referenceSpace = null;
  13601. var referenceSpaceType = 'local-floor';
  13602. var pose = null;
  13603. var controllers = [];
  13604. var inputSources = [];
  13605. function isPresenting() {
  13606. return session !== null && referenceSpace !== null;
  13607. }
  13608. //
  13609. var cameraL = new PerspectiveCamera();
  13610. cameraL.layers.enable( 1 );
  13611. cameraL.viewport = new Vector4();
  13612. var cameraR = new PerspectiveCamera();
  13613. cameraR.layers.enable( 2 );
  13614. cameraR.viewport = new Vector4();
  13615. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13616. cameraVR.layers.enable( 1 );
  13617. cameraVR.layers.enable( 2 );
  13618. //
  13619. this.enabled = false;
  13620. this.getController = function ( id ) {
  13621. var controller = controllers[ id ];
  13622. if ( controller === undefined ) {
  13623. controller = new Group();
  13624. controller.matrixAutoUpdate = false;
  13625. controller.visible = false;
  13626. controllers[ id ] = controller;
  13627. }
  13628. return controller;
  13629. };
  13630. //
  13631. function onSessionEvent( event ) {
  13632. for ( var i = 0; i < controllers.length; i ++ ) {
  13633. if ( inputSources[ i ] === event.inputSource ) {
  13634. controllers[ i ].dispatchEvent( { type: event.type } );
  13635. }
  13636. }
  13637. }
  13638. function onSessionEnd() {
  13639. renderer.setFramebuffer( null );
  13640. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13641. animation.stop();
  13642. scope.dispatchEvent( { type: 'sessionend' } );
  13643. }
  13644. function onRequestReferenceSpace( value ) {
  13645. referenceSpace = value;
  13646. animation.setContext( session );
  13647. animation.start();
  13648. scope.dispatchEvent( { type: 'sessionstart' } );
  13649. }
  13650. this.setFramebufferScaleFactor = function ( value ) {
  13651. };
  13652. this.setReferenceSpaceType = function ( value ) {
  13653. referenceSpaceType = value;
  13654. };
  13655. this.getSession = function () {
  13656. return session;
  13657. };
  13658. this.setSession = function ( value ) {
  13659. session = value;
  13660. if ( session !== null ) {
  13661. session.addEventListener( 'select', onSessionEvent );
  13662. session.addEventListener( 'selectstart', onSessionEvent );
  13663. session.addEventListener( 'selectend', onSessionEvent );
  13664. session.addEventListener( 'end', onSessionEnd );
  13665. session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
  13666. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13667. //
  13668. inputSources = session.inputSources;
  13669. session.addEventListener( 'inputsourceschange', function () {
  13670. inputSources = session.inputSources;
  13671. console.log( inputSources );
  13672. for ( var i = 0; i < controllers.length; i ++ ) {
  13673. var controller = controllers[ i ];
  13674. controller.userData.inputSource = inputSources[ i ];
  13675. }
  13676. } );
  13677. }
  13678. };
  13679. function updateCamera( camera, parent ) {
  13680. if ( parent === null ) {
  13681. camera.matrixWorld.copy( camera.matrix );
  13682. } else {
  13683. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13684. }
  13685. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13686. }
  13687. this.getCamera = function ( camera ) {
  13688. if ( isPresenting() ) {
  13689. var parent = camera.parent;
  13690. var cameras = cameraVR.cameras;
  13691. updateCamera( cameraVR, parent );
  13692. for ( var i = 0; i < cameras.length; i ++ ) {
  13693. updateCamera( cameras[ i ], parent );
  13694. }
  13695. // update camera and its children
  13696. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13697. var children = camera.children;
  13698. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13699. children[ i ].updateMatrixWorld( true );
  13700. }
  13701. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13702. return cameraVR;
  13703. }
  13704. return camera;
  13705. };
  13706. this.isPresenting = isPresenting;
  13707. // Animation Loop
  13708. var onAnimationFrameCallback = null;
  13709. function onAnimationFrame( time, frame ) {
  13710. pose = frame.getViewerPose( referenceSpace );
  13711. if ( pose !== null ) {
  13712. var views = pose.views;
  13713. var baseLayer = session.renderState.baseLayer;
  13714. renderer.setFramebuffer( baseLayer.framebuffer );
  13715. for ( var i = 0; i < views.length; i ++ ) {
  13716. var view = views[ i ];
  13717. var viewport = baseLayer.getViewport( view );
  13718. var viewMatrix = view.transform.inverse.matrix;
  13719. var camera = cameraVR.cameras[ i ];
  13720. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13721. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13722. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13723. if ( i === 0 ) {
  13724. cameraVR.matrix.copy( camera.matrix );
  13725. }
  13726. }
  13727. }
  13728. //
  13729. for ( var i = 0; i < controllers.length; i ++ ) {
  13730. var controller = controllers[ i ];
  13731. var inputSource = inputSources[ i ];
  13732. if ( inputSource ) {
  13733. var inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13734. if ( inputPose !== null ) {
  13735. controller.matrix.fromArray( inputPose.transform.matrix );
  13736. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13737. controller.visible = true;
  13738. continue;
  13739. }
  13740. }
  13741. controller.visible = false;
  13742. }
  13743. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13744. }
  13745. var animation = new WebGLAnimation();
  13746. animation.setAnimationLoop( onAnimationFrame );
  13747. this.setAnimationLoop = function ( callback ) {
  13748. onAnimationFrameCallback = callback;
  13749. };
  13750. this.dispose = function () {};
  13751. // DEPRECATED
  13752. this.getStandingMatrix = function () {
  13753. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13754. return new Matrix4();
  13755. };
  13756. this.getDevice = function () {
  13757. console.warn( 'THREE.WebXRManager: getDevice() has been deprecated.' );
  13758. };
  13759. this.setDevice = function () {
  13760. console.warn( 'THREE.WebXRManager: setDevice() has been deprecated.' );
  13761. };
  13762. this.setFrameOfReferenceType = function () {
  13763. console.warn( 'THREE.WebXRManager: setFrameOfReferenceType() has been deprecated.' );
  13764. };
  13765. this.submitFrame = function () {};
  13766. }
  13767. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  13768. /**
  13769. * @author supereggbert / http://www.paulbrunt.co.uk/
  13770. * @author mrdoob / http://mrdoob.com/
  13771. * @author alteredq / http://alteredqualia.com/
  13772. * @author szimek / https://github.com/szimek/
  13773. * @author tschw
  13774. */
  13775. function WebGLRenderer( parameters ) {
  13776. console.log( 'THREE.WebGLRenderer', REVISION );
  13777. parameters = parameters || {};
  13778. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13779. _context = parameters.context !== undefined ? parameters.context : null,
  13780. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13781. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13782. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13783. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13784. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13785. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13786. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13787. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13788. var currentRenderList = null;
  13789. var currentRenderState = null;
  13790. // public properties
  13791. this.domElement = _canvas;
  13792. // Debug configuration container
  13793. this.debug = {
  13794. /**
  13795. * Enables error checking and reporting when shader programs are being compiled
  13796. * @type {boolean}
  13797. */
  13798. checkShaderErrors: true
  13799. };
  13800. // clearing
  13801. this.autoClear = true;
  13802. this.autoClearColor = true;
  13803. this.autoClearDepth = true;
  13804. this.autoClearStencil = true;
  13805. // scene graph
  13806. this.sortObjects = true;
  13807. // user-defined clipping
  13808. this.clippingPlanes = [];
  13809. this.localClippingEnabled = false;
  13810. // physically based shading
  13811. this.gammaFactor = 2.0; // for backwards compatibility
  13812. this.gammaInput = false;
  13813. this.gammaOutput = false;
  13814. // physical lights
  13815. this.physicallyCorrectLights = false;
  13816. // tone mapping
  13817. this.toneMapping = LinearToneMapping;
  13818. this.toneMappingExposure = 1.0;
  13819. this.toneMappingWhitePoint = 1.0;
  13820. // morphs
  13821. this.maxMorphTargets = 8;
  13822. this.maxMorphNormals = 4;
  13823. // internal properties
  13824. var _this = this,
  13825. _isContextLost = false,
  13826. // internal state cache
  13827. _framebuffer = null,
  13828. _currentActiveCubeFace = 0,
  13829. _currentActiveMipmapLevel = 0,
  13830. _currentRenderTarget = null,
  13831. _currentFramebuffer = null,
  13832. _currentMaterialId = - 1,
  13833. // geometry and program caching
  13834. _currentGeometryProgram = {
  13835. geometry: null,
  13836. program: null,
  13837. wireframe: false
  13838. },
  13839. _currentCamera = null,
  13840. _currentArrayCamera = null,
  13841. _currentViewport = new Vector4(),
  13842. _currentScissor = new Vector4(),
  13843. _currentScissorTest = null,
  13844. //
  13845. _width = _canvas.width,
  13846. _height = _canvas.height,
  13847. _pixelRatio = 1,
  13848. _viewport = new Vector4( 0, 0, _width, _height ),
  13849. _scissor = new Vector4( 0, 0, _width, _height ),
  13850. _scissorTest = false,
  13851. // frustum
  13852. _frustum = new Frustum(),
  13853. // clipping
  13854. _clipping = new WebGLClipping(),
  13855. _clippingEnabled = false,
  13856. _localClippingEnabled = false,
  13857. // camera matrices cache
  13858. _projScreenMatrix = new Matrix4(),
  13859. _vector3 = new Vector3();
  13860. function getTargetPixelRatio() {
  13861. return _currentRenderTarget === null ? _pixelRatio : 1;
  13862. }
  13863. // initialize
  13864. var _gl;
  13865. try {
  13866. var contextAttributes = {
  13867. alpha: _alpha,
  13868. depth: _depth,
  13869. stencil: _stencil,
  13870. antialias: _antialias,
  13871. premultipliedAlpha: _premultipliedAlpha,
  13872. preserveDrawingBuffer: _preserveDrawingBuffer,
  13873. powerPreference: _powerPreference,
  13874. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
  13875. xrCompatible: true
  13876. };
  13877. // event listeners must be registered before WebGL context is created, see #12753
  13878. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13879. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13880. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13881. if ( _gl === null ) {
  13882. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13883. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13884. } else {
  13885. throw new Error( 'Error creating WebGL context.' );
  13886. }
  13887. }
  13888. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13889. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13890. _gl.getShaderPrecisionFormat = function () {
  13891. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13892. };
  13893. }
  13894. } catch ( error ) {
  13895. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13896. throw error;
  13897. }
  13898. var extensions, capabilities, state, info;
  13899. var properties, textures, attributes, geometries, objects;
  13900. var programCache, renderLists, renderStates;
  13901. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13902. var utils;
  13903. function initGLContext() {
  13904. extensions = new WebGLExtensions( _gl );
  13905. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13906. if ( ! capabilities.isWebGL2 ) {
  13907. extensions.get( 'WEBGL_depth_texture' );
  13908. extensions.get( 'OES_texture_float' );
  13909. extensions.get( 'OES_texture_half_float' );
  13910. extensions.get( 'OES_texture_half_float_linear' );
  13911. extensions.get( 'OES_standard_derivatives' );
  13912. extensions.get( 'OES_element_index_uint' );
  13913. extensions.get( 'ANGLE_instanced_arrays' );
  13914. }
  13915. extensions.get( 'OES_texture_float_linear' );
  13916. utils = new WebGLUtils( _gl, extensions, capabilities );
  13917. state = new WebGLState( _gl, extensions, utils, capabilities );
  13918. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  13919. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  13920. info = new WebGLInfo( _gl );
  13921. properties = new WebGLProperties();
  13922. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13923. attributes = new WebGLAttributes( _gl );
  13924. geometries = new WebGLGeometries( _gl, attributes, info );
  13925. objects = new WebGLObjects( geometries, info );
  13926. morphtargets = new WebGLMorphtargets( _gl );
  13927. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13928. renderLists = new WebGLRenderLists();
  13929. renderStates = new WebGLRenderStates();
  13930. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13931. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13932. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13933. info.programs = programCache.programs;
  13934. _this.capabilities = capabilities;
  13935. _this.extensions = extensions;
  13936. _this.properties = properties;
  13937. _this.renderLists = renderLists;
  13938. _this.state = state;
  13939. _this.info = info;
  13940. }
  13941. initGLContext();
  13942. // vr
  13943. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator && 'supportsSession' in navigator.xr ) ? new WebXRManager( _this, _gl ) : new WebVRManager( _this );
  13944. this.vr = vr;
  13945. // shadow map
  13946. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13947. this.shadowMap = shadowMap;
  13948. // API
  13949. this.getContext = function () {
  13950. return _gl;
  13951. };
  13952. this.getContextAttributes = function () {
  13953. return _gl.getContextAttributes();
  13954. };
  13955. this.forceContextLoss = function () {
  13956. var extension = extensions.get( 'WEBGL_lose_context' );
  13957. if ( extension ) extension.loseContext();
  13958. };
  13959. this.forceContextRestore = function () {
  13960. var extension = extensions.get( 'WEBGL_lose_context' );
  13961. if ( extension ) extension.restoreContext();
  13962. };
  13963. this.getPixelRatio = function () {
  13964. return _pixelRatio;
  13965. };
  13966. this.setPixelRatio = function ( value ) {
  13967. if ( value === undefined ) return;
  13968. _pixelRatio = value;
  13969. this.setSize( _width, _height, false );
  13970. };
  13971. this.getSize = function ( target ) {
  13972. if ( target === undefined ) {
  13973. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13974. target = new Vector2();
  13975. }
  13976. return target.set( _width, _height );
  13977. };
  13978. this.setSize = function ( width, height, updateStyle ) {
  13979. if ( vr.isPresenting() ) {
  13980. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13981. return;
  13982. }
  13983. _width = width;
  13984. _height = height;
  13985. _canvas.width = Math.floor( width * _pixelRatio );
  13986. _canvas.height = Math.floor( height * _pixelRatio );
  13987. if ( updateStyle !== false ) {
  13988. _canvas.style.width = width + 'px';
  13989. _canvas.style.height = height + 'px';
  13990. }
  13991. this.setViewport( 0, 0, width, height );
  13992. };
  13993. this.getDrawingBufferSize = function ( target ) {
  13994. if ( target === undefined ) {
  13995. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13996. target = new Vector2();
  13997. }
  13998. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  13999. };
  14000. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14001. _width = width;
  14002. _height = height;
  14003. _pixelRatio = pixelRatio;
  14004. _canvas.width = Math.floor( width * pixelRatio );
  14005. _canvas.height = Math.floor( height * pixelRatio );
  14006. this.setViewport( 0, 0, width, height );
  14007. };
  14008. this.getCurrentViewport = function ( target ) {
  14009. if ( target === undefined ) {
  14010. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14011. target = new Vector4();
  14012. }
  14013. return target.copy( _currentViewport );
  14014. };
  14015. this.getViewport = function ( target ) {
  14016. return target.copy( _viewport );
  14017. };
  14018. this.setViewport = function ( x, y, width, height ) {
  14019. if ( x.isVector4 ) {
  14020. _viewport.set( x.x, x.y, x.z, x.w );
  14021. } else {
  14022. _viewport.set( x, y, width, height );
  14023. }
  14024. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14025. };
  14026. this.getScissor = function ( target ) {
  14027. return target.copy( _scissor );
  14028. };
  14029. this.setScissor = function ( x, y, width, height ) {
  14030. if ( x.isVector4 ) {
  14031. _scissor.set( x.x, x.y, x.z, x.w );
  14032. } else {
  14033. _scissor.set( x, y, width, height );
  14034. }
  14035. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14036. };
  14037. this.getScissorTest = function () {
  14038. return _scissorTest;
  14039. };
  14040. this.setScissorTest = function ( boolean ) {
  14041. state.setScissorTest( _scissorTest = boolean );
  14042. };
  14043. // Clearing
  14044. this.getClearColor = function () {
  14045. return background.getClearColor();
  14046. };
  14047. this.setClearColor = function () {
  14048. background.setClearColor.apply( background, arguments );
  14049. };
  14050. this.getClearAlpha = function () {
  14051. return background.getClearAlpha();
  14052. };
  14053. this.setClearAlpha = function () {
  14054. background.setClearAlpha.apply( background, arguments );
  14055. };
  14056. this.clear = function ( color, depth, stencil ) {
  14057. var bits = 0;
  14058. if ( color === undefined || color ) bits |= 16384;
  14059. if ( depth === undefined || depth ) bits |= 256;
  14060. if ( stencil === undefined || stencil ) bits |= 1024;
  14061. _gl.clear( bits );
  14062. };
  14063. this.clearColor = function () {
  14064. this.clear( true, false, false );
  14065. };
  14066. this.clearDepth = function () {
  14067. this.clear( false, true, false );
  14068. };
  14069. this.clearStencil = function () {
  14070. this.clear( false, false, true );
  14071. };
  14072. //
  14073. this.dispose = function () {
  14074. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14075. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14076. renderLists.dispose();
  14077. renderStates.dispose();
  14078. properties.dispose();
  14079. objects.dispose();
  14080. vr.dispose();
  14081. animation.stop();
  14082. };
  14083. // Events
  14084. function onContextLost( event ) {
  14085. event.preventDefault();
  14086. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14087. _isContextLost = true;
  14088. }
  14089. function onContextRestore( /* event */ ) {
  14090. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14091. _isContextLost = false;
  14092. initGLContext();
  14093. }
  14094. function onMaterialDispose( event ) {
  14095. var material = event.target;
  14096. material.removeEventListener( 'dispose', onMaterialDispose );
  14097. deallocateMaterial( material );
  14098. }
  14099. // Buffer deallocation
  14100. function deallocateMaterial( material ) {
  14101. releaseMaterialProgramReference( material );
  14102. properties.remove( material );
  14103. }
  14104. function releaseMaterialProgramReference( material ) {
  14105. var programInfo = properties.get( material ).program;
  14106. material.program = undefined;
  14107. if ( programInfo !== undefined ) {
  14108. programCache.releaseProgram( programInfo );
  14109. }
  14110. }
  14111. // Buffer rendering
  14112. function renderObjectImmediate( object, program ) {
  14113. object.render( function ( object ) {
  14114. _this.renderBufferImmediate( object, program );
  14115. } );
  14116. }
  14117. this.renderBufferImmediate = function ( object, program ) {
  14118. state.initAttributes();
  14119. var buffers = properties.get( object );
  14120. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14121. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14122. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14123. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14124. var programAttributes = program.getAttributes();
  14125. if ( object.hasPositions ) {
  14126. _gl.bindBuffer( 34962, buffers.position );
  14127. _gl.bufferData( 34962, object.positionArray, 35048 );
  14128. state.enableAttribute( programAttributes.position );
  14129. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14130. }
  14131. if ( object.hasNormals ) {
  14132. _gl.bindBuffer( 34962, buffers.normal );
  14133. _gl.bufferData( 34962, object.normalArray, 35048 );
  14134. state.enableAttribute( programAttributes.normal );
  14135. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14136. }
  14137. if ( object.hasUvs ) {
  14138. _gl.bindBuffer( 34962, buffers.uv );
  14139. _gl.bufferData( 34962, object.uvArray, 35048 );
  14140. state.enableAttribute( programAttributes.uv );
  14141. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14142. }
  14143. if ( object.hasColors ) {
  14144. _gl.bindBuffer( 34962, buffers.color );
  14145. _gl.bufferData( 34962, object.colorArray, 35048 );
  14146. state.enableAttribute( programAttributes.color );
  14147. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14148. }
  14149. state.disableUnusedAttributes();
  14150. _gl.drawArrays( 4, 0, object.count );
  14151. object.count = 0;
  14152. };
  14153. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14154. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14155. state.setMaterial( material, frontFaceCW );
  14156. var program = setProgram( camera, fog, material, object );
  14157. var updateBuffers = false;
  14158. if ( _currentGeometryProgram.geometry !== geometry.id ||
  14159. _currentGeometryProgram.program !== program.id ||
  14160. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  14161. _currentGeometryProgram.geometry = geometry.id;
  14162. _currentGeometryProgram.program = program.id;
  14163. _currentGeometryProgram.wireframe = material.wireframe === true;
  14164. updateBuffers = true;
  14165. }
  14166. if ( object.morphTargetInfluences ) {
  14167. morphtargets.update( object, geometry, material, program );
  14168. updateBuffers = true;
  14169. }
  14170. //
  14171. var index = geometry.index;
  14172. var position = geometry.attributes.position;
  14173. var rangeFactor = 1;
  14174. if ( material.wireframe === true ) {
  14175. index = geometries.getWireframeAttribute( geometry );
  14176. rangeFactor = 2;
  14177. }
  14178. var attribute;
  14179. var renderer = bufferRenderer;
  14180. if ( index !== null ) {
  14181. attribute = attributes.get( index );
  14182. renderer = indexedBufferRenderer;
  14183. renderer.setIndex( attribute );
  14184. }
  14185. if ( updateBuffers ) {
  14186. setupVertexAttributes( material, program, geometry );
  14187. if ( index !== null ) {
  14188. _gl.bindBuffer( 34963, attribute.buffer );
  14189. }
  14190. }
  14191. //
  14192. var dataCount = Infinity;
  14193. if ( index !== null ) {
  14194. dataCount = index.count;
  14195. } else if ( position !== undefined ) {
  14196. dataCount = position.count;
  14197. }
  14198. var rangeStart = geometry.drawRange.start * rangeFactor;
  14199. var rangeCount = geometry.drawRange.count * rangeFactor;
  14200. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14201. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14202. var drawStart = Math.max( rangeStart, groupStart );
  14203. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14204. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14205. if ( drawCount === 0 ) return;
  14206. //
  14207. if ( object.isMesh ) {
  14208. if ( material.wireframe === true ) {
  14209. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14210. renderer.setMode( 1 );
  14211. } else {
  14212. switch ( object.drawMode ) {
  14213. case TrianglesDrawMode:
  14214. renderer.setMode( 4 );
  14215. break;
  14216. case TriangleStripDrawMode:
  14217. renderer.setMode( 5 );
  14218. break;
  14219. case TriangleFanDrawMode:
  14220. renderer.setMode( 6 );
  14221. break;
  14222. }
  14223. }
  14224. } else if ( object.isLine ) {
  14225. var lineWidth = material.linewidth;
  14226. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14227. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14228. if ( object.isLineSegments ) {
  14229. renderer.setMode( 1 );
  14230. } else if ( object.isLineLoop ) {
  14231. renderer.setMode( 2 );
  14232. } else {
  14233. renderer.setMode( 3 );
  14234. }
  14235. } else if ( object.isPoints ) {
  14236. renderer.setMode( 0 );
  14237. } else if ( object.isSprite ) {
  14238. renderer.setMode( 4 );
  14239. }
  14240. if ( geometry && geometry.isInstancedBufferGeometry ) {
  14241. if ( geometry.maxInstancedCount > 0 ) {
  14242. renderer.renderInstances( geometry, drawStart, drawCount );
  14243. }
  14244. } else {
  14245. renderer.render( drawStart, drawCount );
  14246. }
  14247. };
  14248. function setupVertexAttributes( material, program, geometry ) {
  14249. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  14250. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  14251. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14252. return;
  14253. }
  14254. }
  14255. state.initAttributes();
  14256. var geometryAttributes = geometry.attributes;
  14257. var programAttributes = program.getAttributes();
  14258. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14259. for ( var name in programAttributes ) {
  14260. var programAttribute = programAttributes[ name ];
  14261. if ( programAttribute >= 0 ) {
  14262. var geometryAttribute = geometryAttributes[ name ];
  14263. if ( geometryAttribute !== undefined ) {
  14264. var normalized = geometryAttribute.normalized;
  14265. var size = geometryAttribute.itemSize;
  14266. var attribute = attributes.get( geometryAttribute );
  14267. // TODO Attribute may not be available on context restore
  14268. if ( attribute === undefined ) continue;
  14269. var buffer = attribute.buffer;
  14270. var type = attribute.type;
  14271. var bytesPerElement = attribute.bytesPerElement;
  14272. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14273. var data = geometryAttribute.data;
  14274. var stride = data.stride;
  14275. var offset = geometryAttribute.offset;
  14276. if ( data && data.isInstancedInterleavedBuffer ) {
  14277. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14278. if ( geometry.maxInstancedCount === undefined ) {
  14279. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14280. }
  14281. } else {
  14282. state.enableAttribute( programAttribute );
  14283. }
  14284. _gl.bindBuffer( 34962, buffer );
  14285. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14286. } else {
  14287. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14288. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14289. if ( geometry.maxInstancedCount === undefined ) {
  14290. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14291. }
  14292. } else {
  14293. state.enableAttribute( programAttribute );
  14294. }
  14295. _gl.bindBuffer( 34962, buffer );
  14296. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14297. }
  14298. } else if ( materialDefaultAttributeValues !== undefined ) {
  14299. var value = materialDefaultAttributeValues[ name ];
  14300. if ( value !== undefined ) {
  14301. switch ( value.length ) {
  14302. case 2:
  14303. _gl.vertexAttrib2fv( programAttribute, value );
  14304. break;
  14305. case 3:
  14306. _gl.vertexAttrib3fv( programAttribute, value );
  14307. break;
  14308. case 4:
  14309. _gl.vertexAttrib4fv( programAttribute, value );
  14310. break;
  14311. default:
  14312. _gl.vertexAttrib1fv( programAttribute, value );
  14313. }
  14314. }
  14315. }
  14316. }
  14317. }
  14318. state.disableUnusedAttributes();
  14319. }
  14320. // Compile
  14321. this.compile = function ( scene, camera ) {
  14322. currentRenderState = renderStates.get( scene, camera );
  14323. currentRenderState.init();
  14324. scene.traverse( function ( object ) {
  14325. if ( object.isLight ) {
  14326. currentRenderState.pushLight( object );
  14327. if ( object.castShadow ) {
  14328. currentRenderState.pushShadow( object );
  14329. }
  14330. }
  14331. } );
  14332. currentRenderState.setupLights( camera );
  14333. scene.traverse( function ( object ) {
  14334. if ( object.material ) {
  14335. if ( Array.isArray( object.material ) ) {
  14336. for ( var i = 0; i < object.material.length; i ++ ) {
  14337. initMaterial( object.material[ i ], scene.fog, object );
  14338. }
  14339. } else {
  14340. initMaterial( object.material, scene.fog, object );
  14341. }
  14342. }
  14343. } );
  14344. };
  14345. // Animation Loop
  14346. var onAnimationFrameCallback = null;
  14347. function onAnimationFrame( time ) {
  14348. if ( vr.isPresenting() ) return;
  14349. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14350. }
  14351. var animation = new WebGLAnimation();
  14352. animation.setAnimationLoop( onAnimationFrame );
  14353. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14354. this.setAnimationLoop = function ( callback ) {
  14355. onAnimationFrameCallback = callback;
  14356. vr.setAnimationLoop( callback );
  14357. animation.start();
  14358. };
  14359. // Rendering
  14360. this.render = function ( scene, camera ) {
  14361. var renderTarget, forceClear;
  14362. if ( arguments[ 2 ] !== undefined ) {
  14363. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14364. renderTarget = arguments[ 2 ];
  14365. }
  14366. if ( arguments[ 3 ] !== undefined ) {
  14367. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14368. forceClear = arguments[ 3 ];
  14369. }
  14370. if ( ! ( camera && camera.isCamera ) ) {
  14371. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14372. return;
  14373. }
  14374. if ( _isContextLost ) return;
  14375. // reset caching for this frame
  14376. _currentGeometryProgram.geometry = null;
  14377. _currentGeometryProgram.program = null;
  14378. _currentGeometryProgram.wireframe = false;
  14379. _currentMaterialId = - 1;
  14380. _currentCamera = null;
  14381. // update scene graph
  14382. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14383. // update camera matrices and frustum
  14384. if ( camera.parent === null ) camera.updateMatrixWorld();
  14385. if ( vr.enabled ) {
  14386. camera = vr.getCamera( camera );
  14387. }
  14388. //
  14389. currentRenderState = renderStates.get( scene, camera );
  14390. currentRenderState.init();
  14391. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14392. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14393. _frustum.setFromMatrix( _projScreenMatrix );
  14394. _localClippingEnabled = this.localClippingEnabled;
  14395. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14396. currentRenderList = renderLists.get( scene, camera );
  14397. currentRenderList.init();
  14398. projectObject( scene, camera, 0, _this.sortObjects );
  14399. if ( _this.sortObjects === true ) {
  14400. currentRenderList.sort();
  14401. }
  14402. //
  14403. if ( _clippingEnabled ) _clipping.beginShadows();
  14404. var shadowsArray = currentRenderState.state.shadowsArray;
  14405. shadowMap.render( shadowsArray, scene, camera );
  14406. currentRenderState.setupLights( camera );
  14407. if ( _clippingEnabled ) _clipping.endShadows();
  14408. //
  14409. if ( this.info.autoReset ) this.info.reset();
  14410. if ( renderTarget !== undefined ) {
  14411. this.setRenderTarget( renderTarget );
  14412. }
  14413. //
  14414. background.render( currentRenderList, scene, camera, forceClear );
  14415. // render scene
  14416. var opaqueObjects = currentRenderList.opaque;
  14417. var transparentObjects = currentRenderList.transparent;
  14418. if ( scene.overrideMaterial ) {
  14419. var overrideMaterial = scene.overrideMaterial;
  14420. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14421. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14422. } else {
  14423. // opaque pass (front-to-back order)
  14424. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14425. // transparent pass (back-to-front order)
  14426. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14427. }
  14428. //
  14429. scene.onAfterRender( _this, scene, camera );
  14430. //
  14431. if ( _currentRenderTarget !== null ) {
  14432. // Generate mipmap if we're using any kind of mipmap filtering
  14433. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14434. // resolve multisample renderbuffers to a single-sample texture if necessary
  14435. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14436. }
  14437. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14438. state.buffers.depth.setTest( true );
  14439. state.buffers.depth.setMask( true );
  14440. state.buffers.color.setMask( true );
  14441. state.setPolygonOffset( false );
  14442. if ( vr.enabled ) {
  14443. vr.submitFrame();
  14444. }
  14445. // _gl.finish();
  14446. currentRenderList = null;
  14447. currentRenderState = null;
  14448. };
  14449. function projectObject( object, camera, groupOrder, sortObjects ) {
  14450. if ( object.visible === false ) return;
  14451. var visible = object.layers.test( camera.layers );
  14452. if ( visible ) {
  14453. if ( object.isGroup ) {
  14454. groupOrder = object.renderOrder;
  14455. } else if ( object.isLOD ) {
  14456. if ( object.autoUpdate === true ) object.update( camera );
  14457. } else if ( object.isLight ) {
  14458. currentRenderState.pushLight( object );
  14459. if ( object.castShadow ) {
  14460. currentRenderState.pushShadow( object );
  14461. }
  14462. } else if ( object.isSprite ) {
  14463. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14464. if ( sortObjects ) {
  14465. _vector3.setFromMatrixPosition( object.matrixWorld )
  14466. .applyMatrix4( _projScreenMatrix );
  14467. }
  14468. var geometry = objects.update( object );
  14469. var material = object.material;
  14470. if ( material.visible ) {
  14471. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14472. }
  14473. }
  14474. } else if ( object.isImmediateRenderObject ) {
  14475. if ( sortObjects ) {
  14476. _vector3.setFromMatrixPosition( object.matrixWorld )
  14477. .applyMatrix4( _projScreenMatrix );
  14478. }
  14479. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14480. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14481. if ( object.isSkinnedMesh ) {
  14482. object.skeleton.update();
  14483. }
  14484. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14485. if ( sortObjects ) {
  14486. _vector3.setFromMatrixPosition( object.matrixWorld )
  14487. .applyMatrix4( _projScreenMatrix );
  14488. }
  14489. var geometry = objects.update( object );
  14490. var material = object.material;
  14491. if ( Array.isArray( material ) ) {
  14492. var groups = geometry.groups;
  14493. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14494. var group = groups[ i ];
  14495. var groupMaterial = material[ group.materialIndex ];
  14496. if ( groupMaterial && groupMaterial.visible ) {
  14497. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14498. }
  14499. }
  14500. } else if ( material.visible ) {
  14501. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14502. }
  14503. }
  14504. }
  14505. }
  14506. var children = object.children;
  14507. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14508. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14509. }
  14510. }
  14511. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14512. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14513. var renderItem = renderList[ i ];
  14514. var object = renderItem.object;
  14515. var geometry = renderItem.geometry;
  14516. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14517. var group = renderItem.group;
  14518. if ( camera.isArrayCamera ) {
  14519. _currentArrayCamera = camera;
  14520. var cameras = camera.cameras;
  14521. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14522. var camera2 = cameras[ j ];
  14523. if ( object.layers.test( camera2.layers ) ) {
  14524. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14525. currentRenderState.setupLights( camera2 );
  14526. renderObject( object, scene, camera2, geometry, material, group );
  14527. }
  14528. }
  14529. } else {
  14530. _currentArrayCamera = null;
  14531. renderObject( object, scene, camera, geometry, material, group );
  14532. }
  14533. }
  14534. }
  14535. function renderObject( object, scene, camera, geometry, material, group ) {
  14536. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14537. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14538. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14539. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14540. if ( object.isImmediateRenderObject ) {
  14541. state.setMaterial( material );
  14542. var program = setProgram( camera, scene.fog, material, object );
  14543. _currentGeometryProgram.geometry = null;
  14544. _currentGeometryProgram.program = null;
  14545. _currentGeometryProgram.wireframe = false;
  14546. renderObjectImmediate( object, program );
  14547. } else {
  14548. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14549. }
  14550. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14551. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14552. }
  14553. function initMaterial( material, fog, object ) {
  14554. var materialProperties = properties.get( material );
  14555. var lights = currentRenderState.state.lights;
  14556. var shadowsArray = currentRenderState.state.shadowsArray;
  14557. var lightsStateVersion = lights.state.version;
  14558. var parameters = programCache.getParameters(
  14559. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14560. var code = programCache.getProgramCode( material, parameters );
  14561. var program = materialProperties.program;
  14562. var programChange = true;
  14563. if ( program === undefined ) {
  14564. // new material
  14565. material.addEventListener( 'dispose', onMaterialDispose );
  14566. } else if ( program.code !== code ) {
  14567. // changed glsl or parameters
  14568. releaseMaterialProgramReference( material );
  14569. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  14570. materialProperties.lightsStateVersion = lightsStateVersion;
  14571. programChange = false;
  14572. } else if ( parameters.shaderID !== undefined ) {
  14573. // same glsl and uniform list
  14574. return;
  14575. } else {
  14576. // only rebuild uniform list
  14577. programChange = false;
  14578. }
  14579. if ( programChange ) {
  14580. if ( parameters.shaderID ) {
  14581. var shader = ShaderLib[ parameters.shaderID ];
  14582. materialProperties.shader = {
  14583. name: material.type,
  14584. uniforms: cloneUniforms( shader.uniforms ),
  14585. vertexShader: shader.vertexShader,
  14586. fragmentShader: shader.fragmentShader
  14587. };
  14588. } else {
  14589. materialProperties.shader = {
  14590. name: material.type,
  14591. uniforms: material.uniforms,
  14592. vertexShader: material.vertexShader,
  14593. fragmentShader: material.fragmentShader
  14594. };
  14595. }
  14596. material.onBeforeCompile( materialProperties.shader, _this );
  14597. // Computing code again as onBeforeCompile may have changed the shaders
  14598. code = programCache.getProgramCode( material, parameters );
  14599. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14600. materialProperties.program = program;
  14601. material.program = program;
  14602. }
  14603. var programAttributes = program.getAttributes();
  14604. if ( material.morphTargets ) {
  14605. material.numSupportedMorphTargets = 0;
  14606. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14607. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14608. material.numSupportedMorphTargets ++;
  14609. }
  14610. }
  14611. }
  14612. if ( material.morphNormals ) {
  14613. material.numSupportedMorphNormals = 0;
  14614. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14615. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14616. material.numSupportedMorphNormals ++;
  14617. }
  14618. }
  14619. }
  14620. var uniforms = materialProperties.shader.uniforms;
  14621. if ( ! material.isShaderMaterial &&
  14622. ! material.isRawShaderMaterial ||
  14623. material.clipping === true ) {
  14624. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14625. materialProperties.numIntersection = _clipping.numIntersection;
  14626. uniforms.clippingPlanes = _clipping.uniform;
  14627. }
  14628. materialProperties.fog = fog;
  14629. // store the light setup it was created for
  14630. materialProperties.lightsStateVersion = lightsStateVersion;
  14631. if ( material.lights ) {
  14632. // wire up the material to this renderer's lighting state
  14633. uniforms.ambientLightColor.value = lights.state.ambient;
  14634. uniforms.lightProbe.value = lights.state.probe;
  14635. uniforms.directionalLights.value = lights.state.directional;
  14636. uniforms.spotLights.value = lights.state.spot;
  14637. uniforms.rectAreaLights.value = lights.state.rectArea;
  14638. uniforms.pointLights.value = lights.state.point;
  14639. uniforms.hemisphereLights.value = lights.state.hemi;
  14640. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14641. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14642. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14643. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14644. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14645. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14646. // TODO (abelnation): add area lights shadow info to uniforms
  14647. }
  14648. var progUniforms = materialProperties.program.getUniforms(),
  14649. uniformsList =
  14650. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14651. materialProperties.uniformsList = uniformsList;
  14652. }
  14653. function setProgram( camera, fog, material, object ) {
  14654. textures.resetTextureUnits();
  14655. var materialProperties = properties.get( material );
  14656. var lights = currentRenderState.state.lights;
  14657. if ( _clippingEnabled ) {
  14658. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14659. var useCache =
  14660. camera === _currentCamera &&
  14661. material.id === _currentMaterialId;
  14662. // we might want to call this function with some ClippingGroup
  14663. // object instead of the material, once it becomes feasible
  14664. // (#8465, #8379)
  14665. _clipping.setState(
  14666. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14667. camera, materialProperties, useCache );
  14668. }
  14669. }
  14670. if ( material.needsUpdate === false ) {
  14671. if ( materialProperties.program === undefined ) {
  14672. material.needsUpdate = true;
  14673. } else if ( material.fog && materialProperties.fog !== fog ) {
  14674. material.needsUpdate = true;
  14675. } else if ( material.lights && materialProperties.lightsStateVersion !== lights.state.version ) {
  14676. material.needsUpdate = true;
  14677. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14678. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14679. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14680. material.needsUpdate = true;
  14681. }
  14682. }
  14683. if ( material.needsUpdate ) {
  14684. initMaterial( material, fog, object );
  14685. material.needsUpdate = false;
  14686. }
  14687. var refreshProgram = false;
  14688. var refreshMaterial = false;
  14689. var refreshLights = false;
  14690. var program = materialProperties.program,
  14691. p_uniforms = program.getUniforms(),
  14692. m_uniforms = materialProperties.shader.uniforms;
  14693. if ( state.useProgram( program.program ) ) {
  14694. refreshProgram = true;
  14695. refreshMaterial = true;
  14696. refreshLights = true;
  14697. }
  14698. if ( material.id !== _currentMaterialId ) {
  14699. _currentMaterialId = material.id;
  14700. refreshMaterial = true;
  14701. }
  14702. if ( refreshProgram || _currentCamera !== camera ) {
  14703. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14704. if ( capabilities.logarithmicDepthBuffer ) {
  14705. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14706. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14707. }
  14708. if ( _currentCamera !== camera ) {
  14709. _currentCamera = camera;
  14710. // lighting uniforms depend on the camera so enforce an update
  14711. // now, in case this material supports lights - or later, when
  14712. // the next material that does gets activated:
  14713. refreshMaterial = true; // set to true on material change
  14714. refreshLights = true; // remains set until update done
  14715. }
  14716. // load material specific uniforms
  14717. // (shader material also gets them for the sake of genericity)
  14718. if ( material.isShaderMaterial ||
  14719. material.isMeshPhongMaterial ||
  14720. material.isMeshStandardMaterial ||
  14721. material.envMap ) {
  14722. var uCamPos = p_uniforms.map.cameraPosition;
  14723. if ( uCamPos !== undefined ) {
  14724. uCamPos.setValue( _gl,
  14725. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14726. }
  14727. }
  14728. if ( material.isMeshPhongMaterial ||
  14729. material.isMeshLambertMaterial ||
  14730. material.isMeshBasicMaterial ||
  14731. material.isMeshStandardMaterial ||
  14732. material.isShaderMaterial ||
  14733. material.skinning ) {
  14734. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14735. }
  14736. }
  14737. // skinning uniforms must be set even if material didn't change
  14738. // auto-setting of texture unit for bone texture must go before other textures
  14739. // not sure why, but otherwise weird things happen
  14740. if ( material.skinning ) {
  14741. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14742. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14743. var skeleton = object.skeleton;
  14744. if ( skeleton ) {
  14745. var bones = skeleton.bones;
  14746. if ( capabilities.floatVertexTextures ) {
  14747. if ( skeleton.boneTexture === undefined ) {
  14748. // layout (1 matrix = 4 pixels)
  14749. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14750. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14751. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14752. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14753. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14754. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14755. size = _Math.ceilPowerOfTwo( size );
  14756. size = Math.max( size, 4 );
  14757. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14758. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14759. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14760. boneTexture.needsUpdate = true;
  14761. skeleton.boneMatrices = boneMatrices;
  14762. skeleton.boneTexture = boneTexture;
  14763. skeleton.boneTextureSize = size;
  14764. }
  14765. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14766. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14767. } else {
  14768. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14769. }
  14770. }
  14771. }
  14772. if ( refreshMaterial ) {
  14773. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14774. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14775. if ( material.lights ) {
  14776. // the current material requires lighting info
  14777. // note: all lighting uniforms are always set correctly
  14778. // they simply reference the renderer's state for their
  14779. // values
  14780. //
  14781. // use the current material's .needsUpdate flags to set
  14782. // the GL state when required
  14783. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14784. }
  14785. // refresh uniforms common to several materials
  14786. if ( fog && material.fog ) {
  14787. refreshUniformsFog( m_uniforms, fog );
  14788. }
  14789. if ( material.isMeshBasicMaterial ) {
  14790. refreshUniformsCommon( m_uniforms, material );
  14791. } else if ( material.isMeshLambertMaterial ) {
  14792. refreshUniformsCommon( m_uniforms, material );
  14793. refreshUniformsLambert( m_uniforms, material );
  14794. } else if ( material.isMeshPhongMaterial ) {
  14795. refreshUniformsCommon( m_uniforms, material );
  14796. if ( material.isMeshToonMaterial ) {
  14797. refreshUniformsToon( m_uniforms, material );
  14798. } else {
  14799. refreshUniformsPhong( m_uniforms, material );
  14800. }
  14801. } else if ( material.isMeshStandardMaterial ) {
  14802. refreshUniformsCommon( m_uniforms, material );
  14803. if ( material.isMeshPhysicalMaterial ) {
  14804. refreshUniformsPhysical( m_uniforms, material );
  14805. } else {
  14806. refreshUniformsStandard( m_uniforms, material );
  14807. }
  14808. } else if ( material.isMeshMatcapMaterial ) {
  14809. refreshUniformsCommon( m_uniforms, material );
  14810. refreshUniformsMatcap( m_uniforms, material );
  14811. } else if ( material.isMeshDepthMaterial ) {
  14812. refreshUniformsCommon( m_uniforms, material );
  14813. refreshUniformsDepth( m_uniforms, material );
  14814. } else if ( material.isMeshDistanceMaterial ) {
  14815. refreshUniformsCommon( m_uniforms, material );
  14816. refreshUniformsDistance( m_uniforms, material );
  14817. } else if ( material.isMeshNormalMaterial ) {
  14818. refreshUniformsCommon( m_uniforms, material );
  14819. refreshUniformsNormal( m_uniforms, material );
  14820. } else if ( material.isLineBasicMaterial ) {
  14821. refreshUniformsLine( m_uniforms, material );
  14822. if ( material.isLineDashedMaterial ) {
  14823. refreshUniformsDash( m_uniforms, material );
  14824. }
  14825. } else if ( material.isPointsMaterial ) {
  14826. refreshUniformsPoints( m_uniforms, material );
  14827. } else if ( material.isSpriteMaterial ) {
  14828. refreshUniformsSprites( m_uniforms, material );
  14829. } else if ( material.isShadowMaterial ) {
  14830. m_uniforms.color.value.copy( material.color );
  14831. m_uniforms.opacity.value = material.opacity;
  14832. }
  14833. // RectAreaLight Texture
  14834. // TODO (mrdoob): Find a nicer implementation
  14835. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14836. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14837. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14838. }
  14839. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14840. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14841. material.uniformsNeedUpdate = false;
  14842. }
  14843. if ( material.isSpriteMaterial ) {
  14844. p_uniforms.setValue( _gl, 'center', object.center );
  14845. }
  14846. // common matrices
  14847. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14848. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14849. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14850. return program;
  14851. }
  14852. // Uniforms (refresh uniforms objects)
  14853. function refreshUniformsCommon( uniforms, material ) {
  14854. uniforms.opacity.value = material.opacity;
  14855. if ( material.color ) {
  14856. uniforms.diffuse.value.copy( material.color );
  14857. }
  14858. if ( material.emissive ) {
  14859. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14860. }
  14861. if ( material.map ) {
  14862. uniforms.map.value = material.map;
  14863. }
  14864. if ( material.alphaMap ) {
  14865. uniforms.alphaMap.value = material.alphaMap;
  14866. }
  14867. if ( material.specularMap ) {
  14868. uniforms.specularMap.value = material.specularMap;
  14869. }
  14870. if ( material.envMap ) {
  14871. uniforms.envMap.value = material.envMap;
  14872. // don't flip CubeTexture envMaps, flip everything else:
  14873. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14874. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14875. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14876. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14877. uniforms.reflectivity.value = material.reflectivity;
  14878. uniforms.refractionRatio.value = material.refractionRatio;
  14879. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14880. }
  14881. if ( material.lightMap ) {
  14882. uniforms.lightMap.value = material.lightMap;
  14883. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14884. }
  14885. if ( material.aoMap ) {
  14886. uniforms.aoMap.value = material.aoMap;
  14887. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14888. }
  14889. // uv repeat and offset setting priorities
  14890. // 1. color map
  14891. // 2. specular map
  14892. // 3. normal map
  14893. // 4. bump map
  14894. // 5. alpha map
  14895. // 6. emissive map
  14896. var uvScaleMap;
  14897. if ( material.map ) {
  14898. uvScaleMap = material.map;
  14899. } else if ( material.specularMap ) {
  14900. uvScaleMap = material.specularMap;
  14901. } else if ( material.displacementMap ) {
  14902. uvScaleMap = material.displacementMap;
  14903. } else if ( material.normalMap ) {
  14904. uvScaleMap = material.normalMap;
  14905. } else if ( material.bumpMap ) {
  14906. uvScaleMap = material.bumpMap;
  14907. } else if ( material.roughnessMap ) {
  14908. uvScaleMap = material.roughnessMap;
  14909. } else if ( material.metalnessMap ) {
  14910. uvScaleMap = material.metalnessMap;
  14911. } else if ( material.alphaMap ) {
  14912. uvScaleMap = material.alphaMap;
  14913. } else if ( material.emissiveMap ) {
  14914. uvScaleMap = material.emissiveMap;
  14915. }
  14916. if ( uvScaleMap !== undefined ) {
  14917. // backwards compatibility
  14918. if ( uvScaleMap.isWebGLRenderTarget ) {
  14919. uvScaleMap = uvScaleMap.texture;
  14920. }
  14921. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14922. uvScaleMap.updateMatrix();
  14923. }
  14924. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14925. }
  14926. }
  14927. function refreshUniformsLine( uniforms, material ) {
  14928. uniforms.diffuse.value.copy( material.color );
  14929. uniforms.opacity.value = material.opacity;
  14930. }
  14931. function refreshUniformsDash( uniforms, material ) {
  14932. uniforms.dashSize.value = material.dashSize;
  14933. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14934. uniforms.scale.value = material.scale;
  14935. }
  14936. function refreshUniformsPoints( uniforms, material ) {
  14937. uniforms.diffuse.value.copy( material.color );
  14938. uniforms.opacity.value = material.opacity;
  14939. uniforms.size.value = material.size * _pixelRatio;
  14940. uniforms.scale.value = _height * 0.5;
  14941. uniforms.map.value = material.map;
  14942. if ( material.map !== null ) {
  14943. if ( material.map.matrixAutoUpdate === true ) {
  14944. material.map.updateMatrix();
  14945. }
  14946. uniforms.uvTransform.value.copy( material.map.matrix );
  14947. }
  14948. }
  14949. function refreshUniformsSprites( uniforms, material ) {
  14950. uniforms.diffuse.value.copy( material.color );
  14951. uniforms.opacity.value = material.opacity;
  14952. uniforms.rotation.value = material.rotation;
  14953. uniforms.map.value = material.map;
  14954. if ( material.map !== null ) {
  14955. if ( material.map.matrixAutoUpdate === true ) {
  14956. material.map.updateMatrix();
  14957. }
  14958. uniforms.uvTransform.value.copy( material.map.matrix );
  14959. }
  14960. }
  14961. function refreshUniformsFog( uniforms, fog ) {
  14962. uniforms.fogColor.value.copy( fog.color );
  14963. if ( fog.isFog ) {
  14964. uniforms.fogNear.value = fog.near;
  14965. uniforms.fogFar.value = fog.far;
  14966. } else if ( fog.isFogExp2 ) {
  14967. uniforms.fogDensity.value = fog.density;
  14968. }
  14969. }
  14970. function refreshUniformsLambert( uniforms, material ) {
  14971. if ( material.emissiveMap ) {
  14972. uniforms.emissiveMap.value = material.emissiveMap;
  14973. }
  14974. }
  14975. function refreshUniformsPhong( uniforms, material ) {
  14976. uniforms.specular.value.copy( material.specular );
  14977. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14978. if ( material.emissiveMap ) {
  14979. uniforms.emissiveMap.value = material.emissiveMap;
  14980. }
  14981. if ( material.bumpMap ) {
  14982. uniforms.bumpMap.value = material.bumpMap;
  14983. uniforms.bumpScale.value = material.bumpScale;
  14984. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14985. }
  14986. if ( material.normalMap ) {
  14987. uniforms.normalMap.value = material.normalMap;
  14988. uniforms.normalScale.value.copy( material.normalScale );
  14989. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14990. }
  14991. if ( material.displacementMap ) {
  14992. uniforms.displacementMap.value = material.displacementMap;
  14993. uniforms.displacementScale.value = material.displacementScale;
  14994. uniforms.displacementBias.value = material.displacementBias;
  14995. }
  14996. }
  14997. function refreshUniformsToon( uniforms, material ) {
  14998. refreshUniformsPhong( uniforms, material );
  14999. if ( material.gradientMap ) {
  15000. uniforms.gradientMap.value = material.gradientMap;
  15001. }
  15002. }
  15003. function refreshUniformsStandard( uniforms, material ) {
  15004. uniforms.roughness.value = material.roughness;
  15005. uniforms.metalness.value = material.metalness;
  15006. if ( material.roughnessMap ) {
  15007. uniforms.roughnessMap.value = material.roughnessMap;
  15008. }
  15009. if ( material.metalnessMap ) {
  15010. uniforms.metalnessMap.value = material.metalnessMap;
  15011. }
  15012. if ( material.emissiveMap ) {
  15013. uniforms.emissiveMap.value = material.emissiveMap;
  15014. }
  15015. if ( material.bumpMap ) {
  15016. uniforms.bumpMap.value = material.bumpMap;
  15017. uniforms.bumpScale.value = material.bumpScale;
  15018. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15019. }
  15020. if ( material.normalMap ) {
  15021. uniforms.normalMap.value = material.normalMap;
  15022. uniforms.normalScale.value.copy( material.normalScale );
  15023. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15024. }
  15025. if ( material.displacementMap ) {
  15026. uniforms.displacementMap.value = material.displacementMap;
  15027. uniforms.displacementScale.value = material.displacementScale;
  15028. uniforms.displacementBias.value = material.displacementBias;
  15029. }
  15030. if ( material.envMap ) {
  15031. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15032. uniforms.envMapIntensity.value = material.envMapIntensity;
  15033. }
  15034. }
  15035. function refreshUniformsPhysical( uniforms, material ) {
  15036. refreshUniformsStandard( uniforms, material );
  15037. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  15038. uniforms.clearCoat.value = material.clearCoat;
  15039. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15040. }
  15041. function refreshUniformsMatcap( uniforms, material ) {
  15042. if ( material.matcap ) {
  15043. uniforms.matcap.value = material.matcap;
  15044. }
  15045. if ( material.bumpMap ) {
  15046. uniforms.bumpMap.value = material.bumpMap;
  15047. uniforms.bumpScale.value = material.bumpScale;
  15048. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15049. }
  15050. if ( material.normalMap ) {
  15051. uniforms.normalMap.value = material.normalMap;
  15052. uniforms.normalScale.value.copy( material.normalScale );
  15053. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15054. }
  15055. if ( material.displacementMap ) {
  15056. uniforms.displacementMap.value = material.displacementMap;
  15057. uniforms.displacementScale.value = material.displacementScale;
  15058. uniforms.displacementBias.value = material.displacementBias;
  15059. }
  15060. }
  15061. function refreshUniformsDepth( uniforms, material ) {
  15062. if ( material.displacementMap ) {
  15063. uniforms.displacementMap.value = material.displacementMap;
  15064. uniforms.displacementScale.value = material.displacementScale;
  15065. uniforms.displacementBias.value = material.displacementBias;
  15066. }
  15067. }
  15068. function refreshUniformsDistance( uniforms, material ) {
  15069. if ( material.displacementMap ) {
  15070. uniforms.displacementMap.value = material.displacementMap;
  15071. uniforms.displacementScale.value = material.displacementScale;
  15072. uniforms.displacementBias.value = material.displacementBias;
  15073. }
  15074. uniforms.referencePosition.value.copy( material.referencePosition );
  15075. uniforms.nearDistance.value = material.nearDistance;
  15076. uniforms.farDistance.value = material.farDistance;
  15077. }
  15078. function refreshUniformsNormal( uniforms, material ) {
  15079. if ( material.bumpMap ) {
  15080. uniforms.bumpMap.value = material.bumpMap;
  15081. uniforms.bumpScale.value = material.bumpScale;
  15082. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15083. }
  15084. if ( material.normalMap ) {
  15085. uniforms.normalMap.value = material.normalMap;
  15086. uniforms.normalScale.value.copy( material.normalScale );
  15087. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15088. }
  15089. if ( material.displacementMap ) {
  15090. uniforms.displacementMap.value = material.displacementMap;
  15091. uniforms.displacementScale.value = material.displacementScale;
  15092. uniforms.displacementBias.value = material.displacementBias;
  15093. }
  15094. }
  15095. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15096. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15097. uniforms.ambientLightColor.needsUpdate = value;
  15098. uniforms.lightProbe.needsUpdate = value;
  15099. uniforms.directionalLights.needsUpdate = value;
  15100. uniforms.pointLights.needsUpdate = value;
  15101. uniforms.spotLights.needsUpdate = value;
  15102. uniforms.rectAreaLights.needsUpdate = value;
  15103. uniforms.hemisphereLights.needsUpdate = value;
  15104. }
  15105. //
  15106. this.setFramebuffer = function ( value ) {
  15107. if ( _framebuffer !== value ) _gl.bindFramebuffer( 36160, value );
  15108. _framebuffer = value;
  15109. };
  15110. this.getActiveCubeFace = function () {
  15111. return _currentActiveCubeFace;
  15112. };
  15113. this.getActiveMipmapLevel = function () {
  15114. return _currentActiveMipmapLevel;
  15115. };
  15116. this.getRenderTarget = function () {
  15117. return _currentRenderTarget;
  15118. };
  15119. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15120. _currentRenderTarget = renderTarget;
  15121. _currentActiveCubeFace = activeCubeFace;
  15122. _currentActiveMipmapLevel = activeMipmapLevel;
  15123. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15124. textures.setupRenderTarget( renderTarget );
  15125. }
  15126. var framebuffer = _framebuffer;
  15127. var isCube = false;
  15128. if ( renderTarget ) {
  15129. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15130. if ( renderTarget.isWebGLRenderTargetCube ) {
  15131. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15132. isCube = true;
  15133. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15134. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15135. } else {
  15136. framebuffer = __webglFramebuffer;
  15137. }
  15138. _currentViewport.copy( renderTarget.viewport );
  15139. _currentScissor.copy( renderTarget.scissor );
  15140. _currentScissorTest = renderTarget.scissorTest;
  15141. } else {
  15142. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15143. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15144. _currentScissorTest = _scissorTest;
  15145. }
  15146. if ( _currentFramebuffer !== framebuffer ) {
  15147. _gl.bindFramebuffer( 36160, framebuffer );
  15148. _currentFramebuffer = framebuffer;
  15149. }
  15150. state.viewport( _currentViewport );
  15151. state.scissor( _currentScissor );
  15152. state.setScissorTest( _currentScissorTest );
  15153. if ( isCube ) {
  15154. var textureProperties = properties.get( renderTarget.texture );
  15155. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15156. }
  15157. };
  15158. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15159. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15160. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15161. return;
  15162. }
  15163. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15164. if ( renderTarget.isWebGLRenderTargetCube && activeCubeFaceIndex !== undefined ) {
  15165. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15166. }
  15167. if ( framebuffer ) {
  15168. var restore = false;
  15169. if ( framebuffer !== _currentFramebuffer ) {
  15170. _gl.bindFramebuffer( 36160, framebuffer );
  15171. restore = true;
  15172. }
  15173. try {
  15174. var texture = renderTarget.texture;
  15175. var textureFormat = texture.format;
  15176. var textureType = texture.type;
  15177. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15178. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15179. return;
  15180. }
  15181. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15182. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15183. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15184. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15185. return;
  15186. }
  15187. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15188. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15189. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15190. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15191. }
  15192. } else {
  15193. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15194. }
  15195. } finally {
  15196. if ( restore ) {
  15197. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15198. }
  15199. }
  15200. }
  15201. };
  15202. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15203. var width = texture.image.width;
  15204. var height = texture.image.height;
  15205. var glFormat = utils.convert( texture.format );
  15206. textures.setTexture2D( texture, 0 );
  15207. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  15208. };
  15209. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15210. var width = srcTexture.image.width;
  15211. var height = srcTexture.image.height;
  15212. var glFormat = utils.convert( dstTexture.format );
  15213. var glType = utils.convert( dstTexture.type );
  15214. textures.setTexture2D( dstTexture, 0 );
  15215. if ( srcTexture.isDataTexture ) {
  15216. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15217. } else {
  15218. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  15219. }
  15220. };
  15221. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15222. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15223. }
  15224. }
  15225. /**
  15226. * @author mrdoob / http://mrdoob.com/
  15227. * @author alteredq / http://alteredqualia.com/
  15228. */
  15229. function FogExp2( color, density ) {
  15230. this.name = '';
  15231. this.color = new Color( color );
  15232. this.density = ( density !== undefined ) ? density : 0.00025;
  15233. }
  15234. Object.assign( FogExp2.prototype, {
  15235. isFogExp2: true,
  15236. clone: function () {
  15237. return new FogExp2( this.color, this.density );
  15238. },
  15239. toJSON: function ( /* meta */ ) {
  15240. return {
  15241. type: 'FogExp2',
  15242. color: this.color.getHex(),
  15243. density: this.density
  15244. };
  15245. }
  15246. } );
  15247. /**
  15248. * @author mrdoob / http://mrdoob.com/
  15249. * @author alteredq / http://alteredqualia.com/
  15250. */
  15251. function Fog( color, near, far ) {
  15252. this.name = '';
  15253. this.color = new Color( color );
  15254. this.near = ( near !== undefined ) ? near : 1;
  15255. this.far = ( far !== undefined ) ? far : 1000;
  15256. }
  15257. Object.assign( Fog.prototype, {
  15258. isFog: true,
  15259. clone: function () {
  15260. return new Fog( this.color, this.near, this.far );
  15261. },
  15262. toJSON: function ( /* meta */ ) {
  15263. return {
  15264. type: 'Fog',
  15265. color: this.color.getHex(),
  15266. near: this.near,
  15267. far: this.far
  15268. };
  15269. }
  15270. } );
  15271. /**
  15272. * @author benaadams / https://twitter.com/ben_a_adams
  15273. */
  15274. function InterleavedBuffer( array, stride ) {
  15275. this.array = array;
  15276. this.stride = stride;
  15277. this.count = array !== undefined ? array.length / stride : 0;
  15278. this.dynamic = false;
  15279. this.updateRange = { offset: 0, count: - 1 };
  15280. this.version = 0;
  15281. }
  15282. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15283. set: function ( value ) {
  15284. if ( value === true ) this.version ++;
  15285. }
  15286. } );
  15287. Object.assign( InterleavedBuffer.prototype, {
  15288. isInterleavedBuffer: true,
  15289. onUploadCallback: function () {},
  15290. setArray: function ( array ) {
  15291. if ( Array.isArray( array ) ) {
  15292. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15293. }
  15294. this.count = array !== undefined ? array.length / this.stride : 0;
  15295. this.array = array;
  15296. return this;
  15297. },
  15298. setDynamic: function ( value ) {
  15299. this.dynamic = value;
  15300. return this;
  15301. },
  15302. copy: function ( source ) {
  15303. this.array = new source.array.constructor( source.array );
  15304. this.count = source.count;
  15305. this.stride = source.stride;
  15306. this.dynamic = source.dynamic;
  15307. return this;
  15308. },
  15309. copyAt: function ( index1, attribute, index2 ) {
  15310. index1 *= this.stride;
  15311. index2 *= attribute.stride;
  15312. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15313. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15314. }
  15315. return this;
  15316. },
  15317. set: function ( value, offset ) {
  15318. if ( offset === undefined ) offset = 0;
  15319. this.array.set( value, offset );
  15320. return this;
  15321. },
  15322. clone: function () {
  15323. return new this.constructor().copy( this );
  15324. },
  15325. onUpload: function ( callback ) {
  15326. this.onUploadCallback = callback;
  15327. return this;
  15328. }
  15329. } );
  15330. /**
  15331. * @author benaadams / https://twitter.com/ben_a_adams
  15332. */
  15333. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15334. this.data = interleavedBuffer;
  15335. this.itemSize = itemSize;
  15336. this.offset = offset;
  15337. this.normalized = normalized === true;
  15338. }
  15339. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15340. count: {
  15341. get: function () {
  15342. return this.data.count;
  15343. }
  15344. },
  15345. array: {
  15346. get: function () {
  15347. return this.data.array;
  15348. }
  15349. }
  15350. } );
  15351. Object.assign( InterleavedBufferAttribute.prototype, {
  15352. isInterleavedBufferAttribute: true,
  15353. setX: function ( index, x ) {
  15354. this.data.array[ index * this.data.stride + this.offset ] = x;
  15355. return this;
  15356. },
  15357. setY: function ( index, y ) {
  15358. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15359. return this;
  15360. },
  15361. setZ: function ( index, z ) {
  15362. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15363. return this;
  15364. },
  15365. setW: function ( index, w ) {
  15366. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15367. return this;
  15368. },
  15369. getX: function ( index ) {
  15370. return this.data.array[ index * this.data.stride + this.offset ];
  15371. },
  15372. getY: function ( index ) {
  15373. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15374. },
  15375. getZ: function ( index ) {
  15376. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15377. },
  15378. getW: function ( index ) {
  15379. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15380. },
  15381. setXY: function ( index, x, y ) {
  15382. index = index * this.data.stride + this.offset;
  15383. this.data.array[ index + 0 ] = x;
  15384. this.data.array[ index + 1 ] = y;
  15385. return this;
  15386. },
  15387. setXYZ: function ( index, x, y, z ) {
  15388. index = index * this.data.stride + this.offset;
  15389. this.data.array[ index + 0 ] = x;
  15390. this.data.array[ index + 1 ] = y;
  15391. this.data.array[ index + 2 ] = z;
  15392. return this;
  15393. },
  15394. setXYZW: function ( index, x, y, z, w ) {
  15395. index = index * this.data.stride + this.offset;
  15396. this.data.array[ index + 0 ] = x;
  15397. this.data.array[ index + 1 ] = y;
  15398. this.data.array[ index + 2 ] = z;
  15399. this.data.array[ index + 3 ] = w;
  15400. return this;
  15401. }
  15402. } );
  15403. /**
  15404. * @author alteredq / http://alteredqualia.com/
  15405. *
  15406. * parameters = {
  15407. * color: <hex>,
  15408. * map: new THREE.Texture( <Image> ),
  15409. * rotation: <float>,
  15410. * sizeAttenuation: <bool>
  15411. * }
  15412. */
  15413. function SpriteMaterial( parameters ) {
  15414. Material.call( this );
  15415. this.type = 'SpriteMaterial';
  15416. this.color = new Color( 0xffffff );
  15417. this.map = null;
  15418. this.rotation = 0;
  15419. this.sizeAttenuation = true;
  15420. this.lights = false;
  15421. this.transparent = true;
  15422. this.setValues( parameters );
  15423. }
  15424. SpriteMaterial.prototype = Object.create( Material.prototype );
  15425. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15426. SpriteMaterial.prototype.isSpriteMaterial = true;
  15427. SpriteMaterial.prototype.copy = function ( source ) {
  15428. Material.prototype.copy.call( this, source );
  15429. this.color.copy( source.color );
  15430. this.map = source.map;
  15431. this.rotation = source.rotation;
  15432. this.sizeAttenuation = source.sizeAttenuation;
  15433. return this;
  15434. };
  15435. /**
  15436. * @author mikael emtinger / http://gomo.se/
  15437. * @author alteredq / http://alteredqualia.com/
  15438. */
  15439. var geometry;
  15440. function Sprite( material ) {
  15441. Object3D.call( this );
  15442. this.type = 'Sprite';
  15443. if ( geometry === undefined ) {
  15444. geometry = new BufferGeometry();
  15445. var float32Array = new Float32Array( [
  15446. - 0.5, - 0.5, 0, 0, 0,
  15447. 0.5, - 0.5, 0, 1, 0,
  15448. 0.5, 0.5, 0, 1, 1,
  15449. - 0.5, 0.5, 0, 0, 1
  15450. ] );
  15451. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15452. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15453. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15454. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15455. }
  15456. this.geometry = geometry;
  15457. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15458. this.center = new Vector2( 0.5, 0.5 );
  15459. }
  15460. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15461. constructor: Sprite,
  15462. isSprite: true,
  15463. raycast: ( function () {
  15464. var intersectPoint = new Vector3();
  15465. var worldScale = new Vector3();
  15466. var mvPosition = new Vector3();
  15467. var alignedPosition = new Vector2();
  15468. var rotatedPosition = new Vector2();
  15469. var viewWorldMatrix = new Matrix4();
  15470. var vA = new Vector3();
  15471. var vB = new Vector3();
  15472. var vC = new Vector3();
  15473. var uvA = new Vector2();
  15474. var uvB = new Vector2();
  15475. var uvC = new Vector2();
  15476. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15477. // compute position in camera space
  15478. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15479. // to check if rotation is not zero
  15480. if ( sin !== undefined ) {
  15481. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15482. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15483. } else {
  15484. rotatedPosition.copy( alignedPosition );
  15485. }
  15486. vertexPosition.copy( mvPosition );
  15487. vertexPosition.x += rotatedPosition.x;
  15488. vertexPosition.y += rotatedPosition.y;
  15489. // transform to world space
  15490. vertexPosition.applyMatrix4( viewWorldMatrix );
  15491. }
  15492. return function raycast( raycaster, intersects ) {
  15493. worldScale.setFromMatrixScale( this.matrixWorld );
  15494. viewWorldMatrix.copy( raycaster._camera.matrixWorld );
  15495. this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
  15496. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15497. if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15498. worldScale.multiplyScalar( - mvPosition.z );
  15499. }
  15500. var rotation = this.material.rotation;
  15501. var sin, cos;
  15502. if ( rotation !== 0 ) {
  15503. cos = Math.cos( rotation );
  15504. sin = Math.sin( rotation );
  15505. }
  15506. var center = this.center;
  15507. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15508. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15509. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15510. uvA.set( 0, 0 );
  15511. uvB.set( 1, 0 );
  15512. uvC.set( 1, 1 );
  15513. // check first triangle
  15514. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15515. if ( intersect === null ) {
  15516. // check second triangle
  15517. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15518. uvB.set( 0, 1 );
  15519. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15520. if ( intersect === null ) {
  15521. return;
  15522. }
  15523. }
  15524. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15525. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15526. intersects.push( {
  15527. distance: distance,
  15528. point: intersectPoint.clone(),
  15529. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15530. face: null,
  15531. object: this
  15532. } );
  15533. };
  15534. }() ),
  15535. clone: function () {
  15536. return new this.constructor( this.material ).copy( this );
  15537. },
  15538. copy: function ( source ) {
  15539. Object3D.prototype.copy.call( this, source );
  15540. if ( source.center !== undefined ) this.center.copy( source.center );
  15541. return this;
  15542. }
  15543. } );
  15544. /**
  15545. * @author mikael emtinger / http://gomo.se/
  15546. * @author alteredq / http://alteredqualia.com/
  15547. * @author mrdoob / http://mrdoob.com/
  15548. */
  15549. function LOD() {
  15550. Object3D.call( this );
  15551. this.type = 'LOD';
  15552. Object.defineProperties( this, {
  15553. levels: {
  15554. enumerable: true,
  15555. value: []
  15556. }
  15557. } );
  15558. this.autoUpdate = true;
  15559. }
  15560. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15561. constructor: LOD,
  15562. isLOD: true,
  15563. copy: function ( source ) {
  15564. Object3D.prototype.copy.call( this, source, false );
  15565. var levels = source.levels;
  15566. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15567. var level = levels[ i ];
  15568. this.addLevel( level.object.clone(), level.distance );
  15569. }
  15570. return this;
  15571. },
  15572. addLevel: function ( object, distance ) {
  15573. if ( distance === undefined ) distance = 0;
  15574. distance = Math.abs( distance );
  15575. var levels = this.levels;
  15576. for ( var l = 0; l < levels.length; l ++ ) {
  15577. if ( distance < levels[ l ].distance ) {
  15578. break;
  15579. }
  15580. }
  15581. levels.splice( l, 0, { distance: distance, object: object } );
  15582. this.add( object );
  15583. return this;
  15584. },
  15585. getObjectForDistance: function ( distance ) {
  15586. var levels = this.levels;
  15587. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15588. if ( distance < levels[ i ].distance ) {
  15589. break;
  15590. }
  15591. }
  15592. return levels[ i - 1 ].object;
  15593. },
  15594. raycast: ( function () {
  15595. var matrixPosition = new Vector3();
  15596. return function raycast( raycaster, intersects ) {
  15597. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15598. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15599. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15600. };
  15601. }() ),
  15602. update: function () {
  15603. var v1 = new Vector3();
  15604. var v2 = new Vector3();
  15605. return function update( camera ) {
  15606. var levels = this.levels;
  15607. if ( levels.length > 1 ) {
  15608. v1.setFromMatrixPosition( camera.matrixWorld );
  15609. v2.setFromMatrixPosition( this.matrixWorld );
  15610. var distance = v1.distanceTo( v2 );
  15611. levels[ 0 ].object.visible = true;
  15612. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15613. if ( distance >= levels[ i ].distance ) {
  15614. levels[ i - 1 ].object.visible = false;
  15615. levels[ i ].object.visible = true;
  15616. } else {
  15617. break;
  15618. }
  15619. }
  15620. for ( ; i < l; i ++ ) {
  15621. levels[ i ].object.visible = false;
  15622. }
  15623. }
  15624. };
  15625. }(),
  15626. toJSON: function ( meta ) {
  15627. var data = Object3D.prototype.toJSON.call( this, meta );
  15628. data.object.levels = [];
  15629. var levels = this.levels;
  15630. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15631. var level = levels[ i ];
  15632. data.object.levels.push( {
  15633. object: level.object.uuid,
  15634. distance: level.distance
  15635. } );
  15636. }
  15637. return data;
  15638. }
  15639. } );
  15640. /**
  15641. * @author mikael emtinger / http://gomo.se/
  15642. * @author alteredq / http://alteredqualia.com/
  15643. * @author ikerr / http://verold.com
  15644. */
  15645. function SkinnedMesh( geometry, material ) {
  15646. if ( geometry && geometry.isGeometry ) {
  15647. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15648. }
  15649. Mesh.call( this, geometry, material );
  15650. this.type = 'SkinnedMesh';
  15651. this.bindMode = 'attached';
  15652. this.bindMatrix = new Matrix4();
  15653. this.bindMatrixInverse = new Matrix4();
  15654. }
  15655. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15656. constructor: SkinnedMesh,
  15657. isSkinnedMesh: true,
  15658. bind: function ( skeleton, bindMatrix ) {
  15659. this.skeleton = skeleton;
  15660. if ( bindMatrix === undefined ) {
  15661. this.updateMatrixWorld( true );
  15662. this.skeleton.calculateInverses();
  15663. bindMatrix = this.matrixWorld;
  15664. }
  15665. this.bindMatrix.copy( bindMatrix );
  15666. this.bindMatrixInverse.getInverse( bindMatrix );
  15667. },
  15668. pose: function () {
  15669. this.skeleton.pose();
  15670. },
  15671. normalizeSkinWeights: function () {
  15672. var vector = new Vector4();
  15673. var skinWeight = this.geometry.attributes.skinWeight;
  15674. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15675. vector.x = skinWeight.getX( i );
  15676. vector.y = skinWeight.getY( i );
  15677. vector.z = skinWeight.getZ( i );
  15678. vector.w = skinWeight.getW( i );
  15679. var scale = 1.0 / vector.manhattanLength();
  15680. if ( scale !== Infinity ) {
  15681. vector.multiplyScalar( scale );
  15682. } else {
  15683. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15684. }
  15685. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15686. }
  15687. },
  15688. updateMatrixWorld: function ( force ) {
  15689. Mesh.prototype.updateMatrixWorld.call( this, force );
  15690. if ( this.bindMode === 'attached' ) {
  15691. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15692. } else if ( this.bindMode === 'detached' ) {
  15693. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15694. } else {
  15695. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15696. }
  15697. },
  15698. clone: function () {
  15699. return new this.constructor( this.geometry, this.material ).copy( this );
  15700. }
  15701. } );
  15702. /**
  15703. * @author mikael emtinger / http://gomo.se/
  15704. * @author alteredq / http://alteredqualia.com/
  15705. * @author michael guerrero / http://realitymeltdown.com
  15706. * @author ikerr / http://verold.com
  15707. */
  15708. function Skeleton( bones, boneInverses ) {
  15709. // copy the bone array
  15710. bones = bones || [];
  15711. this.bones = bones.slice( 0 );
  15712. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15713. // use the supplied bone inverses or calculate the inverses
  15714. if ( boneInverses === undefined ) {
  15715. this.calculateInverses();
  15716. } else {
  15717. if ( this.bones.length === boneInverses.length ) {
  15718. this.boneInverses = boneInverses.slice( 0 );
  15719. } else {
  15720. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15721. this.boneInverses = [];
  15722. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15723. this.boneInverses.push( new Matrix4() );
  15724. }
  15725. }
  15726. }
  15727. }
  15728. Object.assign( Skeleton.prototype, {
  15729. calculateInverses: function () {
  15730. this.boneInverses = [];
  15731. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15732. var inverse = new Matrix4();
  15733. if ( this.bones[ i ] ) {
  15734. inverse.getInverse( this.bones[ i ].matrixWorld );
  15735. }
  15736. this.boneInverses.push( inverse );
  15737. }
  15738. },
  15739. pose: function () {
  15740. var bone, i, il;
  15741. // recover the bind-time world matrices
  15742. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15743. bone = this.bones[ i ];
  15744. if ( bone ) {
  15745. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15746. }
  15747. }
  15748. // compute the local matrices, positions, rotations and scales
  15749. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15750. bone = this.bones[ i ];
  15751. if ( bone ) {
  15752. if ( bone.parent && bone.parent.isBone ) {
  15753. bone.matrix.getInverse( bone.parent.matrixWorld );
  15754. bone.matrix.multiply( bone.matrixWorld );
  15755. } else {
  15756. bone.matrix.copy( bone.matrixWorld );
  15757. }
  15758. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15759. }
  15760. }
  15761. },
  15762. update: ( function () {
  15763. var offsetMatrix = new Matrix4();
  15764. var identityMatrix = new Matrix4();
  15765. return function update() {
  15766. var bones = this.bones;
  15767. var boneInverses = this.boneInverses;
  15768. var boneMatrices = this.boneMatrices;
  15769. var boneTexture = this.boneTexture;
  15770. // flatten bone matrices to array
  15771. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15772. // compute the offset between the current and the original transform
  15773. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15774. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15775. offsetMatrix.toArray( boneMatrices, i * 16 );
  15776. }
  15777. if ( boneTexture !== undefined ) {
  15778. boneTexture.needsUpdate = true;
  15779. }
  15780. };
  15781. } )(),
  15782. clone: function () {
  15783. return new Skeleton( this.bones, this.boneInverses );
  15784. },
  15785. getBoneByName: function ( name ) {
  15786. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15787. var bone = this.bones[ i ];
  15788. if ( bone.name === name ) {
  15789. return bone;
  15790. }
  15791. }
  15792. return undefined;
  15793. }
  15794. } );
  15795. /**
  15796. * @author mikael emtinger / http://gomo.se/
  15797. * @author alteredq / http://alteredqualia.com/
  15798. * @author ikerr / http://verold.com
  15799. */
  15800. function Bone() {
  15801. Object3D.call( this );
  15802. this.type = 'Bone';
  15803. }
  15804. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15805. constructor: Bone,
  15806. isBone: true
  15807. } );
  15808. /**
  15809. * @author mrdoob / http://mrdoob.com/
  15810. * @author alteredq / http://alteredqualia.com/
  15811. *
  15812. * parameters = {
  15813. * color: <hex>,
  15814. * opacity: <float>,
  15815. *
  15816. * linewidth: <float>,
  15817. * linecap: "round",
  15818. * linejoin: "round"
  15819. * }
  15820. */
  15821. function LineBasicMaterial( parameters ) {
  15822. Material.call( this );
  15823. this.type = 'LineBasicMaterial';
  15824. this.color = new Color( 0xffffff );
  15825. this.linewidth = 1;
  15826. this.linecap = 'round';
  15827. this.linejoin = 'round';
  15828. this.lights = false;
  15829. this.setValues( parameters );
  15830. }
  15831. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15832. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15833. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15834. LineBasicMaterial.prototype.copy = function ( source ) {
  15835. Material.prototype.copy.call( this, source );
  15836. this.color.copy( source.color );
  15837. this.linewidth = source.linewidth;
  15838. this.linecap = source.linecap;
  15839. this.linejoin = source.linejoin;
  15840. return this;
  15841. };
  15842. /**
  15843. * @author mrdoob / http://mrdoob.com/
  15844. */
  15845. function Line( geometry, material, mode ) {
  15846. if ( mode === 1 ) {
  15847. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15848. }
  15849. Object3D.call( this );
  15850. this.type = 'Line';
  15851. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15852. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15853. }
  15854. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15855. constructor: Line,
  15856. isLine: true,
  15857. computeLineDistances: ( function () {
  15858. var start = new Vector3();
  15859. var end = new Vector3();
  15860. return function computeLineDistances() {
  15861. var geometry = this.geometry;
  15862. if ( geometry.isBufferGeometry ) {
  15863. // we assume non-indexed geometry
  15864. if ( geometry.index === null ) {
  15865. var positionAttribute = geometry.attributes.position;
  15866. var lineDistances = [ 0 ];
  15867. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15868. start.fromBufferAttribute( positionAttribute, i - 1 );
  15869. end.fromBufferAttribute( positionAttribute, i );
  15870. lineDistances[ i ] = lineDistances[ i - 1 ];
  15871. lineDistances[ i ] += start.distanceTo( end );
  15872. }
  15873. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15874. } else {
  15875. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15876. }
  15877. } else if ( geometry.isGeometry ) {
  15878. var vertices = geometry.vertices;
  15879. var lineDistances = geometry.lineDistances;
  15880. lineDistances[ 0 ] = 0;
  15881. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15882. lineDistances[ i ] = lineDistances[ i - 1 ];
  15883. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15884. }
  15885. }
  15886. return this;
  15887. };
  15888. }() ),
  15889. raycast: ( function () {
  15890. var inverseMatrix = new Matrix4();
  15891. var ray = new Ray();
  15892. var sphere = new Sphere();
  15893. return function raycast( raycaster, intersects ) {
  15894. var precision = raycaster.linePrecision;
  15895. var geometry = this.geometry;
  15896. var matrixWorld = this.matrixWorld;
  15897. // Checking boundingSphere distance to ray
  15898. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15899. sphere.copy( geometry.boundingSphere );
  15900. sphere.applyMatrix4( matrixWorld );
  15901. sphere.radius += precision;
  15902. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15903. //
  15904. inverseMatrix.getInverse( matrixWorld );
  15905. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15906. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15907. var localPrecisionSq = localPrecision * localPrecision;
  15908. var vStart = new Vector3();
  15909. var vEnd = new Vector3();
  15910. var interSegment = new Vector3();
  15911. var interRay = new Vector3();
  15912. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15913. if ( geometry.isBufferGeometry ) {
  15914. var index = geometry.index;
  15915. var attributes = geometry.attributes;
  15916. var positions = attributes.position.array;
  15917. if ( index !== null ) {
  15918. var indices = index.array;
  15919. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15920. var a = indices[ i ];
  15921. var b = indices[ i + 1 ];
  15922. vStart.fromArray( positions, a * 3 );
  15923. vEnd.fromArray( positions, b * 3 );
  15924. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15925. if ( distSq > localPrecisionSq ) continue;
  15926. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15927. var distance = raycaster.ray.origin.distanceTo( interRay );
  15928. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15929. intersects.push( {
  15930. distance: distance,
  15931. // What do we want? intersection point on the ray or on the segment??
  15932. // point: raycaster.ray.at( distance ),
  15933. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15934. index: i,
  15935. face: null,
  15936. faceIndex: null,
  15937. object: this
  15938. } );
  15939. }
  15940. } else {
  15941. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15942. vStart.fromArray( positions, 3 * i );
  15943. vEnd.fromArray( positions, 3 * i + 3 );
  15944. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15945. if ( distSq > localPrecisionSq ) continue;
  15946. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15947. var distance = raycaster.ray.origin.distanceTo( interRay );
  15948. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15949. intersects.push( {
  15950. distance: distance,
  15951. // What do we want? intersection point on the ray or on the segment??
  15952. // point: raycaster.ray.at( distance ),
  15953. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15954. index: i,
  15955. face: null,
  15956. faceIndex: null,
  15957. object: this
  15958. } );
  15959. }
  15960. }
  15961. } else if ( geometry.isGeometry ) {
  15962. var vertices = geometry.vertices;
  15963. var nbVertices = vertices.length;
  15964. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15965. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15966. if ( distSq > localPrecisionSq ) continue;
  15967. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15968. var distance = raycaster.ray.origin.distanceTo( interRay );
  15969. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15970. intersects.push( {
  15971. distance: distance,
  15972. // What do we want? intersection point on the ray or on the segment??
  15973. // point: raycaster.ray.at( distance ),
  15974. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15975. index: i,
  15976. face: null,
  15977. faceIndex: null,
  15978. object: this
  15979. } );
  15980. }
  15981. }
  15982. };
  15983. }() ),
  15984. clone: function () {
  15985. return new this.constructor( this.geometry, this.material ).copy( this );
  15986. }
  15987. } );
  15988. /**
  15989. * @author mrdoob / http://mrdoob.com/
  15990. */
  15991. function LineSegments( geometry, material ) {
  15992. Line.call( this, geometry, material );
  15993. this.type = 'LineSegments';
  15994. }
  15995. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15996. constructor: LineSegments,
  15997. isLineSegments: true,
  15998. computeLineDistances: ( function () {
  15999. var start = new Vector3();
  16000. var end = new Vector3();
  16001. return function computeLineDistances() {
  16002. var geometry = this.geometry;
  16003. if ( geometry.isBufferGeometry ) {
  16004. // we assume non-indexed geometry
  16005. if ( geometry.index === null ) {
  16006. var positionAttribute = geometry.attributes.position;
  16007. var lineDistances = [];
  16008. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16009. start.fromBufferAttribute( positionAttribute, i );
  16010. end.fromBufferAttribute( positionAttribute, i + 1 );
  16011. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16012. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16013. }
  16014. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16015. } else {
  16016. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16017. }
  16018. } else if ( geometry.isGeometry ) {
  16019. var vertices = geometry.vertices;
  16020. var lineDistances = geometry.lineDistances;
  16021. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  16022. start.copy( vertices[ i ] );
  16023. end.copy( vertices[ i + 1 ] );
  16024. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16025. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16026. }
  16027. }
  16028. return this;
  16029. };
  16030. }() )
  16031. } );
  16032. /**
  16033. * @author mgreter / http://github.com/mgreter
  16034. */
  16035. function LineLoop( geometry, material ) {
  16036. Line.call( this, geometry, material );
  16037. this.type = 'LineLoop';
  16038. }
  16039. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16040. constructor: LineLoop,
  16041. isLineLoop: true,
  16042. } );
  16043. /**
  16044. * @author mrdoob / http://mrdoob.com/
  16045. * @author alteredq / http://alteredqualia.com/
  16046. *
  16047. * parameters = {
  16048. * color: <hex>,
  16049. * opacity: <float>,
  16050. * map: new THREE.Texture( <Image> ),
  16051. *
  16052. * size: <float>,
  16053. * sizeAttenuation: <bool>
  16054. *
  16055. * morphTargets: <bool>
  16056. * }
  16057. */
  16058. function PointsMaterial( parameters ) {
  16059. Material.call( this );
  16060. this.type = 'PointsMaterial';
  16061. this.color = new Color( 0xffffff );
  16062. this.map = null;
  16063. this.size = 1;
  16064. this.sizeAttenuation = true;
  16065. this.morphTargets = false;
  16066. this.lights = false;
  16067. this.setValues( parameters );
  16068. }
  16069. PointsMaterial.prototype = Object.create( Material.prototype );
  16070. PointsMaterial.prototype.constructor = PointsMaterial;
  16071. PointsMaterial.prototype.isPointsMaterial = true;
  16072. PointsMaterial.prototype.copy = function ( source ) {
  16073. Material.prototype.copy.call( this, source );
  16074. this.color.copy( source.color );
  16075. this.map = source.map;
  16076. this.size = source.size;
  16077. this.sizeAttenuation = source.sizeAttenuation;
  16078. this.morphTargets = source.morphTargets;
  16079. return this;
  16080. };
  16081. /**
  16082. * @author alteredq / http://alteredqualia.com/
  16083. */
  16084. function Points( geometry, material ) {
  16085. Object3D.call( this );
  16086. this.type = 'Points';
  16087. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16088. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  16089. this.updateMorphTargets();
  16090. }
  16091. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16092. constructor: Points,
  16093. isPoints: true,
  16094. raycast: ( function () {
  16095. var inverseMatrix = new Matrix4();
  16096. var ray = new Ray();
  16097. var sphere = new Sphere();
  16098. return function raycast( raycaster, intersects ) {
  16099. var object = this;
  16100. var geometry = this.geometry;
  16101. var matrixWorld = this.matrixWorld;
  16102. var threshold = raycaster.params.Points.threshold;
  16103. // Checking boundingSphere distance to ray
  16104. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16105. sphere.copy( geometry.boundingSphere );
  16106. sphere.applyMatrix4( matrixWorld );
  16107. sphere.radius += threshold;
  16108. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  16109. //
  16110. inverseMatrix.getInverse( matrixWorld );
  16111. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  16112. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16113. var localThresholdSq = localThreshold * localThreshold;
  16114. var position = new Vector3();
  16115. var intersectPoint = new Vector3();
  16116. function testPoint( point, index ) {
  16117. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  16118. if ( rayPointDistanceSq < localThresholdSq ) {
  16119. ray.closestPointToPoint( point, intersectPoint );
  16120. intersectPoint.applyMatrix4( matrixWorld );
  16121. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16122. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16123. intersects.push( {
  16124. distance: distance,
  16125. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16126. point: intersectPoint.clone(),
  16127. index: index,
  16128. face: null,
  16129. object: object
  16130. } );
  16131. }
  16132. }
  16133. if ( geometry.isBufferGeometry ) {
  16134. var index = geometry.index;
  16135. var attributes = geometry.attributes;
  16136. var positions = attributes.position.array;
  16137. if ( index !== null ) {
  16138. var indices = index.array;
  16139. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  16140. var a = indices[ i ];
  16141. position.fromArray( positions, a * 3 );
  16142. testPoint( position, a );
  16143. }
  16144. } else {
  16145. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  16146. position.fromArray( positions, i * 3 );
  16147. testPoint( position, i );
  16148. }
  16149. }
  16150. } else {
  16151. var vertices = geometry.vertices;
  16152. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  16153. testPoint( vertices[ i ], i );
  16154. }
  16155. }
  16156. };
  16157. }() ),
  16158. updateMorphTargets: function () {
  16159. var geometry = this.geometry;
  16160. var m, ml, name;
  16161. if ( geometry.isBufferGeometry ) {
  16162. var morphAttributes = geometry.morphAttributes;
  16163. var keys = Object.keys( morphAttributes );
  16164. if ( keys.length > 0 ) {
  16165. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16166. if ( morphAttribute !== undefined ) {
  16167. this.morphTargetInfluences = [];
  16168. this.morphTargetDictionary = {};
  16169. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16170. name = morphAttribute[ m ].name || String( m );
  16171. this.morphTargetInfluences.push( 0 );
  16172. this.morphTargetDictionary[ name ] = m;
  16173. }
  16174. }
  16175. }
  16176. } else {
  16177. var morphTargets = geometry.morphTargets;
  16178. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16179. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16180. }
  16181. }
  16182. },
  16183. clone: function () {
  16184. return new this.constructor( this.geometry, this.material ).copy( this );
  16185. }
  16186. } );
  16187. /**
  16188. * @author mrdoob / http://mrdoob.com/
  16189. */
  16190. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16191. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16192. this.format = format !== undefined ? format : RGBFormat;
  16193. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16194. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16195. this.generateMipmaps = false;
  16196. }
  16197. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16198. constructor: VideoTexture,
  16199. isVideoTexture: true,
  16200. update: function () {
  16201. var video = this.image;
  16202. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  16203. this.needsUpdate = true;
  16204. }
  16205. }
  16206. } );
  16207. /**
  16208. * @author alteredq / http://alteredqualia.com/
  16209. */
  16210. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16211. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16212. this.image = { width: width, height: height };
  16213. this.mipmaps = mipmaps;
  16214. // no flipping for cube textures
  16215. // (also flipping doesn't work for compressed textures )
  16216. this.flipY = false;
  16217. // can't generate mipmaps for compressed textures
  16218. // mips must be embedded in DDS files
  16219. this.generateMipmaps = false;
  16220. }
  16221. CompressedTexture.prototype = Object.create( Texture.prototype );
  16222. CompressedTexture.prototype.constructor = CompressedTexture;
  16223. CompressedTexture.prototype.isCompressedTexture = true;
  16224. /**
  16225. * @author mrdoob / http://mrdoob.com/
  16226. */
  16227. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16228. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16229. this.needsUpdate = true;
  16230. }
  16231. CanvasTexture.prototype = Object.create( Texture.prototype );
  16232. CanvasTexture.prototype.constructor = CanvasTexture;
  16233. CanvasTexture.prototype.isCanvasTexture = true;
  16234. /**
  16235. * @author Matt DesLauriers / @mattdesl
  16236. * @author atix / arthursilber.de
  16237. */
  16238. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16239. format = format !== undefined ? format : DepthFormat;
  16240. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16241. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16242. }
  16243. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16244. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16245. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16246. this.image = { width: width, height: height };
  16247. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16248. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16249. this.flipY = false;
  16250. this.generateMipmaps = false;
  16251. }
  16252. DepthTexture.prototype = Object.create( Texture.prototype );
  16253. DepthTexture.prototype.constructor = DepthTexture;
  16254. DepthTexture.prototype.isDepthTexture = true;
  16255. /**
  16256. * @author mrdoob / http://mrdoob.com/
  16257. * @author Mugen87 / https://github.com/Mugen87
  16258. */
  16259. function WireframeGeometry( geometry ) {
  16260. BufferGeometry.call( this );
  16261. this.type = 'WireframeGeometry';
  16262. // buffer
  16263. var vertices = [];
  16264. // helper variables
  16265. var i, j, l, o, ol;
  16266. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16267. var key, keys = [ 'a', 'b', 'c' ];
  16268. var vertex;
  16269. // different logic for Geometry and BufferGeometry
  16270. if ( geometry && geometry.isGeometry ) {
  16271. // create a data structure that contains all edges without duplicates
  16272. var faces = geometry.faces;
  16273. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16274. var face = faces[ i ];
  16275. for ( j = 0; j < 3; j ++ ) {
  16276. edge1 = face[ keys[ j ] ];
  16277. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16278. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16279. edge[ 1 ] = Math.max( edge1, edge2 );
  16280. key = edge[ 0 ] + ',' + edge[ 1 ];
  16281. if ( edges[ key ] === undefined ) {
  16282. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16283. }
  16284. }
  16285. }
  16286. // generate vertices
  16287. for ( key in edges ) {
  16288. e = edges[ key ];
  16289. vertex = geometry.vertices[ e.index1 ];
  16290. vertices.push( vertex.x, vertex.y, vertex.z );
  16291. vertex = geometry.vertices[ e.index2 ];
  16292. vertices.push( vertex.x, vertex.y, vertex.z );
  16293. }
  16294. } else if ( geometry && geometry.isBufferGeometry ) {
  16295. var position, indices, groups;
  16296. var group, start, count;
  16297. var index1, index2;
  16298. vertex = new Vector3();
  16299. if ( geometry.index !== null ) {
  16300. // indexed BufferGeometry
  16301. position = geometry.attributes.position;
  16302. indices = geometry.index;
  16303. groups = geometry.groups;
  16304. if ( groups.length === 0 ) {
  16305. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16306. }
  16307. // create a data structure that contains all eges without duplicates
  16308. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16309. group = groups[ o ];
  16310. start = group.start;
  16311. count = group.count;
  16312. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16313. for ( j = 0; j < 3; j ++ ) {
  16314. edge1 = indices.getX( i + j );
  16315. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16316. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16317. edge[ 1 ] = Math.max( edge1, edge2 );
  16318. key = edge[ 0 ] + ',' + edge[ 1 ];
  16319. if ( edges[ key ] === undefined ) {
  16320. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16321. }
  16322. }
  16323. }
  16324. }
  16325. // generate vertices
  16326. for ( key in edges ) {
  16327. e = edges[ key ];
  16328. vertex.fromBufferAttribute( position, e.index1 );
  16329. vertices.push( vertex.x, vertex.y, vertex.z );
  16330. vertex.fromBufferAttribute( position, e.index2 );
  16331. vertices.push( vertex.x, vertex.y, vertex.z );
  16332. }
  16333. } else {
  16334. // non-indexed BufferGeometry
  16335. position = geometry.attributes.position;
  16336. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16337. for ( j = 0; j < 3; j ++ ) {
  16338. // three edges per triangle, an edge is represented as (index1, index2)
  16339. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16340. index1 = 3 * i + j;
  16341. vertex.fromBufferAttribute( position, index1 );
  16342. vertices.push( vertex.x, vertex.y, vertex.z );
  16343. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16344. vertex.fromBufferAttribute( position, index2 );
  16345. vertices.push( vertex.x, vertex.y, vertex.z );
  16346. }
  16347. }
  16348. }
  16349. }
  16350. // build geometry
  16351. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16352. }
  16353. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16354. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16355. /**
  16356. * @author zz85 / https://github.com/zz85
  16357. * @author Mugen87 / https://github.com/Mugen87
  16358. *
  16359. * Parametric Surfaces Geometry
  16360. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16361. */
  16362. // ParametricGeometry
  16363. function ParametricGeometry( func, slices, stacks ) {
  16364. Geometry.call( this );
  16365. this.type = 'ParametricGeometry';
  16366. this.parameters = {
  16367. func: func,
  16368. slices: slices,
  16369. stacks: stacks
  16370. };
  16371. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16372. this.mergeVertices();
  16373. }
  16374. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16375. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16376. // ParametricBufferGeometry
  16377. function ParametricBufferGeometry( func, slices, stacks ) {
  16378. BufferGeometry.call( this );
  16379. this.type = 'ParametricBufferGeometry';
  16380. this.parameters = {
  16381. func: func,
  16382. slices: slices,
  16383. stacks: stacks
  16384. };
  16385. // buffers
  16386. var indices = [];
  16387. var vertices = [];
  16388. var normals = [];
  16389. var uvs = [];
  16390. var EPS = 0.00001;
  16391. var normal = new Vector3();
  16392. var p0 = new Vector3(), p1 = new Vector3();
  16393. var pu = new Vector3(), pv = new Vector3();
  16394. var i, j;
  16395. if ( func.length < 3 ) {
  16396. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16397. }
  16398. // generate vertices, normals and uvs
  16399. var sliceCount = slices + 1;
  16400. for ( i = 0; i <= stacks; i ++ ) {
  16401. var v = i / stacks;
  16402. for ( j = 0; j <= slices; j ++ ) {
  16403. var u = j / slices;
  16404. // vertex
  16405. func( u, v, p0 );
  16406. vertices.push( p0.x, p0.y, p0.z );
  16407. // normal
  16408. // approximate tangent vectors via finite differences
  16409. if ( u - EPS >= 0 ) {
  16410. func( u - EPS, v, p1 );
  16411. pu.subVectors( p0, p1 );
  16412. } else {
  16413. func( u + EPS, v, p1 );
  16414. pu.subVectors( p1, p0 );
  16415. }
  16416. if ( v - EPS >= 0 ) {
  16417. func( u, v - EPS, p1 );
  16418. pv.subVectors( p0, p1 );
  16419. } else {
  16420. func( u, v + EPS, p1 );
  16421. pv.subVectors( p1, p0 );
  16422. }
  16423. // cross product of tangent vectors returns surface normal
  16424. normal.crossVectors( pu, pv ).normalize();
  16425. normals.push( normal.x, normal.y, normal.z );
  16426. // uv
  16427. uvs.push( u, v );
  16428. }
  16429. }
  16430. // generate indices
  16431. for ( i = 0; i < stacks; i ++ ) {
  16432. for ( j = 0; j < slices; j ++ ) {
  16433. var a = i * sliceCount + j;
  16434. var b = i * sliceCount + j + 1;
  16435. var c = ( i + 1 ) * sliceCount + j + 1;
  16436. var d = ( i + 1 ) * sliceCount + j;
  16437. // faces one and two
  16438. indices.push( a, b, d );
  16439. indices.push( b, c, d );
  16440. }
  16441. }
  16442. // build geometry
  16443. this.setIndex( indices );
  16444. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16445. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16446. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16447. }
  16448. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16449. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16450. /**
  16451. * @author clockworkgeek / https://github.com/clockworkgeek
  16452. * @author timothypratley / https://github.com/timothypratley
  16453. * @author WestLangley / http://github.com/WestLangley
  16454. * @author Mugen87 / https://github.com/Mugen87
  16455. */
  16456. // PolyhedronGeometry
  16457. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16458. Geometry.call( this );
  16459. this.type = 'PolyhedronGeometry';
  16460. this.parameters = {
  16461. vertices: vertices,
  16462. indices: indices,
  16463. radius: radius,
  16464. detail: detail
  16465. };
  16466. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16467. this.mergeVertices();
  16468. }
  16469. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16470. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16471. // PolyhedronBufferGeometry
  16472. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16473. BufferGeometry.call( this );
  16474. this.type = 'PolyhedronBufferGeometry';
  16475. this.parameters = {
  16476. vertices: vertices,
  16477. indices: indices,
  16478. radius: radius,
  16479. detail: detail
  16480. };
  16481. radius = radius || 1;
  16482. detail = detail || 0;
  16483. // default buffer data
  16484. var vertexBuffer = [];
  16485. var uvBuffer = [];
  16486. // the subdivision creates the vertex buffer data
  16487. subdivide( detail );
  16488. // all vertices should lie on a conceptual sphere with a given radius
  16489. applyRadius( radius );
  16490. // finally, create the uv data
  16491. generateUVs();
  16492. // build non-indexed geometry
  16493. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16494. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16495. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16496. if ( detail === 0 ) {
  16497. this.computeVertexNormals(); // flat normals
  16498. } else {
  16499. this.normalizeNormals(); // smooth normals
  16500. }
  16501. // helper functions
  16502. function subdivide( detail ) {
  16503. var a = new Vector3();
  16504. var b = new Vector3();
  16505. var c = new Vector3();
  16506. // iterate over all faces and apply a subdivison with the given detail value
  16507. for ( var i = 0; i < indices.length; i += 3 ) {
  16508. // get the vertices of the face
  16509. getVertexByIndex( indices[ i + 0 ], a );
  16510. getVertexByIndex( indices[ i + 1 ], b );
  16511. getVertexByIndex( indices[ i + 2 ], c );
  16512. // perform subdivision
  16513. subdivideFace( a, b, c, detail );
  16514. }
  16515. }
  16516. function subdivideFace( a, b, c, detail ) {
  16517. var cols = Math.pow( 2, detail );
  16518. // we use this multidimensional array as a data structure for creating the subdivision
  16519. var v = [];
  16520. var i, j;
  16521. // construct all of the vertices for this subdivision
  16522. for ( i = 0; i <= cols; i ++ ) {
  16523. v[ i ] = [];
  16524. var aj = a.clone().lerp( c, i / cols );
  16525. var bj = b.clone().lerp( c, i / cols );
  16526. var rows = cols - i;
  16527. for ( j = 0; j <= rows; j ++ ) {
  16528. if ( j === 0 && i === cols ) {
  16529. v[ i ][ j ] = aj;
  16530. } else {
  16531. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16532. }
  16533. }
  16534. }
  16535. // construct all of the faces
  16536. for ( i = 0; i < cols; i ++ ) {
  16537. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16538. var k = Math.floor( j / 2 );
  16539. if ( j % 2 === 0 ) {
  16540. pushVertex( v[ i ][ k + 1 ] );
  16541. pushVertex( v[ i + 1 ][ k ] );
  16542. pushVertex( v[ i ][ k ] );
  16543. } else {
  16544. pushVertex( v[ i ][ k + 1 ] );
  16545. pushVertex( v[ i + 1 ][ k + 1 ] );
  16546. pushVertex( v[ i + 1 ][ k ] );
  16547. }
  16548. }
  16549. }
  16550. }
  16551. function applyRadius( radius ) {
  16552. var vertex = new Vector3();
  16553. // iterate over the entire buffer and apply the radius to each vertex
  16554. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16555. vertex.x = vertexBuffer[ i + 0 ];
  16556. vertex.y = vertexBuffer[ i + 1 ];
  16557. vertex.z = vertexBuffer[ i + 2 ];
  16558. vertex.normalize().multiplyScalar( radius );
  16559. vertexBuffer[ i + 0 ] = vertex.x;
  16560. vertexBuffer[ i + 1 ] = vertex.y;
  16561. vertexBuffer[ i + 2 ] = vertex.z;
  16562. }
  16563. }
  16564. function generateUVs() {
  16565. var vertex = new Vector3();
  16566. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16567. vertex.x = vertexBuffer[ i + 0 ];
  16568. vertex.y = vertexBuffer[ i + 1 ];
  16569. vertex.z = vertexBuffer[ i + 2 ];
  16570. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16571. var v = inclination( vertex ) / Math.PI + 0.5;
  16572. uvBuffer.push( u, 1 - v );
  16573. }
  16574. correctUVs();
  16575. correctSeam();
  16576. }
  16577. function correctSeam() {
  16578. // handle case when face straddles the seam, see #3269
  16579. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16580. // uv data of a single face
  16581. var x0 = uvBuffer[ i + 0 ];
  16582. var x1 = uvBuffer[ i + 2 ];
  16583. var x2 = uvBuffer[ i + 4 ];
  16584. var max = Math.max( x0, x1, x2 );
  16585. var min = Math.min( x0, x1, x2 );
  16586. // 0.9 is somewhat arbitrary
  16587. if ( max > 0.9 && min < 0.1 ) {
  16588. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16589. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16590. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16591. }
  16592. }
  16593. }
  16594. function pushVertex( vertex ) {
  16595. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16596. }
  16597. function getVertexByIndex( index, vertex ) {
  16598. var stride = index * 3;
  16599. vertex.x = vertices[ stride + 0 ];
  16600. vertex.y = vertices[ stride + 1 ];
  16601. vertex.z = vertices[ stride + 2 ];
  16602. }
  16603. function correctUVs() {
  16604. var a = new Vector3();
  16605. var b = new Vector3();
  16606. var c = new Vector3();
  16607. var centroid = new Vector3();
  16608. var uvA = new Vector2();
  16609. var uvB = new Vector2();
  16610. var uvC = new Vector2();
  16611. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16612. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16613. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16614. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16615. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16616. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16617. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16618. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16619. var azi = azimuth( centroid );
  16620. correctUV( uvA, j + 0, a, azi );
  16621. correctUV( uvB, j + 2, b, azi );
  16622. correctUV( uvC, j + 4, c, azi );
  16623. }
  16624. }
  16625. function correctUV( uv, stride, vector, azimuth ) {
  16626. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16627. uvBuffer[ stride ] = uv.x - 1;
  16628. }
  16629. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16630. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16631. }
  16632. }
  16633. // Angle around the Y axis, counter-clockwise when looking from above.
  16634. function azimuth( vector ) {
  16635. return Math.atan2( vector.z, - vector.x );
  16636. }
  16637. // Angle above the XZ plane.
  16638. function inclination( vector ) {
  16639. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16640. }
  16641. }
  16642. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16643. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16644. /**
  16645. * @author timothypratley / https://github.com/timothypratley
  16646. * @author Mugen87 / https://github.com/Mugen87
  16647. */
  16648. // TetrahedronGeometry
  16649. function TetrahedronGeometry( radius, detail ) {
  16650. Geometry.call( this );
  16651. this.type = 'TetrahedronGeometry';
  16652. this.parameters = {
  16653. radius: radius,
  16654. detail: detail
  16655. };
  16656. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16657. this.mergeVertices();
  16658. }
  16659. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16660. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16661. // TetrahedronBufferGeometry
  16662. function TetrahedronBufferGeometry( radius, detail ) {
  16663. var vertices = [
  16664. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16665. ];
  16666. var indices = [
  16667. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16668. ];
  16669. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16670. this.type = 'TetrahedronBufferGeometry';
  16671. this.parameters = {
  16672. radius: radius,
  16673. detail: detail
  16674. };
  16675. }
  16676. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16677. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16678. /**
  16679. * @author timothypratley / https://github.com/timothypratley
  16680. * @author Mugen87 / https://github.com/Mugen87
  16681. */
  16682. // OctahedronGeometry
  16683. function OctahedronGeometry( radius, detail ) {
  16684. Geometry.call( this );
  16685. this.type = 'OctahedronGeometry';
  16686. this.parameters = {
  16687. radius: radius,
  16688. detail: detail
  16689. };
  16690. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16691. this.mergeVertices();
  16692. }
  16693. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16694. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16695. // OctahedronBufferGeometry
  16696. function OctahedronBufferGeometry( radius, detail ) {
  16697. var vertices = [
  16698. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16699. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16700. ];
  16701. var indices = [
  16702. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16703. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16704. 1, 3, 4, 1, 4, 2
  16705. ];
  16706. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16707. this.type = 'OctahedronBufferGeometry';
  16708. this.parameters = {
  16709. radius: radius,
  16710. detail: detail
  16711. };
  16712. }
  16713. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16714. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16715. /**
  16716. * @author timothypratley / https://github.com/timothypratley
  16717. * @author Mugen87 / https://github.com/Mugen87
  16718. */
  16719. // IcosahedronGeometry
  16720. function IcosahedronGeometry( radius, detail ) {
  16721. Geometry.call( this );
  16722. this.type = 'IcosahedronGeometry';
  16723. this.parameters = {
  16724. radius: radius,
  16725. detail: detail
  16726. };
  16727. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16728. this.mergeVertices();
  16729. }
  16730. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16731. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16732. // IcosahedronBufferGeometry
  16733. function IcosahedronBufferGeometry( radius, detail ) {
  16734. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16735. var vertices = [
  16736. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16737. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16738. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16739. ];
  16740. var indices = [
  16741. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16742. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16743. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16744. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16745. ];
  16746. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16747. this.type = 'IcosahedronBufferGeometry';
  16748. this.parameters = {
  16749. radius: radius,
  16750. detail: detail
  16751. };
  16752. }
  16753. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16754. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16755. /**
  16756. * @author Abe Pazos / https://hamoid.com
  16757. * @author Mugen87 / https://github.com/Mugen87
  16758. */
  16759. // DodecahedronGeometry
  16760. function DodecahedronGeometry( radius, detail ) {
  16761. Geometry.call( this );
  16762. this.type = 'DodecahedronGeometry';
  16763. this.parameters = {
  16764. radius: radius,
  16765. detail: detail
  16766. };
  16767. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16768. this.mergeVertices();
  16769. }
  16770. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16771. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16772. // DodecahedronBufferGeometry
  16773. function DodecahedronBufferGeometry( radius, detail ) {
  16774. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16775. var r = 1 / t;
  16776. var vertices = [
  16777. // (±1, ±1, ±1)
  16778. - 1, - 1, - 1, - 1, - 1, 1,
  16779. - 1, 1, - 1, - 1, 1, 1,
  16780. 1, - 1, - 1, 1, - 1, 1,
  16781. 1, 1, - 1, 1, 1, 1,
  16782. // (0, ±1/φ, ±φ)
  16783. 0, - r, - t, 0, - r, t,
  16784. 0, r, - t, 0, r, t,
  16785. // (±1/φ, ±φ, 0)
  16786. - r, - t, 0, - r, t, 0,
  16787. r, - t, 0, r, t, 0,
  16788. // (±φ, 0, ±1/φ)
  16789. - t, 0, - r, t, 0, - r,
  16790. - t, 0, r, t, 0, r
  16791. ];
  16792. var indices = [
  16793. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16794. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16795. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16796. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16797. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16798. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16799. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16800. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16801. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16802. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16803. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16804. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16805. ];
  16806. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16807. this.type = 'DodecahedronBufferGeometry';
  16808. this.parameters = {
  16809. radius: radius,
  16810. detail: detail
  16811. };
  16812. }
  16813. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16814. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16815. /**
  16816. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16817. * @author WestLangley / https://github.com/WestLangley
  16818. * @author zz85 / https://github.com/zz85
  16819. * @author miningold / https://github.com/miningold
  16820. * @author jonobr1 / https://github.com/jonobr1
  16821. * @author Mugen87 / https://github.com/Mugen87
  16822. *
  16823. */
  16824. // TubeGeometry
  16825. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16826. Geometry.call( this );
  16827. this.type = 'TubeGeometry';
  16828. this.parameters = {
  16829. path: path,
  16830. tubularSegments: tubularSegments,
  16831. radius: radius,
  16832. radialSegments: radialSegments,
  16833. closed: closed
  16834. };
  16835. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16836. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16837. // expose internals
  16838. this.tangents = bufferGeometry.tangents;
  16839. this.normals = bufferGeometry.normals;
  16840. this.binormals = bufferGeometry.binormals;
  16841. // create geometry
  16842. this.fromBufferGeometry( bufferGeometry );
  16843. this.mergeVertices();
  16844. }
  16845. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16846. TubeGeometry.prototype.constructor = TubeGeometry;
  16847. // TubeBufferGeometry
  16848. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16849. BufferGeometry.call( this );
  16850. this.type = 'TubeBufferGeometry';
  16851. this.parameters = {
  16852. path: path,
  16853. tubularSegments: tubularSegments,
  16854. radius: radius,
  16855. radialSegments: radialSegments,
  16856. closed: closed
  16857. };
  16858. tubularSegments = tubularSegments || 64;
  16859. radius = radius || 1;
  16860. radialSegments = radialSegments || 8;
  16861. closed = closed || false;
  16862. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16863. // expose internals
  16864. this.tangents = frames.tangents;
  16865. this.normals = frames.normals;
  16866. this.binormals = frames.binormals;
  16867. // helper variables
  16868. var vertex = new Vector3();
  16869. var normal = new Vector3();
  16870. var uv = new Vector2();
  16871. var P = new Vector3();
  16872. var i, j;
  16873. // buffer
  16874. var vertices = [];
  16875. var normals = [];
  16876. var uvs = [];
  16877. var indices = [];
  16878. // create buffer data
  16879. generateBufferData();
  16880. // build geometry
  16881. this.setIndex( indices );
  16882. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16883. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16884. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16885. // functions
  16886. function generateBufferData() {
  16887. for ( i = 0; i < tubularSegments; i ++ ) {
  16888. generateSegment( i );
  16889. }
  16890. // if the geometry is not closed, generate the last row of vertices and normals
  16891. // at the regular position on the given path
  16892. //
  16893. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16894. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16895. // uvs are generated in a separate function.
  16896. // this makes it easy compute correct values for closed geometries
  16897. generateUVs();
  16898. // finally create faces
  16899. generateIndices();
  16900. }
  16901. function generateSegment( i ) {
  16902. // we use getPointAt to sample evenly distributed points from the given path
  16903. P = path.getPointAt( i / tubularSegments, P );
  16904. // retrieve corresponding normal and binormal
  16905. var N = frames.normals[ i ];
  16906. var B = frames.binormals[ i ];
  16907. // generate normals and vertices for the current segment
  16908. for ( j = 0; j <= radialSegments; j ++ ) {
  16909. var v = j / radialSegments * Math.PI * 2;
  16910. var sin = Math.sin( v );
  16911. var cos = - Math.cos( v );
  16912. // normal
  16913. normal.x = ( cos * N.x + sin * B.x );
  16914. normal.y = ( cos * N.y + sin * B.y );
  16915. normal.z = ( cos * N.z + sin * B.z );
  16916. normal.normalize();
  16917. normals.push( normal.x, normal.y, normal.z );
  16918. // vertex
  16919. vertex.x = P.x + radius * normal.x;
  16920. vertex.y = P.y + radius * normal.y;
  16921. vertex.z = P.z + radius * normal.z;
  16922. vertices.push( vertex.x, vertex.y, vertex.z );
  16923. }
  16924. }
  16925. function generateIndices() {
  16926. for ( j = 1; j <= tubularSegments; j ++ ) {
  16927. for ( i = 1; i <= radialSegments; i ++ ) {
  16928. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16929. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16930. var c = ( radialSegments + 1 ) * j + i;
  16931. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16932. // faces
  16933. indices.push( a, b, d );
  16934. indices.push( b, c, d );
  16935. }
  16936. }
  16937. }
  16938. function generateUVs() {
  16939. for ( i = 0; i <= tubularSegments; i ++ ) {
  16940. for ( j = 0; j <= radialSegments; j ++ ) {
  16941. uv.x = i / tubularSegments;
  16942. uv.y = j / radialSegments;
  16943. uvs.push( uv.x, uv.y );
  16944. }
  16945. }
  16946. }
  16947. }
  16948. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16949. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16950. TubeBufferGeometry.prototype.toJSON = function () {
  16951. var data = BufferGeometry.prototype.toJSON.call( this );
  16952. data.path = this.parameters.path.toJSON();
  16953. return data;
  16954. };
  16955. /**
  16956. * @author oosmoxiecode
  16957. * @author Mugen87 / https://github.com/Mugen87
  16958. *
  16959. * based on http://www.blackpawn.com/texts/pqtorus/
  16960. */
  16961. // TorusKnotGeometry
  16962. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16963. Geometry.call( this );
  16964. this.type = 'TorusKnotGeometry';
  16965. this.parameters = {
  16966. radius: radius,
  16967. tube: tube,
  16968. tubularSegments: tubularSegments,
  16969. radialSegments: radialSegments,
  16970. p: p,
  16971. q: q
  16972. };
  16973. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16974. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16975. this.mergeVertices();
  16976. }
  16977. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16978. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16979. // TorusKnotBufferGeometry
  16980. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16981. BufferGeometry.call( this );
  16982. this.type = 'TorusKnotBufferGeometry';
  16983. this.parameters = {
  16984. radius: radius,
  16985. tube: tube,
  16986. tubularSegments: tubularSegments,
  16987. radialSegments: radialSegments,
  16988. p: p,
  16989. q: q
  16990. };
  16991. radius = radius || 1;
  16992. tube = tube || 0.4;
  16993. tubularSegments = Math.floor( tubularSegments ) || 64;
  16994. radialSegments = Math.floor( radialSegments ) || 8;
  16995. p = p || 2;
  16996. q = q || 3;
  16997. // buffers
  16998. var indices = [];
  16999. var vertices = [];
  17000. var normals = [];
  17001. var uvs = [];
  17002. // helper variables
  17003. var i, j;
  17004. var vertex = new Vector3();
  17005. var normal = new Vector3();
  17006. var P1 = new Vector3();
  17007. var P2 = new Vector3();
  17008. var B = new Vector3();
  17009. var T = new Vector3();
  17010. var N = new Vector3();
  17011. // generate vertices, normals and uvs
  17012. for ( i = 0; i <= tubularSegments; ++ i ) {
  17013. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17014. var u = i / tubularSegments * p * Math.PI * 2;
  17015. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17016. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17017. calculatePositionOnCurve( u, p, q, radius, P1 );
  17018. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17019. // calculate orthonormal basis
  17020. T.subVectors( P2, P1 );
  17021. N.addVectors( P2, P1 );
  17022. B.crossVectors( T, N );
  17023. N.crossVectors( B, T );
  17024. // normalize B, N. T can be ignored, we don't use it
  17025. B.normalize();
  17026. N.normalize();
  17027. for ( j = 0; j <= radialSegments; ++ j ) {
  17028. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17029. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17030. var v = j / radialSegments * Math.PI * 2;
  17031. var cx = - tube * Math.cos( v );
  17032. var cy = tube * Math.sin( v );
  17033. // now calculate the final vertex position.
  17034. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17035. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17036. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17037. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17038. vertices.push( vertex.x, vertex.y, vertex.z );
  17039. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17040. normal.subVectors( vertex, P1 ).normalize();
  17041. normals.push( normal.x, normal.y, normal.z );
  17042. // uv
  17043. uvs.push( i / tubularSegments );
  17044. uvs.push( j / radialSegments );
  17045. }
  17046. }
  17047. // generate indices
  17048. for ( j = 1; j <= tubularSegments; j ++ ) {
  17049. for ( i = 1; i <= radialSegments; i ++ ) {
  17050. // indices
  17051. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17052. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17053. var c = ( radialSegments + 1 ) * j + i;
  17054. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17055. // faces
  17056. indices.push( a, b, d );
  17057. indices.push( b, c, d );
  17058. }
  17059. }
  17060. // build geometry
  17061. this.setIndex( indices );
  17062. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17063. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17064. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17065. // this function calculates the current position on the torus curve
  17066. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17067. var cu = Math.cos( u );
  17068. var su = Math.sin( u );
  17069. var quOverP = q / p * u;
  17070. var cs = Math.cos( quOverP );
  17071. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17072. position.y = radius * ( 2 + cs ) * su * 0.5;
  17073. position.z = radius * Math.sin( quOverP ) * 0.5;
  17074. }
  17075. }
  17076. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17077. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17078. /**
  17079. * @author oosmoxiecode
  17080. * @author mrdoob / http://mrdoob.com/
  17081. * @author Mugen87 / https://github.com/Mugen87
  17082. */
  17083. // TorusGeometry
  17084. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17085. Geometry.call( this );
  17086. this.type = 'TorusGeometry';
  17087. this.parameters = {
  17088. radius: radius,
  17089. tube: tube,
  17090. radialSegments: radialSegments,
  17091. tubularSegments: tubularSegments,
  17092. arc: arc
  17093. };
  17094. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17095. this.mergeVertices();
  17096. }
  17097. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17098. TorusGeometry.prototype.constructor = TorusGeometry;
  17099. // TorusBufferGeometry
  17100. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17101. BufferGeometry.call( this );
  17102. this.type = 'TorusBufferGeometry';
  17103. this.parameters = {
  17104. radius: radius,
  17105. tube: tube,
  17106. radialSegments: radialSegments,
  17107. tubularSegments: tubularSegments,
  17108. arc: arc
  17109. };
  17110. radius = radius || 1;
  17111. tube = tube || 0.4;
  17112. radialSegments = Math.floor( radialSegments ) || 8;
  17113. tubularSegments = Math.floor( tubularSegments ) || 6;
  17114. arc = arc || Math.PI * 2;
  17115. // buffers
  17116. var indices = [];
  17117. var vertices = [];
  17118. var normals = [];
  17119. var uvs = [];
  17120. // helper variables
  17121. var center = new Vector3();
  17122. var vertex = new Vector3();
  17123. var normal = new Vector3();
  17124. var j, i;
  17125. // generate vertices, normals and uvs
  17126. for ( j = 0; j <= radialSegments; j ++ ) {
  17127. for ( i = 0; i <= tubularSegments; i ++ ) {
  17128. var u = i / tubularSegments * arc;
  17129. var v = j / radialSegments * Math.PI * 2;
  17130. // vertex
  17131. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  17132. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  17133. vertex.z = tube * Math.sin( v );
  17134. vertices.push( vertex.x, vertex.y, vertex.z );
  17135. // normal
  17136. center.x = radius * Math.cos( u );
  17137. center.y = radius * Math.sin( u );
  17138. normal.subVectors( vertex, center ).normalize();
  17139. normals.push( normal.x, normal.y, normal.z );
  17140. // uv
  17141. uvs.push( i / tubularSegments );
  17142. uvs.push( j / radialSegments );
  17143. }
  17144. }
  17145. // generate indices
  17146. for ( j = 1; j <= radialSegments; j ++ ) {
  17147. for ( i = 1; i <= tubularSegments; i ++ ) {
  17148. // indices
  17149. var a = ( tubularSegments + 1 ) * j + i - 1;
  17150. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  17151. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  17152. var d = ( tubularSegments + 1 ) * j + i;
  17153. // faces
  17154. indices.push( a, b, d );
  17155. indices.push( b, c, d );
  17156. }
  17157. }
  17158. // build geometry
  17159. this.setIndex( indices );
  17160. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17161. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17162. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17163. }
  17164. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17165. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  17166. /**
  17167. * @author Mugen87 / https://github.com/Mugen87
  17168. * Port from https://github.com/mapbox/earcut (v2.1.5)
  17169. */
  17170. var Earcut = {
  17171. triangulate: function ( data, holeIndices, dim ) {
  17172. dim = dim || 2;
  17173. var hasHoles = holeIndices && holeIndices.length,
  17174. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  17175. outerNode = linkedList( data, 0, outerLen, dim, true ),
  17176. triangles = [];
  17177. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  17178. var minX, minY, maxX, maxY, x, y, invSize;
  17179. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  17180. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17181. if ( data.length > 80 * dim ) {
  17182. minX = maxX = data[ 0 ];
  17183. minY = maxY = data[ 1 ];
  17184. for ( var i = dim; i < outerLen; i += dim ) {
  17185. x = data[ i ];
  17186. y = data[ i + 1 ];
  17187. if ( x < minX ) minX = x;
  17188. if ( y < minY ) minY = y;
  17189. if ( x > maxX ) maxX = x;
  17190. if ( y > maxY ) maxY = y;
  17191. }
  17192. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17193. invSize = Math.max( maxX - minX, maxY - minY );
  17194. invSize = invSize !== 0 ? 1 / invSize : 0;
  17195. }
  17196. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  17197. return triangles;
  17198. }
  17199. };
  17200. // create a circular doubly linked list from polygon points in the specified winding order
  17201. function linkedList( data, start, end, dim, clockwise ) {
  17202. var i, last;
  17203. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  17204. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17205. } else {
  17206. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17207. }
  17208. if ( last && equals( last, last.next ) ) {
  17209. removeNode( last );
  17210. last = last.next;
  17211. }
  17212. return last;
  17213. }
  17214. // eliminate colinear or duplicate points
  17215. function filterPoints( start, end ) {
  17216. if ( ! start ) return start;
  17217. if ( ! end ) end = start;
  17218. var p = start,
  17219. again;
  17220. do {
  17221. again = false;
  17222. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17223. removeNode( p );
  17224. p = end = p.prev;
  17225. if ( p === p.next ) break;
  17226. again = true;
  17227. } else {
  17228. p = p.next;
  17229. }
  17230. } while ( again || p !== end );
  17231. return end;
  17232. }
  17233. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17234. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17235. if ( ! ear ) return;
  17236. // interlink polygon nodes in z-order
  17237. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17238. var stop = ear,
  17239. prev, next;
  17240. // iterate through ears, slicing them one by one
  17241. while ( ear.prev !== ear.next ) {
  17242. prev = ear.prev;
  17243. next = ear.next;
  17244. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17245. // cut off the triangle
  17246. triangles.push( prev.i / dim );
  17247. triangles.push( ear.i / dim );
  17248. triangles.push( next.i / dim );
  17249. removeNode( ear );
  17250. // skipping the next vertex leads to less sliver triangles
  17251. ear = next.next;
  17252. stop = next.next;
  17253. continue;
  17254. }
  17255. ear = next;
  17256. // if we looped through the whole remaining polygon and can't find any more ears
  17257. if ( ear === stop ) {
  17258. // try filtering points and slicing again
  17259. if ( ! pass ) {
  17260. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17261. // if this didn't work, try curing all small self-intersections locally
  17262. } else if ( pass === 1 ) {
  17263. ear = cureLocalIntersections( ear, triangles, dim );
  17264. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17265. // as a last resort, try splitting the remaining polygon into two
  17266. } else if ( pass === 2 ) {
  17267. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17268. }
  17269. break;
  17270. }
  17271. }
  17272. }
  17273. // check whether a polygon node forms a valid ear with adjacent nodes
  17274. function isEar( ear ) {
  17275. var a = ear.prev,
  17276. b = ear,
  17277. c = ear.next;
  17278. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17279. // now make sure we don't have other points inside the potential ear
  17280. var p = ear.next.next;
  17281. while ( p !== ear.prev ) {
  17282. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17283. area( p.prev, p, p.next ) >= 0 ) return false;
  17284. p = p.next;
  17285. }
  17286. return true;
  17287. }
  17288. function isEarHashed( ear, minX, minY, invSize ) {
  17289. var a = ear.prev,
  17290. b = ear,
  17291. c = ear.next;
  17292. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17293. // triangle bbox; min & max are calculated like this for speed
  17294. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17295. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17296. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17297. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17298. // z-order range for the current triangle bbox;
  17299. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17300. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17301. var p = ear.prevZ,
  17302. n = ear.nextZ;
  17303. // look for points inside the triangle in both directions
  17304. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  17305. if ( p !== ear.prev && p !== ear.next &&
  17306. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17307. area( p.prev, p, p.next ) >= 0 ) return false;
  17308. p = p.prevZ;
  17309. if ( n !== ear.prev && n !== ear.next &&
  17310. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17311. area( n.prev, n, n.next ) >= 0 ) return false;
  17312. n = n.nextZ;
  17313. }
  17314. // look for remaining points in decreasing z-order
  17315. while ( p && p.z >= minZ ) {
  17316. if ( p !== ear.prev && p !== ear.next &&
  17317. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17318. area( p.prev, p, p.next ) >= 0 ) return false;
  17319. p = p.prevZ;
  17320. }
  17321. // look for remaining points in increasing z-order
  17322. while ( n && n.z <= maxZ ) {
  17323. if ( n !== ear.prev && n !== ear.next &&
  17324. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17325. area( n.prev, n, n.next ) >= 0 ) return false;
  17326. n = n.nextZ;
  17327. }
  17328. return true;
  17329. }
  17330. // go through all polygon nodes and cure small local self-intersections
  17331. function cureLocalIntersections( start, triangles, dim ) {
  17332. var p = start;
  17333. do {
  17334. var a = p.prev,
  17335. b = p.next.next;
  17336. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17337. triangles.push( a.i / dim );
  17338. triangles.push( p.i / dim );
  17339. triangles.push( b.i / dim );
  17340. // remove two nodes involved
  17341. removeNode( p );
  17342. removeNode( p.next );
  17343. p = start = b;
  17344. }
  17345. p = p.next;
  17346. } while ( p !== start );
  17347. return p;
  17348. }
  17349. // try splitting polygon into two and triangulate them independently
  17350. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17351. // look for a valid diagonal that divides the polygon into two
  17352. var a = start;
  17353. do {
  17354. var b = a.next.next;
  17355. while ( b !== a.prev ) {
  17356. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17357. // split the polygon in two by the diagonal
  17358. var c = splitPolygon( a, b );
  17359. // filter colinear points around the cuts
  17360. a = filterPoints( a, a.next );
  17361. c = filterPoints( c, c.next );
  17362. // run earcut on each half
  17363. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17364. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17365. return;
  17366. }
  17367. b = b.next;
  17368. }
  17369. a = a.next;
  17370. } while ( a !== start );
  17371. }
  17372. // link every hole into the outer loop, producing a single-ring polygon without holes
  17373. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17374. var queue = [],
  17375. i, len, start, end, list;
  17376. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17377. start = holeIndices[ i ] * dim;
  17378. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17379. list = linkedList( data, start, end, dim, false );
  17380. if ( list === list.next ) list.steiner = true;
  17381. queue.push( getLeftmost( list ) );
  17382. }
  17383. queue.sort( compareX );
  17384. // process holes from left to right
  17385. for ( i = 0; i < queue.length; i ++ ) {
  17386. eliminateHole( queue[ i ], outerNode );
  17387. outerNode = filterPoints( outerNode, outerNode.next );
  17388. }
  17389. return outerNode;
  17390. }
  17391. function compareX( a, b ) {
  17392. return a.x - b.x;
  17393. }
  17394. // find a bridge between vertices that connects hole with an outer ring and and link it
  17395. function eliminateHole( hole, outerNode ) {
  17396. outerNode = findHoleBridge( hole, outerNode );
  17397. if ( outerNode ) {
  17398. var b = splitPolygon( outerNode, hole );
  17399. filterPoints( b, b.next );
  17400. }
  17401. }
  17402. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17403. function findHoleBridge( hole, outerNode ) {
  17404. var p = outerNode,
  17405. hx = hole.x,
  17406. hy = hole.y,
  17407. qx = - Infinity,
  17408. m;
  17409. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17410. // segment's endpoint with lesser x will be potential connection point
  17411. do {
  17412. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17413. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17414. if ( x <= hx && x > qx ) {
  17415. qx = x;
  17416. if ( x === hx ) {
  17417. if ( hy === p.y ) return p;
  17418. if ( hy === p.next.y ) return p.next;
  17419. }
  17420. m = p.x < p.next.x ? p : p.next;
  17421. }
  17422. }
  17423. p = p.next;
  17424. } while ( p !== outerNode );
  17425. if ( ! m ) return null;
  17426. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17427. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17428. // if there are no points found, we have a valid connection;
  17429. // otherwise choose the point of the minimum angle with the ray as connection point
  17430. var stop = m,
  17431. mx = m.x,
  17432. my = m.y,
  17433. tanMin = Infinity,
  17434. tan;
  17435. p = m.next;
  17436. while ( p !== stop ) {
  17437. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17438. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17439. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17440. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17441. m = p;
  17442. tanMin = tan;
  17443. }
  17444. }
  17445. p = p.next;
  17446. }
  17447. return m;
  17448. }
  17449. // interlink polygon nodes in z-order
  17450. function indexCurve( start, minX, minY, invSize ) {
  17451. var p = start;
  17452. do {
  17453. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17454. p.prevZ = p.prev;
  17455. p.nextZ = p.next;
  17456. p = p.next;
  17457. } while ( p !== start );
  17458. p.prevZ.nextZ = null;
  17459. p.prevZ = null;
  17460. sortLinked( p );
  17461. }
  17462. // Simon Tatham's linked list merge sort algorithm
  17463. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17464. function sortLinked( list ) {
  17465. var i, p, q, e, tail, numMerges, pSize, qSize,
  17466. inSize = 1;
  17467. do {
  17468. p = list;
  17469. list = null;
  17470. tail = null;
  17471. numMerges = 0;
  17472. while ( p ) {
  17473. numMerges ++;
  17474. q = p;
  17475. pSize = 0;
  17476. for ( i = 0; i < inSize; i ++ ) {
  17477. pSize ++;
  17478. q = q.nextZ;
  17479. if ( ! q ) break;
  17480. }
  17481. qSize = inSize;
  17482. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17483. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17484. e = p;
  17485. p = p.nextZ;
  17486. pSize --;
  17487. } else {
  17488. e = q;
  17489. q = q.nextZ;
  17490. qSize --;
  17491. }
  17492. if ( tail ) tail.nextZ = e;
  17493. else list = e;
  17494. e.prevZ = tail;
  17495. tail = e;
  17496. }
  17497. p = q;
  17498. }
  17499. tail.nextZ = null;
  17500. inSize *= 2;
  17501. } while ( numMerges > 1 );
  17502. return list;
  17503. }
  17504. // z-order of a point given coords and inverse of the longer side of data bbox
  17505. function zOrder( x, y, minX, minY, invSize ) {
  17506. // coords are transformed into non-negative 15-bit integer range
  17507. x = 32767 * ( x - minX ) * invSize;
  17508. y = 32767 * ( y - minY ) * invSize;
  17509. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17510. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17511. x = ( x | ( x << 2 ) ) & 0x33333333;
  17512. x = ( x | ( x << 1 ) ) & 0x55555555;
  17513. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17514. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17515. y = ( y | ( y << 2 ) ) & 0x33333333;
  17516. y = ( y | ( y << 1 ) ) & 0x55555555;
  17517. return x | ( y << 1 );
  17518. }
  17519. // find the leftmost node of a polygon ring
  17520. function getLeftmost( start ) {
  17521. var p = start,
  17522. leftmost = start;
  17523. do {
  17524. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  17525. p = p.next;
  17526. } while ( p !== start );
  17527. return leftmost;
  17528. }
  17529. // check if a point lies within a convex triangle
  17530. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17531. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17532. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17533. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17534. }
  17535. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17536. function isValidDiagonal( a, b ) {
  17537. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17538. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17539. }
  17540. // signed area of a triangle
  17541. function area( p, q, r ) {
  17542. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17543. }
  17544. // check if two points are equal
  17545. function equals( p1, p2 ) {
  17546. return p1.x === p2.x && p1.y === p2.y;
  17547. }
  17548. // check if two segments intersect
  17549. function intersects( p1, q1, p2, q2 ) {
  17550. if ( ( equals( p1, p2 ) && equals( q1, q2 ) ) ||
  17551. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17552. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17553. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17554. }
  17555. // check if a polygon diagonal intersects any polygon segments
  17556. function intersectsPolygon( a, b ) {
  17557. var p = a;
  17558. do {
  17559. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17560. intersects( p, p.next, a, b ) ) return true;
  17561. p = p.next;
  17562. } while ( p !== a );
  17563. return false;
  17564. }
  17565. // check if a polygon diagonal is locally inside the polygon
  17566. function locallyInside( a, b ) {
  17567. return area( a.prev, a, a.next ) < 0 ?
  17568. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17569. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17570. }
  17571. // check if the middle point of a polygon diagonal is inside the polygon
  17572. function middleInside( a, b ) {
  17573. var p = a,
  17574. inside = false,
  17575. px = ( a.x + b.x ) / 2,
  17576. py = ( a.y + b.y ) / 2;
  17577. do {
  17578. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17579. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  17580. inside = ! inside;
  17581. p = p.next;
  17582. } while ( p !== a );
  17583. return inside;
  17584. }
  17585. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17586. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17587. function splitPolygon( a, b ) {
  17588. var a2 = new Node( a.i, a.x, a.y ),
  17589. b2 = new Node( b.i, b.x, b.y ),
  17590. an = a.next,
  17591. bp = b.prev;
  17592. a.next = b;
  17593. b.prev = a;
  17594. a2.next = an;
  17595. an.prev = a2;
  17596. b2.next = a2;
  17597. a2.prev = b2;
  17598. bp.next = b2;
  17599. b2.prev = bp;
  17600. return b2;
  17601. }
  17602. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17603. function insertNode( i, x, y, last ) {
  17604. var p = new Node( i, x, y );
  17605. if ( ! last ) {
  17606. p.prev = p;
  17607. p.next = p;
  17608. } else {
  17609. p.next = last.next;
  17610. p.prev = last;
  17611. last.next.prev = p;
  17612. last.next = p;
  17613. }
  17614. return p;
  17615. }
  17616. function removeNode( p ) {
  17617. p.next.prev = p.prev;
  17618. p.prev.next = p.next;
  17619. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17620. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17621. }
  17622. function Node( i, x, y ) {
  17623. // vertex index in coordinates array
  17624. this.i = i;
  17625. // vertex coordinates
  17626. this.x = x;
  17627. this.y = y;
  17628. // previous and next vertex nodes in a polygon ring
  17629. this.prev = null;
  17630. this.next = null;
  17631. // z-order curve value
  17632. this.z = null;
  17633. // previous and next nodes in z-order
  17634. this.prevZ = null;
  17635. this.nextZ = null;
  17636. // indicates whether this is a steiner point
  17637. this.steiner = false;
  17638. }
  17639. function signedArea( data, start, end, dim ) {
  17640. var sum = 0;
  17641. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17642. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17643. j = i;
  17644. }
  17645. return sum;
  17646. }
  17647. /**
  17648. * @author zz85 / http://www.lab4games.net/zz85/blog
  17649. */
  17650. var ShapeUtils = {
  17651. // calculate area of the contour polygon
  17652. area: function ( contour ) {
  17653. var n = contour.length;
  17654. var a = 0.0;
  17655. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17656. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17657. }
  17658. return a * 0.5;
  17659. },
  17660. isClockWise: function ( pts ) {
  17661. return ShapeUtils.area( pts ) < 0;
  17662. },
  17663. triangulateShape: function ( contour, holes ) {
  17664. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17665. var holeIndices = []; // array of hole indices
  17666. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17667. removeDupEndPts( contour );
  17668. addContour( vertices, contour );
  17669. //
  17670. var holeIndex = contour.length;
  17671. holes.forEach( removeDupEndPts );
  17672. for ( var i = 0; i < holes.length; i ++ ) {
  17673. holeIndices.push( holeIndex );
  17674. holeIndex += holes[ i ].length;
  17675. addContour( vertices, holes[ i ] );
  17676. }
  17677. //
  17678. var triangles = Earcut.triangulate( vertices, holeIndices );
  17679. //
  17680. for ( var i = 0; i < triangles.length; i += 3 ) {
  17681. faces.push( triangles.slice( i, i + 3 ) );
  17682. }
  17683. return faces;
  17684. }
  17685. };
  17686. function removeDupEndPts( points ) {
  17687. var l = points.length;
  17688. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17689. points.pop();
  17690. }
  17691. }
  17692. function addContour( vertices, contour ) {
  17693. for ( var i = 0; i < contour.length; i ++ ) {
  17694. vertices.push( contour[ i ].x );
  17695. vertices.push( contour[ i ].y );
  17696. }
  17697. }
  17698. /**
  17699. * @author zz85 / http://www.lab4games.net/zz85/blog
  17700. *
  17701. * Creates extruded geometry from a path shape.
  17702. *
  17703. * parameters = {
  17704. *
  17705. * curveSegments: <int>, // number of points on the curves
  17706. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17707. * depth: <float>, // Depth to extrude the shape
  17708. *
  17709. * bevelEnabled: <bool>, // turn on bevel
  17710. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17711. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17712. * bevelOffset: <float>, // how far from shape outline does bevel start
  17713. * bevelSegments: <int>, // number of bevel layers
  17714. *
  17715. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17716. *
  17717. * UVGenerator: <Object> // object that provides UV generator functions
  17718. *
  17719. * }
  17720. */
  17721. // ExtrudeGeometry
  17722. function ExtrudeGeometry( shapes, options ) {
  17723. Geometry.call( this );
  17724. this.type = 'ExtrudeGeometry';
  17725. this.parameters = {
  17726. shapes: shapes,
  17727. options: options
  17728. };
  17729. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17730. this.mergeVertices();
  17731. }
  17732. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17733. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17734. ExtrudeGeometry.prototype.toJSON = function () {
  17735. var data = Geometry.prototype.toJSON.call( this );
  17736. var shapes = this.parameters.shapes;
  17737. var options = this.parameters.options;
  17738. return toJSON( shapes, options, data );
  17739. };
  17740. // ExtrudeBufferGeometry
  17741. function ExtrudeBufferGeometry( shapes, options ) {
  17742. BufferGeometry.call( this );
  17743. this.type = 'ExtrudeBufferGeometry';
  17744. this.parameters = {
  17745. shapes: shapes,
  17746. options: options
  17747. };
  17748. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17749. var scope = this;
  17750. var verticesArray = [];
  17751. var uvArray = [];
  17752. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17753. var shape = shapes[ i ];
  17754. addShape( shape );
  17755. }
  17756. // build geometry
  17757. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17758. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17759. this.computeVertexNormals();
  17760. // functions
  17761. function addShape( shape ) {
  17762. var placeholder = [];
  17763. // options
  17764. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17765. var steps = options.steps !== undefined ? options.steps : 1;
  17766. var depth = options.depth !== undefined ? options.depth : 100;
  17767. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17768. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17769. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17770. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17771. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17772. var extrudePath = options.extrudePath;
  17773. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17774. // deprecated options
  17775. if ( options.amount !== undefined ) {
  17776. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17777. depth = options.amount;
  17778. }
  17779. //
  17780. var extrudePts, extrudeByPath = false;
  17781. var splineTube, binormal, normal, position2;
  17782. if ( extrudePath ) {
  17783. extrudePts = extrudePath.getSpacedPoints( steps );
  17784. extrudeByPath = true;
  17785. bevelEnabled = false; // bevels not supported for path extrusion
  17786. // SETUP TNB variables
  17787. // TODO1 - have a .isClosed in spline?
  17788. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17789. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17790. binormal = new Vector3();
  17791. normal = new Vector3();
  17792. position2 = new Vector3();
  17793. }
  17794. // Safeguards if bevels are not enabled
  17795. if ( ! bevelEnabled ) {
  17796. bevelSegments = 0;
  17797. bevelThickness = 0;
  17798. bevelSize = 0;
  17799. bevelOffset = 0;
  17800. }
  17801. // Variables initialization
  17802. var ahole, h, hl; // looping of holes
  17803. var shapePoints = shape.extractPoints( curveSegments );
  17804. var vertices = shapePoints.shape;
  17805. var holes = shapePoints.holes;
  17806. var reverse = ! ShapeUtils.isClockWise( vertices );
  17807. if ( reverse ) {
  17808. vertices = vertices.reverse();
  17809. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17810. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17811. ahole = holes[ h ];
  17812. if ( ShapeUtils.isClockWise( ahole ) ) {
  17813. holes[ h ] = ahole.reverse();
  17814. }
  17815. }
  17816. }
  17817. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17818. /* Vertices */
  17819. var contour = vertices; // vertices has all points but contour has only points of circumference
  17820. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17821. ahole = holes[ h ];
  17822. vertices = vertices.concat( ahole );
  17823. }
  17824. function scalePt2( pt, vec, size ) {
  17825. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17826. return vec.clone().multiplyScalar( size ).add( pt );
  17827. }
  17828. var b, bs, t, z,
  17829. vert, vlen = vertices.length,
  17830. face, flen = faces.length;
  17831. // Find directions for point movement
  17832. function getBevelVec( inPt, inPrev, inNext ) {
  17833. // computes for inPt the corresponding point inPt' on a new contour
  17834. // shifted by 1 unit (length of normalized vector) to the left
  17835. // if we walk along contour clockwise, this new contour is outside the old one
  17836. //
  17837. // inPt' is the intersection of the two lines parallel to the two
  17838. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17839. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17840. // good reading for geometry algorithms (here: line-line intersection)
  17841. // http://geomalgorithms.com/a05-_intersect-1.html
  17842. var v_prev_x = inPt.x - inPrev.x,
  17843. v_prev_y = inPt.y - inPrev.y;
  17844. var v_next_x = inNext.x - inPt.x,
  17845. v_next_y = inNext.y - inPt.y;
  17846. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17847. // check for collinear edges
  17848. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17849. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17850. // not collinear
  17851. // length of vectors for normalizing
  17852. var v_prev_len = Math.sqrt( v_prev_lensq );
  17853. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17854. // shift adjacent points by unit vectors to the left
  17855. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17856. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17857. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17858. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17859. // scaling factor for v_prev to intersection point
  17860. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17861. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17862. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17863. // vector from inPt to intersection point
  17864. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17865. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17866. // Don't normalize!, otherwise sharp corners become ugly
  17867. // but prevent crazy spikes
  17868. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17869. if ( v_trans_lensq <= 2 ) {
  17870. return new Vector2( v_trans_x, v_trans_y );
  17871. } else {
  17872. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17873. }
  17874. } else {
  17875. // handle special case of collinear edges
  17876. var direction_eq = false; // assumes: opposite
  17877. if ( v_prev_x > Number.EPSILON ) {
  17878. if ( v_next_x > Number.EPSILON ) {
  17879. direction_eq = true;
  17880. }
  17881. } else {
  17882. if ( v_prev_x < - Number.EPSILON ) {
  17883. if ( v_next_x < - Number.EPSILON ) {
  17884. direction_eq = true;
  17885. }
  17886. } else {
  17887. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17888. direction_eq = true;
  17889. }
  17890. }
  17891. }
  17892. if ( direction_eq ) {
  17893. // console.log("Warning: lines are a straight sequence");
  17894. v_trans_x = - v_prev_y;
  17895. v_trans_y = v_prev_x;
  17896. shrink_by = Math.sqrt( v_prev_lensq );
  17897. } else {
  17898. // console.log("Warning: lines are a straight spike");
  17899. v_trans_x = v_prev_x;
  17900. v_trans_y = v_prev_y;
  17901. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17902. }
  17903. }
  17904. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17905. }
  17906. var contourMovements = [];
  17907. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17908. if ( j === il ) j = 0;
  17909. if ( k === il ) k = 0;
  17910. // (j)---(i)---(k)
  17911. // console.log('i,j,k', i, j , k)
  17912. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17913. }
  17914. var holesMovements = [],
  17915. oneHoleMovements, verticesMovements = contourMovements.concat();
  17916. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17917. ahole = holes[ h ];
  17918. oneHoleMovements = [];
  17919. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17920. if ( j === il ) j = 0;
  17921. if ( k === il ) k = 0;
  17922. // (j)---(i)---(k)
  17923. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17924. }
  17925. holesMovements.push( oneHoleMovements );
  17926. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17927. }
  17928. // Loop bevelSegments, 1 for the front, 1 for the back
  17929. for ( b = 0; b < bevelSegments; b ++ ) {
  17930. //for ( b = bevelSegments; b > 0; b -- ) {
  17931. t = b / bevelSegments;
  17932. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17933. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17934. // contract shape
  17935. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17936. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17937. v( vert.x, vert.y, - z );
  17938. }
  17939. // expand holes
  17940. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17941. ahole = holes[ h ];
  17942. oneHoleMovements = holesMovements[ h ];
  17943. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17944. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17945. v( vert.x, vert.y, - z );
  17946. }
  17947. }
  17948. }
  17949. bs = bevelSize + bevelOffset;
  17950. // Back facing vertices
  17951. for ( i = 0; i < vlen; i ++ ) {
  17952. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17953. if ( ! extrudeByPath ) {
  17954. v( vert.x, vert.y, 0 );
  17955. } else {
  17956. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17957. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17958. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17959. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17960. v( position2.x, position2.y, position2.z );
  17961. }
  17962. }
  17963. // Add stepped vertices...
  17964. // Including front facing vertices
  17965. var s;
  17966. for ( s = 1; s <= steps; s ++ ) {
  17967. for ( i = 0; i < vlen; i ++ ) {
  17968. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17969. if ( ! extrudeByPath ) {
  17970. v( vert.x, vert.y, depth / steps * s );
  17971. } else {
  17972. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17973. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17974. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17975. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17976. v( position2.x, position2.y, position2.z );
  17977. }
  17978. }
  17979. }
  17980. // Add bevel segments planes
  17981. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17982. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17983. t = b / bevelSegments;
  17984. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17985. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17986. // contract shape
  17987. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17988. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17989. v( vert.x, vert.y, depth + z );
  17990. }
  17991. // expand holes
  17992. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17993. ahole = holes[ h ];
  17994. oneHoleMovements = holesMovements[ h ];
  17995. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17996. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17997. if ( ! extrudeByPath ) {
  17998. v( vert.x, vert.y, depth + z );
  17999. } else {
  18000. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18001. }
  18002. }
  18003. }
  18004. }
  18005. /* Faces */
  18006. // Top and bottom faces
  18007. buildLidFaces();
  18008. // Sides faces
  18009. buildSideFaces();
  18010. ///// Internal functions
  18011. function buildLidFaces() {
  18012. var start = verticesArray.length / 3;
  18013. if ( bevelEnabled ) {
  18014. var layer = 0; // steps + 1
  18015. var offset = vlen * layer;
  18016. // Bottom faces
  18017. for ( i = 0; i < flen; i ++ ) {
  18018. face = faces[ i ];
  18019. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18020. }
  18021. layer = steps + bevelSegments * 2;
  18022. offset = vlen * layer;
  18023. // Top faces
  18024. for ( i = 0; i < flen; i ++ ) {
  18025. face = faces[ i ];
  18026. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18027. }
  18028. } else {
  18029. // Bottom faces
  18030. for ( i = 0; i < flen; i ++ ) {
  18031. face = faces[ i ];
  18032. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18033. }
  18034. // Top faces
  18035. for ( i = 0; i < flen; i ++ ) {
  18036. face = faces[ i ];
  18037. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18038. }
  18039. }
  18040. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18041. }
  18042. // Create faces for the z-sides of the shape
  18043. function buildSideFaces() {
  18044. var start = verticesArray.length / 3;
  18045. var layeroffset = 0;
  18046. sidewalls( contour, layeroffset );
  18047. layeroffset += contour.length;
  18048. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18049. ahole = holes[ h ];
  18050. sidewalls( ahole, layeroffset );
  18051. //, true
  18052. layeroffset += ahole.length;
  18053. }
  18054. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18055. }
  18056. function sidewalls( contour, layeroffset ) {
  18057. var j, k;
  18058. i = contour.length;
  18059. while ( -- i >= 0 ) {
  18060. j = i;
  18061. k = i - 1;
  18062. if ( k < 0 ) k = contour.length - 1;
  18063. //console.log('b', i,j, i-1, k,vertices.length);
  18064. var s = 0,
  18065. sl = steps + bevelSegments * 2;
  18066. for ( s = 0; s < sl; s ++ ) {
  18067. var slen1 = vlen * s;
  18068. var slen2 = vlen * ( s + 1 );
  18069. var a = layeroffset + j + slen1,
  18070. b = layeroffset + k + slen1,
  18071. c = layeroffset + k + slen2,
  18072. d = layeroffset + j + slen2;
  18073. f4( a, b, c, d );
  18074. }
  18075. }
  18076. }
  18077. function v( x, y, z ) {
  18078. placeholder.push( x );
  18079. placeholder.push( y );
  18080. placeholder.push( z );
  18081. }
  18082. function f3( a, b, c ) {
  18083. addVertex( a );
  18084. addVertex( b );
  18085. addVertex( c );
  18086. var nextIndex = verticesArray.length / 3;
  18087. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18088. addUV( uvs[ 0 ] );
  18089. addUV( uvs[ 1 ] );
  18090. addUV( uvs[ 2 ] );
  18091. }
  18092. function f4( a, b, c, d ) {
  18093. addVertex( a );
  18094. addVertex( b );
  18095. addVertex( d );
  18096. addVertex( b );
  18097. addVertex( c );
  18098. addVertex( d );
  18099. var nextIndex = verticesArray.length / 3;
  18100. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18101. addUV( uvs[ 0 ] );
  18102. addUV( uvs[ 1 ] );
  18103. addUV( uvs[ 3 ] );
  18104. addUV( uvs[ 1 ] );
  18105. addUV( uvs[ 2 ] );
  18106. addUV( uvs[ 3 ] );
  18107. }
  18108. function addVertex( index ) {
  18109. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18110. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18111. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18112. }
  18113. function addUV( vector2 ) {
  18114. uvArray.push( vector2.x );
  18115. uvArray.push( vector2.y );
  18116. }
  18117. }
  18118. }
  18119. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18120. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  18121. ExtrudeBufferGeometry.prototype.toJSON = function () {
  18122. var data = BufferGeometry.prototype.toJSON.call( this );
  18123. var shapes = this.parameters.shapes;
  18124. var options = this.parameters.options;
  18125. return toJSON( shapes, options, data );
  18126. };
  18127. //
  18128. var WorldUVGenerator = {
  18129. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18130. var a_x = vertices[ indexA * 3 ];
  18131. var a_y = vertices[ indexA * 3 + 1 ];
  18132. var b_x = vertices[ indexB * 3 ];
  18133. var b_y = vertices[ indexB * 3 + 1 ];
  18134. var c_x = vertices[ indexC * 3 ];
  18135. var c_y = vertices[ indexC * 3 + 1 ];
  18136. return [
  18137. new Vector2( a_x, a_y ),
  18138. new Vector2( b_x, b_y ),
  18139. new Vector2( c_x, c_y )
  18140. ];
  18141. },
  18142. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  18143. var a_x = vertices[ indexA * 3 ];
  18144. var a_y = vertices[ indexA * 3 + 1 ];
  18145. var a_z = vertices[ indexA * 3 + 2 ];
  18146. var b_x = vertices[ indexB * 3 ];
  18147. var b_y = vertices[ indexB * 3 + 1 ];
  18148. var b_z = vertices[ indexB * 3 + 2 ];
  18149. var c_x = vertices[ indexC * 3 ];
  18150. var c_y = vertices[ indexC * 3 + 1 ];
  18151. var c_z = vertices[ indexC * 3 + 2 ];
  18152. var d_x = vertices[ indexD * 3 ];
  18153. var d_y = vertices[ indexD * 3 + 1 ];
  18154. var d_z = vertices[ indexD * 3 + 2 ];
  18155. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  18156. return [
  18157. new Vector2( a_x, 1 - a_z ),
  18158. new Vector2( b_x, 1 - b_z ),
  18159. new Vector2( c_x, 1 - c_z ),
  18160. new Vector2( d_x, 1 - d_z )
  18161. ];
  18162. } else {
  18163. return [
  18164. new Vector2( a_y, 1 - a_z ),
  18165. new Vector2( b_y, 1 - b_z ),
  18166. new Vector2( c_y, 1 - c_z ),
  18167. new Vector2( d_y, 1 - d_z )
  18168. ];
  18169. }
  18170. }
  18171. };
  18172. function toJSON( shapes, options, data ) {
  18173. //
  18174. data.shapes = [];
  18175. if ( Array.isArray( shapes ) ) {
  18176. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18177. var shape = shapes[ i ];
  18178. data.shapes.push( shape.uuid );
  18179. }
  18180. } else {
  18181. data.shapes.push( shapes.uuid );
  18182. }
  18183. //
  18184. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18185. return data;
  18186. }
  18187. /**
  18188. * @author zz85 / http://www.lab4games.net/zz85/blog
  18189. * @author alteredq / http://alteredqualia.com/
  18190. *
  18191. * Text = 3D Text
  18192. *
  18193. * parameters = {
  18194. * font: <THREE.Font>, // font
  18195. *
  18196. * size: <float>, // size of the text
  18197. * height: <float>, // thickness to extrude text
  18198. * curveSegments: <int>, // number of points on the curves
  18199. *
  18200. * bevelEnabled: <bool>, // turn on bevel
  18201. * bevelThickness: <float>, // how deep into text bevel goes
  18202. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18203. * bevelOffset: <float> // how far from text outline does bevel start
  18204. * }
  18205. */
  18206. // TextGeometry
  18207. function TextGeometry( text, parameters ) {
  18208. Geometry.call( this );
  18209. this.type = 'TextGeometry';
  18210. this.parameters = {
  18211. text: text,
  18212. parameters: parameters
  18213. };
  18214. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  18215. this.mergeVertices();
  18216. }
  18217. TextGeometry.prototype = Object.create( Geometry.prototype );
  18218. TextGeometry.prototype.constructor = TextGeometry;
  18219. // TextBufferGeometry
  18220. function TextBufferGeometry( text, parameters ) {
  18221. parameters = parameters || {};
  18222. var font = parameters.font;
  18223. if ( ! ( font && font.isFont ) ) {
  18224. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18225. return new Geometry();
  18226. }
  18227. var shapes = font.generateShapes( text, parameters.size );
  18228. // translate parameters to ExtrudeGeometry API
  18229. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18230. // defaults
  18231. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18232. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18233. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18234. ExtrudeBufferGeometry.call( this, shapes, parameters );
  18235. this.type = 'TextBufferGeometry';
  18236. }
  18237. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  18238. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  18239. /**
  18240. * @author mrdoob / http://mrdoob.com/
  18241. * @author benaadams / https://twitter.com/ben_a_adams
  18242. * @author Mugen87 / https://github.com/Mugen87
  18243. */
  18244. // SphereGeometry
  18245. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18246. Geometry.call( this );
  18247. this.type = 'SphereGeometry';
  18248. this.parameters = {
  18249. radius: radius,
  18250. widthSegments: widthSegments,
  18251. heightSegments: heightSegments,
  18252. phiStart: phiStart,
  18253. phiLength: phiLength,
  18254. thetaStart: thetaStart,
  18255. thetaLength: thetaLength
  18256. };
  18257. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  18258. this.mergeVertices();
  18259. }
  18260. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18261. SphereGeometry.prototype.constructor = SphereGeometry;
  18262. // SphereBufferGeometry
  18263. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18264. BufferGeometry.call( this );
  18265. this.type = 'SphereBufferGeometry';
  18266. this.parameters = {
  18267. radius: radius,
  18268. widthSegments: widthSegments,
  18269. heightSegments: heightSegments,
  18270. phiStart: phiStart,
  18271. phiLength: phiLength,
  18272. thetaStart: thetaStart,
  18273. thetaLength: thetaLength
  18274. };
  18275. radius = radius || 1;
  18276. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18277. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18278. phiStart = phiStart !== undefined ? phiStart : 0;
  18279. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18280. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18281. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18282. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18283. var ix, iy;
  18284. var index = 0;
  18285. var grid = [];
  18286. var vertex = new Vector3();
  18287. var normal = new Vector3();
  18288. // buffers
  18289. var indices = [];
  18290. var vertices = [];
  18291. var normals = [];
  18292. var uvs = [];
  18293. // generate vertices, normals and uvs
  18294. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18295. var verticesRow = [];
  18296. var v = iy / heightSegments;
  18297. // special case for the poles
  18298. var uOffset = 0;
  18299. if ( iy == 0 && thetaStart == 0 ) {
  18300. uOffset = 0.5 / widthSegments;
  18301. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18302. uOffset = - 0.5 / widthSegments;
  18303. }
  18304. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18305. var u = ix / widthSegments;
  18306. // vertex
  18307. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18308. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18309. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18310. vertices.push( vertex.x, vertex.y, vertex.z );
  18311. // normal
  18312. normal.copy( vertex ).normalize();
  18313. normals.push( normal.x, normal.y, normal.z );
  18314. // uv
  18315. uvs.push( u + uOffset, 1 - v );
  18316. verticesRow.push( index ++ );
  18317. }
  18318. grid.push( verticesRow );
  18319. }
  18320. // indices
  18321. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18322. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18323. var a = grid[ iy ][ ix + 1 ];
  18324. var b = grid[ iy ][ ix ];
  18325. var c = grid[ iy + 1 ][ ix ];
  18326. var d = grid[ iy + 1 ][ ix + 1 ];
  18327. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18328. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18329. }
  18330. }
  18331. // build geometry
  18332. this.setIndex( indices );
  18333. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18334. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18335. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18336. }
  18337. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18338. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18339. /**
  18340. * @author Kaleb Murphy
  18341. * @author Mugen87 / https://github.com/Mugen87
  18342. */
  18343. // RingGeometry
  18344. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18345. Geometry.call( this );
  18346. this.type = 'RingGeometry';
  18347. this.parameters = {
  18348. innerRadius: innerRadius,
  18349. outerRadius: outerRadius,
  18350. thetaSegments: thetaSegments,
  18351. phiSegments: phiSegments,
  18352. thetaStart: thetaStart,
  18353. thetaLength: thetaLength
  18354. };
  18355. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18356. this.mergeVertices();
  18357. }
  18358. RingGeometry.prototype = Object.create( Geometry.prototype );
  18359. RingGeometry.prototype.constructor = RingGeometry;
  18360. // RingBufferGeometry
  18361. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18362. BufferGeometry.call( this );
  18363. this.type = 'RingBufferGeometry';
  18364. this.parameters = {
  18365. innerRadius: innerRadius,
  18366. outerRadius: outerRadius,
  18367. thetaSegments: thetaSegments,
  18368. phiSegments: phiSegments,
  18369. thetaStart: thetaStart,
  18370. thetaLength: thetaLength
  18371. };
  18372. innerRadius = innerRadius || 0.5;
  18373. outerRadius = outerRadius || 1;
  18374. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18375. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18376. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18377. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18378. // buffers
  18379. var indices = [];
  18380. var vertices = [];
  18381. var normals = [];
  18382. var uvs = [];
  18383. // some helper variables
  18384. var segment;
  18385. var radius = innerRadius;
  18386. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18387. var vertex = new Vector3();
  18388. var uv = new Vector2();
  18389. var j, i;
  18390. // generate vertices, normals and uvs
  18391. for ( j = 0; j <= phiSegments; j ++ ) {
  18392. for ( i = 0; i <= thetaSegments; i ++ ) {
  18393. // values are generate from the inside of the ring to the outside
  18394. segment = thetaStart + i / thetaSegments * thetaLength;
  18395. // vertex
  18396. vertex.x = radius * Math.cos( segment );
  18397. vertex.y = radius * Math.sin( segment );
  18398. vertices.push( vertex.x, vertex.y, vertex.z );
  18399. // normal
  18400. normals.push( 0, 0, 1 );
  18401. // uv
  18402. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18403. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18404. uvs.push( uv.x, uv.y );
  18405. }
  18406. // increase the radius for next row of vertices
  18407. radius += radiusStep;
  18408. }
  18409. // indices
  18410. for ( j = 0; j < phiSegments; j ++ ) {
  18411. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18412. for ( i = 0; i < thetaSegments; i ++ ) {
  18413. segment = i + thetaSegmentLevel;
  18414. var a = segment;
  18415. var b = segment + thetaSegments + 1;
  18416. var c = segment + thetaSegments + 2;
  18417. var d = segment + 1;
  18418. // faces
  18419. indices.push( a, b, d );
  18420. indices.push( b, c, d );
  18421. }
  18422. }
  18423. // build geometry
  18424. this.setIndex( indices );
  18425. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18426. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18427. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18428. }
  18429. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18430. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18431. /**
  18432. * @author zz85 / https://github.com/zz85
  18433. * @author bhouston / http://clara.io
  18434. * @author Mugen87 / https://github.com/Mugen87
  18435. */
  18436. // LatheGeometry
  18437. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18438. Geometry.call( this );
  18439. this.type = 'LatheGeometry';
  18440. this.parameters = {
  18441. points: points,
  18442. segments: segments,
  18443. phiStart: phiStart,
  18444. phiLength: phiLength
  18445. };
  18446. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18447. this.mergeVertices();
  18448. }
  18449. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18450. LatheGeometry.prototype.constructor = LatheGeometry;
  18451. // LatheBufferGeometry
  18452. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18453. BufferGeometry.call( this );
  18454. this.type = 'LatheBufferGeometry';
  18455. this.parameters = {
  18456. points: points,
  18457. segments: segments,
  18458. phiStart: phiStart,
  18459. phiLength: phiLength
  18460. };
  18461. segments = Math.floor( segments ) || 12;
  18462. phiStart = phiStart || 0;
  18463. phiLength = phiLength || Math.PI * 2;
  18464. // clamp phiLength so it's in range of [ 0, 2PI ]
  18465. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18466. // buffers
  18467. var indices = [];
  18468. var vertices = [];
  18469. var uvs = [];
  18470. // helper variables
  18471. var base;
  18472. var inverseSegments = 1.0 / segments;
  18473. var vertex = new Vector3();
  18474. var uv = new Vector2();
  18475. var i, j;
  18476. // generate vertices and uvs
  18477. for ( i = 0; i <= segments; i ++ ) {
  18478. var phi = phiStart + i * inverseSegments * phiLength;
  18479. var sin = Math.sin( phi );
  18480. var cos = Math.cos( phi );
  18481. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18482. // vertex
  18483. vertex.x = points[ j ].x * sin;
  18484. vertex.y = points[ j ].y;
  18485. vertex.z = points[ j ].x * cos;
  18486. vertices.push( vertex.x, vertex.y, vertex.z );
  18487. // uv
  18488. uv.x = i / segments;
  18489. uv.y = j / ( points.length - 1 );
  18490. uvs.push( uv.x, uv.y );
  18491. }
  18492. }
  18493. // indices
  18494. for ( i = 0; i < segments; i ++ ) {
  18495. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18496. base = j + i * points.length;
  18497. var a = base;
  18498. var b = base + points.length;
  18499. var c = base + points.length + 1;
  18500. var d = base + 1;
  18501. // faces
  18502. indices.push( a, b, d );
  18503. indices.push( b, c, d );
  18504. }
  18505. }
  18506. // build geometry
  18507. this.setIndex( indices );
  18508. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18509. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18510. // generate normals
  18511. this.computeVertexNormals();
  18512. // if the geometry is closed, we need to average the normals along the seam.
  18513. // because the corresponding vertices are identical (but still have different UVs).
  18514. if ( phiLength === Math.PI * 2 ) {
  18515. var normals = this.attributes.normal.array;
  18516. var n1 = new Vector3();
  18517. var n2 = new Vector3();
  18518. var n = new Vector3();
  18519. // this is the buffer offset for the last line of vertices
  18520. base = segments * points.length * 3;
  18521. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18522. // select the normal of the vertex in the first line
  18523. n1.x = normals[ j + 0 ];
  18524. n1.y = normals[ j + 1 ];
  18525. n1.z = normals[ j + 2 ];
  18526. // select the normal of the vertex in the last line
  18527. n2.x = normals[ base + j + 0 ];
  18528. n2.y = normals[ base + j + 1 ];
  18529. n2.z = normals[ base + j + 2 ];
  18530. // average normals
  18531. n.addVectors( n1, n2 ).normalize();
  18532. // assign the new values to both normals
  18533. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18534. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18535. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18536. }
  18537. }
  18538. }
  18539. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18540. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18541. /**
  18542. * @author jonobr1 / http://jonobr1.com
  18543. * @author Mugen87 / https://github.com/Mugen87
  18544. */
  18545. // ShapeGeometry
  18546. function ShapeGeometry( shapes, curveSegments ) {
  18547. Geometry.call( this );
  18548. this.type = 'ShapeGeometry';
  18549. if ( typeof curveSegments === 'object' ) {
  18550. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18551. curveSegments = curveSegments.curveSegments;
  18552. }
  18553. this.parameters = {
  18554. shapes: shapes,
  18555. curveSegments: curveSegments
  18556. };
  18557. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18558. this.mergeVertices();
  18559. }
  18560. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18561. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18562. ShapeGeometry.prototype.toJSON = function () {
  18563. var data = Geometry.prototype.toJSON.call( this );
  18564. var shapes = this.parameters.shapes;
  18565. return toJSON$1( shapes, data );
  18566. };
  18567. // ShapeBufferGeometry
  18568. function ShapeBufferGeometry( shapes, curveSegments ) {
  18569. BufferGeometry.call( this );
  18570. this.type = 'ShapeBufferGeometry';
  18571. this.parameters = {
  18572. shapes: shapes,
  18573. curveSegments: curveSegments
  18574. };
  18575. curveSegments = curveSegments || 12;
  18576. // buffers
  18577. var indices = [];
  18578. var vertices = [];
  18579. var normals = [];
  18580. var uvs = [];
  18581. // helper variables
  18582. var groupStart = 0;
  18583. var groupCount = 0;
  18584. // allow single and array values for "shapes" parameter
  18585. if ( Array.isArray( shapes ) === false ) {
  18586. addShape( shapes );
  18587. } else {
  18588. for ( var i = 0; i < shapes.length; i ++ ) {
  18589. addShape( shapes[ i ] );
  18590. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18591. groupStart += groupCount;
  18592. groupCount = 0;
  18593. }
  18594. }
  18595. // build geometry
  18596. this.setIndex( indices );
  18597. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18598. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18599. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18600. // helper functions
  18601. function addShape( shape ) {
  18602. var i, l, shapeHole;
  18603. var indexOffset = vertices.length / 3;
  18604. var points = shape.extractPoints( curveSegments );
  18605. var shapeVertices = points.shape;
  18606. var shapeHoles = points.holes;
  18607. // check direction of vertices
  18608. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18609. shapeVertices = shapeVertices.reverse();
  18610. }
  18611. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18612. shapeHole = shapeHoles[ i ];
  18613. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18614. shapeHoles[ i ] = shapeHole.reverse();
  18615. }
  18616. }
  18617. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18618. // join vertices of inner and outer paths to a single array
  18619. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18620. shapeHole = shapeHoles[ i ];
  18621. shapeVertices = shapeVertices.concat( shapeHole );
  18622. }
  18623. // vertices, normals, uvs
  18624. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18625. var vertex = shapeVertices[ i ];
  18626. vertices.push( vertex.x, vertex.y, 0 );
  18627. normals.push( 0, 0, 1 );
  18628. uvs.push( vertex.x, vertex.y ); // world uvs
  18629. }
  18630. // incides
  18631. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18632. var face = faces[ i ];
  18633. var a = face[ 0 ] + indexOffset;
  18634. var b = face[ 1 ] + indexOffset;
  18635. var c = face[ 2 ] + indexOffset;
  18636. indices.push( a, b, c );
  18637. groupCount += 3;
  18638. }
  18639. }
  18640. }
  18641. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18642. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18643. ShapeBufferGeometry.prototype.toJSON = function () {
  18644. var data = BufferGeometry.prototype.toJSON.call( this );
  18645. var shapes = this.parameters.shapes;
  18646. return toJSON$1( shapes, data );
  18647. };
  18648. //
  18649. function toJSON$1( shapes, data ) {
  18650. data.shapes = [];
  18651. if ( Array.isArray( shapes ) ) {
  18652. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18653. var shape = shapes[ i ];
  18654. data.shapes.push( shape.uuid );
  18655. }
  18656. } else {
  18657. data.shapes.push( shapes.uuid );
  18658. }
  18659. return data;
  18660. }
  18661. /**
  18662. * @author WestLangley / http://github.com/WestLangley
  18663. * @author Mugen87 / https://github.com/Mugen87
  18664. */
  18665. function EdgesGeometry( geometry, thresholdAngle ) {
  18666. BufferGeometry.call( this );
  18667. this.type = 'EdgesGeometry';
  18668. this.parameters = {
  18669. thresholdAngle: thresholdAngle
  18670. };
  18671. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18672. // buffer
  18673. var vertices = [];
  18674. // helper variables
  18675. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18676. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18677. var key, keys = [ 'a', 'b', 'c' ];
  18678. // prepare source geometry
  18679. var geometry2;
  18680. if ( geometry.isBufferGeometry ) {
  18681. geometry2 = new Geometry();
  18682. geometry2.fromBufferGeometry( geometry );
  18683. } else {
  18684. geometry2 = geometry.clone();
  18685. }
  18686. geometry2.mergeVertices();
  18687. geometry2.computeFaceNormals();
  18688. var sourceVertices = geometry2.vertices;
  18689. var faces = geometry2.faces;
  18690. // now create a data structure where each entry represents an edge with its adjoining faces
  18691. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18692. var face = faces[ i ];
  18693. for ( var j = 0; j < 3; j ++ ) {
  18694. edge1 = face[ keys[ j ] ];
  18695. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18696. edge[ 0 ] = Math.min( edge1, edge2 );
  18697. edge[ 1 ] = Math.max( edge1, edge2 );
  18698. key = edge[ 0 ] + ',' + edge[ 1 ];
  18699. if ( edges[ key ] === undefined ) {
  18700. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18701. } else {
  18702. edges[ key ].face2 = i;
  18703. }
  18704. }
  18705. }
  18706. // generate vertices
  18707. for ( key in edges ) {
  18708. var e = edges[ key ];
  18709. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18710. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18711. var vertex = sourceVertices[ e.index1 ];
  18712. vertices.push( vertex.x, vertex.y, vertex.z );
  18713. vertex = sourceVertices[ e.index2 ];
  18714. vertices.push( vertex.x, vertex.y, vertex.z );
  18715. }
  18716. }
  18717. // build geometry
  18718. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18719. }
  18720. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18721. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18722. /**
  18723. * @author mrdoob / http://mrdoob.com/
  18724. * @author Mugen87 / https://github.com/Mugen87
  18725. */
  18726. // CylinderGeometry
  18727. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18728. Geometry.call( this );
  18729. this.type = 'CylinderGeometry';
  18730. this.parameters = {
  18731. radiusTop: radiusTop,
  18732. radiusBottom: radiusBottom,
  18733. height: height,
  18734. radialSegments: radialSegments,
  18735. heightSegments: heightSegments,
  18736. openEnded: openEnded,
  18737. thetaStart: thetaStart,
  18738. thetaLength: thetaLength
  18739. };
  18740. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18741. this.mergeVertices();
  18742. }
  18743. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18744. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18745. // CylinderBufferGeometry
  18746. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18747. BufferGeometry.call( this );
  18748. this.type = 'CylinderBufferGeometry';
  18749. this.parameters = {
  18750. radiusTop: radiusTop,
  18751. radiusBottom: radiusBottom,
  18752. height: height,
  18753. radialSegments: radialSegments,
  18754. heightSegments: heightSegments,
  18755. openEnded: openEnded,
  18756. thetaStart: thetaStart,
  18757. thetaLength: thetaLength
  18758. };
  18759. var scope = this;
  18760. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18761. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18762. height = height || 1;
  18763. radialSegments = Math.floor( radialSegments ) || 8;
  18764. heightSegments = Math.floor( heightSegments ) || 1;
  18765. openEnded = openEnded !== undefined ? openEnded : false;
  18766. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18767. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18768. // buffers
  18769. var indices = [];
  18770. var vertices = [];
  18771. var normals = [];
  18772. var uvs = [];
  18773. // helper variables
  18774. var index = 0;
  18775. var indexArray = [];
  18776. var halfHeight = height / 2;
  18777. var groupStart = 0;
  18778. // generate geometry
  18779. generateTorso();
  18780. if ( openEnded === false ) {
  18781. if ( radiusTop > 0 ) generateCap( true );
  18782. if ( radiusBottom > 0 ) generateCap( false );
  18783. }
  18784. // build geometry
  18785. this.setIndex( indices );
  18786. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18787. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18788. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18789. function generateTorso() {
  18790. var x, y;
  18791. var normal = new Vector3();
  18792. var vertex = new Vector3();
  18793. var groupCount = 0;
  18794. // this will be used to calculate the normal
  18795. var slope = ( radiusBottom - radiusTop ) / height;
  18796. // generate vertices, normals and uvs
  18797. for ( y = 0; y <= heightSegments; y ++ ) {
  18798. var indexRow = [];
  18799. var v = y / heightSegments;
  18800. // calculate the radius of the current row
  18801. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18802. for ( x = 0; x <= radialSegments; x ++ ) {
  18803. var u = x / radialSegments;
  18804. var theta = u * thetaLength + thetaStart;
  18805. var sinTheta = Math.sin( theta );
  18806. var cosTheta = Math.cos( theta );
  18807. // vertex
  18808. vertex.x = radius * sinTheta;
  18809. vertex.y = - v * height + halfHeight;
  18810. vertex.z = radius * cosTheta;
  18811. vertices.push( vertex.x, vertex.y, vertex.z );
  18812. // normal
  18813. normal.set( sinTheta, slope, cosTheta ).normalize();
  18814. normals.push( normal.x, normal.y, normal.z );
  18815. // uv
  18816. uvs.push( u, 1 - v );
  18817. // save index of vertex in respective row
  18818. indexRow.push( index ++ );
  18819. }
  18820. // now save vertices of the row in our index array
  18821. indexArray.push( indexRow );
  18822. }
  18823. // generate indices
  18824. for ( x = 0; x < radialSegments; x ++ ) {
  18825. for ( y = 0; y < heightSegments; y ++ ) {
  18826. // we use the index array to access the correct indices
  18827. var a = indexArray[ y ][ x ];
  18828. var b = indexArray[ y + 1 ][ x ];
  18829. var c = indexArray[ y + 1 ][ x + 1 ];
  18830. var d = indexArray[ y ][ x + 1 ];
  18831. // faces
  18832. indices.push( a, b, d );
  18833. indices.push( b, c, d );
  18834. // update group counter
  18835. groupCount += 6;
  18836. }
  18837. }
  18838. // add a group to the geometry. this will ensure multi material support
  18839. scope.addGroup( groupStart, groupCount, 0 );
  18840. // calculate new start value for groups
  18841. groupStart += groupCount;
  18842. }
  18843. function generateCap( top ) {
  18844. var x, centerIndexStart, centerIndexEnd;
  18845. var uv = new Vector2();
  18846. var vertex = new Vector3();
  18847. var groupCount = 0;
  18848. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18849. var sign = ( top === true ) ? 1 : - 1;
  18850. // save the index of the first center vertex
  18851. centerIndexStart = index;
  18852. // first we generate the center vertex data of the cap.
  18853. // because the geometry needs one set of uvs per face,
  18854. // we must generate a center vertex per face/segment
  18855. for ( x = 1; x <= radialSegments; x ++ ) {
  18856. // vertex
  18857. vertices.push( 0, halfHeight * sign, 0 );
  18858. // normal
  18859. normals.push( 0, sign, 0 );
  18860. // uv
  18861. uvs.push( 0.5, 0.5 );
  18862. // increase index
  18863. index ++;
  18864. }
  18865. // save the index of the last center vertex
  18866. centerIndexEnd = index;
  18867. // now we generate the surrounding vertices, normals and uvs
  18868. for ( x = 0; x <= radialSegments; x ++ ) {
  18869. var u = x / radialSegments;
  18870. var theta = u * thetaLength + thetaStart;
  18871. var cosTheta = Math.cos( theta );
  18872. var sinTheta = Math.sin( theta );
  18873. // vertex
  18874. vertex.x = radius * sinTheta;
  18875. vertex.y = halfHeight * sign;
  18876. vertex.z = radius * cosTheta;
  18877. vertices.push( vertex.x, vertex.y, vertex.z );
  18878. // normal
  18879. normals.push( 0, sign, 0 );
  18880. // uv
  18881. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18882. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18883. uvs.push( uv.x, uv.y );
  18884. // increase index
  18885. index ++;
  18886. }
  18887. // generate indices
  18888. for ( x = 0; x < radialSegments; x ++ ) {
  18889. var c = centerIndexStart + x;
  18890. var i = centerIndexEnd + x;
  18891. if ( top === true ) {
  18892. // face top
  18893. indices.push( i, i + 1, c );
  18894. } else {
  18895. // face bottom
  18896. indices.push( i + 1, i, c );
  18897. }
  18898. groupCount += 3;
  18899. }
  18900. // add a group to the geometry. this will ensure multi material support
  18901. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18902. // calculate new start value for groups
  18903. groupStart += groupCount;
  18904. }
  18905. }
  18906. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18907. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18908. /**
  18909. * @author abelnation / http://github.com/abelnation
  18910. */
  18911. // ConeGeometry
  18912. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18913. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18914. this.type = 'ConeGeometry';
  18915. this.parameters = {
  18916. radius: radius,
  18917. height: height,
  18918. radialSegments: radialSegments,
  18919. heightSegments: heightSegments,
  18920. openEnded: openEnded,
  18921. thetaStart: thetaStart,
  18922. thetaLength: thetaLength
  18923. };
  18924. }
  18925. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18926. ConeGeometry.prototype.constructor = ConeGeometry;
  18927. // ConeBufferGeometry
  18928. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18929. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18930. this.type = 'ConeBufferGeometry';
  18931. this.parameters = {
  18932. radius: radius,
  18933. height: height,
  18934. radialSegments: radialSegments,
  18935. heightSegments: heightSegments,
  18936. openEnded: openEnded,
  18937. thetaStart: thetaStart,
  18938. thetaLength: thetaLength
  18939. };
  18940. }
  18941. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18942. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18943. /**
  18944. * @author benaadams / https://twitter.com/ben_a_adams
  18945. * @author Mugen87 / https://github.com/Mugen87
  18946. * @author hughes
  18947. */
  18948. // CircleGeometry
  18949. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18950. Geometry.call( this );
  18951. this.type = 'CircleGeometry';
  18952. this.parameters = {
  18953. radius: radius,
  18954. segments: segments,
  18955. thetaStart: thetaStart,
  18956. thetaLength: thetaLength
  18957. };
  18958. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18959. this.mergeVertices();
  18960. }
  18961. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18962. CircleGeometry.prototype.constructor = CircleGeometry;
  18963. // CircleBufferGeometry
  18964. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18965. BufferGeometry.call( this );
  18966. this.type = 'CircleBufferGeometry';
  18967. this.parameters = {
  18968. radius: radius,
  18969. segments: segments,
  18970. thetaStart: thetaStart,
  18971. thetaLength: thetaLength
  18972. };
  18973. radius = radius || 1;
  18974. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18975. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18976. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18977. // buffers
  18978. var indices = [];
  18979. var vertices = [];
  18980. var normals = [];
  18981. var uvs = [];
  18982. // helper variables
  18983. var i, s;
  18984. var vertex = new Vector3();
  18985. var uv = new Vector2();
  18986. // center point
  18987. vertices.push( 0, 0, 0 );
  18988. normals.push( 0, 0, 1 );
  18989. uvs.push( 0.5, 0.5 );
  18990. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18991. var segment = thetaStart + s / segments * thetaLength;
  18992. // vertex
  18993. vertex.x = radius * Math.cos( segment );
  18994. vertex.y = radius * Math.sin( segment );
  18995. vertices.push( vertex.x, vertex.y, vertex.z );
  18996. // normal
  18997. normals.push( 0, 0, 1 );
  18998. // uvs
  18999. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19000. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19001. uvs.push( uv.x, uv.y );
  19002. }
  19003. // indices
  19004. for ( i = 1; i <= segments; i ++ ) {
  19005. indices.push( i, i + 1, 0 );
  19006. }
  19007. // build geometry
  19008. this.setIndex( indices );
  19009. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19010. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19011. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19012. }
  19013. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19014. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19015. var Geometries = /*#__PURE__*/Object.freeze({
  19016. WireframeGeometry: WireframeGeometry,
  19017. ParametricGeometry: ParametricGeometry,
  19018. ParametricBufferGeometry: ParametricBufferGeometry,
  19019. TetrahedronGeometry: TetrahedronGeometry,
  19020. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19021. OctahedronGeometry: OctahedronGeometry,
  19022. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19023. IcosahedronGeometry: IcosahedronGeometry,
  19024. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19025. DodecahedronGeometry: DodecahedronGeometry,
  19026. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19027. PolyhedronGeometry: PolyhedronGeometry,
  19028. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19029. TubeGeometry: TubeGeometry,
  19030. TubeBufferGeometry: TubeBufferGeometry,
  19031. TorusKnotGeometry: TorusKnotGeometry,
  19032. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19033. TorusGeometry: TorusGeometry,
  19034. TorusBufferGeometry: TorusBufferGeometry,
  19035. TextGeometry: TextGeometry,
  19036. TextBufferGeometry: TextBufferGeometry,
  19037. SphereGeometry: SphereGeometry,
  19038. SphereBufferGeometry: SphereBufferGeometry,
  19039. RingGeometry: RingGeometry,
  19040. RingBufferGeometry: RingBufferGeometry,
  19041. PlaneGeometry: PlaneGeometry,
  19042. PlaneBufferGeometry: PlaneBufferGeometry,
  19043. LatheGeometry: LatheGeometry,
  19044. LatheBufferGeometry: LatheBufferGeometry,
  19045. ShapeGeometry: ShapeGeometry,
  19046. ShapeBufferGeometry: ShapeBufferGeometry,
  19047. ExtrudeGeometry: ExtrudeGeometry,
  19048. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19049. EdgesGeometry: EdgesGeometry,
  19050. ConeGeometry: ConeGeometry,
  19051. ConeBufferGeometry: ConeBufferGeometry,
  19052. CylinderGeometry: CylinderGeometry,
  19053. CylinderBufferGeometry: CylinderBufferGeometry,
  19054. CircleGeometry: CircleGeometry,
  19055. CircleBufferGeometry: CircleBufferGeometry,
  19056. BoxGeometry: BoxGeometry,
  19057. BoxBufferGeometry: BoxBufferGeometry
  19058. });
  19059. /**
  19060. * @author mrdoob / http://mrdoob.com/
  19061. *
  19062. * parameters = {
  19063. * color: <THREE.Color>
  19064. * }
  19065. */
  19066. function ShadowMaterial( parameters ) {
  19067. Material.call( this );
  19068. this.type = 'ShadowMaterial';
  19069. this.color = new Color( 0x000000 );
  19070. this.transparent = true;
  19071. this.setValues( parameters );
  19072. }
  19073. ShadowMaterial.prototype = Object.create( Material.prototype );
  19074. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19075. ShadowMaterial.prototype.isShadowMaterial = true;
  19076. ShadowMaterial.prototype.copy = function ( source ) {
  19077. Material.prototype.copy.call( this, source );
  19078. this.color.copy( source.color );
  19079. return this;
  19080. };
  19081. /**
  19082. * @author mrdoob / http://mrdoob.com/
  19083. */
  19084. function RawShaderMaterial( parameters ) {
  19085. ShaderMaterial.call( this, parameters );
  19086. this.type = 'RawShaderMaterial';
  19087. }
  19088. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19089. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19090. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19091. /**
  19092. * @author WestLangley / http://github.com/WestLangley
  19093. *
  19094. * parameters = {
  19095. * color: <hex>,
  19096. * roughness: <float>,
  19097. * metalness: <float>,
  19098. * opacity: <float>,
  19099. *
  19100. * map: new THREE.Texture( <Image> ),
  19101. *
  19102. * lightMap: new THREE.Texture( <Image> ),
  19103. * lightMapIntensity: <float>
  19104. *
  19105. * aoMap: new THREE.Texture( <Image> ),
  19106. * aoMapIntensity: <float>
  19107. *
  19108. * emissive: <hex>,
  19109. * emissiveIntensity: <float>
  19110. * emissiveMap: new THREE.Texture( <Image> ),
  19111. *
  19112. * bumpMap: new THREE.Texture( <Image> ),
  19113. * bumpScale: <float>,
  19114. *
  19115. * normalMap: new THREE.Texture( <Image> ),
  19116. * normalMapType: THREE.TangentSpaceNormalMap,
  19117. * normalScale: <Vector2>,
  19118. *
  19119. * displacementMap: new THREE.Texture( <Image> ),
  19120. * displacementScale: <float>,
  19121. * displacementBias: <float>,
  19122. *
  19123. * roughnessMap: new THREE.Texture( <Image> ),
  19124. *
  19125. * metalnessMap: new THREE.Texture( <Image> ),
  19126. *
  19127. * alphaMap: new THREE.Texture( <Image> ),
  19128. *
  19129. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19130. * envMapIntensity: <float>
  19131. *
  19132. * refractionRatio: <float>,
  19133. *
  19134. * wireframe: <boolean>,
  19135. * wireframeLinewidth: <float>,
  19136. *
  19137. * skinning: <bool>,
  19138. * morphTargets: <bool>,
  19139. * morphNormals: <bool>
  19140. * }
  19141. */
  19142. function MeshStandardMaterial( parameters ) {
  19143. Material.call( this );
  19144. this.defines = { 'STANDARD': '' };
  19145. this.type = 'MeshStandardMaterial';
  19146. this.color = new Color( 0xffffff ); // diffuse
  19147. this.roughness = 0.5;
  19148. this.metalness = 0.5;
  19149. this.map = null;
  19150. this.lightMap = null;
  19151. this.lightMapIntensity = 1.0;
  19152. this.aoMap = null;
  19153. this.aoMapIntensity = 1.0;
  19154. this.emissive = new Color( 0x000000 );
  19155. this.emissiveIntensity = 1.0;
  19156. this.emissiveMap = null;
  19157. this.bumpMap = null;
  19158. this.bumpScale = 1;
  19159. this.normalMap = null;
  19160. this.normalMapType = TangentSpaceNormalMap;
  19161. this.normalScale = new Vector2( 1, 1 );
  19162. this.displacementMap = null;
  19163. this.displacementScale = 1;
  19164. this.displacementBias = 0;
  19165. this.roughnessMap = null;
  19166. this.metalnessMap = null;
  19167. this.alphaMap = null;
  19168. this.envMap = null;
  19169. this.envMapIntensity = 1.0;
  19170. this.refractionRatio = 0.98;
  19171. this.wireframe = false;
  19172. this.wireframeLinewidth = 1;
  19173. this.wireframeLinecap = 'round';
  19174. this.wireframeLinejoin = 'round';
  19175. this.skinning = false;
  19176. this.morphTargets = false;
  19177. this.morphNormals = false;
  19178. this.setValues( parameters );
  19179. }
  19180. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  19181. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19182. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19183. MeshStandardMaterial.prototype.copy = function ( source ) {
  19184. Material.prototype.copy.call( this, source );
  19185. this.defines = { 'STANDARD': '' };
  19186. this.color.copy( source.color );
  19187. this.roughness = source.roughness;
  19188. this.metalness = source.metalness;
  19189. this.map = source.map;
  19190. this.lightMap = source.lightMap;
  19191. this.lightMapIntensity = source.lightMapIntensity;
  19192. this.aoMap = source.aoMap;
  19193. this.aoMapIntensity = source.aoMapIntensity;
  19194. this.emissive.copy( source.emissive );
  19195. this.emissiveMap = source.emissiveMap;
  19196. this.emissiveIntensity = source.emissiveIntensity;
  19197. this.bumpMap = source.bumpMap;
  19198. this.bumpScale = source.bumpScale;
  19199. this.normalMap = source.normalMap;
  19200. this.normalMapType = source.normalMapType;
  19201. this.normalScale.copy( source.normalScale );
  19202. this.displacementMap = source.displacementMap;
  19203. this.displacementScale = source.displacementScale;
  19204. this.displacementBias = source.displacementBias;
  19205. this.roughnessMap = source.roughnessMap;
  19206. this.metalnessMap = source.metalnessMap;
  19207. this.alphaMap = source.alphaMap;
  19208. this.envMap = source.envMap;
  19209. this.envMapIntensity = source.envMapIntensity;
  19210. this.refractionRatio = source.refractionRatio;
  19211. this.wireframe = source.wireframe;
  19212. this.wireframeLinewidth = source.wireframeLinewidth;
  19213. this.wireframeLinecap = source.wireframeLinecap;
  19214. this.wireframeLinejoin = source.wireframeLinejoin;
  19215. this.skinning = source.skinning;
  19216. this.morphTargets = source.morphTargets;
  19217. this.morphNormals = source.morphNormals;
  19218. return this;
  19219. };
  19220. /**
  19221. * @author WestLangley / http://github.com/WestLangley
  19222. *
  19223. * parameters = {
  19224. * reflectivity: <float>
  19225. * clearCoat: <float>
  19226. * clearCoatRoughness: <float>
  19227. * }
  19228. */
  19229. function MeshPhysicalMaterial( parameters ) {
  19230. MeshStandardMaterial.call( this );
  19231. this.defines = { 'PHYSICAL': '' };
  19232. this.type = 'MeshPhysicalMaterial';
  19233. this.reflectivity = 0.5; // maps to F0 = 0.04
  19234. this.clearCoat = 0.0;
  19235. this.clearCoatRoughness = 0.0;
  19236. this.setValues( parameters );
  19237. }
  19238. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  19239. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19240. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19241. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  19242. MeshStandardMaterial.prototype.copy.call( this, source );
  19243. this.defines = { 'PHYSICAL': '' };
  19244. this.reflectivity = source.reflectivity;
  19245. this.clearCoat = source.clearCoat;
  19246. this.clearCoatRoughness = source.clearCoatRoughness;
  19247. return this;
  19248. };
  19249. /**
  19250. * @author mrdoob / http://mrdoob.com/
  19251. * @author alteredq / http://alteredqualia.com/
  19252. *
  19253. * parameters = {
  19254. * color: <hex>,
  19255. * specular: <hex>,
  19256. * shininess: <float>,
  19257. * opacity: <float>,
  19258. *
  19259. * map: new THREE.Texture( <Image> ),
  19260. *
  19261. * lightMap: new THREE.Texture( <Image> ),
  19262. * lightMapIntensity: <float>
  19263. *
  19264. * aoMap: new THREE.Texture( <Image> ),
  19265. * aoMapIntensity: <float>
  19266. *
  19267. * emissive: <hex>,
  19268. * emissiveIntensity: <float>
  19269. * emissiveMap: new THREE.Texture( <Image> ),
  19270. *
  19271. * bumpMap: new THREE.Texture( <Image> ),
  19272. * bumpScale: <float>,
  19273. *
  19274. * normalMap: new THREE.Texture( <Image> ),
  19275. * normalMapType: THREE.TangentSpaceNormalMap,
  19276. * normalScale: <Vector2>,
  19277. *
  19278. * displacementMap: new THREE.Texture( <Image> ),
  19279. * displacementScale: <float>,
  19280. * displacementBias: <float>,
  19281. *
  19282. * specularMap: new THREE.Texture( <Image> ),
  19283. *
  19284. * alphaMap: new THREE.Texture( <Image> ),
  19285. *
  19286. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19287. * combine: THREE.Multiply,
  19288. * reflectivity: <float>,
  19289. * refractionRatio: <float>,
  19290. *
  19291. * wireframe: <boolean>,
  19292. * wireframeLinewidth: <float>,
  19293. *
  19294. * skinning: <bool>,
  19295. * morphTargets: <bool>,
  19296. * morphNormals: <bool>
  19297. * }
  19298. */
  19299. function MeshPhongMaterial( parameters ) {
  19300. Material.call( this );
  19301. this.type = 'MeshPhongMaterial';
  19302. this.color = new Color( 0xffffff ); // diffuse
  19303. this.specular = new Color( 0x111111 );
  19304. this.shininess = 30;
  19305. this.map = null;
  19306. this.lightMap = null;
  19307. this.lightMapIntensity = 1.0;
  19308. this.aoMap = null;
  19309. this.aoMapIntensity = 1.0;
  19310. this.emissive = new Color( 0x000000 );
  19311. this.emissiveIntensity = 1.0;
  19312. this.emissiveMap = null;
  19313. this.bumpMap = null;
  19314. this.bumpScale = 1;
  19315. this.normalMap = null;
  19316. this.normalMapType = TangentSpaceNormalMap;
  19317. this.normalScale = new Vector2( 1, 1 );
  19318. this.displacementMap = null;
  19319. this.displacementScale = 1;
  19320. this.displacementBias = 0;
  19321. this.specularMap = null;
  19322. this.alphaMap = null;
  19323. this.envMap = null;
  19324. this.combine = MultiplyOperation;
  19325. this.reflectivity = 1;
  19326. this.refractionRatio = 0.98;
  19327. this.wireframe = false;
  19328. this.wireframeLinewidth = 1;
  19329. this.wireframeLinecap = 'round';
  19330. this.wireframeLinejoin = 'round';
  19331. this.skinning = false;
  19332. this.morphTargets = false;
  19333. this.morphNormals = false;
  19334. this.setValues( parameters );
  19335. }
  19336. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19337. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19338. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19339. MeshPhongMaterial.prototype.copy = function ( source ) {
  19340. Material.prototype.copy.call( this, source );
  19341. this.color.copy( source.color );
  19342. this.specular.copy( source.specular );
  19343. this.shininess = source.shininess;
  19344. this.map = source.map;
  19345. this.lightMap = source.lightMap;
  19346. this.lightMapIntensity = source.lightMapIntensity;
  19347. this.aoMap = source.aoMap;
  19348. this.aoMapIntensity = source.aoMapIntensity;
  19349. this.emissive.copy( source.emissive );
  19350. this.emissiveMap = source.emissiveMap;
  19351. this.emissiveIntensity = source.emissiveIntensity;
  19352. this.bumpMap = source.bumpMap;
  19353. this.bumpScale = source.bumpScale;
  19354. this.normalMap = source.normalMap;
  19355. this.normalMapType = source.normalMapType;
  19356. this.normalScale.copy( source.normalScale );
  19357. this.displacementMap = source.displacementMap;
  19358. this.displacementScale = source.displacementScale;
  19359. this.displacementBias = source.displacementBias;
  19360. this.specularMap = source.specularMap;
  19361. this.alphaMap = source.alphaMap;
  19362. this.envMap = source.envMap;
  19363. this.combine = source.combine;
  19364. this.reflectivity = source.reflectivity;
  19365. this.refractionRatio = source.refractionRatio;
  19366. this.wireframe = source.wireframe;
  19367. this.wireframeLinewidth = source.wireframeLinewidth;
  19368. this.wireframeLinecap = source.wireframeLinecap;
  19369. this.wireframeLinejoin = source.wireframeLinejoin;
  19370. this.skinning = source.skinning;
  19371. this.morphTargets = source.morphTargets;
  19372. this.morphNormals = source.morphNormals;
  19373. return this;
  19374. };
  19375. /**
  19376. * @author takahirox / http://github.com/takahirox
  19377. *
  19378. * parameters = {
  19379. * gradientMap: new THREE.Texture( <Image> )
  19380. * }
  19381. */
  19382. function MeshToonMaterial( parameters ) {
  19383. MeshPhongMaterial.call( this );
  19384. this.defines = { 'TOON': '' };
  19385. this.type = 'MeshToonMaterial';
  19386. this.gradientMap = null;
  19387. this.setValues( parameters );
  19388. }
  19389. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19390. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19391. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19392. MeshToonMaterial.prototype.copy = function ( source ) {
  19393. MeshPhongMaterial.prototype.copy.call( this, source );
  19394. this.gradientMap = source.gradientMap;
  19395. return this;
  19396. };
  19397. /**
  19398. * @author mrdoob / http://mrdoob.com/
  19399. * @author WestLangley / http://github.com/WestLangley
  19400. *
  19401. * parameters = {
  19402. * opacity: <float>,
  19403. *
  19404. * bumpMap: new THREE.Texture( <Image> ),
  19405. * bumpScale: <float>,
  19406. *
  19407. * normalMap: new THREE.Texture( <Image> ),
  19408. * normalMapType: THREE.TangentSpaceNormalMap,
  19409. * normalScale: <Vector2>,
  19410. *
  19411. * displacementMap: new THREE.Texture( <Image> ),
  19412. * displacementScale: <float>,
  19413. * displacementBias: <float>,
  19414. *
  19415. * wireframe: <boolean>,
  19416. * wireframeLinewidth: <float>
  19417. *
  19418. * skinning: <bool>,
  19419. * morphTargets: <bool>,
  19420. * morphNormals: <bool>
  19421. * }
  19422. */
  19423. function MeshNormalMaterial( parameters ) {
  19424. Material.call( this );
  19425. this.type = 'MeshNormalMaterial';
  19426. this.bumpMap = null;
  19427. this.bumpScale = 1;
  19428. this.normalMap = null;
  19429. this.normalMapType = TangentSpaceNormalMap;
  19430. this.normalScale = new Vector2( 1, 1 );
  19431. this.displacementMap = null;
  19432. this.displacementScale = 1;
  19433. this.displacementBias = 0;
  19434. this.wireframe = false;
  19435. this.wireframeLinewidth = 1;
  19436. this.fog = false;
  19437. this.lights = false;
  19438. this.skinning = false;
  19439. this.morphTargets = false;
  19440. this.morphNormals = false;
  19441. this.setValues( parameters );
  19442. }
  19443. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19444. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19445. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19446. MeshNormalMaterial.prototype.copy = function ( source ) {
  19447. Material.prototype.copy.call( this, source );
  19448. this.bumpMap = source.bumpMap;
  19449. this.bumpScale = source.bumpScale;
  19450. this.normalMap = source.normalMap;
  19451. this.normalMapType = source.normalMapType;
  19452. this.normalScale.copy( source.normalScale );
  19453. this.displacementMap = source.displacementMap;
  19454. this.displacementScale = source.displacementScale;
  19455. this.displacementBias = source.displacementBias;
  19456. this.wireframe = source.wireframe;
  19457. this.wireframeLinewidth = source.wireframeLinewidth;
  19458. this.skinning = source.skinning;
  19459. this.morphTargets = source.morphTargets;
  19460. this.morphNormals = source.morphNormals;
  19461. return this;
  19462. };
  19463. /**
  19464. * @author mrdoob / http://mrdoob.com/
  19465. * @author alteredq / http://alteredqualia.com/
  19466. *
  19467. * parameters = {
  19468. * color: <hex>,
  19469. * opacity: <float>,
  19470. *
  19471. * map: new THREE.Texture( <Image> ),
  19472. *
  19473. * lightMap: new THREE.Texture( <Image> ),
  19474. * lightMapIntensity: <float>
  19475. *
  19476. * aoMap: new THREE.Texture( <Image> ),
  19477. * aoMapIntensity: <float>
  19478. *
  19479. * emissive: <hex>,
  19480. * emissiveIntensity: <float>
  19481. * emissiveMap: new THREE.Texture( <Image> ),
  19482. *
  19483. * specularMap: new THREE.Texture( <Image> ),
  19484. *
  19485. * alphaMap: new THREE.Texture( <Image> ),
  19486. *
  19487. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19488. * combine: THREE.Multiply,
  19489. * reflectivity: <float>,
  19490. * refractionRatio: <float>,
  19491. *
  19492. * wireframe: <boolean>,
  19493. * wireframeLinewidth: <float>,
  19494. *
  19495. * skinning: <bool>,
  19496. * morphTargets: <bool>,
  19497. * morphNormals: <bool>
  19498. * }
  19499. */
  19500. function MeshLambertMaterial( parameters ) {
  19501. Material.call( this );
  19502. this.type = 'MeshLambertMaterial';
  19503. this.color = new Color( 0xffffff ); // diffuse
  19504. this.map = null;
  19505. this.lightMap = null;
  19506. this.lightMapIntensity = 1.0;
  19507. this.aoMap = null;
  19508. this.aoMapIntensity = 1.0;
  19509. this.emissive = new Color( 0x000000 );
  19510. this.emissiveIntensity = 1.0;
  19511. this.emissiveMap = null;
  19512. this.specularMap = null;
  19513. this.alphaMap = null;
  19514. this.envMap = null;
  19515. this.combine = MultiplyOperation;
  19516. this.reflectivity = 1;
  19517. this.refractionRatio = 0.98;
  19518. this.wireframe = false;
  19519. this.wireframeLinewidth = 1;
  19520. this.wireframeLinecap = 'round';
  19521. this.wireframeLinejoin = 'round';
  19522. this.skinning = false;
  19523. this.morphTargets = false;
  19524. this.morphNormals = false;
  19525. this.setValues( parameters );
  19526. }
  19527. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19528. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19529. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19530. MeshLambertMaterial.prototype.copy = function ( source ) {
  19531. Material.prototype.copy.call( this, source );
  19532. this.color.copy( source.color );
  19533. this.map = source.map;
  19534. this.lightMap = source.lightMap;
  19535. this.lightMapIntensity = source.lightMapIntensity;
  19536. this.aoMap = source.aoMap;
  19537. this.aoMapIntensity = source.aoMapIntensity;
  19538. this.emissive.copy( source.emissive );
  19539. this.emissiveMap = source.emissiveMap;
  19540. this.emissiveIntensity = source.emissiveIntensity;
  19541. this.specularMap = source.specularMap;
  19542. this.alphaMap = source.alphaMap;
  19543. this.envMap = source.envMap;
  19544. this.combine = source.combine;
  19545. this.reflectivity = source.reflectivity;
  19546. this.refractionRatio = source.refractionRatio;
  19547. this.wireframe = source.wireframe;
  19548. this.wireframeLinewidth = source.wireframeLinewidth;
  19549. this.wireframeLinecap = source.wireframeLinecap;
  19550. this.wireframeLinejoin = source.wireframeLinejoin;
  19551. this.skinning = source.skinning;
  19552. this.morphTargets = source.morphTargets;
  19553. this.morphNormals = source.morphNormals;
  19554. return this;
  19555. };
  19556. /**
  19557. * @author WestLangley / http://github.com/WestLangley
  19558. *
  19559. * parameters = {
  19560. * color: <hex>,
  19561. * opacity: <float>,
  19562. *
  19563. * matcap: new THREE.Texture( <Image> ),
  19564. *
  19565. * map: new THREE.Texture( <Image> ),
  19566. *
  19567. * bumpMap: new THREE.Texture( <Image> ),
  19568. * bumpScale: <float>,
  19569. *
  19570. * normalMap: new THREE.Texture( <Image> ),
  19571. * normalMapType: THREE.TangentSpaceNormalMap,
  19572. * normalScale: <Vector2>,
  19573. *
  19574. * displacementMap: new THREE.Texture( <Image> ),
  19575. * displacementScale: <float>,
  19576. * displacementBias: <float>,
  19577. *
  19578. * alphaMap: new THREE.Texture( <Image> ),
  19579. *
  19580. * skinning: <bool>,
  19581. * morphTargets: <bool>,
  19582. * morphNormals: <bool>
  19583. * }
  19584. */
  19585. function MeshMatcapMaterial( parameters ) {
  19586. Material.call( this );
  19587. this.defines = { 'MATCAP': '' };
  19588. this.type = 'MeshMatcapMaterial';
  19589. this.color = new Color( 0xffffff ); // diffuse
  19590. this.matcap = null;
  19591. this.map = null;
  19592. this.bumpMap = null;
  19593. this.bumpScale = 1;
  19594. this.normalMap = null;
  19595. this.normalMapType = TangentSpaceNormalMap;
  19596. this.normalScale = new Vector2( 1, 1 );
  19597. this.displacementMap = null;
  19598. this.displacementScale = 1;
  19599. this.displacementBias = 0;
  19600. this.alphaMap = null;
  19601. this.skinning = false;
  19602. this.morphTargets = false;
  19603. this.morphNormals = false;
  19604. this.lights = false;
  19605. this.setValues( parameters );
  19606. }
  19607. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19608. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19609. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19610. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19611. Material.prototype.copy.call( this, source );
  19612. this.defines = { 'MATCAP': '' };
  19613. this.color.copy( source.color );
  19614. this.matcap = source.matcap;
  19615. this.map = source.map;
  19616. this.bumpMap = source.bumpMap;
  19617. this.bumpScale = source.bumpScale;
  19618. this.normalMap = source.normalMap;
  19619. this.normalMapType = source.normalMapType;
  19620. this.normalScale.copy( source.normalScale );
  19621. this.displacementMap = source.displacementMap;
  19622. this.displacementScale = source.displacementScale;
  19623. this.displacementBias = source.displacementBias;
  19624. this.alphaMap = source.alphaMap;
  19625. this.skinning = source.skinning;
  19626. this.morphTargets = source.morphTargets;
  19627. this.morphNormals = source.morphNormals;
  19628. return this;
  19629. };
  19630. /**
  19631. * @author alteredq / http://alteredqualia.com/
  19632. *
  19633. * parameters = {
  19634. * color: <hex>,
  19635. * opacity: <float>,
  19636. *
  19637. * linewidth: <float>,
  19638. *
  19639. * scale: <float>,
  19640. * dashSize: <float>,
  19641. * gapSize: <float>
  19642. * }
  19643. */
  19644. function LineDashedMaterial( parameters ) {
  19645. LineBasicMaterial.call( this );
  19646. this.type = 'LineDashedMaterial';
  19647. this.scale = 1;
  19648. this.dashSize = 3;
  19649. this.gapSize = 1;
  19650. this.setValues( parameters );
  19651. }
  19652. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19653. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19654. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19655. LineDashedMaterial.prototype.copy = function ( source ) {
  19656. LineBasicMaterial.prototype.copy.call( this, source );
  19657. this.scale = source.scale;
  19658. this.dashSize = source.dashSize;
  19659. this.gapSize = source.gapSize;
  19660. return this;
  19661. };
  19662. var Materials = /*#__PURE__*/Object.freeze({
  19663. ShadowMaterial: ShadowMaterial,
  19664. SpriteMaterial: SpriteMaterial,
  19665. RawShaderMaterial: RawShaderMaterial,
  19666. ShaderMaterial: ShaderMaterial,
  19667. PointsMaterial: PointsMaterial,
  19668. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19669. MeshStandardMaterial: MeshStandardMaterial,
  19670. MeshPhongMaterial: MeshPhongMaterial,
  19671. MeshToonMaterial: MeshToonMaterial,
  19672. MeshNormalMaterial: MeshNormalMaterial,
  19673. MeshLambertMaterial: MeshLambertMaterial,
  19674. MeshDepthMaterial: MeshDepthMaterial,
  19675. MeshDistanceMaterial: MeshDistanceMaterial,
  19676. MeshBasicMaterial: MeshBasicMaterial,
  19677. MeshMatcapMaterial: MeshMatcapMaterial,
  19678. LineDashedMaterial: LineDashedMaterial,
  19679. LineBasicMaterial: LineBasicMaterial,
  19680. Material: Material
  19681. });
  19682. /**
  19683. * @author tschw
  19684. * @author Ben Houston / http://clara.io/
  19685. * @author David Sarno / http://lighthaus.us/
  19686. */
  19687. var AnimationUtils = {
  19688. // same as Array.prototype.slice, but also works on typed arrays
  19689. arraySlice: function ( array, from, to ) {
  19690. if ( AnimationUtils.isTypedArray( array ) ) {
  19691. // in ios9 array.subarray(from, undefined) will return empty array
  19692. // but array.subarray(from) or array.subarray(from, len) is correct
  19693. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19694. }
  19695. return array.slice( from, to );
  19696. },
  19697. // converts an array to a specific type
  19698. convertArray: function ( array, type, forceClone ) {
  19699. if ( ! array || // let 'undefined' and 'null' pass
  19700. ! forceClone && array.constructor === type ) return array;
  19701. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19702. return new type( array ); // create typed array
  19703. }
  19704. return Array.prototype.slice.call( array ); // create Array
  19705. },
  19706. isTypedArray: function ( object ) {
  19707. return ArrayBuffer.isView( object ) &&
  19708. ! ( object instanceof DataView );
  19709. },
  19710. // returns an array by which times and values can be sorted
  19711. getKeyframeOrder: function ( times ) {
  19712. function compareTime( i, j ) {
  19713. return times[ i ] - times[ j ];
  19714. }
  19715. var n = times.length;
  19716. var result = new Array( n );
  19717. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19718. result.sort( compareTime );
  19719. return result;
  19720. },
  19721. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19722. sortedArray: function ( values, stride, order ) {
  19723. var nValues = values.length;
  19724. var result = new values.constructor( nValues );
  19725. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19726. var srcOffset = order[ i ] * stride;
  19727. for ( var j = 0; j !== stride; ++ j ) {
  19728. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19729. }
  19730. }
  19731. return result;
  19732. },
  19733. // function for parsing AOS keyframe formats
  19734. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19735. var i = 1, key = jsonKeys[ 0 ];
  19736. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19737. key = jsonKeys[ i ++ ];
  19738. }
  19739. if ( key === undefined ) return; // no data
  19740. var value = key[ valuePropertyName ];
  19741. if ( value === undefined ) return; // no data
  19742. if ( Array.isArray( value ) ) {
  19743. do {
  19744. value = key[ valuePropertyName ];
  19745. if ( value !== undefined ) {
  19746. times.push( key.time );
  19747. values.push.apply( values, value ); // push all elements
  19748. }
  19749. key = jsonKeys[ i ++ ];
  19750. } while ( key !== undefined );
  19751. } else if ( value.toArray !== undefined ) {
  19752. // ...assume THREE.Math-ish
  19753. do {
  19754. value = key[ valuePropertyName ];
  19755. if ( value !== undefined ) {
  19756. times.push( key.time );
  19757. value.toArray( values, values.length );
  19758. }
  19759. key = jsonKeys[ i ++ ];
  19760. } while ( key !== undefined );
  19761. } else {
  19762. // otherwise push as-is
  19763. do {
  19764. value = key[ valuePropertyName ];
  19765. if ( value !== undefined ) {
  19766. times.push( key.time );
  19767. values.push( value );
  19768. }
  19769. key = jsonKeys[ i ++ ];
  19770. } while ( key !== undefined );
  19771. }
  19772. }
  19773. };
  19774. /**
  19775. * Abstract base class of interpolants over parametric samples.
  19776. *
  19777. * The parameter domain is one dimensional, typically the time or a path
  19778. * along a curve defined by the data.
  19779. *
  19780. * The sample values can have any dimensionality and derived classes may
  19781. * apply special interpretations to the data.
  19782. *
  19783. * This class provides the interval seek in a Template Method, deferring
  19784. * the actual interpolation to derived classes.
  19785. *
  19786. * Time complexity is O(1) for linear access crossing at most two points
  19787. * and O(log N) for random access, where N is the number of positions.
  19788. *
  19789. * References:
  19790. *
  19791. * http://www.oodesign.com/template-method-pattern.html
  19792. *
  19793. * @author tschw
  19794. */
  19795. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19796. this.parameterPositions = parameterPositions;
  19797. this._cachedIndex = 0;
  19798. this.resultBuffer = resultBuffer !== undefined ?
  19799. resultBuffer : new sampleValues.constructor( sampleSize );
  19800. this.sampleValues = sampleValues;
  19801. this.valueSize = sampleSize;
  19802. }
  19803. Object.assign( Interpolant.prototype, {
  19804. evaluate: function ( t ) {
  19805. var pp = this.parameterPositions,
  19806. i1 = this._cachedIndex,
  19807. t1 = pp[ i1 ],
  19808. t0 = pp[ i1 - 1 ];
  19809. validate_interval: {
  19810. seek: {
  19811. var right;
  19812. linear_scan: {
  19813. //- See http://jsperf.com/comparison-to-undefined/3
  19814. //- slower code:
  19815. //-
  19816. //- if ( t >= t1 || t1 === undefined ) {
  19817. forward_scan: if ( ! ( t < t1 ) ) {
  19818. for ( var giveUpAt = i1 + 2; ; ) {
  19819. if ( t1 === undefined ) {
  19820. if ( t < t0 ) break forward_scan;
  19821. // after end
  19822. i1 = pp.length;
  19823. this._cachedIndex = i1;
  19824. return this.afterEnd_( i1 - 1, t, t0 );
  19825. }
  19826. if ( i1 === giveUpAt ) break; // this loop
  19827. t0 = t1;
  19828. t1 = pp[ ++ i1 ];
  19829. if ( t < t1 ) {
  19830. // we have arrived at the sought interval
  19831. break seek;
  19832. }
  19833. }
  19834. // prepare binary search on the right side of the index
  19835. right = pp.length;
  19836. break linear_scan;
  19837. }
  19838. //- slower code:
  19839. //- if ( t < t0 || t0 === undefined ) {
  19840. if ( ! ( t >= t0 ) ) {
  19841. // looping?
  19842. var t1global = pp[ 1 ];
  19843. if ( t < t1global ) {
  19844. i1 = 2; // + 1, using the scan for the details
  19845. t0 = t1global;
  19846. }
  19847. // linear reverse scan
  19848. for ( var giveUpAt = i1 - 2; ; ) {
  19849. if ( t0 === undefined ) {
  19850. // before start
  19851. this._cachedIndex = 0;
  19852. return this.beforeStart_( 0, t, t1 );
  19853. }
  19854. if ( i1 === giveUpAt ) break; // this loop
  19855. t1 = t0;
  19856. t0 = pp[ -- i1 - 1 ];
  19857. if ( t >= t0 ) {
  19858. // we have arrived at the sought interval
  19859. break seek;
  19860. }
  19861. }
  19862. // prepare binary search on the left side of the index
  19863. right = i1;
  19864. i1 = 0;
  19865. break linear_scan;
  19866. }
  19867. // the interval is valid
  19868. break validate_interval;
  19869. } // linear scan
  19870. // binary search
  19871. while ( i1 < right ) {
  19872. var mid = ( i1 + right ) >>> 1;
  19873. if ( t < pp[ mid ] ) {
  19874. right = mid;
  19875. } else {
  19876. i1 = mid + 1;
  19877. }
  19878. }
  19879. t1 = pp[ i1 ];
  19880. t0 = pp[ i1 - 1 ];
  19881. // check boundary cases, again
  19882. if ( t0 === undefined ) {
  19883. this._cachedIndex = 0;
  19884. return this.beforeStart_( 0, t, t1 );
  19885. }
  19886. if ( t1 === undefined ) {
  19887. i1 = pp.length;
  19888. this._cachedIndex = i1;
  19889. return this.afterEnd_( i1 - 1, t0, t );
  19890. }
  19891. } // seek
  19892. this._cachedIndex = i1;
  19893. this.intervalChanged_( i1, t0, t1 );
  19894. } // validate_interval
  19895. return this.interpolate_( i1, t0, t, t1 );
  19896. },
  19897. settings: null, // optional, subclass-specific settings structure
  19898. // Note: The indirection allows central control of many interpolants.
  19899. // --- Protected interface
  19900. DefaultSettings_: {},
  19901. getSettings_: function () {
  19902. return this.settings || this.DefaultSettings_;
  19903. },
  19904. copySampleValue_: function ( index ) {
  19905. // copies a sample value to the result buffer
  19906. var result = this.resultBuffer,
  19907. values = this.sampleValues,
  19908. stride = this.valueSize,
  19909. offset = index * stride;
  19910. for ( var i = 0; i !== stride; ++ i ) {
  19911. result[ i ] = values[ offset + i ];
  19912. }
  19913. return result;
  19914. },
  19915. // Template methods for derived classes:
  19916. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19917. throw new Error( 'call to abstract method' );
  19918. // implementations shall return this.resultBuffer
  19919. },
  19920. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19921. // empty
  19922. }
  19923. } );
  19924. //!\ DECLARE ALIAS AFTER assign prototype !
  19925. Object.assign( Interpolant.prototype, {
  19926. //( 0, t, t0 ), returns this.resultBuffer
  19927. beforeStart_: Interpolant.prototype.copySampleValue_,
  19928. //( N-1, tN-1, t ), returns this.resultBuffer
  19929. afterEnd_: Interpolant.prototype.copySampleValue_,
  19930. } );
  19931. /**
  19932. * Fast and simple cubic spline interpolant.
  19933. *
  19934. * It was derived from a Hermitian construction setting the first derivative
  19935. * at each sample position to the linear slope between neighboring positions
  19936. * over their parameter interval.
  19937. *
  19938. * @author tschw
  19939. */
  19940. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19941. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19942. this._weightPrev = - 0;
  19943. this._offsetPrev = - 0;
  19944. this._weightNext = - 0;
  19945. this._offsetNext = - 0;
  19946. }
  19947. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19948. constructor: CubicInterpolant,
  19949. DefaultSettings_: {
  19950. endingStart: ZeroCurvatureEnding,
  19951. endingEnd: ZeroCurvatureEnding
  19952. },
  19953. intervalChanged_: function ( i1, t0, t1 ) {
  19954. var pp = this.parameterPositions,
  19955. iPrev = i1 - 2,
  19956. iNext = i1 + 1,
  19957. tPrev = pp[ iPrev ],
  19958. tNext = pp[ iNext ];
  19959. if ( tPrev === undefined ) {
  19960. switch ( this.getSettings_().endingStart ) {
  19961. case ZeroSlopeEnding:
  19962. // f'(t0) = 0
  19963. iPrev = i1;
  19964. tPrev = 2 * t0 - t1;
  19965. break;
  19966. case WrapAroundEnding:
  19967. // use the other end of the curve
  19968. iPrev = pp.length - 2;
  19969. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19970. break;
  19971. default: // ZeroCurvatureEnding
  19972. // f''(t0) = 0 a.k.a. Natural Spline
  19973. iPrev = i1;
  19974. tPrev = t1;
  19975. }
  19976. }
  19977. if ( tNext === undefined ) {
  19978. switch ( this.getSettings_().endingEnd ) {
  19979. case ZeroSlopeEnding:
  19980. // f'(tN) = 0
  19981. iNext = i1;
  19982. tNext = 2 * t1 - t0;
  19983. break;
  19984. case WrapAroundEnding:
  19985. // use the other end of the curve
  19986. iNext = 1;
  19987. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19988. break;
  19989. default: // ZeroCurvatureEnding
  19990. // f''(tN) = 0, a.k.a. Natural Spline
  19991. iNext = i1 - 1;
  19992. tNext = t0;
  19993. }
  19994. }
  19995. var halfDt = ( t1 - t0 ) * 0.5,
  19996. stride = this.valueSize;
  19997. this._weightPrev = halfDt / ( t0 - tPrev );
  19998. this._weightNext = halfDt / ( tNext - t1 );
  19999. this._offsetPrev = iPrev * stride;
  20000. this._offsetNext = iNext * stride;
  20001. },
  20002. interpolate_: function ( i1, t0, t, t1 ) {
  20003. var result = this.resultBuffer,
  20004. values = this.sampleValues,
  20005. stride = this.valueSize,
  20006. o1 = i1 * stride, o0 = o1 - stride,
  20007. oP = this._offsetPrev, oN = this._offsetNext,
  20008. wP = this._weightPrev, wN = this._weightNext,
  20009. p = ( t - t0 ) / ( t1 - t0 ),
  20010. pp = p * p,
  20011. ppp = pp * p;
  20012. // evaluate polynomials
  20013. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20014. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20015. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20016. var sN = wN * ppp - wN * pp;
  20017. // combine data linearly
  20018. for ( var i = 0; i !== stride; ++ i ) {
  20019. result[ i ] =
  20020. sP * values[ oP + i ] +
  20021. s0 * values[ o0 + i ] +
  20022. s1 * values[ o1 + i ] +
  20023. sN * values[ oN + i ];
  20024. }
  20025. return result;
  20026. }
  20027. } );
  20028. /**
  20029. * @author tschw
  20030. */
  20031. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20032. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20033. }
  20034. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20035. constructor: LinearInterpolant,
  20036. interpolate_: function ( i1, t0, t, t1 ) {
  20037. var result = this.resultBuffer,
  20038. values = this.sampleValues,
  20039. stride = this.valueSize,
  20040. offset1 = i1 * stride,
  20041. offset0 = offset1 - stride,
  20042. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20043. weight0 = 1 - weight1;
  20044. for ( var i = 0; i !== stride; ++ i ) {
  20045. result[ i ] =
  20046. values[ offset0 + i ] * weight0 +
  20047. values[ offset1 + i ] * weight1;
  20048. }
  20049. return result;
  20050. }
  20051. } );
  20052. /**
  20053. *
  20054. * Interpolant that evaluates to the sample value at the position preceeding
  20055. * the parameter.
  20056. *
  20057. * @author tschw
  20058. */
  20059. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20060. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20061. }
  20062. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20063. constructor: DiscreteInterpolant,
  20064. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20065. return this.copySampleValue_( i1 - 1 );
  20066. }
  20067. } );
  20068. /**
  20069. *
  20070. * A timed sequence of keyframes for a specific property.
  20071. *
  20072. *
  20073. * @author Ben Houston / http://clara.io/
  20074. * @author David Sarno / http://lighthaus.us/
  20075. * @author tschw
  20076. */
  20077. function KeyframeTrack( name, times, values, interpolation ) {
  20078. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20079. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20080. this.name = name;
  20081. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20082. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20083. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20084. }
  20085. // Static methods
  20086. Object.assign( KeyframeTrack, {
  20087. // Serialization (in static context, because of constructor invocation
  20088. // and automatic invocation of .toJSON):
  20089. toJSON: function ( track ) {
  20090. var trackType = track.constructor;
  20091. var json;
  20092. // derived classes can define a static toJSON method
  20093. if ( trackType.toJSON !== undefined ) {
  20094. json = trackType.toJSON( track );
  20095. } else {
  20096. // by default, we assume the data can be serialized as-is
  20097. json = {
  20098. 'name': track.name,
  20099. 'times': AnimationUtils.convertArray( track.times, Array ),
  20100. 'values': AnimationUtils.convertArray( track.values, Array )
  20101. };
  20102. var interpolation = track.getInterpolation();
  20103. if ( interpolation !== track.DefaultInterpolation ) {
  20104. json.interpolation = interpolation;
  20105. }
  20106. }
  20107. json.type = track.ValueTypeName; // mandatory
  20108. return json;
  20109. }
  20110. } );
  20111. Object.assign( KeyframeTrack.prototype, {
  20112. constructor: KeyframeTrack,
  20113. TimeBufferType: Float32Array,
  20114. ValueBufferType: Float32Array,
  20115. DefaultInterpolation: InterpolateLinear,
  20116. InterpolantFactoryMethodDiscrete: function ( result ) {
  20117. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20118. },
  20119. InterpolantFactoryMethodLinear: function ( result ) {
  20120. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20121. },
  20122. InterpolantFactoryMethodSmooth: function ( result ) {
  20123. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  20124. },
  20125. setInterpolation: function ( interpolation ) {
  20126. var factoryMethod;
  20127. switch ( interpolation ) {
  20128. case InterpolateDiscrete:
  20129. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20130. break;
  20131. case InterpolateLinear:
  20132. factoryMethod = this.InterpolantFactoryMethodLinear;
  20133. break;
  20134. case InterpolateSmooth:
  20135. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20136. break;
  20137. }
  20138. if ( factoryMethod === undefined ) {
  20139. var message = "unsupported interpolation for " +
  20140. this.ValueTypeName + " keyframe track named " + this.name;
  20141. if ( this.createInterpolant === undefined ) {
  20142. // fall back to default, unless the default itself is messed up
  20143. if ( interpolation !== this.DefaultInterpolation ) {
  20144. this.setInterpolation( this.DefaultInterpolation );
  20145. } else {
  20146. throw new Error( message ); // fatal, in this case
  20147. }
  20148. }
  20149. console.warn( 'THREE.KeyframeTrack:', message );
  20150. return this;
  20151. }
  20152. this.createInterpolant = factoryMethod;
  20153. return this;
  20154. },
  20155. getInterpolation: function () {
  20156. switch ( this.createInterpolant ) {
  20157. case this.InterpolantFactoryMethodDiscrete:
  20158. return InterpolateDiscrete;
  20159. case this.InterpolantFactoryMethodLinear:
  20160. return InterpolateLinear;
  20161. case this.InterpolantFactoryMethodSmooth:
  20162. return InterpolateSmooth;
  20163. }
  20164. },
  20165. getValueSize: function () {
  20166. return this.values.length / this.times.length;
  20167. },
  20168. // move all keyframes either forwards or backwards in time
  20169. shift: function ( timeOffset ) {
  20170. if ( timeOffset !== 0.0 ) {
  20171. var times = this.times;
  20172. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20173. times[ i ] += timeOffset;
  20174. }
  20175. }
  20176. return this;
  20177. },
  20178. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20179. scale: function ( timeScale ) {
  20180. if ( timeScale !== 1.0 ) {
  20181. var times = this.times;
  20182. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20183. times[ i ] *= timeScale;
  20184. }
  20185. }
  20186. return this;
  20187. },
  20188. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20189. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20190. trim: function ( startTime, endTime ) {
  20191. var times = this.times,
  20192. nKeys = times.length,
  20193. from = 0,
  20194. to = nKeys - 1;
  20195. while ( from !== nKeys && times[ from ] < startTime ) {
  20196. ++ from;
  20197. }
  20198. while ( to !== - 1 && times[ to ] > endTime ) {
  20199. -- to;
  20200. }
  20201. ++ to; // inclusive -> exclusive bound
  20202. if ( from !== 0 || to !== nKeys ) {
  20203. // empty tracks are forbidden, so keep at least one keyframe
  20204. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  20205. var stride = this.getValueSize();
  20206. this.times = AnimationUtils.arraySlice( times, from, to );
  20207. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  20208. }
  20209. return this;
  20210. },
  20211. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20212. validate: function () {
  20213. var valid = true;
  20214. var valueSize = this.getValueSize();
  20215. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  20216. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  20217. valid = false;
  20218. }
  20219. var times = this.times,
  20220. values = this.values,
  20221. nKeys = times.length;
  20222. if ( nKeys === 0 ) {
  20223. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20224. valid = false;
  20225. }
  20226. var prevTime = null;
  20227. for ( var i = 0; i !== nKeys; i ++ ) {
  20228. var currTime = times[ i ];
  20229. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20230. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20231. valid = false;
  20232. break;
  20233. }
  20234. if ( prevTime !== null && prevTime > currTime ) {
  20235. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20236. valid = false;
  20237. break;
  20238. }
  20239. prevTime = currTime;
  20240. }
  20241. if ( values !== undefined ) {
  20242. if ( AnimationUtils.isTypedArray( values ) ) {
  20243. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20244. var value = values[ i ];
  20245. if ( isNaN( value ) ) {
  20246. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20247. valid = false;
  20248. break;
  20249. }
  20250. }
  20251. }
  20252. }
  20253. return valid;
  20254. },
  20255. // removes equivalent sequential keys as common in morph target sequences
  20256. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20257. optimize: function () {
  20258. var times = this.times,
  20259. values = this.values,
  20260. stride = this.getValueSize(),
  20261. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20262. writeIndex = 1,
  20263. lastIndex = times.length - 1;
  20264. for ( var i = 1; i < lastIndex; ++ i ) {
  20265. var keep = false;
  20266. var time = times[ i ];
  20267. var timeNext = times[ i + 1 ];
  20268. // remove adjacent keyframes scheduled at the same time
  20269. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20270. if ( ! smoothInterpolation ) {
  20271. // remove unnecessary keyframes same as their neighbors
  20272. var offset = i * stride,
  20273. offsetP = offset - stride,
  20274. offsetN = offset + stride;
  20275. for ( var j = 0; j !== stride; ++ j ) {
  20276. var value = values[ offset + j ];
  20277. if ( value !== values[ offsetP + j ] ||
  20278. value !== values[ offsetN + j ] ) {
  20279. keep = true;
  20280. break;
  20281. }
  20282. }
  20283. } else {
  20284. keep = true;
  20285. }
  20286. }
  20287. // in-place compaction
  20288. if ( keep ) {
  20289. if ( i !== writeIndex ) {
  20290. times[ writeIndex ] = times[ i ];
  20291. var readOffset = i * stride,
  20292. writeOffset = writeIndex * stride;
  20293. for ( var j = 0; j !== stride; ++ j ) {
  20294. values[ writeOffset + j ] = values[ readOffset + j ];
  20295. }
  20296. }
  20297. ++ writeIndex;
  20298. }
  20299. }
  20300. // flush last keyframe (compaction looks ahead)
  20301. if ( lastIndex > 0 ) {
  20302. times[ writeIndex ] = times[ lastIndex ];
  20303. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20304. values[ writeOffset + j ] = values[ readOffset + j ];
  20305. }
  20306. ++ writeIndex;
  20307. }
  20308. if ( writeIndex !== times.length ) {
  20309. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20310. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20311. }
  20312. return this;
  20313. },
  20314. clone: function () {
  20315. var times = AnimationUtils.arraySlice( this.times, 0 );
  20316. var values = AnimationUtils.arraySlice( this.values, 0 );
  20317. var TypedKeyframeTrack = this.constructor;
  20318. var track = new TypedKeyframeTrack( this.name, times, values );
  20319. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20320. track.createInterpolant = this.createInterpolant;
  20321. return track;
  20322. }
  20323. } );
  20324. /**
  20325. *
  20326. * A Track of Boolean keyframe values.
  20327. *
  20328. *
  20329. * @author Ben Houston / http://clara.io/
  20330. * @author David Sarno / http://lighthaus.us/
  20331. * @author tschw
  20332. */
  20333. function BooleanKeyframeTrack( name, times, values ) {
  20334. KeyframeTrack.call( this, name, times, values );
  20335. }
  20336. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20337. constructor: BooleanKeyframeTrack,
  20338. ValueTypeName: 'bool',
  20339. ValueBufferType: Array,
  20340. DefaultInterpolation: InterpolateDiscrete,
  20341. InterpolantFactoryMethodLinear: undefined,
  20342. InterpolantFactoryMethodSmooth: undefined
  20343. // Note: Actually this track could have a optimized / compressed
  20344. // representation of a single value and a custom interpolant that
  20345. // computes "firstValue ^ isOdd( index )".
  20346. } );
  20347. /**
  20348. *
  20349. * A Track of keyframe values that represent color.
  20350. *
  20351. *
  20352. * @author Ben Houston / http://clara.io/
  20353. * @author David Sarno / http://lighthaus.us/
  20354. * @author tschw
  20355. */
  20356. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20357. KeyframeTrack.call( this, name, times, values, interpolation );
  20358. }
  20359. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20360. constructor: ColorKeyframeTrack,
  20361. ValueTypeName: 'color'
  20362. // ValueBufferType is inherited
  20363. // DefaultInterpolation is inherited
  20364. // Note: Very basic implementation and nothing special yet.
  20365. // However, this is the place for color space parameterization.
  20366. } );
  20367. /**
  20368. *
  20369. * A Track of numeric keyframe values.
  20370. *
  20371. * @author Ben Houston / http://clara.io/
  20372. * @author David Sarno / http://lighthaus.us/
  20373. * @author tschw
  20374. */
  20375. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20376. KeyframeTrack.call( this, name, times, values, interpolation );
  20377. }
  20378. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20379. constructor: NumberKeyframeTrack,
  20380. ValueTypeName: 'number'
  20381. // ValueBufferType is inherited
  20382. // DefaultInterpolation is inherited
  20383. } );
  20384. /**
  20385. * Spherical linear unit quaternion interpolant.
  20386. *
  20387. * @author tschw
  20388. */
  20389. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20390. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20391. }
  20392. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20393. constructor: QuaternionLinearInterpolant,
  20394. interpolate_: function ( i1, t0, t, t1 ) {
  20395. var result = this.resultBuffer,
  20396. values = this.sampleValues,
  20397. stride = this.valueSize,
  20398. offset = i1 * stride,
  20399. alpha = ( t - t0 ) / ( t1 - t0 );
  20400. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20401. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20402. }
  20403. return result;
  20404. }
  20405. } );
  20406. /**
  20407. *
  20408. * A Track of quaternion keyframe values.
  20409. *
  20410. * @author Ben Houston / http://clara.io/
  20411. * @author David Sarno / http://lighthaus.us/
  20412. * @author tschw
  20413. */
  20414. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20415. KeyframeTrack.call( this, name, times, values, interpolation );
  20416. }
  20417. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20418. constructor: QuaternionKeyframeTrack,
  20419. ValueTypeName: 'quaternion',
  20420. // ValueBufferType is inherited
  20421. DefaultInterpolation: InterpolateLinear,
  20422. InterpolantFactoryMethodLinear: function ( result ) {
  20423. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20424. },
  20425. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20426. } );
  20427. /**
  20428. *
  20429. * A Track that interpolates Strings
  20430. *
  20431. *
  20432. * @author Ben Houston / http://clara.io/
  20433. * @author David Sarno / http://lighthaus.us/
  20434. * @author tschw
  20435. */
  20436. function StringKeyframeTrack( name, times, values, interpolation ) {
  20437. KeyframeTrack.call( this, name, times, values, interpolation );
  20438. }
  20439. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20440. constructor: StringKeyframeTrack,
  20441. ValueTypeName: 'string',
  20442. ValueBufferType: Array,
  20443. DefaultInterpolation: InterpolateDiscrete,
  20444. InterpolantFactoryMethodLinear: undefined,
  20445. InterpolantFactoryMethodSmooth: undefined
  20446. } );
  20447. /**
  20448. *
  20449. * A Track of vectored keyframe values.
  20450. *
  20451. *
  20452. * @author Ben Houston / http://clara.io/
  20453. * @author David Sarno / http://lighthaus.us/
  20454. * @author tschw
  20455. */
  20456. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20457. KeyframeTrack.call( this, name, times, values, interpolation );
  20458. }
  20459. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20460. constructor: VectorKeyframeTrack,
  20461. ValueTypeName: 'vector'
  20462. // ValueBufferType is inherited
  20463. // DefaultInterpolation is inherited
  20464. } );
  20465. /**
  20466. *
  20467. * Reusable set of Tracks that represent an animation.
  20468. *
  20469. * @author Ben Houston / http://clara.io/
  20470. * @author David Sarno / http://lighthaus.us/
  20471. */
  20472. function AnimationClip( name, duration, tracks ) {
  20473. this.name = name;
  20474. this.tracks = tracks;
  20475. this.duration = ( duration !== undefined ) ? duration : - 1;
  20476. this.uuid = _Math.generateUUID();
  20477. // this means it should figure out its duration by scanning the tracks
  20478. if ( this.duration < 0 ) {
  20479. this.resetDuration();
  20480. }
  20481. }
  20482. function getTrackTypeForValueTypeName( typeName ) {
  20483. switch ( typeName.toLowerCase() ) {
  20484. case 'scalar':
  20485. case 'double':
  20486. case 'float':
  20487. case 'number':
  20488. case 'integer':
  20489. return NumberKeyframeTrack;
  20490. case 'vector':
  20491. case 'vector2':
  20492. case 'vector3':
  20493. case 'vector4':
  20494. return VectorKeyframeTrack;
  20495. case 'color':
  20496. return ColorKeyframeTrack;
  20497. case 'quaternion':
  20498. return QuaternionKeyframeTrack;
  20499. case 'bool':
  20500. case 'boolean':
  20501. return BooleanKeyframeTrack;
  20502. case 'string':
  20503. return StringKeyframeTrack;
  20504. }
  20505. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20506. }
  20507. function parseKeyframeTrack( json ) {
  20508. if ( json.type === undefined ) {
  20509. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20510. }
  20511. var trackType = getTrackTypeForValueTypeName( json.type );
  20512. if ( json.times === undefined ) {
  20513. var times = [], values = [];
  20514. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20515. json.times = times;
  20516. json.values = values;
  20517. }
  20518. // derived classes can define a static parse method
  20519. if ( trackType.parse !== undefined ) {
  20520. return trackType.parse( json );
  20521. } else {
  20522. // by default, we assume a constructor compatible with the base
  20523. return new trackType( json.name, json.times, json.values, json.interpolation );
  20524. }
  20525. }
  20526. Object.assign( AnimationClip, {
  20527. parse: function ( json ) {
  20528. var tracks = [],
  20529. jsonTracks = json.tracks,
  20530. frameTime = 1.0 / ( json.fps || 1.0 );
  20531. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20532. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20533. }
  20534. return new AnimationClip( json.name, json.duration, tracks );
  20535. },
  20536. toJSON: function ( clip ) {
  20537. var tracks = [],
  20538. clipTracks = clip.tracks;
  20539. var json = {
  20540. 'name': clip.name,
  20541. 'duration': clip.duration,
  20542. 'tracks': tracks,
  20543. 'uuid': clip.uuid
  20544. };
  20545. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20546. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20547. }
  20548. return json;
  20549. },
  20550. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20551. var numMorphTargets = morphTargetSequence.length;
  20552. var tracks = [];
  20553. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20554. var times = [];
  20555. var values = [];
  20556. times.push(
  20557. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20558. i,
  20559. ( i + 1 ) % numMorphTargets );
  20560. values.push( 0, 1, 0 );
  20561. var order = AnimationUtils.getKeyframeOrder( times );
  20562. times = AnimationUtils.sortedArray( times, 1, order );
  20563. values = AnimationUtils.sortedArray( values, 1, order );
  20564. // if there is a key at the first frame, duplicate it as the
  20565. // last frame as well for perfect loop.
  20566. if ( ! noLoop && times[ 0 ] === 0 ) {
  20567. times.push( numMorphTargets );
  20568. values.push( values[ 0 ] );
  20569. }
  20570. tracks.push(
  20571. new NumberKeyframeTrack(
  20572. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20573. times, values
  20574. ).scale( 1.0 / fps ) );
  20575. }
  20576. return new AnimationClip( name, - 1, tracks );
  20577. },
  20578. findByName: function ( objectOrClipArray, name ) {
  20579. var clipArray = objectOrClipArray;
  20580. if ( ! Array.isArray( objectOrClipArray ) ) {
  20581. var o = objectOrClipArray;
  20582. clipArray = o.geometry && o.geometry.animations || o.animations;
  20583. }
  20584. for ( var i = 0; i < clipArray.length; i ++ ) {
  20585. if ( clipArray[ i ].name === name ) {
  20586. return clipArray[ i ];
  20587. }
  20588. }
  20589. return null;
  20590. },
  20591. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20592. var animationToMorphTargets = {};
  20593. // tested with https://regex101.com/ on trick sequences
  20594. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20595. var pattern = /^([\w-]*?)([\d]+)$/;
  20596. // sort morph target names into animation groups based
  20597. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20598. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20599. var morphTarget = morphTargets[ i ];
  20600. var parts = morphTarget.name.match( pattern );
  20601. if ( parts && parts.length > 1 ) {
  20602. var name = parts[ 1 ];
  20603. var animationMorphTargets = animationToMorphTargets[ name ];
  20604. if ( ! animationMorphTargets ) {
  20605. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20606. }
  20607. animationMorphTargets.push( morphTarget );
  20608. }
  20609. }
  20610. var clips = [];
  20611. for ( var name in animationToMorphTargets ) {
  20612. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20613. }
  20614. return clips;
  20615. },
  20616. // parse the animation.hierarchy format
  20617. parseAnimation: function ( animation, bones ) {
  20618. if ( ! animation ) {
  20619. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20620. return null;
  20621. }
  20622. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20623. // only return track if there are actually keys.
  20624. if ( animationKeys.length !== 0 ) {
  20625. var times = [];
  20626. var values = [];
  20627. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20628. // empty keys are filtered out, so check again
  20629. if ( times.length !== 0 ) {
  20630. destTracks.push( new trackType( trackName, times, values ) );
  20631. }
  20632. }
  20633. };
  20634. var tracks = [];
  20635. var clipName = animation.name || 'default';
  20636. // automatic length determination in AnimationClip.
  20637. var duration = animation.length || - 1;
  20638. var fps = animation.fps || 30;
  20639. var hierarchyTracks = animation.hierarchy || [];
  20640. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20641. var animationKeys = hierarchyTracks[ h ].keys;
  20642. // skip empty tracks
  20643. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20644. // process morph targets
  20645. if ( animationKeys[ 0 ].morphTargets ) {
  20646. // figure out all morph targets used in this track
  20647. var morphTargetNames = {};
  20648. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20649. if ( animationKeys[ k ].morphTargets ) {
  20650. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20651. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20652. }
  20653. }
  20654. }
  20655. // create a track for each morph target with all zero
  20656. // morphTargetInfluences except for the keys in which
  20657. // the morphTarget is named.
  20658. for ( var morphTargetName in morphTargetNames ) {
  20659. var times = [];
  20660. var values = [];
  20661. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20662. var animationKey = animationKeys[ k ];
  20663. times.push( animationKey.time );
  20664. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20665. }
  20666. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20667. }
  20668. duration = morphTargetNames.length * ( fps || 1.0 );
  20669. } else {
  20670. // ...assume skeletal animation
  20671. var boneName = '.bones[' + bones[ h ].name + ']';
  20672. addNonemptyTrack(
  20673. VectorKeyframeTrack, boneName + '.position',
  20674. animationKeys, 'pos', tracks );
  20675. addNonemptyTrack(
  20676. QuaternionKeyframeTrack, boneName + '.quaternion',
  20677. animationKeys, 'rot', tracks );
  20678. addNonemptyTrack(
  20679. VectorKeyframeTrack, boneName + '.scale',
  20680. animationKeys, 'scl', tracks );
  20681. }
  20682. }
  20683. if ( tracks.length === 0 ) {
  20684. return null;
  20685. }
  20686. var clip = new AnimationClip( clipName, duration, tracks );
  20687. return clip;
  20688. }
  20689. } );
  20690. Object.assign( AnimationClip.prototype, {
  20691. resetDuration: function () {
  20692. var tracks = this.tracks, duration = 0;
  20693. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20694. var track = this.tracks[ i ];
  20695. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20696. }
  20697. this.duration = duration;
  20698. return this;
  20699. },
  20700. trim: function () {
  20701. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20702. this.tracks[ i ].trim( 0, this.duration );
  20703. }
  20704. return this;
  20705. },
  20706. validate: function () {
  20707. var valid = true;
  20708. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20709. valid = valid && this.tracks[ i ].validate();
  20710. }
  20711. return valid;
  20712. },
  20713. optimize: function () {
  20714. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20715. this.tracks[ i ].optimize();
  20716. }
  20717. return this;
  20718. },
  20719. clone: function () {
  20720. var tracks = [];
  20721. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20722. tracks.push( this.tracks[ i ].clone() );
  20723. }
  20724. return new AnimationClip( this.name, this.duration, tracks );
  20725. }
  20726. } );
  20727. /**
  20728. * @author mrdoob / http://mrdoob.com/
  20729. */
  20730. var Cache = {
  20731. enabled: false,
  20732. files: {},
  20733. add: function ( key, file ) {
  20734. if ( this.enabled === false ) return;
  20735. // console.log( 'THREE.Cache', 'Adding key:', key );
  20736. this.files[ key ] = file;
  20737. },
  20738. get: function ( key ) {
  20739. if ( this.enabled === false ) return;
  20740. // console.log( 'THREE.Cache', 'Checking key:', key );
  20741. return this.files[ key ];
  20742. },
  20743. remove: function ( key ) {
  20744. delete this.files[ key ];
  20745. },
  20746. clear: function () {
  20747. this.files = {};
  20748. }
  20749. };
  20750. /**
  20751. * @author mrdoob / http://mrdoob.com/
  20752. */
  20753. function LoadingManager( onLoad, onProgress, onError ) {
  20754. var scope = this;
  20755. var isLoading = false;
  20756. var itemsLoaded = 0;
  20757. var itemsTotal = 0;
  20758. var urlModifier = undefined;
  20759. // Refer to #5689 for the reason why we don't set .onStart
  20760. // in the constructor
  20761. this.onStart = undefined;
  20762. this.onLoad = onLoad;
  20763. this.onProgress = onProgress;
  20764. this.onError = onError;
  20765. this.itemStart = function ( url ) {
  20766. itemsTotal ++;
  20767. if ( isLoading === false ) {
  20768. if ( scope.onStart !== undefined ) {
  20769. scope.onStart( url, itemsLoaded, itemsTotal );
  20770. }
  20771. }
  20772. isLoading = true;
  20773. };
  20774. this.itemEnd = function ( url ) {
  20775. itemsLoaded ++;
  20776. if ( scope.onProgress !== undefined ) {
  20777. scope.onProgress( url, itemsLoaded, itemsTotal );
  20778. }
  20779. if ( itemsLoaded === itemsTotal ) {
  20780. isLoading = false;
  20781. if ( scope.onLoad !== undefined ) {
  20782. scope.onLoad();
  20783. }
  20784. }
  20785. };
  20786. this.itemError = function ( url ) {
  20787. if ( scope.onError !== undefined ) {
  20788. scope.onError( url );
  20789. }
  20790. };
  20791. this.resolveURL = function ( url ) {
  20792. if ( urlModifier ) {
  20793. return urlModifier( url );
  20794. }
  20795. return url;
  20796. };
  20797. this.setURLModifier = function ( transform ) {
  20798. urlModifier = transform;
  20799. return this;
  20800. };
  20801. }
  20802. var DefaultLoadingManager = new LoadingManager();
  20803. /**
  20804. * @author mrdoob / http://mrdoob.com/
  20805. */
  20806. var loading = {};
  20807. function FileLoader( manager ) {
  20808. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20809. }
  20810. Object.assign( FileLoader.prototype, {
  20811. load: function ( url, onLoad, onProgress, onError ) {
  20812. if ( url === undefined ) url = '';
  20813. if ( this.path !== undefined ) url = this.path + url;
  20814. url = this.manager.resolveURL( url );
  20815. var scope = this;
  20816. var cached = Cache.get( url );
  20817. if ( cached !== undefined ) {
  20818. scope.manager.itemStart( url );
  20819. setTimeout( function () {
  20820. if ( onLoad ) onLoad( cached );
  20821. scope.manager.itemEnd( url );
  20822. }, 0 );
  20823. return cached;
  20824. }
  20825. // Check if request is duplicate
  20826. if ( loading[ url ] !== undefined ) {
  20827. loading[ url ].push( {
  20828. onLoad: onLoad,
  20829. onProgress: onProgress,
  20830. onError: onError
  20831. } );
  20832. return;
  20833. }
  20834. // Check for data: URI
  20835. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20836. var dataUriRegexResult = url.match( dataUriRegex );
  20837. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20838. if ( dataUriRegexResult ) {
  20839. var mimeType = dataUriRegexResult[ 1 ];
  20840. var isBase64 = !! dataUriRegexResult[ 2 ];
  20841. var data = dataUriRegexResult[ 3 ];
  20842. data = decodeURIComponent( data );
  20843. if ( isBase64 ) data = atob( data );
  20844. try {
  20845. var response;
  20846. var responseType = ( this.responseType || '' ).toLowerCase();
  20847. switch ( responseType ) {
  20848. case 'arraybuffer':
  20849. case 'blob':
  20850. var view = new Uint8Array( data.length );
  20851. for ( var i = 0; i < data.length; i ++ ) {
  20852. view[ i ] = data.charCodeAt( i );
  20853. }
  20854. if ( responseType === 'blob' ) {
  20855. response = new Blob( [ view.buffer ], { type: mimeType } );
  20856. } else {
  20857. response = view.buffer;
  20858. }
  20859. break;
  20860. case 'document':
  20861. var parser = new DOMParser();
  20862. response = parser.parseFromString( data, mimeType );
  20863. break;
  20864. case 'json':
  20865. response = JSON.parse( data );
  20866. break;
  20867. default: // 'text' or other
  20868. response = data;
  20869. break;
  20870. }
  20871. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20872. setTimeout( function () {
  20873. if ( onLoad ) onLoad( response );
  20874. scope.manager.itemEnd( url );
  20875. }, 0 );
  20876. } catch ( error ) {
  20877. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20878. setTimeout( function () {
  20879. if ( onError ) onError( error );
  20880. scope.manager.itemError( url );
  20881. scope.manager.itemEnd( url );
  20882. }, 0 );
  20883. }
  20884. } else {
  20885. // Initialise array for duplicate requests
  20886. loading[ url ] = [];
  20887. loading[ url ].push( {
  20888. onLoad: onLoad,
  20889. onProgress: onProgress,
  20890. onError: onError
  20891. } );
  20892. var request = new XMLHttpRequest();
  20893. request.open( 'GET', url, true );
  20894. request.addEventListener( 'load', function ( event ) {
  20895. var response = this.response;
  20896. Cache.add( url, response );
  20897. var callbacks = loading[ url ];
  20898. delete loading[ url ];
  20899. if ( this.status === 200 || this.status === 0 ) {
  20900. // Some browsers return HTTP Status 0 when using non-http protocol
  20901. // e.g. 'file://' or 'data://'. Handle as success.
  20902. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20903. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20904. var callback = callbacks[ i ];
  20905. if ( callback.onLoad ) callback.onLoad( response );
  20906. }
  20907. scope.manager.itemEnd( url );
  20908. } else {
  20909. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20910. var callback = callbacks[ i ];
  20911. if ( callback.onError ) callback.onError( event );
  20912. }
  20913. scope.manager.itemError( url );
  20914. scope.manager.itemEnd( url );
  20915. }
  20916. }, false );
  20917. request.addEventListener( 'progress', function ( event ) {
  20918. var callbacks = loading[ url ];
  20919. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20920. var callback = callbacks[ i ];
  20921. if ( callback.onProgress ) callback.onProgress( event );
  20922. }
  20923. }, false );
  20924. request.addEventListener( 'error', function ( event ) {
  20925. var callbacks = loading[ url ];
  20926. delete loading[ url ];
  20927. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20928. var callback = callbacks[ i ];
  20929. if ( callback.onError ) callback.onError( event );
  20930. }
  20931. scope.manager.itemError( url );
  20932. scope.manager.itemEnd( url );
  20933. }, false );
  20934. request.addEventListener( 'abort', function ( event ) {
  20935. var callbacks = loading[ url ];
  20936. delete loading[ url ];
  20937. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20938. var callback = callbacks[ i ];
  20939. if ( callback.onError ) callback.onError( event );
  20940. }
  20941. scope.manager.itemError( url );
  20942. scope.manager.itemEnd( url );
  20943. }, false );
  20944. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20945. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20946. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20947. for ( var header in this.requestHeader ) {
  20948. request.setRequestHeader( header, this.requestHeader[ header ] );
  20949. }
  20950. request.send( null );
  20951. }
  20952. scope.manager.itemStart( url );
  20953. return request;
  20954. },
  20955. setPath: function ( value ) {
  20956. this.path = value;
  20957. return this;
  20958. },
  20959. setResponseType: function ( value ) {
  20960. this.responseType = value;
  20961. return this;
  20962. },
  20963. setWithCredentials: function ( value ) {
  20964. this.withCredentials = value;
  20965. return this;
  20966. },
  20967. setMimeType: function ( value ) {
  20968. this.mimeType = value;
  20969. return this;
  20970. },
  20971. setRequestHeader: function ( value ) {
  20972. this.requestHeader = value;
  20973. return this;
  20974. }
  20975. } );
  20976. /**
  20977. * @author bhouston / http://clara.io/
  20978. */
  20979. function AnimationLoader( manager ) {
  20980. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20981. }
  20982. Object.assign( AnimationLoader.prototype, {
  20983. load: function ( url, onLoad, onProgress, onError ) {
  20984. var scope = this;
  20985. var loader = new FileLoader( scope.manager );
  20986. loader.setPath( scope.path );
  20987. loader.load( url, function ( text ) {
  20988. onLoad( scope.parse( JSON.parse( text ) ) );
  20989. }, onProgress, onError );
  20990. },
  20991. parse: function ( json ) {
  20992. var animations = [];
  20993. for ( var i = 0; i < json.length; i ++ ) {
  20994. var clip = AnimationClip.parse( json[ i ] );
  20995. animations.push( clip );
  20996. }
  20997. return animations;
  20998. },
  20999. setPath: function ( value ) {
  21000. this.path = value;
  21001. return this;
  21002. }
  21003. } );
  21004. /**
  21005. * @author mrdoob / http://mrdoob.com/
  21006. *
  21007. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21008. */
  21009. function CompressedTextureLoader( manager ) {
  21010. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21011. // override in sub classes
  21012. this._parser = null;
  21013. }
  21014. Object.assign( CompressedTextureLoader.prototype, {
  21015. load: function ( url, onLoad, onProgress, onError ) {
  21016. var scope = this;
  21017. var images = [];
  21018. var texture = new CompressedTexture();
  21019. texture.image = images;
  21020. var loader = new FileLoader( this.manager );
  21021. loader.setPath( this.path );
  21022. loader.setResponseType( 'arraybuffer' );
  21023. function loadTexture( i ) {
  21024. loader.load( url[ i ], function ( buffer ) {
  21025. var texDatas = scope._parser( buffer, true );
  21026. images[ i ] = {
  21027. width: texDatas.width,
  21028. height: texDatas.height,
  21029. format: texDatas.format,
  21030. mipmaps: texDatas.mipmaps
  21031. };
  21032. loaded += 1;
  21033. if ( loaded === 6 ) {
  21034. if ( texDatas.mipmapCount === 1 )
  21035. texture.minFilter = LinearFilter;
  21036. texture.format = texDatas.format;
  21037. texture.needsUpdate = true;
  21038. if ( onLoad ) onLoad( texture );
  21039. }
  21040. }, onProgress, onError );
  21041. }
  21042. if ( Array.isArray( url ) ) {
  21043. var loaded = 0;
  21044. for ( var i = 0, il = url.length; i < il; ++ i ) {
  21045. loadTexture( i );
  21046. }
  21047. } else {
  21048. // compressed cubemap texture stored in a single DDS file
  21049. loader.load( url, function ( buffer ) {
  21050. var texDatas = scope._parser( buffer, true );
  21051. if ( texDatas.isCubemap ) {
  21052. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21053. for ( var f = 0; f < faces; f ++ ) {
  21054. images[ f ] = { mipmaps: [] };
  21055. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  21056. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  21057. images[ f ].format = texDatas.format;
  21058. images[ f ].width = texDatas.width;
  21059. images[ f ].height = texDatas.height;
  21060. }
  21061. }
  21062. } else {
  21063. texture.image.width = texDatas.width;
  21064. texture.image.height = texDatas.height;
  21065. texture.mipmaps = texDatas.mipmaps;
  21066. }
  21067. if ( texDatas.mipmapCount === 1 ) {
  21068. texture.minFilter = LinearFilter;
  21069. }
  21070. texture.format = texDatas.format;
  21071. texture.needsUpdate = true;
  21072. if ( onLoad ) onLoad( texture );
  21073. }, onProgress, onError );
  21074. }
  21075. return texture;
  21076. },
  21077. setPath: function ( value ) {
  21078. this.path = value;
  21079. return this;
  21080. }
  21081. } );
  21082. /**
  21083. * @author Nikos M. / https://github.com/foo123/
  21084. *
  21085. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21086. */
  21087. function DataTextureLoader( manager ) {
  21088. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21089. // override in sub classes
  21090. this._parser = null;
  21091. }
  21092. Object.assign( DataTextureLoader.prototype, {
  21093. load: function ( url, onLoad, onProgress, onError ) {
  21094. var scope = this;
  21095. var texture = new DataTexture();
  21096. var loader = new FileLoader( this.manager );
  21097. loader.setResponseType( 'arraybuffer' );
  21098. loader.setPath( this.path );
  21099. loader.load( url, function ( buffer ) {
  21100. var texData = scope._parser( buffer );
  21101. if ( ! texData ) return;
  21102. if ( texData.image !== undefined ) {
  21103. texture.image = texData.image;
  21104. } else if ( texData.data !== undefined ) {
  21105. texture.image.width = texData.width;
  21106. texture.image.height = texData.height;
  21107. texture.image.data = texData.data;
  21108. }
  21109. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21110. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21111. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21112. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipmapLinearFilter;
  21113. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21114. if ( texData.format !== undefined ) {
  21115. texture.format = texData.format;
  21116. }
  21117. if ( texData.type !== undefined ) {
  21118. texture.type = texData.type;
  21119. }
  21120. if ( texData.mipmaps !== undefined ) {
  21121. texture.mipmaps = texData.mipmaps;
  21122. }
  21123. if ( texData.mipmapCount === 1 ) {
  21124. texture.minFilter = LinearFilter;
  21125. }
  21126. texture.needsUpdate = true;
  21127. if ( onLoad ) onLoad( texture, texData );
  21128. }, onProgress, onError );
  21129. return texture;
  21130. },
  21131. setPath: function ( value ) {
  21132. this.path = value;
  21133. return this;
  21134. }
  21135. } );
  21136. /**
  21137. * @author mrdoob / http://mrdoob.com/
  21138. */
  21139. function ImageLoader( manager ) {
  21140. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21141. }
  21142. Object.assign( ImageLoader.prototype, {
  21143. crossOrigin: 'anonymous',
  21144. load: function ( url, onLoad, onProgress, onError ) {
  21145. if ( url === undefined ) url = '';
  21146. if ( this.path !== undefined ) url = this.path + url;
  21147. url = this.manager.resolveURL( url );
  21148. var scope = this;
  21149. var cached = Cache.get( url );
  21150. if ( cached !== undefined ) {
  21151. scope.manager.itemStart( url );
  21152. setTimeout( function () {
  21153. if ( onLoad ) onLoad( cached );
  21154. scope.manager.itemEnd( url );
  21155. }, 0 );
  21156. return cached;
  21157. }
  21158. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  21159. function onImageLoad() {
  21160. image.removeEventListener( 'load', onImageLoad, false );
  21161. image.removeEventListener( 'error', onImageError, false );
  21162. Cache.add( url, this );
  21163. if ( onLoad ) onLoad( this );
  21164. scope.manager.itemEnd( url );
  21165. }
  21166. function onImageError( event ) {
  21167. image.removeEventListener( 'load', onImageLoad, false );
  21168. image.removeEventListener( 'error', onImageError, false );
  21169. if ( onError ) onError( event );
  21170. scope.manager.itemError( url );
  21171. scope.manager.itemEnd( url );
  21172. }
  21173. image.addEventListener( 'load', onImageLoad, false );
  21174. image.addEventListener( 'error', onImageError, false );
  21175. if ( url.substr( 0, 5 ) !== 'data:' ) {
  21176. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  21177. }
  21178. scope.manager.itemStart( url );
  21179. image.src = url;
  21180. return image;
  21181. },
  21182. setCrossOrigin: function ( value ) {
  21183. this.crossOrigin = value;
  21184. return this;
  21185. },
  21186. setPath: function ( value ) {
  21187. this.path = value;
  21188. return this;
  21189. }
  21190. } );
  21191. /**
  21192. * @author mrdoob / http://mrdoob.com/
  21193. */
  21194. function CubeTextureLoader( manager ) {
  21195. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21196. }
  21197. Object.assign( CubeTextureLoader.prototype, {
  21198. crossOrigin: 'anonymous',
  21199. load: function ( urls, onLoad, onProgress, onError ) {
  21200. var texture = new CubeTexture();
  21201. var loader = new ImageLoader( this.manager );
  21202. loader.setCrossOrigin( this.crossOrigin );
  21203. loader.setPath( this.path );
  21204. var loaded = 0;
  21205. function loadTexture( i ) {
  21206. loader.load( urls[ i ], function ( image ) {
  21207. texture.images[ i ] = image;
  21208. loaded ++;
  21209. if ( loaded === 6 ) {
  21210. texture.needsUpdate = true;
  21211. if ( onLoad ) onLoad( texture );
  21212. }
  21213. }, undefined, onError );
  21214. }
  21215. for ( var i = 0; i < urls.length; ++ i ) {
  21216. loadTexture( i );
  21217. }
  21218. return texture;
  21219. },
  21220. setCrossOrigin: function ( value ) {
  21221. this.crossOrigin = value;
  21222. return this;
  21223. },
  21224. setPath: function ( value ) {
  21225. this.path = value;
  21226. return this;
  21227. }
  21228. } );
  21229. /**
  21230. * @author mrdoob / http://mrdoob.com/
  21231. */
  21232. function TextureLoader( manager ) {
  21233. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21234. }
  21235. Object.assign( TextureLoader.prototype, {
  21236. crossOrigin: 'anonymous',
  21237. load: function ( url, onLoad, onProgress, onError ) {
  21238. var texture = new Texture();
  21239. var loader = new ImageLoader( this.manager );
  21240. loader.setCrossOrigin( this.crossOrigin );
  21241. loader.setPath( this.path );
  21242. loader.load( url, function ( image ) {
  21243. texture.image = image;
  21244. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21245. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  21246. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21247. texture.needsUpdate = true;
  21248. if ( onLoad !== undefined ) {
  21249. onLoad( texture );
  21250. }
  21251. }, onProgress, onError );
  21252. return texture;
  21253. },
  21254. setCrossOrigin: function ( value ) {
  21255. this.crossOrigin = value;
  21256. return this;
  21257. },
  21258. setPath: function ( value ) {
  21259. this.path = value;
  21260. return this;
  21261. }
  21262. } );
  21263. /**
  21264. * @author zz85 / http://www.lab4games.net/zz85/blog
  21265. * Extensible curve object
  21266. *
  21267. * Some common of curve methods:
  21268. * .getPoint( t, optionalTarget ), .getTangent( t )
  21269. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  21270. * .getPoints(), .getSpacedPoints()
  21271. * .getLength()
  21272. * .updateArcLengths()
  21273. *
  21274. * This following curves inherit from THREE.Curve:
  21275. *
  21276. * -- 2D curves --
  21277. * THREE.ArcCurve
  21278. * THREE.CubicBezierCurve
  21279. * THREE.EllipseCurve
  21280. * THREE.LineCurve
  21281. * THREE.QuadraticBezierCurve
  21282. * THREE.SplineCurve
  21283. *
  21284. * -- 3D curves --
  21285. * THREE.CatmullRomCurve3
  21286. * THREE.CubicBezierCurve3
  21287. * THREE.LineCurve3
  21288. * THREE.QuadraticBezierCurve3
  21289. *
  21290. * A series of curves can be represented as a THREE.CurvePath.
  21291. *
  21292. **/
  21293. /**************************************************************
  21294. * Abstract Curve base class
  21295. **************************************************************/
  21296. function Curve() {
  21297. this.type = 'Curve';
  21298. this.arcLengthDivisions = 200;
  21299. }
  21300. Object.assign( Curve.prototype, {
  21301. // Virtual base class method to overwrite and implement in subclasses
  21302. // - t [0 .. 1]
  21303. getPoint: function ( /* t, optionalTarget */ ) {
  21304. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21305. return null;
  21306. },
  21307. // Get point at relative position in curve according to arc length
  21308. // - u [0 .. 1]
  21309. getPointAt: function ( u, optionalTarget ) {
  21310. var t = this.getUtoTmapping( u );
  21311. return this.getPoint( t, optionalTarget );
  21312. },
  21313. // Get sequence of points using getPoint( t )
  21314. getPoints: function ( divisions ) {
  21315. if ( divisions === undefined ) divisions = 5;
  21316. var points = [];
  21317. for ( var d = 0; d <= divisions; d ++ ) {
  21318. points.push( this.getPoint( d / divisions ) );
  21319. }
  21320. return points;
  21321. },
  21322. // Get sequence of points using getPointAt( u )
  21323. getSpacedPoints: function ( divisions ) {
  21324. if ( divisions === undefined ) divisions = 5;
  21325. var points = [];
  21326. for ( var d = 0; d <= divisions; d ++ ) {
  21327. points.push( this.getPointAt( d / divisions ) );
  21328. }
  21329. return points;
  21330. },
  21331. // Get total curve arc length
  21332. getLength: function () {
  21333. var lengths = this.getLengths();
  21334. return lengths[ lengths.length - 1 ];
  21335. },
  21336. // Get list of cumulative segment lengths
  21337. getLengths: function ( divisions ) {
  21338. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21339. if ( this.cacheArcLengths &&
  21340. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21341. ! this.needsUpdate ) {
  21342. return this.cacheArcLengths;
  21343. }
  21344. this.needsUpdate = false;
  21345. var cache = [];
  21346. var current, last = this.getPoint( 0 );
  21347. var p, sum = 0;
  21348. cache.push( 0 );
  21349. for ( p = 1; p <= divisions; p ++ ) {
  21350. current = this.getPoint( p / divisions );
  21351. sum += current.distanceTo( last );
  21352. cache.push( sum );
  21353. last = current;
  21354. }
  21355. this.cacheArcLengths = cache;
  21356. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21357. },
  21358. updateArcLengths: function () {
  21359. this.needsUpdate = true;
  21360. this.getLengths();
  21361. },
  21362. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21363. getUtoTmapping: function ( u, distance ) {
  21364. var arcLengths = this.getLengths();
  21365. var i = 0, il = arcLengths.length;
  21366. var targetArcLength; // The targeted u distance value to get
  21367. if ( distance ) {
  21368. targetArcLength = distance;
  21369. } else {
  21370. targetArcLength = u * arcLengths[ il - 1 ];
  21371. }
  21372. // binary search for the index with largest value smaller than target u distance
  21373. var low = 0, high = il - 1, comparison;
  21374. while ( low <= high ) {
  21375. 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
  21376. comparison = arcLengths[ i ] - targetArcLength;
  21377. if ( comparison < 0 ) {
  21378. low = i + 1;
  21379. } else if ( comparison > 0 ) {
  21380. high = i - 1;
  21381. } else {
  21382. high = i;
  21383. break;
  21384. // DONE
  21385. }
  21386. }
  21387. i = high;
  21388. if ( arcLengths[ i ] === targetArcLength ) {
  21389. return i / ( il - 1 );
  21390. }
  21391. // we could get finer grain at lengths, or use simple interpolation between two points
  21392. var lengthBefore = arcLengths[ i ];
  21393. var lengthAfter = arcLengths[ i + 1 ];
  21394. var segmentLength = lengthAfter - lengthBefore;
  21395. // determine where we are between the 'before' and 'after' points
  21396. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21397. // add that fractional amount to t
  21398. var t = ( i + segmentFraction ) / ( il - 1 );
  21399. return t;
  21400. },
  21401. // Returns a unit vector tangent at t
  21402. // In case any sub curve does not implement its tangent derivation,
  21403. // 2 points a small delta apart will be used to find its gradient
  21404. // which seems to give a reasonable approximation
  21405. getTangent: function ( t ) {
  21406. var delta = 0.0001;
  21407. var t1 = t - delta;
  21408. var t2 = t + delta;
  21409. // Capping in case of danger
  21410. if ( t1 < 0 ) t1 = 0;
  21411. if ( t2 > 1 ) t2 = 1;
  21412. var pt1 = this.getPoint( t1 );
  21413. var pt2 = this.getPoint( t2 );
  21414. var vec = pt2.clone().sub( pt1 );
  21415. return vec.normalize();
  21416. },
  21417. getTangentAt: function ( u ) {
  21418. var t = this.getUtoTmapping( u );
  21419. return this.getTangent( t );
  21420. },
  21421. computeFrenetFrames: function ( segments, closed ) {
  21422. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21423. var normal = new Vector3();
  21424. var tangents = [];
  21425. var normals = [];
  21426. var binormals = [];
  21427. var vec = new Vector3();
  21428. var mat = new Matrix4();
  21429. var i, u, theta;
  21430. // compute the tangent vectors for each segment on the curve
  21431. for ( i = 0; i <= segments; i ++ ) {
  21432. u = i / segments;
  21433. tangents[ i ] = this.getTangentAt( u );
  21434. tangents[ i ].normalize();
  21435. }
  21436. // select an initial normal vector perpendicular to the first tangent vector,
  21437. // and in the direction of the minimum tangent xyz component
  21438. normals[ 0 ] = new Vector3();
  21439. binormals[ 0 ] = new Vector3();
  21440. var min = Number.MAX_VALUE;
  21441. var tx = Math.abs( tangents[ 0 ].x );
  21442. var ty = Math.abs( tangents[ 0 ].y );
  21443. var tz = Math.abs( tangents[ 0 ].z );
  21444. if ( tx <= min ) {
  21445. min = tx;
  21446. normal.set( 1, 0, 0 );
  21447. }
  21448. if ( ty <= min ) {
  21449. min = ty;
  21450. normal.set( 0, 1, 0 );
  21451. }
  21452. if ( tz <= min ) {
  21453. normal.set( 0, 0, 1 );
  21454. }
  21455. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21456. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21457. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21458. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21459. for ( i = 1; i <= segments; i ++ ) {
  21460. normals[ i ] = normals[ i - 1 ].clone();
  21461. binormals[ i ] = binormals[ i - 1 ].clone();
  21462. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21463. if ( vec.length() > Number.EPSILON ) {
  21464. vec.normalize();
  21465. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21466. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21467. }
  21468. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21469. }
  21470. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21471. if ( closed === true ) {
  21472. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21473. theta /= segments;
  21474. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21475. theta = - theta;
  21476. }
  21477. for ( i = 1; i <= segments; i ++ ) {
  21478. // twist a little...
  21479. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21480. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21481. }
  21482. }
  21483. return {
  21484. tangents: tangents,
  21485. normals: normals,
  21486. binormals: binormals
  21487. };
  21488. },
  21489. clone: function () {
  21490. return new this.constructor().copy( this );
  21491. },
  21492. copy: function ( source ) {
  21493. this.arcLengthDivisions = source.arcLengthDivisions;
  21494. return this;
  21495. },
  21496. toJSON: function () {
  21497. var data = {
  21498. metadata: {
  21499. version: 4.5,
  21500. type: 'Curve',
  21501. generator: 'Curve.toJSON'
  21502. }
  21503. };
  21504. data.arcLengthDivisions = this.arcLengthDivisions;
  21505. data.type = this.type;
  21506. return data;
  21507. },
  21508. fromJSON: function ( json ) {
  21509. this.arcLengthDivisions = json.arcLengthDivisions;
  21510. return this;
  21511. }
  21512. } );
  21513. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21514. Curve.call( this );
  21515. this.type = 'EllipseCurve';
  21516. this.aX = aX || 0;
  21517. this.aY = aY || 0;
  21518. this.xRadius = xRadius || 1;
  21519. this.yRadius = yRadius || 1;
  21520. this.aStartAngle = aStartAngle || 0;
  21521. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21522. this.aClockwise = aClockwise || false;
  21523. this.aRotation = aRotation || 0;
  21524. }
  21525. EllipseCurve.prototype = Object.create( Curve.prototype );
  21526. EllipseCurve.prototype.constructor = EllipseCurve;
  21527. EllipseCurve.prototype.isEllipseCurve = true;
  21528. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21529. var point = optionalTarget || new Vector2();
  21530. var twoPi = Math.PI * 2;
  21531. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21532. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21533. // ensures that deltaAngle is 0 .. 2 PI
  21534. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21535. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21536. if ( deltaAngle < Number.EPSILON ) {
  21537. if ( samePoints ) {
  21538. deltaAngle = 0;
  21539. } else {
  21540. deltaAngle = twoPi;
  21541. }
  21542. }
  21543. if ( this.aClockwise === true && ! samePoints ) {
  21544. if ( deltaAngle === twoPi ) {
  21545. deltaAngle = - twoPi;
  21546. } else {
  21547. deltaAngle = deltaAngle - twoPi;
  21548. }
  21549. }
  21550. var angle = this.aStartAngle + t * deltaAngle;
  21551. var x = this.aX + this.xRadius * Math.cos( angle );
  21552. var y = this.aY + this.yRadius * Math.sin( angle );
  21553. if ( this.aRotation !== 0 ) {
  21554. var cos = Math.cos( this.aRotation );
  21555. var sin = Math.sin( this.aRotation );
  21556. var tx = x - this.aX;
  21557. var ty = y - this.aY;
  21558. // Rotate the point about the center of the ellipse.
  21559. x = tx * cos - ty * sin + this.aX;
  21560. y = tx * sin + ty * cos + this.aY;
  21561. }
  21562. return point.set( x, y );
  21563. };
  21564. EllipseCurve.prototype.copy = function ( source ) {
  21565. Curve.prototype.copy.call( this, source );
  21566. this.aX = source.aX;
  21567. this.aY = source.aY;
  21568. this.xRadius = source.xRadius;
  21569. this.yRadius = source.yRadius;
  21570. this.aStartAngle = source.aStartAngle;
  21571. this.aEndAngle = source.aEndAngle;
  21572. this.aClockwise = source.aClockwise;
  21573. this.aRotation = source.aRotation;
  21574. return this;
  21575. };
  21576. EllipseCurve.prototype.toJSON = function () {
  21577. var data = Curve.prototype.toJSON.call( this );
  21578. data.aX = this.aX;
  21579. data.aY = this.aY;
  21580. data.xRadius = this.xRadius;
  21581. data.yRadius = this.yRadius;
  21582. data.aStartAngle = this.aStartAngle;
  21583. data.aEndAngle = this.aEndAngle;
  21584. data.aClockwise = this.aClockwise;
  21585. data.aRotation = this.aRotation;
  21586. return data;
  21587. };
  21588. EllipseCurve.prototype.fromJSON = function ( json ) {
  21589. Curve.prototype.fromJSON.call( this, json );
  21590. this.aX = json.aX;
  21591. this.aY = json.aY;
  21592. this.xRadius = json.xRadius;
  21593. this.yRadius = json.yRadius;
  21594. this.aStartAngle = json.aStartAngle;
  21595. this.aEndAngle = json.aEndAngle;
  21596. this.aClockwise = json.aClockwise;
  21597. this.aRotation = json.aRotation;
  21598. return this;
  21599. };
  21600. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21601. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21602. this.type = 'ArcCurve';
  21603. }
  21604. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21605. ArcCurve.prototype.constructor = ArcCurve;
  21606. ArcCurve.prototype.isArcCurve = true;
  21607. /**
  21608. * @author zz85 https://github.com/zz85
  21609. *
  21610. * Centripetal CatmullRom Curve - which is useful for avoiding
  21611. * cusps and self-intersections in non-uniform catmull rom curves.
  21612. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21613. *
  21614. * curve.type accepts centripetal(default), chordal and catmullrom
  21615. * curve.tension is used for catmullrom which defaults to 0.5
  21616. */
  21617. /*
  21618. Based on an optimized c++ solution in
  21619. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21620. - http://ideone.com/NoEbVM
  21621. This CubicPoly class could be used for reusing some variables and calculations,
  21622. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21623. which can be placed in CurveUtils.
  21624. */
  21625. function CubicPoly() {
  21626. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21627. /*
  21628. * Compute coefficients for a cubic polynomial
  21629. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21630. * such that
  21631. * p(0) = x0, p(1) = x1
  21632. * and
  21633. * p'(0) = t0, p'(1) = t1.
  21634. */
  21635. function init( x0, x1, t0, t1 ) {
  21636. c0 = x0;
  21637. c1 = t0;
  21638. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21639. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21640. }
  21641. return {
  21642. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21643. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21644. },
  21645. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21646. // compute tangents when parameterized in [t1,t2]
  21647. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21648. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21649. // rescale tangents for parametrization in [0,1]
  21650. t1 *= dt1;
  21651. t2 *= dt1;
  21652. init( x1, x2, t1, t2 );
  21653. },
  21654. calc: function ( t ) {
  21655. var t2 = t * t;
  21656. var t3 = t2 * t;
  21657. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21658. }
  21659. };
  21660. }
  21661. //
  21662. var tmp = new Vector3();
  21663. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21664. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21665. Curve.call( this );
  21666. this.type = 'CatmullRomCurve3';
  21667. this.points = points || [];
  21668. this.closed = closed || false;
  21669. this.curveType = curveType || 'centripetal';
  21670. this.tension = tension || 0.5;
  21671. }
  21672. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21673. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21674. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21675. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21676. var point = optionalTarget || new Vector3();
  21677. var points = this.points;
  21678. var l = points.length;
  21679. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21680. var intPoint = Math.floor( p );
  21681. var weight = p - intPoint;
  21682. if ( this.closed ) {
  21683. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21684. } else if ( weight === 0 && intPoint === l - 1 ) {
  21685. intPoint = l - 2;
  21686. weight = 1;
  21687. }
  21688. var p0, p1, p2, p3; // 4 points
  21689. if ( this.closed || intPoint > 0 ) {
  21690. p0 = points[ ( intPoint - 1 ) % l ];
  21691. } else {
  21692. // extrapolate first point
  21693. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21694. p0 = tmp;
  21695. }
  21696. p1 = points[ intPoint % l ];
  21697. p2 = points[ ( intPoint + 1 ) % l ];
  21698. if ( this.closed || intPoint + 2 < l ) {
  21699. p3 = points[ ( intPoint + 2 ) % l ];
  21700. } else {
  21701. // extrapolate last point
  21702. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21703. p3 = tmp;
  21704. }
  21705. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21706. // init Centripetal / Chordal Catmull-Rom
  21707. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21708. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21709. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21710. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21711. // safety check for repeated points
  21712. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21713. if ( dt0 < 1e-4 ) dt0 = dt1;
  21714. if ( dt2 < 1e-4 ) dt2 = dt1;
  21715. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21716. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21717. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21718. } else if ( this.curveType === 'catmullrom' ) {
  21719. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21720. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21721. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21722. }
  21723. point.set(
  21724. px.calc( weight ),
  21725. py.calc( weight ),
  21726. pz.calc( weight )
  21727. );
  21728. return point;
  21729. };
  21730. CatmullRomCurve3.prototype.copy = function ( source ) {
  21731. Curve.prototype.copy.call( this, source );
  21732. this.points = [];
  21733. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21734. var point = source.points[ i ];
  21735. this.points.push( point.clone() );
  21736. }
  21737. this.closed = source.closed;
  21738. this.curveType = source.curveType;
  21739. this.tension = source.tension;
  21740. return this;
  21741. };
  21742. CatmullRomCurve3.prototype.toJSON = function () {
  21743. var data = Curve.prototype.toJSON.call( this );
  21744. data.points = [];
  21745. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21746. var point = this.points[ i ];
  21747. data.points.push( point.toArray() );
  21748. }
  21749. data.closed = this.closed;
  21750. data.curveType = this.curveType;
  21751. data.tension = this.tension;
  21752. return data;
  21753. };
  21754. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21755. Curve.prototype.fromJSON.call( this, json );
  21756. this.points = [];
  21757. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21758. var point = json.points[ i ];
  21759. this.points.push( new Vector3().fromArray( point ) );
  21760. }
  21761. this.closed = json.closed;
  21762. this.curveType = json.curveType;
  21763. this.tension = json.tension;
  21764. return this;
  21765. };
  21766. /**
  21767. * @author zz85 / http://www.lab4games.net/zz85/blog
  21768. *
  21769. * Bezier Curves formulas obtained from
  21770. * http://en.wikipedia.org/wiki/Bézier_curve
  21771. */
  21772. function CatmullRom( t, p0, p1, p2, p3 ) {
  21773. var v0 = ( p2 - p0 ) * 0.5;
  21774. var v1 = ( p3 - p1 ) * 0.5;
  21775. var t2 = t * t;
  21776. var t3 = t * t2;
  21777. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21778. }
  21779. //
  21780. function QuadraticBezierP0( t, p ) {
  21781. var k = 1 - t;
  21782. return k * k * p;
  21783. }
  21784. function QuadraticBezierP1( t, p ) {
  21785. return 2 * ( 1 - t ) * t * p;
  21786. }
  21787. function QuadraticBezierP2( t, p ) {
  21788. return t * t * p;
  21789. }
  21790. function QuadraticBezier( t, p0, p1, p2 ) {
  21791. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21792. QuadraticBezierP2( t, p2 );
  21793. }
  21794. //
  21795. function CubicBezierP0( t, p ) {
  21796. var k = 1 - t;
  21797. return k * k * k * p;
  21798. }
  21799. function CubicBezierP1( t, p ) {
  21800. var k = 1 - t;
  21801. return 3 * k * k * t * p;
  21802. }
  21803. function CubicBezierP2( t, p ) {
  21804. return 3 * ( 1 - t ) * t * t * p;
  21805. }
  21806. function CubicBezierP3( t, p ) {
  21807. return t * t * t * p;
  21808. }
  21809. function CubicBezier( t, p0, p1, p2, p3 ) {
  21810. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21811. CubicBezierP3( t, p3 );
  21812. }
  21813. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21814. Curve.call( this );
  21815. this.type = 'CubicBezierCurve';
  21816. this.v0 = v0 || new Vector2();
  21817. this.v1 = v1 || new Vector2();
  21818. this.v2 = v2 || new Vector2();
  21819. this.v3 = v3 || new Vector2();
  21820. }
  21821. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21822. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21823. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21824. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21825. var point = optionalTarget || new Vector2();
  21826. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21827. point.set(
  21828. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21829. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21830. );
  21831. return point;
  21832. };
  21833. CubicBezierCurve.prototype.copy = function ( source ) {
  21834. Curve.prototype.copy.call( this, source );
  21835. this.v0.copy( source.v0 );
  21836. this.v1.copy( source.v1 );
  21837. this.v2.copy( source.v2 );
  21838. this.v3.copy( source.v3 );
  21839. return this;
  21840. };
  21841. CubicBezierCurve.prototype.toJSON = function () {
  21842. var data = Curve.prototype.toJSON.call( this );
  21843. data.v0 = this.v0.toArray();
  21844. data.v1 = this.v1.toArray();
  21845. data.v2 = this.v2.toArray();
  21846. data.v3 = this.v3.toArray();
  21847. return data;
  21848. };
  21849. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21850. Curve.prototype.fromJSON.call( this, json );
  21851. this.v0.fromArray( json.v0 );
  21852. this.v1.fromArray( json.v1 );
  21853. this.v2.fromArray( json.v2 );
  21854. this.v3.fromArray( json.v3 );
  21855. return this;
  21856. };
  21857. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21858. Curve.call( this );
  21859. this.type = 'CubicBezierCurve3';
  21860. this.v0 = v0 || new Vector3();
  21861. this.v1 = v1 || new Vector3();
  21862. this.v2 = v2 || new Vector3();
  21863. this.v3 = v3 || new Vector3();
  21864. }
  21865. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21866. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21867. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21868. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21869. var point = optionalTarget || new Vector3();
  21870. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21871. point.set(
  21872. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21873. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21874. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21875. );
  21876. return point;
  21877. };
  21878. CubicBezierCurve3.prototype.copy = function ( source ) {
  21879. Curve.prototype.copy.call( this, source );
  21880. this.v0.copy( source.v0 );
  21881. this.v1.copy( source.v1 );
  21882. this.v2.copy( source.v2 );
  21883. this.v3.copy( source.v3 );
  21884. return this;
  21885. };
  21886. CubicBezierCurve3.prototype.toJSON = function () {
  21887. var data = Curve.prototype.toJSON.call( this );
  21888. data.v0 = this.v0.toArray();
  21889. data.v1 = this.v1.toArray();
  21890. data.v2 = this.v2.toArray();
  21891. data.v3 = this.v3.toArray();
  21892. return data;
  21893. };
  21894. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21895. Curve.prototype.fromJSON.call( this, json );
  21896. this.v0.fromArray( json.v0 );
  21897. this.v1.fromArray( json.v1 );
  21898. this.v2.fromArray( json.v2 );
  21899. this.v3.fromArray( json.v3 );
  21900. return this;
  21901. };
  21902. function LineCurve( v1, v2 ) {
  21903. Curve.call( this );
  21904. this.type = 'LineCurve';
  21905. this.v1 = v1 || new Vector2();
  21906. this.v2 = v2 || new Vector2();
  21907. }
  21908. LineCurve.prototype = Object.create( Curve.prototype );
  21909. LineCurve.prototype.constructor = LineCurve;
  21910. LineCurve.prototype.isLineCurve = true;
  21911. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21912. var point = optionalTarget || new Vector2();
  21913. if ( t === 1 ) {
  21914. point.copy( this.v2 );
  21915. } else {
  21916. point.copy( this.v2 ).sub( this.v1 );
  21917. point.multiplyScalar( t ).add( this.v1 );
  21918. }
  21919. return point;
  21920. };
  21921. // Line curve is linear, so we can overwrite default getPointAt
  21922. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21923. return this.getPoint( u, optionalTarget );
  21924. };
  21925. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21926. var tangent = this.v2.clone().sub( this.v1 );
  21927. return tangent.normalize();
  21928. };
  21929. LineCurve.prototype.copy = function ( source ) {
  21930. Curve.prototype.copy.call( this, source );
  21931. this.v1.copy( source.v1 );
  21932. this.v2.copy( source.v2 );
  21933. return this;
  21934. };
  21935. LineCurve.prototype.toJSON = function () {
  21936. var data = Curve.prototype.toJSON.call( this );
  21937. data.v1 = this.v1.toArray();
  21938. data.v2 = this.v2.toArray();
  21939. return data;
  21940. };
  21941. LineCurve.prototype.fromJSON = function ( json ) {
  21942. Curve.prototype.fromJSON.call( this, json );
  21943. this.v1.fromArray( json.v1 );
  21944. this.v2.fromArray( json.v2 );
  21945. return this;
  21946. };
  21947. function LineCurve3( v1, v2 ) {
  21948. Curve.call( this );
  21949. this.type = 'LineCurve3';
  21950. this.v1 = v1 || new Vector3();
  21951. this.v2 = v2 || new Vector3();
  21952. }
  21953. LineCurve3.prototype = Object.create( Curve.prototype );
  21954. LineCurve3.prototype.constructor = LineCurve3;
  21955. LineCurve3.prototype.isLineCurve3 = true;
  21956. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21957. var point = optionalTarget || new Vector3();
  21958. if ( t === 1 ) {
  21959. point.copy( this.v2 );
  21960. } else {
  21961. point.copy( this.v2 ).sub( this.v1 );
  21962. point.multiplyScalar( t ).add( this.v1 );
  21963. }
  21964. return point;
  21965. };
  21966. // Line curve is linear, so we can overwrite default getPointAt
  21967. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21968. return this.getPoint( u, optionalTarget );
  21969. };
  21970. LineCurve3.prototype.copy = function ( source ) {
  21971. Curve.prototype.copy.call( this, source );
  21972. this.v1.copy( source.v1 );
  21973. this.v2.copy( source.v2 );
  21974. return this;
  21975. };
  21976. LineCurve3.prototype.toJSON = function () {
  21977. var data = Curve.prototype.toJSON.call( this );
  21978. data.v1 = this.v1.toArray();
  21979. data.v2 = this.v2.toArray();
  21980. return data;
  21981. };
  21982. LineCurve3.prototype.fromJSON = function ( json ) {
  21983. Curve.prototype.fromJSON.call( this, json );
  21984. this.v1.fromArray( json.v1 );
  21985. this.v2.fromArray( json.v2 );
  21986. return this;
  21987. };
  21988. function QuadraticBezierCurve( v0, v1, v2 ) {
  21989. Curve.call( this );
  21990. this.type = 'QuadraticBezierCurve';
  21991. this.v0 = v0 || new Vector2();
  21992. this.v1 = v1 || new Vector2();
  21993. this.v2 = v2 || new Vector2();
  21994. }
  21995. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21996. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21997. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21998. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21999. var point = optionalTarget || new Vector2();
  22000. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22001. point.set(
  22002. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22003. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22004. );
  22005. return point;
  22006. };
  22007. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22008. Curve.prototype.copy.call( this, source );
  22009. this.v0.copy( source.v0 );
  22010. this.v1.copy( source.v1 );
  22011. this.v2.copy( source.v2 );
  22012. return this;
  22013. };
  22014. QuadraticBezierCurve.prototype.toJSON = function () {
  22015. var data = Curve.prototype.toJSON.call( this );
  22016. data.v0 = this.v0.toArray();
  22017. data.v1 = this.v1.toArray();
  22018. data.v2 = this.v2.toArray();
  22019. return data;
  22020. };
  22021. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22022. Curve.prototype.fromJSON.call( this, json );
  22023. this.v0.fromArray( json.v0 );
  22024. this.v1.fromArray( json.v1 );
  22025. this.v2.fromArray( json.v2 );
  22026. return this;
  22027. };
  22028. function QuadraticBezierCurve3( v0, v1, v2 ) {
  22029. Curve.call( this );
  22030. this.type = 'QuadraticBezierCurve3';
  22031. this.v0 = v0 || new Vector3();
  22032. this.v1 = v1 || new Vector3();
  22033. this.v2 = v2 || new Vector3();
  22034. }
  22035. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22036. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22037. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22038. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22039. var point = optionalTarget || new Vector3();
  22040. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22041. point.set(
  22042. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22043. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22044. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22045. );
  22046. return point;
  22047. };
  22048. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22049. Curve.prototype.copy.call( this, source );
  22050. this.v0.copy( source.v0 );
  22051. this.v1.copy( source.v1 );
  22052. this.v2.copy( source.v2 );
  22053. return this;
  22054. };
  22055. QuadraticBezierCurve3.prototype.toJSON = function () {
  22056. var data = Curve.prototype.toJSON.call( this );
  22057. data.v0 = this.v0.toArray();
  22058. data.v1 = this.v1.toArray();
  22059. data.v2 = this.v2.toArray();
  22060. return data;
  22061. };
  22062. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  22063. Curve.prototype.fromJSON.call( this, json );
  22064. this.v0.fromArray( json.v0 );
  22065. this.v1.fromArray( json.v1 );
  22066. this.v2.fromArray( json.v2 );
  22067. return this;
  22068. };
  22069. function SplineCurve( points /* array of Vector2 */ ) {
  22070. Curve.call( this );
  22071. this.type = 'SplineCurve';
  22072. this.points = points || [];
  22073. }
  22074. SplineCurve.prototype = Object.create( Curve.prototype );
  22075. SplineCurve.prototype.constructor = SplineCurve;
  22076. SplineCurve.prototype.isSplineCurve = true;
  22077. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22078. var point = optionalTarget || new Vector2();
  22079. var points = this.points;
  22080. var p = ( points.length - 1 ) * t;
  22081. var intPoint = Math.floor( p );
  22082. var weight = p - intPoint;
  22083. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  22084. var p1 = points[ intPoint ];
  22085. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  22086. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  22087. point.set(
  22088. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  22089. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  22090. );
  22091. return point;
  22092. };
  22093. SplineCurve.prototype.copy = function ( source ) {
  22094. Curve.prototype.copy.call( this, source );
  22095. this.points = [];
  22096. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22097. var point = source.points[ i ];
  22098. this.points.push( point.clone() );
  22099. }
  22100. return this;
  22101. };
  22102. SplineCurve.prototype.toJSON = function () {
  22103. var data = Curve.prototype.toJSON.call( this );
  22104. data.points = [];
  22105. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22106. var point = this.points[ i ];
  22107. data.points.push( point.toArray() );
  22108. }
  22109. return data;
  22110. };
  22111. SplineCurve.prototype.fromJSON = function ( json ) {
  22112. Curve.prototype.fromJSON.call( this, json );
  22113. this.points = [];
  22114. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22115. var point = json.points[ i ];
  22116. this.points.push( new Vector2().fromArray( point ) );
  22117. }
  22118. return this;
  22119. };
  22120. var Curves = /*#__PURE__*/Object.freeze({
  22121. ArcCurve: ArcCurve,
  22122. CatmullRomCurve3: CatmullRomCurve3,
  22123. CubicBezierCurve: CubicBezierCurve,
  22124. CubicBezierCurve3: CubicBezierCurve3,
  22125. EllipseCurve: EllipseCurve,
  22126. LineCurve: LineCurve,
  22127. LineCurve3: LineCurve3,
  22128. QuadraticBezierCurve: QuadraticBezierCurve,
  22129. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22130. SplineCurve: SplineCurve
  22131. });
  22132. /**
  22133. * @author zz85 / http://www.lab4games.net/zz85/blog
  22134. *
  22135. **/
  22136. /**************************************************************
  22137. * Curved Path - a curve path is simply a array of connected
  22138. * curves, but retains the api of a curve
  22139. **************************************************************/
  22140. function CurvePath() {
  22141. Curve.call( this );
  22142. this.type = 'CurvePath';
  22143. this.curves = [];
  22144. this.autoClose = false; // Automatically closes the path
  22145. }
  22146. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  22147. constructor: CurvePath,
  22148. add: function ( curve ) {
  22149. this.curves.push( curve );
  22150. },
  22151. closePath: function () {
  22152. // Add a line curve if start and end of lines are not connected
  22153. var startPoint = this.curves[ 0 ].getPoint( 0 );
  22154. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  22155. if ( ! startPoint.equals( endPoint ) ) {
  22156. this.curves.push( new LineCurve( endPoint, startPoint ) );
  22157. }
  22158. },
  22159. // To get accurate point with reference to
  22160. // entire path distance at time t,
  22161. // following has to be done:
  22162. // 1. Length of each sub path have to be known
  22163. // 2. Locate and identify type of curve
  22164. // 3. Get t for the curve
  22165. // 4. Return curve.getPointAt(t')
  22166. getPoint: function ( t ) {
  22167. var d = t * this.getLength();
  22168. var curveLengths = this.getCurveLengths();
  22169. var i = 0;
  22170. // To think about boundaries points.
  22171. while ( i < curveLengths.length ) {
  22172. if ( curveLengths[ i ] >= d ) {
  22173. var diff = curveLengths[ i ] - d;
  22174. var curve = this.curves[ i ];
  22175. var segmentLength = curve.getLength();
  22176. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22177. return curve.getPointAt( u );
  22178. }
  22179. i ++;
  22180. }
  22181. return null;
  22182. // loop where sum != 0, sum > d , sum+1 <d
  22183. },
  22184. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22185. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22186. // getPoint() depends on getLength
  22187. getLength: function () {
  22188. var lens = this.getCurveLengths();
  22189. return lens[ lens.length - 1 ];
  22190. },
  22191. // cacheLengths must be recalculated.
  22192. updateArcLengths: function () {
  22193. this.needsUpdate = true;
  22194. this.cacheLengths = null;
  22195. this.getCurveLengths();
  22196. },
  22197. // Compute lengths and cache them
  22198. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22199. getCurveLengths: function () {
  22200. // We use cache values if curves and cache array are same length
  22201. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  22202. return this.cacheLengths;
  22203. }
  22204. // Get length of sub-curve
  22205. // Push sums into cached array
  22206. var lengths = [], sums = 0;
  22207. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22208. sums += this.curves[ i ].getLength();
  22209. lengths.push( sums );
  22210. }
  22211. this.cacheLengths = lengths;
  22212. return lengths;
  22213. },
  22214. getSpacedPoints: function ( divisions ) {
  22215. if ( divisions === undefined ) divisions = 40;
  22216. var points = [];
  22217. for ( var i = 0; i <= divisions; i ++ ) {
  22218. points.push( this.getPoint( i / divisions ) );
  22219. }
  22220. if ( this.autoClose ) {
  22221. points.push( points[ 0 ] );
  22222. }
  22223. return points;
  22224. },
  22225. getPoints: function ( divisions ) {
  22226. divisions = divisions || 12;
  22227. var points = [], last;
  22228. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  22229. var curve = curves[ i ];
  22230. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  22231. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  22232. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  22233. : divisions;
  22234. var pts = curve.getPoints( resolution );
  22235. for ( var j = 0; j < pts.length; j ++ ) {
  22236. var point = pts[ j ];
  22237. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  22238. points.push( point );
  22239. last = point;
  22240. }
  22241. }
  22242. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  22243. points.push( points[ 0 ] );
  22244. }
  22245. return points;
  22246. },
  22247. copy: function ( source ) {
  22248. Curve.prototype.copy.call( this, source );
  22249. this.curves = [];
  22250. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  22251. var curve = source.curves[ i ];
  22252. this.curves.push( curve.clone() );
  22253. }
  22254. this.autoClose = source.autoClose;
  22255. return this;
  22256. },
  22257. toJSON: function () {
  22258. var data = Curve.prototype.toJSON.call( this );
  22259. data.autoClose = this.autoClose;
  22260. data.curves = [];
  22261. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22262. var curve = this.curves[ i ];
  22263. data.curves.push( curve.toJSON() );
  22264. }
  22265. return data;
  22266. },
  22267. fromJSON: function ( json ) {
  22268. Curve.prototype.fromJSON.call( this, json );
  22269. this.autoClose = json.autoClose;
  22270. this.curves = [];
  22271. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  22272. var curve = json.curves[ i ];
  22273. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22274. }
  22275. return this;
  22276. }
  22277. } );
  22278. /**
  22279. * @author zz85 / http://www.lab4games.net/zz85/blog
  22280. * Creates free form 2d path using series of points, lines or curves.
  22281. **/
  22282. function Path( points ) {
  22283. CurvePath.call( this );
  22284. this.type = 'Path';
  22285. this.currentPoint = new Vector2();
  22286. if ( points ) {
  22287. this.setFromPoints( points );
  22288. }
  22289. }
  22290. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22291. constructor: Path,
  22292. setFromPoints: function ( points ) {
  22293. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22294. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22295. this.lineTo( points[ i ].x, points[ i ].y );
  22296. }
  22297. },
  22298. moveTo: function ( x, y ) {
  22299. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22300. },
  22301. lineTo: function ( x, y ) {
  22302. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22303. this.curves.push( curve );
  22304. this.currentPoint.set( x, y );
  22305. },
  22306. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22307. var curve = new QuadraticBezierCurve(
  22308. this.currentPoint.clone(),
  22309. new Vector2( aCPx, aCPy ),
  22310. new Vector2( aX, aY )
  22311. );
  22312. this.curves.push( curve );
  22313. this.currentPoint.set( aX, aY );
  22314. },
  22315. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22316. var curve = new CubicBezierCurve(
  22317. this.currentPoint.clone(),
  22318. new Vector2( aCP1x, aCP1y ),
  22319. new Vector2( aCP2x, aCP2y ),
  22320. new Vector2( aX, aY )
  22321. );
  22322. this.curves.push( curve );
  22323. this.currentPoint.set( aX, aY );
  22324. },
  22325. splineThru: function ( pts /*Array of Vector*/ ) {
  22326. var npts = [ this.currentPoint.clone() ].concat( pts );
  22327. var curve = new SplineCurve( npts );
  22328. this.curves.push( curve );
  22329. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22330. },
  22331. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22332. var x0 = this.currentPoint.x;
  22333. var y0 = this.currentPoint.y;
  22334. this.absarc( aX + x0, aY + y0, aRadius,
  22335. aStartAngle, aEndAngle, aClockwise );
  22336. },
  22337. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22338. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22339. },
  22340. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22341. var x0 = this.currentPoint.x;
  22342. var y0 = this.currentPoint.y;
  22343. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22344. },
  22345. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22346. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22347. if ( this.curves.length > 0 ) {
  22348. // if a previous curve is present, attempt to join
  22349. var firstPoint = curve.getPoint( 0 );
  22350. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22351. this.lineTo( firstPoint.x, firstPoint.y );
  22352. }
  22353. }
  22354. this.curves.push( curve );
  22355. var lastPoint = curve.getPoint( 1 );
  22356. this.currentPoint.copy( lastPoint );
  22357. },
  22358. copy: function ( source ) {
  22359. CurvePath.prototype.copy.call( this, source );
  22360. this.currentPoint.copy( source.currentPoint );
  22361. return this;
  22362. },
  22363. toJSON: function () {
  22364. var data = CurvePath.prototype.toJSON.call( this );
  22365. data.currentPoint = this.currentPoint.toArray();
  22366. return data;
  22367. },
  22368. fromJSON: function ( json ) {
  22369. CurvePath.prototype.fromJSON.call( this, json );
  22370. this.currentPoint.fromArray( json.currentPoint );
  22371. return this;
  22372. }
  22373. } );
  22374. /**
  22375. * @author zz85 / http://www.lab4games.net/zz85/blog
  22376. * Defines a 2d shape plane using paths.
  22377. **/
  22378. // STEP 1 Create a path.
  22379. // STEP 2 Turn path into shape.
  22380. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22381. // STEP 3a - Extract points from each shape, turn to vertices
  22382. // STEP 3b - Triangulate each shape, add faces.
  22383. function Shape( points ) {
  22384. Path.call( this, points );
  22385. this.uuid = _Math.generateUUID();
  22386. this.type = 'Shape';
  22387. this.holes = [];
  22388. }
  22389. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22390. constructor: Shape,
  22391. getPointsHoles: function ( divisions ) {
  22392. var holesPts = [];
  22393. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22394. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22395. }
  22396. return holesPts;
  22397. },
  22398. // get points of shape and holes (keypoints based on segments parameter)
  22399. extractPoints: function ( divisions ) {
  22400. return {
  22401. shape: this.getPoints( divisions ),
  22402. holes: this.getPointsHoles( divisions )
  22403. };
  22404. },
  22405. copy: function ( source ) {
  22406. Path.prototype.copy.call( this, source );
  22407. this.holes = [];
  22408. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22409. var hole = source.holes[ i ];
  22410. this.holes.push( hole.clone() );
  22411. }
  22412. return this;
  22413. },
  22414. toJSON: function () {
  22415. var data = Path.prototype.toJSON.call( this );
  22416. data.uuid = this.uuid;
  22417. data.holes = [];
  22418. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22419. var hole = this.holes[ i ];
  22420. data.holes.push( hole.toJSON() );
  22421. }
  22422. return data;
  22423. },
  22424. fromJSON: function ( json ) {
  22425. Path.prototype.fromJSON.call( this, json );
  22426. this.uuid = json.uuid;
  22427. this.holes = [];
  22428. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22429. var hole = json.holes[ i ];
  22430. this.holes.push( new Path().fromJSON( hole ) );
  22431. }
  22432. return this;
  22433. }
  22434. } );
  22435. /**
  22436. * @author mrdoob / http://mrdoob.com/
  22437. * @author alteredq / http://alteredqualia.com/
  22438. */
  22439. function Light( color, intensity ) {
  22440. Object3D.call( this );
  22441. this.type = 'Light';
  22442. this.color = new Color( color );
  22443. this.intensity = intensity !== undefined ? intensity : 1;
  22444. this.receiveShadow = undefined;
  22445. }
  22446. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22447. constructor: Light,
  22448. isLight: true,
  22449. copy: function ( source ) {
  22450. Object3D.prototype.copy.call( this, source );
  22451. this.color.copy( source.color );
  22452. this.intensity = source.intensity;
  22453. return this;
  22454. },
  22455. toJSON: function ( meta ) {
  22456. var data = Object3D.prototype.toJSON.call( this, meta );
  22457. data.object.color = this.color.getHex();
  22458. data.object.intensity = this.intensity;
  22459. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22460. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22461. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22462. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22463. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22464. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22465. return data;
  22466. }
  22467. } );
  22468. /**
  22469. * @author alteredq / http://alteredqualia.com/
  22470. */
  22471. function HemisphereLight( skyColor, groundColor, intensity ) {
  22472. Light.call( this, skyColor, intensity );
  22473. this.type = 'HemisphereLight';
  22474. this.castShadow = undefined;
  22475. this.position.copy( Object3D.DefaultUp );
  22476. this.updateMatrix();
  22477. this.groundColor = new Color( groundColor );
  22478. }
  22479. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22480. constructor: HemisphereLight,
  22481. isHemisphereLight: true,
  22482. copy: function ( source ) {
  22483. Light.prototype.copy.call( this, source );
  22484. this.groundColor.copy( source.groundColor );
  22485. return this;
  22486. }
  22487. } );
  22488. /**
  22489. * @author mrdoob / http://mrdoob.com/
  22490. */
  22491. function LightShadow( camera ) {
  22492. this.camera = camera;
  22493. this.bias = 0;
  22494. this.radius = 1;
  22495. this.mapSize = new Vector2( 512, 512 );
  22496. this.map = null;
  22497. this.matrix = new Matrix4();
  22498. }
  22499. Object.assign( LightShadow.prototype, {
  22500. copy: function ( source ) {
  22501. this.camera = source.camera.clone();
  22502. this.bias = source.bias;
  22503. this.radius = source.radius;
  22504. this.mapSize.copy( source.mapSize );
  22505. return this;
  22506. },
  22507. clone: function () {
  22508. return new this.constructor().copy( this );
  22509. },
  22510. toJSON: function () {
  22511. var object = {};
  22512. if ( this.bias !== 0 ) object.bias = this.bias;
  22513. if ( this.radius !== 1 ) object.radius = this.radius;
  22514. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22515. object.camera = this.camera.toJSON( false ).object;
  22516. delete object.camera.matrix;
  22517. return object;
  22518. }
  22519. } );
  22520. /**
  22521. * @author mrdoob / http://mrdoob.com/
  22522. */
  22523. function SpotLightShadow() {
  22524. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22525. }
  22526. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22527. constructor: SpotLightShadow,
  22528. isSpotLightShadow: true,
  22529. update: function ( light ) {
  22530. var camera = this.camera;
  22531. var fov = _Math.RAD2DEG * 2 * light.angle;
  22532. var aspect = this.mapSize.width / this.mapSize.height;
  22533. var far = light.distance || camera.far;
  22534. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22535. camera.fov = fov;
  22536. camera.aspect = aspect;
  22537. camera.far = far;
  22538. camera.updateProjectionMatrix();
  22539. }
  22540. }
  22541. } );
  22542. /**
  22543. * @author alteredq / http://alteredqualia.com/
  22544. */
  22545. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22546. Light.call( this, color, intensity );
  22547. this.type = 'SpotLight';
  22548. this.position.copy( Object3D.DefaultUp );
  22549. this.updateMatrix();
  22550. this.target = new Object3D();
  22551. Object.defineProperty( this, 'power', {
  22552. get: function () {
  22553. // intensity = power per solid angle.
  22554. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22555. return this.intensity * Math.PI;
  22556. },
  22557. set: function ( power ) {
  22558. // intensity = power per solid angle.
  22559. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22560. this.intensity = power / Math.PI;
  22561. }
  22562. } );
  22563. this.distance = ( distance !== undefined ) ? distance : 0;
  22564. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22565. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22566. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22567. this.shadow = new SpotLightShadow();
  22568. }
  22569. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22570. constructor: SpotLight,
  22571. isSpotLight: true,
  22572. copy: function ( source ) {
  22573. Light.prototype.copy.call( this, source );
  22574. this.distance = source.distance;
  22575. this.angle = source.angle;
  22576. this.penumbra = source.penumbra;
  22577. this.decay = source.decay;
  22578. this.target = source.target.clone();
  22579. this.shadow = source.shadow.clone();
  22580. return this;
  22581. }
  22582. } );
  22583. /**
  22584. * @author mrdoob / http://mrdoob.com/
  22585. */
  22586. function PointLight( color, intensity, distance, decay ) {
  22587. Light.call( this, color, intensity );
  22588. this.type = 'PointLight';
  22589. Object.defineProperty( this, 'power', {
  22590. get: function () {
  22591. // intensity = power per solid angle.
  22592. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22593. return this.intensity * 4 * Math.PI;
  22594. },
  22595. set: function ( power ) {
  22596. // intensity = power per solid angle.
  22597. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22598. this.intensity = power / ( 4 * Math.PI );
  22599. }
  22600. } );
  22601. this.distance = ( distance !== undefined ) ? distance : 0;
  22602. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22603. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22604. }
  22605. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22606. constructor: PointLight,
  22607. isPointLight: true,
  22608. copy: function ( source ) {
  22609. Light.prototype.copy.call( this, source );
  22610. this.distance = source.distance;
  22611. this.decay = source.decay;
  22612. this.shadow = source.shadow.clone();
  22613. return this;
  22614. }
  22615. } );
  22616. /**
  22617. * @author alteredq / http://alteredqualia.com/
  22618. * @author arose / http://github.com/arose
  22619. */
  22620. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22621. Camera.call( this );
  22622. this.type = 'OrthographicCamera';
  22623. this.zoom = 1;
  22624. this.view = null;
  22625. this.left = ( left !== undefined ) ? left : - 1;
  22626. this.right = ( right !== undefined ) ? right : 1;
  22627. this.top = ( top !== undefined ) ? top : 1;
  22628. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22629. this.near = ( near !== undefined ) ? near : 0.1;
  22630. this.far = ( far !== undefined ) ? far : 2000;
  22631. this.updateProjectionMatrix();
  22632. }
  22633. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22634. constructor: OrthographicCamera,
  22635. isOrthographicCamera: true,
  22636. copy: function ( source, recursive ) {
  22637. Camera.prototype.copy.call( this, source, recursive );
  22638. this.left = source.left;
  22639. this.right = source.right;
  22640. this.top = source.top;
  22641. this.bottom = source.bottom;
  22642. this.near = source.near;
  22643. this.far = source.far;
  22644. this.zoom = source.zoom;
  22645. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22646. return this;
  22647. },
  22648. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22649. if ( this.view === null ) {
  22650. this.view = {
  22651. enabled: true,
  22652. fullWidth: 1,
  22653. fullHeight: 1,
  22654. offsetX: 0,
  22655. offsetY: 0,
  22656. width: 1,
  22657. height: 1
  22658. };
  22659. }
  22660. this.view.enabled = true;
  22661. this.view.fullWidth = fullWidth;
  22662. this.view.fullHeight = fullHeight;
  22663. this.view.offsetX = x;
  22664. this.view.offsetY = y;
  22665. this.view.width = width;
  22666. this.view.height = height;
  22667. this.updateProjectionMatrix();
  22668. },
  22669. clearViewOffset: function () {
  22670. if ( this.view !== null ) {
  22671. this.view.enabled = false;
  22672. }
  22673. this.updateProjectionMatrix();
  22674. },
  22675. updateProjectionMatrix: function () {
  22676. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22677. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22678. var cx = ( this.right + this.left ) / 2;
  22679. var cy = ( this.top + this.bottom ) / 2;
  22680. var left = cx - dx;
  22681. var right = cx + dx;
  22682. var top = cy + dy;
  22683. var bottom = cy - dy;
  22684. if ( this.view !== null && this.view.enabled ) {
  22685. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22686. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22687. var scaleW = ( this.right - this.left ) / this.view.width;
  22688. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22689. left += scaleW * ( this.view.offsetX / zoomW );
  22690. right = left + scaleW * ( this.view.width / zoomW );
  22691. top -= scaleH * ( this.view.offsetY / zoomH );
  22692. bottom = top - scaleH * ( this.view.height / zoomH );
  22693. }
  22694. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22695. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22696. },
  22697. toJSON: function ( meta ) {
  22698. var data = Object3D.prototype.toJSON.call( this, meta );
  22699. data.object.zoom = this.zoom;
  22700. data.object.left = this.left;
  22701. data.object.right = this.right;
  22702. data.object.top = this.top;
  22703. data.object.bottom = this.bottom;
  22704. data.object.near = this.near;
  22705. data.object.far = this.far;
  22706. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22707. return data;
  22708. }
  22709. } );
  22710. /**
  22711. * @author mrdoob / http://mrdoob.com/
  22712. */
  22713. function DirectionalLightShadow( ) {
  22714. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22715. }
  22716. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22717. constructor: DirectionalLightShadow
  22718. } );
  22719. /**
  22720. * @author mrdoob / http://mrdoob.com/
  22721. * @author alteredq / http://alteredqualia.com/
  22722. */
  22723. function DirectionalLight( color, intensity ) {
  22724. Light.call( this, color, intensity );
  22725. this.type = 'DirectionalLight';
  22726. this.position.copy( Object3D.DefaultUp );
  22727. this.updateMatrix();
  22728. this.target = new Object3D();
  22729. this.shadow = new DirectionalLightShadow();
  22730. }
  22731. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22732. constructor: DirectionalLight,
  22733. isDirectionalLight: true,
  22734. copy: function ( source ) {
  22735. Light.prototype.copy.call( this, source );
  22736. this.target = source.target.clone();
  22737. this.shadow = source.shadow.clone();
  22738. return this;
  22739. }
  22740. } );
  22741. /**
  22742. * @author mrdoob / http://mrdoob.com/
  22743. */
  22744. function AmbientLight( color, intensity ) {
  22745. Light.call( this, color, intensity );
  22746. this.type = 'AmbientLight';
  22747. this.castShadow = undefined;
  22748. }
  22749. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22750. constructor: AmbientLight,
  22751. isAmbientLight: true
  22752. } );
  22753. /**
  22754. * @author abelnation / http://github.com/abelnation
  22755. */
  22756. function RectAreaLight( color, intensity, width, height ) {
  22757. Light.call( this, color, intensity );
  22758. this.type = 'RectAreaLight';
  22759. this.width = ( width !== undefined ) ? width : 10;
  22760. this.height = ( height !== undefined ) ? height : 10;
  22761. }
  22762. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22763. constructor: RectAreaLight,
  22764. isRectAreaLight: true,
  22765. copy: function ( source ) {
  22766. Light.prototype.copy.call( this, source );
  22767. this.width = source.width;
  22768. this.height = source.height;
  22769. return this;
  22770. },
  22771. toJSON: function ( meta ) {
  22772. var data = Light.prototype.toJSON.call( this, meta );
  22773. data.object.width = this.width;
  22774. data.object.height = this.height;
  22775. return data;
  22776. }
  22777. } );
  22778. /**
  22779. * @author mrdoob / http://mrdoob.com/
  22780. */
  22781. function MaterialLoader( manager ) {
  22782. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22783. this.textures = {};
  22784. }
  22785. Object.assign( MaterialLoader.prototype, {
  22786. load: function ( url, onLoad, onProgress, onError ) {
  22787. var scope = this;
  22788. var loader = new FileLoader( scope.manager );
  22789. loader.setPath( scope.path );
  22790. loader.load( url, function ( text ) {
  22791. onLoad( scope.parse( JSON.parse( text ) ) );
  22792. }, onProgress, onError );
  22793. },
  22794. parse: function ( json ) {
  22795. var textures = this.textures;
  22796. function getTexture( name ) {
  22797. if ( textures[ name ] === undefined ) {
  22798. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22799. }
  22800. return textures[ name ];
  22801. }
  22802. var material = new Materials[ json.type ]();
  22803. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22804. if ( json.name !== undefined ) material.name = json.name;
  22805. if ( json.color !== undefined ) material.color.setHex( json.color );
  22806. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22807. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22808. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22809. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22810. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22811. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22812. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22813. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22814. if ( json.fog !== undefined ) material.fog = json.fog;
  22815. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22816. if ( json.blending !== undefined ) material.blending = json.blending;
  22817. if ( json.combine !== undefined ) material.combine = json.combine;
  22818. if ( json.side !== undefined ) material.side = json.side;
  22819. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22820. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22821. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22822. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22823. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22824. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22825. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22826. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22827. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22828. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22829. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22830. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22831. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22832. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22833. if ( json.scale !== undefined ) material.scale = json.scale;
  22834. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22835. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22836. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22837. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22838. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22839. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  22840. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22841. if ( json.visible !== undefined ) material.visible = json.visible;
  22842. if ( json.userData !== undefined ) material.userData = json.userData;
  22843. // Shader Material
  22844. if ( json.uniforms !== undefined ) {
  22845. for ( var name in json.uniforms ) {
  22846. var uniform = json.uniforms[ name ];
  22847. material.uniforms[ name ] = {};
  22848. switch ( uniform.type ) {
  22849. case 't':
  22850. material.uniforms[ name ].value = getTexture( uniform.value );
  22851. break;
  22852. case 'c':
  22853. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22854. break;
  22855. case 'v2':
  22856. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22857. break;
  22858. case 'v3':
  22859. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22860. break;
  22861. case 'v4':
  22862. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22863. break;
  22864. case 'm3':
  22865. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22866. case 'm4':
  22867. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22868. break;
  22869. default:
  22870. material.uniforms[ name ].value = uniform.value;
  22871. }
  22872. }
  22873. }
  22874. if ( json.defines !== undefined ) material.defines = json.defines;
  22875. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22876. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22877. if ( json.extensions !== undefined ) {
  22878. for ( var key in json.extensions ) {
  22879. material.extensions[ key ] = json.extensions[ key ];
  22880. }
  22881. }
  22882. // Deprecated
  22883. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22884. // for PointsMaterial
  22885. if ( json.size !== undefined ) material.size = json.size;
  22886. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22887. // maps
  22888. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22889. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22890. if ( json.alphaMap !== undefined ) {
  22891. material.alphaMap = getTexture( json.alphaMap );
  22892. material.transparent = true;
  22893. }
  22894. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22895. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22896. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22897. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22898. if ( json.normalScale !== undefined ) {
  22899. var normalScale = json.normalScale;
  22900. if ( Array.isArray( normalScale ) === false ) {
  22901. // Blender exporter used to export a scalar. See #7459
  22902. normalScale = [ normalScale, normalScale ];
  22903. }
  22904. material.normalScale = new Vector2().fromArray( normalScale );
  22905. }
  22906. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22907. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22908. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22909. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22910. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22911. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22912. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22913. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22914. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22915. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22916. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22917. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  22918. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22919. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22920. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22921. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22922. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22923. return material;
  22924. },
  22925. setPath: function ( value ) {
  22926. this.path = value;
  22927. return this;
  22928. },
  22929. setTextures: function ( value ) {
  22930. this.textures = value;
  22931. return this;
  22932. }
  22933. } );
  22934. /**
  22935. * @author Don McCurdy / https://www.donmccurdy.com
  22936. */
  22937. var LoaderUtils = {
  22938. decodeText: function ( array ) {
  22939. if ( typeof TextDecoder !== 'undefined' ) {
  22940. return new TextDecoder().decode( array );
  22941. }
  22942. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22943. // throws a "maximum call stack size exceeded" error for large arrays.
  22944. var s = '';
  22945. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22946. // Implicitly assumes little-endian.
  22947. s += String.fromCharCode( array[ i ] );
  22948. }
  22949. try {
  22950. // merges multi-byte utf-8 characters.
  22951. return decodeURIComponent( escape( s ) );
  22952. } catch ( e ) { // see #16358
  22953. return s;
  22954. }
  22955. },
  22956. extractUrlBase: function ( url ) {
  22957. var index = url.lastIndexOf( '/' );
  22958. if ( index === - 1 ) return './';
  22959. return url.substr( 0, index + 1 );
  22960. }
  22961. };
  22962. /**
  22963. * @author benaadams / https://twitter.com/ben_a_adams
  22964. */
  22965. function InstancedBufferGeometry() {
  22966. BufferGeometry.call( this );
  22967. this.type = 'InstancedBufferGeometry';
  22968. this.maxInstancedCount = undefined;
  22969. }
  22970. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  22971. constructor: InstancedBufferGeometry,
  22972. isInstancedBufferGeometry: true,
  22973. copy: function ( source ) {
  22974. BufferGeometry.prototype.copy.call( this, source );
  22975. this.maxInstancedCount = source.maxInstancedCount;
  22976. return this;
  22977. },
  22978. clone: function () {
  22979. return new this.constructor().copy( this );
  22980. },
  22981. toJSON: function () {
  22982. var data = BufferGeometry.prototype.toJSON.call( this );
  22983. data.maxInstancedCount = this.maxInstancedCount;
  22984. data.isInstancedBufferGeometry = true;
  22985. return data;
  22986. }
  22987. } );
  22988. /**
  22989. * @author benaadams / https://twitter.com/ben_a_adams
  22990. */
  22991. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  22992. if ( typeof ( normalized ) === 'number' ) {
  22993. meshPerAttribute = normalized;
  22994. normalized = false;
  22995. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  22996. }
  22997. BufferAttribute.call( this, array, itemSize, normalized );
  22998. this.meshPerAttribute = meshPerAttribute || 1;
  22999. }
  23000. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23001. constructor: InstancedBufferAttribute,
  23002. isInstancedBufferAttribute: true,
  23003. copy: function ( source ) {
  23004. BufferAttribute.prototype.copy.call( this, source );
  23005. this.meshPerAttribute = source.meshPerAttribute;
  23006. return this;
  23007. },
  23008. toJSON: function () {
  23009. var data = BufferAttribute.prototype.toJSON.call( this );
  23010. data.meshPerAttribute = this.meshPerAttribute;
  23011. data.isInstancedBufferAttribute = true;
  23012. return data;
  23013. }
  23014. } );
  23015. /**
  23016. * @author mrdoob / http://mrdoob.com/
  23017. */
  23018. function BufferGeometryLoader( manager ) {
  23019. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23020. }
  23021. Object.assign( BufferGeometryLoader.prototype, {
  23022. load: function ( url, onLoad, onProgress, onError ) {
  23023. var scope = this;
  23024. var loader = new FileLoader( scope.manager );
  23025. loader.setPath( scope.path );
  23026. loader.load( url, function ( text ) {
  23027. onLoad( scope.parse( JSON.parse( text ) ) );
  23028. }, onProgress, onError );
  23029. },
  23030. parse: function ( json ) {
  23031. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23032. var index = json.data.index;
  23033. if ( index !== undefined ) {
  23034. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  23035. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  23036. }
  23037. var attributes = json.data.attributes;
  23038. for ( var key in attributes ) {
  23039. var attribute = attributes[ key ];
  23040. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23041. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23042. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  23043. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23044. geometry.addAttribute( key, bufferAttribute );
  23045. }
  23046. var morphAttributes = json.data.morphAttributes;
  23047. if ( morphAttributes ) {
  23048. for ( var key in morphAttributes ) {
  23049. var attributeArray = morphAttributes[ key ];
  23050. var array = [];
  23051. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  23052. var attribute = attributeArray[ i ];
  23053. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23054. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  23055. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23056. array.push( bufferAttribute );
  23057. }
  23058. geometry.morphAttributes[ key ] = array;
  23059. }
  23060. }
  23061. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23062. if ( groups !== undefined ) {
  23063. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  23064. var group = groups[ i ];
  23065. geometry.addGroup( group.start, group.count, group.materialIndex );
  23066. }
  23067. }
  23068. var boundingSphere = json.data.boundingSphere;
  23069. if ( boundingSphere !== undefined ) {
  23070. var center = new Vector3();
  23071. if ( boundingSphere.center !== undefined ) {
  23072. center.fromArray( boundingSphere.center );
  23073. }
  23074. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  23075. }
  23076. if ( json.name ) geometry.name = json.name;
  23077. if ( json.userData ) geometry.userData = json.userData;
  23078. return geometry;
  23079. },
  23080. setPath: function ( value ) {
  23081. this.path = value;
  23082. return this;
  23083. }
  23084. } );
  23085. var TYPED_ARRAYS = {
  23086. Int8Array: Int8Array,
  23087. Uint8Array: Uint8Array,
  23088. // Workaround for IE11 pre KB2929437. See #11440
  23089. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  23090. Int16Array: Int16Array,
  23091. Uint16Array: Uint16Array,
  23092. Int32Array: Int32Array,
  23093. Uint32Array: Uint32Array,
  23094. Float32Array: Float32Array,
  23095. Float64Array: Float64Array
  23096. };
  23097. /**
  23098. * @author mrdoob / http://mrdoob.com/
  23099. */
  23100. function ObjectLoader( manager ) {
  23101. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23102. this.resourcePath = '';
  23103. }
  23104. Object.assign( ObjectLoader.prototype, {
  23105. crossOrigin: 'anonymous',
  23106. load: function ( url, onLoad, onProgress, onError ) {
  23107. var scope = this;
  23108. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  23109. this.resourcePath = this.resourcePath || path;
  23110. var loader = new FileLoader( scope.manager );
  23111. loader.setPath( this.path );
  23112. loader.load( url, function ( text ) {
  23113. var json = null;
  23114. try {
  23115. json = JSON.parse( text );
  23116. } catch ( error ) {
  23117. if ( onError !== undefined ) onError( error );
  23118. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  23119. return;
  23120. }
  23121. var metadata = json.metadata;
  23122. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  23123. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  23124. return;
  23125. }
  23126. scope.parse( json, onLoad );
  23127. }, onProgress, onError );
  23128. },
  23129. setPath: function ( value ) {
  23130. this.path = value;
  23131. return this;
  23132. },
  23133. setResourcePath: function ( value ) {
  23134. this.resourcePath = value;
  23135. return this;
  23136. },
  23137. setCrossOrigin: function ( value ) {
  23138. this.crossOrigin = value;
  23139. return this;
  23140. },
  23141. parse: function ( json, onLoad ) {
  23142. var shapes = this.parseShape( json.shapes );
  23143. var geometries = this.parseGeometries( json.geometries, shapes );
  23144. var images = this.parseImages( json.images, function () {
  23145. if ( onLoad !== undefined ) onLoad( object );
  23146. } );
  23147. var textures = this.parseTextures( json.textures, images );
  23148. var materials = this.parseMaterials( json.materials, textures );
  23149. var object = this.parseObject( json.object, geometries, materials );
  23150. if ( json.animations ) {
  23151. object.animations = this.parseAnimations( json.animations );
  23152. }
  23153. if ( json.images === undefined || json.images.length === 0 ) {
  23154. if ( onLoad !== undefined ) onLoad( object );
  23155. }
  23156. return object;
  23157. },
  23158. parseShape: function ( json ) {
  23159. var shapes = {};
  23160. if ( json !== undefined ) {
  23161. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23162. var shape = new Shape().fromJSON( json[ i ] );
  23163. shapes[ shape.uuid ] = shape;
  23164. }
  23165. }
  23166. return shapes;
  23167. },
  23168. parseGeometries: function ( json, shapes ) {
  23169. var geometries = {};
  23170. if ( json !== undefined ) {
  23171. var bufferGeometryLoader = new BufferGeometryLoader();
  23172. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23173. var geometry;
  23174. var data = json[ i ];
  23175. switch ( data.type ) {
  23176. case 'PlaneGeometry':
  23177. case 'PlaneBufferGeometry':
  23178. geometry = new Geometries[ data.type ](
  23179. data.width,
  23180. data.height,
  23181. data.widthSegments,
  23182. data.heightSegments
  23183. );
  23184. break;
  23185. case 'BoxGeometry':
  23186. case 'BoxBufferGeometry':
  23187. case 'CubeGeometry': // backwards compatible
  23188. geometry = new Geometries[ data.type ](
  23189. data.width,
  23190. data.height,
  23191. data.depth,
  23192. data.widthSegments,
  23193. data.heightSegments,
  23194. data.depthSegments
  23195. );
  23196. break;
  23197. case 'CircleGeometry':
  23198. case 'CircleBufferGeometry':
  23199. geometry = new Geometries[ data.type ](
  23200. data.radius,
  23201. data.segments,
  23202. data.thetaStart,
  23203. data.thetaLength
  23204. );
  23205. break;
  23206. case 'CylinderGeometry':
  23207. case 'CylinderBufferGeometry':
  23208. geometry = new Geometries[ data.type ](
  23209. data.radiusTop,
  23210. data.radiusBottom,
  23211. data.height,
  23212. data.radialSegments,
  23213. data.heightSegments,
  23214. data.openEnded,
  23215. data.thetaStart,
  23216. data.thetaLength
  23217. );
  23218. break;
  23219. case 'ConeGeometry':
  23220. case 'ConeBufferGeometry':
  23221. geometry = new Geometries[ data.type ](
  23222. data.radius,
  23223. data.height,
  23224. data.radialSegments,
  23225. data.heightSegments,
  23226. data.openEnded,
  23227. data.thetaStart,
  23228. data.thetaLength
  23229. );
  23230. break;
  23231. case 'SphereGeometry':
  23232. case 'SphereBufferGeometry':
  23233. geometry = new Geometries[ data.type ](
  23234. data.radius,
  23235. data.widthSegments,
  23236. data.heightSegments,
  23237. data.phiStart,
  23238. data.phiLength,
  23239. data.thetaStart,
  23240. data.thetaLength
  23241. );
  23242. break;
  23243. case 'DodecahedronGeometry':
  23244. case 'DodecahedronBufferGeometry':
  23245. case 'IcosahedronGeometry':
  23246. case 'IcosahedronBufferGeometry':
  23247. case 'OctahedronGeometry':
  23248. case 'OctahedronBufferGeometry':
  23249. case 'TetrahedronGeometry':
  23250. case 'TetrahedronBufferGeometry':
  23251. geometry = new Geometries[ data.type ](
  23252. data.radius,
  23253. data.detail
  23254. );
  23255. break;
  23256. case 'RingGeometry':
  23257. case 'RingBufferGeometry':
  23258. geometry = new Geometries[ data.type ](
  23259. data.innerRadius,
  23260. data.outerRadius,
  23261. data.thetaSegments,
  23262. data.phiSegments,
  23263. data.thetaStart,
  23264. data.thetaLength
  23265. );
  23266. break;
  23267. case 'TorusGeometry':
  23268. case 'TorusBufferGeometry':
  23269. geometry = new Geometries[ data.type ](
  23270. data.radius,
  23271. data.tube,
  23272. data.radialSegments,
  23273. data.tubularSegments,
  23274. data.arc
  23275. );
  23276. break;
  23277. case 'TorusKnotGeometry':
  23278. case 'TorusKnotBufferGeometry':
  23279. geometry = new Geometries[ data.type ](
  23280. data.radius,
  23281. data.tube,
  23282. data.tubularSegments,
  23283. data.radialSegments,
  23284. data.p,
  23285. data.q
  23286. );
  23287. break;
  23288. case 'TubeGeometry':
  23289. case 'TubeBufferGeometry':
  23290. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23291. // User defined curves or instances of CurvePath will not be deserialized.
  23292. geometry = new Geometries[ data.type ](
  23293. new Curves[ data.path.type ]().fromJSON( data.path ),
  23294. data.tubularSegments,
  23295. data.radius,
  23296. data.radialSegments,
  23297. data.closed
  23298. );
  23299. break;
  23300. case 'LatheGeometry':
  23301. case 'LatheBufferGeometry':
  23302. geometry = new Geometries[ data.type ](
  23303. data.points,
  23304. data.segments,
  23305. data.phiStart,
  23306. data.phiLength
  23307. );
  23308. break;
  23309. case 'PolyhedronGeometry':
  23310. case 'PolyhedronBufferGeometry':
  23311. geometry = new Geometries[ data.type ](
  23312. data.vertices,
  23313. data.indices,
  23314. data.radius,
  23315. data.details
  23316. );
  23317. break;
  23318. case 'ShapeGeometry':
  23319. case 'ShapeBufferGeometry':
  23320. var geometryShapes = [];
  23321. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23322. var shape = shapes[ data.shapes[ j ] ];
  23323. geometryShapes.push( shape );
  23324. }
  23325. geometry = new Geometries[ data.type ](
  23326. geometryShapes,
  23327. data.curveSegments
  23328. );
  23329. break;
  23330. case 'ExtrudeGeometry':
  23331. case 'ExtrudeBufferGeometry':
  23332. var geometryShapes = [];
  23333. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23334. var shape = shapes[ data.shapes[ j ] ];
  23335. geometryShapes.push( shape );
  23336. }
  23337. var extrudePath = data.options.extrudePath;
  23338. if ( extrudePath !== undefined ) {
  23339. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23340. }
  23341. geometry = new Geometries[ data.type ](
  23342. geometryShapes,
  23343. data.options
  23344. );
  23345. break;
  23346. case 'BufferGeometry':
  23347. case 'InstancedBufferGeometry':
  23348. geometry = bufferGeometryLoader.parse( data );
  23349. break;
  23350. case 'Geometry':
  23351. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23352. var geometryLoader = new THREE.LegacyJSONLoader();
  23353. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23354. } else {
  23355. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23356. }
  23357. break;
  23358. default:
  23359. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23360. continue;
  23361. }
  23362. geometry.uuid = data.uuid;
  23363. if ( data.name !== undefined ) geometry.name = data.name;
  23364. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23365. geometries[ data.uuid ] = geometry;
  23366. }
  23367. }
  23368. return geometries;
  23369. },
  23370. parseMaterials: function ( json, textures ) {
  23371. var cache = {}; // MultiMaterial
  23372. var materials = {};
  23373. if ( json !== undefined ) {
  23374. var loader = new MaterialLoader();
  23375. loader.setTextures( textures );
  23376. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23377. var data = json[ i ];
  23378. if ( data.type === 'MultiMaterial' ) {
  23379. // Deprecated
  23380. var array = [];
  23381. for ( var j = 0; j < data.materials.length; j ++ ) {
  23382. var material = data.materials[ j ];
  23383. if ( cache[ material.uuid ] === undefined ) {
  23384. cache[ material.uuid ] = loader.parse( material );
  23385. }
  23386. array.push( cache[ material.uuid ] );
  23387. }
  23388. materials[ data.uuid ] = array;
  23389. } else {
  23390. if ( cache[ data.uuid ] === undefined ) {
  23391. cache[ data.uuid ] = loader.parse( data );
  23392. }
  23393. materials[ data.uuid ] = cache[ data.uuid ];
  23394. }
  23395. }
  23396. }
  23397. return materials;
  23398. },
  23399. parseAnimations: function ( json ) {
  23400. var animations = [];
  23401. for ( var i = 0; i < json.length; i ++ ) {
  23402. var data = json[ i ];
  23403. var clip = AnimationClip.parse( data );
  23404. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23405. animations.push( clip );
  23406. }
  23407. return animations;
  23408. },
  23409. parseImages: function ( json, onLoad ) {
  23410. var scope = this;
  23411. var images = {};
  23412. function loadImage( url ) {
  23413. scope.manager.itemStart( url );
  23414. return loader.load( url, function () {
  23415. scope.manager.itemEnd( url );
  23416. }, undefined, function () {
  23417. scope.manager.itemError( url );
  23418. scope.manager.itemEnd( url );
  23419. } );
  23420. }
  23421. if ( json !== undefined && json.length > 0 ) {
  23422. var manager = new LoadingManager( onLoad );
  23423. var loader = new ImageLoader( manager );
  23424. loader.setCrossOrigin( this.crossOrigin );
  23425. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23426. var image = json[ i ];
  23427. var url = image.url;
  23428. if ( Array.isArray( url ) ) {
  23429. // load array of images e.g CubeTexture
  23430. images[ image.uuid ] = [];
  23431. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23432. var currentUrl = url[ j ];
  23433. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23434. images[ image.uuid ].push( loadImage( path ) );
  23435. }
  23436. } else {
  23437. // load single image
  23438. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23439. images[ image.uuid ] = loadImage( path );
  23440. }
  23441. }
  23442. }
  23443. return images;
  23444. },
  23445. parseTextures: function ( json, images ) {
  23446. function parseConstant( value, type ) {
  23447. if ( typeof value === 'number' ) return value;
  23448. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23449. return type[ value ];
  23450. }
  23451. var textures = {};
  23452. if ( json !== undefined ) {
  23453. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23454. var data = json[ i ];
  23455. if ( data.image === undefined ) {
  23456. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23457. }
  23458. if ( images[ data.image ] === undefined ) {
  23459. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23460. }
  23461. var texture;
  23462. if ( Array.isArray( images[ data.image ] ) ) {
  23463. texture = new CubeTexture( images[ data.image ] );
  23464. } else {
  23465. texture = new Texture( images[ data.image ] );
  23466. }
  23467. texture.needsUpdate = true;
  23468. texture.uuid = data.uuid;
  23469. if ( data.name !== undefined ) texture.name = data.name;
  23470. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23471. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23472. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23473. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23474. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23475. if ( data.wrap !== undefined ) {
  23476. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23477. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23478. }
  23479. if ( data.format !== undefined ) texture.format = data.format;
  23480. if ( data.type !== undefined ) texture.type = data.type;
  23481. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23482. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23483. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23484. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23485. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23486. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23487. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23488. textures[ data.uuid ] = texture;
  23489. }
  23490. }
  23491. return textures;
  23492. },
  23493. parseObject: function ( data, geometries, materials ) {
  23494. var object;
  23495. function getGeometry( name ) {
  23496. if ( geometries[ name ] === undefined ) {
  23497. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23498. }
  23499. return geometries[ name ];
  23500. }
  23501. function getMaterial( name ) {
  23502. if ( name === undefined ) return undefined;
  23503. if ( Array.isArray( name ) ) {
  23504. var array = [];
  23505. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23506. var uuid = name[ i ];
  23507. if ( materials[ uuid ] === undefined ) {
  23508. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23509. }
  23510. array.push( materials[ uuid ] );
  23511. }
  23512. return array;
  23513. }
  23514. if ( materials[ name ] === undefined ) {
  23515. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23516. }
  23517. return materials[ name ];
  23518. }
  23519. switch ( data.type ) {
  23520. case 'Scene':
  23521. object = new Scene();
  23522. if ( data.background !== undefined ) {
  23523. if ( Number.isInteger( data.background ) ) {
  23524. object.background = new Color( data.background );
  23525. }
  23526. }
  23527. if ( data.fog !== undefined ) {
  23528. if ( data.fog.type === 'Fog' ) {
  23529. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23530. } else if ( data.fog.type === 'FogExp2' ) {
  23531. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23532. }
  23533. }
  23534. break;
  23535. case 'PerspectiveCamera':
  23536. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23537. if ( data.focus !== undefined ) object.focus = data.focus;
  23538. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23539. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23540. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23541. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23542. break;
  23543. case 'OrthographicCamera':
  23544. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23545. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23546. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23547. break;
  23548. case 'AmbientLight':
  23549. object = new AmbientLight( data.color, data.intensity );
  23550. break;
  23551. case 'DirectionalLight':
  23552. object = new DirectionalLight( data.color, data.intensity );
  23553. break;
  23554. case 'PointLight':
  23555. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23556. break;
  23557. case 'RectAreaLight':
  23558. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23559. break;
  23560. case 'SpotLight':
  23561. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23562. break;
  23563. case 'HemisphereLight':
  23564. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23565. break;
  23566. case 'SkinnedMesh':
  23567. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23568. case 'Mesh':
  23569. var geometry = getGeometry( data.geometry );
  23570. var material = getMaterial( data.material );
  23571. if ( geometry.bones && geometry.bones.length > 0 ) {
  23572. object = new SkinnedMesh( geometry, material );
  23573. } else {
  23574. object = new Mesh( geometry, material );
  23575. }
  23576. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23577. break;
  23578. case 'LOD':
  23579. object = new LOD();
  23580. break;
  23581. case 'Line':
  23582. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23583. break;
  23584. case 'LineLoop':
  23585. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23586. break;
  23587. case 'LineSegments':
  23588. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23589. break;
  23590. case 'PointCloud':
  23591. case 'Points':
  23592. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23593. break;
  23594. case 'Sprite':
  23595. object = new Sprite( getMaterial( data.material ) );
  23596. break;
  23597. case 'Group':
  23598. object = new Group();
  23599. break;
  23600. default:
  23601. object = new Object3D();
  23602. }
  23603. object.uuid = data.uuid;
  23604. if ( data.name !== undefined ) object.name = data.name;
  23605. if ( data.matrix !== undefined ) {
  23606. object.matrix.fromArray( data.matrix );
  23607. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23608. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23609. } else {
  23610. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23611. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23612. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23613. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23614. }
  23615. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23616. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23617. if ( data.shadow ) {
  23618. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23619. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23620. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23621. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23622. }
  23623. if ( data.visible !== undefined ) object.visible = data.visible;
  23624. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23625. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23626. if ( data.userData !== undefined ) object.userData = data.userData;
  23627. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23628. if ( data.children !== undefined ) {
  23629. var children = data.children;
  23630. for ( var i = 0; i < children.length; i ++ ) {
  23631. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23632. }
  23633. }
  23634. if ( data.type === 'LOD' ) {
  23635. var levels = data.levels;
  23636. for ( var l = 0; l < levels.length; l ++ ) {
  23637. var level = levels[ l ];
  23638. var child = object.getObjectByProperty( 'uuid', level.object );
  23639. if ( child !== undefined ) {
  23640. object.addLevel( child, level.distance );
  23641. }
  23642. }
  23643. }
  23644. return object;
  23645. }
  23646. } );
  23647. var TEXTURE_MAPPING = {
  23648. UVMapping: UVMapping,
  23649. CubeReflectionMapping: CubeReflectionMapping,
  23650. CubeRefractionMapping: CubeRefractionMapping,
  23651. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23652. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23653. SphericalReflectionMapping: SphericalReflectionMapping,
  23654. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23655. CubeUVRefractionMapping: CubeUVRefractionMapping
  23656. };
  23657. var TEXTURE_WRAPPING = {
  23658. RepeatWrapping: RepeatWrapping,
  23659. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23660. MirroredRepeatWrapping: MirroredRepeatWrapping
  23661. };
  23662. var TEXTURE_FILTER = {
  23663. NearestFilter: NearestFilter,
  23664. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  23665. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  23666. LinearFilter: LinearFilter,
  23667. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  23668. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  23669. };
  23670. /**
  23671. * @author thespite / http://clicktorelease.com/
  23672. */
  23673. function ImageBitmapLoader( manager ) {
  23674. if ( typeof createImageBitmap === 'undefined' ) {
  23675. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23676. }
  23677. if ( typeof fetch === 'undefined' ) {
  23678. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23679. }
  23680. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23681. this.options = undefined;
  23682. }
  23683. ImageBitmapLoader.prototype = {
  23684. constructor: ImageBitmapLoader,
  23685. setOptions: function setOptions( options ) {
  23686. this.options = options;
  23687. return this;
  23688. },
  23689. load: function ( url, onLoad, onProgress, onError ) {
  23690. if ( url === undefined ) url = '';
  23691. if ( this.path !== undefined ) url = this.path + url;
  23692. url = this.manager.resolveURL( url );
  23693. var scope = this;
  23694. var cached = Cache.get( url );
  23695. if ( cached !== undefined ) {
  23696. scope.manager.itemStart( url );
  23697. setTimeout( function () {
  23698. if ( onLoad ) onLoad( cached );
  23699. scope.manager.itemEnd( url );
  23700. }, 0 );
  23701. return cached;
  23702. }
  23703. fetch( url ).then( function ( res ) {
  23704. return res.blob();
  23705. } ).then( function ( blob ) {
  23706. if ( scope.options === undefined ) {
  23707. // Workaround for FireFox. It causes an error if you pass options.
  23708. return createImageBitmap( blob );
  23709. } else {
  23710. return createImageBitmap( blob, scope.options );
  23711. }
  23712. } ).then( function ( imageBitmap ) {
  23713. Cache.add( url, imageBitmap );
  23714. if ( onLoad ) onLoad( imageBitmap );
  23715. scope.manager.itemEnd( url );
  23716. } ).catch( function ( e ) {
  23717. if ( onError ) onError( e );
  23718. scope.manager.itemError( url );
  23719. scope.manager.itemEnd( url );
  23720. } );
  23721. scope.manager.itemStart( url );
  23722. },
  23723. setCrossOrigin: function ( /* value */ ) {
  23724. return this;
  23725. },
  23726. setPath: function ( value ) {
  23727. this.path = value;
  23728. return this;
  23729. }
  23730. };
  23731. /**
  23732. * @author zz85 / http://www.lab4games.net/zz85/blog
  23733. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23734. **/
  23735. function ShapePath() {
  23736. this.type = 'ShapePath';
  23737. this.color = new Color();
  23738. this.subPaths = [];
  23739. this.currentPath = null;
  23740. }
  23741. Object.assign( ShapePath.prototype, {
  23742. moveTo: function ( x, y ) {
  23743. this.currentPath = new Path();
  23744. this.subPaths.push( this.currentPath );
  23745. this.currentPath.moveTo( x, y );
  23746. },
  23747. lineTo: function ( x, y ) {
  23748. this.currentPath.lineTo( x, y );
  23749. },
  23750. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23751. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23752. },
  23753. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23754. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23755. },
  23756. splineThru: function ( pts ) {
  23757. this.currentPath.splineThru( pts );
  23758. },
  23759. toShapes: function ( isCCW, noHoles ) {
  23760. function toShapesNoHoles( inSubpaths ) {
  23761. var shapes = [];
  23762. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23763. var tmpPath = inSubpaths[ i ];
  23764. var tmpShape = new Shape();
  23765. tmpShape.curves = tmpPath.curves;
  23766. shapes.push( tmpShape );
  23767. }
  23768. return shapes;
  23769. }
  23770. function isPointInsidePolygon( inPt, inPolygon ) {
  23771. var polyLen = inPolygon.length;
  23772. // inPt on polygon contour => immediate success or
  23773. // toggling of inside/outside at every single! intersection point of an edge
  23774. // with the horizontal line through inPt, left of inPt
  23775. // not counting lowerY endpoints of edges and whole edges on that line
  23776. var inside = false;
  23777. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23778. var edgeLowPt = inPolygon[ p ];
  23779. var edgeHighPt = inPolygon[ q ];
  23780. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23781. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23782. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23783. // not parallel
  23784. if ( edgeDy < 0 ) {
  23785. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23786. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23787. }
  23788. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23789. if ( inPt.y === edgeLowPt.y ) {
  23790. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23791. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23792. } else {
  23793. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23794. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23795. if ( perpEdge < 0 ) continue;
  23796. inside = ! inside; // true intersection left of inPt
  23797. }
  23798. } else {
  23799. // parallel or collinear
  23800. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23801. // edge lies on the same horizontal line as inPt
  23802. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23803. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23804. // continue;
  23805. }
  23806. }
  23807. return inside;
  23808. }
  23809. var isClockWise = ShapeUtils.isClockWise;
  23810. var subPaths = this.subPaths;
  23811. if ( subPaths.length === 0 ) return [];
  23812. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23813. var solid, tmpPath, tmpShape, shapes = [];
  23814. if ( subPaths.length === 1 ) {
  23815. tmpPath = subPaths[ 0 ];
  23816. tmpShape = new Shape();
  23817. tmpShape.curves = tmpPath.curves;
  23818. shapes.push( tmpShape );
  23819. return shapes;
  23820. }
  23821. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23822. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23823. // console.log("Holes first", holesFirst);
  23824. var betterShapeHoles = [];
  23825. var newShapes = [];
  23826. var newShapeHoles = [];
  23827. var mainIdx = 0;
  23828. var tmpPoints;
  23829. newShapes[ mainIdx ] = undefined;
  23830. newShapeHoles[ mainIdx ] = [];
  23831. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23832. tmpPath = subPaths[ i ];
  23833. tmpPoints = tmpPath.getPoints();
  23834. solid = isClockWise( tmpPoints );
  23835. solid = isCCW ? ! solid : solid;
  23836. if ( solid ) {
  23837. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23838. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23839. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23840. if ( holesFirst ) mainIdx ++;
  23841. newShapeHoles[ mainIdx ] = [];
  23842. //console.log('cw', i);
  23843. } else {
  23844. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23845. //console.log('ccw', i);
  23846. }
  23847. }
  23848. // only Holes? -> probably all Shapes with wrong orientation
  23849. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23850. if ( newShapes.length > 1 ) {
  23851. var ambiguous = false;
  23852. var toChange = [];
  23853. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23854. betterShapeHoles[ sIdx ] = [];
  23855. }
  23856. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23857. var sho = newShapeHoles[ sIdx ];
  23858. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23859. var ho = sho[ hIdx ];
  23860. var hole_unassigned = true;
  23861. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23862. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23863. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23864. if ( hole_unassigned ) {
  23865. hole_unassigned = false;
  23866. betterShapeHoles[ s2Idx ].push( ho );
  23867. } else {
  23868. ambiguous = true;
  23869. }
  23870. }
  23871. }
  23872. if ( hole_unassigned ) {
  23873. betterShapeHoles[ sIdx ].push( ho );
  23874. }
  23875. }
  23876. }
  23877. // console.log("ambiguous: ", ambiguous);
  23878. if ( toChange.length > 0 ) {
  23879. // console.log("to change: ", toChange);
  23880. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23881. }
  23882. }
  23883. var tmpHoles;
  23884. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23885. tmpShape = newShapes[ i ].s;
  23886. shapes.push( tmpShape );
  23887. tmpHoles = newShapeHoles[ i ];
  23888. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23889. tmpShape.holes.push( tmpHoles[ j ].h );
  23890. }
  23891. }
  23892. //console.log("shape", shapes);
  23893. return shapes;
  23894. }
  23895. } );
  23896. /**
  23897. * @author zz85 / http://www.lab4games.net/zz85/blog
  23898. * @author mrdoob / http://mrdoob.com/
  23899. */
  23900. function Font( data ) {
  23901. this.type = 'Font';
  23902. this.data = data;
  23903. }
  23904. Object.assign( Font.prototype, {
  23905. isFont: true,
  23906. generateShapes: function ( text, size ) {
  23907. if ( size === undefined ) size = 100;
  23908. var shapes = [];
  23909. var paths = createPaths( text, size, this.data );
  23910. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23911. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23912. }
  23913. return shapes;
  23914. }
  23915. } );
  23916. function createPaths( text, size, data ) {
  23917. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23918. var scale = size / data.resolution;
  23919. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23920. var paths = [];
  23921. var offsetX = 0, offsetY = 0;
  23922. for ( var i = 0; i < chars.length; i ++ ) {
  23923. var char = chars[ i ];
  23924. if ( char === '\n' ) {
  23925. offsetX = 0;
  23926. offsetY -= line_height;
  23927. } else {
  23928. var ret = createPath( char, scale, offsetX, offsetY, data );
  23929. offsetX += ret.offsetX;
  23930. paths.push( ret.path );
  23931. }
  23932. }
  23933. return paths;
  23934. }
  23935. function createPath( char, scale, offsetX, offsetY, data ) {
  23936. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23937. if ( ! glyph ) {
  23938. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  23939. return;
  23940. }
  23941. var path = new ShapePath();
  23942. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23943. if ( glyph.o ) {
  23944. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23945. for ( var i = 0, l = outline.length; i < l; ) {
  23946. var action = outline[ i ++ ];
  23947. switch ( action ) {
  23948. case 'm': // moveTo
  23949. x = outline[ i ++ ] * scale + offsetX;
  23950. y = outline[ i ++ ] * scale + offsetY;
  23951. path.moveTo( x, y );
  23952. break;
  23953. case 'l': // lineTo
  23954. x = outline[ i ++ ] * scale + offsetX;
  23955. y = outline[ i ++ ] * scale + offsetY;
  23956. path.lineTo( x, y );
  23957. break;
  23958. case 'q': // quadraticCurveTo
  23959. cpx = outline[ i ++ ] * scale + offsetX;
  23960. cpy = outline[ i ++ ] * scale + offsetY;
  23961. cpx1 = outline[ i ++ ] * scale + offsetX;
  23962. cpy1 = outline[ i ++ ] * scale + offsetY;
  23963. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23964. break;
  23965. case 'b': // bezierCurveTo
  23966. cpx = outline[ i ++ ] * scale + offsetX;
  23967. cpy = outline[ i ++ ] * scale + offsetY;
  23968. cpx1 = outline[ i ++ ] * scale + offsetX;
  23969. cpy1 = outline[ i ++ ] * scale + offsetY;
  23970. cpx2 = outline[ i ++ ] * scale + offsetX;
  23971. cpy2 = outline[ i ++ ] * scale + offsetY;
  23972. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23973. break;
  23974. }
  23975. }
  23976. }
  23977. return { offsetX: glyph.ha * scale, path: path };
  23978. }
  23979. /**
  23980. * @author mrdoob / http://mrdoob.com/
  23981. */
  23982. function FontLoader( manager ) {
  23983. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23984. }
  23985. Object.assign( FontLoader.prototype, {
  23986. load: function ( url, onLoad, onProgress, onError ) {
  23987. var scope = this;
  23988. var loader = new FileLoader( this.manager );
  23989. loader.setPath( this.path );
  23990. loader.load( url, function ( text ) {
  23991. var json;
  23992. try {
  23993. json = JSON.parse( text );
  23994. } catch ( e ) {
  23995. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23996. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23997. }
  23998. var font = scope.parse( json );
  23999. if ( onLoad ) onLoad( font );
  24000. }, onProgress, onError );
  24001. },
  24002. parse: function ( json ) {
  24003. return new Font( json );
  24004. },
  24005. setPath: function ( value ) {
  24006. this.path = value;
  24007. return this;
  24008. }
  24009. } );
  24010. /**
  24011. * @author alteredq / http://alteredqualia.com/
  24012. */
  24013. function Loader() {}
  24014. Loader.Handlers = {
  24015. handlers: [],
  24016. add: function ( regex, loader ) {
  24017. this.handlers.push( regex, loader );
  24018. },
  24019. get: function ( file ) {
  24020. var handlers = this.handlers;
  24021. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  24022. var regex = handlers[ i ];
  24023. var loader = handlers[ i + 1 ];
  24024. if ( regex.test( file ) ) {
  24025. return loader;
  24026. }
  24027. }
  24028. return null;
  24029. }
  24030. };
  24031. Object.assign( Loader.prototype, {
  24032. crossOrigin: 'anonymous',
  24033. onLoadStart: function () {},
  24034. onLoadProgress: function () {},
  24035. onLoadComplete: function () {},
  24036. initMaterials: function ( materials, texturePath, crossOrigin ) {
  24037. var array = [];
  24038. for ( var i = 0; i < materials.length; ++ i ) {
  24039. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  24040. }
  24041. return array;
  24042. },
  24043. createMaterial: ( function () {
  24044. var BlendingMode = {
  24045. NoBlending: NoBlending,
  24046. NormalBlending: NormalBlending,
  24047. AdditiveBlending: AdditiveBlending,
  24048. SubtractiveBlending: SubtractiveBlending,
  24049. MultiplyBlending: MultiplyBlending,
  24050. CustomBlending: CustomBlending
  24051. };
  24052. var color = new Color();
  24053. var textureLoader = new TextureLoader();
  24054. var materialLoader = new MaterialLoader();
  24055. return function createMaterial( m, texturePath, crossOrigin ) {
  24056. // convert from old material format
  24057. var textures = {};
  24058. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  24059. var fullPath = texturePath + path;
  24060. var loader = Loader.Handlers.get( fullPath );
  24061. var texture;
  24062. if ( loader !== null ) {
  24063. texture = loader.load( fullPath );
  24064. } else {
  24065. textureLoader.setCrossOrigin( crossOrigin );
  24066. texture = textureLoader.load( fullPath );
  24067. }
  24068. if ( repeat !== undefined ) {
  24069. texture.repeat.fromArray( repeat );
  24070. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  24071. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  24072. }
  24073. if ( offset !== undefined ) {
  24074. texture.offset.fromArray( offset );
  24075. }
  24076. if ( wrap !== undefined ) {
  24077. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  24078. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  24079. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  24080. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  24081. }
  24082. if ( anisotropy !== undefined ) {
  24083. texture.anisotropy = anisotropy;
  24084. }
  24085. var uuid = _Math.generateUUID();
  24086. textures[ uuid ] = texture;
  24087. return uuid;
  24088. }
  24089. //
  24090. var json = {
  24091. uuid: _Math.generateUUID(),
  24092. type: 'MeshLambertMaterial'
  24093. };
  24094. for ( var name in m ) {
  24095. var value = m[ name ];
  24096. switch ( name ) {
  24097. case 'DbgColor':
  24098. case 'DbgIndex':
  24099. case 'opticalDensity':
  24100. case 'illumination':
  24101. break;
  24102. case 'DbgName':
  24103. json.name = value;
  24104. break;
  24105. case 'blending':
  24106. json.blending = BlendingMode[ value ];
  24107. break;
  24108. case 'colorAmbient':
  24109. case 'mapAmbient':
  24110. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  24111. break;
  24112. case 'colorDiffuse':
  24113. json.color = color.fromArray( value ).getHex();
  24114. break;
  24115. case 'colorSpecular':
  24116. json.specular = color.fromArray( value ).getHex();
  24117. break;
  24118. case 'colorEmissive':
  24119. json.emissive = color.fromArray( value ).getHex();
  24120. break;
  24121. case 'specularCoef':
  24122. json.shininess = value;
  24123. break;
  24124. case 'shading':
  24125. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  24126. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  24127. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  24128. break;
  24129. case 'mapDiffuse':
  24130. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  24131. break;
  24132. case 'mapDiffuseRepeat':
  24133. case 'mapDiffuseOffset':
  24134. case 'mapDiffuseWrap':
  24135. case 'mapDiffuseAnisotropy':
  24136. break;
  24137. case 'mapEmissive':
  24138. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  24139. break;
  24140. case 'mapEmissiveRepeat':
  24141. case 'mapEmissiveOffset':
  24142. case 'mapEmissiveWrap':
  24143. case 'mapEmissiveAnisotropy':
  24144. break;
  24145. case 'mapLight':
  24146. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  24147. break;
  24148. case 'mapLightRepeat':
  24149. case 'mapLightOffset':
  24150. case 'mapLightWrap':
  24151. case 'mapLightAnisotropy':
  24152. break;
  24153. case 'mapAO':
  24154. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  24155. break;
  24156. case 'mapAORepeat':
  24157. case 'mapAOOffset':
  24158. case 'mapAOWrap':
  24159. case 'mapAOAnisotropy':
  24160. break;
  24161. case 'mapBump':
  24162. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  24163. break;
  24164. case 'mapBumpScale':
  24165. json.bumpScale = value;
  24166. break;
  24167. case 'mapBumpRepeat':
  24168. case 'mapBumpOffset':
  24169. case 'mapBumpWrap':
  24170. case 'mapBumpAnisotropy':
  24171. break;
  24172. case 'mapNormal':
  24173. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  24174. break;
  24175. case 'mapNormalFactor':
  24176. json.normalScale = value;
  24177. break;
  24178. case 'mapNormalRepeat':
  24179. case 'mapNormalOffset':
  24180. case 'mapNormalWrap':
  24181. case 'mapNormalAnisotropy':
  24182. break;
  24183. case 'mapSpecular':
  24184. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  24185. break;
  24186. case 'mapSpecularRepeat':
  24187. case 'mapSpecularOffset':
  24188. case 'mapSpecularWrap':
  24189. case 'mapSpecularAnisotropy':
  24190. break;
  24191. case 'mapMetalness':
  24192. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  24193. break;
  24194. case 'mapMetalnessRepeat':
  24195. case 'mapMetalnessOffset':
  24196. case 'mapMetalnessWrap':
  24197. case 'mapMetalnessAnisotropy':
  24198. break;
  24199. case 'mapRoughness':
  24200. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  24201. break;
  24202. case 'mapRoughnessRepeat':
  24203. case 'mapRoughnessOffset':
  24204. case 'mapRoughnessWrap':
  24205. case 'mapRoughnessAnisotropy':
  24206. break;
  24207. case 'mapAlpha':
  24208. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  24209. break;
  24210. case 'mapAlphaRepeat':
  24211. case 'mapAlphaOffset':
  24212. case 'mapAlphaWrap':
  24213. case 'mapAlphaAnisotropy':
  24214. break;
  24215. case 'flipSided':
  24216. json.side = BackSide;
  24217. break;
  24218. case 'doubleSided':
  24219. json.side = DoubleSide;
  24220. break;
  24221. case 'transparency':
  24222. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  24223. json.opacity = value;
  24224. break;
  24225. case 'depthTest':
  24226. case 'depthWrite':
  24227. case 'colorWrite':
  24228. case 'opacity':
  24229. case 'reflectivity':
  24230. case 'transparent':
  24231. case 'visible':
  24232. case 'wireframe':
  24233. json[ name ] = value;
  24234. break;
  24235. case 'vertexColors':
  24236. if ( value === true ) json.vertexColors = VertexColors;
  24237. if ( value === 'face' ) json.vertexColors = FaceColors;
  24238. break;
  24239. default:
  24240. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  24241. break;
  24242. }
  24243. }
  24244. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  24245. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  24246. if ( json.opacity < 1 ) json.transparent = true;
  24247. materialLoader.setTextures( textures );
  24248. return materialLoader.parse( json );
  24249. };
  24250. } )()
  24251. } );
  24252. /**
  24253. * @author mrdoob / http://mrdoob.com/
  24254. */
  24255. var context;
  24256. var AudioContext = {
  24257. getContext: function () {
  24258. if ( context === undefined ) {
  24259. context = new ( window.AudioContext || window.webkitAudioContext )();
  24260. }
  24261. return context;
  24262. },
  24263. setContext: function ( value ) {
  24264. context = value;
  24265. }
  24266. };
  24267. /**
  24268. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24269. */
  24270. function AudioLoader( manager ) {
  24271. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  24272. }
  24273. Object.assign( AudioLoader.prototype, {
  24274. load: function ( url, onLoad, onProgress, onError ) {
  24275. var loader = new FileLoader( this.manager );
  24276. loader.setResponseType( 'arraybuffer' );
  24277. loader.setPath( this.path );
  24278. loader.load( url, function ( buffer ) {
  24279. // Create a copy of the buffer. The `decodeAudioData` method
  24280. // detaches the buffer when complete, preventing reuse.
  24281. var bufferCopy = buffer.slice( 0 );
  24282. var context = AudioContext.getContext();
  24283. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  24284. onLoad( audioBuffer );
  24285. } );
  24286. }, onProgress, onError );
  24287. },
  24288. setPath: function ( value ) {
  24289. this.path = value;
  24290. return this;
  24291. }
  24292. } );
  24293. /**
  24294. * @author bhouston / http://clara.io
  24295. * @author WestLangley / http://github.com/WestLangley
  24296. *
  24297. * Primary reference:
  24298. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24299. *
  24300. * Secondary reference:
  24301. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24302. */
  24303. // 3-band SH defined by 9 coefficients
  24304. function SphericalHarmonics3() {
  24305. this.coefficients = [];
  24306. for ( var i = 0; i < 9; i ++ ) {
  24307. this.coefficients.push( new Vector3() );
  24308. }
  24309. }
  24310. Object.assign( SphericalHarmonics3.prototype, {
  24311. isSphericalHarmonics3: true,
  24312. set: function ( coefficients ) {
  24313. for ( var i = 0; i < 9; i ++ ) {
  24314. this.coefficients[ i ].copy( coefficients[ i ] );
  24315. }
  24316. return this;
  24317. },
  24318. zero: function () {
  24319. for ( var i = 0; i < 9; i ++ ) {
  24320. this.coefficients[ i ].set( 0, 0, 0 );
  24321. }
  24322. return this;
  24323. },
  24324. // get the radiance in the direction of the normal
  24325. // target is a Vector3
  24326. getAt: function ( normal, target ) {
  24327. // normal is assumed to be unit length
  24328. var x = normal.x, y = normal.y, z = normal.z;
  24329. var coeff = this.coefficients;
  24330. // band 0
  24331. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  24332. // band 1
  24333. target.addScale( coeff[ 1 ], 0.488603 * y );
  24334. target.addScale( coeff[ 2 ], 0.488603 * z );
  24335. target.addScale( coeff[ 3 ], 0.488603 * x );
  24336. // band 2
  24337. target.addScale( coeff[ 4 ], 1.092548 * ( x * y ) );
  24338. target.addScale( coeff[ 5 ], 1.092548 * ( y * z ) );
  24339. target.addScale( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  24340. target.addScale( coeff[ 7 ], 1.092548 * ( x * z ) );
  24341. target.addScale( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  24342. return target;
  24343. },
  24344. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24345. // target is a Vector3
  24346. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24347. getIrradianceAt: function ( normal, target ) {
  24348. // normal is assumed to be unit length
  24349. var x = normal.x, y = normal.y, z = normal.z;
  24350. var coeff = this.coefficients;
  24351. // band 0
  24352. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  24353. // band 1
  24354. target.addScale( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  24355. target.addScale( coeff[ 2 ], 2.0 * 0.511664 * z );
  24356. target.addScale( coeff[ 3 ], 2.0 * 0.511664 * x );
  24357. // band 2
  24358. target.addScale( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  24359. target.addScale( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  24360. target.addScale( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24361. target.addScale( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  24362. target.addScale( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  24363. return target;
  24364. },
  24365. add: function ( sh ) {
  24366. for ( var i = 0; i < 9; i ++ ) {
  24367. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24368. }
  24369. return this;
  24370. },
  24371. scale: function ( s ) {
  24372. for ( var i = 0; i < 9; i ++ ) {
  24373. this.coefficients[ i ].multiplyScalar( s );
  24374. }
  24375. return this;
  24376. },
  24377. lerp: function ( sh, alpha ) {
  24378. for ( var i = 0; i < 9; i ++ ) {
  24379. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24380. }
  24381. return this;
  24382. },
  24383. equals: function ( sh ) {
  24384. for ( var i = 0; i < 9; i ++ ) {
  24385. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24386. return false;
  24387. }
  24388. }
  24389. return true;
  24390. },
  24391. copy: function ( sh ) {
  24392. return this.set( sh.coefficients );
  24393. },
  24394. clone: function () {
  24395. return new this.constructor().copy( this );
  24396. },
  24397. fromArray: function ( array ) {
  24398. var coefficients = this.coefficients;
  24399. for ( var i = 0; i < 9; i ++ ) {
  24400. coefficients[ i ].fromArray( array, i * 3 );
  24401. }
  24402. return this;
  24403. },
  24404. toArray: function () {
  24405. var array = [];
  24406. var coefficients = this.coefficients;
  24407. for ( var i = 0; i < 9; i ++ ) {
  24408. coefficients[ i ].toArray( array, i * 3 );
  24409. }
  24410. return array;
  24411. }
  24412. } );
  24413. Object.assign( SphericalHarmonics3, {
  24414. // evaluate the basis functions
  24415. // shBasis is an Array[ 9 ]
  24416. getBasisAt: function ( normal, shBasis ) {
  24417. // normal is assumed to be unit length
  24418. var x = normal.x, y = normal.y, z = normal.z;
  24419. // band 0
  24420. shBasis[ 0 ] = 0.282095;
  24421. // band 1
  24422. shBasis[ 1 ] = 0.488603 * y;
  24423. shBasis[ 2 ] = 0.488603 * z;
  24424. shBasis[ 3 ] = 0.488603 * x;
  24425. // band 2
  24426. shBasis[ 4 ] = 1.092548 * x * y;
  24427. shBasis[ 5 ] = 1.092548 * y * z;
  24428. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24429. shBasis[ 7 ] = 1.092548 * x * z;
  24430. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24431. }
  24432. } );
  24433. /**
  24434. * @author WestLangley / http://github.com/WestLangley
  24435. *
  24436. * A LightProbe is a source of indirect-diffuse light
  24437. */
  24438. function LightProbe( sh, intensity ) {
  24439. Light.call( this, undefined, intensity );
  24440. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24441. }
  24442. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24443. constructor: LightProbe,
  24444. isLightProbe: true,
  24445. copy: function ( source ) {
  24446. Light.prototype.copy.call( this, source );
  24447. this.sh.copy( source.sh );
  24448. this.intensity = source.intensity;
  24449. return this;
  24450. },
  24451. toJSON: function ( meta ) {
  24452. var data = Light.prototype.toJSON.call( this, meta );
  24453. // data.sh = this.sh.toArray(); // todo
  24454. return data;
  24455. }
  24456. } );
  24457. /**
  24458. * @author WestLangley / http://github.com/WestLangley
  24459. */
  24460. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24461. LightProbe.call( this, undefined, intensity );
  24462. var color1 = new Color().set( skyColor );
  24463. var color2 = new Color().set( groundColor );
  24464. var sky = new Vector3( color1.r, color1.g, color1.b );
  24465. var ground = new Vector3( color2.r, color2.g, color2.b );
  24466. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24467. var c0 = Math.sqrt( Math.PI );
  24468. var c1 = c0 * Math.sqrt( 0.75 );
  24469. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24470. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24471. }
  24472. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24473. constructor: HemisphereLightProbe,
  24474. isHemisphereLightProbe: true,
  24475. copy: function ( source ) { // modifying colors not currently supported
  24476. LightProbe.prototype.copy.call( this, source );
  24477. return this;
  24478. },
  24479. toJSON: function ( meta ) {
  24480. var data = LightProbe.prototype.toJSON.call( this, meta );
  24481. // data.sh = this.sh.toArray(); // todo
  24482. return data;
  24483. }
  24484. } );
  24485. /**
  24486. * @author WestLangley / http://github.com/WestLangley
  24487. */
  24488. function AmbientLightProbe( color, intensity ) {
  24489. LightProbe.call( this, undefined, intensity );
  24490. var color1 = new Color().set( color );
  24491. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24492. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24493. }
  24494. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24495. constructor: AmbientLightProbe,
  24496. isAmbientLightProbe: true,
  24497. copy: function ( source ) { // modifying color not currently supported
  24498. LightProbe.prototype.copy.call( this, source );
  24499. return this;
  24500. },
  24501. toJSON: function ( meta ) {
  24502. var data = LightProbe.prototype.toJSON.call( this, meta );
  24503. // data.sh = this.sh.toArray(); // todo
  24504. return data;
  24505. }
  24506. } );
  24507. /**
  24508. * @author mrdoob / http://mrdoob.com/
  24509. */
  24510. function StereoCamera() {
  24511. this.type = 'StereoCamera';
  24512. this.aspect = 1;
  24513. this.eyeSep = 0.064;
  24514. this.cameraL = new PerspectiveCamera();
  24515. this.cameraL.layers.enable( 1 );
  24516. this.cameraL.matrixAutoUpdate = false;
  24517. this.cameraR = new PerspectiveCamera();
  24518. this.cameraR.layers.enable( 2 );
  24519. this.cameraR.matrixAutoUpdate = false;
  24520. }
  24521. Object.assign( StereoCamera.prototype, {
  24522. update: ( function () {
  24523. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  24524. var eyeRight = new Matrix4();
  24525. var eyeLeft = new Matrix4();
  24526. return function update( camera ) {
  24527. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  24528. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  24529. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  24530. if ( needsUpdate ) {
  24531. instance = this;
  24532. focus = camera.focus;
  24533. fov = camera.fov;
  24534. aspect = camera.aspect * this.aspect;
  24535. near = camera.near;
  24536. far = camera.far;
  24537. zoom = camera.zoom;
  24538. // Off-axis stereoscopic effect based on
  24539. // http://paulbourke.net/stereographics/stereorender/
  24540. var projectionMatrix = camera.projectionMatrix.clone();
  24541. eyeSep = this.eyeSep / 2;
  24542. var eyeSepOnProjection = eyeSep * near / focus;
  24543. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  24544. var xmin, xmax;
  24545. // translate xOffset
  24546. eyeLeft.elements[ 12 ] = - eyeSep;
  24547. eyeRight.elements[ 12 ] = eyeSep;
  24548. // for left eye
  24549. xmin = - ymax * aspect + eyeSepOnProjection;
  24550. xmax = ymax * aspect + eyeSepOnProjection;
  24551. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24552. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24553. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24554. // for right eye
  24555. xmin = - ymax * aspect - eyeSepOnProjection;
  24556. xmax = ymax * aspect - eyeSepOnProjection;
  24557. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24558. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24559. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24560. }
  24561. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  24562. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  24563. };
  24564. } )()
  24565. } );
  24566. /**
  24567. * @author alteredq / http://alteredqualia.com/
  24568. */
  24569. function Clock( autoStart ) {
  24570. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24571. this.startTime = 0;
  24572. this.oldTime = 0;
  24573. this.elapsedTime = 0;
  24574. this.running = false;
  24575. }
  24576. Object.assign( Clock.prototype, {
  24577. start: function () {
  24578. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24579. this.oldTime = this.startTime;
  24580. this.elapsedTime = 0;
  24581. this.running = true;
  24582. },
  24583. stop: function () {
  24584. this.getElapsedTime();
  24585. this.running = false;
  24586. this.autoStart = false;
  24587. },
  24588. getElapsedTime: function () {
  24589. this.getDelta();
  24590. return this.elapsedTime;
  24591. },
  24592. getDelta: function () {
  24593. var diff = 0;
  24594. if ( this.autoStart && ! this.running ) {
  24595. this.start();
  24596. return 0;
  24597. }
  24598. if ( this.running ) {
  24599. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24600. diff = ( newTime - this.oldTime ) / 1000;
  24601. this.oldTime = newTime;
  24602. this.elapsedTime += diff;
  24603. }
  24604. return diff;
  24605. }
  24606. } );
  24607. /**
  24608. * @author mrdoob / http://mrdoob.com/
  24609. */
  24610. function AudioListener() {
  24611. Object3D.call( this );
  24612. this.type = 'AudioListener';
  24613. this.context = AudioContext.getContext();
  24614. this.gain = this.context.createGain();
  24615. this.gain.connect( this.context.destination );
  24616. this.filter = null;
  24617. this.timeDelta = 0;
  24618. }
  24619. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24620. constructor: AudioListener,
  24621. getInput: function () {
  24622. return this.gain;
  24623. },
  24624. removeFilter: function ( ) {
  24625. if ( this.filter !== null ) {
  24626. this.gain.disconnect( this.filter );
  24627. this.filter.disconnect( this.context.destination );
  24628. this.gain.connect( this.context.destination );
  24629. this.filter = null;
  24630. }
  24631. return this;
  24632. },
  24633. getFilter: function () {
  24634. return this.filter;
  24635. },
  24636. setFilter: function ( value ) {
  24637. if ( this.filter !== null ) {
  24638. this.gain.disconnect( this.filter );
  24639. this.filter.disconnect( this.context.destination );
  24640. } else {
  24641. this.gain.disconnect( this.context.destination );
  24642. }
  24643. this.filter = value;
  24644. this.gain.connect( this.filter );
  24645. this.filter.connect( this.context.destination );
  24646. return this;
  24647. },
  24648. getMasterVolume: function () {
  24649. return this.gain.gain.value;
  24650. },
  24651. setMasterVolume: function ( value ) {
  24652. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24653. return this;
  24654. },
  24655. updateMatrixWorld: ( function () {
  24656. var position = new Vector3();
  24657. var quaternion = new Quaternion();
  24658. var scale = new Vector3();
  24659. var orientation = new Vector3();
  24660. var clock = new Clock();
  24661. return function updateMatrixWorld( force ) {
  24662. Object3D.prototype.updateMatrixWorld.call( this, force );
  24663. var listener = this.context.listener;
  24664. var up = this.up;
  24665. this.timeDelta = clock.getDelta();
  24666. this.matrixWorld.decompose( position, quaternion, scale );
  24667. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24668. if ( listener.positionX ) {
  24669. // code path for Chrome (see #14393)
  24670. var endTime = this.context.currentTime + this.timeDelta;
  24671. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24672. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24673. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24674. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24675. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24676. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24677. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24678. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24679. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24680. } else {
  24681. listener.setPosition( position.x, position.y, position.z );
  24682. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24683. }
  24684. };
  24685. } )()
  24686. } );
  24687. /**
  24688. * @author mrdoob / http://mrdoob.com/
  24689. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24690. */
  24691. function Audio( listener ) {
  24692. Object3D.call( this );
  24693. this.type = 'Audio';
  24694. this.listener = listener;
  24695. this.context = listener.context;
  24696. this.gain = this.context.createGain();
  24697. this.gain.connect( listener.getInput() );
  24698. this.autoplay = false;
  24699. this.buffer = null;
  24700. this.detune = 0;
  24701. this.loop = false;
  24702. this.startTime = 0;
  24703. this.offset = 0;
  24704. this.playbackRate = 1;
  24705. this.isPlaying = false;
  24706. this.hasPlaybackControl = true;
  24707. this.sourceType = 'empty';
  24708. this.filters = [];
  24709. }
  24710. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24711. constructor: Audio,
  24712. getOutput: function () {
  24713. return this.gain;
  24714. },
  24715. setNodeSource: function ( audioNode ) {
  24716. this.hasPlaybackControl = false;
  24717. this.sourceType = 'audioNode';
  24718. this.source = audioNode;
  24719. this.connect();
  24720. return this;
  24721. },
  24722. setMediaElementSource: function ( mediaElement ) {
  24723. this.hasPlaybackControl = false;
  24724. this.sourceType = 'mediaNode';
  24725. this.source = this.context.createMediaElementSource( mediaElement );
  24726. this.connect();
  24727. return this;
  24728. },
  24729. setBuffer: function ( audioBuffer ) {
  24730. this.buffer = audioBuffer;
  24731. this.sourceType = 'buffer';
  24732. if ( this.autoplay ) this.play();
  24733. return this;
  24734. },
  24735. play: function () {
  24736. if ( this.isPlaying === true ) {
  24737. console.warn( 'THREE.Audio: Audio is already playing.' );
  24738. return;
  24739. }
  24740. if ( this.hasPlaybackControl === false ) {
  24741. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24742. return;
  24743. }
  24744. var source = this.context.createBufferSource();
  24745. source.buffer = this.buffer;
  24746. source.loop = this.loop;
  24747. source.onended = this.onEnded.bind( this );
  24748. this.startTime = this.context.currentTime;
  24749. source.start( this.startTime, this.offset );
  24750. this.isPlaying = true;
  24751. this.source = source;
  24752. this.setDetune( this.detune );
  24753. this.setPlaybackRate( this.playbackRate );
  24754. return this.connect();
  24755. },
  24756. pause: function () {
  24757. if ( this.hasPlaybackControl === false ) {
  24758. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24759. return;
  24760. }
  24761. if ( this.isPlaying === true ) {
  24762. this.source.stop();
  24763. this.source.onended = null;
  24764. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24765. this.isPlaying = false;
  24766. }
  24767. return this;
  24768. },
  24769. stop: function () {
  24770. if ( this.hasPlaybackControl === false ) {
  24771. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24772. return;
  24773. }
  24774. this.source.stop();
  24775. this.source.onended = null;
  24776. this.offset = 0;
  24777. this.isPlaying = false;
  24778. return this;
  24779. },
  24780. connect: function () {
  24781. if ( this.filters.length > 0 ) {
  24782. this.source.connect( this.filters[ 0 ] );
  24783. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24784. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24785. }
  24786. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24787. } else {
  24788. this.source.connect( this.getOutput() );
  24789. }
  24790. return this;
  24791. },
  24792. disconnect: function () {
  24793. if ( this.filters.length > 0 ) {
  24794. this.source.disconnect( this.filters[ 0 ] );
  24795. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24796. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24797. }
  24798. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24799. } else {
  24800. this.source.disconnect( this.getOutput() );
  24801. }
  24802. return this;
  24803. },
  24804. getFilters: function () {
  24805. return this.filters;
  24806. },
  24807. setFilters: function ( value ) {
  24808. if ( ! value ) value = [];
  24809. if ( this.isPlaying === true ) {
  24810. this.disconnect();
  24811. this.filters = value;
  24812. this.connect();
  24813. } else {
  24814. this.filters = value;
  24815. }
  24816. return this;
  24817. },
  24818. setDetune: function ( value ) {
  24819. this.detune = value;
  24820. if ( this.source.detune === undefined ) return; // only set detune when available
  24821. if ( this.isPlaying === true ) {
  24822. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24823. }
  24824. return this;
  24825. },
  24826. getDetune: function () {
  24827. return this.detune;
  24828. },
  24829. getFilter: function () {
  24830. return this.getFilters()[ 0 ];
  24831. },
  24832. setFilter: function ( filter ) {
  24833. return this.setFilters( filter ? [ filter ] : [] );
  24834. },
  24835. setPlaybackRate: function ( value ) {
  24836. if ( this.hasPlaybackControl === false ) {
  24837. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24838. return;
  24839. }
  24840. this.playbackRate = value;
  24841. if ( this.isPlaying === true ) {
  24842. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24843. }
  24844. return this;
  24845. },
  24846. getPlaybackRate: function () {
  24847. return this.playbackRate;
  24848. },
  24849. onEnded: function () {
  24850. this.isPlaying = false;
  24851. },
  24852. getLoop: function () {
  24853. if ( this.hasPlaybackControl === false ) {
  24854. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24855. return false;
  24856. }
  24857. return this.loop;
  24858. },
  24859. setLoop: function ( value ) {
  24860. if ( this.hasPlaybackControl === false ) {
  24861. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24862. return;
  24863. }
  24864. this.loop = value;
  24865. if ( this.isPlaying === true ) {
  24866. this.source.loop = this.loop;
  24867. }
  24868. return this;
  24869. },
  24870. getVolume: function () {
  24871. return this.gain.gain.value;
  24872. },
  24873. setVolume: function ( value ) {
  24874. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24875. return this;
  24876. }
  24877. } );
  24878. /**
  24879. * @author mrdoob / http://mrdoob.com/
  24880. */
  24881. function PositionalAudio( listener ) {
  24882. Audio.call( this, listener );
  24883. this.panner = this.context.createPanner();
  24884. this.panner.panningModel = 'HRTF';
  24885. this.panner.connect( this.gain );
  24886. }
  24887. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24888. constructor: PositionalAudio,
  24889. getOutput: function () {
  24890. return this.panner;
  24891. },
  24892. getRefDistance: function () {
  24893. return this.panner.refDistance;
  24894. },
  24895. setRefDistance: function ( value ) {
  24896. this.panner.refDistance = value;
  24897. return this;
  24898. },
  24899. getRolloffFactor: function () {
  24900. return this.panner.rolloffFactor;
  24901. },
  24902. setRolloffFactor: function ( value ) {
  24903. this.panner.rolloffFactor = value;
  24904. return this;
  24905. },
  24906. getDistanceModel: function () {
  24907. return this.panner.distanceModel;
  24908. },
  24909. setDistanceModel: function ( value ) {
  24910. this.panner.distanceModel = value;
  24911. return this;
  24912. },
  24913. getMaxDistance: function () {
  24914. return this.panner.maxDistance;
  24915. },
  24916. setMaxDistance: function ( value ) {
  24917. this.panner.maxDistance = value;
  24918. return this;
  24919. },
  24920. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24921. this.panner.coneInnerAngle = coneInnerAngle;
  24922. this.panner.coneOuterAngle = coneOuterAngle;
  24923. this.panner.coneOuterGain = coneOuterGain;
  24924. return this;
  24925. },
  24926. updateMatrixWorld: ( function () {
  24927. var position = new Vector3();
  24928. var quaternion = new Quaternion();
  24929. var scale = new Vector3();
  24930. var orientation = new Vector3();
  24931. return function updateMatrixWorld( force ) {
  24932. Object3D.prototype.updateMatrixWorld.call( this, force );
  24933. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24934. this.matrixWorld.decompose( position, quaternion, scale );
  24935. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24936. var panner = this.panner;
  24937. if ( panner.positionX ) {
  24938. // code path for Chrome and Firefox (see #14393)
  24939. var endTime = this.context.currentTime + this.listener.timeDelta;
  24940. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24941. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24942. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24943. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24944. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24945. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24946. } else {
  24947. panner.setPosition( position.x, position.y, position.z );
  24948. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24949. }
  24950. };
  24951. } )()
  24952. } );
  24953. /**
  24954. * @author mrdoob / http://mrdoob.com/
  24955. */
  24956. function AudioAnalyser( audio, fftSize ) {
  24957. this.analyser = audio.context.createAnalyser();
  24958. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24959. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24960. audio.getOutput().connect( this.analyser );
  24961. }
  24962. Object.assign( AudioAnalyser.prototype, {
  24963. getFrequencyData: function () {
  24964. this.analyser.getByteFrequencyData( this.data );
  24965. return this.data;
  24966. },
  24967. getAverageFrequency: function () {
  24968. var value = 0, data = this.getFrequencyData();
  24969. for ( var i = 0; i < data.length; i ++ ) {
  24970. value += data[ i ];
  24971. }
  24972. return value / data.length;
  24973. }
  24974. } );
  24975. /**
  24976. *
  24977. * Buffered scene graph property that allows weighted accumulation.
  24978. *
  24979. *
  24980. * @author Ben Houston / http://clara.io/
  24981. * @author David Sarno / http://lighthaus.us/
  24982. * @author tschw
  24983. */
  24984. function PropertyMixer( binding, typeName, valueSize ) {
  24985. this.binding = binding;
  24986. this.valueSize = valueSize;
  24987. var bufferType = Float64Array,
  24988. mixFunction;
  24989. switch ( typeName ) {
  24990. case 'quaternion':
  24991. mixFunction = this._slerp;
  24992. break;
  24993. case 'string':
  24994. case 'bool':
  24995. bufferType = Array;
  24996. mixFunction = this._select;
  24997. break;
  24998. default:
  24999. mixFunction = this._lerp;
  25000. }
  25001. this.buffer = new bufferType( valueSize * 4 );
  25002. // layout: [ incoming | accu0 | accu1 | orig ]
  25003. //
  25004. // interpolators can use .buffer as their .result
  25005. // the data then goes to 'incoming'
  25006. //
  25007. // 'accu0' and 'accu1' are used frame-interleaved for
  25008. // the cumulative result and are compared to detect
  25009. // changes
  25010. //
  25011. // 'orig' stores the original state of the property
  25012. this._mixBufferRegion = mixFunction;
  25013. this.cumulativeWeight = 0;
  25014. this.useCount = 0;
  25015. this.referenceCount = 0;
  25016. }
  25017. Object.assign( PropertyMixer.prototype, {
  25018. // accumulate data in the 'incoming' region into 'accu<i>'
  25019. accumulate: function ( accuIndex, weight ) {
  25020. // note: happily accumulating nothing when weight = 0, the caller knows
  25021. // the weight and shouldn't have made the call in the first place
  25022. var buffer = this.buffer,
  25023. stride = this.valueSize,
  25024. offset = accuIndex * stride + stride,
  25025. currentWeight = this.cumulativeWeight;
  25026. if ( currentWeight === 0 ) {
  25027. // accuN := incoming * weight
  25028. for ( var i = 0; i !== stride; ++ i ) {
  25029. buffer[ offset + i ] = buffer[ i ];
  25030. }
  25031. currentWeight = weight;
  25032. } else {
  25033. // accuN := accuN + incoming * weight
  25034. currentWeight += weight;
  25035. var mix = weight / currentWeight;
  25036. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25037. }
  25038. this.cumulativeWeight = currentWeight;
  25039. },
  25040. // apply the state of 'accu<i>' to the binding when accus differ
  25041. apply: function ( accuIndex ) {
  25042. var stride = this.valueSize,
  25043. buffer = this.buffer,
  25044. offset = accuIndex * stride + stride,
  25045. weight = this.cumulativeWeight,
  25046. binding = this.binding;
  25047. this.cumulativeWeight = 0;
  25048. if ( weight < 1 ) {
  25049. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25050. var originalValueOffset = stride * 3;
  25051. this._mixBufferRegion(
  25052. buffer, offset, originalValueOffset, 1 - weight, stride );
  25053. }
  25054. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  25055. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25056. // value has changed -> update scene graph
  25057. binding.setValue( buffer, offset );
  25058. break;
  25059. }
  25060. }
  25061. },
  25062. // remember the state of the bound property and copy it to both accus
  25063. saveOriginalState: function () {
  25064. var binding = this.binding;
  25065. var buffer = this.buffer,
  25066. stride = this.valueSize,
  25067. originalValueOffset = stride * 3;
  25068. binding.getValue( buffer, originalValueOffset );
  25069. // accu[0..1] := orig -- initially detect changes against the original
  25070. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25071. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25072. }
  25073. this.cumulativeWeight = 0;
  25074. },
  25075. // apply the state previously taken via 'saveOriginalState' to the binding
  25076. restoreOriginalState: function () {
  25077. var originalValueOffset = this.valueSize * 3;
  25078. this.binding.setValue( this.buffer, originalValueOffset );
  25079. },
  25080. // mix functions
  25081. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25082. if ( t >= 0.5 ) {
  25083. for ( var i = 0; i !== stride; ++ i ) {
  25084. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  25085. }
  25086. }
  25087. },
  25088. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  25089. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  25090. },
  25091. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25092. var s = 1 - t;
  25093. for ( var i = 0; i !== stride; ++ i ) {
  25094. var j = dstOffset + i;
  25095. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  25096. }
  25097. }
  25098. } );
  25099. /**
  25100. *
  25101. * A reference to a real property in the scene graph.
  25102. *
  25103. *
  25104. * @author Ben Houston / http://clara.io/
  25105. * @author David Sarno / http://lighthaus.us/
  25106. * @author tschw
  25107. */
  25108. // Characters [].:/ are reserved for track binding syntax.
  25109. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25110. function Composite( targetGroup, path, optionalParsedPath ) {
  25111. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  25112. this._targetGroup = targetGroup;
  25113. this._bindings = targetGroup.subscribe_( path, parsedPath );
  25114. }
  25115. Object.assign( Composite.prototype, {
  25116. getValue: function ( array, offset ) {
  25117. this.bind(); // bind all binding
  25118. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25119. binding = this._bindings[ firstValidIndex ];
  25120. // and only call .getValue on the first
  25121. if ( binding !== undefined ) binding.getValue( array, offset );
  25122. },
  25123. setValue: function ( array, offset ) {
  25124. var bindings = this._bindings;
  25125. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25126. bindings[ i ].setValue( array, offset );
  25127. }
  25128. },
  25129. bind: function () {
  25130. var bindings = this._bindings;
  25131. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25132. bindings[ i ].bind();
  25133. }
  25134. },
  25135. unbind: function () {
  25136. var bindings = this._bindings;
  25137. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25138. bindings[ i ].unbind();
  25139. }
  25140. }
  25141. } );
  25142. function PropertyBinding( rootNode, path, parsedPath ) {
  25143. this.path = path;
  25144. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  25145. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  25146. this.rootNode = rootNode;
  25147. }
  25148. Object.assign( PropertyBinding, {
  25149. Composite: Composite,
  25150. create: function ( root, path, parsedPath ) {
  25151. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  25152. return new PropertyBinding( root, path, parsedPath );
  25153. } else {
  25154. return new PropertyBinding.Composite( root, path, parsedPath );
  25155. }
  25156. },
  25157. /**
  25158. * Replaces spaces with underscores and removes unsupported characters from
  25159. * node names, to ensure compatibility with parseTrackName().
  25160. *
  25161. * @param {string} name Node name to be sanitized.
  25162. * @return {string}
  25163. */
  25164. sanitizeNodeName: ( function () {
  25165. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  25166. return function sanitizeNodeName( name ) {
  25167. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  25168. };
  25169. }() ),
  25170. parseTrackName: function () {
  25171. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25172. // only latin characters, and the unicode \p{L} is not yet supported. So
  25173. // instead, we exclude reserved characters and match everything else.
  25174. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  25175. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  25176. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25177. // be matched to parse the rest of the track name.
  25178. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  25179. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25180. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  25181. // Object on target node, and accessor. May not contain reserved
  25182. // characters. Accessor may contain any character except closing bracket.
  25183. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  25184. // Property and accessor. May not contain reserved characters. Accessor may
  25185. // contain any non-bracket characters.
  25186. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  25187. var trackRe = new RegExp( ''
  25188. + '^'
  25189. + directoryRe
  25190. + nodeRe
  25191. + objectRe
  25192. + propertyRe
  25193. + '$'
  25194. );
  25195. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  25196. return function parseTrackName( trackName ) {
  25197. var matches = trackRe.exec( trackName );
  25198. if ( ! matches ) {
  25199. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  25200. }
  25201. var results = {
  25202. // directoryName: matches[ 1 ], // (tschw) currently unused
  25203. nodeName: matches[ 2 ],
  25204. objectName: matches[ 3 ],
  25205. objectIndex: matches[ 4 ],
  25206. propertyName: matches[ 5 ], // required
  25207. propertyIndex: matches[ 6 ]
  25208. };
  25209. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  25210. if ( lastDot !== undefined && lastDot !== - 1 ) {
  25211. var objectName = results.nodeName.substring( lastDot + 1 );
  25212. // Object names must be checked against a whitelist. Otherwise, there
  25213. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25214. // 'bar' could be the objectName, or part of a nodeName (which can
  25215. // include '.' characters).
  25216. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  25217. results.nodeName = results.nodeName.substring( 0, lastDot );
  25218. results.objectName = objectName;
  25219. }
  25220. }
  25221. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  25222. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  25223. }
  25224. return results;
  25225. };
  25226. }(),
  25227. findNode: function ( root, nodeName ) {
  25228. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  25229. return root;
  25230. }
  25231. // search into skeleton bones.
  25232. if ( root.skeleton ) {
  25233. var bone = root.skeleton.getBoneByName( nodeName );
  25234. if ( bone !== undefined ) {
  25235. return bone;
  25236. }
  25237. }
  25238. // search into node subtree.
  25239. if ( root.children ) {
  25240. var searchNodeSubtree = function ( children ) {
  25241. for ( var i = 0; i < children.length; i ++ ) {
  25242. var childNode = children[ i ];
  25243. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  25244. return childNode;
  25245. }
  25246. var result = searchNodeSubtree( childNode.children );
  25247. if ( result ) return result;
  25248. }
  25249. return null;
  25250. };
  25251. var subTreeNode = searchNodeSubtree( root.children );
  25252. if ( subTreeNode ) {
  25253. return subTreeNode;
  25254. }
  25255. }
  25256. return null;
  25257. }
  25258. } );
  25259. Object.assign( PropertyBinding.prototype, { // prototype, continued
  25260. // these are used to "bind" a nonexistent property
  25261. _getValue_unavailable: function () {},
  25262. _setValue_unavailable: function () {},
  25263. BindingType: {
  25264. Direct: 0,
  25265. EntireArray: 1,
  25266. ArrayElement: 2,
  25267. HasFromToArray: 3
  25268. },
  25269. Versioning: {
  25270. None: 0,
  25271. NeedsUpdate: 1,
  25272. MatrixWorldNeedsUpdate: 2
  25273. },
  25274. GetterByBindingType: [
  25275. function getValue_direct( buffer, offset ) {
  25276. buffer[ offset ] = this.node[ this.propertyName ];
  25277. },
  25278. function getValue_array( buffer, offset ) {
  25279. var source = this.resolvedProperty;
  25280. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25281. buffer[ offset ++ ] = source[ i ];
  25282. }
  25283. },
  25284. function getValue_arrayElement( buffer, offset ) {
  25285. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25286. },
  25287. function getValue_toArray( buffer, offset ) {
  25288. this.resolvedProperty.toArray( buffer, offset );
  25289. }
  25290. ],
  25291. SetterByBindingTypeAndVersioning: [
  25292. [
  25293. // Direct
  25294. function setValue_direct( buffer, offset ) {
  25295. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25296. },
  25297. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25298. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25299. this.targetObject.needsUpdate = true;
  25300. },
  25301. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25302. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25303. this.targetObject.matrixWorldNeedsUpdate = true;
  25304. }
  25305. ], [
  25306. // EntireArray
  25307. function setValue_array( buffer, offset ) {
  25308. var dest = this.resolvedProperty;
  25309. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25310. dest[ i ] = buffer[ offset ++ ];
  25311. }
  25312. },
  25313. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25314. var dest = this.resolvedProperty;
  25315. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25316. dest[ i ] = buffer[ offset ++ ];
  25317. }
  25318. this.targetObject.needsUpdate = true;
  25319. },
  25320. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25321. var dest = this.resolvedProperty;
  25322. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25323. dest[ i ] = buffer[ offset ++ ];
  25324. }
  25325. this.targetObject.matrixWorldNeedsUpdate = true;
  25326. }
  25327. ], [
  25328. // ArrayElement
  25329. function setValue_arrayElement( buffer, offset ) {
  25330. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25331. },
  25332. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25333. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25334. this.targetObject.needsUpdate = true;
  25335. },
  25336. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25337. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25338. this.targetObject.matrixWorldNeedsUpdate = true;
  25339. }
  25340. ], [
  25341. // HasToFromArray
  25342. function setValue_fromArray( buffer, offset ) {
  25343. this.resolvedProperty.fromArray( buffer, offset );
  25344. },
  25345. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25346. this.resolvedProperty.fromArray( buffer, offset );
  25347. this.targetObject.needsUpdate = true;
  25348. },
  25349. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25350. this.resolvedProperty.fromArray( buffer, offset );
  25351. this.targetObject.matrixWorldNeedsUpdate = true;
  25352. }
  25353. ]
  25354. ],
  25355. getValue: function getValue_unbound( targetArray, offset ) {
  25356. this.bind();
  25357. this.getValue( targetArray, offset );
  25358. // Note: This class uses a State pattern on a per-method basis:
  25359. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25360. // prototype version of these methods with one that represents
  25361. // the bound state. When the property is not found, the methods
  25362. // become no-ops.
  25363. },
  25364. setValue: function getValue_unbound( sourceArray, offset ) {
  25365. this.bind();
  25366. this.setValue( sourceArray, offset );
  25367. },
  25368. // create getter / setter pair for a property in the scene graph
  25369. bind: function () {
  25370. var targetObject = this.node,
  25371. parsedPath = this.parsedPath,
  25372. objectName = parsedPath.objectName,
  25373. propertyName = parsedPath.propertyName,
  25374. propertyIndex = parsedPath.propertyIndex;
  25375. if ( ! targetObject ) {
  25376. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25377. this.node = targetObject;
  25378. }
  25379. // set fail state so we can just 'return' on error
  25380. this.getValue = this._getValue_unavailable;
  25381. this.setValue = this._setValue_unavailable;
  25382. // ensure there is a value node
  25383. if ( ! targetObject ) {
  25384. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25385. return;
  25386. }
  25387. if ( objectName ) {
  25388. var objectIndex = parsedPath.objectIndex;
  25389. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25390. switch ( objectName ) {
  25391. case 'materials':
  25392. if ( ! targetObject.material ) {
  25393. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25394. return;
  25395. }
  25396. if ( ! targetObject.material.materials ) {
  25397. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25398. return;
  25399. }
  25400. targetObject = targetObject.material.materials;
  25401. break;
  25402. case 'bones':
  25403. if ( ! targetObject.skeleton ) {
  25404. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25405. return;
  25406. }
  25407. // potential future optimization: skip this if propertyIndex is already an integer
  25408. // and convert the integer string to a true integer.
  25409. targetObject = targetObject.skeleton.bones;
  25410. // support resolving morphTarget names into indices.
  25411. for ( var i = 0; i < targetObject.length; i ++ ) {
  25412. if ( targetObject[ i ].name === objectIndex ) {
  25413. objectIndex = i;
  25414. break;
  25415. }
  25416. }
  25417. break;
  25418. default:
  25419. if ( targetObject[ objectName ] === undefined ) {
  25420. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25421. return;
  25422. }
  25423. targetObject = targetObject[ objectName ];
  25424. }
  25425. if ( objectIndex !== undefined ) {
  25426. if ( targetObject[ objectIndex ] === undefined ) {
  25427. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25428. return;
  25429. }
  25430. targetObject = targetObject[ objectIndex ];
  25431. }
  25432. }
  25433. // resolve property
  25434. var nodeProperty = targetObject[ propertyName ];
  25435. if ( nodeProperty === undefined ) {
  25436. var nodeName = parsedPath.nodeName;
  25437. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25438. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25439. return;
  25440. }
  25441. // determine versioning scheme
  25442. var versioning = this.Versioning.None;
  25443. this.targetObject = targetObject;
  25444. if ( targetObject.needsUpdate !== undefined ) { // material
  25445. versioning = this.Versioning.NeedsUpdate;
  25446. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25447. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25448. }
  25449. // determine how the property gets bound
  25450. var bindingType = this.BindingType.Direct;
  25451. if ( propertyIndex !== undefined ) {
  25452. // access a sub element of the property array (only primitives are supported right now)
  25453. if ( propertyName === "morphTargetInfluences" ) {
  25454. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25455. // support resolving morphTarget names into indices.
  25456. if ( ! targetObject.geometry ) {
  25457. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25458. return;
  25459. }
  25460. if ( targetObject.geometry.isBufferGeometry ) {
  25461. if ( ! targetObject.geometry.morphAttributes ) {
  25462. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25463. return;
  25464. }
  25465. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25466. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25467. propertyIndex = i;
  25468. break;
  25469. }
  25470. }
  25471. } else {
  25472. if ( ! targetObject.geometry.morphTargets ) {
  25473. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25474. return;
  25475. }
  25476. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25477. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25478. propertyIndex = i;
  25479. break;
  25480. }
  25481. }
  25482. }
  25483. }
  25484. bindingType = this.BindingType.ArrayElement;
  25485. this.resolvedProperty = nodeProperty;
  25486. this.propertyIndex = propertyIndex;
  25487. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25488. // must use copy for Object3D.Euler/Quaternion
  25489. bindingType = this.BindingType.HasFromToArray;
  25490. this.resolvedProperty = nodeProperty;
  25491. } else if ( Array.isArray( nodeProperty ) ) {
  25492. bindingType = this.BindingType.EntireArray;
  25493. this.resolvedProperty = nodeProperty;
  25494. } else {
  25495. this.propertyName = propertyName;
  25496. }
  25497. // select getter / setter
  25498. this.getValue = this.GetterByBindingType[ bindingType ];
  25499. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25500. },
  25501. unbind: function () {
  25502. this.node = null;
  25503. // back to the prototype version of getValue / setValue
  25504. // note: avoiding to mutate the shape of 'this' via 'delete'
  25505. this.getValue = this._getValue_unbound;
  25506. this.setValue = this._setValue_unbound;
  25507. }
  25508. } );
  25509. //!\ DECLARE ALIAS AFTER assign prototype !
  25510. Object.assign( PropertyBinding.prototype, {
  25511. // initial state of these methods that calls 'bind'
  25512. _getValue_unbound: PropertyBinding.prototype.getValue,
  25513. _setValue_unbound: PropertyBinding.prototype.setValue,
  25514. } );
  25515. /**
  25516. *
  25517. * A group of objects that receives a shared animation state.
  25518. *
  25519. * Usage:
  25520. *
  25521. * - Add objects you would otherwise pass as 'root' to the
  25522. * constructor or the .clipAction method of AnimationMixer.
  25523. *
  25524. * - Instead pass this object as 'root'.
  25525. *
  25526. * - You can also add and remove objects later when the mixer
  25527. * is running.
  25528. *
  25529. * Note:
  25530. *
  25531. * Objects of this class appear as one object to the mixer,
  25532. * so cache control of the individual objects must be done
  25533. * on the group.
  25534. *
  25535. * Limitation:
  25536. *
  25537. * - The animated properties must be compatible among the
  25538. * all objects in the group.
  25539. *
  25540. * - A single property can either be controlled through a
  25541. * target group or directly, but not both.
  25542. *
  25543. * @author tschw
  25544. */
  25545. function AnimationObjectGroup() {
  25546. this.uuid = _Math.generateUUID();
  25547. // cached objects followed by the active ones
  25548. this._objects = Array.prototype.slice.call( arguments );
  25549. this.nCachedObjects_ = 0; // threshold
  25550. // note: read by PropertyBinding.Composite
  25551. var indices = {};
  25552. this._indicesByUUID = indices; // for bookkeeping
  25553. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25554. indices[ arguments[ i ].uuid ] = i;
  25555. }
  25556. this._paths = []; // inside: string
  25557. this._parsedPaths = []; // inside: { we don't care, here }
  25558. this._bindings = []; // inside: Array< PropertyBinding >
  25559. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25560. var scope = this;
  25561. this.stats = {
  25562. objects: {
  25563. get total() {
  25564. return scope._objects.length;
  25565. },
  25566. get inUse() {
  25567. return this.total - scope.nCachedObjects_;
  25568. }
  25569. },
  25570. get bindingsPerObject() {
  25571. return scope._bindings.length;
  25572. }
  25573. };
  25574. }
  25575. Object.assign( AnimationObjectGroup.prototype, {
  25576. isAnimationObjectGroup: true,
  25577. add: function () {
  25578. var objects = this._objects,
  25579. nObjects = objects.length,
  25580. nCachedObjects = this.nCachedObjects_,
  25581. indicesByUUID = this._indicesByUUID,
  25582. paths = this._paths,
  25583. parsedPaths = this._parsedPaths,
  25584. bindings = this._bindings,
  25585. nBindings = bindings.length,
  25586. knownObject = undefined;
  25587. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25588. var object = arguments[ i ],
  25589. uuid = object.uuid,
  25590. index = indicesByUUID[ uuid ];
  25591. if ( index === undefined ) {
  25592. // unknown object -> add it to the ACTIVE region
  25593. index = nObjects ++;
  25594. indicesByUUID[ uuid ] = index;
  25595. objects.push( object );
  25596. // accounting is done, now do the same for all bindings
  25597. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25598. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25599. }
  25600. } else if ( index < nCachedObjects ) {
  25601. knownObject = objects[ index ];
  25602. // move existing object to the ACTIVE region
  25603. var firstActiveIndex = -- nCachedObjects,
  25604. lastCachedObject = objects[ firstActiveIndex ];
  25605. indicesByUUID[ lastCachedObject.uuid ] = index;
  25606. objects[ index ] = lastCachedObject;
  25607. indicesByUUID[ uuid ] = firstActiveIndex;
  25608. objects[ firstActiveIndex ] = object;
  25609. // accounting is done, now do the same for all bindings
  25610. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25611. var bindingsForPath = bindings[ j ],
  25612. lastCached = bindingsForPath[ firstActiveIndex ],
  25613. binding = bindingsForPath[ index ];
  25614. bindingsForPath[ index ] = lastCached;
  25615. if ( binding === undefined ) {
  25616. // since we do not bother to create new bindings
  25617. // for objects that are cached, the binding may
  25618. // or may not exist
  25619. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25620. }
  25621. bindingsForPath[ firstActiveIndex ] = binding;
  25622. }
  25623. } else if ( objects[ index ] !== knownObject ) {
  25624. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25625. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25626. } // else the object is already where we want it to be
  25627. } // for arguments
  25628. this.nCachedObjects_ = nCachedObjects;
  25629. },
  25630. remove: function () {
  25631. var objects = this._objects,
  25632. nCachedObjects = this.nCachedObjects_,
  25633. indicesByUUID = this._indicesByUUID,
  25634. bindings = this._bindings,
  25635. nBindings = bindings.length;
  25636. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25637. var object = arguments[ i ],
  25638. uuid = object.uuid,
  25639. index = indicesByUUID[ uuid ];
  25640. if ( index !== undefined && index >= nCachedObjects ) {
  25641. // move existing object into the CACHED region
  25642. var lastCachedIndex = nCachedObjects ++,
  25643. firstActiveObject = objects[ lastCachedIndex ];
  25644. indicesByUUID[ firstActiveObject.uuid ] = index;
  25645. objects[ index ] = firstActiveObject;
  25646. indicesByUUID[ uuid ] = lastCachedIndex;
  25647. objects[ lastCachedIndex ] = object;
  25648. // accounting is done, now do the same for all bindings
  25649. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25650. var bindingsForPath = bindings[ j ],
  25651. firstActive = bindingsForPath[ lastCachedIndex ],
  25652. binding = bindingsForPath[ index ];
  25653. bindingsForPath[ index ] = firstActive;
  25654. bindingsForPath[ lastCachedIndex ] = binding;
  25655. }
  25656. }
  25657. } // for arguments
  25658. this.nCachedObjects_ = nCachedObjects;
  25659. },
  25660. // remove & forget
  25661. uncache: function () {
  25662. var objects = this._objects,
  25663. nObjects = objects.length,
  25664. nCachedObjects = this.nCachedObjects_,
  25665. indicesByUUID = this._indicesByUUID,
  25666. bindings = this._bindings,
  25667. nBindings = bindings.length;
  25668. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25669. var object = arguments[ i ],
  25670. uuid = object.uuid,
  25671. index = indicesByUUID[ uuid ];
  25672. if ( index !== undefined ) {
  25673. delete indicesByUUID[ uuid ];
  25674. if ( index < nCachedObjects ) {
  25675. // object is cached, shrink the CACHED region
  25676. var firstActiveIndex = -- nCachedObjects,
  25677. lastCachedObject = objects[ firstActiveIndex ],
  25678. lastIndex = -- nObjects,
  25679. lastObject = objects[ lastIndex ];
  25680. // last cached object takes this object's place
  25681. indicesByUUID[ lastCachedObject.uuid ] = index;
  25682. objects[ index ] = lastCachedObject;
  25683. // last object goes to the activated slot and pop
  25684. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25685. objects[ firstActiveIndex ] = lastObject;
  25686. objects.pop();
  25687. // accounting is done, now do the same for all bindings
  25688. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25689. var bindingsForPath = bindings[ j ],
  25690. lastCached = bindingsForPath[ firstActiveIndex ],
  25691. last = bindingsForPath[ lastIndex ];
  25692. bindingsForPath[ index ] = lastCached;
  25693. bindingsForPath[ firstActiveIndex ] = last;
  25694. bindingsForPath.pop();
  25695. }
  25696. } else {
  25697. // object is active, just swap with the last and pop
  25698. var lastIndex = -- nObjects,
  25699. lastObject = objects[ lastIndex ];
  25700. indicesByUUID[ lastObject.uuid ] = index;
  25701. objects[ index ] = lastObject;
  25702. objects.pop();
  25703. // accounting is done, now do the same for all bindings
  25704. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25705. var bindingsForPath = bindings[ j ];
  25706. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25707. bindingsForPath.pop();
  25708. }
  25709. } // cached or active
  25710. } // if object is known
  25711. } // for arguments
  25712. this.nCachedObjects_ = nCachedObjects;
  25713. },
  25714. // Internal interface used by befriended PropertyBinding.Composite:
  25715. subscribe_: function ( path, parsedPath ) {
  25716. // returns an array of bindings for the given path that is changed
  25717. // according to the contained objects in the group
  25718. var indicesByPath = this._bindingsIndicesByPath,
  25719. index = indicesByPath[ path ],
  25720. bindings = this._bindings;
  25721. if ( index !== undefined ) return bindings[ index ];
  25722. var paths = this._paths,
  25723. parsedPaths = this._parsedPaths,
  25724. objects = this._objects,
  25725. nObjects = objects.length,
  25726. nCachedObjects = this.nCachedObjects_,
  25727. bindingsForPath = new Array( nObjects );
  25728. index = bindings.length;
  25729. indicesByPath[ path ] = index;
  25730. paths.push( path );
  25731. parsedPaths.push( parsedPath );
  25732. bindings.push( bindingsForPath );
  25733. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25734. var object = objects[ i ];
  25735. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25736. }
  25737. return bindingsForPath;
  25738. },
  25739. unsubscribe_: function ( path ) {
  25740. // tells the group to forget about a property path and no longer
  25741. // update the array previously obtained with 'subscribe_'
  25742. var indicesByPath = this._bindingsIndicesByPath,
  25743. index = indicesByPath[ path ];
  25744. if ( index !== undefined ) {
  25745. var paths = this._paths,
  25746. parsedPaths = this._parsedPaths,
  25747. bindings = this._bindings,
  25748. lastBindingsIndex = bindings.length - 1,
  25749. lastBindings = bindings[ lastBindingsIndex ],
  25750. lastBindingsPath = path[ lastBindingsIndex ];
  25751. indicesByPath[ lastBindingsPath ] = index;
  25752. bindings[ index ] = lastBindings;
  25753. bindings.pop();
  25754. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25755. parsedPaths.pop();
  25756. paths[ index ] = paths[ lastBindingsIndex ];
  25757. paths.pop();
  25758. }
  25759. }
  25760. } );
  25761. /**
  25762. *
  25763. * Action provided by AnimationMixer for scheduling clip playback on specific
  25764. * objects.
  25765. *
  25766. * @author Ben Houston / http://clara.io/
  25767. * @author David Sarno / http://lighthaus.us/
  25768. * @author tschw
  25769. *
  25770. */
  25771. function AnimationAction( mixer, clip, localRoot ) {
  25772. this._mixer = mixer;
  25773. this._clip = clip;
  25774. this._localRoot = localRoot || null;
  25775. var tracks = clip.tracks,
  25776. nTracks = tracks.length,
  25777. interpolants = new Array( nTracks );
  25778. var interpolantSettings = {
  25779. endingStart: ZeroCurvatureEnding,
  25780. endingEnd: ZeroCurvatureEnding
  25781. };
  25782. for ( var i = 0; i !== nTracks; ++ i ) {
  25783. var interpolant = tracks[ i ].createInterpolant( null );
  25784. interpolants[ i ] = interpolant;
  25785. interpolant.settings = interpolantSettings;
  25786. }
  25787. this._interpolantSettings = interpolantSettings;
  25788. this._interpolants = interpolants; // bound by the mixer
  25789. // inside: PropertyMixer (managed by the mixer)
  25790. this._propertyBindings = new Array( nTracks );
  25791. this._cacheIndex = null; // for the memory manager
  25792. this._byClipCacheIndex = null; // for the memory manager
  25793. this._timeScaleInterpolant = null;
  25794. this._weightInterpolant = null;
  25795. this.loop = LoopRepeat;
  25796. this._loopCount = - 1;
  25797. // global mixer time when the action is to be started
  25798. // it's set back to 'null' upon start of the action
  25799. this._startTime = null;
  25800. // scaled local time of the action
  25801. // gets clamped or wrapped to 0..clip.duration according to loop
  25802. this.time = 0;
  25803. this.timeScale = 1;
  25804. this._effectiveTimeScale = 1;
  25805. this.weight = 1;
  25806. this._effectiveWeight = 1;
  25807. this.repetitions = Infinity; // no. of repetitions when looping
  25808. this.paused = false; // true -> zero effective time scale
  25809. this.enabled = true; // false -> zero effective weight
  25810. this.clampWhenFinished = false;// keep feeding the last frame?
  25811. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25812. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25813. }
  25814. Object.assign( AnimationAction.prototype, {
  25815. // State & Scheduling
  25816. play: function () {
  25817. this._mixer._activateAction( this );
  25818. return this;
  25819. },
  25820. stop: function () {
  25821. this._mixer._deactivateAction( this );
  25822. return this.reset();
  25823. },
  25824. reset: function () {
  25825. this.paused = false;
  25826. this.enabled = true;
  25827. this.time = 0; // restart clip
  25828. this._loopCount = - 1;// forget previous loops
  25829. this._startTime = null;// forget scheduling
  25830. return this.stopFading().stopWarping();
  25831. },
  25832. isRunning: function () {
  25833. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25834. this._startTime === null && this._mixer._isActiveAction( this );
  25835. },
  25836. // return true when play has been called
  25837. isScheduled: function () {
  25838. return this._mixer._isActiveAction( this );
  25839. },
  25840. startAt: function ( time ) {
  25841. this._startTime = time;
  25842. return this;
  25843. },
  25844. setLoop: function ( mode, repetitions ) {
  25845. this.loop = mode;
  25846. this.repetitions = repetitions;
  25847. return this;
  25848. },
  25849. // Weight
  25850. // set the weight stopping any scheduled fading
  25851. // although .enabled = false yields an effective weight of zero, this
  25852. // method does *not* change .enabled, because it would be confusing
  25853. setEffectiveWeight: function ( weight ) {
  25854. this.weight = weight;
  25855. // note: same logic as when updated at runtime
  25856. this._effectiveWeight = this.enabled ? weight : 0;
  25857. return this.stopFading();
  25858. },
  25859. // return the weight considering fading and .enabled
  25860. getEffectiveWeight: function () {
  25861. return this._effectiveWeight;
  25862. },
  25863. fadeIn: function ( duration ) {
  25864. return this._scheduleFading( duration, 0, 1 );
  25865. },
  25866. fadeOut: function ( duration ) {
  25867. return this._scheduleFading( duration, 1, 0 );
  25868. },
  25869. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25870. fadeOutAction.fadeOut( duration );
  25871. this.fadeIn( duration );
  25872. if ( warp ) {
  25873. var fadeInDuration = this._clip.duration,
  25874. fadeOutDuration = fadeOutAction._clip.duration,
  25875. startEndRatio = fadeOutDuration / fadeInDuration,
  25876. endStartRatio = fadeInDuration / fadeOutDuration;
  25877. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25878. this.warp( endStartRatio, 1.0, duration );
  25879. }
  25880. return this;
  25881. },
  25882. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25883. return fadeInAction.crossFadeFrom( this, duration, warp );
  25884. },
  25885. stopFading: function () {
  25886. var weightInterpolant = this._weightInterpolant;
  25887. if ( weightInterpolant !== null ) {
  25888. this._weightInterpolant = null;
  25889. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25890. }
  25891. return this;
  25892. },
  25893. // Time Scale Control
  25894. // set the time scale stopping any scheduled warping
  25895. // although .paused = true yields an effective time scale of zero, this
  25896. // method does *not* change .paused, because it would be confusing
  25897. setEffectiveTimeScale: function ( timeScale ) {
  25898. this.timeScale = timeScale;
  25899. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25900. return this.stopWarping();
  25901. },
  25902. // return the time scale considering warping and .paused
  25903. getEffectiveTimeScale: function () {
  25904. return this._effectiveTimeScale;
  25905. },
  25906. setDuration: function ( duration ) {
  25907. this.timeScale = this._clip.duration / duration;
  25908. return this.stopWarping();
  25909. },
  25910. syncWith: function ( action ) {
  25911. this.time = action.time;
  25912. this.timeScale = action.timeScale;
  25913. return this.stopWarping();
  25914. },
  25915. halt: function ( duration ) {
  25916. return this.warp( this._effectiveTimeScale, 0, duration );
  25917. },
  25918. warp: function ( startTimeScale, endTimeScale, duration ) {
  25919. var mixer = this._mixer, now = mixer.time,
  25920. interpolant = this._timeScaleInterpolant,
  25921. timeScale = this.timeScale;
  25922. if ( interpolant === null ) {
  25923. interpolant = mixer._lendControlInterpolant();
  25924. this._timeScaleInterpolant = interpolant;
  25925. }
  25926. var times = interpolant.parameterPositions,
  25927. values = interpolant.sampleValues;
  25928. times[ 0 ] = now;
  25929. times[ 1 ] = now + duration;
  25930. values[ 0 ] = startTimeScale / timeScale;
  25931. values[ 1 ] = endTimeScale / timeScale;
  25932. return this;
  25933. },
  25934. stopWarping: function () {
  25935. var timeScaleInterpolant = this._timeScaleInterpolant;
  25936. if ( timeScaleInterpolant !== null ) {
  25937. this._timeScaleInterpolant = null;
  25938. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25939. }
  25940. return this;
  25941. },
  25942. // Object Accessors
  25943. getMixer: function () {
  25944. return this._mixer;
  25945. },
  25946. getClip: function () {
  25947. return this._clip;
  25948. },
  25949. getRoot: function () {
  25950. return this._localRoot || this._mixer._root;
  25951. },
  25952. // Interna
  25953. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25954. // called by the mixer
  25955. if ( ! this.enabled ) {
  25956. // call ._updateWeight() to update ._effectiveWeight
  25957. this._updateWeight( time );
  25958. return;
  25959. }
  25960. var startTime = this._startTime;
  25961. if ( startTime !== null ) {
  25962. // check for scheduled start of action
  25963. var timeRunning = ( time - startTime ) * timeDirection;
  25964. if ( timeRunning < 0 || timeDirection === 0 ) {
  25965. return; // yet to come / don't decide when delta = 0
  25966. }
  25967. // start
  25968. this._startTime = null; // unschedule
  25969. deltaTime = timeDirection * timeRunning;
  25970. }
  25971. // apply time scale and advance time
  25972. deltaTime *= this._updateTimeScale( time );
  25973. var clipTime = this._updateTime( deltaTime );
  25974. // note: _updateTime may disable the action resulting in
  25975. // an effective weight of 0
  25976. var weight = this._updateWeight( time );
  25977. if ( weight > 0 ) {
  25978. var interpolants = this._interpolants;
  25979. var propertyMixers = this._propertyBindings;
  25980. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25981. interpolants[ j ].evaluate( clipTime );
  25982. propertyMixers[ j ].accumulate( accuIndex, weight );
  25983. }
  25984. }
  25985. },
  25986. _updateWeight: function ( time ) {
  25987. var weight = 0;
  25988. if ( this.enabled ) {
  25989. weight = this.weight;
  25990. var interpolant = this._weightInterpolant;
  25991. if ( interpolant !== null ) {
  25992. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25993. weight *= interpolantValue;
  25994. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25995. this.stopFading();
  25996. if ( interpolantValue === 0 ) {
  25997. // faded out, disable
  25998. this.enabled = false;
  25999. }
  26000. }
  26001. }
  26002. }
  26003. this._effectiveWeight = weight;
  26004. return weight;
  26005. },
  26006. _updateTimeScale: function ( time ) {
  26007. var timeScale = 0;
  26008. if ( ! this.paused ) {
  26009. timeScale = this.timeScale;
  26010. var interpolant = this._timeScaleInterpolant;
  26011. if ( interpolant !== null ) {
  26012. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26013. timeScale *= interpolantValue;
  26014. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26015. this.stopWarping();
  26016. if ( timeScale === 0 ) {
  26017. // motion has halted, pause
  26018. this.paused = true;
  26019. } else {
  26020. // warp done - apply final time scale
  26021. this.timeScale = timeScale;
  26022. }
  26023. }
  26024. }
  26025. }
  26026. this._effectiveTimeScale = timeScale;
  26027. return timeScale;
  26028. },
  26029. _updateTime: function ( deltaTime ) {
  26030. var time = this.time + deltaTime;
  26031. var duration = this._clip.duration;
  26032. var loop = this.loop;
  26033. var loopCount = this._loopCount;
  26034. var pingPong = ( loop === LoopPingPong );
  26035. if ( deltaTime === 0 ) {
  26036. if ( loopCount === - 1 ) return time;
  26037. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26038. }
  26039. if ( loop === LoopOnce ) {
  26040. if ( loopCount === - 1 ) {
  26041. // just started
  26042. this._loopCount = 0;
  26043. this._setEndings( true, true, false );
  26044. }
  26045. handle_stop: {
  26046. if ( time >= duration ) {
  26047. time = duration;
  26048. } else if ( time < 0 ) {
  26049. time = 0;
  26050. } else {
  26051. this.time = time;
  26052. break handle_stop;
  26053. }
  26054. if ( this.clampWhenFinished ) this.paused = true;
  26055. else this.enabled = false;
  26056. this.time = time;
  26057. this._mixer.dispatchEvent( {
  26058. type: 'finished', action: this,
  26059. direction: deltaTime < 0 ? - 1 : 1
  26060. } );
  26061. }
  26062. } else { // repetitive Repeat or PingPong
  26063. if ( loopCount === - 1 ) {
  26064. // just started
  26065. if ( deltaTime >= 0 ) {
  26066. loopCount = 0;
  26067. this._setEndings( true, this.repetitions === 0, pingPong );
  26068. } else {
  26069. // when looping in reverse direction, the initial
  26070. // transition through zero counts as a repetition,
  26071. // so leave loopCount at -1
  26072. this._setEndings( this.repetitions === 0, true, pingPong );
  26073. }
  26074. }
  26075. if ( time >= duration || time < 0 ) {
  26076. // wrap around
  26077. var loopDelta = Math.floor( time / duration ); // signed
  26078. time -= duration * loopDelta;
  26079. loopCount += Math.abs( loopDelta );
  26080. var pending = this.repetitions - loopCount;
  26081. if ( pending <= 0 ) {
  26082. // have to stop (switch state, clamp time, fire event)
  26083. if ( this.clampWhenFinished ) this.paused = true;
  26084. else this.enabled = false;
  26085. time = deltaTime > 0 ? duration : 0;
  26086. this.time = time;
  26087. this._mixer.dispatchEvent( {
  26088. type: 'finished', action: this,
  26089. direction: deltaTime > 0 ? 1 : - 1
  26090. } );
  26091. } else {
  26092. // keep running
  26093. if ( pending === 1 ) {
  26094. // entering the last round
  26095. var atStart = deltaTime < 0;
  26096. this._setEndings( atStart, ! atStart, pingPong );
  26097. } else {
  26098. this._setEndings( false, false, pingPong );
  26099. }
  26100. this._loopCount = loopCount;
  26101. this.time = time;
  26102. this._mixer.dispatchEvent( {
  26103. type: 'loop', action: this, loopDelta: loopDelta
  26104. } );
  26105. }
  26106. } else {
  26107. this.time = time;
  26108. }
  26109. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  26110. // invert time for the "pong round"
  26111. return duration - time;
  26112. }
  26113. }
  26114. return time;
  26115. },
  26116. _setEndings: function ( atStart, atEnd, pingPong ) {
  26117. var settings = this._interpolantSettings;
  26118. if ( pingPong ) {
  26119. settings.endingStart = ZeroSlopeEnding;
  26120. settings.endingEnd = ZeroSlopeEnding;
  26121. } else {
  26122. // assuming for LoopOnce atStart == atEnd == true
  26123. if ( atStart ) {
  26124. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26125. } else {
  26126. settings.endingStart = WrapAroundEnding;
  26127. }
  26128. if ( atEnd ) {
  26129. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26130. } else {
  26131. settings.endingEnd = WrapAroundEnding;
  26132. }
  26133. }
  26134. },
  26135. _scheduleFading: function ( duration, weightNow, weightThen ) {
  26136. var mixer = this._mixer, now = mixer.time,
  26137. interpolant = this._weightInterpolant;
  26138. if ( interpolant === null ) {
  26139. interpolant = mixer._lendControlInterpolant();
  26140. this._weightInterpolant = interpolant;
  26141. }
  26142. var times = interpolant.parameterPositions,
  26143. values = interpolant.sampleValues;
  26144. times[ 0 ] = now;
  26145. values[ 0 ] = weightNow;
  26146. times[ 1 ] = now + duration;
  26147. values[ 1 ] = weightThen;
  26148. return this;
  26149. }
  26150. } );
  26151. /**
  26152. *
  26153. * Player for AnimationClips.
  26154. *
  26155. *
  26156. * @author Ben Houston / http://clara.io/
  26157. * @author David Sarno / http://lighthaus.us/
  26158. * @author tschw
  26159. */
  26160. function AnimationMixer( root ) {
  26161. this._root = root;
  26162. this._initMemoryManager();
  26163. this._accuIndex = 0;
  26164. this.time = 0;
  26165. this.timeScale = 1.0;
  26166. }
  26167. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  26168. constructor: AnimationMixer,
  26169. _bindAction: function ( action, prototypeAction ) {
  26170. var root = action._localRoot || this._root,
  26171. tracks = action._clip.tracks,
  26172. nTracks = tracks.length,
  26173. bindings = action._propertyBindings,
  26174. interpolants = action._interpolants,
  26175. rootUuid = root.uuid,
  26176. bindingsByRoot = this._bindingsByRootAndName,
  26177. bindingsByName = bindingsByRoot[ rootUuid ];
  26178. if ( bindingsByName === undefined ) {
  26179. bindingsByName = {};
  26180. bindingsByRoot[ rootUuid ] = bindingsByName;
  26181. }
  26182. for ( var i = 0; i !== nTracks; ++ i ) {
  26183. var track = tracks[ i ],
  26184. trackName = track.name,
  26185. binding = bindingsByName[ trackName ];
  26186. if ( binding !== undefined ) {
  26187. bindings[ i ] = binding;
  26188. } else {
  26189. binding = bindings[ i ];
  26190. if ( binding !== undefined ) {
  26191. // existing binding, make sure the cache knows
  26192. if ( binding._cacheIndex === null ) {
  26193. ++ binding.referenceCount;
  26194. this._addInactiveBinding( binding, rootUuid, trackName );
  26195. }
  26196. continue;
  26197. }
  26198. var path = prototypeAction && prototypeAction.
  26199. _propertyBindings[ i ].binding.parsedPath;
  26200. binding = new PropertyMixer(
  26201. PropertyBinding.create( root, trackName, path ),
  26202. track.ValueTypeName, track.getValueSize() );
  26203. ++ binding.referenceCount;
  26204. this._addInactiveBinding( binding, rootUuid, trackName );
  26205. bindings[ i ] = binding;
  26206. }
  26207. interpolants[ i ].resultBuffer = binding.buffer;
  26208. }
  26209. },
  26210. _activateAction: function ( action ) {
  26211. if ( ! this._isActiveAction( action ) ) {
  26212. if ( action._cacheIndex === null ) {
  26213. // this action has been forgotten by the cache, but the user
  26214. // appears to be still using it -> rebind
  26215. var rootUuid = ( action._localRoot || this._root ).uuid,
  26216. clipUuid = action._clip.uuid,
  26217. actionsForClip = this._actionsByClip[ clipUuid ];
  26218. this._bindAction( action,
  26219. actionsForClip && actionsForClip.knownActions[ 0 ] );
  26220. this._addInactiveAction( action, clipUuid, rootUuid );
  26221. }
  26222. var bindings = action._propertyBindings;
  26223. // increment reference counts / sort out state
  26224. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26225. var binding = bindings[ i ];
  26226. if ( binding.useCount ++ === 0 ) {
  26227. this._lendBinding( binding );
  26228. binding.saveOriginalState();
  26229. }
  26230. }
  26231. this._lendAction( action );
  26232. }
  26233. },
  26234. _deactivateAction: function ( action ) {
  26235. if ( this._isActiveAction( action ) ) {
  26236. var bindings = action._propertyBindings;
  26237. // decrement reference counts / sort out state
  26238. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26239. var binding = bindings[ i ];
  26240. if ( -- binding.useCount === 0 ) {
  26241. binding.restoreOriginalState();
  26242. this._takeBackBinding( binding );
  26243. }
  26244. }
  26245. this._takeBackAction( action );
  26246. }
  26247. },
  26248. // Memory manager
  26249. _initMemoryManager: function () {
  26250. this._actions = []; // 'nActiveActions' followed by inactive ones
  26251. this._nActiveActions = 0;
  26252. this._actionsByClip = {};
  26253. // inside:
  26254. // {
  26255. // knownActions: Array< AnimationAction > - used as prototypes
  26256. // actionByRoot: AnimationAction - lookup
  26257. // }
  26258. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26259. this._nActiveBindings = 0;
  26260. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26261. this._controlInterpolants = []; // same game as above
  26262. this._nActiveControlInterpolants = 0;
  26263. var scope = this;
  26264. this.stats = {
  26265. actions: {
  26266. get total() {
  26267. return scope._actions.length;
  26268. },
  26269. get inUse() {
  26270. return scope._nActiveActions;
  26271. }
  26272. },
  26273. bindings: {
  26274. get total() {
  26275. return scope._bindings.length;
  26276. },
  26277. get inUse() {
  26278. return scope._nActiveBindings;
  26279. }
  26280. },
  26281. controlInterpolants: {
  26282. get total() {
  26283. return scope._controlInterpolants.length;
  26284. },
  26285. get inUse() {
  26286. return scope._nActiveControlInterpolants;
  26287. }
  26288. }
  26289. };
  26290. },
  26291. // Memory management for AnimationAction objects
  26292. _isActiveAction: function ( action ) {
  26293. var index = action._cacheIndex;
  26294. return index !== null && index < this._nActiveActions;
  26295. },
  26296. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26297. var actions = this._actions,
  26298. actionsByClip = this._actionsByClip,
  26299. actionsForClip = actionsByClip[ clipUuid ];
  26300. if ( actionsForClip === undefined ) {
  26301. actionsForClip = {
  26302. knownActions: [ action ],
  26303. actionByRoot: {}
  26304. };
  26305. action._byClipCacheIndex = 0;
  26306. actionsByClip[ clipUuid ] = actionsForClip;
  26307. } else {
  26308. var knownActions = actionsForClip.knownActions;
  26309. action._byClipCacheIndex = knownActions.length;
  26310. knownActions.push( action );
  26311. }
  26312. action._cacheIndex = actions.length;
  26313. actions.push( action );
  26314. actionsForClip.actionByRoot[ rootUuid ] = action;
  26315. },
  26316. _removeInactiveAction: function ( action ) {
  26317. var actions = this._actions,
  26318. lastInactiveAction = actions[ actions.length - 1 ],
  26319. cacheIndex = action._cacheIndex;
  26320. lastInactiveAction._cacheIndex = cacheIndex;
  26321. actions[ cacheIndex ] = lastInactiveAction;
  26322. actions.pop();
  26323. action._cacheIndex = null;
  26324. var clipUuid = action._clip.uuid,
  26325. actionsByClip = this._actionsByClip,
  26326. actionsForClip = actionsByClip[ clipUuid ],
  26327. knownActionsForClip = actionsForClip.knownActions,
  26328. lastKnownAction =
  26329. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26330. byClipCacheIndex = action._byClipCacheIndex;
  26331. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26332. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26333. knownActionsForClip.pop();
  26334. action._byClipCacheIndex = null;
  26335. var actionByRoot = actionsForClip.actionByRoot,
  26336. rootUuid = ( action._localRoot || this._root ).uuid;
  26337. delete actionByRoot[ rootUuid ];
  26338. if ( knownActionsForClip.length === 0 ) {
  26339. delete actionsByClip[ clipUuid ];
  26340. }
  26341. this._removeInactiveBindingsForAction( action );
  26342. },
  26343. _removeInactiveBindingsForAction: function ( action ) {
  26344. var bindings = action._propertyBindings;
  26345. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26346. var binding = bindings[ i ];
  26347. if ( -- binding.referenceCount === 0 ) {
  26348. this._removeInactiveBinding( binding );
  26349. }
  26350. }
  26351. },
  26352. _lendAction: function ( action ) {
  26353. // [ active actions | inactive actions ]
  26354. // [ active actions >| inactive actions ]
  26355. // s a
  26356. // <-swap->
  26357. // a s
  26358. var actions = this._actions,
  26359. prevIndex = action._cacheIndex,
  26360. lastActiveIndex = this._nActiveActions ++,
  26361. firstInactiveAction = actions[ lastActiveIndex ];
  26362. action._cacheIndex = lastActiveIndex;
  26363. actions[ lastActiveIndex ] = action;
  26364. firstInactiveAction._cacheIndex = prevIndex;
  26365. actions[ prevIndex ] = firstInactiveAction;
  26366. },
  26367. _takeBackAction: function ( action ) {
  26368. // [ active actions | inactive actions ]
  26369. // [ active actions |< inactive actions ]
  26370. // a s
  26371. // <-swap->
  26372. // s a
  26373. var actions = this._actions,
  26374. prevIndex = action._cacheIndex,
  26375. firstInactiveIndex = -- this._nActiveActions,
  26376. lastActiveAction = actions[ firstInactiveIndex ];
  26377. action._cacheIndex = firstInactiveIndex;
  26378. actions[ firstInactiveIndex ] = action;
  26379. lastActiveAction._cacheIndex = prevIndex;
  26380. actions[ prevIndex ] = lastActiveAction;
  26381. },
  26382. // Memory management for PropertyMixer objects
  26383. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26384. var bindingsByRoot = this._bindingsByRootAndName,
  26385. bindingByName = bindingsByRoot[ rootUuid ],
  26386. bindings = this._bindings;
  26387. if ( bindingByName === undefined ) {
  26388. bindingByName = {};
  26389. bindingsByRoot[ rootUuid ] = bindingByName;
  26390. }
  26391. bindingByName[ trackName ] = binding;
  26392. binding._cacheIndex = bindings.length;
  26393. bindings.push( binding );
  26394. },
  26395. _removeInactiveBinding: function ( binding ) {
  26396. var bindings = this._bindings,
  26397. propBinding = binding.binding,
  26398. rootUuid = propBinding.rootNode.uuid,
  26399. trackName = propBinding.path,
  26400. bindingsByRoot = this._bindingsByRootAndName,
  26401. bindingByName = bindingsByRoot[ rootUuid ],
  26402. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26403. cacheIndex = binding._cacheIndex;
  26404. lastInactiveBinding._cacheIndex = cacheIndex;
  26405. bindings[ cacheIndex ] = lastInactiveBinding;
  26406. bindings.pop();
  26407. delete bindingByName[ trackName ];
  26408. if ( Object.keys( bindingByName ).length === 0 ) {
  26409. delete bindingsByRoot[ rootUuid ];
  26410. }
  26411. },
  26412. _lendBinding: function ( binding ) {
  26413. var bindings = this._bindings,
  26414. prevIndex = binding._cacheIndex,
  26415. lastActiveIndex = this._nActiveBindings ++,
  26416. firstInactiveBinding = bindings[ lastActiveIndex ];
  26417. binding._cacheIndex = lastActiveIndex;
  26418. bindings[ lastActiveIndex ] = binding;
  26419. firstInactiveBinding._cacheIndex = prevIndex;
  26420. bindings[ prevIndex ] = firstInactiveBinding;
  26421. },
  26422. _takeBackBinding: function ( binding ) {
  26423. var bindings = this._bindings,
  26424. prevIndex = binding._cacheIndex,
  26425. firstInactiveIndex = -- this._nActiveBindings,
  26426. lastActiveBinding = bindings[ firstInactiveIndex ];
  26427. binding._cacheIndex = firstInactiveIndex;
  26428. bindings[ firstInactiveIndex ] = binding;
  26429. lastActiveBinding._cacheIndex = prevIndex;
  26430. bindings[ prevIndex ] = lastActiveBinding;
  26431. },
  26432. // Memory management of Interpolants for weight and time scale
  26433. _lendControlInterpolant: function () {
  26434. var interpolants = this._controlInterpolants,
  26435. lastActiveIndex = this._nActiveControlInterpolants ++,
  26436. interpolant = interpolants[ lastActiveIndex ];
  26437. if ( interpolant === undefined ) {
  26438. interpolant = new LinearInterpolant(
  26439. new Float32Array( 2 ), new Float32Array( 2 ),
  26440. 1, this._controlInterpolantsResultBuffer );
  26441. interpolant.__cacheIndex = lastActiveIndex;
  26442. interpolants[ lastActiveIndex ] = interpolant;
  26443. }
  26444. return interpolant;
  26445. },
  26446. _takeBackControlInterpolant: function ( interpolant ) {
  26447. var interpolants = this._controlInterpolants,
  26448. prevIndex = interpolant.__cacheIndex,
  26449. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26450. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26451. interpolant.__cacheIndex = firstInactiveIndex;
  26452. interpolants[ firstInactiveIndex ] = interpolant;
  26453. lastActiveInterpolant.__cacheIndex = prevIndex;
  26454. interpolants[ prevIndex ] = lastActiveInterpolant;
  26455. },
  26456. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26457. // return an action for a clip optionally using a custom root target
  26458. // object (this method allocates a lot of dynamic memory in case a
  26459. // previously unknown clip/root combination is specified)
  26460. clipAction: function ( clip, optionalRoot ) {
  26461. var root = optionalRoot || this._root,
  26462. rootUuid = root.uuid,
  26463. clipObject = typeof clip === 'string' ?
  26464. AnimationClip.findByName( root, clip ) : clip,
  26465. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26466. actionsForClip = this._actionsByClip[ clipUuid ],
  26467. prototypeAction = null;
  26468. if ( actionsForClip !== undefined ) {
  26469. var existingAction =
  26470. actionsForClip.actionByRoot[ rootUuid ];
  26471. if ( existingAction !== undefined ) {
  26472. return existingAction;
  26473. }
  26474. // we know the clip, so we don't have to parse all
  26475. // the bindings again but can just copy
  26476. prototypeAction = actionsForClip.knownActions[ 0 ];
  26477. // also, take the clip from the prototype action
  26478. if ( clipObject === null )
  26479. clipObject = prototypeAction._clip;
  26480. }
  26481. // clip must be known when specified via string
  26482. if ( clipObject === null ) return null;
  26483. // allocate all resources required to run it
  26484. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26485. this._bindAction( newAction, prototypeAction );
  26486. // and make the action known to the memory manager
  26487. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26488. return newAction;
  26489. },
  26490. // get an existing action
  26491. existingAction: function ( clip, optionalRoot ) {
  26492. var root = optionalRoot || this._root,
  26493. rootUuid = root.uuid,
  26494. clipObject = typeof clip === 'string' ?
  26495. AnimationClip.findByName( root, clip ) : clip,
  26496. clipUuid = clipObject ? clipObject.uuid : clip,
  26497. actionsForClip = this._actionsByClip[ clipUuid ];
  26498. if ( actionsForClip !== undefined ) {
  26499. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26500. }
  26501. return null;
  26502. },
  26503. // deactivates all previously scheduled actions
  26504. stopAllAction: function () {
  26505. var actions = this._actions,
  26506. nActions = this._nActiveActions,
  26507. bindings = this._bindings,
  26508. nBindings = this._nActiveBindings;
  26509. this._nActiveActions = 0;
  26510. this._nActiveBindings = 0;
  26511. for ( var i = 0; i !== nActions; ++ i ) {
  26512. actions[ i ].reset();
  26513. }
  26514. for ( var i = 0; i !== nBindings; ++ i ) {
  26515. bindings[ i ].useCount = 0;
  26516. }
  26517. return this;
  26518. },
  26519. // advance the time and update apply the animation
  26520. update: function ( deltaTime ) {
  26521. deltaTime *= this.timeScale;
  26522. var actions = this._actions,
  26523. nActions = this._nActiveActions,
  26524. time = this.time += deltaTime,
  26525. timeDirection = Math.sign( deltaTime ),
  26526. accuIndex = this._accuIndex ^= 1;
  26527. // run active actions
  26528. for ( var i = 0; i !== nActions; ++ i ) {
  26529. var action = actions[ i ];
  26530. action._update( time, deltaTime, timeDirection, accuIndex );
  26531. }
  26532. // update scene graph
  26533. var bindings = this._bindings,
  26534. nBindings = this._nActiveBindings;
  26535. for ( var i = 0; i !== nBindings; ++ i ) {
  26536. bindings[ i ].apply( accuIndex );
  26537. }
  26538. return this;
  26539. },
  26540. // return this mixer's root target object
  26541. getRoot: function () {
  26542. return this._root;
  26543. },
  26544. // free all resources specific to a particular clip
  26545. uncacheClip: function ( clip ) {
  26546. var actions = this._actions,
  26547. clipUuid = clip.uuid,
  26548. actionsByClip = this._actionsByClip,
  26549. actionsForClip = actionsByClip[ clipUuid ];
  26550. if ( actionsForClip !== undefined ) {
  26551. // note: just calling _removeInactiveAction would mess up the
  26552. // iteration state and also require updating the state we can
  26553. // just throw away
  26554. var actionsToRemove = actionsForClip.knownActions;
  26555. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26556. var action = actionsToRemove[ i ];
  26557. this._deactivateAction( action );
  26558. var cacheIndex = action._cacheIndex,
  26559. lastInactiveAction = actions[ actions.length - 1 ];
  26560. action._cacheIndex = null;
  26561. action._byClipCacheIndex = null;
  26562. lastInactiveAction._cacheIndex = cacheIndex;
  26563. actions[ cacheIndex ] = lastInactiveAction;
  26564. actions.pop();
  26565. this._removeInactiveBindingsForAction( action );
  26566. }
  26567. delete actionsByClip[ clipUuid ];
  26568. }
  26569. },
  26570. // free all resources specific to a particular root target object
  26571. uncacheRoot: function ( root ) {
  26572. var rootUuid = root.uuid,
  26573. actionsByClip = this._actionsByClip;
  26574. for ( var clipUuid in actionsByClip ) {
  26575. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26576. action = actionByRoot[ rootUuid ];
  26577. if ( action !== undefined ) {
  26578. this._deactivateAction( action );
  26579. this._removeInactiveAction( action );
  26580. }
  26581. }
  26582. var bindingsByRoot = this._bindingsByRootAndName,
  26583. bindingByName = bindingsByRoot[ rootUuid ];
  26584. if ( bindingByName !== undefined ) {
  26585. for ( var trackName in bindingByName ) {
  26586. var binding = bindingByName[ trackName ];
  26587. binding.restoreOriginalState();
  26588. this._removeInactiveBinding( binding );
  26589. }
  26590. }
  26591. },
  26592. // remove a targeted clip from the cache
  26593. uncacheAction: function ( clip, optionalRoot ) {
  26594. var action = this.existingAction( clip, optionalRoot );
  26595. if ( action !== null ) {
  26596. this._deactivateAction( action );
  26597. this._removeInactiveAction( action );
  26598. }
  26599. }
  26600. } );
  26601. /**
  26602. * @author mrdoob / http://mrdoob.com/
  26603. */
  26604. function Uniform( value ) {
  26605. if ( typeof value === 'string' ) {
  26606. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26607. value = arguments[ 1 ];
  26608. }
  26609. this.value = value;
  26610. }
  26611. Uniform.prototype.clone = function () {
  26612. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26613. };
  26614. /**
  26615. * @author benaadams / https://twitter.com/ben_a_adams
  26616. */
  26617. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26618. InterleavedBuffer.call( this, array, stride );
  26619. this.meshPerAttribute = meshPerAttribute || 1;
  26620. }
  26621. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26622. constructor: InstancedInterleavedBuffer,
  26623. isInstancedInterleavedBuffer: true,
  26624. copy: function ( source ) {
  26625. InterleavedBuffer.prototype.copy.call( this, source );
  26626. this.meshPerAttribute = source.meshPerAttribute;
  26627. return this;
  26628. }
  26629. } );
  26630. /**
  26631. * @author mrdoob / http://mrdoob.com/
  26632. * @author bhouston / http://clara.io/
  26633. * @author stephomi / http://stephaneginier.com/
  26634. */
  26635. function Raycaster( origin, direction, near, far ) {
  26636. this.ray = new Ray( origin, direction );
  26637. // direction is assumed to be normalized (for accurate distance calculations)
  26638. this.near = near || 0;
  26639. this.far = far || Infinity;
  26640. this.params = {
  26641. Mesh: {},
  26642. Line: {},
  26643. LOD: {},
  26644. Points: { threshold: 1 },
  26645. Sprite: {}
  26646. };
  26647. Object.defineProperties( this.params, {
  26648. PointCloud: {
  26649. get: function () {
  26650. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26651. return this.Points;
  26652. }
  26653. }
  26654. } );
  26655. }
  26656. function ascSort( a, b ) {
  26657. return a.distance - b.distance;
  26658. }
  26659. function intersectObject( object, raycaster, intersects, recursive ) {
  26660. if ( object.visible === false ) return;
  26661. object.raycast( raycaster, intersects );
  26662. if ( recursive === true ) {
  26663. var children = object.children;
  26664. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26665. intersectObject( children[ i ], raycaster, intersects, true );
  26666. }
  26667. }
  26668. }
  26669. Object.assign( Raycaster.prototype, {
  26670. linePrecision: 1,
  26671. set: function ( origin, direction ) {
  26672. // direction is assumed to be normalized (for accurate distance calculations)
  26673. this.ray.set( origin, direction );
  26674. },
  26675. setFromCamera: function ( coords, camera ) {
  26676. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26677. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26678. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26679. this._camera = camera;
  26680. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26681. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26682. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26683. this._camera = camera;
  26684. } else {
  26685. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26686. }
  26687. },
  26688. intersectObject: function ( object, recursive, optionalTarget ) {
  26689. var intersects = optionalTarget || [];
  26690. intersectObject( object, this, intersects, recursive );
  26691. intersects.sort( ascSort );
  26692. return intersects;
  26693. },
  26694. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26695. var intersects = optionalTarget || [];
  26696. if ( Array.isArray( objects ) === false ) {
  26697. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26698. return intersects;
  26699. }
  26700. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26701. intersectObject( objects[ i ], this, intersects, recursive );
  26702. }
  26703. intersects.sort( ascSort );
  26704. return intersects;
  26705. }
  26706. } );
  26707. /**
  26708. * @author bhouston / http://clara.io
  26709. * @author WestLangley / http://github.com/WestLangley
  26710. *
  26711. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26712. *
  26713. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26714. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26715. */
  26716. function Spherical( radius, phi, theta ) {
  26717. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26718. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26719. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26720. return this;
  26721. }
  26722. Object.assign( Spherical.prototype, {
  26723. set: function ( radius, phi, theta ) {
  26724. this.radius = radius;
  26725. this.phi = phi;
  26726. this.theta = theta;
  26727. return this;
  26728. },
  26729. clone: function () {
  26730. return new this.constructor().copy( this );
  26731. },
  26732. copy: function ( other ) {
  26733. this.radius = other.radius;
  26734. this.phi = other.phi;
  26735. this.theta = other.theta;
  26736. return this;
  26737. },
  26738. // restrict phi to be betwee EPS and PI-EPS
  26739. makeSafe: function () {
  26740. var EPS = 0.000001;
  26741. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26742. return this;
  26743. },
  26744. setFromVector3: function ( v ) {
  26745. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26746. },
  26747. setFromCartesianCoords: function ( x, y, z ) {
  26748. this.radius = Math.sqrt( x * x + y * y + z * z );
  26749. if ( this.radius === 0 ) {
  26750. this.theta = 0;
  26751. this.phi = 0;
  26752. } else {
  26753. this.theta = Math.atan2( x, z );
  26754. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26755. }
  26756. return this;
  26757. }
  26758. } );
  26759. /**
  26760. * @author Mugen87 / https://github.com/Mugen87
  26761. *
  26762. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26763. *
  26764. */
  26765. function Cylindrical( radius, theta, y ) {
  26766. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26767. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26768. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26769. return this;
  26770. }
  26771. Object.assign( Cylindrical.prototype, {
  26772. set: function ( radius, theta, y ) {
  26773. this.radius = radius;
  26774. this.theta = theta;
  26775. this.y = y;
  26776. return this;
  26777. },
  26778. clone: function () {
  26779. return new this.constructor().copy( this );
  26780. },
  26781. copy: function ( other ) {
  26782. this.radius = other.radius;
  26783. this.theta = other.theta;
  26784. this.y = other.y;
  26785. return this;
  26786. },
  26787. setFromVector3: function ( v ) {
  26788. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26789. },
  26790. setFromCartesianCoords: function ( x, y, z ) {
  26791. this.radius = Math.sqrt( x * x + z * z );
  26792. this.theta = Math.atan2( x, z );
  26793. this.y = y;
  26794. return this;
  26795. }
  26796. } );
  26797. /**
  26798. * @author bhouston / http://clara.io
  26799. */
  26800. function Box2( min, max ) {
  26801. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26802. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26803. }
  26804. Object.assign( Box2.prototype, {
  26805. set: function ( min, max ) {
  26806. this.min.copy( min );
  26807. this.max.copy( max );
  26808. return this;
  26809. },
  26810. setFromPoints: function ( points ) {
  26811. this.makeEmpty();
  26812. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26813. this.expandByPoint( points[ i ] );
  26814. }
  26815. return this;
  26816. },
  26817. setFromCenterAndSize: function () {
  26818. var v1 = new Vector2();
  26819. return function setFromCenterAndSize( center, size ) {
  26820. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26821. this.min.copy( center ).sub( halfSize );
  26822. this.max.copy( center ).add( halfSize );
  26823. return this;
  26824. };
  26825. }(),
  26826. clone: function () {
  26827. return new this.constructor().copy( this );
  26828. },
  26829. copy: function ( box ) {
  26830. this.min.copy( box.min );
  26831. this.max.copy( box.max );
  26832. return this;
  26833. },
  26834. makeEmpty: function () {
  26835. this.min.x = this.min.y = + Infinity;
  26836. this.max.x = this.max.y = - Infinity;
  26837. return this;
  26838. },
  26839. isEmpty: function () {
  26840. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26841. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26842. },
  26843. getCenter: function ( target ) {
  26844. if ( target === undefined ) {
  26845. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26846. target = new Vector2();
  26847. }
  26848. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26849. },
  26850. getSize: function ( target ) {
  26851. if ( target === undefined ) {
  26852. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26853. target = new Vector2();
  26854. }
  26855. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26856. },
  26857. expandByPoint: function ( point ) {
  26858. this.min.min( point );
  26859. this.max.max( point );
  26860. return this;
  26861. },
  26862. expandByVector: function ( vector ) {
  26863. this.min.sub( vector );
  26864. this.max.add( vector );
  26865. return this;
  26866. },
  26867. expandByScalar: function ( scalar ) {
  26868. this.min.addScalar( - scalar );
  26869. this.max.addScalar( scalar );
  26870. return this;
  26871. },
  26872. containsPoint: function ( point ) {
  26873. return point.x < this.min.x || point.x > this.max.x ||
  26874. point.y < this.min.y || point.y > this.max.y ? false : true;
  26875. },
  26876. containsBox: function ( box ) {
  26877. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26878. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26879. },
  26880. getParameter: function ( point, target ) {
  26881. // This can potentially have a divide by zero if the box
  26882. // has a size dimension of 0.
  26883. if ( target === undefined ) {
  26884. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26885. target = new Vector2();
  26886. }
  26887. return target.set(
  26888. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26889. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26890. );
  26891. },
  26892. intersectsBox: function ( box ) {
  26893. // using 4 splitting planes to rule out intersections
  26894. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26895. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26896. },
  26897. clampPoint: function ( point, target ) {
  26898. if ( target === undefined ) {
  26899. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26900. target = new Vector2();
  26901. }
  26902. return target.copy( point ).clamp( this.min, this.max );
  26903. },
  26904. distanceToPoint: function () {
  26905. var v1 = new Vector2();
  26906. return function distanceToPoint( point ) {
  26907. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26908. return clampedPoint.sub( point ).length();
  26909. };
  26910. }(),
  26911. intersect: function ( box ) {
  26912. this.min.max( box.min );
  26913. this.max.min( box.max );
  26914. return this;
  26915. },
  26916. union: function ( box ) {
  26917. this.min.min( box.min );
  26918. this.max.max( box.max );
  26919. return this;
  26920. },
  26921. translate: function ( offset ) {
  26922. this.min.add( offset );
  26923. this.max.add( offset );
  26924. return this;
  26925. },
  26926. equals: function ( box ) {
  26927. return box.min.equals( this.min ) && box.max.equals( this.max );
  26928. }
  26929. } );
  26930. /**
  26931. * @author bhouston / http://clara.io
  26932. */
  26933. var _startP, _startEnd;
  26934. function Line3( start, end ) {
  26935. this.start = ( start !== undefined ) ? start : new Vector3();
  26936. this.end = ( end !== undefined ) ? end : new Vector3();
  26937. }
  26938. Object.assign( Line3.prototype, {
  26939. set: function ( start, end ) {
  26940. this.start.copy( start );
  26941. this.end.copy( end );
  26942. return this;
  26943. },
  26944. clone: function () {
  26945. return new this.constructor().copy( this );
  26946. },
  26947. copy: function ( line ) {
  26948. this.start.copy( line.start );
  26949. this.end.copy( line.end );
  26950. return this;
  26951. },
  26952. getCenter: function ( target ) {
  26953. if ( target === undefined ) {
  26954. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26955. target = new Vector3();
  26956. }
  26957. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26958. },
  26959. delta: function ( target ) {
  26960. if ( target === undefined ) {
  26961. console.warn( 'THREE.Line3: .delta() target is now required' );
  26962. target = new Vector3();
  26963. }
  26964. return target.subVectors( this.end, this.start );
  26965. },
  26966. distanceSq: function () {
  26967. return this.start.distanceToSquared( this.end );
  26968. },
  26969. distance: function () {
  26970. return this.start.distanceTo( this.end );
  26971. },
  26972. at: function ( t, target ) {
  26973. if ( target === undefined ) {
  26974. console.warn( 'THREE.Line3: .at() target is now required' );
  26975. target = new Vector3();
  26976. }
  26977. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26978. },
  26979. closestPointToPointParameter: function ( point, clampToLine ) {
  26980. if ( _startP === undefined ) {
  26981. _startP = new Vector3();
  26982. _startEnd = new Vector3();
  26983. }
  26984. _startP.subVectors( point, this.start );
  26985. _startEnd.subVectors( this.end, this.start );
  26986. var startEnd2 = _startEnd.dot( _startEnd );
  26987. var startEnd_startP = _startEnd.dot( _startP );
  26988. var t = startEnd_startP / startEnd2;
  26989. if ( clampToLine ) {
  26990. t = _Math.clamp( t, 0, 1 );
  26991. }
  26992. return t;
  26993. },
  26994. closestPointToPoint: function ( point, clampToLine, target ) {
  26995. var t = this.closestPointToPointParameter( point, clampToLine );
  26996. if ( target === undefined ) {
  26997. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26998. target = new Vector3();
  26999. }
  27000. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27001. },
  27002. applyMatrix4: function ( matrix ) {
  27003. this.start.applyMatrix4( matrix );
  27004. this.end.applyMatrix4( matrix );
  27005. return this;
  27006. },
  27007. equals: function ( line ) {
  27008. return line.start.equals( this.start ) && line.end.equals( this.end );
  27009. }
  27010. } );
  27011. /**
  27012. * @author alteredq / http://alteredqualia.com/
  27013. */
  27014. function ImmediateRenderObject( material ) {
  27015. Object3D.call( this );
  27016. this.material = material;
  27017. this.render = function ( /* renderCallback */ ) {};
  27018. }
  27019. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27020. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27021. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27022. /**
  27023. * @author mrdoob / http://mrdoob.com/
  27024. * @author WestLangley / http://github.com/WestLangley
  27025. */
  27026. function VertexNormalsHelper( object, size, hex, linewidth ) {
  27027. this.object = object;
  27028. this.size = ( size !== undefined ) ? size : 1;
  27029. var color = ( hex !== undefined ) ? hex : 0xff0000;
  27030. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27031. //
  27032. var nNormals = 0;
  27033. var objGeometry = this.object.geometry;
  27034. if ( objGeometry && objGeometry.isGeometry ) {
  27035. nNormals = objGeometry.faces.length * 3;
  27036. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27037. nNormals = objGeometry.attributes.normal.count;
  27038. }
  27039. //
  27040. var geometry = new BufferGeometry();
  27041. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27042. geometry.addAttribute( 'position', positions );
  27043. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27044. //
  27045. this.matrixAutoUpdate = false;
  27046. this.update();
  27047. }
  27048. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27049. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  27050. VertexNormalsHelper.prototype.update = ( function () {
  27051. var v1 = new Vector3();
  27052. var v2 = new Vector3();
  27053. var normalMatrix = new Matrix3();
  27054. return function update() {
  27055. var keys = [ 'a', 'b', 'c' ];
  27056. this.object.updateMatrixWorld( true );
  27057. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27058. var matrixWorld = this.object.matrixWorld;
  27059. var position = this.geometry.attributes.position;
  27060. //
  27061. var objGeometry = this.object.geometry;
  27062. if ( objGeometry && objGeometry.isGeometry ) {
  27063. var vertices = objGeometry.vertices;
  27064. var faces = objGeometry.faces;
  27065. var idx = 0;
  27066. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27067. var face = faces[ i ];
  27068. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  27069. var vertex = vertices[ face[ keys[ j ] ] ];
  27070. var normal = face.vertexNormals[ j ];
  27071. v1.copy( vertex ).applyMatrix4( matrixWorld );
  27072. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27073. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27074. idx = idx + 1;
  27075. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27076. idx = idx + 1;
  27077. }
  27078. }
  27079. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27080. var objPos = objGeometry.attributes.position;
  27081. var objNorm = objGeometry.attributes.normal;
  27082. var idx = 0;
  27083. // for simplicity, ignore index and drawcalls, and render every normal
  27084. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  27085. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  27086. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  27087. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27088. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27089. idx = idx + 1;
  27090. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27091. idx = idx + 1;
  27092. }
  27093. }
  27094. position.needsUpdate = true;
  27095. };
  27096. }() );
  27097. /**
  27098. * @author alteredq / http://alteredqualia.com/
  27099. * @author mrdoob / http://mrdoob.com/
  27100. * @author WestLangley / http://github.com/WestLangley
  27101. */
  27102. function SpotLightHelper( light, color ) {
  27103. Object3D.call( this );
  27104. this.light = light;
  27105. this.light.updateMatrixWorld();
  27106. this.matrix = light.matrixWorld;
  27107. this.matrixAutoUpdate = false;
  27108. this.color = color;
  27109. var geometry = new BufferGeometry();
  27110. var positions = [
  27111. 0, 0, 0, 0, 0, 1,
  27112. 0, 0, 0, 1, 0, 1,
  27113. 0, 0, 0, - 1, 0, 1,
  27114. 0, 0, 0, 0, 1, 1,
  27115. 0, 0, 0, 0, - 1, 1
  27116. ];
  27117. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27118. var p1 = ( i / l ) * Math.PI * 2;
  27119. var p2 = ( j / l ) * Math.PI * 2;
  27120. positions.push(
  27121. Math.cos( p1 ), Math.sin( p1 ), 1,
  27122. Math.cos( p2 ), Math.sin( p2 ), 1
  27123. );
  27124. }
  27125. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27126. var material = new LineBasicMaterial( { fog: false } );
  27127. this.cone = new LineSegments( geometry, material );
  27128. this.add( this.cone );
  27129. this.update();
  27130. }
  27131. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  27132. SpotLightHelper.prototype.constructor = SpotLightHelper;
  27133. SpotLightHelper.prototype.dispose = function () {
  27134. this.cone.geometry.dispose();
  27135. this.cone.material.dispose();
  27136. };
  27137. SpotLightHelper.prototype.update = function () {
  27138. var vector = new Vector3();
  27139. return function update() {
  27140. this.light.updateMatrixWorld();
  27141. var coneLength = this.light.distance ? this.light.distance : 1000;
  27142. var coneWidth = coneLength * Math.tan( this.light.angle );
  27143. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  27144. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  27145. this.cone.lookAt( vector );
  27146. if ( this.color !== undefined ) {
  27147. this.cone.material.color.set( this.color );
  27148. } else {
  27149. this.cone.material.color.copy( this.light.color );
  27150. }
  27151. };
  27152. }();
  27153. /**
  27154. * @author Sean Griffin / http://twitter.com/sgrif
  27155. * @author Michael Guerrero / http://realitymeltdown.com
  27156. * @author mrdoob / http://mrdoob.com/
  27157. * @author ikerr / http://verold.com
  27158. * @author Mugen87 / https://github.com/Mugen87
  27159. */
  27160. function getBoneList( object ) {
  27161. var boneList = [];
  27162. if ( object && object.isBone ) {
  27163. boneList.push( object );
  27164. }
  27165. for ( var i = 0; i < object.children.length; i ++ ) {
  27166. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  27167. }
  27168. return boneList;
  27169. }
  27170. function SkeletonHelper( object ) {
  27171. var bones = getBoneList( object );
  27172. var geometry = new BufferGeometry();
  27173. var vertices = [];
  27174. var colors = [];
  27175. var color1 = new Color( 0, 0, 1 );
  27176. var color2 = new Color( 0, 1, 0 );
  27177. for ( var i = 0; i < bones.length; i ++ ) {
  27178. var bone = bones[ i ];
  27179. if ( bone.parent && bone.parent.isBone ) {
  27180. vertices.push( 0, 0, 0 );
  27181. vertices.push( 0, 0, 0 );
  27182. colors.push( color1.r, color1.g, color1.b );
  27183. colors.push( color2.r, color2.g, color2.b );
  27184. }
  27185. }
  27186. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27187. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27188. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  27189. LineSegments.call( this, geometry, material );
  27190. this.root = object;
  27191. this.bones = bones;
  27192. this.matrix = object.matrixWorld;
  27193. this.matrixAutoUpdate = false;
  27194. }
  27195. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  27196. SkeletonHelper.prototype.constructor = SkeletonHelper;
  27197. SkeletonHelper.prototype.updateMatrixWorld = function () {
  27198. var vector = new Vector3();
  27199. var boneMatrix = new Matrix4();
  27200. var matrixWorldInv = new Matrix4();
  27201. return function updateMatrixWorld( force ) {
  27202. var bones = this.bones;
  27203. var geometry = this.geometry;
  27204. var position = geometry.getAttribute( 'position' );
  27205. matrixWorldInv.getInverse( this.root.matrixWorld );
  27206. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  27207. var bone = bones[ i ];
  27208. if ( bone.parent && bone.parent.isBone ) {
  27209. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  27210. vector.setFromMatrixPosition( boneMatrix );
  27211. position.setXYZ( j, vector.x, vector.y, vector.z );
  27212. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  27213. vector.setFromMatrixPosition( boneMatrix );
  27214. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  27215. j += 2;
  27216. }
  27217. }
  27218. geometry.getAttribute( 'position' ).needsUpdate = true;
  27219. Object3D.prototype.updateMatrixWorld.call( this, force );
  27220. };
  27221. }();
  27222. /**
  27223. * @author alteredq / http://alteredqualia.com/
  27224. * @author mrdoob / http://mrdoob.com/
  27225. */
  27226. function PointLightHelper( light, sphereSize, color ) {
  27227. this.light = light;
  27228. this.light.updateMatrixWorld();
  27229. this.color = color;
  27230. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  27231. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27232. Mesh.call( this, geometry, material );
  27233. this.matrix = this.light.matrixWorld;
  27234. this.matrixAutoUpdate = false;
  27235. this.update();
  27236. /*
  27237. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27238. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27239. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27240. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27241. var d = light.distance;
  27242. if ( d === 0.0 ) {
  27243. this.lightDistance.visible = false;
  27244. } else {
  27245. this.lightDistance.scale.set( d, d, d );
  27246. }
  27247. this.add( this.lightDistance );
  27248. */
  27249. }
  27250. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27251. PointLightHelper.prototype.constructor = PointLightHelper;
  27252. PointLightHelper.prototype.dispose = function () {
  27253. this.geometry.dispose();
  27254. this.material.dispose();
  27255. };
  27256. PointLightHelper.prototype.update = function () {
  27257. if ( this.color !== undefined ) {
  27258. this.material.color.set( this.color );
  27259. } else {
  27260. this.material.color.copy( this.light.color );
  27261. }
  27262. /*
  27263. var d = this.light.distance;
  27264. if ( d === 0.0 ) {
  27265. this.lightDistance.visible = false;
  27266. } else {
  27267. this.lightDistance.visible = true;
  27268. this.lightDistance.scale.set( d, d, d );
  27269. }
  27270. */
  27271. };
  27272. /**
  27273. * @author abelnation / http://github.com/abelnation
  27274. * @author Mugen87 / http://github.com/Mugen87
  27275. * @author WestLangley / http://github.com/WestLangley
  27276. *
  27277. * This helper must be added as a child of the light
  27278. */
  27279. function RectAreaLightHelper( light, color ) {
  27280. this.type = 'RectAreaLightHelper';
  27281. this.light = light;
  27282. this.color = color; // optional hardwired color for the helper
  27283. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27284. var geometry = new BufferGeometry();
  27285. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27286. geometry.computeBoundingSphere();
  27287. var material = new LineBasicMaterial( { fog: false } );
  27288. Line.call( this, geometry, material );
  27289. //
  27290. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27291. var geometry2 = new BufferGeometry();
  27292. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27293. geometry2.computeBoundingSphere();
  27294. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27295. this.update();
  27296. }
  27297. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27298. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27299. RectAreaLightHelper.prototype.update = function () {
  27300. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27301. if ( this.color !== undefined ) {
  27302. this.material.color.set( this.color );
  27303. this.children[ 0 ].material.color.set( this.color );
  27304. } else {
  27305. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27306. // prevent hue shift
  27307. var c = this.material.color;
  27308. var max = Math.max( c.r, c.g, c.b );
  27309. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27310. this.children[ 0 ].material.color.copy( this.material.color );
  27311. }
  27312. };
  27313. RectAreaLightHelper.prototype.dispose = function () {
  27314. this.geometry.dispose();
  27315. this.material.dispose();
  27316. this.children[ 0 ].geometry.dispose();
  27317. this.children[ 0 ].material.dispose();
  27318. };
  27319. /**
  27320. * @author alteredq / http://alteredqualia.com/
  27321. * @author mrdoob / http://mrdoob.com/
  27322. * @author Mugen87 / https://github.com/Mugen87
  27323. */
  27324. function HemisphereLightHelper( light, size, color ) {
  27325. Object3D.call( this );
  27326. this.light = light;
  27327. this.light.updateMatrixWorld();
  27328. this.matrix = light.matrixWorld;
  27329. this.matrixAutoUpdate = false;
  27330. this.color = color;
  27331. var geometry = new OctahedronBufferGeometry( size );
  27332. geometry.rotateY( Math.PI * 0.5 );
  27333. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27334. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27335. var position = geometry.getAttribute( 'position' );
  27336. var colors = new Float32Array( position.count * 3 );
  27337. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27338. this.add( new Mesh( geometry, this.material ) );
  27339. this.update();
  27340. }
  27341. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27342. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27343. HemisphereLightHelper.prototype.dispose = function () {
  27344. this.children[ 0 ].geometry.dispose();
  27345. this.children[ 0 ].material.dispose();
  27346. };
  27347. HemisphereLightHelper.prototype.update = function () {
  27348. var vector = new Vector3();
  27349. var color1 = new Color();
  27350. var color2 = new Color();
  27351. return function update() {
  27352. var mesh = this.children[ 0 ];
  27353. if ( this.color !== undefined ) {
  27354. this.material.color.set( this.color );
  27355. } else {
  27356. var colors = mesh.geometry.getAttribute( 'color' );
  27357. color1.copy( this.light.color );
  27358. color2.copy( this.light.groundColor );
  27359. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27360. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  27361. colors.setXYZ( i, color.r, color.g, color.b );
  27362. }
  27363. colors.needsUpdate = true;
  27364. }
  27365. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27366. };
  27367. }();
  27368. /**
  27369. * @author WestLangley / http://github.com/WestLangley
  27370. */
  27371. function LightProbeHelper( lightProbe, size ) {
  27372. this.lightProbe = lightProbe;
  27373. this.size = size;
  27374. var defines = {};
  27375. defines[ 'GAMMA_OUTPUT' ] = "";
  27376. // material
  27377. var material = new ShaderMaterial( {
  27378. defines: defines,
  27379. uniforms: {
  27380. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  27381. intensity: { value: this.lightProbe.intensity }
  27382. },
  27383. vertexShader: [
  27384. 'varying vec3 vNormal;',
  27385. 'void main() {',
  27386. ' vNormal = normalize( normalMatrix * normal );',
  27387. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  27388. '}',
  27389. ].join( '\n' ),
  27390. fragmentShader: [
  27391. '#define RECIPROCAL_PI 0.318309886',
  27392. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  27393. ' // matrix is assumed to be orthogonal',
  27394. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  27395. '}',
  27396. 'vec3 linearToOutput( in vec3 a ) {',
  27397. ' #ifdef GAMMA_OUTPUT',
  27398. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  27399. ' #else',
  27400. ' return a;',
  27401. ' #endif',
  27402. '}',
  27403. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  27404. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  27405. ' // normal is assumed to have unit length',
  27406. ' float x = normal.x, y = normal.y, z = normal.z;',
  27407. ' // band 0',
  27408. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  27409. ' // band 1',
  27410. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  27411. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  27412. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  27413. ' // band 2',
  27414. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  27415. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  27416. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  27417. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  27418. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  27419. ' return result;',
  27420. '}',
  27421. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  27422. 'uniform float intensity; // light probe intensity',
  27423. 'varying vec3 vNormal;',
  27424. 'void main() {',
  27425. ' vec3 normal = normalize( vNormal );',
  27426. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  27427. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  27428. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  27429. ' outgoingLight = linearToOutput( outgoingLight );',
  27430. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  27431. '}'
  27432. ].join( '\n' )
  27433. } );
  27434. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  27435. Mesh.call( this, geometry, material );
  27436. this.onBeforeRender();
  27437. }
  27438. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  27439. LightProbeHelper.prototype.constructor = LightProbeHelper;
  27440. LightProbeHelper.prototype.dispose = function () {
  27441. this.geometry.dispose();
  27442. this.material.dispose();
  27443. };
  27444. LightProbeHelper.prototype.onBeforeRender = function () {
  27445. return function update() {
  27446. this.position.copy( this.lightProbe.position );
  27447. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  27448. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  27449. };
  27450. }();
  27451. /**
  27452. * @author mrdoob / http://mrdoob.com/
  27453. */
  27454. function GridHelper( size, divisions, color1, color2 ) {
  27455. size = size || 10;
  27456. divisions = divisions || 10;
  27457. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27458. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27459. var center = divisions / 2;
  27460. var step = size / divisions;
  27461. var halfSize = size / 2;
  27462. var vertices = [], colors = [];
  27463. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27464. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27465. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27466. var color = i === center ? color1 : color2;
  27467. color.toArray( colors, j ); j += 3;
  27468. color.toArray( colors, j ); j += 3;
  27469. color.toArray( colors, j ); j += 3;
  27470. color.toArray( colors, j ); j += 3;
  27471. }
  27472. var geometry = new BufferGeometry();
  27473. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27474. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27475. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27476. LineSegments.call( this, geometry, material );
  27477. }
  27478. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27479. constructor: GridHelper,
  27480. copy: function ( source ) {
  27481. LineSegments.prototype.copy.call( this, source );
  27482. this.geometry.copy( source.geometry );
  27483. this.material.copy( source.material );
  27484. return this;
  27485. },
  27486. clone: function () {
  27487. return new this.constructor().copy( this );
  27488. }
  27489. } );
  27490. /**
  27491. * @author mrdoob / http://mrdoob.com/
  27492. * @author Mugen87 / http://github.com/Mugen87
  27493. * @author Hectate / http://www.github.com/Hectate
  27494. */
  27495. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27496. radius = radius || 10;
  27497. radials = radials || 16;
  27498. circles = circles || 8;
  27499. divisions = divisions || 64;
  27500. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27501. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27502. var vertices = [];
  27503. var colors = [];
  27504. var x, z;
  27505. var v, i, j, r, color;
  27506. // create the radials
  27507. for ( i = 0; i <= radials; i ++ ) {
  27508. v = ( i / radials ) * ( Math.PI * 2 );
  27509. x = Math.sin( v ) * radius;
  27510. z = Math.cos( v ) * radius;
  27511. vertices.push( 0, 0, 0 );
  27512. vertices.push( x, 0, z );
  27513. color = ( i & 1 ) ? color1 : color2;
  27514. colors.push( color.r, color.g, color.b );
  27515. colors.push( color.r, color.g, color.b );
  27516. }
  27517. // create the circles
  27518. for ( i = 0; i <= circles; i ++ ) {
  27519. color = ( i & 1 ) ? color1 : color2;
  27520. r = radius - ( radius / circles * i );
  27521. for ( j = 0; j < divisions; j ++ ) {
  27522. // first vertex
  27523. v = ( j / divisions ) * ( Math.PI * 2 );
  27524. x = Math.sin( v ) * r;
  27525. z = Math.cos( v ) * r;
  27526. vertices.push( x, 0, z );
  27527. colors.push( color.r, color.g, color.b );
  27528. // second vertex
  27529. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27530. x = Math.sin( v ) * r;
  27531. z = Math.cos( v ) * r;
  27532. vertices.push( x, 0, z );
  27533. colors.push( color.r, color.g, color.b );
  27534. }
  27535. }
  27536. var geometry = new BufferGeometry();
  27537. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27538. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27539. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27540. LineSegments.call( this, geometry, material );
  27541. }
  27542. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27543. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27544. /**
  27545. * @author Mugen87 / http://github.com/Mugen87
  27546. */
  27547. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27548. this.audio = audio;
  27549. this.range = range || 1;
  27550. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27551. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27552. var geometry = new BufferGeometry();
  27553. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27554. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27555. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27556. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27557. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27558. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27559. this.update();
  27560. }
  27561. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27562. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27563. PositionalAudioHelper.prototype.update = function () {
  27564. var audio = this.audio;
  27565. var range = this.range;
  27566. var divisionsInnerAngle = this.divisionsInnerAngle;
  27567. var divisionsOuterAngle = this.divisionsOuterAngle;
  27568. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27569. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27570. var halfConeInnerAngle = coneInnerAngle / 2;
  27571. var halfConeOuterAngle = coneOuterAngle / 2;
  27572. var start = 0;
  27573. var count = 0;
  27574. var i, stride;
  27575. var geometry = this.geometry;
  27576. var positionAttribute = geometry.attributes.position;
  27577. geometry.clearGroups();
  27578. //
  27579. function generateSegment( from, to, divisions, materialIndex ) {
  27580. var step = ( to - from ) / divisions;
  27581. positionAttribute.setXYZ( start, 0, 0, 0 );
  27582. count ++;
  27583. for ( i = from; i < to; i += step ) {
  27584. stride = start + count;
  27585. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27586. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27587. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27588. count += 3;
  27589. }
  27590. geometry.addGroup( start, count, materialIndex );
  27591. start += count;
  27592. count = 0;
  27593. }
  27594. //
  27595. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27596. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27597. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27598. //
  27599. positionAttribute.needsUpdate = true;
  27600. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27601. };
  27602. PositionalAudioHelper.prototype.dispose = function () {
  27603. this.geometry.dispose();
  27604. this.material[ 0 ].dispose();
  27605. this.material[ 1 ].dispose();
  27606. };
  27607. /**
  27608. * @author mrdoob / http://mrdoob.com/
  27609. * @author WestLangley / http://github.com/WestLangley
  27610. */
  27611. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27612. // FaceNormalsHelper only supports THREE.Geometry
  27613. this.object = object;
  27614. this.size = ( size !== undefined ) ? size : 1;
  27615. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27616. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27617. //
  27618. var nNormals = 0;
  27619. var objGeometry = this.object.geometry;
  27620. if ( objGeometry && objGeometry.isGeometry ) {
  27621. nNormals = objGeometry.faces.length;
  27622. } else {
  27623. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27624. }
  27625. //
  27626. var geometry = new BufferGeometry();
  27627. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27628. geometry.addAttribute( 'position', positions );
  27629. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27630. //
  27631. this.matrixAutoUpdate = false;
  27632. this.update();
  27633. }
  27634. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27635. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27636. FaceNormalsHelper.prototype.update = ( function () {
  27637. var v1 = new Vector3();
  27638. var v2 = new Vector3();
  27639. var normalMatrix = new Matrix3();
  27640. return function update() {
  27641. this.object.updateMatrixWorld( true );
  27642. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27643. var matrixWorld = this.object.matrixWorld;
  27644. var position = this.geometry.attributes.position;
  27645. //
  27646. var objGeometry = this.object.geometry;
  27647. var vertices = objGeometry.vertices;
  27648. var faces = objGeometry.faces;
  27649. var idx = 0;
  27650. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27651. var face = faces[ i ];
  27652. var normal = face.normal;
  27653. v1.copy( vertices[ face.a ] )
  27654. .add( vertices[ face.b ] )
  27655. .add( vertices[ face.c ] )
  27656. .divideScalar( 3 )
  27657. .applyMatrix4( matrixWorld );
  27658. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27659. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27660. idx = idx + 1;
  27661. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27662. idx = idx + 1;
  27663. }
  27664. position.needsUpdate = true;
  27665. };
  27666. }() );
  27667. /**
  27668. * @author alteredq / http://alteredqualia.com/
  27669. * @author mrdoob / http://mrdoob.com/
  27670. * @author WestLangley / http://github.com/WestLangley
  27671. */
  27672. function DirectionalLightHelper( light, size, color ) {
  27673. Object3D.call( this );
  27674. this.light = light;
  27675. this.light.updateMatrixWorld();
  27676. this.matrix = light.matrixWorld;
  27677. this.matrixAutoUpdate = false;
  27678. this.color = color;
  27679. if ( size === undefined ) size = 1;
  27680. var geometry = new BufferGeometry();
  27681. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27682. - size, size, 0,
  27683. size, size, 0,
  27684. size, - size, 0,
  27685. - size, - size, 0,
  27686. - size, size, 0
  27687. ], 3 ) );
  27688. var material = new LineBasicMaterial( { fog: false } );
  27689. this.lightPlane = new Line( geometry, material );
  27690. this.add( this.lightPlane );
  27691. geometry = new BufferGeometry();
  27692. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27693. this.targetLine = new Line( geometry, material );
  27694. this.add( this.targetLine );
  27695. this.update();
  27696. }
  27697. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27698. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27699. DirectionalLightHelper.prototype.dispose = function () {
  27700. this.lightPlane.geometry.dispose();
  27701. this.lightPlane.material.dispose();
  27702. this.targetLine.geometry.dispose();
  27703. this.targetLine.material.dispose();
  27704. };
  27705. DirectionalLightHelper.prototype.update = function () {
  27706. var v1 = new Vector3();
  27707. var v2 = new Vector3();
  27708. var v3 = new Vector3();
  27709. return function update() {
  27710. v1.setFromMatrixPosition( this.light.matrixWorld );
  27711. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27712. v3.subVectors( v2, v1 );
  27713. this.lightPlane.lookAt( v2 );
  27714. if ( this.color !== undefined ) {
  27715. this.lightPlane.material.color.set( this.color );
  27716. this.targetLine.material.color.set( this.color );
  27717. } else {
  27718. this.lightPlane.material.color.copy( this.light.color );
  27719. this.targetLine.material.color.copy( this.light.color );
  27720. }
  27721. this.targetLine.lookAt( v2 );
  27722. this.targetLine.scale.z = v3.length();
  27723. };
  27724. }();
  27725. /**
  27726. * @author alteredq / http://alteredqualia.com/
  27727. * @author Mugen87 / https://github.com/Mugen87
  27728. *
  27729. * - shows frustum, line of sight and up of the camera
  27730. * - suitable for fast updates
  27731. * - based on frustum visualization in lightgl.js shadowmap example
  27732. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27733. */
  27734. function CameraHelper( camera ) {
  27735. var geometry = new BufferGeometry();
  27736. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27737. var vertices = [];
  27738. var colors = [];
  27739. var pointMap = {};
  27740. // colors
  27741. var colorFrustum = new Color( 0xffaa00 );
  27742. var colorCone = new Color( 0xff0000 );
  27743. var colorUp = new Color( 0x00aaff );
  27744. var colorTarget = new Color( 0xffffff );
  27745. var colorCross = new Color( 0x333333 );
  27746. // near
  27747. addLine( 'n1', 'n2', colorFrustum );
  27748. addLine( 'n2', 'n4', colorFrustum );
  27749. addLine( 'n4', 'n3', colorFrustum );
  27750. addLine( 'n3', 'n1', colorFrustum );
  27751. // far
  27752. addLine( 'f1', 'f2', colorFrustum );
  27753. addLine( 'f2', 'f4', colorFrustum );
  27754. addLine( 'f4', 'f3', colorFrustum );
  27755. addLine( 'f3', 'f1', colorFrustum );
  27756. // sides
  27757. addLine( 'n1', 'f1', colorFrustum );
  27758. addLine( 'n2', 'f2', colorFrustum );
  27759. addLine( 'n3', 'f3', colorFrustum );
  27760. addLine( 'n4', 'f4', colorFrustum );
  27761. // cone
  27762. addLine( 'p', 'n1', colorCone );
  27763. addLine( 'p', 'n2', colorCone );
  27764. addLine( 'p', 'n3', colorCone );
  27765. addLine( 'p', 'n4', colorCone );
  27766. // up
  27767. addLine( 'u1', 'u2', colorUp );
  27768. addLine( 'u2', 'u3', colorUp );
  27769. addLine( 'u3', 'u1', colorUp );
  27770. // target
  27771. addLine( 'c', 't', colorTarget );
  27772. addLine( 'p', 'c', colorCross );
  27773. // cross
  27774. addLine( 'cn1', 'cn2', colorCross );
  27775. addLine( 'cn3', 'cn4', colorCross );
  27776. addLine( 'cf1', 'cf2', colorCross );
  27777. addLine( 'cf3', 'cf4', colorCross );
  27778. function addLine( a, b, color ) {
  27779. addPoint( a, color );
  27780. addPoint( b, color );
  27781. }
  27782. function addPoint( id, color ) {
  27783. vertices.push( 0, 0, 0 );
  27784. colors.push( color.r, color.g, color.b );
  27785. if ( pointMap[ id ] === undefined ) {
  27786. pointMap[ id ] = [];
  27787. }
  27788. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27789. }
  27790. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27791. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27792. LineSegments.call( this, geometry, material );
  27793. this.camera = camera;
  27794. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27795. this.matrix = camera.matrixWorld;
  27796. this.matrixAutoUpdate = false;
  27797. this.pointMap = pointMap;
  27798. this.update();
  27799. }
  27800. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27801. CameraHelper.prototype.constructor = CameraHelper;
  27802. CameraHelper.prototype.update = function () {
  27803. var geometry, pointMap;
  27804. var vector = new Vector3();
  27805. var camera = new Camera();
  27806. function setPoint( point, x, y, z ) {
  27807. vector.set( x, y, z ).unproject( camera );
  27808. var points = pointMap[ point ];
  27809. if ( points !== undefined ) {
  27810. var position = geometry.getAttribute( 'position' );
  27811. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27812. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27813. }
  27814. }
  27815. }
  27816. return function update() {
  27817. geometry = this.geometry;
  27818. pointMap = this.pointMap;
  27819. var w = 1, h = 1;
  27820. // we need just camera projection matrix inverse
  27821. // world matrix must be identity
  27822. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27823. // center / target
  27824. setPoint( 'c', 0, 0, - 1 );
  27825. setPoint( 't', 0, 0, 1 );
  27826. // near
  27827. setPoint( 'n1', - w, - h, - 1 );
  27828. setPoint( 'n2', w, - h, - 1 );
  27829. setPoint( 'n3', - w, h, - 1 );
  27830. setPoint( 'n4', w, h, - 1 );
  27831. // far
  27832. setPoint( 'f1', - w, - h, 1 );
  27833. setPoint( 'f2', w, - h, 1 );
  27834. setPoint( 'f3', - w, h, 1 );
  27835. setPoint( 'f4', w, h, 1 );
  27836. // up
  27837. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27838. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27839. setPoint( 'u3', 0, h * 2, - 1 );
  27840. // cross
  27841. setPoint( 'cf1', - w, 0, 1 );
  27842. setPoint( 'cf2', w, 0, 1 );
  27843. setPoint( 'cf3', 0, - h, 1 );
  27844. setPoint( 'cf4', 0, h, 1 );
  27845. setPoint( 'cn1', - w, 0, - 1 );
  27846. setPoint( 'cn2', w, 0, - 1 );
  27847. setPoint( 'cn3', 0, - h, - 1 );
  27848. setPoint( 'cn4', 0, h, - 1 );
  27849. geometry.getAttribute( 'position' ).needsUpdate = true;
  27850. };
  27851. }();
  27852. /**
  27853. * @author mrdoob / http://mrdoob.com/
  27854. * @author Mugen87 / http://github.com/Mugen87
  27855. */
  27856. function BoxHelper( object, color ) {
  27857. this.object = object;
  27858. if ( color === undefined ) color = 0xffff00;
  27859. 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 ] );
  27860. var positions = new Float32Array( 8 * 3 );
  27861. var geometry = new BufferGeometry();
  27862. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27863. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27864. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27865. this.matrixAutoUpdate = false;
  27866. this.update();
  27867. }
  27868. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27869. BoxHelper.prototype.constructor = BoxHelper;
  27870. BoxHelper.prototype.update = ( function () {
  27871. var box = new Box3();
  27872. return function update( object ) {
  27873. if ( object !== undefined ) {
  27874. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27875. }
  27876. if ( this.object !== undefined ) {
  27877. box.setFromObject( this.object );
  27878. }
  27879. if ( box.isEmpty() ) return;
  27880. var min = box.min;
  27881. var max = box.max;
  27882. /*
  27883. 5____4
  27884. 1/___0/|
  27885. | 6__|_7
  27886. 2/___3/
  27887. 0: max.x, max.y, max.z
  27888. 1: min.x, max.y, max.z
  27889. 2: min.x, min.y, max.z
  27890. 3: max.x, min.y, max.z
  27891. 4: max.x, max.y, min.z
  27892. 5: min.x, max.y, min.z
  27893. 6: min.x, min.y, min.z
  27894. 7: max.x, min.y, min.z
  27895. */
  27896. var position = this.geometry.attributes.position;
  27897. var array = position.array;
  27898. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27899. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27900. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27901. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27902. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27903. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27904. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27905. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27906. position.needsUpdate = true;
  27907. this.geometry.computeBoundingSphere();
  27908. };
  27909. } )();
  27910. BoxHelper.prototype.setFromObject = function ( object ) {
  27911. this.object = object;
  27912. this.update();
  27913. return this;
  27914. };
  27915. BoxHelper.prototype.copy = function ( source ) {
  27916. LineSegments.prototype.copy.call( this, source );
  27917. this.object = source.object;
  27918. return this;
  27919. };
  27920. BoxHelper.prototype.clone = function () {
  27921. return new this.constructor().copy( this );
  27922. };
  27923. /**
  27924. * @author WestLangley / http://github.com/WestLangley
  27925. */
  27926. function Box3Helper( box, color ) {
  27927. this.type = 'Box3Helper';
  27928. this.box = box;
  27929. color = color || 0xffff00;
  27930. 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 ] );
  27931. 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 ];
  27932. var geometry = new BufferGeometry();
  27933. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27934. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27935. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27936. this.geometry.computeBoundingSphere();
  27937. }
  27938. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27939. Box3Helper.prototype.constructor = Box3Helper;
  27940. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27941. var box = this.box;
  27942. if ( box.isEmpty() ) return;
  27943. box.getCenter( this.position );
  27944. box.getSize( this.scale );
  27945. this.scale.multiplyScalar( 0.5 );
  27946. Object3D.prototype.updateMatrixWorld.call( this, force );
  27947. };
  27948. /**
  27949. * @author WestLangley / http://github.com/WestLangley
  27950. */
  27951. function PlaneHelper( plane, size, hex ) {
  27952. this.type = 'PlaneHelper';
  27953. this.plane = plane;
  27954. this.size = ( size === undefined ) ? 1 : size;
  27955. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27956. var positions = [ 1, - 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 ];
  27957. var geometry = new BufferGeometry();
  27958. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27959. geometry.computeBoundingSphere();
  27960. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27961. //
  27962. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27963. var geometry2 = new BufferGeometry();
  27964. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27965. geometry2.computeBoundingSphere();
  27966. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27967. }
  27968. PlaneHelper.prototype = Object.create( Line.prototype );
  27969. PlaneHelper.prototype.constructor = PlaneHelper;
  27970. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27971. var scale = - this.plane.constant;
  27972. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27973. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27974. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27975. this.lookAt( this.plane.normal );
  27976. Object3D.prototype.updateMatrixWorld.call( this, force );
  27977. };
  27978. /**
  27979. * @author WestLangley / http://github.com/WestLangley
  27980. * @author zz85 / http://github.com/zz85
  27981. * @author bhouston / http://clara.io
  27982. *
  27983. * Creates an arrow for visualizing directions
  27984. *
  27985. * Parameters:
  27986. * dir - Vector3
  27987. * origin - Vector3
  27988. * length - Number
  27989. * color - color in hex value
  27990. * headLength - Number
  27991. * headWidth - Number
  27992. */
  27993. var lineGeometry, coneGeometry;
  27994. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27995. // dir is assumed to be normalized
  27996. Object3D.call( this );
  27997. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  27998. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  27999. if ( length === undefined ) length = 1;
  28000. if ( color === undefined ) color = 0xffff00;
  28001. if ( headLength === undefined ) headLength = 0.2 * length;
  28002. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28003. if ( lineGeometry === undefined ) {
  28004. lineGeometry = new BufferGeometry();
  28005. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28006. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28007. coneGeometry.translate( 0, - 0.5, 0 );
  28008. }
  28009. this.position.copy( origin );
  28010. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  28011. this.line.matrixAutoUpdate = false;
  28012. this.add( this.line );
  28013. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  28014. this.cone.matrixAutoUpdate = false;
  28015. this.add( this.cone );
  28016. this.setDirection( dir );
  28017. this.setLength( length, headLength, headWidth );
  28018. }
  28019. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28020. ArrowHelper.prototype.constructor = ArrowHelper;
  28021. ArrowHelper.prototype.setDirection = ( function () {
  28022. var axis = new Vector3();
  28023. var radians;
  28024. return function setDirection( dir ) {
  28025. // dir is assumed to be normalized
  28026. if ( dir.y > 0.99999 ) {
  28027. this.quaternion.set( 0, 0, 0, 1 );
  28028. } else if ( dir.y < - 0.99999 ) {
  28029. this.quaternion.set( 1, 0, 0, 0 );
  28030. } else {
  28031. axis.set( dir.z, 0, - dir.x ).normalize();
  28032. radians = Math.acos( dir.y );
  28033. this.quaternion.setFromAxisAngle( axis, radians );
  28034. }
  28035. };
  28036. }() );
  28037. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28038. if ( headLength === undefined ) headLength = 0.2 * length;
  28039. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28040. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  28041. this.line.updateMatrix();
  28042. this.cone.scale.set( headWidth, headLength, headWidth );
  28043. this.cone.position.y = length;
  28044. this.cone.updateMatrix();
  28045. };
  28046. ArrowHelper.prototype.setColor = function ( color ) {
  28047. this.line.material.color.set( color );
  28048. this.cone.material.color.set( color );
  28049. };
  28050. ArrowHelper.prototype.copy = function ( source ) {
  28051. Object3D.prototype.copy.call( this, source, false );
  28052. this.line.copy( source.line );
  28053. this.cone.copy( source.cone );
  28054. return this;
  28055. };
  28056. ArrowHelper.prototype.clone = function () {
  28057. return new this.constructor().copy( this );
  28058. };
  28059. /**
  28060. * @author sroucheray / http://sroucheray.org/
  28061. * @author mrdoob / http://mrdoob.com/
  28062. */
  28063. function AxesHelper( size ) {
  28064. size = size || 1;
  28065. var vertices = [
  28066. 0, 0, 0, size, 0, 0,
  28067. 0, 0, 0, 0, size, 0,
  28068. 0, 0, 0, 0, 0, size
  28069. ];
  28070. var colors = [
  28071. 1, 0, 0, 1, 0.6, 0,
  28072. 0, 1, 0, 0.6, 1, 0,
  28073. 0, 0, 1, 0, 0.6, 1
  28074. ];
  28075. var geometry = new BufferGeometry();
  28076. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28077. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28078. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28079. LineSegments.call( this, geometry, material );
  28080. }
  28081. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28082. AxesHelper.prototype.constructor = AxesHelper;
  28083. /**
  28084. * @author mrdoob / http://mrdoob.com/
  28085. */
  28086. function Face4( a, b, c, d, normal, color, materialIndex ) {
  28087. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  28088. return new Face3( a, b, c, normal, color, materialIndex );
  28089. }
  28090. var LineStrip = 0;
  28091. var LinePieces = 1;
  28092. function MeshFaceMaterial( materials ) {
  28093. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28094. return materials;
  28095. }
  28096. function MultiMaterial( materials ) {
  28097. if ( materials === undefined ) materials = [];
  28098. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28099. materials.isMultiMaterial = true;
  28100. materials.materials = materials;
  28101. materials.clone = function () {
  28102. return materials.slice();
  28103. };
  28104. return materials;
  28105. }
  28106. function PointCloud( geometry, material ) {
  28107. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28108. return new Points( geometry, material );
  28109. }
  28110. function Particle( material ) {
  28111. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28112. return new Sprite( material );
  28113. }
  28114. function ParticleSystem( geometry, material ) {
  28115. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28116. return new Points( geometry, material );
  28117. }
  28118. function PointCloudMaterial( parameters ) {
  28119. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28120. return new PointsMaterial( parameters );
  28121. }
  28122. function ParticleBasicMaterial( parameters ) {
  28123. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28124. return new PointsMaterial( parameters );
  28125. }
  28126. function ParticleSystemMaterial( parameters ) {
  28127. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  28128. return new PointsMaterial( parameters );
  28129. }
  28130. function Vertex( x, y, z ) {
  28131. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  28132. return new Vector3( x, y, z );
  28133. }
  28134. //
  28135. function DynamicBufferAttribute( array, itemSize ) {
  28136. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  28137. return new BufferAttribute( array, itemSize ).setDynamic( true );
  28138. }
  28139. function Int8Attribute( array, itemSize ) {
  28140. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  28141. return new Int8BufferAttribute( array, itemSize );
  28142. }
  28143. function Uint8Attribute( array, itemSize ) {
  28144. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  28145. return new Uint8BufferAttribute( array, itemSize );
  28146. }
  28147. function Uint8ClampedAttribute( array, itemSize ) {
  28148. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  28149. return new Uint8ClampedBufferAttribute( array, itemSize );
  28150. }
  28151. function Int16Attribute( array, itemSize ) {
  28152. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  28153. return new Int16BufferAttribute( array, itemSize );
  28154. }
  28155. function Uint16Attribute( array, itemSize ) {
  28156. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  28157. return new Uint16BufferAttribute( array, itemSize );
  28158. }
  28159. function Int32Attribute( array, itemSize ) {
  28160. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28161. return new Int32BufferAttribute( array, itemSize );
  28162. }
  28163. function Uint32Attribute( array, itemSize ) {
  28164. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28165. return new Uint32BufferAttribute( array, itemSize );
  28166. }
  28167. function Float32Attribute( array, itemSize ) {
  28168. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28169. return new Float32BufferAttribute( array, itemSize );
  28170. }
  28171. function Float64Attribute( array, itemSize ) {
  28172. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28173. return new Float64BufferAttribute( array, itemSize );
  28174. }
  28175. //
  28176. Curve.create = function ( construct, getPoint ) {
  28177. console.log( 'THREE.Curve.create() has been deprecated' );
  28178. construct.prototype = Object.create( Curve.prototype );
  28179. construct.prototype.constructor = construct;
  28180. construct.prototype.getPoint = getPoint;
  28181. return construct;
  28182. };
  28183. //
  28184. Object.assign( CurvePath.prototype, {
  28185. createPointsGeometry: function ( divisions ) {
  28186. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28187. // generate geometry from path points (for Line or Points objects)
  28188. var pts = this.getPoints( divisions );
  28189. return this.createGeometry( pts );
  28190. },
  28191. createSpacedPointsGeometry: function ( divisions ) {
  28192. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28193. // generate geometry from equidistant sampling along the path
  28194. var pts = this.getSpacedPoints( divisions );
  28195. return this.createGeometry( pts );
  28196. },
  28197. createGeometry: function ( points ) {
  28198. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28199. var geometry = new Geometry();
  28200. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28201. var point = points[ i ];
  28202. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  28203. }
  28204. return geometry;
  28205. }
  28206. } );
  28207. //
  28208. Object.assign( Path.prototype, {
  28209. fromPoints: function ( points ) {
  28210. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28211. this.setFromPoints( points );
  28212. }
  28213. } );
  28214. //
  28215. function ClosedSplineCurve3( points ) {
  28216. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28217. CatmullRomCurve3.call( this, points );
  28218. this.type = 'catmullrom';
  28219. this.closed = true;
  28220. }
  28221. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28222. //
  28223. function SplineCurve3( points ) {
  28224. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28225. CatmullRomCurve3.call( this, points );
  28226. this.type = 'catmullrom';
  28227. }
  28228. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28229. //
  28230. function Spline( points ) {
  28231. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28232. CatmullRomCurve3.call( this, points );
  28233. this.type = 'catmullrom';
  28234. }
  28235. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28236. Object.assign( Spline.prototype, {
  28237. initFromArray: function ( /* a */ ) {
  28238. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28239. },
  28240. getControlPointsArray: function ( /* optionalTarget */ ) {
  28241. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28242. },
  28243. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  28244. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  28245. }
  28246. } );
  28247. //
  28248. function AxisHelper( size ) {
  28249. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28250. return new AxesHelper( size );
  28251. }
  28252. function BoundingBoxHelper( object, color ) {
  28253. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28254. return new BoxHelper( object, color );
  28255. }
  28256. function EdgesHelper( object, hex ) {
  28257. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28258. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28259. }
  28260. GridHelper.prototype.setColors = function () {
  28261. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28262. };
  28263. SkeletonHelper.prototype.update = function () {
  28264. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28265. };
  28266. function WireframeHelper( object, hex ) {
  28267. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28268. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28269. }
  28270. //
  28271. Object.assign( Loader.prototype, {
  28272. extractUrlBase: function ( url ) {
  28273. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28274. return LoaderUtils.extractUrlBase( url );
  28275. }
  28276. } );
  28277. function XHRLoader( manager ) {
  28278. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28279. return new FileLoader( manager );
  28280. }
  28281. function BinaryTextureLoader( manager ) {
  28282. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28283. return new DataTextureLoader( manager );
  28284. }
  28285. Object.assign( ObjectLoader.prototype, {
  28286. setTexturePath: function ( value ) {
  28287. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  28288. return this.setResourcePath( value );
  28289. }
  28290. } );
  28291. //
  28292. Object.assign( Box2.prototype, {
  28293. center: function ( optionalTarget ) {
  28294. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28295. return this.getCenter( optionalTarget );
  28296. },
  28297. empty: function () {
  28298. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28299. return this.isEmpty();
  28300. },
  28301. isIntersectionBox: function ( box ) {
  28302. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28303. return this.intersectsBox( box );
  28304. },
  28305. size: function ( optionalTarget ) {
  28306. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28307. return this.getSize( optionalTarget );
  28308. }
  28309. } );
  28310. Object.assign( Box3.prototype, {
  28311. center: function ( optionalTarget ) {
  28312. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28313. return this.getCenter( optionalTarget );
  28314. },
  28315. empty: function () {
  28316. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28317. return this.isEmpty();
  28318. },
  28319. isIntersectionBox: function ( box ) {
  28320. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28321. return this.intersectsBox( box );
  28322. },
  28323. isIntersectionSphere: function ( sphere ) {
  28324. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28325. return this.intersectsSphere( sphere );
  28326. },
  28327. size: function ( optionalTarget ) {
  28328. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28329. return this.getSize( optionalTarget );
  28330. }
  28331. } );
  28332. Line3.prototype.center = function ( optionalTarget ) {
  28333. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28334. return this.getCenter( optionalTarget );
  28335. };
  28336. Object.assign( _Math, {
  28337. random16: function () {
  28338. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28339. return Math.random();
  28340. },
  28341. nearestPowerOfTwo: function ( value ) {
  28342. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28343. return _Math.floorPowerOfTwo( value );
  28344. },
  28345. nextPowerOfTwo: function ( value ) {
  28346. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28347. return _Math.ceilPowerOfTwo( value );
  28348. }
  28349. } );
  28350. Object.assign( Matrix3.prototype, {
  28351. flattenToArrayOffset: function ( array, offset ) {
  28352. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28353. return this.toArray( array, offset );
  28354. },
  28355. multiplyVector3: function ( vector ) {
  28356. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28357. return vector.applyMatrix3( this );
  28358. },
  28359. multiplyVector3Array: function ( /* a */ ) {
  28360. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28361. },
  28362. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28363. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28364. return this.applyToBufferAttribute( buffer );
  28365. },
  28366. applyToVector3Array: function ( /* array, offset, length */ ) {
  28367. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28368. }
  28369. } );
  28370. Object.assign( Matrix4.prototype, {
  28371. extractPosition: function ( m ) {
  28372. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28373. return this.copyPosition( m );
  28374. },
  28375. flattenToArrayOffset: function ( array, offset ) {
  28376. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28377. return this.toArray( array, offset );
  28378. },
  28379. getPosition: function () {
  28380. var v1;
  28381. return function getPosition() {
  28382. if ( v1 === undefined ) v1 = new Vector3();
  28383. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28384. return v1.setFromMatrixColumn( this, 3 );
  28385. };
  28386. }(),
  28387. setRotationFromQuaternion: function ( q ) {
  28388. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28389. return this.makeRotationFromQuaternion( q );
  28390. },
  28391. multiplyToArray: function () {
  28392. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28393. },
  28394. multiplyVector3: function ( vector ) {
  28395. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28396. return vector.applyMatrix4( this );
  28397. },
  28398. multiplyVector4: function ( vector ) {
  28399. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28400. return vector.applyMatrix4( this );
  28401. },
  28402. multiplyVector3Array: function ( /* a */ ) {
  28403. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28404. },
  28405. rotateAxis: function ( v ) {
  28406. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28407. v.transformDirection( this );
  28408. },
  28409. crossVector: function ( vector ) {
  28410. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28411. return vector.applyMatrix4( this );
  28412. },
  28413. translate: function () {
  28414. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28415. },
  28416. rotateX: function () {
  28417. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28418. },
  28419. rotateY: function () {
  28420. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28421. },
  28422. rotateZ: function () {
  28423. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28424. },
  28425. rotateByAxis: function () {
  28426. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28427. },
  28428. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28429. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28430. return this.applyToBufferAttribute( buffer );
  28431. },
  28432. applyToVector3Array: function ( /* array, offset, length */ ) {
  28433. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28434. },
  28435. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28436. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28437. return this.makePerspective( left, right, top, bottom, near, far );
  28438. }
  28439. } );
  28440. Plane.prototype.isIntersectionLine = function ( line ) {
  28441. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28442. return this.intersectsLine( line );
  28443. };
  28444. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28445. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28446. return vector.applyQuaternion( this );
  28447. };
  28448. Object.assign( Ray.prototype, {
  28449. isIntersectionBox: function ( box ) {
  28450. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28451. return this.intersectsBox( box );
  28452. },
  28453. isIntersectionPlane: function ( plane ) {
  28454. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28455. return this.intersectsPlane( plane );
  28456. },
  28457. isIntersectionSphere: function ( sphere ) {
  28458. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28459. return this.intersectsSphere( sphere );
  28460. }
  28461. } );
  28462. Object.assign( Triangle.prototype, {
  28463. area: function () {
  28464. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28465. return this.getArea();
  28466. },
  28467. barycoordFromPoint: function ( point, target ) {
  28468. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28469. return this.getBarycoord( point, target );
  28470. },
  28471. midpoint: function ( target ) {
  28472. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28473. return this.getMidpoint( target );
  28474. },
  28475. normal: function ( target ) {
  28476. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28477. return this.getNormal( target );
  28478. },
  28479. plane: function ( target ) {
  28480. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28481. return this.getPlane( target );
  28482. }
  28483. } );
  28484. Object.assign( Triangle, {
  28485. barycoordFromPoint: function ( point, a, b, c, target ) {
  28486. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28487. return Triangle.getBarycoord( point, a, b, c, target );
  28488. },
  28489. normal: function ( a, b, c, target ) {
  28490. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28491. return Triangle.getNormal( a, b, c, target );
  28492. }
  28493. } );
  28494. Object.assign( Shape.prototype, {
  28495. extractAllPoints: function ( divisions ) {
  28496. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28497. return this.extractPoints( divisions );
  28498. },
  28499. extrude: function ( options ) {
  28500. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28501. return new ExtrudeGeometry( this, options );
  28502. },
  28503. makeGeometry: function ( options ) {
  28504. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28505. return new ShapeGeometry( this, options );
  28506. }
  28507. } );
  28508. Object.assign( Vector2.prototype, {
  28509. fromAttribute: function ( attribute, index, offset ) {
  28510. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28511. return this.fromBufferAttribute( attribute, index, offset );
  28512. },
  28513. distanceToManhattan: function ( v ) {
  28514. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28515. return this.manhattanDistanceTo( v );
  28516. },
  28517. lengthManhattan: function () {
  28518. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28519. return this.manhattanLength();
  28520. }
  28521. } );
  28522. Object.assign( Vector3.prototype, {
  28523. setEulerFromRotationMatrix: function () {
  28524. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28525. },
  28526. setEulerFromQuaternion: function () {
  28527. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28528. },
  28529. getPositionFromMatrix: function ( m ) {
  28530. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28531. return this.setFromMatrixPosition( m );
  28532. },
  28533. getScaleFromMatrix: function ( m ) {
  28534. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28535. return this.setFromMatrixScale( m );
  28536. },
  28537. getColumnFromMatrix: function ( index, matrix ) {
  28538. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28539. return this.setFromMatrixColumn( matrix, index );
  28540. },
  28541. applyProjection: function ( m ) {
  28542. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28543. return this.applyMatrix4( m );
  28544. },
  28545. fromAttribute: function ( attribute, index, offset ) {
  28546. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28547. return this.fromBufferAttribute( attribute, index, offset );
  28548. },
  28549. distanceToManhattan: function ( v ) {
  28550. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28551. return this.manhattanDistanceTo( v );
  28552. },
  28553. lengthManhattan: function () {
  28554. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28555. return this.manhattanLength();
  28556. }
  28557. } );
  28558. Object.assign( Vector4.prototype, {
  28559. fromAttribute: function ( attribute, index, offset ) {
  28560. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28561. return this.fromBufferAttribute( attribute, index, offset );
  28562. },
  28563. lengthManhattan: function () {
  28564. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28565. return this.manhattanLength();
  28566. }
  28567. } );
  28568. //
  28569. Object.assign( Geometry.prototype, {
  28570. computeTangents: function () {
  28571. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28572. },
  28573. computeLineDistances: function () {
  28574. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28575. }
  28576. } );
  28577. Object.assign( Object3D.prototype, {
  28578. getChildByName: function ( name ) {
  28579. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28580. return this.getObjectByName( name );
  28581. },
  28582. renderDepth: function () {
  28583. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28584. },
  28585. translate: function ( distance, axis ) {
  28586. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28587. return this.translateOnAxis( axis, distance );
  28588. },
  28589. getWorldRotation: function () {
  28590. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28591. }
  28592. } );
  28593. Object.defineProperties( Object3D.prototype, {
  28594. eulerOrder: {
  28595. get: function () {
  28596. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28597. return this.rotation.order;
  28598. },
  28599. set: function ( value ) {
  28600. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28601. this.rotation.order = value;
  28602. }
  28603. },
  28604. useQuaternion: {
  28605. get: function () {
  28606. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28607. },
  28608. set: function () {
  28609. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28610. }
  28611. }
  28612. } );
  28613. Object.defineProperties( LOD.prototype, {
  28614. objects: {
  28615. get: function () {
  28616. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28617. return this.levels;
  28618. }
  28619. }
  28620. } );
  28621. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28622. get: function () {
  28623. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28624. },
  28625. set: function () {
  28626. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28627. }
  28628. } );
  28629. SkinnedMesh.prototype.initBones = function () {
  28630. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28631. };
  28632. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28633. get: function () {
  28634. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28635. return this.arcLengthDivisions;
  28636. },
  28637. set: function ( value ) {
  28638. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28639. this.arcLengthDivisions = value;
  28640. }
  28641. } );
  28642. //
  28643. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28644. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28645. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28646. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28647. this.setFocalLength( focalLength );
  28648. };
  28649. //
  28650. Object.defineProperties( Light.prototype, {
  28651. onlyShadow: {
  28652. set: function () {
  28653. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28654. }
  28655. },
  28656. shadowCameraFov: {
  28657. set: function ( value ) {
  28658. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28659. this.shadow.camera.fov = value;
  28660. }
  28661. },
  28662. shadowCameraLeft: {
  28663. set: function ( value ) {
  28664. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28665. this.shadow.camera.left = value;
  28666. }
  28667. },
  28668. shadowCameraRight: {
  28669. set: function ( value ) {
  28670. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28671. this.shadow.camera.right = value;
  28672. }
  28673. },
  28674. shadowCameraTop: {
  28675. set: function ( value ) {
  28676. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28677. this.shadow.camera.top = value;
  28678. }
  28679. },
  28680. shadowCameraBottom: {
  28681. set: function ( value ) {
  28682. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28683. this.shadow.camera.bottom = value;
  28684. }
  28685. },
  28686. shadowCameraNear: {
  28687. set: function ( value ) {
  28688. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28689. this.shadow.camera.near = value;
  28690. }
  28691. },
  28692. shadowCameraFar: {
  28693. set: function ( value ) {
  28694. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28695. this.shadow.camera.far = value;
  28696. }
  28697. },
  28698. shadowCameraVisible: {
  28699. set: function () {
  28700. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28701. }
  28702. },
  28703. shadowBias: {
  28704. set: function ( value ) {
  28705. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28706. this.shadow.bias = value;
  28707. }
  28708. },
  28709. shadowDarkness: {
  28710. set: function () {
  28711. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28712. }
  28713. },
  28714. shadowMapWidth: {
  28715. set: function ( value ) {
  28716. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28717. this.shadow.mapSize.width = value;
  28718. }
  28719. },
  28720. shadowMapHeight: {
  28721. set: function ( value ) {
  28722. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28723. this.shadow.mapSize.height = value;
  28724. }
  28725. }
  28726. } );
  28727. //
  28728. Object.defineProperties( BufferAttribute.prototype, {
  28729. length: {
  28730. get: function () {
  28731. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28732. return this.array.length;
  28733. }
  28734. },
  28735. copyIndicesArray: function ( /* indices */ ) {
  28736. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28737. }
  28738. } );
  28739. Object.assign( BufferGeometry.prototype, {
  28740. addIndex: function ( index ) {
  28741. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28742. this.setIndex( index );
  28743. },
  28744. addDrawCall: function ( start, count, indexOffset ) {
  28745. if ( indexOffset !== undefined ) {
  28746. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28747. }
  28748. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28749. this.addGroup( start, count );
  28750. },
  28751. clearDrawCalls: function () {
  28752. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28753. this.clearGroups();
  28754. },
  28755. computeTangents: function () {
  28756. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28757. },
  28758. computeOffsets: function () {
  28759. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28760. }
  28761. } );
  28762. Object.defineProperties( BufferGeometry.prototype, {
  28763. drawcalls: {
  28764. get: function () {
  28765. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28766. return this.groups;
  28767. }
  28768. },
  28769. offsets: {
  28770. get: function () {
  28771. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28772. return this.groups;
  28773. }
  28774. }
  28775. } );
  28776. //
  28777. Object.assign( ExtrudeBufferGeometry.prototype, {
  28778. getArrays: function () {
  28779. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28780. },
  28781. addShapeList: function () {
  28782. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28783. },
  28784. addShape: function () {
  28785. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28786. }
  28787. } );
  28788. //
  28789. Object.defineProperties( Uniform.prototype, {
  28790. dynamic: {
  28791. set: function () {
  28792. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28793. }
  28794. },
  28795. onUpdate: {
  28796. value: function () {
  28797. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28798. return this;
  28799. }
  28800. }
  28801. } );
  28802. //
  28803. Object.defineProperties( Material.prototype, {
  28804. wrapAround: {
  28805. get: function () {
  28806. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28807. },
  28808. set: function () {
  28809. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28810. }
  28811. },
  28812. overdraw: {
  28813. get: function () {
  28814. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28815. },
  28816. set: function () {
  28817. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28818. }
  28819. },
  28820. wrapRGB: {
  28821. get: function () {
  28822. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28823. return new Color();
  28824. }
  28825. },
  28826. shading: {
  28827. get: function () {
  28828. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28829. },
  28830. set: function ( value ) {
  28831. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28832. this.flatShading = ( value === FlatShading );
  28833. }
  28834. }
  28835. } );
  28836. Object.defineProperties( MeshPhongMaterial.prototype, {
  28837. metal: {
  28838. get: function () {
  28839. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28840. return false;
  28841. },
  28842. set: function () {
  28843. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28844. }
  28845. }
  28846. } );
  28847. Object.defineProperties( ShaderMaterial.prototype, {
  28848. derivatives: {
  28849. get: function () {
  28850. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28851. return this.extensions.derivatives;
  28852. },
  28853. set: function ( value ) {
  28854. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28855. this.extensions.derivatives = value;
  28856. }
  28857. }
  28858. } );
  28859. //
  28860. Object.assign( WebGLRenderer.prototype, {
  28861. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28862. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28863. this.setRenderTarget( renderTarget );
  28864. this.clear( color, depth, stencil );
  28865. },
  28866. animate: function ( callback ) {
  28867. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28868. this.setAnimationLoop( callback );
  28869. },
  28870. getCurrentRenderTarget: function () {
  28871. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28872. return this.getRenderTarget();
  28873. },
  28874. getMaxAnisotropy: function () {
  28875. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28876. return this.capabilities.getMaxAnisotropy();
  28877. },
  28878. getPrecision: function () {
  28879. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28880. return this.capabilities.precision;
  28881. },
  28882. resetGLState: function () {
  28883. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28884. return this.state.reset();
  28885. },
  28886. supportsFloatTextures: function () {
  28887. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28888. return this.extensions.get( 'OES_texture_float' );
  28889. },
  28890. supportsHalfFloatTextures: function () {
  28891. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28892. return this.extensions.get( 'OES_texture_half_float' );
  28893. },
  28894. supportsStandardDerivatives: function () {
  28895. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28896. return this.extensions.get( 'OES_standard_derivatives' );
  28897. },
  28898. supportsCompressedTextureS3TC: function () {
  28899. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28900. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28901. },
  28902. supportsCompressedTexturePVRTC: function () {
  28903. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28904. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28905. },
  28906. supportsBlendMinMax: function () {
  28907. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28908. return this.extensions.get( 'EXT_blend_minmax' );
  28909. },
  28910. supportsVertexTextures: function () {
  28911. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28912. return this.capabilities.vertexTextures;
  28913. },
  28914. supportsInstancedArrays: function () {
  28915. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28916. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28917. },
  28918. enableScissorTest: function ( boolean ) {
  28919. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28920. this.setScissorTest( boolean );
  28921. },
  28922. initMaterial: function () {
  28923. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28924. },
  28925. addPrePlugin: function () {
  28926. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28927. },
  28928. addPostPlugin: function () {
  28929. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28930. },
  28931. updateShadowMap: function () {
  28932. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28933. },
  28934. setFaceCulling: function () {
  28935. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28936. },
  28937. allocTextureUnit: function () {
  28938. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28939. },
  28940. setTexture: function () {
  28941. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28942. },
  28943. setTexture2D: function () {
  28944. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28945. },
  28946. setTextureCube: function () {
  28947. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28948. },
  28949. getActiveMipMapLevel: function () {
  28950. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  28951. return this.getActiveMipmapLevel();
  28952. }
  28953. } );
  28954. Object.defineProperties( WebGLRenderer.prototype, {
  28955. shadowMapEnabled: {
  28956. get: function () {
  28957. return this.shadowMap.enabled;
  28958. },
  28959. set: function ( value ) {
  28960. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28961. this.shadowMap.enabled = value;
  28962. }
  28963. },
  28964. shadowMapType: {
  28965. get: function () {
  28966. return this.shadowMap.type;
  28967. },
  28968. set: function ( value ) {
  28969. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28970. this.shadowMap.type = value;
  28971. }
  28972. },
  28973. shadowMapCullFace: {
  28974. get: function () {
  28975. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28976. return undefined;
  28977. },
  28978. set: function ( /* value */ ) {
  28979. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28980. }
  28981. },
  28982. context: {
  28983. get: function () {
  28984. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  28985. return this.getContext();
  28986. }
  28987. }
  28988. } );
  28989. Object.defineProperties( WebGLShadowMap.prototype, {
  28990. cullFace: {
  28991. get: function () {
  28992. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28993. return undefined;
  28994. },
  28995. set: function ( /* cullFace */ ) {
  28996. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28997. }
  28998. },
  28999. renderReverseSided: {
  29000. get: function () {
  29001. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29002. return undefined;
  29003. },
  29004. set: function () {
  29005. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29006. }
  29007. },
  29008. renderSingleSided: {
  29009. get: function () {
  29010. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29011. return undefined;
  29012. },
  29013. set: function () {
  29014. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29015. }
  29016. }
  29017. } );
  29018. //
  29019. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  29020. activeCubeFace: {
  29021. set: function ( /* value */ ) {
  29022. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  29023. }
  29024. },
  29025. activeMipMapLevel: {
  29026. set: function ( /* value */ ) {
  29027. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  29028. }
  29029. }
  29030. } );
  29031. //
  29032. Object.defineProperties( WebGLRenderTarget.prototype, {
  29033. wrapS: {
  29034. get: function () {
  29035. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29036. return this.texture.wrapS;
  29037. },
  29038. set: function ( value ) {
  29039. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29040. this.texture.wrapS = value;
  29041. }
  29042. },
  29043. wrapT: {
  29044. get: function () {
  29045. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29046. return this.texture.wrapT;
  29047. },
  29048. set: function ( value ) {
  29049. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29050. this.texture.wrapT = value;
  29051. }
  29052. },
  29053. magFilter: {
  29054. get: function () {
  29055. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29056. return this.texture.magFilter;
  29057. },
  29058. set: function ( value ) {
  29059. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29060. this.texture.magFilter = value;
  29061. }
  29062. },
  29063. minFilter: {
  29064. get: function () {
  29065. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29066. return this.texture.minFilter;
  29067. },
  29068. set: function ( value ) {
  29069. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29070. this.texture.minFilter = value;
  29071. }
  29072. },
  29073. anisotropy: {
  29074. get: function () {
  29075. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29076. return this.texture.anisotropy;
  29077. },
  29078. set: function ( value ) {
  29079. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29080. this.texture.anisotropy = value;
  29081. }
  29082. },
  29083. offset: {
  29084. get: function () {
  29085. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29086. return this.texture.offset;
  29087. },
  29088. set: function ( value ) {
  29089. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29090. this.texture.offset = value;
  29091. }
  29092. },
  29093. repeat: {
  29094. get: function () {
  29095. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29096. return this.texture.repeat;
  29097. },
  29098. set: function ( value ) {
  29099. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29100. this.texture.repeat = value;
  29101. }
  29102. },
  29103. format: {
  29104. get: function () {
  29105. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29106. return this.texture.format;
  29107. },
  29108. set: function ( value ) {
  29109. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29110. this.texture.format = value;
  29111. }
  29112. },
  29113. type: {
  29114. get: function () {
  29115. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29116. return this.texture.type;
  29117. },
  29118. set: function ( value ) {
  29119. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29120. this.texture.type = value;
  29121. }
  29122. },
  29123. generateMipmaps: {
  29124. get: function () {
  29125. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29126. return this.texture.generateMipmaps;
  29127. },
  29128. set: function ( value ) {
  29129. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29130. this.texture.generateMipmaps = value;
  29131. }
  29132. }
  29133. } );
  29134. //
  29135. Object.defineProperties( WebVRManager.prototype, {
  29136. standing: {
  29137. set: function ( /* value */ ) {
  29138. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  29139. }
  29140. },
  29141. userHeight: {
  29142. set: function ( /* value */ ) {
  29143. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  29144. }
  29145. }
  29146. } );
  29147. //
  29148. Audio.prototype.load = function ( file ) {
  29149. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  29150. var scope = this;
  29151. var audioLoader = new AudioLoader();
  29152. audioLoader.load( file, function ( buffer ) {
  29153. scope.setBuffer( buffer );
  29154. } );
  29155. return this;
  29156. };
  29157. AudioAnalyser.prototype.getData = function () {
  29158. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  29159. return this.getFrequencyData();
  29160. };
  29161. //
  29162. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  29163. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  29164. return this.update( renderer, scene );
  29165. };
  29166. //
  29167. var GeometryUtils = {
  29168. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  29169. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  29170. var matrix;
  29171. if ( geometry2.isMesh ) {
  29172. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  29173. matrix = geometry2.matrix;
  29174. geometry2 = geometry2.geometry;
  29175. }
  29176. geometry1.merge( geometry2, matrix, materialIndexOffset );
  29177. },
  29178. center: function ( geometry ) {
  29179. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  29180. return geometry.center();
  29181. }
  29182. };
  29183. ImageUtils.crossOrigin = undefined;
  29184. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29185. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29186. var loader = new TextureLoader();
  29187. loader.setCrossOrigin( this.crossOrigin );
  29188. var texture = loader.load( url, onLoad, undefined, onError );
  29189. if ( mapping ) texture.mapping = mapping;
  29190. return texture;
  29191. };
  29192. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29193. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29194. var loader = new CubeTextureLoader();
  29195. loader.setCrossOrigin( this.crossOrigin );
  29196. var texture = loader.load( urls, onLoad, undefined, onError );
  29197. if ( mapping ) texture.mapping = mapping;
  29198. return texture;
  29199. };
  29200. ImageUtils.loadCompressedTexture = function () {
  29201. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29202. };
  29203. ImageUtils.loadCompressedTextureCube = function () {
  29204. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29205. };
  29206. //
  29207. function CanvasRenderer() {
  29208. console.error( 'THREE.CanvasRenderer has been removed' );
  29209. }
  29210. //
  29211. function JSONLoader() {
  29212. console.error( 'THREE.JSONLoader has been removed.' );
  29213. }
  29214. //
  29215. var SceneUtils = {
  29216. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29217. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29218. },
  29219. detach: function ( /* child, parent, scene */ ) {
  29220. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29221. },
  29222. attach: function ( /* child, scene, parent */ ) {
  29223. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29224. }
  29225. };
  29226. //
  29227. function LensFlare() {
  29228. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  29229. }
  29230. export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveBlending, AlphaFormat, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightProbe, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrowHelper, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, AxisHelper, BackSide, BasicDepthPacking, BasicShadowMap, BinaryTextureLoader, Bone, BooleanKeyframeTrack, BoundingBoxHelper, Box2, Box3, Box3Helper, BoxBufferGeometry, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasRenderer, CanvasTexture, CatmullRomCurve3, CineonToneMapping, CircleBufferGeometry, CircleGeometry, ClampToEdgeWrapping, Clock, ClosedSplineCurve3, Color, ColorKeyframeTrack, CompressedTexture, CompressedTextureLoader, ConeBufferGeometry, ConeGeometry, CubeCamera, BoxGeometry as CubeGeometry, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubeUVRefractionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CylinderBufferGeometry, CylinderGeometry, Cylindrical, DataTexture, DataTexture2DArray, DataTexture3D, DataTextureLoader, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightHelper, DirectionalLightShadow, DiscreteInterpolant, DodecahedronBufferGeometry, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicBufferAttribute, EdgesGeometry, EdgesHelper, EllipseCurve, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeBufferGeometry, ExtrudeGeometry, Face3, Face4, FaceColors, FaceNormalsHelper, FileLoader, FlatShading, Float32Attribute, Float32BufferAttribute, Float64Attribute, Float64BufferAttribute, FloatType, Fog, FogExp2, Font, FontLoader, FrontFaceDirectionCCW, FrontFaceDirectionCW, FrontSide, Frustum, GammaEncoding, Geometry, GeometryUtils, GreaterDepth, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, HemisphereLightProbe, IcosahedronBufferGeometry, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, ImmediateRenderObject, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, Int16Attribute, Int16BufferAttribute, Int32Attribute, Int32BufferAttribute, Int8Attribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, JSONLoader, KeepStencilOp, KeyframeTrack, LOD, LatheBufferGeometry, LatheGeometry, Layers, LensFlare, LessDepth, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, LightProbeHelper, LightShadow, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LinePieces, LineSegments, LineStrip, LinearEncoding, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearToneMapping, Loader, LoaderUtils, LoadingManager, LogLuvEncoding, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, MOUSE, Material, MaterialLoader, _Math as Math, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshFaceMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiMaterial, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeverDepth, NeverStencilFunc, NoBlending, NoColors, NoToneMapping, NormalBlending, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronBufferGeometry, OctahedronGeometry, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, ParametricBufferGeometry, ParametricGeometry, Particle, ParticleBasicMaterial, ParticleSystem, ParticleSystemMaterial, Path, PerspectiveCamera, Plane, PlaneBufferGeometry, PlaneGeometry, PlaneHelper, PointCloud, PointCloudMaterial, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronBufferGeometry, PolyhedronGeometry, PositionalAudio, PositionalAudioHelper, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, REVISION, RGBADepthPacking, RGBAFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDEncoding, RGBEEncoding, RGBEFormat, RGBFormat, RGBM16Encoding, RGBM7Encoding, RGB_ETC1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RectAreaLightHelper, RedFormat, ReinhardToneMapping, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingBufferGeometry, RingGeometry, Scene, SceneUtils, ShaderChunk, ShaderLib, ShaderMaterial, ShadowMaterial, Shape, ShapeBufferGeometry, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, SmoothShading, Sphere, SphereBufferGeometry, SphereGeometry, Spherical, SphericalHarmonics3, SphericalReflectionMapping, Spline, SplineCurve, SplineCurve3, SpotLight, SpotLightHelper, SpotLightShadow, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StereoCamera, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronBufferGeometry, TetrahedronGeometry, TextBufferGeometry, TextGeometry, Texture, TextureLoader, TorusBufferGeometry, TorusGeometry, TorusKnotBufferGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeBufferGeometry, TubeGeometry, UVMapping, Uint16Attribute, Uint16BufferAttribute, Uint32Attribute, Uint32BufferAttribute, Uint8Attribute, Uint8BufferAttribute, Uint8ClampedAttribute, Uint8ClampedBufferAttribute, Uncharted2ToneMapping, Uniform, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedShortType, Vector2, Vector3, Vector4, VectorKeyframeTrack, Vertex, VertexColors, VertexNormalsHelper, VideoTexture, WebGLMultisampleRenderTarget, WebGLRenderTarget, WebGLRenderTargetCube, WebGLRenderer, WebGLUtils, WireframeGeometry, WireframeHelper, WrapAroundEnding, XHRLoader, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, sRGBEncoding };